How to stop C ++ application at runtime for debugging in dll?

I have an application for which I have no code, and a dll for which I have code. I need to be able to debug a DLL, but I do not have a source for exe, how can I do this?

The dll code is mfc C ++; I believe the main application is the same.

I tried to execute the "install the target application" transaction, where I installed the application from which the dll will be called, and the application is caused by a terrible, terrible death when this method is called. I do not know if the error is related to this dll or to the executable for this behavior, and this is just one of many things that I would like to solve.

I think there must be some kind of call to let the dll rotate endlessly until a debugger joins the process, after which I have to debug the dll by joining the process. Does this make sense? Is there a better way to do this?

+3
source share
11 answers

- DLL , . Windows, , , DLL Windows, , , , - .

+2

DebugBreak . , .

#ifdef DEBUG
if (... file exists...) {
    DebugBreak();
}
#endif

, .

+4

ImageFileExecutionOptions, , DLL. ISAPI. .

+2

DLL- Visual Studio, , . exe. , DLL-, . DLL, COM-.

, , .

: , , , - exe, , , .

+1
__asm int {3};

DLL. ? , , , int3 . - ? .

+1

, :

while(!IsDebuggerPresent())
{
  Sleep(0);  // yield
}

MSDN: IsDebuggerPresent().

+1

, DLL, , . , ​​, Process Explorer ( "" DLL).

" Visual Studio" " " , DLL. , DLL .

+1

: Sleep(10000); DllMain ( - ), Tools / Attach to Process, .

0

, , dll , , dll, . ? ?

, ? , . Visual Studio, Debug. , F9 dll.

0

" " ", DLL , , . , dll , .

Windows NT. , DLL .

NT, _NO_DEBUG_HEAP 1 ( XP ). , .

Running the application outside the debugger will also disable the NT debugging heap, and adding a debugger will not turn it on later.

0
source

Source: https://habr.com/ru/post/1709617/


All Articles