Subject: [SCRIPT] Windows system dll function addresses
From: Joe Buehler <[email-masked]>
To: [email-masked]
Date: Fri, 13 Dec 2002 09:16:58 -0500

Sometimes it is useful to be able to tell what Windows
DLL functions are at the top of a stack trace in gdb
(not everyone can remember functions by address instead
of name).

Here is a perl script to dump a sorted list of symbol
addresses from the dlls on a Windows system.  You need
dumpbin to run this.  Only tested on Windows NT --
dumpbin may have different output on other versions, in
which case this may break.

Oh, one thing -- I have a mount point named "/sys" that is the
directory where the dlls reside.  I think I made that myself.
You will have to substitute whatever the appropriate path is
on your machine.

Joe Buehler

#!/usr/bin/perl
#
# dump symbols and absolute address from Windows system dlls
#
# You need dumpbin for this to work.
# You also need to change /sys to whatever is appropriate.
#

opendir(SYSDIR, "/sys");
while ($dll = readdir(SYSDIR)) {
	next unless $dll =~ /[.]dll$/io;
	next unless -f "/sys/$dll";
	open(DUMPBIN, qq{ cd /sys && dumpbin /headers /exports $dll | });
	while (<DUMPBIN>) {
		s/\r*\n//o;
		next if /^\s*$/o;
		if (/^\s*(\S+)\s+image\s+base\s*$/io) {
			$image_base_address = hex $1;
		} elsif (/^\s+ordinal\s+hint\s+RVA\s+name\s*$/io .. /^\S/o) {
			next if /^\s+ordinal\s+hint\s+RVA\s+name\s*$/io;
			next if /^\S/io;
			next unless ($ordinal, $hint, $RVA, $name) = /^\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+)$/o;
			$RVA = hex $RVA;
			push(@out, sprintf("0x%08x %16s %s\n", $image_base_address + $RVA, $dll, $name));
		}
	}
	close(DUMPBIN);
}
closedir(SYSDIR);

print sort @out;

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/