7.4.8.27 Program Built with Foreign Tools and DLL Built with GCC/GNAT

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

Debugging the DLL Directly

You can also debug the DLL by attaching GDB to a running process.

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

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.