toolkit/crashreporter/google-breakpad/src/common/mac/dump_syms.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/common/mac/dump_syms.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,182 @@
     1.4 +// -*- mode: c++ -*-
     1.5 +
     1.6 +// Copyright (c) 2011, Google Inc.
     1.7 +// All rights reserved.
     1.8 +//
     1.9 +// Redistribution and use in source and binary forms, with or without
    1.10 +// modification, are permitted provided that the following conditions are
    1.11 +// met:
    1.12 +//
    1.13 +//     * Redistributions of source code must retain the above copyright
    1.14 +// notice, this list of conditions and the following disclaimer.
    1.15 +//     * Redistributions in binary form must reproduce the above
    1.16 +// copyright notice, this list of conditions and the following disclaimer
    1.17 +// in the documentation and/or other materials provided with the
    1.18 +// distribution.
    1.19 +//     * Neither the name of Google Inc. nor the names of its
    1.20 +// contributors may be used to endorse or promote products derived from
    1.21 +// this software without specific prior written permission.
    1.22 +//
    1.23 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.24 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.25 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.26 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.27 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.28 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.29 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.30 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.31 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.32 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.33 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.34 +
    1.35 +// Author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
    1.36 +
    1.37 +// dump_syms.h: Declaration of google_breakpad::DumpSymbols, a class for
    1.38 +// reading debugging information from Mach-O files and writing it out as a
    1.39 +// Breakpad symbol file.
    1.40 +
    1.41 +#include <Foundation/Foundation.h>
    1.42 +#include <mach-o/loader.h>
    1.43 +#include <stdio.h>
    1.44 +#include <stdlib.h>
    1.45 +
    1.46 +#include <ostream>
    1.47 +#include <string>
    1.48 +#include <vector>
    1.49 +
    1.50 +#include "common/byte_cursor.h"
    1.51 +#include "common/mac/macho_reader.h"
    1.52 +#include "common/module.h"
    1.53 +#include "common/symbol_data.h"
    1.54 +
    1.55 +namespace google_breakpad {
    1.56 +
    1.57 +class DumpSymbols {
    1.58 + public:
    1.59 +  explicit DumpSymbols(SymbolData symbol_data)
    1.60 +      : symbol_data_(symbol_data),
    1.61 +        input_pathname_(),
    1.62 +        object_filename_(),
    1.63 +        contents_(),
    1.64 +        selected_object_file_(),
    1.65 +        selected_object_name_() { }
    1.66 +  ~DumpSymbols() {
    1.67 +    [input_pathname_ release];
    1.68 +    [object_filename_ release];
    1.69 +    [contents_ release];
    1.70 +  }
    1.71 +
    1.72 +  // Prepare to read debugging information from |filename|. |filename| may be
    1.73 +  // the name of a universal binary, a Mach-O file, or a dSYM bundle
    1.74 +  // containing either of the above. On success, return true; if there is a
    1.75 +  // problem reading |filename|, report it and return false.
    1.76 +  //
    1.77 +  // (This class uses NSString for filenames and related values,
    1.78 +  // because the Mac Foundation framework seems to support
    1.79 +  // filename-related operations more fully on NSString values.)
    1.80 +  bool Read(NSString *filename);
    1.81 +
    1.82 +  // If this dumper's file includes an object file for |cpu_type| and
    1.83 +  // |cpu_subtype|, then select that object file for dumping, and return
    1.84 +  // true. Otherwise, return false, and leave this dumper's selected
    1.85 +  // architecture unchanged.
    1.86 +  //
    1.87 +  // By default, if this dumper's file contains only one object file, then
    1.88 +  // the dumper will dump those symbols; and if it contains more than one
    1.89 +  // object file, then the dumper will dump the object file whose
    1.90 +  // architecture matches that of this dumper program.
    1.91 +  bool SetArchitecture(cpu_type_t cpu_type, cpu_subtype_t cpu_subtype);
    1.92 +
    1.93 +  // If this dumper's file includes an object file for |arch_name|, then select
    1.94 +  // that object file for dumping, and return true. Otherwise, return false,
    1.95 +  // and leave this dumper's selected architecture unchanged.
    1.96 +  //
    1.97 +  // By default, if this dumper's file contains only one object file, then
    1.98 +  // the dumper will dump those symbols; and if it contains more than one
    1.99 +  // object file, then the dumper will dump the object file whose
   1.100 +  // architecture matches that of this dumper program.
   1.101 +  bool SetArchitecture(const std::string &arch_name);
   1.102 +
   1.103 +  // Return a pointer to an array of 'struct fat_arch' structures,
   1.104 +  // describing the object files contained in this dumper's file. Set
   1.105 +  // *|count| to the number of elements in the array. The returned array is
   1.106 +  // owned by this DumpSymbols instance.
   1.107 +  //
   1.108 +  // If there are no available architectures, this function
   1.109 +  // may return NULL.
   1.110 +  const struct fat_arch *AvailableArchitectures(size_t *count) {
   1.111 +    *count = object_files_.size();
   1.112 +    if (object_files_.size() > 0)
   1.113 +      return &object_files_[0];
   1.114 +    return NULL;
   1.115 +  }
   1.116 +
   1.117 +  // Read the selected object file's debugging information, and write it out to
   1.118 +  // |stream|. Return true on success; if an error occurs, report it and
   1.119 +  // return false.
   1.120 +  bool WriteSymbolFile(std::ostream &stream);
   1.121 +
   1.122 +  // As above, but simply return the debugging information in module
   1.123 +  // instead of writing it to a stream. The caller owns the resulting
   1.124 +  // module object and must delete it when finished.
   1.125 +  bool ReadSymbolData(Module** module);
   1.126 +
   1.127 + private:
   1.128 +  // Used internally.
   1.129 +  class DumperLineToModule;
   1.130 +  class LoadCommandDumper;
   1.131 +
   1.132 +  // Return an identifier string for the file this DumpSymbols is dumping.
   1.133 +  std::string Identifier();
   1.134 +
   1.135 +  // Read debugging information from |dwarf_sections|, which was taken from
   1.136 +  // |macho_reader|, and add it to |module|. On success, return true;
   1.137 +  // on failure, report the problem and return false.
   1.138 +  bool ReadDwarf(google_breakpad::Module *module,
   1.139 +                 const mach_o::Reader &macho_reader,
   1.140 +                 const mach_o::SectionMap &dwarf_sections) const;
   1.141 +
   1.142 +  // Read DWARF CFI or .eh_frame data from |section|, belonging to
   1.143 +  // |macho_reader|, and record it in |module|.  If |eh_frame| is true,
   1.144 +  // then the data is .eh_frame-format data; otherwise, it is standard DWARF
   1.145 +  // .debug_frame data. On success, return true; on failure, report
   1.146 +  // the problem and return false.
   1.147 +  bool ReadCFI(google_breakpad::Module *module,
   1.148 +               const mach_o::Reader &macho_reader,
   1.149 +               const mach_o::Section &section,
   1.150 +               bool eh_frame) const;
   1.151 +
   1.152 +  // The selection of what type of symbol data to read/write.
   1.153 +  const SymbolData symbol_data_;
   1.154 +
   1.155 +  // The name of the file or bundle whose symbols this will dump.
   1.156 +  // This is the path given to Read, for use in error messages.
   1.157 +  NSString *input_pathname_;
   1.158 +
   1.159 +  // The name of the file this DumpSymbols will actually read debugging
   1.160 +  // information from. Normally, this is the same as input_pathname_, but if
   1.161 +  // filename refers to a dSYM bundle, then this is the resource file
   1.162 +  // within that bundle.
   1.163 +  NSString *object_filename_;
   1.164 +
   1.165 +  // The complete contents of object_filename_, mapped into memory.
   1.166 +  NSData *contents_;
   1.167 +
   1.168 +  // A vector of fat_arch structures describing the object files
   1.169 +  // object_filename_ contains. If object_filename_ refers to a fat binary,
   1.170 +  // this may have more than one element; if it refers to a Mach-O file, this
   1.171 +  // has exactly one element.
   1.172 +  vector<struct fat_arch> object_files_;
   1.173 +
   1.174 +  // The object file in object_files_ selected to dump, or NULL if
   1.175 +  // SetArchitecture hasn't been called yet.
   1.176 +  const struct fat_arch *selected_object_file_;
   1.177 +
   1.178 +  // A string that identifies the selected object file, for use in error
   1.179 +  // messages.  This is usually object_filename_, but if that refers to a
   1.180 +  // fat binary, it includes an indication of the particular architecture
   1.181 +  // within that binary.
   1.182 +  string selected_object_name_;
   1.183 +};
   1.184 +
   1.185 +}  // namespace google_breakpad

mercurial