問題描述
如何在加載任何鏈接的 DLL 之前停止程序?
我嘗試在 Break At Function
調(diào)試選項(xiàng)中設(shè)置 LoadLibraryExW
函數(shù),它在該函數(shù)處停止,但在此之前,我在 Visual Studio 輸出中有以下內(nèi)容窗戶:
那么如何在加載 ntdll.dll
之前停止調(diào)試器中的程序?好的,不是在加載之前,而是在執(zhí)行任何 DllMain
函數(shù)之前和初始化任何靜態(tài)對象之前.
您可以通過將注冊表項(xiàng)添加到圖像文件執(zhí)行選項(xiàng)"并使用您的 exe 名稱來實(shí)現(xiàn).添加名為Debugger"的字符串類型值并將其設(shè)置為 vsjitdebugger.exe 以啟動(dòng)即時(shí)調(diào)試器對話框.然后,您可以選擇一種可用的調(diào)試器,包括 Visual Studio.此對話框在 Windows 加載 EXE 之后,在任何代碼開始運(yùn)行之前立即觸發(fā).
這是在您啟動(dòng) notepad.exe 時(shí)觸發(fā)對話框的示例 .reg 文件.將密鑰名稱修改為您的 .exe:
REGEDIT4[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options
otepad.exe]"調(diào)試器"="vsjitdebugger.exe"
How can I stop the program before loading any of the linked DLLs?
I've tried to set LoadLibraryExW
function in the Break At Function
debugging option and it stops at that function, but before that I have the following in Visual Studio output windows:
'test.exe': Loaded 'C:WindowsSystem32 tdll.dll', Symbols loaded (source information stripped). 'test.exe': Loaded 'C:WindowsSystem32kernel32.dll', Symbols loaded (source information stripped). 'test.exe': Loaded 'C:WindowsSystem32KernelBase.dll', Symbols loaded (source information stripped). 'test.exe': Loaded 'C:WindowsSystem32uxtheme.dll', Symbols loaded (source information stripped). 'test.exe': Loaded 'C:WindowsSystem32msvcrt.dll', Symbols loaded (source information stripped). ---- plus about 30 DLLs ---
So how can I stop the program in the debugger before loading the ntdll.dll
? Ok, not before loading, but before executing any of DllMain
functions and before initializing any of static objects.
You can do this by adding a registry key to "Image File Execution Options" with the name of your exe. Add a value of type string named "Debugger" and set it to vsjitdebugger.exe to launch the just-in-time debugger dialog. Which then lets you pick one of the available debuggers, including Visual Studio. This dialog is triggered right after Windows has loaded the EXE, before any code starts running.
Here's is a sample .reg file that triggers the dialog when you start notepad.exe. Modify the key name to your .exe:
REGEDIT4
[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options
otepad.exe]
"Debugger"="vsjitdebugger.exe"
這篇關(guān)于如何在程序執(zhí)行的最開始設(shè)置斷點(diǎn)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!