diff --git a/src/mgwhelp/dwarf_find.cpp b/src/mgwhelp/dwarf_find.cpp index d14d27b..f39a20c 100644 --- a/src/mgwhelp/dwarf_find.cpp +++ b/src/mgwhelp/dwarf_find.cpp @@ -263,10 +263,12 @@ dwarf_find_line(dwarf_module *dwarf, Dwarf_Addr addr, struct dwarf_line_info *in Dwarf_Unsigned lineno, plineno; Dwarf_Addr lineaddr, plineaddr; + Dwarf_Bool lineendsequence; char *file, *pfile; plineaddr = ~0ULL; plineno = lineno = 0; pfile = file = nullptr; + lineendsequence = FALSE; Dwarf_Signed i; i = 0; @@ -307,12 +309,21 @@ dwarf_find_line(dwarf_module *dwarf, Dwarf_Addr addr, struct dwarf_line_info *in break; } - if (dwarf_lineno(linebuf[i], &lineno, &error) != DW_DLV_OK) { + if (dwarf_lineendsequence(linebuf[i], &lineendsequence, &error) != DW_DLV_OK) { + OutputDebug("MGWHELP: dwarf_lineendsequence failed - %s\n", dwarf_errmsg(error)); + break; + } + + if (lineendsequence) { + lineno = 0; + } else if (dwarf_lineno(linebuf[i], &lineno, &error) != DW_DLV_OK) { OutputDebug("MGWHELP: dwarf_lineno failed - %s\n", dwarf_errmsg(error)); break; } - if (dwarf_linesrc(linebuf[i], &file, &error) != DW_DLV_OK) { + if (lineendsequence) { + file = nullptr; + } else if (dwarf_linesrc(linebuf[i], &file, &error) != DW_DLV_OK) { OutputDebug("MGWHELP: dwarf_linesrc failed - %s\n", dwarf_errmsg(error)); } @@ -322,7 +333,7 @@ dwarf_find_line(dwarf_module *dwarf, Dwarf_Addr addr, struct dwarf_line_info *in break; } - plineaddr = lineaddr; + plineaddr = lineendsequence ? ~0ULL : lineaddr; plineno = lineno; if (pfile) { dwarf_dealloc(dbg, pfile, DW_DLA_STRING); @@ -332,8 +343,9 @@ dwarf_find_line(dwarf_module *dwarf, Dwarf_Addr addr, struct dwarf_line_info *in ++i; } - if (result && file) { - info->filename = file; + if (result) { + if (file) + info->filename = file; info->line = lineno; info->offset_addr = offset_addr; } @@ -578,6 +590,7 @@ record_die(Dwarf_Debug dbg, res = dwarf_attr(cur_die, DW_AT_ranges, &attr, error); if (res != DW_DLV_OK) return res; + dwarf_dealloc_attribute(attr); res = dwarf_get_version_of_die(cur_die, &version, &offset_size); if (res != DW_DLV_OK) return res; @@ -605,7 +618,6 @@ create_aranges(Dwarf_Debug dbg, std::vector &myrec, Dwarf_Error *er Dwarf_Unsigned typeoffset = 0; Dwarf_Unsigned next_cu_header = 0; Dwarf_Half header_cu_type = 0; - Dwarf_Bool is_info = TRUE; int res = DW_DLV_OK; while (true) { @@ -613,7 +625,7 @@ create_aranges(Dwarf_Debug dbg, std::vector &myrec, Dwarf_Error *er Dwarf_Unsigned cu_header_length = 0; memset(&signature, 0, sizeof(signature)); - res = dwarf_next_cu_header_e(dbg, is_info, &cu_die, &cu_header_length, &version_stamp, + res = dwarf_next_cu_header_e(dbg, TRUE, &cu_die, &cu_header_length, &version_stamp, &abbrev_offset, &address_size, &offset_size, &extension_size, &signature, &typeoffset, &next_cu_header, &header_cu_type, error); @@ -621,19 +633,12 @@ create_aranges(Dwarf_Debug dbg, std::vector &myrec, Dwarf_Error *er return res; } if (res == DW_DLV_NO_ENTRY) { - if (is_info == TRUE) { - /* Done with .debug_info, now check for - .debug_types. */ - is_info = FALSE; - continue; - } /* No more CUs to read! Never found - what we were looking for in either - .debug_info or .debug_types. */ + what we were looking for in .debug_info. */ return res; } /* We have the cu_die . */ - res = record_die(dbg, cu_die, is_info, 0, myrec, error); + res = record_die(dbg, cu_die, TRUE, 0, myrec, error); dwarf_dealloc_die(cu_die); } return res;