DWARFDebugLine.cpp [plain text]
#include "DWARFDebugLine.h"
#include <assert.h>
#include "lldb/Core/FileSpecList.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/Timer.h"
#include "lldb/Host/Host.h"
#include "SymbolFileDWARF.h"
#include "LogChannelDWARF.h"
using namespace lldb;
using namespace lldb_private;
using namespace std;
void
DWARFDebugLine::Parse(const DataExtractor& debug_line_data)
{
m_lineTableMap.clear();
dw_offset_t offset = 0;
LineTable::shared_ptr line_table_sp(new LineTable);
while (debug_line_data.ValidOffset(offset))
{
const uint32_t debug_line_offset = offset;
if (line_table_sp.get() == NULL)
break;
if (ParseStatementTable(debug_line_data, &offset, line_table_sp.get()))
{
if (offset <= debug_line_offset)
break;
m_lineTableMap[debug_line_offset] = line_table_sp;
line_table_sp.reset(new LineTable);
}
else
++offset; }
}
void
DWARFDebugLine::ParseIfNeeded(const DataExtractor& debug_line_data)
{
if (m_lineTableMap.empty())
Parse(debug_line_data);
}
DWARFDebugLine::LineTable::shared_ptr
DWARFDebugLine::GetLineTable(const dw_offset_t offset) const
{
DWARFDebugLine::LineTable::shared_ptr line_table_shared_ptr;
LineTableConstIter pos = m_lineTableMap.find(offset);
if (pos != m_lineTableMap.end())
line_table_shared_ptr = pos->second;
return line_table_shared_ptr;
}
static void
DumpStateToFile (dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
{
Log *log = (Log *)userData;
if (state.row == DWARFDebugLine::State::StartParsingLineTable)
{
state.prologue->Dump (log);
log->PutCString ("Address Line Column File");
log->PutCString ("------------------ ------ ------ ------");
}
else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
{
}
else
{
log->Printf( "0x%16.16llx %6u %6u %6u%s\n", state.address, state.line, state.column, state.file, state.end_sequence ? " END" : "");
}
}
bool
DWARFDebugLine::DumpLineTableRows(Log *log, SymbolFileDWARF* dwarf2Data, dw_offset_t debug_line_offset)
{
const DataExtractor& debug_line_data = dwarf2Data->get_debug_line_data();
if (debug_line_offset == DW_INVALID_OFFSET)
{
debug_line_offset = 0;
while (debug_line_data.ValidOffset(debug_line_offset))
debug_line_offset = DumpStatementTable (log, debug_line_data, debug_line_offset);
}
else
{
DumpStatementTable (log, debug_line_data, debug_line_offset);
}
return false;
}
dw_offset_t
DWARFDebugLine::DumpStatementTable(Log *log, const DataExtractor& debug_line_data, const dw_offset_t debug_line_offset)
{
if (debug_line_data.ValidOffset(debug_line_offset))
{
uint32_t offset = debug_line_offset;
log->Printf( "----------------------------------------------------------------------\n"
"debug_line[0x%8.8x]\n"
"----------------------------------------------------------------------\n", debug_line_offset);
if (ParseStatementTable(debug_line_data, &offset, DumpStateToFile, log))
return offset;
else
return debug_line_offset + 1; }
return DW_INVALID_OFFSET;
}
bool
DWARFDebugLine::DumpOpcodes(Log *log, SymbolFileDWARF* dwarf2Data, dw_offset_t debug_line_offset, uint32_t dump_flags)
{
const DataExtractor& debug_line_data = dwarf2Data->get_debug_line_data();
if (debug_line_data.GetByteSize() == 0)
{
log->Printf( "< EMPTY >\n");
return false;
}
if (debug_line_offset == DW_INVALID_OFFSET)
{
debug_line_offset = 0;
while (debug_line_data.ValidOffset(debug_line_offset))
debug_line_offset = DumpStatementOpcodes (log, debug_line_data, debug_line_offset, dump_flags);
}
else
{
DumpStatementOpcodes (log, debug_line_data, debug_line_offset, dump_flags);
}
return false;
}
dw_offset_t
DWARFDebugLine::DumpStatementOpcodes(Log *log, const DataExtractor& debug_line_data, const dw_offset_t debug_line_offset, uint32_t flags)
{
uint32_t offset = debug_line_offset;
if (debug_line_data.ValidOffset(offset))
{
Prologue prologue;
if (ParsePrologue(debug_line_data, &offset, &prologue))
{
log->PutCString ("----------------------------------------------------------------------");
log->Printf ("debug_line[0x%8.8x]", debug_line_offset);
log->PutCString ("----------------------------------------------------------------------\n");
prologue.Dump (log);
}
else
{
offset = debug_line_offset;
log->Printf( "0x%8.8x: skipping pad byte %2.2x", offset, debug_line_data.GetU8(&offset));
return offset;
}
Row row(prologue.default_is_stmt);
const dw_offset_t end_offset = debug_line_offset + prologue.total_length + sizeof(prologue.total_length);
assert(debug_line_data.ValidOffset(end_offset-1));
while (offset < end_offset)
{
const uint32_t op_offset = offset;
uint8_t opcode = debug_line_data.GetU8(&offset);
switch (opcode)
{
case 0: {
dw_offset_t ext_offset = offset;
dw_uleb128_t len = debug_line_data.GetULEB128(&offset);
dw_offset_t arg_size = len - (offset - ext_offset);
uint8_t sub_opcode = debug_line_data.GetU8(&offset);
switch (sub_opcode)
{
case DW_LNE_end_sequence :
log->Printf( "0x%8.8x: DW_LNE_end_sequence", op_offset);
row.Dump(log);
row.Reset(prologue.default_is_stmt);
break;
case DW_LNE_set_address :
{
row.address = debug_line_data.GetMaxU64(&offset, arg_size);
log->Printf( "0x%8.8x: DW_LNE_set_address (0x%llx)", op_offset, row.address);
}
break;
case DW_LNE_define_file:
{
FileNameEntry fileEntry;
fileEntry.name = debug_line_data.GetCStr(&offset);
fileEntry.dir_idx = debug_line_data.GetULEB128(&offset);
fileEntry.mod_time = debug_line_data.GetULEB128(&offset);
fileEntry.length = debug_line_data.GetULEB128(&offset);
log->Printf( "0x%8.8x: DW_LNE_define_file('%s', dir=%i, mod_time=0x%8.8x, length=%i )",
op_offset,
fileEntry.name.c_str(),
fileEntry.dir_idx,
fileEntry.mod_time,
fileEntry.length);
prologue.file_names.push_back(fileEntry);
}
break;
default:
log->Printf( "0x%8.8x: DW_LNE_??? (%2.2x) - Skipping unknown upcode", op_offset, opcode);
offset += arg_size;
break;
}
}
break;
case DW_LNS_copy:
log->Printf( "0x%8.8x: DW_LNS_copy", op_offset);
row.Dump (log);
break;
case DW_LNS_advance_pc:
{
dw_uleb128_t addr_offset_n = debug_line_data.GetULEB128(&offset);
dw_uleb128_t addr_offset = addr_offset_n * prologue.min_inst_length;
log->Printf( "0x%8.8x: DW_LNS_advance_pc (0x%x)", op_offset, addr_offset);
row.address += addr_offset;
}
break;
case DW_LNS_advance_line:
{
dw_sleb128_t line_offset = debug_line_data.GetSLEB128(&offset);
log->Printf( "0x%8.8x: DW_LNS_advance_line (%i)", op_offset, line_offset);
row.line += line_offset;
}
break;
case DW_LNS_set_file:
row.file = debug_line_data.GetULEB128(&offset);
log->Printf( "0x%8.8x: DW_LNS_set_file (%u)", op_offset, row.file);
break;
case DW_LNS_set_column:
row.column = debug_line_data.GetULEB128(&offset);
log->Printf( "0x%8.8x: DW_LNS_set_column (%u)", op_offset, row.column);
break;
case DW_LNS_negate_stmt:
row.is_stmt = !row.is_stmt;
log->Printf( "0x%8.8x: DW_LNS_negate_stmt", op_offset);
break;
case DW_LNS_set_basic_block:
row.basic_block = true;
log->Printf( "0x%8.8x: DW_LNS_set_basic_block", op_offset);
break;
case DW_LNS_const_add_pc:
{
uint8_t adjust_opcode = 255 - prologue.opcode_base;
dw_addr_t addr_offset = (adjust_opcode / prologue.line_range) * prologue.min_inst_length;
log->Printf( "0x%8.8x: DW_LNS_const_add_pc (0x%8.8llx)", op_offset, addr_offset);
row.address += addr_offset;
}
break;
case DW_LNS_fixed_advance_pc:
{
uint16_t pc_offset = debug_line_data.GetU16(&offset);
log->Printf( "0x%8.8x: DW_LNS_fixed_advance_pc (0x%4.4x)", op_offset, pc_offset);
row.address += pc_offset;
}
break;
case DW_LNS_set_prologue_end:
row.prologue_end = true;
log->Printf( "0x%8.8x: DW_LNS_set_prologue_end", op_offset);
break;
case DW_LNS_set_epilogue_begin:
row.epilogue_begin = true;
log->Printf( "0x%8.8x: DW_LNS_set_epilogue_begin", op_offset);
break;
case DW_LNS_set_isa:
row.isa = debug_line_data.GetULEB128(&offset);
log->Printf( "0x%8.8x: DW_LNS_set_isa (%u)", op_offset, row.isa);
break;
default:
if (opcode < prologue.opcode_base)
{
uint8_t n = prologue.standard_opcode_lengths[opcode-1];
log->Printf( "0x%8.8x: Special : Unknown skipping %u ULEB128 values.", op_offset, n);
while (n > 0)
{
debug_line_data.GetULEB128(&offset);
--n;
}
}
else
{
uint8_t adjust_opcode = opcode - prologue.opcode_base;
dw_addr_t addr_offset = (adjust_opcode / prologue.line_range) * prologue.min_inst_length;
int32_t line_offset = prologue.line_base + (adjust_opcode % prologue.line_range);
log->Printf("0x%8.8x: address += 0x%llx, line += %i\n", op_offset, (uint64_t)addr_offset, line_offset);
row.address += addr_offset;
row.line += line_offset;
row.Dump (log);
}
break;
}
}
return end_offset;
}
return DW_INVALID_OFFSET;
}
void
DWARFDebugLine::Parse(const DataExtractor& debug_line_data, DWARFDebugLine::State::Callback callback, void* userData)
{
uint32_t offset = 0;
if (debug_line_data.ValidOffset(offset))
{
if (!ParseStatementTable(debug_line_data, &offset, callback, userData))
++offset; }
}
bool
DWARFDebugLine::ParsePrologue(const DataExtractor& debug_line_data, dw_offset_t* offset_ptr, Prologue* prologue)
{
const uint32_t prologue_offset = *offset_ptr;
prologue->Clear();
uint32_t i;
const char * s;
prologue->total_length = debug_line_data.GetU32(offset_ptr);
prologue->version = debug_line_data.GetU16(offset_ptr);
if (prologue->version != 2)
return false;
prologue->prologue_length = debug_line_data.GetU32(offset_ptr);
const dw_offset_t end_prologue_offset = prologue->prologue_length + *offset_ptr;
prologue->min_inst_length = debug_line_data.GetU8(offset_ptr);
prologue->default_is_stmt = debug_line_data.GetU8(offset_ptr);
prologue->line_base = debug_line_data.GetU8(offset_ptr);
prologue->line_range = debug_line_data.GetU8(offset_ptr);
prologue->opcode_base = debug_line_data.GetU8(offset_ptr);
prologue->standard_opcode_lengths.reserve(prologue->opcode_base-1);
for (i=1; i<prologue->opcode_base; ++i)
{
uint8_t op_len = debug_line_data.GetU8(offset_ptr);
prologue->standard_opcode_lengths.push_back(op_len);
}
while (*offset_ptr < end_prologue_offset)
{
s = debug_line_data.GetCStr(offset_ptr);
if (s && s[0])
prologue->include_directories.push_back(s);
else
break;
}
while (*offset_ptr < end_prologue_offset)
{
const char* name = debug_line_data.GetCStr( offset_ptr );
if (name && name[0])
{
FileNameEntry fileEntry;
fileEntry.name = name;
fileEntry.dir_idx = debug_line_data.GetULEB128( offset_ptr );
fileEntry.mod_time = debug_line_data.GetULEB128( offset_ptr );
fileEntry.length = debug_line_data.GetULEB128( offset_ptr );
prologue->file_names.push_back(fileEntry);
}
else
break;
}
if (*offset_ptr != end_prologue_offset)
{
Host::SystemLog (Host::eSystemLogWarning,
"warning: parsing line table prologue at 0x%8.8x should have ended at 0x%8.8x but it ended ad 0x%8.8x\n",
prologue_offset,
end_prologue_offset,
*offset_ptr);
}
return end_prologue_offset;
}
bool
DWARFDebugLine::ParseSupportFiles (const lldb::ModuleSP &module_sp,
const DataExtractor& debug_line_data,
const char *cu_comp_dir,
dw_offset_t stmt_list,
FileSpecList &support_files)
{
uint32_t offset = stmt_list + 4; const char * s;
uint32_t version = debug_line_data.GetU16(&offset);
if (version != 2)
return false;
const dw_offset_t end_prologue_offset = debug_line_data.GetU32(&offset) + offset;
offset += 4;
const uint8_t opcode_base = debug_line_data.GetU8(&offset);
offset += opcode_base - 1;
std::vector<std::string> include_directories;
include_directories.push_back(""); while (offset < end_prologue_offset)
{
s = debug_line_data.GetCStr(&offset);
if (s && s[0])
include_directories.push_back(s);
else
break;
}
std::string fullpath;
std::string remapped_fullpath;
while (offset < end_prologue_offset)
{
const char* path = debug_line_data.GetCStr( &offset );
if (path && path[0])
{
uint32_t dir_idx = debug_line_data.GetULEB128( &offset );
debug_line_data.Skip_LEB128(&offset); debug_line_data.Skip_LEB128(&offset);
if (path[0] == '/')
{
if (module_sp->RemapSourceFile (path, fullpath))
support_files.Append(FileSpec (fullpath.c_str(), false));
else
support_files.Append(FileSpec (path, false));
}
else
{
if (dir_idx > 0 && dir_idx < include_directories.size())
{
if (cu_comp_dir && include_directories[dir_idx][0] != '/')
{
fullpath = cu_comp_dir;
if (*fullpath.rbegin() != '/')
fullpath += '/';
fullpath += include_directories[dir_idx];
}
else
fullpath = include_directories[dir_idx];
}
else if (cu_comp_dir && cu_comp_dir[0])
{
fullpath = cu_comp_dir;
}
if (!fullpath.empty())
{
if (*fullpath.rbegin() != '/')
fullpath += '/';
}
fullpath += path;
if (module_sp->RemapSourceFile (fullpath.c_str(), remapped_fullpath))
support_files.Append(FileSpec (remapped_fullpath.c_str(), false));
else
support_files.Append(FileSpec (fullpath.c_str(), false));
}
}
}
if (offset != end_prologue_offset)
{
Host::SystemLog (Host::eSystemLogError,
"warning: parsing line table prologue at 0x%8.8x should have ended at 0x%8.8x but it ended ad 0x%8.8x\n",
stmt_list,
end_prologue_offset,
offset);
}
return end_prologue_offset;
}
bool
DWARFDebugLine::ParseStatementTable
(
const DataExtractor& debug_line_data,
dw_offset_t* offset_ptr,
DWARFDebugLine::State::Callback callback,
void* userData
)
{
LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_LINE));
Prologue::shared_ptr prologue(new Prologue());
const dw_offset_t debug_line_offset = *offset_ptr;
Timer scoped_timer (__PRETTY_FUNCTION__,
"DWARFDebugLine::ParseStatementTable (.debug_line[0x%8.8x])",
debug_line_offset);
if (!ParsePrologue(debug_line_data, offset_ptr, prologue.get()))
{
if (log)
log->Error ("failed to parse DWARF line table prologue");
*offset_ptr = debug_line_offset;
return false;
}
if (log)
prologue->Dump (log.get());
const dw_offset_t end_offset = debug_line_offset + prologue->total_length + sizeof(prologue->total_length);
State state(prologue, log.get(), callback, userData);
while (*offset_ptr < end_offset)
{
uint8_t opcode = debug_line_data.GetU8(offset_ptr);
if (opcode == 0)
{
dw_offset_t ext_offset = *offset_ptr;
dw_uleb128_t len = debug_line_data.GetULEB128(offset_ptr);
dw_offset_t arg_size = len - (*offset_ptr - ext_offset);
uint8_t sub_opcode = debug_line_data.GetU8(offset_ptr);
switch (sub_opcode)
{
case DW_LNE_end_sequence:
state.end_sequence = true;
state.AppendRowToMatrix(*offset_ptr);
state.Reset();
break;
case DW_LNE_set_address:
state.address = debug_line_data.GetAddress(offset_ptr);
break;
case DW_LNE_define_file:
{
FileNameEntry fileEntry;
fileEntry.name = debug_line_data.GetCStr(offset_ptr);
fileEntry.dir_idx = debug_line_data.GetULEB128(offset_ptr);
fileEntry.mod_time = debug_line_data.GetULEB128(offset_ptr);
fileEntry.length = debug_line_data.GetULEB128(offset_ptr);
state.prologue->file_names.push_back(fileEntry);
}
break;
default:
(*offset_ptr) += arg_size;
break;
}
}
else if (opcode < prologue->opcode_base)
{
switch (opcode)
{
case DW_LNS_copy:
state.AppendRowToMatrix(*offset_ptr);
break;
case DW_LNS_advance_pc:
state.address += debug_line_data.GetULEB128(offset_ptr) * prologue->min_inst_length;
break;
case DW_LNS_advance_line:
state.line += debug_line_data.GetSLEB128(offset_ptr);
break;
case DW_LNS_set_file:
state.file = debug_line_data.GetULEB128(offset_ptr);
break;
case DW_LNS_set_column:
state.column = debug_line_data.GetULEB128(offset_ptr);
break;
case DW_LNS_negate_stmt:
state.is_stmt = !state.is_stmt;
break;
case DW_LNS_set_basic_block:
state.basic_block = true;
break;
case DW_LNS_const_add_pc:
{
uint8_t adjust_opcode = 255 - prologue->opcode_base;
dw_addr_t addr_offset = (adjust_opcode / prologue->line_range) * prologue->min_inst_length;
state.address += addr_offset;
}
break;
case DW_LNS_fixed_advance_pc:
state.address += debug_line_data.GetU16(offset_ptr);
break;
case DW_LNS_set_prologue_end:
state.prologue_end = true;
break;
case DW_LNS_set_epilogue_begin:
state.epilogue_begin = true;
break;
case DW_LNS_set_isa:
state.isa = debug_line_data.GetULEB128(offset_ptr);
break;
default:
{
uint8_t i;
assert (opcode - 1 < prologue->standard_opcode_lengths.size());
const uint8_t opcode_length = prologue->standard_opcode_lengths[opcode - 1];
for (i=0; i<opcode_length; ++i)
debug_line_data.Skip_LEB128(offset_ptr);
}
break;
}
}
else
{
uint8_t adjust_opcode = opcode - prologue->opcode_base;
dw_addr_t addr_offset = (adjust_opcode / prologue->line_range) * prologue->min_inst_length;
int32_t line_offset = prologue->line_base + (adjust_opcode % prologue->line_range);
state.line += line_offset;
state.address += addr_offset;
state.AppendRowToMatrix(*offset_ptr);
}
}
state.Finalize( *offset_ptr );
return end_offset;
}
static void
ParseStatementTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
{
DWARFDebugLine::LineTable* line_table = (DWARFDebugLine::LineTable*)userData;
if (state.row == DWARFDebugLine::State::StartParsingLineTable)
{
line_table->prologue = state.prologue;
}
else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
{
}
else
{
line_table->AppendRow(state);
}
}
bool
DWARFDebugLine::ParseStatementTable(const DataExtractor& debug_line_data, uint32_t* offset_ptr, LineTable* line_table)
{
return ParseStatementTable(debug_line_data, offset_ptr, ParseStatementTableCallback, line_table);
}
inline bool
DWARFDebugLine::Prologue::IsValid() const
{
return SymbolFileDWARF::SupportedVersion(version);
}
void
DWARFDebugLine::Prologue::Dump(Log *log)
{
uint32_t i;
log->Printf( "Line table prologue:");
log->Printf( " total_length: 0x%8.8x", total_length);
log->Printf( " version: %u", version);
log->Printf( "prologue_length: 0x%8.8x", prologue_length);
log->Printf( "min_inst_length: %u", min_inst_length);
log->Printf( "default_is_stmt: %u", default_is_stmt);
log->Printf( " line_base: %i", line_base);
log->Printf( " line_range: %u", line_range);
log->Printf( " opcode_base: %u", opcode_base);
for (i=0; i<standard_opcode_lengths.size(); ++i)
{
log->Printf( "standard_opcode_lengths[%s] = %u", DW_LNS_value_to_name(i+1), standard_opcode_lengths[i]);
}
if (!include_directories.empty())
{
for (i=0; i<include_directories.size(); ++i)
{
log->Printf( "include_directories[%3u] = '%s'", i+1, include_directories[i].c_str());
}
}
if (!file_names.empty())
{
log->PutCString (" Dir Mod Time File Len File Name");
log->PutCString (" ---- ---------- ---------- ---------------------------");
for (i=0; i<file_names.size(); ++i)
{
const FileNameEntry& fileEntry = file_names[i];
log->Printf ("file_names[%3u] %4u 0x%8.8x 0x%8.8x %s",
i+1,
fileEntry.dir_idx,
fileEntry.mod_time,
fileEntry.length,
fileEntry.name.c_str());
}
}
}
bool DWARFDebugLine::Prologue::GetFile(uint32_t file_idx, std::string& path, std::string& directory) const
{
uint32_t idx = file_idx - 1; if (idx < file_names.size())
{
path = file_names[idx].name;
uint32_t dir_idx = file_names[idx].dir_idx - 1;
if (dir_idx < include_directories.size())
directory = include_directories[dir_idx];
else
directory.clear();
return true;
}
return false;
}
void
DWARFDebugLine::LineTable::Dump(Log *log) const
{
if (prologue.get())
prologue->Dump (log);
if (!rows.empty())
{
log->PutCString ("Address Line Column File ISA Flags");
log->PutCString ("------------------ ------ ------ ------ --- -------------");
Row::const_iterator pos = rows.begin();
Row::const_iterator end = rows.end();
while (pos != end)
{
(*pos).Dump (log);
++pos;
}
}
}
void
DWARFDebugLine::LineTable::AppendRow(const DWARFDebugLine::Row& state)
{
rows.push_back(state);
}
static bool FindMatchingAddress (const DWARFDebugLine::Row& row1, const DWARFDebugLine::Row& row2)
{
return row1.address < row2.address;
}
uint32_t
DWARFDebugLine::LineTable::LookupAddress(dw_addr_t address, dw_addr_t cu_high_pc) const
{
uint32_t index = UINT32_MAX;
if (!rows.empty())
{
DWARFDebugLine::Row row;
row.address = address;
Row::const_iterator begin_pos = rows.begin();
Row::const_iterator end_pos = rows.end();
Row::const_iterator pos = lower_bound(begin_pos, end_pos, row, FindMatchingAddress);
if (pos == end_pos)
{
if (address < cu_high_pc)
return rows.size()-1;
}
else
{
index = pos - begin_pos;
if (pos->address > address)
{
if (index > 0)
--index;
else
index = UINT32_MAX;
}
}
}
return index; }
DWARFDebugLine::Row::Row(bool default_is_stmt) :
address(0),
line(1),
column(0),
file(1),
is_stmt(default_is_stmt),
basic_block(false),
end_sequence(false),
prologue_end(false),
epilogue_begin(false),
isa(0)
{
}
void
DWARFDebugLine::Row::PostAppend()
{
basic_block = false;
prologue_end = false;
epilogue_begin = false;
}
void
DWARFDebugLine::Row::Reset(bool default_is_stmt)
{
address = 0;
line = 1;
column = 0;
file = 1;
is_stmt = default_is_stmt;
basic_block = false;
end_sequence = false;
prologue_end = false;
epilogue_begin = false;
isa = 0;
}
void
DWARFDebugLine::Row::Dump(Log *log) const
{
log->Printf( "0x%16.16llx %6u %6u %6u %3u %s%s%s%s%s",
address,
line,
column,
file,
isa,
is_stmt ? " is_stmt" : "",
basic_block ? " basic_block" : "",
prologue_end ? " prologue_end" : "",
epilogue_begin ? " epilogue_begin" : "",
end_sequence ? " end_sequence" : "");
}
static bool AddressLessThan (const DWARFDebugLine::Row& a, const DWARFDebugLine::Row& b)
{
return a.address < b.address;
}
void
DWARFDebugLine::Row::Insert(Row::collection& state_coll, const Row& state)
{
if (state_coll.empty() || AddressLessThan(state_coll.back(), state))
{
state_coll.push_back(state);
}
else
{
pair<Row::iterator, Row::iterator> range(equal_range(state_coll.begin(), state_coll.end(), state, AddressLessThan));
if (range.first == range.second)
{
state_coll.insert(range.first, state);
}
else
{
if ((distance(range.first, range.second) == 1) && range.first->end_sequence == true)
{
*range.first = state;
}
else
{
state_coll.insert(range.second, state);
}
}
}
}
void
DWARFDebugLine::Row::Dump(Log *log, const Row::collection& state_coll)
{
std::for_each (state_coll.begin(), state_coll.end(), bind2nd(std::mem_fun_ref(&Row::Dump),log));
}
DWARFDebugLine::State::State(Prologue::shared_ptr& p, Log *l, DWARFDebugLine::State::Callback cb, void* userData) :
Row (p->default_is_stmt),
prologue (p),
log (l),
callback (cb),
callbackUserData (userData),
row (StartParsingLineTable)
{
if (callback)
callback(0, *this, callbackUserData);
}
void
DWARFDebugLine::State::Reset()
{
Row::Reset(prologue->default_is_stmt);
}
void
DWARFDebugLine::State::AppendRowToMatrix(dw_offset_t offset)
{
if (log)
{
if (row == 0)
{
log->PutCString ("Address Line Column File ISA Flags");
log->PutCString ("------------------ ------ ------ ------ --- -------------");
}
Dump (log);
}
++row; if (callback)
callback(offset, *this, callbackUserData);
PostAppend();
}
void
DWARFDebugLine::State::Finalize(dw_offset_t offset)
{
row = DoneParsingLineTable;
if (callback)
callback(offset, *this, callbackUserData);
}