简体   繁体   English

如何使用 Visual Studio 调试 dll?

[英]How to debug a dll using Visual Studio?

How can I debug a dll using visual studio?如何使用 Visual Studio 调试 dll?

I have the DLL source, pdb, etc.我有 DLL 源、pdb 等。

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.它启动 exe 但不注入 DLL,默认情况下,此 exe 不加载 DLL,我手动注入它。

Is possible to visual studio attach the DLL? Visual Studio 可以附加 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:解决此问题的最快方法是通过调试器中的模块 Window:

  1. Put a breakpoint after your LoadLibrary call.在您的LoadLibrary调用之后放置一个断点。

  2. Go to Debug->Windows->Modules in the menu bar to bring up the Modules window. Go 到菜单栏中的Debug->Windows->Modules以调出 Modules window。

  3. Search for your dll file in the list.在列表中搜索您的 dll 文件。 In the Symbol Status column it should read "Cannot find or open the PDB file".符号状态列中,它应该显示“无法找到或打开 PDB 文件”。

  4. Right click the dll and choose Load Symbols from the context menu.右键单击 dll 并从上下文菜单中选择加载符号

  5. Point it to the correct pdb file.将其指向正确的 pdb 文件。

  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.您现在应该能够从 dll 进入函数并放置断点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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