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 23 matching lines...) Expand all Loading... |
34 // dump_syms.mm: Create a symbol file for use with minidumps | 34 // dump_syms.mm: Create a symbol file for use with minidumps |
35 | 35 |
36 #include "common/mac/dump_syms.h" | 36 #include "common/mac/dump_syms.h" |
37 | 37 |
38 #include <assert.h> | 38 #include <assert.h> |
39 #include <dirent.h> | 39 #include <dirent.h> |
40 #include <errno.h> | 40 #include <errno.h> |
41 #include <libgen.h> | 41 #include <libgen.h> |
42 #include <mach-o/arch.h> | 42 #include <mach-o/arch.h> |
43 #include <mach-o/fat.h> | 43 #include <mach-o/fat.h> |
| 44 #include <stdint.h> |
44 #include <stdio.h> | 45 #include <stdio.h> |
45 #include <sys/stat.h> | 46 #include <sys/stat.h> |
46 #include <sys/types.h> | 47 #include <sys/types.h> |
47 #include <unistd.h> | 48 #include <unistd.h> |
48 | 49 |
49 #include <ostream> | 50 #include <ostream> |
50 #include <string> | 51 #include <string> |
51 #include <vector> | 52 #include <vector> |
52 | 53 |
53 #include "common/dwarf/bytereader-inl.h" | 54 #include "common/dwarf/bytereader-inl.h" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 public DwarfCUToModule::LineToModuleHandler { | 310 public DwarfCUToModule::LineToModuleHandler { |
310 public: | 311 public: |
311 // Create a line-to-module converter using BYTE_READER. | 312 // Create a line-to-module converter using BYTE_READER. |
312 DumperLineToModule(dwarf2reader::ByteReader *byte_reader) | 313 DumperLineToModule(dwarf2reader::ByteReader *byte_reader) |
313 : byte_reader_(byte_reader) { } | 314 : byte_reader_(byte_reader) { } |
314 | 315 |
315 void StartCompilationUnit(const string& compilation_dir) { | 316 void StartCompilationUnit(const string& compilation_dir) { |
316 compilation_dir_ = compilation_dir; | 317 compilation_dir_ = compilation_dir; |
317 } | 318 } |
318 | 319 |
319 void ReadProgram(const char *program, uint64 length, | 320 void ReadProgram(const uint8_t *program, uint64 length, |
320 Module *module, vector<Module::Line> *lines) { | 321 Module *module, vector<Module::Line> *lines) { |
321 DwarfLineToModule handler(module, compilation_dir_, lines); | 322 DwarfLineToModule handler(module, compilation_dir_, lines); |
322 dwarf2reader::LineInfo parser(program, length, byte_reader_, &handler); | 323 dwarf2reader::LineInfo parser(program, length, byte_reader_, &handler); |
323 parser.Start(); | 324 parser.Start(); |
324 } | 325 } |
325 private: | 326 private: |
326 string compilation_dir_; | 327 string compilation_dir_; |
327 dwarf2reader::ByteReader *byte_reader_; // WEAK | 328 dwarf2reader::ByteReader *byte_reader_; // WEAK |
328 }; | 329 }; |
329 | 330 |
330 bool DumpSymbols::ReadDwarf(google_breakpad::Module *module, | 331 bool DumpSymbols::ReadDwarf(google_breakpad::Module *module, |
331 const mach_o::Reader &macho_reader, | 332 const mach_o::Reader &macho_reader, |
332 const mach_o::SectionMap &dwarf_sections, | 333 const mach_o::SectionMap &dwarf_sections, |
333 bool handle_inter_cu_refs) const { | 334 bool handle_inter_cu_refs) const { |
334 // Build a byte reader of the appropriate endianness. | 335 // Build a byte reader of the appropriate endianness. |
335 ByteReader byte_reader(macho_reader.big_endian() | 336 ByteReader byte_reader(macho_reader.big_endian() |
336 ? dwarf2reader::ENDIANNESS_BIG | 337 ? dwarf2reader::ENDIANNESS_BIG |
337 : dwarf2reader::ENDIANNESS_LITTLE); | 338 : dwarf2reader::ENDIANNESS_LITTLE); |
338 | 339 |
339 // Construct a context for this file. | 340 // Construct a context for this file. |
340 DwarfCUToModule::FileContext file_context(selected_object_name_, | 341 DwarfCUToModule::FileContext file_context(selected_object_name_, |
341 module, | 342 module, |
342 handle_inter_cu_refs); | 343 handle_inter_cu_refs); |
343 | 344 |
344 // Build a dwarf2reader::SectionMap from our mach_o::SectionMap. | 345 // Build a dwarf2reader::SectionMap from our mach_o::SectionMap. |
345 for (mach_o::SectionMap::const_iterator it = dwarf_sections.begin(); | 346 for (mach_o::SectionMap::const_iterator it = dwarf_sections.begin(); |
346 it != dwarf_sections.end(); ++it) { | 347 it != dwarf_sections.end(); ++it) { |
347 file_context.AddSectionToSectionMap( | 348 file_context.AddSectionToSectionMap( |
348 it->first, | 349 it->first, |
349 reinterpret_cast<const char *>(it->second.contents.start), | 350 it->second.contents.start, |
350 it->second.contents.Size()); | 351 it->second.contents.Size()); |
351 } | 352 } |
352 | 353 |
353 // Find the __debug_info section. | 354 // Find the __debug_info section. |
354 dwarf2reader::SectionMap::const_iterator debug_info_entry = | 355 dwarf2reader::SectionMap::const_iterator debug_info_entry = |
355 file_context.section_map().find("__debug_info"); | 356 file_context.section_map().find("__debug_info"); |
356 assert(debug_info_entry != file_context.section_map().end()); | 357 assert(debug_info_entry != file_context.section_map().end()); |
357 const std::pair<const char*, uint64>& debug_info_section = | 358 const std::pair<const uint8_t *, uint64>& debug_info_section = |
358 debug_info_entry->second; | 359 debug_info_entry->second; |
359 // There had better be a __debug_info section! | 360 // There had better be a __debug_info section! |
360 if (!debug_info_section.first) { | 361 if (!debug_info_section.first) { |
361 fprintf(stderr, "%s: __DWARF segment of file has no __debug_info section\n", | 362 fprintf(stderr, "%s: __DWARF segment of file has no __debug_info section\n", |
362 selected_object_name_.c_str()); | 363 selected_object_name_.c_str()); |
363 return false; | 364 return false; |
364 } | 365 } |
365 | 366 |
366 // Build a line-to-module loader for the root handler to use. | 367 // Build a line-to-module loader for the root handler to use. |
367 DumperLineToModule line_to_module(&byte_reader); | 368 DumperLineToModule line_to_module(&byte_reader); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 fprintf(stderr, "architecture '%s'", arch->name); | 418 fprintf(stderr, "architecture '%s'", arch->name); |
418 else | 419 else |
419 fprintf(stderr, "architecture %d,%d", | 420 fprintf(stderr, "architecture %d,%d", |
420 macho_reader.cpu_type(), macho_reader.cpu_subtype()); | 421 macho_reader.cpu_type(), macho_reader.cpu_subtype()); |
421 fprintf(stderr, " to Breakpad symbol file: no register name table\n"); | 422 fprintf(stderr, " to Breakpad symbol file: no register name table\n"); |
422 return false; | 423 return false; |
423 } | 424 } |
424 } | 425 } |
425 | 426 |
426 // Find the call frame information and its size. | 427 // Find the call frame information and its size. |
427 const char *cfi = reinterpret_cast<const char *>(section.contents.start); | 428 const uint8_t *cfi = section.contents.start; |
428 size_t cfi_size = section.contents.Size(); | 429 size_t cfi_size = section.contents.Size(); |
429 | 430 |
430 // Plug together the parser, handler, and their entourages. | 431 // Plug together the parser, handler, and their entourages. |
431 DwarfCFIToModule::Reporter module_reporter(selected_object_name_, | 432 DwarfCFIToModule::Reporter module_reporter(selected_object_name_, |
432 section.section_name); | 433 section.section_name); |
433 DwarfCFIToModule handler(module, register_names, &module_reporter); | 434 DwarfCFIToModule handler(module, register_names, &module_reporter); |
434 dwarf2reader::ByteReader byte_reader(macho_reader.big_endian() ? | 435 dwarf2reader::ByteReader byte_reader(macho_reader.big_endian() ? |
435 dwarf2reader::ENDIANNESS_BIG : | 436 dwarf2reader::ENDIANNESS_BIG : |
436 dwarf2reader::ENDIANNESS_LITTLE); | 437 dwarf2reader::ENDIANNESS_LITTLE); |
437 byte_reader.SetAddressSize(macho_reader.bits_64() ? 8 : 4); | 438 byte_reader.SetAddressSize(macho_reader.bits_64() ? 8 : 4); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 if (ReadSymbolData(&module) && module) { | 618 if (ReadSymbolData(&module) && module) { |
618 bool res = module->Write(stream, symbol_data_); | 619 bool res = module->Write(stream, symbol_data_); |
619 delete module; | 620 delete module; |
620 return res; | 621 return res; |
621 } | 622 } |
622 | 623 |
623 return false; | 624 return false; |
624 } | 625 } |
625 | 626 |
626 } // namespace google_breakpad | 627 } // namespace google_breakpad |
OLD | NEW |