OLD | NEW |
| (Empty) |
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 // dwarf_cfi_to_module.h: Define the DwarfCFIToModule class, which | |
35 // accepts parsed DWARF call frame info and adds it to a | |
36 // google_breakpad::Module object, which can write that information to | |
37 // a Breakpad symbol file. | |
38 | |
39 #ifndef COMMON_LINUX_DWARF_CFI_TO_MODULE_H | |
40 #define COMMON_LINUX_DWARF_CFI_TO_MODULE_H | |
41 | |
42 #include <cassert> | |
43 #include <string> | |
44 #include <vector> | |
45 | |
46 #include "common/module.h" | |
47 #include "common/dwarf/dwarf2reader.h" | |
48 | |
49 namespace google_breakpad { | |
50 | |
51 using dwarf2reader::CallFrameInfo; | |
52 using google_breakpad::Module; | |
53 using std::string; | |
54 using std::vector; | |
55 | |
56 // A class that accepts parsed call frame information from the DWARF | |
57 // CFI parser and populates a google_breakpad::Module object with the | |
58 // contents. | |
59 class DwarfCFIToModule: public CallFrameInfo::Handler { | |
60 public: | |
61 | |
62 // DwarfCFIToModule uses an instance of this class to report errors | |
63 // detected while converting DWARF CFI to Breakpad STACK CFI records. | |
64 class Reporter { | |
65 public: | |
66 // Create a reporter that writes messages to the standard error | |
67 // stream. FILE is the name of the file we're processing, and | |
68 // SECTION is the name of the section within that file that we're | |
69 // looking at (.debug_frame, .eh_frame, etc.). | |
70 Reporter(const string &file, const string §ion) | |
71 : file_(file), section_(section) { } | |
72 virtual ~Reporter() { } | |
73 | |
74 // The DWARF CFI entry at OFFSET cites register REG, but REG is not | |
75 // covered by the vector of register names passed to the | |
76 // DwarfCFIToModule constructor, nor does it match the return | |
77 // address column number for this entry. | |
78 virtual void UnnamedRegister(size_t offset, int reg); | |
79 | |
80 // The DWARF CFI entry at OFFSET says that REG is undefined, but the | |
81 // Breakpad symbol file format cannot express this. | |
82 virtual void UndefinedNotSupported(size_t offset, const string ®); | |
83 | |
84 // The DWARF CFI entry at OFFSET says that REG uses a DWARF | |
85 // expression to find its value, but DwarfCFIToModule is not | |
86 // capable of translating DWARF expressions to Breakpad postfix | |
87 // expressions. | |
88 virtual void ExpressionsNotSupported(size_t offset, const string ®); | |
89 | |
90 protected: | |
91 string file_, section_; | |
92 }; | |
93 | |
94 // Create a handler for the dwarf2reader::CallFrameInfo parser that | |
95 // records the stack unwinding information it receives in MODULE. | |
96 // | |
97 // Use REGISTER_NAMES[I] as the name of register number I; *this | |
98 // keeps a reference to the vector, so the vector should remain | |
99 // alive for as long as the DwarfCFIToModule does. | |
100 // | |
101 // Use REPORTER for reporting problems encountered in the conversion | |
102 // process. | |
103 DwarfCFIToModule(Module *module, const vector<string> ®ister_names, | |
104 Reporter *reporter) | |
105 : module_(module), register_names_(register_names), reporter_(reporter), | |
106 entry_(NULL), return_address_(-1) { } | |
107 virtual ~DwarfCFIToModule() { delete entry_; } | |
108 | |
109 virtual bool Entry(size_t offset, uint64 address, uint64 length, | |
110 uint8 version, const string &augmentation, | |
111 unsigned return_address); | |
112 virtual bool UndefinedRule(uint64 address, int reg); | |
113 virtual bool SameValueRule(uint64 address, int reg); | |
114 virtual bool OffsetRule(uint64 address, int reg, | |
115 int base_register, long offset); | |
116 virtual bool ValOffsetRule(uint64 address, int reg, | |
117 int base_register, long offset); | |
118 virtual bool RegisterRule(uint64 address, int reg, int base_register); | |
119 virtual bool ExpressionRule(uint64 address, int reg, | |
120 const string &expression); | |
121 virtual bool ValExpressionRule(uint64 address, int reg, | |
122 const string &expression); | |
123 virtual bool End(); | |
124 | |
125 private: | |
126 // Return the name to use for register REG. | |
127 string RegisterName(int i); | |
128 | |
129 // Record RULE for register REG at ADDRESS. | |
130 void Record(Module::Address address, int reg, const string &rule); | |
131 | |
132 // The module to which we should add entries. | |
133 Module *module_; | |
134 | |
135 // Map from register numbers to register names. | |
136 const vector<string> ®ister_names_; | |
137 | |
138 // The reporter to use to report problems. | |
139 Reporter *reporter_; | |
140 | |
141 // The current entry we're constructing. | |
142 Module::StackFrameEntry *entry_; | |
143 | |
144 // The section offset of the current frame description entry, for | |
145 // use in error messages. | |
146 size_t entry_offset_; | |
147 | |
148 // The return address column for that entry. | |
149 unsigned return_address_; | |
150 }; | |
151 | |
152 } // namespace google_breakpad | |
153 | |
154 #endif // COMMON_LINUX_DWARF_CFI_TO_MODULE_H | |
OLD | NEW |