https://github.com/Nerixyz created 
https://github.com/llvm/llvm-project/pull/214828

Intends to fix the failure from 
https://github.com/llvm/llvm-project/pull/212013#issuecomment-5220617065.

I overlooked that the original code returned an empty `TypeAndOrName` if no 
type with the specified name was found: 
https://github.com/llvm/llvm-project/blob/9b1218ce69e06a22699bc196888fc0396d989c81/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABIRuntime.cpp#L84-L88

In my PR, I always returned a `TypeAndOrName` with a name set. With this 
change, we only set return a non-empty `TypeAndOrName` if there was any type 
with the specified name.

>From 2f8426b1eb3e42a668084260c996f71ba173c04a Mon Sep 17 00:00:00 2001
From: Nerixyz <[email protected]>
Date: Fri, 7 Aug 2026 20:46:51 +0200
Subject: [PATCH] [lldb] Don't resolve dynamic type info if no named type
 exists

---
 .../LanguageRuntime/CPlusPlus/CommonABIRuntime.cpp       | 9 ++++++---
 .../Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.h | 8 +++++++-
 .../LanguageRuntime/CPlusPlus/ItaniumABIRuntime.cpp      | 7 ++++++-
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.cpp 
b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.cpp
index 91db30ddcc1b4..f72ad0460bf29 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.cpp
@@ -17,11 +17,13 @@ using namespace lldb_private;
 
 CommonABIRuntime::CommonABIRuntime(Process *process) : m_process(process) {}
 
-lldb::TypeSP
-CommonABIRuntime::LookupTypeByName(llvm::StringRef type_name,
-                                   lldb::ModuleSP preferred_module) const {
+lldb::TypeSP CommonABIRuntime::LookupTypeByName(llvm::StringRef type_name,
+                                                lldb::ModuleSP 
preferred_module,
+                                                bool &any_found) const {
   Log *log = GetLog(LLDBLog::Object);
 
+  any_found = false;
+
   ConstString const_lookup_name(type_name);
   TypeList class_types;
   // First look in the module that the vtable symbol came from and
@@ -52,6 +54,7 @@ CommonABIRuntime::LookupTypeByName(llvm::StringRef type_name,
     LLDB_LOG(log, "Failed to find '{0}'", type_name);
     return {};
   }
+  any_found = true;
 
   if (class_types.GetSize() == 1) {
     type_sp = class_types.GetTypeAtIndex(0);
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.h 
b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.h
index 8af61ec2c2c6d..961e9c9606c51 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.h
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.h
@@ -22,8 +22,14 @@ class CommonABIRuntime {
 protected:
   CommonABIRuntime(Process *process);
 
+  /// Find a type by its name, preferably in `preferred_module`.
+  ///
+  /// `any_found` will be set to `true` if any type with the name is found.
+  /// Even if a type with the name was found, this function may return an empty
+  /// `TypeSP` if the type is not a C++ type.
   lldb::TypeSP LookupTypeByName(llvm::StringRef type_name,
-                                lldb::ModuleSP preferred_module) const;
+                                lldb::ModuleSP preferred_module,
+                                bool &any_found) const;
 
 protected:
   Process *m_process;
diff --git 
a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABIRuntime.cpp 
b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABIRuntime.cpp
index e139ee1623f4b..f09a9b40a9807 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABIRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABIRuntime.cpp
@@ -55,8 +55,13 @@ ItaniumABIRuntime::GetTypeInfo(ValueObject &in_value,
       lookup_name.append(class_name.data(), class_name.size());
 
       type_info.SetName(class_name);
+      bool any_found = false;
       TypeSP type_sp = LookupTypeByName(
-          class_name, vtable_info.symbol->CalculateSymbolContextModule());
+          class_name, vtable_info.symbol->CalculateSymbolContextModule(),
+          any_found);
+      if (!any_found)
+        return TypeAndOrName(); // Type is not dynamic.
+
       if (type_sp) {
         LLDB_LOGF(log,
                   "0x%16.16" PRIx64

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to