From: Michael Snyder <msnyder@redhat.com>
To: Raoul Gough <RaoulGough@yahoo.co.uk>
Cc: gdb-patches@sources.redhat.com, Philippe De Muyter <phdm@macqel.be>
Subject: Re: coffread.c extension for DLLs without debugging symbols
Date: Sat, 04 Jan 2003 00:53:00 -0000 [thread overview]
Message-ID: <3E16307E.313CD01@redhat.com> (raw)
In-Reply-To: <av4os0$f0q$1@main.gmane.org>
Raoul Gough wrote:
>
> Patch for coffread.c to extract minimal symbolic information from a
> portable executable using the export table. This provides a fallback
> for DLLs without any gdb-recognized debugging symbols
> (e.g. kernel32.dll). The export table read algorithm is taken from
> pe-dll.c from the ld sources.
>
> Actually, I'm surprised this hasn't been added before, because it
> seems pretty handy to have. This is my *first* gdb patch submission,
> so someone with more experience should probably take a good look at
> (e.g. is coffread.c the right place for this kind of code?). I've
> compiled and tested it on Windows 2000 using Cygwin (where it works)
> and on i386 Suse Linux (where it compiles and remains politely
> inactive).
Well, without having evaluated your code for correctness,
I think it's a well-done change. And I think coffread.c
is the right place for it. You don't change the behavior
except in the specific case you're interested in (and the
behavior can't get much worse than not having any symbols),
so I'd recommend this for acceptance. But Phillipe is the
coff reader maintainer.
>
> Bugs: Using dll-symbols or symbol-file on a DLL that has already had
> its export table loaded results in multiple copies of all of the
> symbols. Also, gdb seems to dereference all minimal symbols as if they
> were pointers, so you often need to add an "&" to the symbol names.
>
> Proposed ChangeLog entry, assuming the code is accepted:
>
> 2003-01-03 Raoul Gough <RaoulGough@yahoo.co.uk>
>
> * coffread.c: Support non-debug export symbols for win32 DLLs
>
> See the example for a simple demonstration of what the new code can
> do. The code amounts to about 350 lines, so I'm not sure if this would
> require me to fill out a copyright form.
>
> Regards,
> Raoul Gough.
>
> Name: coffread.c.diff.gz
> coffread.c.diff.gz Type: unspecified type (application/octet-stream)
> Encoding: x-uuencode
>
> $ cat dlleg.c
> __attribute((__dllexport__)) void fn () { }
>
> __attribute((__dllexport__)) char hello[] = "Hello world";
>
> __attribute((__dllexport__)) int init_data = 42;
>
> __attribute((__dllexport__)) int uninit_data;
>
> $ cat dllegmain.c
> __attribute((__dllimport__)) void fn ();
>
> __attribute((__dllimport__)) char hello[];
>
> __attribute((__dllimport__)) int init_data;
>
> __attribute((__dllimport__)) int uninit_data;
>
> int main ()
> {
> fn();
> uninit_data = init_data;
>
> return 0;
> }
> $ gcc -c dlleg.c
> $ gcc -c dllegmain.c
> $ #
> $ # Note: -Wl,-s strips all possible symbols
> $ #
> $ gcc -Wl,-s -shared -o dlleg.dll dlleg.o
> $ gcc -Wl,-s -o dllegmain dllegmain.o dlleg.dll
> $ gdb dllegmain
> GNU gdb 2003-01-01-cvs
> Copyright 2002 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you are
> welcome to change it and/or distribute copies of it under certain conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB. Type "show warranty" for details.
> This GDB was configured as "i686-pc-cygwin"...(no debugging symbols found)...
> (gdb) break main
> No symbol table is loaded. Use the "file" command.
> (gdb) #
> (gdb) # Run the program to get all DLLs loaded. The new code
> (gdb) # extracts the exported symbols from the DLLs
> (gdb) #
> (gdb) run
> Starting program: /cygdrive/f/Users/Raoul/gdb/dllegmain.exe
>
> Program exited normally.
> (gdb) #
> (gdb) # Can now set a breakpoint and restart the program.
> (gdb) # Use *& to bypass entry point determination (see
> (gdb) # also Pascal Obry's i386-tdep.c patch for gdb
> (gdb) # problem report 780)
> (gdb) #
> (gdb) break *&fn
> Breakpoint 1 at 0x10001000
> (gdb) run
> Starting program: /cygdrive/f/Users/Raoul/gdb/dllegmain.exe
>
> Breakpoint 1, 0x10001000 in fn () from /cygdrive/f/Users/Raoul/gdb/dlleg.dll
> (gdb) #
> (gdb) # Hit the breakpoint! Without the patch, gdb doesn't
> (gdb) # report any of symbolic names in the following
> (gdb) # stack trace:
> (gdb) #
> (gdb) where
> #0 0x10001000 in fn () from /cygdrive/f/Users/Raoul/gdb/dlleg.dll
> #1 0x61003f42 in cygwin1!__assert ()
> #2 0x61004236 in dll_crt0@0 ()
> #3 0x61004275 in dll_crt0 ()
> #4 0x004010bf in ?? ()
> #5 0x0040103d in ?? ()
> #6 0x77e992a6 in KERNEL32!GetCommandLineW ()
> (gdb) #
> (gdb) # Accessing data can be a bit tricky because there is
> (gdb) # no type information
> (gdb) #
> (gdb) print init_data
> $1 = 42
> (gdb) print (char *)&hello
> $2 = 0x10002000 "Hello world"
> (gdb) x/s &hello
> 0x10002000 <hello>: "Hello world"
> (gdb) x/x &init_data
> 0x1000200c <init_data>: 0x0000002a
> (gdb) x/x &uninit_data
> 0x100030fc <uninit_data>: 0x00000000
> (gdb) #
> (gdb) # Qualified names usually need quotes to work properly.
> (gdb) # These may be useful sometimes to resolve name clashes
> (gdb) # or when listing all symbols from a DLL.
> (gdb) #
> (gdb) x/x &'dlleg!init_data'
> 0x1000200c <init_data>: 0x0000002a
> (gdb) info variables dlleg!
> All variables matching regular expression "dlleg!":
>
> Non-debugging symbols:
> 0x10002000 dlleg!hello
> 0x1000200c dlleg!init_data
> 0x100030fc dlleg!uninit_data
> (gdb) info functions dlleg!
> All functions matching regular expression "dlleg!":
>
> Non-debugging symbols:
> 0x10001000 dlleg!fn
> (gdb) #
> (gdb) # Problem here is that symbol-file reloads the *same* symbols
> (gdb) # and creates duplicate minimal symbol entries
> (gdb) #
> (gdb) symbol-file dlleg.dll
> Reading symbols from dlleg.dll...Minimal symbols from dlleg.dll...
> (no debugging symbols found)...done.
> (gdb) info functions KERNEL32.*
> All functions matching regular expression "KERNEL32.*":
>
> Non-debugging symbols:
> 0x77e815f6 KERNEL32!IsDebuggerPresent
> 0x77e81604 KERNEL32!OutputDebugStringW
> 0x77e8166e KERNEL32!WriteProfileSectionA
> 0x77e81680 KERNEL32!GetProfileSectionW
> 0x77e81696 KERNEL32!WritePrivateProfileSectionA
> 0x77e816bf KERNEL32!GetPrivateProfileSectionW
>
> [etc....]
next prev parent reply other threads:[~2003-01-04 0:53 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-03 19:41 Raoul Gough
2003-01-04 0:53 ` Michael Snyder [this message]
2003-01-04 4:43 ` Christopher Faylor
2003-01-04 16:31 ` Raoul Gough
2003-01-04 17:54 ` Eli Zaretskii
2003-01-04 20:51 ` Christopher Faylor
2003-01-05 14:44 ` Mark Kettenis
2003-01-05 17:18 ` Christopher Faylor
2003-01-05 17:40 ` Daniel Jacobowitz
2003-01-07 1:03 ` Raoul Gough
2003-01-07 1:12 ` Daniel Jacobowitz
2003-01-07 13:11 ` Raoul Gough
2003-01-07 16:46 ` Christopher Faylor
2003-01-07 2:28 ` Michael Snyder
2003-01-07 2:24 ` Michael Snyder
2003-01-04 11:03 ` Eli Zaretskii
2003-01-04 16:21 ` Raoul Gough
2003-01-06 17:10 ` Elena Zannoni
2003-01-06 17:41 ` Christopher Faylor
2003-01-07 0:46 ` Raoul Gough
2003-01-07 1:53 ` Elena Zannoni
2003-01-10 22:45 ` Raoul Gough
2003-01-07 1:00 ` Andrew Cagney
2003-01-10 22:37 ` Raoul Gough
2003-01-04 16:42 Michael Elizabeth Chastain
2003-01-05 15:40 ` Andrew Cagney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3E16307E.313CD01@redhat.com \
--to=msnyder@redhat.com \
--cc=RaoulGough@yahoo.co.uk \
--cc=gdb-patches@sources.redhat.com \
--cc=phdm@macqel.be \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox