Home > Enterprise >  How to debug a dll using Visual Studio?
How to debug a dll using Visual Studio?

Time:08-15

How i could debug a dll using visual studio? I have the DLL source, pdb, etc.

I tried these options:

enter image description here

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:

  1. Put a breakpoint after your LoadLibrary call.

  2. Go to Debug->Windows->Modules in the menu bar to bring up the Modules window.

  3. Search for your dll file in the list. In the Symbol Status column it should read "Cannot find or open the PDB file".

  4. Right click the dll and choose Load Symbols from the context menu.

  5. Point it to the correct pdb file.

  6. The Symbol Status should now change to "Symbols Loaded".

You should now be able to step into functions from the dll and put breakpoints.

  • Related