Skip to content

Commit

Permalink
Provide a method to get files from the line table file list
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Clements committed Mar 10, 2013
1 parent 5df3938 commit 66ee179
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
10 changes: 7 additions & 3 deletions dwarf/dwarf++.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1055,9 +1055,6 @@ public:

class iterator;

// XXX Provide access to file list for DW_AT::decl_file and
// DW_AT::call_file.

/**
* Return an iterator to the beginning of this line number
* table. If called on an invalid line table, this will
Expand All @@ -1079,6 +1076,13 @@ public:
*/
iterator find_address(taddr addr) const;

/**
* Return the index'th file in the line table. These indexes
* are typically used by declaration and call coordinates. If
* index is out of range, throws out_of_range.
*/
const file *get_file(unsigned index) const;

private:
friend class iterator;

Expand Down
30 changes: 29 additions & 1 deletion dwarf/line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ struct line_table::impl
// track of how far we've gotten so we don't add the same
// entry twice.
section_offset last_file_name_end;
// If an iterator has traversed the entire program, then we
// know we've gathered all file names.
bool file_names_complete;

impl() : last_file_name_end(0) {};
impl() : last_file_name_end(0), file_names_complete(false) {};

bool read_file_entry(cursor *cur, bool in_header);
};
Expand Down Expand Up @@ -172,6 +175,27 @@ line_table::find_address(taddr addr) const
return prev;
}

const line_table::file *
line_table::get_file(unsigned index) const
{
if (index >= m->file_names.size()) {
// It could be declared in the line table program.
// This is unlikely, so we don't have to be
// super-efficient about this. Just force our way
// through the whole line table program.
if (!m->file_names_complete) {
for (auto &ent : *this)
(void)ent;
}
if (index >= m->file_names.size())
throw out_of_range
("file name index " + std::to_string(index) +
" exceeds file table size of " +
std::to_string(m->file_names.size()));
}
return &m->file_names[index];
}

bool
line_table::impl::read_file_entry(cursor *cur, bool in_header)
{
Expand Down Expand Up @@ -255,6 +279,10 @@ line_table::iterator::operator++()
}
if (stepped && !output)
throw format_error("unexpected end of line table");
if (stepped && cur.end()) {
// Record that all file names must be known now
table->m->file_names_complete = true;
}
if (output) {
// Resolve file name of entry
if (entry.file_index < table->m->file_names.size())
Expand Down

0 comments on commit 66ee179

Please sign in to comment.