Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 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 // dump_syms_tool.mm: Command line tool that uses the DumpSymbols class. | 32 // dump_syms_tool.cc: Command line tool that uses the DumpSymbols class. |
| 33 // TODO(waylonis): accept stdin | 33 // TODO(waylonis): accept stdin |
| 34 | 34 |
| 35 #include <mach-o/arch.h> | 35 #include <mach-o/arch.h> |
| 36 #include <unistd.h> | 36 #include <unistd.h> |
| 37 | 37 |
| 38 #include <iostream> | 38 #include <iostream> |
| 39 #include <vector> | 39 #include <vector> |
| 40 | 40 |
| 41 #include "common/mac/dump_syms.h" | 41 #include "common/mac/dump_syms.h" |
| 42 #include "common/mac/arch_utilities.h" | 42 #include "common/mac/arch_utilities.h" |
| 43 #include "common/mac/macho_utilities.h" | 43 #include "common/mac/macho_utilities.h" |
| 44 #include "common/scoped_ptr.h" | 44 #include "common/scoped_ptr.h" |
| 45 | 45 |
| 46 using google_breakpad::DumpSymbols; | 46 using google_breakpad::DumpSymbols; |
| 47 using google_breakpad::Module; | 47 using google_breakpad::Module; |
| 48 using google_breakpad::scoped_ptr; | 48 using google_breakpad::scoped_ptr; |
| 49 using std::vector; | 49 using std::vector; |
| 50 | 50 |
| 51 struct Options { | 51 struct Options { |
| 52 Options() | 52 Options() |
| 53 : srcPath(), dsymPath(), arch(), cfi(true), handle_inter_cu_refs(true) {} | 53 : srcPath(), dsymPath(), arch(), cfi(true), handle_inter_cu_refs(true) {} |
| 54 NSString *srcPath; | 54 |
| 55 NSString *dsymPath; | 55 string srcPath; |
| 56 string dsymPath; | |
| 56 const NXArchInfo *arch; | 57 const NXArchInfo *arch; |
| 57 bool cfi; | 58 bool cfi; |
| 58 bool handle_inter_cu_refs; | 59 bool handle_inter_cu_refs; |
| 59 }; | 60 }; |
| 60 | 61 |
| 61 static bool StackFrameEntryComparator(const Module::StackFrameEntry* a, | 62 static bool StackFrameEntryComparator(const Module::StackFrameEntry* a, |
| 62 const Module::StackFrameEntry* b) { | 63 const Module::StackFrameEntry* b) { |
| 63 return a->address < b->address; | 64 return a->address < b->address; |
| 64 } | 65 } |
| 65 | 66 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 | 109 |
| 109 // For x86_64 binaries, the CFI data is in the __TEXT,__eh_frame of the | 110 // For x86_64 binaries, the CFI data is in the __TEXT,__eh_frame of the |
| 110 // Mach-O file, which is not copied into the dSYM. Whereas in i386, the CFI | 111 // Mach-O file, which is not copied into the dSYM. Whereas in i386, the CFI |
| 111 // data is in the __DWARF,__debug_frame section, which is moved into the | 112 // data is in the __DWARF,__debug_frame section, which is moved into the |
| 112 // dSYM. Therefore, to get x86_64 CFI data, dump_syms needs to look at both | 113 // dSYM. Therefore, to get x86_64 CFI data, dump_syms needs to look at both |
| 113 // the dSYM and the Mach-O file. If both paths are present and CFI was | 114 // the dSYM and the Mach-O file. If both paths are present and CFI was |
| 114 // requested, then consider the Module as "split" and dump all the debug data | 115 // requested, then consider the Module as "split" and dump all the debug data |
| 115 // from the primary debug info file, the dSYM, and then dump additional CFI | 116 // from the primary debug info file, the dSYM, and then dump additional CFI |
| 116 // data from the source Mach-O file. | 117 // data from the source Mach-O file. |
| 117 bool split_module = options.dsymPath && options.srcPath && options.cfi; | 118 bool split_module = options.dsymPath && options.srcPath && options.cfi; |
| 118 NSString* primary_file = split_module ? options.dsymPath : options.srcPath; | 119 string primary_file = split_module ? options.dsymPath : options.srcPath; |
|
Mark Mentovai
2015/09/11 15:49:51
const string&
Ted Mielczarek
2015/09/15 12:58:36
Done.
| |
| 119 | 120 |
| 120 if (!dump_symbols.Read(primary_file)) | 121 if (!dump_symbols.Read(primary_file)) |
| 121 return false; | 122 return false; |
| 122 | 123 |
| 123 if (options.arch) { | 124 if (options.arch) { |
| 124 if (!dump_symbols.SetArchitecture(options.arch->cputype, | 125 if (!dump_symbols.SetArchitecture(options.arch->cputype, |
| 125 options.arch->cpusubtype)) { | 126 options.arch->cpusubtype)) { |
| 126 fprintf(stderr, "%s: no architecture '%s' is present in file.\n", | 127 fprintf(stderr, "%s: no architecture '%s' is present in file.\n", |
| 127 [primary_file fileSystemRepresentation], options.arch->name); | 128 primary_file.c_str(), options.arch->name); |
| 128 size_t available_size; | 129 size_t available_size; |
| 129 const SuperFatArch *available = | 130 const SuperFatArch *available = |
| 130 dump_symbols.AvailableArchitectures(&available_size); | 131 dump_symbols.AvailableArchitectures(&available_size); |
| 131 if (available_size == 1) | 132 if (available_size == 1) |
| 132 fprintf(stderr, "the file's architecture is: "); | 133 fprintf(stderr, "the file's architecture is: "); |
| 133 else | 134 else |
| 134 fprintf(stderr, "architectures present in the file are:\n"); | 135 fprintf(stderr, "architectures present in the file are:\n"); |
| 135 for (size_t i = 0; i < available_size; i++) { | 136 for (size_t i = 0; i < available_size; i++) { |
| 136 const SuperFatArch *arch = &available[i]; | 137 const SuperFatArch *arch = &available[i]; |
| 137 const NXArchInfo *arch_info = | 138 const NXArchInfo *arch_info = |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 google_breakpad::BreakpadGetArchInfoFromName(optarg); | 208 google_breakpad::BreakpadGetArchInfoFromName(optarg); |
| 208 if (!arch_info) { | 209 if (!arch_info) { |
| 209 fprintf(stderr, "%s: Invalid architecture: %s\n", argv[0], optarg); | 210 fprintf(stderr, "%s: Invalid architecture: %s\n", argv[0], optarg); |
| 210 Usage(argc, argv); | 211 Usage(argc, argv); |
| 211 exit(1); | 212 exit(1); |
| 212 } | 213 } |
| 213 options->arch = arch_info; | 214 options->arch = arch_info; |
| 214 break; | 215 break; |
| 215 } | 216 } |
| 216 case 'g': | 217 case 'g': |
| 217 options->dsymPath = [[NSFileManager defaultManager] | 218 options->dsymPath = optarg; |
| 218 stringWithFileSystemRepresentation:optarg length:strlen(optarg)]; | |
| 219 break; | 219 break; |
| 220 case 'c': | 220 case 'c': |
| 221 options->cfi = false; | 221 options->cfi = false; |
| 222 break; | 222 break; |
| 223 case 'r': | 223 case 'r': |
| 224 options->handle_inter_cu_refs = false; | 224 options->handle_inter_cu_refs = false; |
| 225 break; | 225 break; |
| 226 case '?': | 226 case '?': |
| 227 case 'h': | 227 case 'h': |
| 228 Usage(argc, argv); | 228 Usage(argc, argv); |
| 229 exit(0); | 229 exit(0); |
| 230 break; | 230 break; |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 | 233 |
| 234 if ((argc - optind) != 1) { | 234 if ((argc - optind) != 1) { |
| 235 fprintf(stderr, "Must specify Mach-o file\n"); | 235 fprintf(stderr, "Must specify Mach-o file\n"); |
| 236 Usage(argc, argv); | 236 Usage(argc, argv); |
| 237 exit(1); | 237 exit(1); |
| 238 } | 238 } |
| 239 | 239 |
| 240 options->srcPath = [[NSFileManager defaultManager] | 240 options->srcPath = argv[optind]; |
| 241 stringWithFileSystemRepresentation:argv[optind] | |
| 242 length:strlen(argv[optind])]; | |
| 243 } | 241 } |
| 244 | 242 |
| 245 //============================================================================= | 243 //============================================================================= |
| 246 int main (int argc, const char * argv[]) { | 244 int main (int argc, const char * argv[]) { |
| 247 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
| 248 Options options; | 245 Options options; |
| 249 bool result; | 246 bool result; |
| 250 | 247 |
| 251 SetupOptions(argc, argv, &options); | 248 SetupOptions(argc, argv, &options); |
| 252 result = Start(options); | 249 result = Start(options); |
| 253 | 250 |
| 254 [pool release]; | |
| 255 | |
| 256 return !result; | 251 return !result; |
| 257 } | 252 } |
| OLD | NEW |