Previous: Program and DLL Both Built with GCC/GNAT, Up: Debugging a DLL


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

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 GNAT -g option).

Debugging the DLL Directly

It is also possible to debug the DLL by attaching to a running process.

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.

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.