How i could debug a dll using visual studio? I have the DLL source, pdb, etc.
I tried these options:
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
void DebugBreak();
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
//...
}
break;
case DLL_PROCESS_DETACH:
{
//...
}
break;
}
);
return TRUE;
}
It launches the exe but doesn't inject the DLL, by default this exe didn't load the DLL, im manually injecting it.
Is possible to visual studio attach the DLL? and be able to put breakpoints on it, view call stack on a crash, etc?
CodePudding user response:
The quickest way to fix this is via the Modules Window in the Debugger:
Put a breakpoint after your
LoadLibrary
call.Go to Debug->Windows->Modules in the menu bar to bring up the Modules window.
Search for your dll file in the list. In the Symbol Status column it should read "Cannot find or open the PDB file".
Right click the dll and choose Load Symbols from the context menu.
Point it to the correct pdb file.
The Symbol Status should now change to "Symbols Loaded".
You should now be able to step into functions from the dll and put breakpoints.