| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "common/mac/macho_utilities.h" | 44 #include "common/mac/macho_utilities.h" |
| 45 #include "common/scoped_ptr.h" | 45 #include "common/scoped_ptr.h" |
| 46 | 46 |
| 47 using google_breakpad::DumpSymbols; | 47 using google_breakpad::DumpSymbols; |
| 48 using google_breakpad::Module; | 48 using google_breakpad::Module; |
| 49 using google_breakpad::scoped_ptr; | 49 using google_breakpad::scoped_ptr; |
| 50 using std::vector; | 50 using std::vector; |
| 51 | 51 |
| 52 struct Options { | 52 struct Options { |
| 53 Options() | 53 Options() |
| 54 : srcPath(), dsymPath(), arch(), cfi(true), handle_inter_cu_refs(true) {} | 54 : srcPath(), dsymPath(), arch(), header_only(false), |
| 55 cfi(true), handle_inter_cu_refs(true) {} |
| 55 | 56 |
| 56 string srcPath; | 57 string srcPath; |
| 57 string dsymPath; | 58 string dsymPath; |
| 58 const NXArchInfo *arch; | 59 const NXArchInfo *arch; |
| 60 bool header_only; |
| 59 bool cfi; | 61 bool cfi; |
| 60 bool handle_inter_cu_refs; | 62 bool handle_inter_cu_refs; |
| 61 }; | 63 }; |
| 62 | 64 |
| 63 static bool StackFrameEntryComparator(const Module::StackFrameEntry* a, | 65 static bool StackFrameEntryComparator(const Module::StackFrameEntry* a, |
| 64 const Module::StackFrameEntry* b) { | 66 const Module::StackFrameEntry* b) { |
| 65 return a->address < b->address; | 67 return a->address < b->address; |
| 66 } | 68 } |
| 67 | 69 |
| 68 // Copy the CFI data from |from_module| into |to_module|, for any non- | 70 // Copy the CFI data from |from_module| into |to_module|, for any non- |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 if (arch_info) | 146 if (arch_info) |
| 145 fprintf(stderr, "%s (%s)\n", arch_info->name, arch_info->description); | 147 fprintf(stderr, "%s (%s)\n", arch_info->name, arch_info->description); |
| 146 else | 148 else |
| 147 fprintf(stderr, "unrecognized cpu type 0x%x, subtype 0x%x\n", | 149 fprintf(stderr, "unrecognized cpu type 0x%x, subtype 0x%x\n", |
| 148 arch->cputype, arch->cpusubtype); | 150 arch->cputype, arch->cpusubtype); |
| 149 } | 151 } |
| 150 return false; | 152 return false; |
| 151 } | 153 } |
| 152 } | 154 } |
| 153 | 155 |
| 156 if (options.header_only) |
| 157 return dump_symbols.WriteSymbolFileHeader(std::cout); |
| 158 |
| 154 // Read the primary file into a Breakpad Module. | 159 // Read the primary file into a Breakpad Module. |
| 155 Module* module = NULL; | 160 Module* module = NULL; |
| 156 if (!dump_symbols.ReadSymbolData(&module)) | 161 if (!dump_symbols.ReadSymbolData(&module)) |
| 157 return false; | 162 return false; |
| 158 scoped_ptr<Module> scoped_module(module); | 163 scoped_ptr<Module> scoped_module(module); |
| 159 | 164 |
| 160 // If this is a split module, read the secondary Mach-O file, from which the | 165 // If this is a split module, read the secondary Mach-O file, from which the |
| 161 // CFI data will be extracted. | 166 // CFI data will be extracted. |
| 162 if (split_module && primary_file == options.dsymPath) { | 167 if (split_module && primary_file == options.dsymPath) { |
| 163 if (!dump_symbols.Read(options.srcPath)) | 168 if (!dump_symbols.Read(options.srcPath)) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 182 } | 187 } |
| 183 | 188 |
| 184 return module->Write(std::cout, symbol_data); | 189 return module->Write(std::cout, symbol_data); |
| 185 } | 190 } |
| 186 | 191 |
| 187 //============================================================================= | 192 //============================================================================= |
| 188 static void Usage(int argc, const char *argv[]) { | 193 static void Usage(int argc, const char *argv[]) { |
| 189 fprintf(stderr, "Output a Breakpad symbol file from a Mach-o file.\n"); | 194 fprintf(stderr, "Output a Breakpad symbol file from a Mach-o file.\n"); |
| 190 fprintf(stderr, "Usage: %s [-a ARCHITECTURE] [-c] [-g dSYM path] " | 195 fprintf(stderr, "Usage: %s [-a ARCHITECTURE] [-c] [-g dSYM path] " |
| 191 "<Mach-o file>\n", argv[0]); | 196 "<Mach-o file>\n", argv[0]); |
| 197 fprintf(stderr, "\t-i: Output module header information only.\n"); |
| 192 fprintf(stderr, "\t-a: Architecture type [default: native, or whatever is\n"); | 198 fprintf(stderr, "\t-a: Architecture type [default: native, or whatever is\n"); |
| 193 fprintf(stderr, "\t in the file, if it contains only one architecture]\n"); | 199 fprintf(stderr, "\t in the file, if it contains only one architecture]\n"); |
| 194 fprintf(stderr, "\t-g: Debug symbol file (dSYM) to dump in addition to the " | 200 fprintf(stderr, "\t-g: Debug symbol file (dSYM) to dump in addition to the " |
| 195 "Mach-o file\n"); | 201 "Mach-o file\n"); |
| 196 fprintf(stderr, "\t-c: Do not generate CFI section\n"); | 202 fprintf(stderr, "\t-c: Do not generate CFI section\n"); |
| 197 fprintf(stderr, "\t-r: Do not handle inter-compilation unit references\n"); | 203 fprintf(stderr, "\t-r: Do not handle inter-compilation unit references\n"); |
| 198 fprintf(stderr, "\t-h: Usage\n"); | 204 fprintf(stderr, "\t-h: Usage\n"); |
| 199 fprintf(stderr, "\t-?: Usage\n"); | 205 fprintf(stderr, "\t-?: Usage\n"); |
| 200 } | 206 } |
| 201 | 207 |
| 202 //============================================================================= | 208 //============================================================================= |
| 203 static void SetupOptions(int argc, const char *argv[], Options *options) { | 209 static void SetupOptions(int argc, const char *argv[], Options *options) { |
| 204 extern int optind; | 210 extern int optind; |
| 205 signed char ch; | 211 signed char ch; |
| 206 | 212 |
| 207 while ((ch = getopt(argc, (char * const *)argv, "a:g:chr?")) != -1) { | 213 while ((ch = getopt(argc, (char * const *)argv, "ia:g:chr?")) != -1) { |
| 208 switch (ch) { | 214 switch (ch) { |
| 215 case 'i': |
| 216 options->header_only = true; |
| 217 break; |
| 209 case 'a': { | 218 case 'a': { |
| 210 const NXArchInfo *arch_info = | 219 const NXArchInfo *arch_info = |
| 211 google_breakpad::BreakpadGetArchInfoFromName(optarg); | 220 google_breakpad::BreakpadGetArchInfoFromName(optarg); |
| 212 if (!arch_info) { | 221 if (!arch_info) { |
| 213 fprintf(stderr, "%s: Invalid architecture: %s\n", argv[0], optarg); | 222 fprintf(stderr, "%s: Invalid architecture: %s\n", argv[0], optarg); |
| 214 Usage(argc, argv); | 223 Usage(argc, argv); |
| 215 exit(1); | 224 exit(1); |
| 216 } | 225 } |
| 217 options->arch = arch_info; | 226 options->arch = arch_info; |
| 218 break; | 227 break; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 246 //============================================================================= | 255 //============================================================================= |
| 247 int main (int argc, const char * argv[]) { | 256 int main (int argc, const char * argv[]) { |
| 248 Options options; | 257 Options options; |
| 249 bool result; | 258 bool result; |
| 250 | 259 |
| 251 SetupOptions(argc, argv, &options); | 260 SetupOptions(argc, argv, &options); |
| 252 result = Start(options); | 261 result = Start(options); |
| 253 | 262 |
| 254 return !result; | 263 return !result; |
| 255 } | 264 } |
| OLD | NEW |