Add Linux support to find_typedefs, with help from Alvaro.
authorBruce Momjian <bruce@momjian.us>
Tue, 18 Mar 2008 22:45:11 +0000 (22:45 +0000)
committerBruce Momjian <bruce@momjian.us>
Tue, 18 Mar 2008 22:45:11 +0000 (22:45 +0000)
src/tools/find_typedef

index 63a8dd39df53accecc0ebe50ee06817281fe7b88..7725108170d5944ffc0e14876218f87b874e9f66 100755 (executable)
@@ -8,7 +8,7 @@
 # For this program to work, you must have compiled all binaries with 
 # debugging symbols.
 #
-# This is run on BSD/OS 4.0, so you may need to make changes.
+# This is run on BSD/OS 4.0 or Linux, so you may need to make changes.
 # 
 # Ignore the nm errors about a file not being a binary file.
 #
@@ -37,10 +37,18 @@ fi
 
 for DIR
 do
-       objdump --stabs "$DIR"/* |
-       awk ' $2 == "LSYM" && $7 ~ /:[tT]/ {sub(":.*", "", $7); print $7}' |
-       grep -v ' ' # some typedefs have spaces, remove them
+       if [ `objdump -W 2>&1 | wc -l` -eq 1 ]
+       then    # Linux
+               # unfortunately the Linux version doesn't show unreferenced typedefs
+               objdump -W "$DIR"/* |
+               egrep -A3 '(DW_TAG_typedef|DW_TAG_structure_type|DW_TAG_union_type)' |
+               awk ' $2 == "DW_AT_name" {print $NF}'
+       else    # BSD/OS
+               objdump --stabs "$DIR"/* |
+               awk ' $2 == "LSYM" && $7 ~ /:[tT]/ {sub(":.*", "", $7); print $7}'
+       fi
 done |
+grep -v ' ' | # some typedefs have spaces, remove them
 sort |
 uniq |
 # these are used both for typedefs and variable names