Home | History | Annotate | Download | only in processor
      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 (at) google.com)
     40 
     41 #include <stdio.h>
     42 
     43 #include <map>
     44 #include <string>
     45 
     46 #include "google_breakpad/common/breakpad_types.h"
     47 #include "google_breakpad/processor/source_line_resolver_base.h"
     48 #include "google_breakpad/processor/stack_frame.h"
     49 #include "processor/cfi_frame_info.h"
     50 #include "processor/windows_frame_info.h"
     51 
     52 #ifndef PROCESSOR_SOURCE_LINE_RESOLVER_BASE_TYPES_H__
     53 #define PROCESSOR_SOURCE_LINE_RESOLVER_BASE_TYPES_H__
     54 
     55 namespace google_breakpad {
     56 
     57 class SourceLineResolverBase::AutoFileCloser {
     58  public:
     59   explicit AutoFileCloser(FILE *file) : file_(file) {}
     60   ~AutoFileCloser() {
     61     if (file_)
     62       fclose(file_);
     63   }
     64 
     65  private:
     66   FILE *file_;
     67 };
     68 
     69 struct SourceLineResolverBase::Line {
     70   Line() { }
     71   Line(MemAddr addr, MemAddr code_size, int file_id, int source_line)
     72       : address(addr)
     73       , size(code_size)
     74       , source_file_id(file_id)
     75       , line(source_line) { }
     76 
     77   MemAddr address;
     78   MemAddr size;
     79   int32_t source_file_id;
     80   int32_t line;
     81 };
     82 
     83 struct SourceLineResolverBase::Function {
     84   Function() { }
     85   Function(const string &function_name,
     86            MemAddr function_address,
     87            MemAddr code_size,
     88            int set_parameter_size)
     89       : name(function_name), address(function_address), size(code_size),
     90         parameter_size(set_parameter_size) { }
     91 
     92   string name;
     93   MemAddr address;
     94   MemAddr size;
     95 
     96   // The size of parameters passed to this function on the stack.
     97   int32_t parameter_size;
     98 };
     99 
    100 struct SourceLineResolverBase::PublicSymbol {
    101   PublicSymbol() { }
    102   PublicSymbol(const string& set_name,
    103                MemAddr set_address,
    104                int set_parameter_size)
    105       : name(set_name),
    106         address(set_address),
    107         parameter_size(set_parameter_size) {}
    108 
    109   string name;
    110   MemAddr address;
    111 
    112   // If the public symbol is used as a function entry point, parameter_size
    113   // is set to the size of the parameters passed to the funciton on the
    114   // stack, if known.
    115   int32_t parameter_size;
    116 };
    117 
    118 class SourceLineResolverBase::Module {
    119  public:
    120   virtual ~Module() { };
    121   // Loads a map from the given buffer in char* type.
    122   // Does NOT take ownership of memory_buffer (the caller, source line resolver,
    123   // is the owner of memory_buffer).
    124   // The passed in |memory buffer| is of size |memory_buffer_size|.  If it is
    125   // not null terminated, LoadMapFromMemory will null terminate it by modifying
    126   // the passed in buffer.
    127   virtual bool LoadMapFromMemory(char *memory_buffer,
    128                                  size_t memory_buffer_size) = 0;
    129 
    130   // Tells whether the loaded symbol data is corrupt.  Return value is
    131   // undefined, if the symbol data hasn't been loaded yet.
    132   virtual bool IsCorrupt() const = 0;
    133 
    134   // Looks up the given relative address, and fills the StackFrame struct
    135   // with the result.
    136   virtual void LookupAddress(StackFrame *frame) const = 0;
    137 
    138   // If Windows stack walking information is available covering ADDRESS,
    139   // return a WindowsFrameInfo structure describing it. If the information
    140   // is not available, returns NULL. A NULL return value does not indicate
    141   // an error. The caller takes ownership of any returned WindowsFrameInfo
    142   // object.
    143   virtual WindowsFrameInfo *
    144   FindWindowsFrameInfo(const StackFrame *frame) const = 0;
    145 
    146   // If CFI stack walking information is available covering ADDRESS,
    147   // return a CFIFrameInfo structure describing it. If the information
    148   // is not available, return NULL. The caller takes ownership of any
    149   // returned CFIFrameInfo object.
    150   virtual CFIFrameInfo *FindCFIFrameInfo(const StackFrame *frame) const = 0;
    151  protected:
    152   virtual bool ParseCFIRuleSet(const string &rule_set,
    153                                CFIFrameInfo *frame_info) const;
    154 };
    155 
    156 }  // namespace google_breakpad
    157 
    158 #endif  // PROCESSOR_SOURCE_LINE_RESOLVER_BASE_TYPES_H__
    159