voidDebugger::set_breakpoint_at_function(const std::string& name){ for (constauto& cu : m_dwarf.compilation_units()) { for (constauto& die : cu.root()) { if (die.has(dwarf::DW_AT::name) && at_name(die) == name) { auto low_pc = at_low_pc(die); auto entry = get_line_entry_from_pc(low_pc); ++entry; //skip useless line set_breakPoint(offset_dwarf_address(entry->address)); } } } }
line table 大概是这个样子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
.debug_line: line number info for a single cu Source lines (from CU-DIE at .debug_info offset 0x0000000b):
NS new statement, BB new basic block, ET end of text sequence PE prologue end, EB epilogue begin IS=val ISA number, DI=val discriminator value <pc> [lno,col] NS BB ET PE EB IS= DI= uri: "filepath" 0x00001189 [ 2,12] NS uri: "/home/luyoung/mydebugger/examples/hello.cpp" 0x00001191 [ 3,18] NS 0x000011aa [ 4,12] NS 0x000011af [ 5, 1] NS 0x000011b1 [ 5, 1] NS 0x000011c3 [ 5, 1] NS 0x000011c9 [ 5, 1] DI=0x1 0x000011d2 [ 74,25] NS uri: "/usr/include/c++/11/iostream" 0x00001204 [ 5, 1] NS uri: "/home/luyoung/mydebugger/examples/hello.cpp" 0x00001207 [ 5, 1] NS 0x0000120f [ 5, 1] NS 0x00001220 [ 5, 1] NS ET