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