[英]Why VS2017 debugging will not stop at dllmain breakpoint?
我是第一次構建一個 dll,一切都按預期工作,但我無法調試它。
我制作了盡可能少的示例,只有一個 dllmain() 並使用 Windows DLL(非 MFC)向導設置項目。
活動構建配置:x86 調試
右鍵項目 -> 設置為啟動項目
禁用預編譯頭
項目屬性 -> 調試 -> 命令 -> 應用程序可執行文件的輸入路徑
生成調試信息是
這是整個 DLL,沒有其他源文件或頭文件。 當我按 F5 應用程序運行並加載 dll 時,消息框會觸發。 如果 debugbreak 被取消注釋,則消息框不會觸發,DLL 只會成功加載。 調試器不會中斷。 如果使用斷點,它不會中斷。
該應用程序肯定正在加載我正在構建的 DLL。
.pdb 文件在那里並正在生成。
我嘗試將調試器更改為混合、自動、本機,但仍然無法正常工作。 CALLING 應用程序可能是用 C# 編寫的,但它不是我的。
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files
#include <windows.h>
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
// __debugbreak();
MessageBoxA(NULL, "Hit DLLMAIN", "test", MB_OK);
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
我做了很多研究,但我不明白為什么它不會調試。
更新:我編寫了一個程序來調用 DLL 上的 LoadLibrary 並修改了我的項目以將該程序作為命令調用。
它進入調試器就好了。 即使我將加載程序更改為發布配置。
無論問題是什么,它都可能是由第三方程序加載 dll 引起的。
編輯:這是嘗試使用第三方程序調試我的 dll 時的調試控制台輸出,盡管程序繼續運行,但調試器似乎出於某種原因退出。
'Program.exe' (Win32): Loaded 'C:\Users\Tech1\AppData\Local\ProgramDir\Program.exe'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\win32u.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32full.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp_win.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbase.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\Private_API.dll'. Module was built without symbols.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\apphelp.dll'. Cannot find or open the PDB file.
'Program.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. Cannot find or open the PDB file.
The thread 0x4610 has exited with code 0 (0x0).
The thread 0x2614 has exited with code 0 (0x0).
The thread 0x45c0 has exited with code 0 (0x0).
The program '[21792] Program.exe' has exited with code 0 (0x0).
不是一個確定的答案,但我一直在調試本機 DLL,我有一些建議:
1) 如果使用該 DLL 的應用程序仍然有效,並且您知道如何讓它再次嘗試訪問該 DLL,您也可以嘗試“調試->附加到進程”。
2) 確保當您按 F5 進行調試時,您的 DLL 不會自行重新編譯。 我曾經有一個靜態庫依賴項,它導致 DLL 在每次調試時重新編譯。 還有一個移動步驟,可以在編譯時將 DLL 移動到目標應用程序可執行文件夾中。 這導致調試器認為我沒有使用完全相同版本的 DLL。 可能是時間問題。 如果您有移動步驟,則 DLL 版本必須是完全相同的編譯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.