toolkit/crashreporter/google-breakpad/src/processor/windows_frame_info.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/processor/windows_frame_info.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,209 @@
     1.4 +// Copyright (c) 2006, Google Inc.
     1.5 +// All rights reserved.
     1.6 +//
     1.7 +// Redistribution and use in source and binary forms, with or without
     1.8 +// modification, are permitted provided that the following conditions are
     1.9 +// met:
    1.10 +//
    1.11 +//     * Redistributions of source code must retain the above copyright
    1.12 +// notice, this list of conditions and the following disclaimer.
    1.13 +//     * Redistributions in binary form must reproduce the above
    1.14 +// copyright notice, this list of conditions and the following disclaimer
    1.15 +// in the documentation and/or other materials provided with the
    1.16 +// distribution.
    1.17 +//     * Neither the name of Google Inc. nor the names of its
    1.18 +// contributors may be used to endorse or promote products derived from
    1.19 +// this software without specific prior written permission.
    1.20 +//
    1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.32 +
    1.33 +// windows_frame_info.h: Holds debugging information about a stack frame.
    1.34 +//
    1.35 +// This structure is specific to Windows debugging information obtained
    1.36 +// from pdb files using the DIA API.
    1.37 +//
    1.38 +// Author: Mark Mentovai
    1.39 +
    1.40 +
    1.41 +#ifndef PROCESSOR_WINDOWS_FRAME_INFO_H__
    1.42 +#define PROCESSOR_WINDOWS_FRAME_INFO_H__
    1.43 +
    1.44 +#include <string.h>
    1.45 +#include <stdlib.h>
    1.46 +
    1.47 +#include <string>
    1.48 +#include <vector>
    1.49 +
    1.50 +#include "common/using_std_string.h"
    1.51 +#include "google_breakpad/common/breakpad_types.h"
    1.52 +#include "common/logging.h"
    1.53 +#include "processor/tokenize.h"
    1.54 +
    1.55 +namespace google_breakpad {
    1.56 +
    1.57 +#ifdef _WIN32
    1.58 +#define strtoull _strtoui64
    1.59 +#endif
    1.60 +
    1.61 +struct WindowsFrameInfo {
    1.62 + public:
    1.63 +  enum Validity {
    1.64 +    VALID_NONE           = 0,
    1.65 +    VALID_PARAMETER_SIZE = 1,
    1.66 +    VALID_ALL            = -1
    1.67 +  };
    1.68 +
    1.69 +  // The types for stack_info_.  This is equivalent to MS DIA's
    1.70 +  // StackFrameTypeEnum.  Each identifies a different type of frame
    1.71 +  // information, although all are represented in the symbol file in the
    1.72 +  // same format.  These are used as indices to the stack_info_ array.
    1.73 +  enum StackInfoTypes {
    1.74 +    STACK_INFO_FPO = 0,
    1.75 +    STACK_INFO_TRAP,  // not used here
    1.76 +    STACK_INFO_TSS,   // not used here
    1.77 +    STACK_INFO_STANDARD,
    1.78 +    STACK_INFO_FRAME_DATA,
    1.79 +    STACK_INFO_LAST,  // must be the last sequentially-numbered item
    1.80 +    STACK_INFO_UNKNOWN = -1
    1.81 +  };
    1.82 +
    1.83 +  WindowsFrameInfo() : type_(STACK_INFO_UNKNOWN),
    1.84 +                     valid(VALID_NONE),
    1.85 +                     prolog_size(0),
    1.86 +                     epilog_size(0),
    1.87 +                     parameter_size(0),
    1.88 +                     saved_register_size(0),
    1.89 +                     local_size(0),
    1.90 +                     max_stack_size(0),
    1.91 +                     allocates_base_pointer(0),
    1.92 +                     program_string() {}
    1.93 +
    1.94 +  WindowsFrameInfo(StackInfoTypes type,
    1.95 +                 uint32_t set_prolog_size,
    1.96 +                 uint32_t set_epilog_size,
    1.97 +                 uint32_t set_parameter_size,
    1.98 +                 uint32_t set_saved_register_size,
    1.99 +                 uint32_t set_local_size,
   1.100 +                 uint32_t set_max_stack_size,
   1.101 +                 int set_allocates_base_pointer,
   1.102 +                 const string set_program_string)
   1.103 +      : type_(type),
   1.104 +        valid(VALID_ALL),
   1.105 +        prolog_size(set_prolog_size),
   1.106 +        epilog_size(set_epilog_size),
   1.107 +        parameter_size(set_parameter_size),
   1.108 +        saved_register_size(set_saved_register_size),
   1.109 +        local_size(set_local_size),
   1.110 +        max_stack_size(set_max_stack_size),
   1.111 +        allocates_base_pointer(set_allocates_base_pointer),
   1.112 +        program_string(set_program_string) {}
   1.113 +
   1.114 +  // Parse a textual serialization of a WindowsFrameInfo object from
   1.115 +  // a string. Returns NULL if parsing fails, or a new object
   1.116 +  // otherwise. type, rva and code_size are present in the STACK line,
   1.117 +  // but not the StackFrameInfo structure, so return them as outparams.
   1.118 +  static WindowsFrameInfo *ParseFromString(const string string,
   1.119 +                                           int &type,
   1.120 +                                           uint64_t &rva,
   1.121 +                                           uint64_t &code_size) {
   1.122 +    // The format of a STACK WIN record is documented at:
   1.123 +    //
   1.124 +    // http://code.google.com/p/google-breakpad/wiki/SymbolFiles
   1.125 +
   1.126 +    std::vector<char>  buffer;
   1.127 +    StringToVector(string, buffer);
   1.128 +    std::vector<char*> tokens;
   1.129 +    if (!Tokenize(&buffer[0], " \r\n", 11, &tokens))
   1.130 +      return NULL;
   1.131 +
   1.132 +    type = strtol(tokens[0], NULL, 16);
   1.133 +    if (type < 0 || type > STACK_INFO_LAST - 1)
   1.134 +      return NULL;
   1.135 +
   1.136 +    rva                           = strtoull(tokens[1],  NULL, 16);
   1.137 +    code_size                     = strtoull(tokens[2],  NULL, 16);
   1.138 +    uint32_t prolog_size          =  strtoul(tokens[3],  NULL, 16);
   1.139 +    uint32_t epilog_size          =  strtoul(tokens[4],  NULL, 16);
   1.140 +    uint32_t parameter_size       =  strtoul(tokens[5],  NULL, 16);
   1.141 +    uint32_t saved_register_size  =  strtoul(tokens[6],  NULL, 16);
   1.142 +    uint32_t local_size           =  strtoul(tokens[7],  NULL, 16);
   1.143 +    uint32_t max_stack_size       =  strtoul(tokens[8],  NULL, 16);
   1.144 +    int has_program_string        =  strtoul(tokens[9], NULL, 16);
   1.145 +
   1.146 +    const char *program_string = "";
   1.147 +    int allocates_base_pointer = 0;
   1.148 +    if (has_program_string) {
   1.149 +      program_string = tokens[10];
   1.150 +    } else {
   1.151 +      allocates_base_pointer = strtoul(tokens[10], NULL, 16);
   1.152 +    }
   1.153 +
   1.154 +    return new WindowsFrameInfo(static_cast<StackInfoTypes>(type),
   1.155 +                                prolog_size,
   1.156 +                                epilog_size,
   1.157 +                                parameter_size,
   1.158 +                                saved_register_size,
   1.159 +                                local_size,
   1.160 +                                max_stack_size,
   1.161 +                                allocates_base_pointer,
   1.162 +                                program_string);
   1.163 +  }
   1.164 +
   1.165 +  // CopyFrom makes "this" WindowsFrameInfo object identical to "that".
   1.166 +  void CopyFrom(const WindowsFrameInfo &that) {
   1.167 +    type_ = that.type_;
   1.168 +    valid = that.valid;
   1.169 +    prolog_size = that.prolog_size;
   1.170 +    epilog_size = that.epilog_size;
   1.171 +    parameter_size = that.parameter_size;
   1.172 +    saved_register_size = that.saved_register_size;
   1.173 +    local_size = that.local_size;
   1.174 +    max_stack_size = that.max_stack_size;
   1.175 +    allocates_base_pointer = that.allocates_base_pointer;
   1.176 +    program_string = that.program_string;
   1.177 +  }
   1.178 +
   1.179 +  // Clears the WindowsFrameInfo object so that users will see it as though
   1.180 +  // it contains no information.
   1.181 +  void Clear() {
   1.182 +    type_ = STACK_INFO_UNKNOWN;
   1.183 +    valid = VALID_NONE;
   1.184 +    program_string.erase();
   1.185 +  }
   1.186 +
   1.187 +  StackInfoTypes type_;
   1.188 +
   1.189 +  // Identifies which fields in the structure are valid.  This is of
   1.190 +  // type Validity, but it is defined as an int because it's not
   1.191 +  // possible to OR values into an enumerated type.  Users must check
   1.192 +  // this field before using any other.
   1.193 +  int valid;
   1.194 +
   1.195 +  // These values come from IDiaFrameData.
   1.196 +  uint32_t prolog_size;
   1.197 +  uint32_t epilog_size;
   1.198 +  uint32_t parameter_size;
   1.199 +  uint32_t saved_register_size;
   1.200 +  uint32_t local_size;
   1.201 +  uint32_t max_stack_size;
   1.202 +
   1.203 +  // Only one of allocates_base_pointer or program_string will be valid.
   1.204 +  // If program_string is empty, use allocates_base_pointer.
   1.205 +  bool allocates_base_pointer;
   1.206 +  string program_string;
   1.207 +};
   1.208 +
   1.209 +}  // namespace google_breakpad
   1.210 +
   1.211 +
   1.212 +#endif  // PROCESSOR_WINDOWS_FRAME_INFO_H__

mercurial