Previous: Debugging the DLL Directly, Up: Program Built with Foreign Tools and DLL Built with GCC/GNAT

F.13.2.2 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.

  1. Launch the main program main.exe.
              $ main
  2. Use the Windows Task Manager to find the process ID. Let's say that the process PID for main.exe is 208.
  3. Launch gdb.
              $ gdb -nw
  4. Attach to the running process to be debugged.
              (gdb) attach 208
  5. Load the process debugging information.
              (gdb) symbol-file main.exe
  6. Break somewhere in the DLL.
              (gdb) break ada_dll
  7. Continue process execution.
              (gdb) continue

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 (see Running and Debugging Ada Programs).