OLD | NEW |
1 // -*- mode: c++ -*- | 1 // -*- mode: c++ -*- |
2 | 2 |
3 // Copyright (c) 2011, Google Inc. | 3 // Copyright (c) 2011, Google Inc. |
4 // All rights reserved. | 4 // All rights reserved. |
5 // | 5 // |
6 // Redistribution and use in source and binary forms, with or without | 6 // Redistribution and use in source and binary forms, with or without |
7 // modification, are permitted provided that the following conditions are | 7 // modification, are permitted provided that the following conditions are |
8 // met: | 8 // met: |
9 // | 9 // |
10 // * Redistributions of source code must retain the above copyright | 10 // * Redistributions of source code must retain the above copyright |
(...skipping 17 matching lines...) Expand all Loading... |
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | 31 |
32 // Author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> | 32 // Author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> |
33 | 33 |
34 // dump_syms.h: Declaration of google_breakpad::DumpSymbols, a class for | 34 // dump_syms.h: Declaration of google_breakpad::DumpSymbols, a class for |
35 // reading debugging information from Mach-O files and writing it out as a | 35 // reading debugging information from Mach-O files and writing it out as a |
36 // Breakpad symbol file. | 36 // Breakpad symbol file. |
37 | 37 |
38 #include <Foundation/Foundation.h> | |
39 #include <mach-o/loader.h> | 38 #include <mach-o/loader.h> |
40 #include <stdio.h> | 39 #include <stdio.h> |
41 #include <stdlib.h> | 40 #include <stdlib.h> |
42 | 41 |
43 #include <ostream> | 42 #include <ostream> |
44 #include <string> | 43 #include <string> |
45 #include <vector> | 44 #include <vector> |
46 | 45 |
47 #include "common/byte_cursor.h" | 46 #include "common/byte_cursor.h" |
48 #include "common/mac/macho_reader.h" | 47 #include "common/mac/macho_reader.h" |
49 #include "common/mac/super_fat_arch.h" | 48 #include "common/mac/super_fat_arch.h" |
50 #include "common/module.h" | 49 #include "common/module.h" |
| 50 #include "common/scoped_ptr.h" |
51 #include "common/symbol_data.h" | 51 #include "common/symbol_data.h" |
52 | 52 |
53 namespace google_breakpad { | 53 namespace google_breakpad { |
54 | 54 |
55 class DumpSymbols { | 55 class DumpSymbols { |
56 public: | 56 public: |
57 DumpSymbols(SymbolData symbol_data, bool handle_inter_cu_refs) | 57 DumpSymbols(SymbolData symbol_data, bool handle_inter_cu_refs) |
58 : symbol_data_(symbol_data), | 58 : symbol_data_(symbol_data), |
59 handle_inter_cu_refs_(handle_inter_cu_refs), | 59 handle_inter_cu_refs_(handle_inter_cu_refs), |
60 input_pathname_(), | 60 input_pathname_(), |
61 object_filename_(), | 61 object_filename_(), |
62 contents_(), | 62 contents_(), |
63 object_files_(), | 63 object_files_(), |
64 selected_object_file_(), | 64 selected_object_file_(), |
65 selected_object_name_() { } | 65 selected_object_name_() { } |
66 ~DumpSymbols() { | 66 ~DumpSymbols() { |
67 [input_pathname_ release]; | |
68 [object_filename_ release]; | |
69 [contents_ release]; | |
70 } | 67 } |
71 | 68 |
72 // Prepare to read debugging information from |filename|. |filename| may be | 69 // Prepare to read debugging information from |filename|. |filename| may be |
73 // the name of a universal binary, a Mach-O file, or a dSYM bundle | 70 // the name of a universal binary, a Mach-O file, or a dSYM bundle |
74 // containing either of the above. On success, return true; if there is a | 71 // containing either of the above. On success, return true; if there is a |
75 // problem reading |filename|, report it and return false. | 72 // problem reading |filename|, report it and return false. |
76 // | 73 bool Read(const std::string &filename); |
77 // (This class uses NSString for filenames and related values, | |
78 // because the Mac Foundation framework seems to support | |
79 // filename-related operations more fully on NSString values.) | |
80 bool Read(NSString *filename); | |
81 | 74 |
82 // If this dumper's file includes an object file for |cpu_type| and | 75 // If this dumper's file includes an object file for |cpu_type| and |
83 // |cpu_subtype|, then select that object file for dumping, and return | 76 // |cpu_subtype|, then select that object file for dumping, and return |
84 // true. Otherwise, return false, and leave this dumper's selected | 77 // true. Otherwise, return false, and leave this dumper's selected |
85 // architecture unchanged. | 78 // architecture unchanged. |
86 // | 79 // |
87 // By default, if this dumper's file contains only one object file, then | 80 // By default, if this dumper's file contains only one object file, then |
88 // the dumper will dump those symbols; and if it contains more than one | 81 // the dumper will dump those symbols; and if it contains more than one |
89 // object file, then the dumper will dump the object file whose | 82 // object file, then the dumper will dump the object file whose |
90 // architecture matches that of this dumper program. | 83 // architecture matches that of this dumper program. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 bool eh_frame) const; | 149 bool eh_frame) const; |
157 | 150 |
158 // The selection of what type of symbol data to read/write. | 151 // The selection of what type of symbol data to read/write. |
159 const SymbolData symbol_data_; | 152 const SymbolData symbol_data_; |
160 | 153 |
161 // Whether to handle references between compilation units. | 154 // Whether to handle references between compilation units. |
162 const bool handle_inter_cu_refs_; | 155 const bool handle_inter_cu_refs_; |
163 | 156 |
164 // The name of the file or bundle whose symbols this will dump. | 157 // The name of the file or bundle whose symbols this will dump. |
165 // This is the path given to Read, for use in error messages. | 158 // This is the path given to Read, for use in error messages. |
166 NSString *input_pathname_; | 159 std::string input_pathname_; |
167 | 160 |
168 // The name of the file this DumpSymbols will actually read debugging | 161 // The name of the file this DumpSymbols will actually read debugging |
169 // information from. Normally, this is the same as input_pathname_, but if | 162 // information from. Normally, this is the same as input_pathname_, but if |
170 // filename refers to a dSYM bundle, then this is the resource file | 163 // filename refers to a dSYM bundle, then this is the resource file |
171 // within that bundle. | 164 // within that bundle. |
172 NSString *object_filename_; | 165 std::string object_filename_; |
173 | 166 |
174 // The complete contents of object_filename_, mapped into memory. | 167 // The complete contents of object_filename_, mapped into memory. |
175 NSData *contents_; | 168 scoped_array<uint8_t> contents_; |
176 | 169 |
177 // A vector of SuperFatArch structures describing the object files | 170 // A vector of SuperFatArch structures describing the object files |
178 // object_filename_ contains. If object_filename_ refers to a fat binary, | 171 // object_filename_ contains. If object_filename_ refers to a fat binary, |
179 // this may have more than one element; if it refers to a Mach-O file, this | 172 // this may have more than one element; if it refers to a Mach-O file, this |
180 // has exactly one element. | 173 // has exactly one element. |
181 vector<SuperFatArch> object_files_; | 174 vector<SuperFatArch> object_files_; |
182 | 175 |
183 // The object file in object_files_ selected to dump, or NULL if | 176 // The object file in object_files_ selected to dump, or NULL if |
184 // SetArchitecture hasn't been called yet. | 177 // SetArchitecture hasn't been called yet. |
185 const SuperFatArch *selected_object_file_; | 178 const SuperFatArch *selected_object_file_; |
186 | 179 |
187 // A string that identifies the selected object file, for use in error | 180 // A string that identifies the selected object file, for use in error |
188 // messages. This is usually object_filename_, but if that refers to a | 181 // messages. This is usually object_filename_, but if that refers to a |
189 // fat binary, it includes an indication of the particular architecture | 182 // fat binary, it includes an indication of the particular architecture |
190 // within that binary. | 183 // within that binary. |
191 string selected_object_name_; | 184 string selected_object_name_; |
192 }; | 185 }; |
193 | 186 |
194 } // namespace google_breakpad | 187 } // namespace google_breakpad |
OLD | NEW |