From 144938cf22243407a56601bd5b75147f796a8424 Mon Sep 17 00:00:00 2001 From: "ted.mielczarek@gmail.com" Date: Fri, 13 Aug 2010 20:19:32 +0000 Subject: Allow dumping live processes on OS X R=mark at http://breakpad.appspot.com/148001/show git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@647 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/client/mac/handler/exception_handler.cc | 32 ++++++++++++++++++++++++++++ src/client/mac/handler/exception_handler.h | 8 +++++++ src/client/mac/handler/minidump_generator.cc | 5 ++++- 3 files changed, 44 insertions(+), 1 deletion(-) (limited to 'src/client/mac/handler') diff --git a/src/client/mac/handler/exception_handler.cc b/src/client/mac/handler/exception_handler.cc index ccf1ff99..89cc4e90 100644 --- a/src/client/mac/handler/exception_handler.cc +++ b/src/client/mac/handler/exception_handler.cc @@ -33,6 +33,7 @@ #include "client/mac/handler/exception_handler.h" #include "client/mac/handler/minidump_generator.h" #include "common/mac/macho_utilities.h" +#include "common/mac/scoped_task_suspend-inl.h" #ifndef USE_PROTECTED_ALLOCATIONS #define USE_PROTECTED_ALLOCATIONS 0 @@ -301,6 +302,37 @@ bool ExceptionHandler::WriteMinidump(const string &dump_path, return handler.WriteMinidump(); } +// static +bool ExceptionHandler::WriteMinidumpForChild(mach_port_t child, + mach_port_t child_blamed_thread, + const string &dump_path, + MinidumpCallback callback, + void *callback_context) { + ScopedTaskSuspend suspend(child); + + MinidumpGenerator generator(child, MACH_PORT_NULL); + string dump_id; + string dump_filename = generator.UniqueNameInDirectory(dump_path, &dump_id); + + generator.SetExceptionInformation(EXC_BREAKPOINT, +#if defined (__i386__) || defined(__x86_64__) + EXC_I386_BPT, +#elif defined (__ppc__) || defined (__ppc64__) + EXC_PPC_BREAKPOINT, +#else + #error architecture not supported +#endif + 0, + child_blamed_thread); + bool result = generator.Write(dump_filename.c_str()); + + if (callback) { + return callback(dump_path.c_str(), dump_id.c_str(), + callback_context, result); + } + return result; +} + bool ExceptionHandler::WriteMinidumpWithException(int exception_type, int exception_code, int exception_subcode, diff --git a/src/client/mac/handler/exception_handler.h b/src/client/mac/handler/exception_handler.h index ee3e2e1d..76353255 100644 --- a/src/client/mac/handler/exception_handler.h +++ b/src/client/mac/handler/exception_handler.h @@ -121,6 +121,14 @@ class ExceptionHandler { static bool WriteMinidump(const string &dump_path, MinidumpCallback callback, void *callback_context); + // Write a minidump of child immediately. This can be used to capture + // the execution state of a child process independently of a crash. + static bool WriteMinidumpForChild(mach_port_t child, + mach_port_t child_blamed_thread, + const std::string &dump_path, + MinidumpCallback callback, + void *callback_context); + // Returns whether out-of-process dump generation is used or not. bool IsOutOfProcess() const { return crash_generation_client_.get() != NULL; diff --git a/src/client/mac/handler/minidump_generator.cc b/src/client/mac/handler/minidump_generator.cc index c5886be0..0c54cf42 100644 --- a/src/client/mac/handler/minidump_generator.cc +++ b/src/client/mac/handler/minidump_generator.cc @@ -536,7 +536,10 @@ bool MinidumpGenerator::WriteThreadListStream( return false; // Don't include the generator thread - non_generator_thread_count = thread_count - 1; + if (handler_thread_ != MACH_PORT_NULL) + non_generator_thread_count = thread_count - 1; + else + non_generator_thread_count = thread_count; if (!list.AllocateObjectAndArray(non_generator_thread_count, sizeof(MDRawThread))) return false; -- cgit v1.2.1