-1
我已經創建了控制檯應用程序,我從中調用了Win32項目,並引發了訪問衝突異常。我在SetUnhandledExceptionFilter
附加了我的自定義過濾器。當我使用!clrstack
命令時,它顯示非託管調用堆棧,但MSDN表示Clrstack僅提供託管代碼的堆棧跟蹤。!ClrStack顯示非託管調用堆棧
https://msdn.microsoft.com/en-us/library/bb190764(v=vs.110).aspx
請幫助。
的Program.cs
public void ExceptionMethod()
{
ExceptionCreator.CreateAccessViolationException();
}
Win32項目:
ErrorReportWritter.h
#pragma once
#include "stdafx.h"
#include "DbgHelp.h"
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Text;
public ref class ErrorReportWritter
{
public:
static void InstallHandler();
};
ErrorReportWritter.cpp
LONG WINAPI MyExceptionFilter(__in struct _EXCEPTION_POINTERS *ExceptionInfo)
{
//For test purpose, Dump location will be the solution location itself
HANDLE hFile = CreateFileA("Test.dmp", GENERIC_READ | GENERIC_WRITE,
0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
{
// Create the maxidump
MINIDUMP_TYPE mdt = (MINIDUMP_TYPE)(MiniDumpWithFullMemory |
MiniDumpWithFullMemoryInfo |
MiniDumpWithHandleData |
MiniDumpWithThreadInfo |
MiniDumpWithUnloadedModules);
//MINIDUMP_TYPE mdt = MiniDumpNormal;
MINIDUMP_EXCEPTION_INFORMATION mei;
mei.ThreadId = GetCurrentThreadId();
mei.ClientPointers = FALSE;
mei.ExceptionPointers = ExceptionInfo;
BOOL rv = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, mdt, &mei, 0, 0);
//TODO: put a check for failure return value and throw exception in that case
// Close the file
CloseHandle(hFile);
}
//TODO: Still need to decide if the search next functionality is needed for final solution
if (oldFilter == NULL)
{
return EXCEPTION_CONTINUE_SEARCH;
}
LONG ret = oldFilter(ExceptionInfo);
return ret;
}
void ErrorReportWritter::InstallHandler()
{
//Returns the address of the previous exception filter established with the function.
//A NULL return value means that there is no current top-level exception handler.
oldFilter = SetUnhandledExceptionFilter(MyExceptionFilter);
}
調用堆棧的截圖附在此鏈接http://i.stack.imgur.com/ghUYs.png –
你的非託管崩潰究竟在哪裏?您的Cpp項目也是託管代碼。 – nvoigt
ExceptionCreator.cpp 的#include 「ExceptionCreator.h」 的#pragma評論(LIB, 「dbghelp.lib」)使用命名空間系統 ; 使用命名空間System :: Runtime :: InteropServices; 使用命名空間System :: Text; void ExceptionCreator :: CreateAccessViolationException() { \t Marshal :: StructureToPtr(42,IntPtr(42),true); } –