Fix bug with non-recursive inline walking

This commit is contained in:
Jeremy 2024-03-30 23:10:56 -05:00
parent ab63c34827
commit 50483783cb
No known key found for this signature in database
GPG Key ID: BE03111EB7ED6E2E

View File

@ -384,6 +384,9 @@ namespace libdwarf {
ASSERT(die.get_tag() == DW_TAG_subprogram || die.get_tag() == DW_TAG_inlined_subroutine);
// get_inlines_info is recursive and recurses into dies with pc ranges matching the pc we're looking for,
// however, because I wouldn't want anything stack overflowing I'm breaking the recursion out into a loop
// while looping when we find the target die we need to be able to store a die somewhere that doesn't die
// at the end of the list traversal, we'll use this as a holder for it
die_object current_obj_holder(dbg, nullptr);
optional<std::reference_wrapper<const die_object>> current_die = die;
while(current_die.has_value()) {
auto child = current_die.unwrap().get().get_child();
@ -393,7 +396,7 @@ namespace libdwarf {
optional<std::reference_wrapper<const die_object>> target_die;
walk_die_list(
child,
[this, &cu_die, pc, dwversion, &inlines, &target_die] (const die_object& die) {
[this, &cu_die, pc, dwversion, &inlines, &target_die, &current_obj_holder] (const die_object& die) {
if(die.get_tag() == DW_TAG_inlined_subroutine && die.pc_in_die(dwversion, pc)) {
const auto name = subprogram_symbol(die, dwversion);
auto file_i = die.get_unsigned_attribute(DW_AT_call_file);
@ -427,7 +430,8 @@ namespace libdwarf {
name,
true
});
target_die = die;
current_obj_holder = die.clone();
target_die = current_obj_holder;
return false;
} else {
return true;