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

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:66f03fed5ee0
1 // Copyright (c) 2010 Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
31
32 // dwarf_line_to_module.cc: Implementation of DwarfLineToModule class.
33 // See dwarf_line_to_module.h for details.
34
35 #include <string>
36
37 #include "common/dwarf_line_to_module.h"
38 #include "common/using_std_string.h"
39 #include "common/logging.h"
40
41 // Trying to support Windows paths in a reasonable way adds a lot of
42 // variations to test; it would be better to just put off dealing with
43 // it until we actually have to deal with DWARF on Windows.
44
45 // Return true if PATH is an absolute path, false if it is relative.
46 static bool PathIsAbsolute(const string &path) {
47 return (path.size() >= 1 && path[0] == '/');
48 }
49
50 static bool HasTrailingSlash(const string &path) {
51 return (path.size() >= 1 && path[path.size() - 1] == '/');
52 }
53
54 // If PATH is an absolute path, return PATH. If PATH is a relative path,
55 // treat it as relative to BASE and return the combined path.
56 static string ExpandPath(const string &path,
57 const string &base) {
58 if (PathIsAbsolute(path) || base.empty())
59 return path;
60 return base + (HasTrailingSlash(base) ? "" : "/") + path;
61 }
62
63 namespace google_breakpad {
64
65 void DwarfLineToModule::DefineDir(const string &name, uint32 dir_num) {
66 // Directory number zero is reserved to mean the compilation
67 // directory. Silently ignore attempts to redefine it.
68 if (dir_num != 0)
69 directories_[dir_num] = ExpandPath(name, compilation_dir_);
70 }
71
72 void DwarfLineToModule::DefineFile(const string &name, int32 file_num,
73 uint32 dir_num, uint64 mod_time,
74 uint64 length) {
75 if (file_num == -1)
76 file_num = ++highest_file_number_;
77 else if (file_num > highest_file_number_)
78 highest_file_number_ = file_num;
79
80 string dir_name;
81 if (dir_num == 0) {
82 // Directory number zero is the compilation directory, and is stored as
83 // an attribute on the compilation unit, rather than in the program table.
84 dir_name = compilation_dir_;
85 } else {
86 DirectoryTable::const_iterator directory_it = directories_.find(dir_num);
87 if (directory_it != directories_.end()) {
88 dir_name = directory_it->second;
89 } else {
90 if (!warned_bad_directory_number_) {
91 BPLOG(INFO) << "warning: DWARF line number data refers to undefined"
92 << " directory numbers";
93 warned_bad_directory_number_ = true;
94 }
95 }
96 }
97
98 string full_name = ExpandPath(name, dir_name);
99
100 // Find a Module::File object of the given name, and add it to the
101 // file table.
102 files_[file_num] = module_->FindFile(full_name);
103 }
104
105 void DwarfLineToModule::AddLine(uint64 address, uint64 length,
106 uint32 file_num, uint32 line_num,
107 uint32 column_num) {
108 if (length == 0)
109 return;
110
111 // Clip lines not to extend beyond the end of the address space.
112 if (address + length < address)
113 length = -address;
114
115 // Should we omit this line? (See the comments for omitted_line_end_.)
116 if (address == 0 || address == omitted_line_end_) {
117 omitted_line_end_ = address + length;
118 return;
119 } else {
120 omitted_line_end_ = 0;
121 }
122
123 // Find the source file being referred to.
124 Module::File *file = files_[file_num];
125 if (!file) {
126 if (!warned_bad_file_number_) {
127 BPLOG(INFO) << "warning: DWARF line number data refers to "
128 << "undefined file numbers";
129 warned_bad_file_number_ = true;
130 }
131 return;
132 }
133 Module::Line line;
134 line.address = address;
135 // We set the size when we get the next line or the EndSequence call.
136 line.size = length;
137 line.file = file;
138 line.number = line_num;
139 lines_->push_back(line);
140 }
141
142 } // namespace google_breakpad

mercurial