toolkit/crashreporter/google-breakpad/src/common/dwarf_line_to_module.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/common/dwarf_line_to_module.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,142 @@
     1.4 +// Copyright (c) 2010 Google Inc.
     1.5 +// All rights reserved.
     1.6 +//
     1.7 +// Redistribution and use in source and binary forms, with or without
     1.8 +// modification, are permitted provided that the following conditions are
     1.9 +// met:
    1.10 +//
    1.11 +//     * Redistributions of source code must retain the above copyright
    1.12 +// notice, this list of conditions and the following disclaimer.
    1.13 +//     * Redistributions in binary form must reproduce the above
    1.14 +// copyright notice, this list of conditions and the following disclaimer
    1.15 +// in the documentation and/or other materials provided with the
    1.16 +// distribution.
    1.17 +//     * Neither the name of Google Inc. nor the names of its
    1.18 +// contributors may be used to endorse or promote products derived from
    1.19 +// this software without specific prior written permission.
    1.20 +//
    1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.32 +
    1.33 +// Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
    1.34 +
    1.35 +// dwarf_line_to_module.cc: Implementation of DwarfLineToModule class.
    1.36 +// See dwarf_line_to_module.h for details. 
    1.37 +
    1.38 +#include <string>
    1.39 +
    1.40 +#include "common/dwarf_line_to_module.h"
    1.41 +#include "common/using_std_string.h"
    1.42 +#include "common/logging.h"
    1.43 +
    1.44 +// Trying to support Windows paths in a reasonable way adds a lot of
    1.45 +// variations to test; it would be better to just put off dealing with
    1.46 +// it until we actually have to deal with DWARF on Windows.
    1.47 +
    1.48 +// Return true if PATH is an absolute path, false if it is relative.
    1.49 +static bool PathIsAbsolute(const string &path) {
    1.50 +  return (path.size() >= 1 && path[0] == '/');
    1.51 +}
    1.52 +
    1.53 +static bool HasTrailingSlash(const string &path) {
    1.54 +  return (path.size() >= 1 && path[path.size() - 1] == '/');
    1.55 +}
    1.56 +
    1.57 +// If PATH is an absolute path, return PATH.  If PATH is a relative path,
    1.58 +// treat it as relative to BASE and return the combined path.
    1.59 +static string ExpandPath(const string &path,
    1.60 +                         const string &base) {
    1.61 +  if (PathIsAbsolute(path) || base.empty())
    1.62 +    return path;
    1.63 +  return base + (HasTrailingSlash(base) ? "" : "/") + path;
    1.64 +}
    1.65 +
    1.66 +namespace google_breakpad {
    1.67 +
    1.68 +void DwarfLineToModule::DefineDir(const string &name, uint32 dir_num) {
    1.69 +  // Directory number zero is reserved to mean the compilation
    1.70 +  // directory. Silently ignore attempts to redefine it.
    1.71 +  if (dir_num != 0)
    1.72 +    directories_[dir_num] = ExpandPath(name, compilation_dir_);
    1.73 +}
    1.74 +
    1.75 +void DwarfLineToModule::DefineFile(const string &name, int32 file_num,
    1.76 +                                   uint32 dir_num, uint64 mod_time,
    1.77 +                                   uint64 length) {
    1.78 +  if (file_num == -1)
    1.79 +    file_num = ++highest_file_number_;
    1.80 +  else if (file_num > highest_file_number_)
    1.81 +    highest_file_number_ = file_num;
    1.82 +
    1.83 +  string dir_name;
    1.84 +  if (dir_num == 0) {
    1.85 +    // Directory number zero is the compilation directory, and is stored as
    1.86 +    // an attribute on the compilation unit, rather than in the program table.
    1.87 +    dir_name = compilation_dir_;
    1.88 +  } else {
    1.89 +    DirectoryTable::const_iterator directory_it = directories_.find(dir_num);
    1.90 +    if (directory_it != directories_.end()) {
    1.91 +      dir_name = directory_it->second;
    1.92 +    } else {
    1.93 +      if (!warned_bad_directory_number_) {
    1.94 +        BPLOG(INFO) << "warning: DWARF line number data refers to undefined"
    1.95 +                    << " directory numbers";
    1.96 +        warned_bad_directory_number_ = true;
    1.97 +      }
    1.98 +    }
    1.99 +  }
   1.100 +
   1.101 +  string full_name = ExpandPath(name, dir_name);
   1.102 +
   1.103 +  // Find a Module::File object of the given name, and add it to the
   1.104 +  // file table.
   1.105 +  files_[file_num] = module_->FindFile(full_name);
   1.106 +}
   1.107 +
   1.108 +void DwarfLineToModule::AddLine(uint64 address, uint64 length,
   1.109 +                                uint32 file_num, uint32 line_num,
   1.110 +                                uint32 column_num) {
   1.111 +  if (length == 0)
   1.112 +    return;
   1.113 +
   1.114 +  // Clip lines not to extend beyond the end of the address space.
   1.115 +  if (address + length < address)
   1.116 +    length = -address;
   1.117 +
   1.118 +  // Should we omit this line? (See the comments for omitted_line_end_.)
   1.119 +  if (address == 0 || address == omitted_line_end_) {
   1.120 +    omitted_line_end_ = address + length;
   1.121 +    return;
   1.122 +  } else {
   1.123 +    omitted_line_end_ = 0;
   1.124 +  }
   1.125 +
   1.126 +  // Find the source file being referred to.
   1.127 +  Module::File *file = files_[file_num];
   1.128 +  if (!file) {
   1.129 +    if (!warned_bad_file_number_) {
   1.130 +      BPLOG(INFO) << "warning: DWARF line number data refers to "
   1.131 +                  << "undefined file numbers";
   1.132 +      warned_bad_file_number_ = true;
   1.133 +    }
   1.134 +    return;
   1.135 +  }
   1.136 +  Module::Line line;
   1.137 +  line.address = address;
   1.138 +  // We set the size when we get the next line or the EndSequence call.
   1.139 +  line.size = length;
   1.140 +  line.file = file;
   1.141 +  line.number = line_num;
   1.142 +  lines_->push_back(line);
   1.143 +}
   1.144 +
   1.145 +} // namespace google_breakpad

mercurial