Search code examples
debuggingvisual-c++dllvisual-studio-debugging

DebugBreak in a DLL under another DLL


I can [very usefully] debug my DLL by placing a DebugBreak(), and then attaching to my Visual Studio session. However, that DLL does a LoadLibrary() to dynamically load another DLL. The DLL runs as expected, however I can't seem to set a breakpoint properly.

When I place a DebugBreak() in that second DLL and then attach to it using that project, my VS session always jumps to some point within the Visual C++ library that supports process management, after the function seems to already have finished executing:

(crt0dat.c)

void __cdecl __crtExitProcess ( int status ) { __crtCorExitProcess(status);

    /*
     * Either mscoree.dll isn't loaded,
     * or CorExitProcess isn't exported from mscoree.dll,
     * or CorExitProcess returned (should never happen).
     * Just call ExitProcess.
     */

    ExitProcess(status);

}

What could be happening?


Solution

  • At some point, things started working. It turns out that the second DLL had to be debugged within the session for the first DLL, and this started happening automatically after not working for an extended period of time. All that's required is that the second DLL has a DebugBreak() in it.

    I know that I did a "break all" at one point (as part of some other left-field solution), cleaned a bunch of times, and restarted my Visual Studio sessions multiple times. I don't have an explanation, other than to suggest that you always have a DebugBreak in the first DLL before the LoadLibrary(), and another one at the top of the second DLL. Omitting the DebugBreak() in the first DLL might sabotage the DebugBreak() in the second.