toolkit/crashreporter/google-breakpad/src/common/stabs_to_module.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/common/stabs_to_module.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,143 @@
     1.4 +// -*- mode: C++ -*-
     1.5 +
     1.6 +// Copyright (c) 2010 Google Inc.
     1.7 +// All rights reserved.
     1.8 +//
     1.9 +// Redistribution and use in source and binary forms, with or without
    1.10 +// modification, are permitted provided that the following conditions are
    1.11 +// met:
    1.12 +//
    1.13 +//     * Redistributions of source code must retain the above copyright
    1.14 +// notice, this list of conditions and the following disclaimer.
    1.15 +//     * Redistributions in binary form must reproduce the above
    1.16 +// copyright notice, this list of conditions and the following disclaimer
    1.17 +// in the documentation and/or other materials provided with the
    1.18 +// distribution.
    1.19 +//     * Neither the name of Google Inc. nor the names of its
    1.20 +// contributors may be used to endorse or promote products derived from
    1.21 +// this software without specific prior written permission.
    1.22 +//
    1.23 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.24 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.25 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.26 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.27 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.28 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.29 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.30 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.31 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.32 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.33 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.34 +
    1.35 +// Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
    1.36 +
    1.37 +// dump_stabs.h: Define the StabsToModule class, which receives
    1.38 +// STABS debugging information from a parser and adds it to a Breakpad
    1.39 +// symbol file.
    1.40 +
    1.41 +#ifndef BREAKPAD_COMMON_STABS_TO_MODULE_H_
    1.42 +#define BREAKPAD_COMMON_STABS_TO_MODULE_H_
    1.43 +
    1.44 +#include <stdint.h>
    1.45 +
    1.46 +#include <string>
    1.47 +#include <vector>
    1.48 +
    1.49 +#include "common/module.h"
    1.50 +#include "common/stabs_reader.h"
    1.51 +#include "common/using_std_string.h"
    1.52 +
    1.53 +namespace google_breakpad {
    1.54 +
    1.55 +using std::vector;
    1.56 +
    1.57 +// A StabsToModule is a handler that receives parsed STABS debugging 
    1.58 +// information from a StabsReader, and uses that to populate
    1.59 +// a Module. (All classes are in the google_breakpad namespace.) A
    1.60 +// Module represents the contents of a Breakpad symbol file, and knows
    1.61 +// how to write itself out as such. A StabsToModule thus acts as
    1.62 +// the bridge between STABS and Breakpad data.
    1.63 +// When processing Darwin Mach-O files, this also receives public linker
    1.64 +// symbols, like those found in system libraries.
    1.65 +class StabsToModule: public google_breakpad::StabsHandler {
    1.66 + public:
    1.67 +  // Receive parsed debugging information from a StabsReader, and
    1.68 +  // store it all in MODULE.
    1.69 +  StabsToModule(Module *module) :
    1.70 +      module_(module),
    1.71 +      in_compilation_unit_(false),
    1.72 +      comp_unit_base_address_(0),
    1.73 +      current_function_(NULL),
    1.74 +      current_source_file_(NULL),
    1.75 +      current_source_file_name_(NULL) { }
    1.76 +  ~StabsToModule();
    1.77 +
    1.78 +  // The standard StabsHandler virtual member functions.
    1.79 +  bool StartCompilationUnit(const char *name, uint64_t address,
    1.80 +                            const char *build_directory);
    1.81 +  bool EndCompilationUnit(uint64_t address);
    1.82 +  bool StartFunction(const string &name, uint64_t address);
    1.83 +  bool EndFunction(uint64_t address);
    1.84 +  bool Line(uint64_t address, const char *name, int number);
    1.85 +  bool Extern(const string &name, uint64_t address);
    1.86 +  void Warning(const char *format, ...);
    1.87 +
    1.88 +  // Do any final processing necessary to make module_ contain all the
    1.89 +  // data provided by the STABS reader.
    1.90 +  //
    1.91 +  // Because STABS does not provide reliable size information for
    1.92 +  // functions and lines, we need to make a pass over the data after
    1.93 +  // processing all the STABS to compute those sizes.  We take care of
    1.94 +  // that here.
    1.95 +  void Finalize();
    1.96 +
    1.97 + private:
    1.98 +
    1.99 +  // An arbitrary, but very large, size to use for functions whose
   1.100 +  // size we can't compute properly.
   1.101 +  static const uint64_t kFallbackSize = 0x10000000;
   1.102 +
   1.103 +  // The module we're contributing debugging info to.
   1.104 +  Module *module_;
   1.105 +
   1.106 +  // The functions we've generated so far.  We don't add these to
   1.107 +  // module_ as we parse them.  Instead, we wait until we've computed
   1.108 +  // their ending address, and their lines' ending addresses.
   1.109 +  //
   1.110 +  // We could just stick them in module_ from the outset, but if
   1.111 +  // module_ already contains data gathered from other debugging
   1.112 +  // formats, that would complicate the size computation.
   1.113 +  vector<Module::Function *> functions_;
   1.114 +
   1.115 +  // Boundary addresses.  STABS doesn't necessarily supply sizes for
   1.116 +  // functions and lines, so we need to compute them ourselves by
   1.117 +  // finding the next object.
   1.118 +  vector<Module::Address> boundaries_;
   1.119 +
   1.120 +  // True if we are currently within a compilation unit: we have gotten a
   1.121 +  // StartCompilationUnit call, but no matching EndCompilationUnit call
   1.122 +  // yet. We use this for sanity checks.
   1.123 +  bool in_compilation_unit_;
   1.124 +
   1.125 +  // The base address of the current compilation unit.  We use this to
   1.126 +  // recognize functions we should omit from the symbol file.  (If you
   1.127 +  // know the details of why we omit these, please patch this
   1.128 +  // comment.)
   1.129 +  Module::Address comp_unit_base_address_;
   1.130 +
   1.131 +  // The function we're currently contributing lines to.
   1.132 +  Module::Function *current_function_;
   1.133 +
   1.134 +  // The last Module::File we got a line number in.
   1.135 +  Module::File *current_source_file_;
   1.136 +
   1.137 +  // The pointer in the .stabstr section of the name that
   1.138 +  // current_source_file_ is built from.  This allows us to quickly
   1.139 +  // recognize when the current line is in the same file as the
   1.140 +  // previous one (which it usually is).
   1.141 +  const char *current_source_file_name_;
   1.142 +};
   1.143 +
   1.144 +}  // namespace google_breakpad
   1.145 +
   1.146 +#endif  // BREAKPAD_COMMON_STABS_TO_MODULE_H_

mercurial