In this case, things are slightly more complex because you can’t
start the main program and then break at the beginning to load the DLL and the
associated DLL debugging information. It’s not possible to break at the
beginning of the program because there’s no GDB
debugging information,
and therefore there’s no direct way of getting initial control. This
section addresses this issue by describing some methods that you can use
to break somewhere in the DLL to debug it.
First, suppose that the main procedure is named main
(this is the
case, for example, for some C code built with Microsoft Visual C) and that
there’s a DLL named test.dll
containing an Ada entry point named
ada_dll
.
The DLL (see Introduction to Dynamic Link Libraries (DLLs)) must have
been built with debugging information (see the GNAT -g
switch).
$ objdump --file-header main.exe
The starting address is reported on the last line. For example:
main.exe: file format pei-i386 architecture: i386, flags 0x0000010a: EXEC_P, HAS_DEBUG, D_PAGED start address 0x00401010
$ gdb main.exe
$ (gdb) break *0x00401010 $ (gdb) run
The program will stop at the specified address.
(gdb) break ada_dll.adb:45
Or if you want to break using a symbol on the DLL, you need first to select the Ada language (language used by the DLL).
(gdb) set language ada (gdb) break ada_dll
(gdb) cont
This runs the program until it reaches the breakpoint that you’ve
set. From that point, you can use standard GDB
commands to debug
a program as described in
(Running and Debugging Ada Programs).
You can also debug the DLL by attaching GDB
to a running process.
With GDB
, you can always debug a running process by attaching to
it. It’s possible to debug a DLL this way. The limitation of this
approach is that the DLL must run long enough to perform the attach
operation. To ensure this, you may want, for example, to insert a
time-wasting loop in the code of the DLL to allow this to happen.
main.exe
.
$ main
main.exe
is 208.
$ gdb
(gdb) attach 208
(gdb) symbol-file main.exe
(gdb) break ada_dll
(gdb) cont
This last step will resume the process execution and stop at
the breakpoint we have set. From there you can use standard
GDB
commands to debug a program, as described in
Running and Debugging Ada Programs.