diff options
author | waylonis <waylonis@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2006-12-20 17:41:55 +0000 |
---|---|---|
committer | waylonis <waylonis@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2006-12-20 17:41:55 +0000 |
commit | 5ac2b9a569890f165478f91670dcdd553ce2d10e (patch) | |
tree | 78eda7292ac174ad1c0b53ac179f707391708c0b /src/client/mac/handler/minidump_generator.h | |
parent | Fix UTF32ToUTF16Char() conversion. Fixes issue #99. Reviewed by bryner. (diff) | |
download | breakpad-5ac2b9a569890f165478f91670dcdd553ce2d10e.tar.xz |
Add Mac exception handler and generator. Fixes issue #69. Reviewed by mmentovai.
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@98 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/client/mac/handler/minidump_generator.h')
-rw-r--r-- | src/client/mac/handler/minidump_generator.h | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/src/client/mac/handler/minidump_generator.h b/src/client/mac/handler/minidump_generator.h new file mode 100644 index 00000000..53c76041 --- /dev/null +++ b/src/client/mac/handler/minidump_generator.h @@ -0,0 +1,122 @@ +// Copyright (c) 2006, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// minidump_generator.h: Create a minidump of the current MacOS process. + +#ifndef CLIENT_MAC_GENERATOR_MINIDUMP_GENERATOR_H__ +#define CLIENT_MAC_GENERATOR_MINIDUMP_GENERATOR_H__ + +#include <mach/mach.h> + +#include <string> + +#include "client/minidump_file_writer.h" +#include "google_airbag/common/minidump_format.h" + +namespace google_airbag { + +using std::string; + +// Creates a minidump file of the current process. If there is exception data, +// use SetExceptionInformation() to add this to the minidump. The minidump +// file is generated by the Write() function. +// Usage: +// MinidumpGenerator minidump(); +// minidump.Write("/tmp/minidump"); +// +class MinidumpGenerator { + public: + MinidumpGenerator(); + ~MinidumpGenerator(); + + // Return <dir>/<unique_name>.dmp + // Sets |unique_name| (if requested) to the unique name for the minidump + static string UniqueNameInDirectory(const string &dir, string *unique_name); + + // Write out the minidump into |path| + // All of the components of |path| must exist and be writable + // Return true if successful, false otherwise + bool Write(const char *path); + + // Specify some exception information, if applicable + void SetExceptionInformation(int type, int code, mach_port_t thread_name) { + exception_type_ = type; + exception_code_ = code; + exception_thread_ = thread_name; + } + + // Gather system information. This should be call at least once before using + // the MinidumpGenerator class. + static void GatherSystemInformation(); + + private: + typedef bool (MinidumpGenerator::*WriteStreamFN)(MDRawDirectory *); + + // Stream writers + bool WriteThreadListStream(MDRawDirectory *thread_list_stream); + bool WriteExceptionStream(MDRawDirectory *exception_stream); + bool WriteSystemInfoStream(MDRawDirectory *system_info_stream); + bool WriteModuleListStream(MDRawDirectory *module_list_stream); + bool WriteMiscInfoStream(MDRawDirectory *misc_info_stream); + bool WriteAirbagInfoStream(MDRawDirectory *airbag_info_stream); + + // Helpers + u_int64_t CurrentPCForStack(thread_state_data_t state); + bool WriteStackFromStartAddress(vm_address_t start_addr, + MDMemoryDescriptor *stack_location); + bool WriteStack(thread_state_data_t state, + MDMemoryDescriptor *stack_location); + bool WriteContext(thread_state_data_t state, + MDLocationDescriptor *register_location); + bool WriteThreadStream(mach_port_t thread_id, MDRawThread *thread); + bool WriteCVRecord(MDRawModule *module, const char *module_path); + bool WriteModuleStream(unsigned int index, MDRawModule *module); + + // disallow copy ctor and operator= + explicit MinidumpGenerator(const MinidumpGenerator &); + void operator=(const MinidumpGenerator &); + + // Use this writer to put the data to disk + MinidumpFileWriter writer_; + + // Exception information + int exception_type_; + int exception_code_; + mach_port_t exception_thread_; + + // System information + static char build_string_[16]; + static int os_major_version_; + static int os_minor_version_; + static int os_build_number_; +}; + +} // namespace google_airbag + +#endif // CLIENT_MAC_GENERATOR_MINIDUMP_GENERATOR_H__ |