michael@0: // Copyright (c) 2006, Google Inc. michael@0: // All rights reserved. michael@0: // michael@0: // Redistribution and use in source and binary forms, with or without michael@0: // modification, are permitted provided that the following conditions are michael@0: // met: michael@0: // michael@0: // * Redistributions of source code must retain the above copyright michael@0: // notice, this list of conditions and the following disclaimer. michael@0: // * Redistributions in binary form must reproduce the above michael@0: // copyright notice, this list of conditions and the following disclaimer michael@0: // in the documentation and/or other materials provided with the michael@0: // distribution. michael@0: // * Neither the name of Google Inc. nor the names of its michael@0: // contributors may be used to endorse or promote products derived from michael@0: // this software without specific prior written permission. michael@0: // michael@0: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT michael@0: // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@0: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, michael@0: // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY michael@0: // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: michael@0: // windows_frame_info.h: Holds debugging information about a stack frame. michael@0: // michael@0: // This structure is specific to Windows debugging information obtained michael@0: // from pdb files using the DIA API. michael@0: // michael@0: // Author: Mark Mentovai michael@0: michael@0: michael@0: #ifndef PROCESSOR_WINDOWS_FRAME_INFO_H__ michael@0: #define PROCESSOR_WINDOWS_FRAME_INFO_H__ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "common/using_std_string.h" michael@0: #include "google_breakpad/common/breakpad_types.h" michael@0: #include "common/logging.h" michael@0: #include "processor/tokenize.h" michael@0: michael@0: namespace google_breakpad { michael@0: michael@0: #ifdef _WIN32 michael@0: #define strtoull _strtoui64 michael@0: #endif michael@0: michael@0: struct WindowsFrameInfo { michael@0: public: michael@0: enum Validity { michael@0: VALID_NONE = 0, michael@0: VALID_PARAMETER_SIZE = 1, michael@0: VALID_ALL = -1 michael@0: }; michael@0: michael@0: // The types for stack_info_. This is equivalent to MS DIA's michael@0: // StackFrameTypeEnum. Each identifies a different type of frame michael@0: // information, although all are represented in the symbol file in the michael@0: // same format. These are used as indices to the stack_info_ array. michael@0: enum StackInfoTypes { michael@0: STACK_INFO_FPO = 0, michael@0: STACK_INFO_TRAP, // not used here michael@0: STACK_INFO_TSS, // not used here michael@0: STACK_INFO_STANDARD, michael@0: STACK_INFO_FRAME_DATA, michael@0: STACK_INFO_LAST, // must be the last sequentially-numbered item michael@0: STACK_INFO_UNKNOWN = -1 michael@0: }; michael@0: michael@0: WindowsFrameInfo() : type_(STACK_INFO_UNKNOWN), michael@0: valid(VALID_NONE), michael@0: prolog_size(0), michael@0: epilog_size(0), michael@0: parameter_size(0), michael@0: saved_register_size(0), michael@0: local_size(0), michael@0: max_stack_size(0), michael@0: allocates_base_pointer(0), michael@0: program_string() {} michael@0: michael@0: WindowsFrameInfo(StackInfoTypes type, michael@0: uint32_t set_prolog_size, michael@0: uint32_t set_epilog_size, michael@0: uint32_t set_parameter_size, michael@0: uint32_t set_saved_register_size, michael@0: uint32_t set_local_size, michael@0: uint32_t set_max_stack_size, michael@0: int set_allocates_base_pointer, michael@0: const string set_program_string) michael@0: : type_(type), michael@0: valid(VALID_ALL), michael@0: prolog_size(set_prolog_size), michael@0: epilog_size(set_epilog_size), michael@0: parameter_size(set_parameter_size), michael@0: saved_register_size(set_saved_register_size), michael@0: local_size(set_local_size), michael@0: max_stack_size(set_max_stack_size), michael@0: allocates_base_pointer(set_allocates_base_pointer), michael@0: program_string(set_program_string) {} michael@0: michael@0: // Parse a textual serialization of a WindowsFrameInfo object from michael@0: // a string. Returns NULL if parsing fails, or a new object michael@0: // otherwise. type, rva and code_size are present in the STACK line, michael@0: // but not the StackFrameInfo structure, so return them as outparams. michael@0: static WindowsFrameInfo *ParseFromString(const string string, michael@0: int &type, michael@0: uint64_t &rva, michael@0: uint64_t &code_size) { michael@0: // The format of a STACK WIN record is documented at: michael@0: // michael@0: // http://code.google.com/p/google-breakpad/wiki/SymbolFiles michael@0: michael@0: std::vector buffer; michael@0: StringToVector(string, buffer); michael@0: std::vector tokens; michael@0: if (!Tokenize(&buffer[0], " \r\n", 11, &tokens)) michael@0: return NULL; michael@0: michael@0: type = strtol(tokens[0], NULL, 16); michael@0: if (type < 0 || type > STACK_INFO_LAST - 1) michael@0: return NULL; michael@0: michael@0: rva = strtoull(tokens[1], NULL, 16); michael@0: code_size = strtoull(tokens[2], NULL, 16); michael@0: uint32_t prolog_size = strtoul(tokens[3], NULL, 16); michael@0: uint32_t epilog_size = strtoul(tokens[4], NULL, 16); michael@0: uint32_t parameter_size = strtoul(tokens[5], NULL, 16); michael@0: uint32_t saved_register_size = strtoul(tokens[6], NULL, 16); michael@0: uint32_t local_size = strtoul(tokens[7], NULL, 16); michael@0: uint32_t max_stack_size = strtoul(tokens[8], NULL, 16); michael@0: int has_program_string = strtoul(tokens[9], NULL, 16); michael@0: michael@0: const char *program_string = ""; michael@0: int allocates_base_pointer = 0; michael@0: if (has_program_string) { michael@0: program_string = tokens[10]; michael@0: } else { michael@0: allocates_base_pointer = strtoul(tokens[10], NULL, 16); michael@0: } michael@0: michael@0: return new WindowsFrameInfo(static_cast(type), michael@0: prolog_size, michael@0: epilog_size, michael@0: parameter_size, michael@0: saved_register_size, michael@0: local_size, michael@0: max_stack_size, michael@0: allocates_base_pointer, michael@0: program_string); michael@0: } michael@0: michael@0: // CopyFrom makes "this" WindowsFrameInfo object identical to "that". michael@0: void CopyFrom(const WindowsFrameInfo &that) { michael@0: type_ = that.type_; michael@0: valid = that.valid; michael@0: prolog_size = that.prolog_size; michael@0: epilog_size = that.epilog_size; michael@0: parameter_size = that.parameter_size; michael@0: saved_register_size = that.saved_register_size; michael@0: local_size = that.local_size; michael@0: max_stack_size = that.max_stack_size; michael@0: allocates_base_pointer = that.allocates_base_pointer; michael@0: program_string = that.program_string; michael@0: } michael@0: michael@0: // Clears the WindowsFrameInfo object so that users will see it as though michael@0: // it contains no information. michael@0: void Clear() { michael@0: type_ = STACK_INFO_UNKNOWN; michael@0: valid = VALID_NONE; michael@0: program_string.erase(); michael@0: } michael@0: michael@0: StackInfoTypes type_; michael@0: michael@0: // Identifies which fields in the structure are valid. This is of michael@0: // type Validity, but it is defined as an int because it's not michael@0: // possible to OR values into an enumerated type. Users must check michael@0: // this field before using any other. michael@0: int valid; michael@0: michael@0: // These values come from IDiaFrameData. michael@0: uint32_t prolog_size; michael@0: uint32_t epilog_size; michael@0: uint32_t parameter_size; michael@0: uint32_t saved_register_size; michael@0: uint32_t local_size; michael@0: uint32_t max_stack_size; michael@0: michael@0: // Only one of allocates_base_pointer or program_string will be valid. michael@0: // If program_string is empty, use allocates_base_pointer. michael@0: bool allocates_base_pointer; michael@0: string program_string; michael@0: }; michael@0: michael@0: } // namespace google_breakpad michael@0: michael@0: michael@0: #endif // PROCESSOR_WINDOWS_FRAME_INFO_H__