PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/thirdparty/breakpad/processor/source_line_resolver_base_types.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 149 lines | 71 code | 22 blank | 56 comment | 1 complexity | bd1c1368a565c829c23c8121f53e46e9 MD5 | raw file
  1// Copyright (c) 2010 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// source_line_resolver_base_types.h: definition of nested classes/structs in
 31// SourceLineResolverBase.  It moves the definitions out of
 32// source_line_resolver_base.cc, so that other classes may have access
 33// to these private nested types without including source_line_resolver_base.cc
 34// In addition, Module is defined as a pure abstract class to be implemented by
 35// each concrete source line resolver class.
 36//
 37// See source_line_resolver_base.h for more documentation.
 38//
 39// Author: Siyang Xie (lambxsy@google.com)
 40
 41#include <stdio.h>
 42
 43#include <map>
 44#include <string>
 45
 46#include "google_breakpad/processor/source_line_resolver_base.h"
 47#include "google_breakpad/processor/stack_frame.h"
 48#include "processor/cfi_frame_info.h"
 49#include "processor/windows_frame_info.h"
 50
 51#ifndef PROCESSOR_SOURCE_LINE_RESOLVER_BASE_TYPES_H__
 52#define PROCESSOR_SOURCE_LINE_RESOLVER_BASE_TYPES_H__
 53
 54namespace google_breakpad {
 55
 56class SourceLineResolverBase::AutoFileCloser {
 57 public:
 58  explicit AutoFileCloser(FILE *file) : file_(file) {}
 59  ~AutoFileCloser() {
 60    if (file_)
 61      fclose(file_);
 62  }
 63
 64 private:
 65  FILE *file_;
 66};
 67
 68struct SourceLineResolverBase::Line {
 69  Line() { }
 70  Line(MemAddr addr, MemAddr code_size, int file_id, int source_line)
 71      : address(addr)
 72      , size(code_size)
 73      , source_file_id(file_id)
 74      , line(source_line) { }
 75
 76  MemAddr address;
 77  MemAddr size;
 78  int32_t source_file_id;
 79  int32_t line;
 80};
 81
 82struct SourceLineResolverBase::Function {
 83  Function() { }
 84  Function(const string &function_name,
 85           MemAddr function_address,
 86           MemAddr code_size,
 87           int set_parameter_size)
 88      : name(function_name), address(function_address), size(code_size),
 89        parameter_size(set_parameter_size) { }
 90
 91  string name;
 92  MemAddr address;
 93  MemAddr size;
 94
 95  // The size of parameters passed to this function on the stack.
 96  int32_t parameter_size;
 97};
 98
 99struct SourceLineResolverBase::PublicSymbol {
100  PublicSymbol() { }
101  PublicSymbol(const string& set_name,
102               MemAddr set_address,
103               int set_parameter_size)
104      : name(set_name),
105        address(set_address),
106        parameter_size(set_parameter_size) {}
107
108  string name;
109  MemAddr address;
110
111  // If the public symbol is used as a function entry point, parameter_size
112  // is set to the size of the parameters passed to the funciton on the
113  // stack, if known.
114  int32_t parameter_size;
115};
116
117class SourceLineResolverBase::Module {
118 public:
119  virtual ~Module() { };
120  // Loads a map from the given buffer in char* type.
121  // Does NOT take ownership of memory_buffer (the caller, source line resolver,
122  // is the owner of memory_buffer).
123  virtual bool LoadMapFromMemory(char *memory_buffer) = 0;
124
125  // Looks up the given relative address, and fills the StackFrame struct
126  // with the result.
127  virtual void LookupAddress(StackFrame *frame) const = 0;
128
129  // If Windows stack walking information is available covering ADDRESS,
130  // return a WindowsFrameInfo structure describing it. If the information
131  // is not available, returns NULL. A NULL return value does not indicate
132  // an error. The caller takes ownership of any returned WindowsFrameInfo
133  // object.
134  virtual WindowsFrameInfo *
135  FindWindowsFrameInfo(const StackFrame *frame) const = 0;
136
137  // If CFI stack walking information is available covering ADDRESS,
138  // return a CFIFrameInfo structure describing it. If the information
139  // is not available, return NULL. The caller takes ownership of any
140  // returned CFIFrameInfo object.
141  virtual CFIFrameInfo *FindCFIFrameInfo(const StackFrame *frame) const = 0;
142 protected:
143  virtual bool ParseCFIRuleSet(const string &rule_set,
144                               CFIFrameInfo *frame_info) const;
145};
146
147}  // namespace google_breakpad
148
149#endif  // PROCESSOR_SOURCE_LINE_RESOLVER_BASE_TYPES_H__