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.

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

Continue the program.

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

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.

Launch the main program main.exe.

$ main

Use the Windows `Task Manager' to find the process ID. Let's say
that the process PID for main.exe is 208.

Launch gdb.

$ gdb

Attach to the running process to be debugged.

(gdb) attach 208

Load the process debugging information.

(gdb) symbol-file main.exe

Break somewhere in the DLL.

(gdb) break ada_dll

Continue process execution.

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