find_typedef alternative that works on mainstream systems

Started by Alvaro Herreraover 18 years ago3 messageshackers
Jump to latest
#1Alvaro Herrera
alvherre@2ndquadrant.com

Hi,

I just came across objdump -W which dumps the DWARF info from a object
file. This is useful to build a typedef file for pgindent. It can be
used like this:

objdump -W $object_file | \
awk '/DW_TAG_/ { grab=0 } /DW_TAG_typedef/ { grab=1 } /DW_AT_name/ { if (grab) { print $0 } }' | \
sed -e 's/^.*: \([^ ]*\)/\1/' | \
sort | \
uniq

I am disappointed by the fact that our current find_typedef script only
works on Bruce's rare platforms -- and we stopped shipping a "standard"
typedef file, which makes the problem worse.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#1)
Re: find_typedef alternative that works on mainstream systems

Alvaro Herrera wrote:

objdump -W $object_file | \
awk '/DW_TAG_/ { grab=0 } /DW_TAG_typedef/ { grab=1 } /DW_AT_name/ { if (grab) { print $0 } }' | \
sed -e 's/^.*: \([^ ]*\)/\1/' | \
sort | \
uniq

I oversimplified the awk line, causing some garbage to appear at the end
:-( The full awk line I am using is

awk '
/^Contents of / { if (read) exit }
/^The section / { if (read) exit }
/^The section .debug_info contains:/ { read=1 }
/DW_TAG_/ { grab=0 }
/DW_TAG_typedef/ { grab=1 }
/DW_AT_name/ { if (read && grab) { print $0 } }
'

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#3Bruce Momjian
bruce@momjian.us
In reply to: Alvaro Herrera (#2)
Re: find_typedef alternative that works on mainstream systems

Alvaro Herrera wrote:

Alvaro Herrera wrote:

objdump -W $object_file | \
awk '/DW_TAG_/ { grab=0 } /DW_TAG_typedef/ { grab=1 } /DW_AT_name/ { if (grab) { print $0 } }' | \
sed -e 's/^.*: \([^ ]*\)/\1/' | \
sort | \
uniq

I oversimplified the awk line, causing some garbage to appear at the end
:-( The full awk line I am using is

awk '
/^Contents of / { if (read) exit }
/^The section / { if (read) exit }
/^The section .debug_info contains:/ { read=1 }
/DW_TAG_/ { grab=0 }
/DW_TAG_typedef/ { grab=1 }
/DW_AT_name/ { if (read && grab) { print $0 } }
'

objdump errors on the -W option here (returns -1) so put some
conditional logic in tools/find_typedef and we should be fine.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +