Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | // -*- mode: C++ -*- |
michael@0 | 2 | |
michael@0 | 3 | // Copyright (c) 2010 Google Inc. |
michael@0 | 4 | // All rights reserved. |
michael@0 | 5 | // |
michael@0 | 6 | // Redistribution and use in source and binary forms, with or without |
michael@0 | 7 | // modification, are permitted provided that the following conditions are |
michael@0 | 8 | // met: |
michael@0 | 9 | // |
michael@0 | 10 | // * Redistributions of source code must retain the above copyright |
michael@0 | 11 | // notice, this list of conditions and the following disclaimer. |
michael@0 | 12 | // * Redistributions in binary form must reproduce the above |
michael@0 | 13 | // copyright notice, this list of conditions and the following disclaimer |
michael@0 | 14 | // in the documentation and/or other materials provided with the |
michael@0 | 15 | // distribution. |
michael@0 | 16 | // * Neither the name of Google Inc. nor the names of its |
michael@0 | 17 | // contributors may be used to endorse or promote products derived from |
michael@0 | 18 | // this software without specific prior written permission. |
michael@0 | 19 | // |
michael@0 | 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
michael@0 | 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@0 | 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 31 | |
michael@0 | 32 | // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> |
michael@0 | 33 | |
michael@0 | 34 | // dump_stabs.h: Define the StabsToModule class, which receives |
michael@0 | 35 | // STABS debugging information from a parser and adds it to a Breakpad |
michael@0 | 36 | // symbol file. |
michael@0 | 37 | |
michael@0 | 38 | #ifndef BREAKPAD_COMMON_STABS_TO_MODULE_H_ |
michael@0 | 39 | #define BREAKPAD_COMMON_STABS_TO_MODULE_H_ |
michael@0 | 40 | |
michael@0 | 41 | #include <stdint.h> |
michael@0 | 42 | |
michael@0 | 43 | #include <string> |
michael@0 | 44 | #include <vector> |
michael@0 | 45 | |
michael@0 | 46 | #include "common/module.h" |
michael@0 | 47 | #include "common/stabs_reader.h" |
michael@0 | 48 | #include "common/using_std_string.h" |
michael@0 | 49 | |
michael@0 | 50 | namespace google_breakpad { |
michael@0 | 51 | |
michael@0 | 52 | using std::vector; |
michael@0 | 53 | |
michael@0 | 54 | // A StabsToModule is a handler that receives parsed STABS debugging |
michael@0 | 55 | // information from a StabsReader, and uses that to populate |
michael@0 | 56 | // a Module. (All classes are in the google_breakpad namespace.) A |
michael@0 | 57 | // Module represents the contents of a Breakpad symbol file, and knows |
michael@0 | 58 | // how to write itself out as such. A StabsToModule thus acts as |
michael@0 | 59 | // the bridge between STABS and Breakpad data. |
michael@0 | 60 | // When processing Darwin Mach-O files, this also receives public linker |
michael@0 | 61 | // symbols, like those found in system libraries. |
michael@0 | 62 | class StabsToModule: public google_breakpad::StabsHandler { |
michael@0 | 63 | public: |
michael@0 | 64 | // Receive parsed debugging information from a StabsReader, and |
michael@0 | 65 | // store it all in MODULE. |
michael@0 | 66 | StabsToModule(Module *module) : |
michael@0 | 67 | module_(module), |
michael@0 | 68 | in_compilation_unit_(false), |
michael@0 | 69 | comp_unit_base_address_(0), |
michael@0 | 70 | current_function_(NULL), |
michael@0 | 71 | current_source_file_(NULL), |
michael@0 | 72 | current_source_file_name_(NULL) { } |
michael@0 | 73 | ~StabsToModule(); |
michael@0 | 74 | |
michael@0 | 75 | // The standard StabsHandler virtual member functions. |
michael@0 | 76 | bool StartCompilationUnit(const char *name, uint64_t address, |
michael@0 | 77 | const char *build_directory); |
michael@0 | 78 | bool EndCompilationUnit(uint64_t address); |
michael@0 | 79 | bool StartFunction(const string &name, uint64_t address); |
michael@0 | 80 | bool EndFunction(uint64_t address); |
michael@0 | 81 | bool Line(uint64_t address, const char *name, int number); |
michael@0 | 82 | bool Extern(const string &name, uint64_t address); |
michael@0 | 83 | void Warning(const char *format, ...); |
michael@0 | 84 | |
michael@0 | 85 | // Do any final processing necessary to make module_ contain all the |
michael@0 | 86 | // data provided by the STABS reader. |
michael@0 | 87 | // |
michael@0 | 88 | // Because STABS does not provide reliable size information for |
michael@0 | 89 | // functions and lines, we need to make a pass over the data after |
michael@0 | 90 | // processing all the STABS to compute those sizes. We take care of |
michael@0 | 91 | // that here. |
michael@0 | 92 | void Finalize(); |
michael@0 | 93 | |
michael@0 | 94 | private: |
michael@0 | 95 | |
michael@0 | 96 | // An arbitrary, but very large, size to use for functions whose |
michael@0 | 97 | // size we can't compute properly. |
michael@0 | 98 | static const uint64_t kFallbackSize = 0x10000000; |
michael@0 | 99 | |
michael@0 | 100 | // The module we're contributing debugging info to. |
michael@0 | 101 | Module *module_; |
michael@0 | 102 | |
michael@0 | 103 | // The functions we've generated so far. We don't add these to |
michael@0 | 104 | // module_ as we parse them. Instead, we wait until we've computed |
michael@0 | 105 | // their ending address, and their lines' ending addresses. |
michael@0 | 106 | // |
michael@0 | 107 | // We could just stick them in module_ from the outset, but if |
michael@0 | 108 | // module_ already contains data gathered from other debugging |
michael@0 | 109 | // formats, that would complicate the size computation. |
michael@0 | 110 | vector<Module::Function *> functions_; |
michael@0 | 111 | |
michael@0 | 112 | // Boundary addresses. STABS doesn't necessarily supply sizes for |
michael@0 | 113 | // functions and lines, so we need to compute them ourselves by |
michael@0 | 114 | // finding the next object. |
michael@0 | 115 | vector<Module::Address> boundaries_; |
michael@0 | 116 | |
michael@0 | 117 | // True if we are currently within a compilation unit: we have gotten a |
michael@0 | 118 | // StartCompilationUnit call, but no matching EndCompilationUnit call |
michael@0 | 119 | // yet. We use this for sanity checks. |
michael@0 | 120 | bool in_compilation_unit_; |
michael@0 | 121 | |
michael@0 | 122 | // The base address of the current compilation unit. We use this to |
michael@0 | 123 | // recognize functions we should omit from the symbol file. (If you |
michael@0 | 124 | // know the details of why we omit these, please patch this |
michael@0 | 125 | // comment.) |
michael@0 | 126 | Module::Address comp_unit_base_address_; |
michael@0 | 127 | |
michael@0 | 128 | // The function we're currently contributing lines to. |
michael@0 | 129 | Module::Function *current_function_; |
michael@0 | 130 | |
michael@0 | 131 | // The last Module::File we got a line number in. |
michael@0 | 132 | Module::File *current_source_file_; |
michael@0 | 133 | |
michael@0 | 134 | // The pointer in the .stabstr section of the name that |
michael@0 | 135 | // current_source_file_ is built from. This allows us to quickly |
michael@0 | 136 | // recognize when the current line is in the same file as the |
michael@0 | 137 | // previous one (which it usually is). |
michael@0 | 138 | const char *current_source_file_name_; |
michael@0 | 139 | }; |
michael@0 | 140 | |
michael@0 | 141 | } // namespace google_breakpad |
michael@0 | 142 | |
michael@0 | 143 | #endif // BREAKPAD_COMMON_STABS_TO_MODULE_H_ |