This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: coffread.c extension for DLLs without debugging symbols


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....]


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]