2

I'm writing an out of process minidump for a child process. Here is the relevant code snippet:

CONTEXT thread_context{};
thread_context.ContextFlags = CONTEXT_FULL;
assert(GetThreadContext(child_thread_handle, &thread_context));

EXCEPTION_POINTERS exception_ptrs;
exception_ptrs.ExceptionRecord = &exception_info.ExceptionRecord;
exception_ptrs.ContextRecord = &thread_context;

MINIDUMP_EXCEPTION_INFORMATION minidump_exception_info;
minidump_exception_info.ThreadId = evt.dwThreadId;
minidump_exception_info.ExceptionPointers = &exception_ptrs;
minidump_exception_info.ClientPointers = FALSE;
auto success = MiniDumpWriteDump(child_handle, evt.dwProcessId, file_handle, minidump_flags, &minidump_exception_info, nullptr, nullptr);

This gives me the exception information, and the call stack for every thread except the thread that raised the exception. If I change &minidump_exception_info to nullptr, I get the call stack but no exception information. Is there a way to get both the exception information and the call stack?

Marc Aldorasi
  • 698
  • 7
  • 13
  • 1
    That's a very buggy assert() call. You should not be doing this at all, the EXCEPTION_POINTERS need to be generated by the crashing process. Read [this post](http://stackoverflow.com/a/13591900/17034) for hints. – Hans Passant Jun 29 '15 at 16:16

1 Answers1

1

Calling GetThreadContext with CONTEXT_FULL does not capture all the registers needed to get the stack trace, and the existence of the context prevents the debugger from using other information to get the call stack. Using CONTEXT_ALL instead gets enough information to recreate the call stack.

https://msdn.microsoft.com/en-us/magazine/hh580738.aspx was a helpful reference in figuring this out.

Marc Aldorasi
  • 698
  • 7
  • 13