]> granicus.if.org Git - postgresql/blob - src/tools/find_typedef
Mention BSD/OS find_typedef behavior.
[postgresql] / src / tools / find_typedef
1 #!/bin/sh
2
3 # $PostgreSQL: pgsql/src/tools/find_typedef,v 1.15 2009/06/12 03:04:48 momjian Exp $
4
5 # This script attempts to find all typedef's in the postgres binaries
6 # by using 'nm' to report all typedef debugging symbols.
7
8 # For this program to work, you must have compiled all binaries with 
9 # debugging symbols.
10 #
11 # This is run on BSD/OS 4.0 or Linux, so you may need to make changes.
12
13 # Ignore the nm errors about a file not being a binary file.
14 #
15 # It gets typedefs by reading "STABS":
16 #
17 #    http://www.informatik.uni-frankfurt.de/doc/texi/stabs_toc.html
18 #
19 #    objdump:
20 #       -G, --stabs  Display (in raw form) any STABS info in the file
21 #
22 #       --stabs
23 #         Display the contents of the .stab, .stab.index, and
24 #         .stab.excl sections from an ELF file.  This is only
25 #         useful on systems (such as Solaris  2.0)  in  which
26 #         .stab debugging symbol-table entries are carried in
27 #         an ELF section.  In most other file formats, debug-
28 #         ging  symbol-table  entries  are  interleaved  with
29 #         linkage symbols, and are visible in the --syms out-
30 #         put.
31
32
33 if [ "$#" -eq 0 -o ! -d "$1" ]
34 then    echo "Usage:  $0 postgres_binary_directory [...]" 1>&2
35         exit 1
36 fi
37
38 for DIR
39 do      # if objdump -W is recognized, only one line of error should appear
40         if [ `objdump -W 2>&1 | wc -l` -eq 1 ]
41         then    # Linux
42                 # Unfortunately the Linux version doesn't show unreferenced typedefs.
43                 # The problem is that they are still in the source code so should be
44                 # indented properly.  However, I think pgindent only cares about
45                 # the typedef references, not the definitions, so I think it might
46                 # be fine
47                 objdump -W "$DIR"/* |
48                 egrep -A3 'DW_TAG_typedef' |
49                 awk ' $2 == "DW_AT_name" {print $NF}'
50         elif [ `readelf -w 2>&1 | wc -l` -gt 1 ]
51         then    # FreeBSD, similar output to Linux
52                 readelf -w "$DIR"/* |
53                 egrep -A3 '\(DW_TAG_typedef\)' |
54                 awk ' $1 == "DW_AT_name" {print $NF}'
55         else    # BSD/OS
56                 # BSD/OS reports all typedefs, even those defined in system
57                 # include files but never referenced in the PG code.
58                 objdump --stabs "$DIR"/* |
59                 awk ' $2 == "LSYM" && $7 ~ /:t/ {sub(":.*", "", $7); print $7}'
60         fi
61 done |
62 grep -v ' ' | # some typedefs have spaces, remove them
63 sort |
64 uniq |
65 # these are used both for typedefs and variable names
66 # so do not include them
67 egrep -v '^(date|interval|timestamp|ANY)$'