aboutsummaryrefslogtreecommitdiff
path: root/src/common/mac/dump_syms.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/mac/dump_syms.h')
-rw-r--r--src/common/mac/dump_syms.h180
1 files changed, 131 insertions, 49 deletions
diff --git a/src/common/mac/dump_syms.h b/src/common/mac/dump_syms.h
index 1acaf44a..f2bee657 100644
--- a/src/common/mac/dump_syms.h
+++ b/src/common/mac/dump_syms.h
@@ -1,4 +1,6 @@
-// Copyright (c) 2006, Google Inc.
+// -*- mode: c++ -*-
+
+// Copyright (c) 2010, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -27,53 +29,133 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// dump_syms.h: Interface for DumpSymbols. This class will take a mach-o file
-// and extract the symbol information and write it to a file using the
-// breakpad symbol file format.
+// Author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
+
+// dump_syms.h: Declaration of google_breakpad::DumpSymbols, a class for
+// reading debugging information from Mach-O files and writing it out as a
+// Breakpad symbol file.
-#import <Foundation/Foundation.h>
+#include <Foundation/Foundation.h>
#include <mach-o/loader.h>
-#include "common/dwarf/dwarf2reader.h"
-
-// This will map from an architecture string to a SectionMap, which
-// will contain the offsets for all the sections in the dictionary
-typedef map<string, dwarf2reader::SectionMap *> ArchSectionMap;
-
-@interface DumpSymbols : NSObject {
- @protected
- NSString *sourcePath_; // Source of symbols (STRONG)
- NSString *architecture_; // Architecture to extract (STRONG)
- NSMutableDictionary *addresses_; // Addresses and symbols (STRONG)
- NSMutableSet *functionAddresses_; // Function addresses (STRONG)
- NSMutableDictionary *sources_; // Address and Source file paths (STRONG)
- NSMutableDictionary *headers_; // Mach-o header information (STRONG)
- NSMutableDictionary *sectionData_; // Keyed by seg/sect name (STRONG)
- uint32_t lastStartAddress_;
- ArchSectionMap *sectionsForArch_;
-}
-
-- (id)initWithContentsOfFile:(NSString *)machoFile;
-
-- (NSArray *)availableArchitectures;
-
-// One of ppc, x86, i386, ppc64, x86_64
-// If the architecture is not available, it will return NO
-// If not set, the native architecture will be used
-- (BOOL)setArchitecture:(NSString *)architecture;
-- (NSString *)architecture;
-
-// Write the symbols to |symbolFilePath|. Return YES if successful.
-- (BOOL)writeSymbolFile:(NSString *)symbolFilePath;
-
-@end
-
-@interface MachSection : NSObject {
- @protected
- struct section *sect_;
- uint32_t sectionNumber_;
-}
-- (id)initWithMachSection:(struct section *)sect andNumber:(uint32_t)sectionNumber;
-- (struct section*)sectionPointer;
-- (uint32_t)sectionNumber;
-
-@end
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <string>
+#include <vector>
+
+#include "common/byte_cursor.h"
+#include "common/mac/macho_reader.h"
+#include "common/module.h"
+
+namespace google_breakpad {
+
+class DumpSymbols {
+ public:
+ DumpSymbols()
+ : input_pathname_(),
+ object_filename_(),
+ contents_(),
+ selected_object_file_(),
+ selected_object_name_() { }
+ ~DumpSymbols() {
+ [input_pathname_ release];
+ [object_filename_ release];
+ [contents_ release];
+ }
+
+ // Prepare to read debugging information from |filename|. |filename| may be
+ // the name of a universal binary, a Mach-O file, or a dSYM bundle
+ // containing either of the above. On success, return true; if there is a
+ // problem reading |filename|, report it and return false.
+ //
+ // (This class uses NSString for filenames and related values,
+ // because the Mac Foundation framework seems to support
+ // filename-related operations more fully on NSString values.)
+ bool Read(NSString *filename);
+
+ // If this dumper's file includes an object file for |cpu_type| and
+ // |cpu_subtype|, then select that object file for dumping, and return
+ // true. Otherwise, return false, and leave this dumper's selected
+ // architecture unchanged.
+ //
+ // By default, if this dumper's file contains only one object file, then
+ // the dumper will dump those symbols; and if it contains more than one
+ // object file, then the dumper will dump the object file whose
+ // architecture matches that of this dumper program.
+ bool SetArchitecture(cpu_type_t cpu_type, cpu_subtype_t cpu_subtype);
+
+ // Return a pointer to an array of 'struct fat_arch' structures,
+ // describing the object files contained in this dumper's file. Set
+ // *|count| to the number of elements in the array. The returned array is
+ // owned by this DumpSymbols instance.
+ //
+ // If there are no available architectures, this function
+ // may return NULL.
+ const struct fat_arch *AvailableArchitectures(size_t *count) {
+ *count = object_files_.size();
+ if (object_files_.size() > 0)
+ return &object_files_[0];
+ return NULL;
+ }
+
+ // Read the selected object file's debugging information, and write it
+ // out to |stream|. Return true on success; if an error occurs, report it
+ // and return false.
+ bool WriteSymbolFile(FILE *stream);
+
+ private:
+ // Used internally.
+ class DumperLineToModule;
+ class LoadCommandDumper;
+
+ // Return an identifier string for the file this DumpSymbols is dumping.
+ std::string Identifier();
+
+ // Read debugging information from |dwarf_sections|, which was taken from
+ // |macho_reader|, and add it to |module|. On success, return true;
+ // on failure, report the problem and return false.
+ bool ReadDwarf(google_breakpad::Module *module,
+ const mach_o::Reader &macho_reader,
+ const mach_o::SectionMap &dwarf_sections) const;
+
+ // Read DWARF CFI or .eh_frame data from |section|, belonging to
+ // |macho_reader|, and record it in |module|. If |eh_frame| is true,
+ // then the data is .eh_frame-format data; otherwise, it is standard DWARF
+ // .debug_frame data. On success, return true; on failure, report
+ // the problem and return false.
+ bool ReadCFI(google_breakpad::Module *module,
+ const mach_o::Reader &macho_reader,
+ const mach_o::Section &section,
+ bool eh_frame) const;
+
+ // The name of the file or bundle whose symbols this will dump.
+ // This is the path given to Read, for use in error messages.
+ NSString *input_pathname_;
+
+ // The name of the file this DumpSymbols will actually read debugging
+ // information from. Normally, this is the same as input_pathname_, but if
+ // filename refers to a dSYM bundle, then this is the resource file
+ // within that bundle.
+ NSString *object_filename_;
+
+ // The complete contents of object_filename_, mapped into memory.
+ NSData *contents_;
+
+ // A vector of fat_arch structures describing the object files
+ // object_filename_ contains. If object_filename_ refers to a fat binary,
+ // this may have more than one element; if it refers to a Mach-O file, this
+ // has exactly one element.
+ vector<struct fat_arch> object_files_;
+
+ // The object file in object_files_ selected to dump, or NULL if
+ // SetArchitecture hasn't been called yet.
+ const struct fat_arch *selected_object_file_;
+
+ // A string that identifies the selected object file, for use in error
+ // messages. This is usually object_filename_, but if that refers to a
+ // fat binary, it includes an indication of the particular architecture
+ // within that binary.
+ string selected_object_name_;
+};
+
+} // namespace google_breakpad