From a78899d40a899cabdfa5c7da9558f15e53b8bc22 Mon Sep 17 00:00:00 2001 From: Kacper Kasper Date: Fri, 26 Mar 2021 23:02:52 +0100 Subject: [PATCH] Debugger: fix infinite recursion when resolving lambdas * Should fix #14346. Uploaded executable there doesn't work anymore, but this patch is prepared for case in #16040, and fixes #16680 too. * The issue is that if lambda parameters use an alias, this alias has that lambda as a parent. Specifically the compiler generates operator() subprogram, Debugger tries to resolve types for its parameters, but at the same time it is a parent namespace for those types. * Call chain: operator()( -> type 1 -> namespace: operator()( -> type 1 -> namespace: operator()( -> ... Change-Id: I7aad150a8d9de4f0c01ae0c1db5e486416b72112 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3824 Reviewed-by: Adrien Destugues --- src/kits/debugger/dwarf/DwarfUtils.cpp | 11 +++++++---- src/kits/debugger/dwarf/DwarfUtils.h | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/kits/debugger/dwarf/DwarfUtils.cpp b/src/kits/debugger/dwarf/DwarfUtils.cpp index 88fd0de2f9..535639ea64 100644 --- a/src/kits/debugger/dwarf/DwarfUtils.cpp +++ b/src/kits/debugger/dwarf/DwarfUtils.cpp @@ -40,7 +40,8 @@ DwarfUtils::GetDIEName(const DebugInfoEntry* entry, BString& _name) /*static*/ void -DwarfUtils::GetDIETypeName(const DebugInfoEntry* entry, BString& _name) +DwarfUtils::GetDIETypeName(const DebugInfoEntry* entry, BString& _name, + const DebugInfoEntry* requestingEntry) { const DIEType* type = dynamic_cast(entry); if (type == NULL) @@ -79,7 +80,7 @@ DwarfUtils::GetDIETypeName(const DebugInfoEntry* entry, BString& _name) if (type == NULL) typeName = "void"; else - GetFullyQualifiedDIEName(type, typeName); + GetFullyQualifiedDIEName(type, typeName, requestingEntry); if (modifier.Length() > 0) { if (modifier[modifier.Length() - 1] == ' ') @@ -163,7 +164,7 @@ DwarfUtils::GetFullDIEName(const DebugInfoEntry* entry, BString& _name) BString paramName; BString modifier; DIEType* type = parameter->GetType(); - GetDIETypeName(type, paramName); + GetDIETypeName(type, paramName, entry); if (firstParameter) firstParameter = false; @@ -185,7 +186,7 @@ DwarfUtils::GetFullDIEName(const DebugInfoEntry* entry, BString& _name) /*static*/ void DwarfUtils::GetFullyQualifiedDIEName(const DebugInfoEntry* entry, - BString& _name) + BString& _name, const DebugInfoEntry* requestingEntry) { // If we don't seem to have a name but an abstract origin, return the // origin's name. @@ -207,6 +208,8 @@ DwarfUtils::GetFullyQualifiedDIEName(const DebugInfoEntry* entry, // Get the namespace, if any. DebugInfoEntry* parent = entry->Parent(); while (parent != NULL) { + if (parent == requestingEntry) + break; if (parent->IsNamespace()) { BString parentName; GetFullyQualifiedDIEName(parent, parentName); diff --git a/src/kits/debugger/dwarf/DwarfUtils.h b/src/kits/debugger/dwarf/DwarfUtils.h index bdc41c0490..2f8e0d7e4f 100644 --- a/src/kits/debugger/dwarf/DwarfUtils.h +++ b/src/kits/debugger/dwarf/DwarfUtils.h @@ -19,12 +19,16 @@ public: static void GetDIEName(const DebugInfoEntry* entry, BString& _name); static void GetDIETypeName(const DebugInfoEntry* entry, - BString& _name); + BString& _name, + const DebugInfoEntry* + requestingEntry = NULL); static void GetFullDIEName(const DebugInfoEntry* entry, BString& _name); static void GetFullyQualifiedDIEName( const DebugInfoEntry* entry, - BString& _name); + BString& _name, + const DebugInfoEntry* + requestingEntry = NULL); static bool GetDeclarationLocation(DwarfFile* dwarfFile, const DebugInfoEntry* entry,