Home > Net >  How can I debug a C dynamic library?
How can I debug a C dynamic library?

Time:08-21

How can I debug the dynamic library conveniently and quickly in Visual Studio 2022?

If Xenos injection is used, nothing is output (random process).

If it passes through the attached process, it does not enter any breakpoint (random process).

#include "pch.h"

#include <iostream>

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {

        std::system("ls>1.txt");
    case DLL_PROCESS_ATTACH:
        OutputDebugString(TEXT("INterdll"));
        break;
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

CodePudding user response:

In Visual Studio 2022 you can debug your own library by attaching to the application which uses your library. When I usually develop C libraries, I create a separate project which called <MyLibrary>Tests and connect Enter image description here

When you press it, you'll be able to find your application which is using your library currently.

And, as I understand on my last work place, the best way to debug your library is make your small GUI application with some buttons for testing. It's pretty enough to make a simple Python app to check it.

CodePudding user response:

From Specify symbol (.pdb) and source files in the Visual Studio debugger (C#, C , Visual Basic, F#), the quickest way to fix this is via the Modules Window in the Debugger:

  1. Put a breakpoint after your call.LoadLibrary

  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 add breakpoints.

  • Related