1997-09-08 06:14:01 +02:00
|
|
|
#!/bin/sh
|
2006-03-11 05:38:42 +01:00
|
|
|
|
2010-09-20 22:08:53 +02:00
|
|
|
# src/tools/find_typedef
|
2006-03-11 05:38:42 +01:00
|
|
|
|
1997-09-08 06:14:01 +02:00
|
|
|
# This script attempts to find all typedef's in the postgres binaries
|
2014-11-18 21:51:45 +01:00
|
|
|
# by using 'objdump' or local equivalent to print typedef debugging symbols.
|
|
|
|
# We need this because pgindent needs a list of typedef names.
|
2010-11-23 21:27:50 +01:00
|
|
|
#
|
2014-11-18 21:51:45 +01:00
|
|
|
# For this program to work, you must have compiled all code with
|
1997-09-08 06:14:01 +02:00
|
|
|
# debugging symbols.
|
|
|
|
#
|
2014-11-18 21:51:45 +01:00
|
|
|
# We intentionally examine all files in the targeted directories so as to
|
|
|
|
# find both .o files and executables. Therefore, ignore error messages about
|
|
|
|
# unsuitable files being fed to objdump.
|
2010-11-23 21:27:50 +01:00
|
|
|
#
|
2014-11-18 21:51:45 +01:00
|
|
|
# This is known to work on Linux and on some BSDen, including Mac OS X.
|
1997-09-08 06:14:01 +02:00
|
|
|
#
|
2014-11-18 21:51:45 +01:00
|
|
|
# Caution: on the platforms we use, this only prints typedefs that are used
|
|
|
|
# to declare at least one variable or struct field. If you have say
|
|
|
|
# "typedef struct foo { ... } foo;", and then the structure is only ever
|
|
|
|
# referenced as "struct foo", "foo" will not be reported as a typedef,
|
|
|
|
# causing pgindent to indent the typedef definition oddly. This is not a
|
|
|
|
# huge problem, since by definition there's just the one misindented line.
|
1997-09-08 06:14:01 +02:00
|
|
|
#
|
2014-11-18 21:51:45 +01:00
|
|
|
# We get typedefs by reading "STABS":
|
2007-12-21 22:02:41 +01:00
|
|
|
# http://www.informatik.uni-frankfurt.de/doc/texi/stabs_toc.html
|
|
|
|
|
1997-09-08 06:14:01 +02:00
|
|
|
|
2005-11-15 01:43:01 +01:00
|
|
|
if [ "$#" -eq 0 -o ! -d "$1" ]
|
|
|
|
then echo "Usage: $0 postgres_binary_directory [...]" 1>&2
|
1997-09-08 06:14:01 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2005-11-15 01:43:01 +01:00
|
|
|
for DIR
|
2008-03-19 00:04:34 +01:00
|
|
|
do # if objdump -W is recognized, only one line of error should appear
|
2008-03-18 23:45:11 +01:00
|
|
|
if [ `objdump -W 2>&1 | wc -l` -eq 1 ]
|
|
|
|
then # Linux
|
|
|
|
objdump -W "$DIR"/* |
|
2009-06-12 05:09:07 +02:00
|
|
|
egrep -A3 '\(DW_TAG_typedef\)' |
|
2008-03-18 23:45:11 +01:00
|
|
|
awk ' $2 == "DW_AT_name" {print $NF}'
|
2009-06-11 05:14:08 +02:00
|
|
|
elif [ `readelf -w 2>&1 | wc -l` -gt 1 ]
|
|
|
|
then # FreeBSD, similar output to Linux
|
|
|
|
readelf -w "$DIR"/* |
|
|
|
|
egrep -A3 '\(DW_TAG_typedef\)' |
|
|
|
|
awk ' $1 == "DW_AT_name" {print $NF}'
|
2008-03-18 23:45:11 +01:00
|
|
|
fi
|
2005-11-15 01:43:01 +01:00
|
|
|
done |
|
2008-03-18 23:45:11 +01:00
|
|
|
grep -v ' ' | # some typedefs have spaces, remove them
|
1999-02-10 18:14:32 +01:00
|
|
|
sort |
|
2005-11-15 01:43:01 +01:00
|
|
|
uniq |
|
2005-11-15 15:45:10 +01:00
|
|
|
# these are used both for typedefs and variable names
|
|
|
|
# so do not include them
|
2007-12-21 15:20:36 +01:00
|
|
|
egrep -v '^(date|interval|timestamp|ANY)$'
|