Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions src/mgwhelp/dwarf_find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -605,35 +618,27 @@ create_aranges(Dwarf_Debug dbg, std::vector<My_Arange *> &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) {
Dwarf_Die cu_die = NULL;
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);
if (res == DW_DLV_ERROR) {
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;
Expand Down