minidump.h.svn-base
来自「SumatraPDF是一款小型开源的pdf阅读工具。虽然玲珑小巧(只有800多K」· SVN-BASE 代码 · 共 885 行 · 第 1/3 页
SVN-BASE
885 行
// 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.h: A minidump reader.//// The basic structure of this module tracks the structure of the minidump// file itself. At the top level, a minidump file is represented by a// Minidump object. Like most other classes in this module, Minidump// provides a Read method that initializes the object with information from// the file. Most of the classes in this file are wrappers around the// "raw" structures found in the minidump file itself, and defined in// minidump_format.h. For example, each thread is represented by a// MinidumpThread object, whose parameters are specified in an MDRawThread// structure. A properly byte-swapped MDRawThread can be obtained from a// MinidumpThread easily by calling its thread() method.//// Most of the module lazily reads only the portion of the minidump file// necessary to fulfill the user's request. Calling Minidump::Read// only reads the minidump's directory. The thread list is not read until// it is needed, and even once it's read, the memory regions for each// thread's stack aren't read until they're needed. This strategy avoids// unnecessary file input, and allocating memory for data in which the user// has no interest. Note that although memory allocations for a typical// minidump file are not particularly large, it is possible for legitimate// minidumps to be sizable. A full-memory minidump, for example, contains// a snapshot of the entire mapped memory space. Even a normal minidump,// with stack memory only, can be large if, for example, the dump was// generated in response to a crash that occurred due to an infinite-// recursion bug that caused the stack's limits to be exceeded. Finally,// some users of this library will unfortunately find themselves in the// position of having to process potentially-hostile minidumps that might// attempt to cause problems by forcing the minidump processor to over-// allocate memory.//// Memory management in this module is based on a strict// you-don't-own-anything policy. The only object owned by the user is// the top-level Minidump object, the creation and destruction of which// must be the user's own responsibility. All other objects obtained// through interaction with this module are ultimately owned by the// Minidump object, and will be freed upon the Minidump object's destruction.// Because memory regions can potentially involve large allocations, a// FreeMemory method is provided by MinidumpMemoryRegion, allowing the user// to release data when it is no longer needed. Use of this method is// optional but recommended. If freed data is later required, it will// be read back in from the minidump file again.//// There is one exception to this memory management policy:// Minidump::ReadString will return a string object to the user, and the user// is responsible for its deletion.//// Author: Mark Mentovai#ifndef GOOGLE_BREAKPAD_PROCESSOR_MINIDUMP_H__#define GOOGLE_BREAKPAD_PROCESSOR_MINIDUMP_H__#include <map>#include <string>#include <vector>#include "google_breakpad/common/minidump_format.h"#include "google_breakpad/processor/code_module.h"#include "google_breakpad/processor/code_modules.h"#include "google_breakpad/processor/memory_region.h"namespace google_breakpad {using std::map;using std::string;using std::vector;class Minidump;template<typename AddressType, typename EntryType> class RangeMap;// MinidumpObject is the base of all Minidump* objects except for Minidump// itself.class MinidumpObject { public: virtual ~MinidumpObject() {} protected: explicit MinidumpObject(Minidump* minidump); // Refers to the Minidump object that is the ultimate parent of this // Some MinidumpObjects are owned by other MinidumpObjects, but at the // root of the ownership tree is always a Minidump. The Minidump object // is kept here for access to its seeking and reading facilities, and // for access to data about the minidump file itself, such as whether // it should be byte-swapped. Minidump* minidump_; // MinidumpObjects are not valid when created. When a subclass populates // its own fields, it can set valid_ to true. Accessors and mutators may // wish to consider or alter the valid_ state as they interact with // objects. bool valid_;};// This class exists primarily to provide a virtual destructor in a base// class common to all objects that might be stored in// Minidump::mStreamObjects. Some object types (MinidumpContext) will// never be stored in Minidump::mStreamObjects, but are represented as// streams and adhere to the same interface, and may be derived from// this class.class MinidumpStream : public MinidumpObject { public: virtual ~MinidumpStream() {} protected: explicit MinidumpStream(Minidump* minidump); private: // Populate (and validate) the MinidumpStream. minidump_ is expected // to be positioned at the beginning of the stream, so that the next // read from the minidump will be at the beginning of the stream. // expected_size should be set to the stream's length as contained in // the MDRawDirectory record or other identifying record. A class // that implements MinidumpStream can compare expected_size to a // known size as an integrity check. virtual bool Read(u_int32_t expected_size) = 0;};// MinidumpContext carries a CPU-specific MDRawContext structure, which// contains CPU context such as register states. Each thread has its// own context, and the exception record, if present, also has its own// context. Note that if the exception record is present, the context it// refers to is probably what the user wants to use for the exception// thread, instead of that thread's own context. The exception thread's// context (as opposed to the exception record's context) will contain// context for the exception handler (which performs minidump generation),// and not the context that caused the exception (which is probably what the// user wants).class MinidumpContext : public MinidumpStream { public: virtual ~MinidumpContext(); // Returns an MD_CONTEXT_* value such as MD_CONTEXT_X86 or MD_CONTEXT_PPC // identifying the CPU type that the context was collected from. The // returned value will identify the CPU only, and will have any other // MD_CONTEXT_* bits masked out. Returns 0 on failure. u_int32_t GetContextCPU() const; // Returns raw CPU-specific context data for the named CPU type. If the // context data does not match the CPU type or does not exist, returns // NULL. const MDRawContextX86* GetContextX86() const; const MDRawContextPPC* GetContextPPC() const; // Print a human-readable representation of the object to stdout. void Print(); private: friend class MinidumpThread; friend class MinidumpException; explicit MinidumpContext(Minidump* minidump); bool Read(u_int32_t expected_size); // Free the CPU-specific context structure. void FreeContext(); // If the minidump contains a SYSTEM_INFO_STREAM, makes sure that the // system info stream gives an appropriate CPU type matching the context // CPU type in context_cpu_type. Returns false if the CPU type does not // match. Returns true if the CPU type matches or if the minidump does // not contain a system info stream. bool CheckAgainstSystemInfo(u_int32_t context_cpu_type); // The CPU-specific context structure. union { MDRawContextBase* base; MDRawContextX86* x86; MDRawContextPPC* ppc; } context_;};// MinidumpMemoryRegion does not wrap any MDRaw structure, and only contains// a reference to an MDMemoryDescriptor. This object is intended to wrap// portions of a minidump file that contain memory dumps. In normal// minidumps, each MinidumpThread owns a MinidumpMemoryRegion corresponding// to the thread's stack memory. MinidumpMemoryList also gives access to// memory regions in its list as MinidumpMemoryRegions. This class// adheres to MemoryRegion so that it may be used as a data provider to// the Stackwalker family of classes.class MinidumpMemoryRegion : public MinidumpObject, public MemoryRegion { public: virtual ~MinidumpMemoryRegion(); static void set_max_bytes(u_int32_t max_bytes) { max_bytes_ = max_bytes; } static u_int32_t max_bytes() { return max_bytes_; } // Returns a pointer to the base of the memory region. Returns the // cached value if available, otherwise, reads the minidump file and // caches the memory region. const u_int8_t* GetMemory(); // The address of the base of the memory region. u_int64_t GetBase(); // The size, in bytes, of the memory region. u_int32_t GetSize(); // Frees the cached memory region, if cached. void FreeMemory(); // Obtains the value of memory at the pointer specified by address. bool GetMemoryAtAddress(u_int64_t address, u_int8_t* value); bool GetMemoryAtAddress(u_int64_t address, u_int16_t* value); bool GetMemoryAtAddress(u_int64_t address, u_int32_t* value); bool GetMemoryAtAddress(u_int64_t address, u_int64_t* value); // Print a human-readable representation of the object to stdout. void Print(); private: friend class MinidumpThread; friend class MinidumpMemoryList; explicit MinidumpMemoryRegion(Minidump* minidump); // Identify the base address and size of the memory region, and the // location it may be found in the minidump file. void SetDescriptor(MDMemoryDescriptor* descriptor); // Implementation for GetMemoryAtAddress template<typename T> bool GetMemoryAtAddressInternal(u_int64_t address, T* value); // The largest memory region that will be read from a minidump. The // default is 1MB. static u_int32_t max_bytes_; // Base address and size of the memory region, and its position in the // minidump file. MDMemoryDescriptor* descriptor_; // Cached memory. vector<u_int8_t>* memory_;};// MinidumpThread contains information about a thread of execution,// including a snapshot of the thread's stack and CPU context. For// the thread that caused an exception, the context carried by// MinidumpException is probably desired instead of the CPU context// provided here.class MinidumpThread : public MinidumpObject { public: virtual ~MinidumpThread(); const MDRawThread* thread() const { return valid_ ? &thread_ : NULL; } MinidumpMemoryRegion* GetMemory(); MinidumpContext* GetContext(); // The thread ID is used to determine if a thread is the exception thread, // so a special getter is provided to retrieve this data from the // MDRawThread structure. Returns false if the thread ID cannot be // determined. bool GetThreadID(u_int32_t *thread_id) const;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?