Search code examples
c++debuggingc++builderrad-studio

How to debug an external process under C++ Builder?


I have a DLL that is written in C++ Builder. The DLL is built with "debug info" on.
I cannot run and debug this DLL from the IDE because it is loaded dynamically as a plugin in another process (main exe). My DLL needs to be copied into the main exe's folder first.

So, I attached the IDE to that process but I don't know what to do from here.

I know that if I click a button in the main process to load and use my DLL an AV is raised and a custom message is shown with some minor into about the error. The debugger won't step in when the AV is raised. Probably the error is caught at a higher level.

It would be nice if I could also attach the source-code of my DLL and put a breakpoint in it.

How do I get more info about that AV (its origins)?
(Basically any hint from those that did this type of debugging would be very helpful).


Solution

  • I have a DLL that is written in C++ Builder. The DLL is built with "debug info" on. I cannot run and debug this DLL from the IDE because it is loaded as a plugin in another process.

    Yes, you can.

    Open the DLL project in the IDE, go into the project's Run parameters and set the desired EXE as the project's Host. This way, when you "run" the DLL project for debugging, the IDE will execute the Host instead and attach the debugger to that process. When the Host process loads your DLL into memory, you can then step through and debug the DLL's code as needed.

    If the Host process is already running before you start your debugging, you can simply Attach the debugger to the Host process manually before it loads your DLL, and then the debugger will still be able to step through the DLL's code once the Host loads the DLL into memory.