1
// Copyright (c) 2010 Google Inc.
2
// All rights reserved.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
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
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.
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.
30
// Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
32
// dwarf_line_to_module.cc: Implementation of DwarfLineToModule class.
33
// See dwarf_line_to_module.h for details.
35
#include "common/dwarf_line_to_module.h"
39
// Trying to support Windows paths in a reasonable way adds a lot of
40
// variations to test; it would be better to just put off dealing with
41
// it until we actually have to deal with DWARF on Windows.
43
// Return true if PATH is an absolute path, false if it is relative.
44
static bool PathIsAbsolute(const std::string &path) {
45
return (path.size() >= 1 && path[0] == '/');
48
// If PATH is an absolute path, return PATH. If PATH is a relative path,
49
// treat it as relative to BASE and return the combined path.
50
static std::string ExpandPath(const std::string &path,
51
const std::string &base) {
52
if (PathIsAbsolute(path))
54
return base + "/" + path;
57
namespace google_breakpad {
59
void DwarfLineToModule::DefineDir(const std::string &name, uint32 dir_num) {
60
// Directory number zero is reserved to mean the compilation
61
// directory. Silently ignore attempts to redefine it.
63
directories_[dir_num] = name;
66
void DwarfLineToModule::DefineFile(const std::string &name, int32 file_num,
67
uint32 dir_num, uint64 mod_time,
70
file_num = ++highest_file_number_;
71
else if (file_num > highest_file_number_)
72
highest_file_number_ = file_num;
74
std::string full_name;
76
DirectoryTable::const_iterator directory_it = directories_.find(dir_num);
77
if (directory_it != directories_.end()) {
78
full_name = ExpandPath(name, directory_it->second);
80
if (!warned_bad_directory_number_) {
81
fprintf(stderr, "warning: DWARF line number data refers to undefined"
82
" directory numbers\n");
83
warned_bad_directory_number_ = true;
85
full_name = name; // just treat name as relative
88
// Directory number zero is the compilation directory; we just report
89
// relative paths in that case.
93
// Find a Module::File object of the given name, and add it to the
95
files_[file_num] = module_->FindFile(full_name);
98
void DwarfLineToModule::AddLine(uint64 address, uint64 length,
99
uint32 file_num, uint32 line_num,
104
// Clip lines not to extend beyond the end of the address space.
105
if (address + length < address)
108
// Should we omit this line? (See the comments for omitted_line_end_.)
109
if (address == 0 || address == omitted_line_end_) {
110
omitted_line_end_ = address + length;
113
omitted_line_end_ = 0;
116
// Find the source file being referred to.
117
Module::File *file = files_[file_num];
119
if (!warned_bad_file_number_) {
120
fprintf(stderr, "warning: DWARF line number data refers to "
121
"undefined file numbers\n");
122
warned_bad_file_number_ = true;
127
line.address = address;
128
// We set the size when we get the next line or the EndSequence call.
131
line.number = line_num;
132
lines_->push_back(line);
135
} // namespace google_breakpad