PageRenderTime 45ms CodeModel.GetById 11ms app.highlight 28ms RepoModel.GetById 2ms app.codeStats 0ms

/thirdparty/breakpad/processor/windows_frame_info.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 204 lines | 123 code | 26 blank | 55 comment | 5 complexity | 856d99d12c52eba33232bbf3367dc6c6 MD5 | raw file
  1// Copyright (c) 2006, Google Inc.
  2// All rights reserved.
  3//
  4// Redistribution and use in source and binary forms, with or without
  5// modification, are permitted provided that the following conditions are
  6// met:
  7//
  8//     * Redistributions of source code must retain the above copyright
  9// notice, this list of conditions and the following disclaimer.
 10//     * Redistributions in binary form must reproduce the above
 11// copyright notice, this list of conditions and the following disclaimer
 12// in the documentation and/or other materials provided with the
 13// distribution.
 14//     * Neither the name of Google Inc. nor the names of its
 15// contributors may be used to endorse or promote products derived from
 16// this software without specific prior written permission.
 17//
 18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 29
 30// windows_frame_info.h: Holds debugging information about a stack frame.
 31//
 32// This structure is specific to Windows debugging information obtained
 33// from pdb files using the DIA API.
 34//
 35// Author: Mark Mentovai
 36
 37
 38#ifndef PROCESSOR_WINDOWS_FRAME_INFO_H__
 39#define PROCESSOR_WINDOWS_FRAME_INFO_H__
 40
 41#include <string.h>
 42#include <stdlib.h>
 43
 44#include <string>
 45#include <vector>
 46
 47#include "google_breakpad/common/breakpad_types.h"
 48#include "processor/logging.h"
 49#include "processor/tokenize.h"
 50
 51namespace google_breakpad {
 52
 53struct WindowsFrameInfo {
 54 public:
 55  enum Validity {
 56    VALID_NONE           = 0,
 57    VALID_PARAMETER_SIZE = 1,
 58    VALID_ALL            = -1
 59  };
 60
 61  // The types for stack_info_.  This is equivalent to MS DIA's
 62  // StackFrameTypeEnum.  Each identifies a different type of frame
 63  // information, although all are represented in the symbol file in the
 64  // same format.  These are used as indices to the stack_info_ array.
 65  enum StackInfoTypes {
 66    STACK_INFO_FPO = 0,
 67    STACK_INFO_TRAP,  // not used here
 68    STACK_INFO_TSS,   // not used here
 69    STACK_INFO_STANDARD,
 70    STACK_INFO_FRAME_DATA,
 71    STACK_INFO_LAST,  // must be the last sequentially-numbered item
 72    STACK_INFO_UNKNOWN = -1
 73  };
 74
 75  WindowsFrameInfo() : type_(STACK_INFO_UNKNOWN),
 76                     valid(VALID_NONE),
 77                     prolog_size(0),
 78                     epilog_size(0),
 79                     parameter_size(0),
 80                     saved_register_size(0),
 81                     local_size(0),
 82                     max_stack_size(0),
 83                     allocates_base_pointer(0),
 84                     program_string() {}
 85
 86  WindowsFrameInfo(StackInfoTypes type,
 87                 u_int32_t set_prolog_size,
 88                 u_int32_t set_epilog_size,
 89                 u_int32_t set_parameter_size,
 90                 u_int32_t set_saved_register_size,
 91                 u_int32_t set_local_size,
 92                 u_int32_t set_max_stack_size,
 93                 int set_allocates_base_pointer,
 94                 const std::string set_program_string)
 95      : type_(type),
 96        valid(VALID_ALL),
 97        prolog_size(set_prolog_size),
 98        epilog_size(set_epilog_size),
 99        parameter_size(set_parameter_size),
100        saved_register_size(set_saved_register_size),
101        local_size(set_local_size),
102        max_stack_size(set_max_stack_size),
103        allocates_base_pointer(set_allocates_base_pointer),
104        program_string(set_program_string) {}
105
106  // Parse a textual serialization of a WindowsFrameInfo object from
107  // a string. Returns NULL if parsing fails, or a new object
108  // otherwise. type, rva and code_size are present in the STACK line,
109  // but not the StackFrameInfo structure, so return them as outparams.
110  static WindowsFrameInfo *ParseFromString(const std::string string,
111                                           int &type,
112                                           u_int64_t &rva,
113                                           u_int64_t &code_size) {
114    // The format of a STACK WIN record is documented at: 
115    //
116    // http://code.google.com/p/google-breakpad/wiki/SymbolFiles
117
118    std::vector<char>  buffer;
119    StringToVector(string, buffer);
120    std::vector<char*> tokens;
121    if (!Tokenize(&buffer[0], " \r\n", 11, &tokens))
122      return NULL;
123
124    type = strtol(tokens[0], NULL, 16);
125    if (type < 0 || type > STACK_INFO_LAST - 1)
126      return NULL;
127
128    rva                           = strtoull(tokens[1],  NULL, 16);
129    code_size                     = strtoull(tokens[2],  NULL, 16);
130    u_int32_t prolog_size         =  strtoul(tokens[3],  NULL, 16);
131    u_int32_t epilog_size         =  strtoul(tokens[4],  NULL, 16);
132    u_int32_t parameter_size      =  strtoul(tokens[5],  NULL, 16);
133    u_int32_t saved_register_size =  strtoul(tokens[6],  NULL, 16);
134    u_int32_t local_size          =  strtoul(tokens[7],  NULL, 16);
135    u_int32_t max_stack_size      =  strtoul(tokens[8],  NULL, 16);
136    int has_program_string        =  strtoul(tokens[9], NULL, 16);
137
138    const char *program_string = "";
139    int allocates_base_pointer = 0;
140    if (has_program_string) {
141      program_string = tokens[10];
142    } else {
143      allocates_base_pointer = strtoul(tokens[10], NULL, 16);
144    }
145
146    return new WindowsFrameInfo(static_cast<StackInfoTypes>(type),
147                                prolog_size,
148                                epilog_size,
149                                parameter_size,
150                                saved_register_size,
151                                local_size,
152                                max_stack_size,
153                                allocates_base_pointer,
154                                program_string);
155  }
156
157  // CopyFrom makes "this" WindowsFrameInfo object identical to "that".
158  void CopyFrom(const WindowsFrameInfo &that) {
159    type_ = that.type_;
160    valid = that.valid;
161    prolog_size = that.prolog_size;
162    epilog_size = that.epilog_size;
163    parameter_size = that.parameter_size;
164    saved_register_size = that.saved_register_size;
165    local_size = that.local_size;
166    max_stack_size = that.max_stack_size;
167    allocates_base_pointer = that.allocates_base_pointer;
168    program_string = that.program_string;
169  }
170
171  // Clears the WindowsFrameInfo object so that users will see it as though
172  // it contains no information.
173  void Clear() {
174    type_ = STACK_INFO_UNKNOWN;
175    valid = VALID_NONE;
176    program_string.erase();
177  }
178
179  StackInfoTypes type_;
180
181  // Identifies which fields in the structure are valid.  This is of
182  // type Validity, but it is defined as an int because it's not
183  // possible to OR values into an enumerated type.  Users must check
184  // this field before using any other.
185  int valid;
186
187  // These values come from IDiaFrameData.
188  u_int32_t prolog_size;
189  u_int32_t epilog_size;
190  u_int32_t parameter_size;
191  u_int32_t saved_register_size;
192  u_int32_t local_size;
193  u_int32_t max_stack_size;
194
195  // Only one of allocates_base_pointer or program_string will be valid.
196  // If program_string is empty, use allocates_base_pointer.
197  bool allocates_base_pointer;
198  std::string program_string;
199};
200
201}  // namespace google_breakpad
202
203
204#endif  // PROCESSOR_WINDOWS_FRAME_INFO_H__