!ClrStack显示非托管调用堆栈
问题描述:
我已经创建了控制台应用程序,我从中调用了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);
}
答
您的代码是管理 C++。 (或者C++/CLI或者你的Visual Studio版本支持的任何东西)。
要创建非托管 Win32的项目,例如在Visual Studio 2015年,得到了File
- >New Project
,然后选择Templates
- >Visual C++
- >Win32 Project
。
调用堆栈的截图附在此链接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); } –