2016-08-24 4 views
-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); 
} 

enter image description here

+0

호출 스택의 스크린 샷이 링크에 있습니다. http://i.stack.imgur.com/ghUYs.png –

+1

관리되지 않는 충돌은 어디에서 정확히 발생합니까? Cpp 프로젝트도 관리되는 코드입니다. – nvoigt

+0

ExceptionCreator.cpp 사용법 #include "ExceptionCreator.h" #pragma 주석 (lib, "dbghelp.lib") 네임 스페이스 시스템을 사용하여 ; 네임 스페이스 사용 System :: Runtime :: InteropServices; using namespace System :: Text; void ExceptionCreator :: CreateAccessViolationException ( ) { \t Marshal :: StructureToPtr (42, IntPtr (42), true); } –

답변

0

코드는 C++입니다. (또는 C++/CLI 또는 Visual Studio 버전이 지원하는 모든 것). >New Project 다음 Templates 선택 - ->Visual C++ ->Win32 Project

비주얼 스튜디오 2015 년 예를 들어, File에 도착, 관리되지 않는에서 Win32 프로젝트를 만듭니다.

관련 문제