Previous: Program and DLL Both Built with GCC/GNAT, Up: Debugging a DLL [Contents][Index]
In this case things are slightly more complex because it is not possible to
start the main program and then break at the beginning to load the DLL and the
associated DLL debugging information. It is not possible to break at the
beginning of the program because there is no GDB
debugging information,
and therefore there is no direct way of getting initial control. This
section addresses this issue by describing some methods that can be used
to break somewhere in the DLL to debug it.
First suppose that the main procedure is named main
(this is for
example some C code built with Microsoft Visual C) and that there is 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
option).
$ 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 given 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 will run the program until it reaches the breakpoint that has been set. From that point you can use the standard way to debug a program as described in (Running and Debugging Ada Programs).
It is also possible to debug the DLL by attaching to a running process.
With GDB
it is always possible to debug a running process by
attaching to it. It is 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. It may be useful for instance to insert a time wasting
loop in the code of the DLL to meet this criterion.
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 the standard approach to debug a program as described in Running and Debugging Ada Programs.
Previous: Program and DLL Both Built with GCC/GNAT, Up: Debugging a DLL [Contents][Index]