/thirdparty/breakpad/common/mac/dump_syms.h

http://github.com/tomahawk-player/tomahawk · C Header · 172 lines · 53 code · 24 blank · 95 comment · 1 complexity · 4d73888049810ec97ce32b7425876fcf MD5 · raw file

  1. // -*- mode: c++ -*-
  2. // Copyright (c) 2011, Google Inc.
  3. // All rights reserved.
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // Author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
  31. // dump_syms.h: Declaration of google_breakpad::DumpSymbols, a class for
  32. // reading debugging information from Mach-O files and writing it out as a
  33. // Breakpad symbol file.
  34. #include <Foundation/Foundation.h>
  35. #include <mach-o/loader.h>
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <ostream>
  39. #include <string>
  40. #include <vector>
  41. #include "common/byte_cursor.h"
  42. #include "common/mac/macho_reader.h"
  43. #include "common/module.h"
  44. namespace google_breakpad {
  45. class DumpSymbols {
  46. public:
  47. DumpSymbols()
  48. : input_pathname_(),
  49. object_filename_(),
  50. contents_(),
  51. selected_object_file_(),
  52. selected_object_name_() { }
  53. ~DumpSymbols() {
  54. [input_pathname_ release];
  55. [object_filename_ release];
  56. [contents_ release];
  57. }
  58. // Prepare to read debugging information from |filename|. |filename| may be
  59. // the name of a universal binary, a Mach-O file, or a dSYM bundle
  60. // containing either of the above. On success, return true; if there is a
  61. // problem reading |filename|, report it and return false.
  62. //
  63. // (This class uses NSString for filenames and related values,
  64. // because the Mac Foundation framework seems to support
  65. // filename-related operations more fully on NSString values.)
  66. bool Read(NSString *filename);
  67. // If this dumper's file includes an object file for |cpu_type| and
  68. // |cpu_subtype|, then select that object file for dumping, and return
  69. // true. Otherwise, return false, and leave this dumper's selected
  70. // architecture unchanged.
  71. //
  72. // By default, if this dumper's file contains only one object file, then
  73. // the dumper will dump those symbols; and if it contains more than one
  74. // object file, then the dumper will dump the object file whose
  75. // architecture matches that of this dumper program.
  76. bool SetArchitecture(cpu_type_t cpu_type, cpu_subtype_t cpu_subtype);
  77. // If this dumper's file includes an object file for |arch_name|, then select
  78. // that object file for dumping, and return true. Otherwise, return false,
  79. // and leave this dumper's selected architecture unchanged.
  80. //
  81. // By default, if this dumper's file contains only one object file, then
  82. // the dumper will dump those symbols; and if it contains more than one
  83. // object file, then the dumper will dump the object file whose
  84. // architecture matches that of this dumper program.
  85. bool SetArchitecture(const std::string &arch_name);
  86. // Return a pointer to an array of 'struct fat_arch' structures,
  87. // describing the object files contained in this dumper's file. Set
  88. // *|count| to the number of elements in the array. The returned array is
  89. // owned by this DumpSymbols instance.
  90. //
  91. // If there are no available architectures, this function
  92. // may return NULL.
  93. const struct fat_arch *AvailableArchitectures(size_t *count) {
  94. *count = object_files_.size();
  95. if (object_files_.size() > 0)
  96. return &object_files_[0];
  97. return NULL;
  98. }
  99. // Read the selected object file's debugging information, and write it out to
  100. // |stream|. Write the CFI section if |cfi| is true. Return true on success;
  101. // if an error occurs, report it and return false.
  102. bool WriteSymbolFile(std::ostream &stream, bool cfi);
  103. private:
  104. // Used internally.
  105. class DumperLineToModule;
  106. class LoadCommandDumper;
  107. // Return an identifier string for the file this DumpSymbols is dumping.
  108. std::string Identifier();
  109. // Read debugging information from |dwarf_sections|, which was taken from
  110. // |macho_reader|, and add it to |module|. On success, return true;
  111. // on failure, report the problem and return false.
  112. bool ReadDwarf(google_breakpad::Module *module,
  113. const mach_o::Reader &macho_reader,
  114. const mach_o::SectionMap &dwarf_sections) const;
  115. // Read DWARF CFI or .eh_frame data from |section|, belonging to
  116. // |macho_reader|, and record it in |module|. If |eh_frame| is true,
  117. // then the data is .eh_frame-format data; otherwise, it is standard DWARF
  118. // .debug_frame data. On success, return true; on failure, report
  119. // the problem and return false.
  120. bool ReadCFI(google_breakpad::Module *module,
  121. const mach_o::Reader &macho_reader,
  122. const mach_o::Section &section,
  123. bool eh_frame) const;
  124. // The name of the file or bundle whose symbols this will dump.
  125. // This is the path given to Read, for use in error messages.
  126. NSString *input_pathname_;
  127. // The name of the file this DumpSymbols will actually read debugging
  128. // information from. Normally, this is the same as input_pathname_, but if
  129. // filename refers to a dSYM bundle, then this is the resource file
  130. // within that bundle.
  131. NSString *object_filename_;
  132. // The complete contents of object_filename_, mapped into memory.
  133. NSData *contents_;
  134. // A vector of fat_arch structures describing the object files
  135. // object_filename_ contains. If object_filename_ refers to a fat binary,
  136. // this may have more than one element; if it refers to a Mach-O file, this
  137. // has exactly one element.
  138. vector<struct fat_arch> object_files_;
  139. // The object file in object_files_ selected to dump, or NULL if
  140. // SetArchitecture hasn't been called yet.
  141. const struct fat_arch *selected_object_file_;
  142. // A string that identifies the selected object file, for use in error
  143. // messages. This is usually object_filename_, but if that refers to a
  144. // fat binary, it includes an indication of the particular architecture
  145. // within that binary.
  146. string selected_object_name_;
  147. };
  148. } // namespace google_breakpad