简体   繁体   中英

How to debug a dll using Visual Studio?

How can I 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM