我的可执行文件无法在Windows中启动。如何调试失败的DLL加载?

时间:2019-02-13 15:55:13

标签: c++ windbg mingw-w64

上周我一直在尝试将我的linux代码编译为Windows env,在编译完我的所有代码之后,由于无法自行加载dll,因此无法启动我的可执行文件。

我的项目由1个名为(pcie_logger)的可执行文件和1个dll(libpci_test.dll)组成,这些可执行文件链接到Windows中的几个静态库,该dll仅在启动时才动态加载。

PcieLogger.cpp:

int
main(int argc, char* argv[])
{
LIB_TRACK2(__PRETTY_FUNCTION__);
PcieLogger tool;
printf("Hello World\n");
return PciTest::main(tool, argc, argv);
}

PcieLogger.h:

#include "PciTest.h"

class PcieLogger: public PciTool {
public:
PcieLogger(): PciTool(){}
virtual ~PcieLogger() = default;
virtual u_int32_t   AddParserParams() override;
u_int32_t           Run() override;
};

PciTest.cpp:

 #ifdef _WIN32
BOOL APIENTRY DllMain( HANDLE hModule,
                   DWORD ul_reason_for_call,
                   LPVOID lpReserved
                   )
 {
printf("PciTest::DllMain\n");
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
    break;

case DLL_PROCESS_DETACH:
    // DisconnectFromDriver();
    break;

case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
    break;
}
return TRUE;
}

#endif


int PciTest::main(PciTest& test, int argc, char* argv[]) {
    printf("PciTest::main\n");
    testInstance = &test;
    int status = 0;
try {
    status = status || test.AddParserParams();
    status = status || test.ParseArgs(argc, argv);
    status = status || test.InitResources(argv[0]);
    status = status || test.Run();
} catch (exception& e) {
    test.mainExceptionTagsHandle(e.what());
    status = 1;
}
test.handleTestFinish(status);
return status;
}

当我尝试在可执行文件上运行windbg时,我得到以下信息:

(558.20fc): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for 
z:\compiled\libpci_test.dll - 
libpci_test!ZN7PciTest4mainERS_iPPc+0x3c53b:
00000000`00f6592b 64488b042500000000 mov   rax,qword ptr fs:[0] 
fs:00000000`00000000=????????????????
0:000> 

0 个答案:

没有答案