Skip to content

Commit

Permalink
Efficient processing of lineTable. Only units in source scope are pro…
Browse files Browse the repository at this point in the history
…cessed line by line. Improving performance for large codes.
  • Loading branch information
behnampn committed Jan 11, 2018
1 parent 3b65d81 commit cd2e1d2
Showing 1 changed file with 44 additions and 28 deletions.
72 changes: 44 additions & 28 deletions libcoz/inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,41 +478,57 @@ bool memory_map::process_file(const string& name, uintptr_t load_address,

// Walk through the compilation units (source files) in the executable
for(auto unit : d.compilation_units()) {
auto& lineTable = unit.get_line_table();
int fileIndex = 0;
bool needProcess = false;
//check if files using by lineTable are in source_scope
while(true){
try{
if(in_scope(lineTable.get_file(fileIndex)->path, source_scope)){
needProcess = true;
break;
}
fileIndex++;
}catch (out_of_range &e){
break;
}
}
if(needProcess){
try {
string prev_filename;
size_t prev_line;
uintptr_t prev_address = 0;
set<string> included_files;
// Walk through the line instructions in the DWARF line table
for(auto& line_info : unit.get_line_table()) {
// Insert an entry if this isn't the first line command in the sequence
if(in_scope(prev_filename, source_scope)) {
if(prev_address != 0) {
included_files.insert(prev_filename);
add_range(prev_filename,
prev_line,
interval(prev_address, line_info.address) + load_address);
}
}

try {
string prev_filename;
size_t prev_line;
uintptr_t prev_address = 0;
set<string> included_files;
// Walk through the line instructions in the DWARF line table
for(auto& line_info : unit.get_line_table()) {
// Insert an entry if this isn't the first line command in the sequence
if(in_scope(prev_filename, source_scope)) {
if(prev_address != 0) {
included_files.insert(prev_filename);
add_range(prev_filename,
prev_line,
interval(prev_address, line_info.address) + load_address);
if(line_info.end_sequence) {
prev_address = 0;
} else {
prev_filename = canonicalize_path(line_info.file->path);
prev_line = line_info.line;
prev_address = line_info.address;
}
}
process_inlines(unit.root(), unit.get_line_table(), source_scope, load_address);

if(line_info.end_sequence) {
prev_address = 0;
} else {
prev_filename = canonicalize_path(line_info.file->path);
prev_line = line_info.line;
prev_address = line_info.address;
for(const string& filename : included_files) {
INFO << "Included source file " << filename;
}
}
process_inlines(unit.root(), unit.get_line_table(), source_scope, load_address);

for(const string& filename : included_files) {
INFO << "Included source file " << filename;
} catch(dwarf::format_error e) {
WARNING << "Ignoring DWARF format error when reading line table: " << e.what();
}

} catch(dwarf::format_error e) {
WARNING << "Ignoring DWARF format error when reading line table: " << e.what();
}
}//if needProcess
}

return true;
Expand Down

0 comments on commit cd2e1d2

Please sign in to comment.