我已經創建了我自己的調試器應用程序。它附加到一個進程並創建一個崩潰轉儲文件。這在大多數情況下都是有效的。我遇到的問題是,當正在調試的應用程序正在等待互斥對象時(這是我想要調試的問題),它將無法正常工作。爲什麼MiniDumpWriteDump失敗?
此外,我創建了一個簡單的test.exe應用程序,它只是循環並調用Sleep(100),但我的調試器在每次調用此應用程序的MiniDumpWriteDump時失敗。
我在做什麼錯?
錯誤代碼我從下面的代碼返回爲2147942699(0x8007012b)
void WriteCrashDump(EXCEPTION_DEBUG_INFO *pExceptionInfo)
{
CONTEXT c;
memset(&c, 0, sizeof(c));
GetThreadContext(hThread, &c);
EXCEPTION_POINTERS ep;
memset(&ep, 0, sizeof(ep));
ep.ContextRecord = &c;
ep.ExceptionRecord = &pExceptionInfo->ExceptionRecord;
MINIDUMP_EXCEPTION_INFORMATION minidump_exception;
memset(&minidump_exception, 0, sizeof(minidump_exception));
minidump_exception .ThreadId = dwThreadId;
minidump_exception.ExceptionPointers = &ep;
minidump_exception.ClientPointers = true;
char txDumpPath[ MAX_PATH + 1 ];
sprintf(txDumpPath, "%s.dmp", txProcess);
HANDLE hFile = CreateFile(txDumpPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile)
{
BOOL fSuccess;
SetLastError(0L);
int nDumpOptions =
MiniDumpNormal
| MiniDumpWithDataSegs
| MiniDumpWithFullMemory
| MiniDumpWithHandleData
| MiniDumpFilterMemory
| MiniDumpScanMemory
| MiniDumpWithUnloadedModules
| MiniDumpWithIndirectlyReferencedMemory
| MiniDumpFilterModulePaths
| MiniDumpWithProcessThreadData
| MiniDumpWithPrivateReadWriteMemory
| MiniDumpWithoutOptionalData
;
fSuccess = MiniDumpWriteDump(hProcess,
dwProcessId,
hFile,
(MINIDUMP_TYPE) nDumpOptions,
&minidump_exception,
NULL,
NULL);
DWORD dwErr = GetLastError();
if(! fSuccess)
printf("MiniDumpWriteDump -FAILED (LastError:%u)\n", dwErr);
CloseHandle(hFile);
}
}
我也曾嘗試用下面的代碼片段是我從別人借了誰似乎也有類似的增加特權問題:
BOOL SetDumpPrivileges()
{
BOOL fSuccess = FALSE;
HANDLE TokenHandle = NULL;
TOKEN_PRIVILEGES TokenPrivileges;
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
&TokenHandle))
{
printf("Could not get the process token");
goto Cleanup;
}
TokenPrivileges.PrivilegeCount = 1;
if (!LookupPrivilegeValue(NULL,
SE_DEBUG_NAME,
&TokenPrivileges.Privileges[0].Luid))
{
printf("Couldn't lookup SeDebugPrivilege name");
goto Cleanup;
}
TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
//Add privileges here.
if (!AdjustTokenPrivileges(TokenHandle,
FALSE,
&TokenPrivileges,
sizeof(TokenPrivileges),
NULL,
NULL))
{
printf("Could not revoke the debug privilege");
goto Cleanup;
}
fSuccess = TRUE;
Cleanup:
if (TokenHandle)
{
CloseHandle(TokenHandle);
}
return fSuccess;
}
嗨,上面的東西不適合我。事情是我有我的MiniDump寫從一個單獨的過程。你是一個進程崩潰處理程序嗎?或正在進行中?你能澄清一下嗎? – 2013-06-11 16:06:52