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
|
|
|
|
# by using 'nm' to report all typedef debugging symbols.
|
2010-11-23 21:27:50 +01:00
|
|
|
#
|
|
|
|
# For this program to work, you must have compiled all binaries with
|
1997-09-08 06:14:01 +02:00
|
|
|
# debugging symbols.
|
|
|
|
#
|
2012-05-03 16:58:44 +02:00
|
|
|
# This is run on Linux, so you may need to make changes.
|
2010-11-23 21:27:50 +01:00
|
|
|
#
|
1997-09-08 06:14:01 +02:00
|
|
|
# Ignore the nm errors about a file not being a binary file.
|
|
|
|
#
|
2007-12-21 22:02:41 +01:00
|
|
|
# It gets typedefs by reading "STABS":
|
1997-09-08 06:14:01 +02:00
|
|
|
#
|
2007-12-21 22:02:41 +01:00
|
|
|
# http://www.informatik.uni-frankfurt.de/doc/texi/stabs_toc.html
|
|
|
|
#
|
|
|
|
# objdump:
|
|
|
|
# -G, --stabs Display (in raw form) any STABS info in the file
|
|
|
|
#
|
|
|
|
# --stabs
|
|
|
|
# Display the contents of the .stab, .stab.index, and
|
|
|
|
# .stab.excl sections from an ELF file. This is only
|
|
|
|
# useful on systems (such as Solaris 2.0) in which
|
|
|
|
# .stab debugging symbol-table entries are carried in
|
|
|
|
# an ELF section. In most other file formats, debug-
|
|
|
|
# ging symbol-table entries are interleaved with
|
|
|
|
# linkage symbols, and are visible in the --syms out-
|
|
|
|
# put.
|
|
|
|
|
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
|
2008-03-19 00:23:08 +01:00
|
|
|
# Unfortunately the Linux version doesn't show unreferenced typedefs.
|
|
|
|
# The problem is that they are still in the source code so should be
|
|
|
|
# indented properly. However, I think pgindent only cares about
|
|
|
|
# the typedef references, not the definitions, so I think it might
|
|
|
|
# be fine
|
2008-03-18 23:45:11 +01:00
|
|
|
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)$'
|