[Lldb-commits] [lldb] [lldb] Move common functionality out of Itanium ABI runtime (PR #191275)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Apr 9 11:59:40 PDT 2026
https://github.com/Nerixyz created https://github.com/llvm/llvm-project/pull/191275
To be able to support both the Microsoft ABI and Itanium ABI in the same process, this moves out common functionality of the Itanium ABI. It introduces the `CommonABIRuntime` which is the base class for both ABIs.
In `CPPLanguageRuntime` we store a vector of these runtimes. For exception breakpoints, we let both add their functions and filters.
For dynamic values, we resolve the VTable first. This is identical on both ABIs - the first "member" of a dynamic class will be the VTable. Getting to the dynamic type afterward is ABI specific. So when we found the VTable symbol, we ask each ABI if it's a symbol they can handle. If so, we remember that and let the ABI do the rest.
When adding `GetDynamicTypeAndAddress` for the MS ABI, I needed the functionality to find a type by name and cache the dynamic type info. These were moved to `CommonABIRuntime` as well.
>From 7724db2fc62ceb2b4a7c3b54d8936b3ca2676d20 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Tue, 17 Mar 2026 22:07:24 +0100
Subject: [PATCH] [lldb] Move common functionality out of Itanium ABI runtime
---
.../LanguageRuntime/CPlusPlus/CMakeLists.txt | 1 +
.../CPlusPlus/CPPLanguageRuntime.cpp | 157 +++++++++++-
.../CPlusPlus/CPPLanguageRuntime.h | 15 +-
.../CPlusPlus/CommonABIRuntime.cpp | 139 +++++++++++
.../CPlusPlus/CommonABIRuntime.h | 68 +++++
.../CPlusPlus/ItaniumABIRuntime.cpp | 234 ++----------------
.../CPlusPlus/ItaniumABIRuntime.h | 30 +--
7 files changed, 398 insertions(+), 246 deletions(-)
create mode 100644 lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.cpp
create mode 100644 lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.h
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CMakeLists.txt b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CMakeLists.txt
index ca54601d99cff..dcf8fcd850db5 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CMakeLists.txt
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CMakeLists.txt
@@ -1,5 +1,6 @@
add_lldb_library(lldbPluginCPPRuntime PLUGIN
CommandObjectCPlusPlus.cpp
+ CommonABIRuntime.cpp
CPPLanguageRuntime.cpp
ItaniumABIRuntime.cpp
VerboseTrapFrameRecognizer.cpp
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
index c517ec8611932..2b657796c4f5e 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
@@ -13,6 +13,7 @@
#include "CPPLanguageRuntime.h"
#include "CommandObjectCPlusPlus.h"
+#include "ItaniumABIRuntime.h"
#include "VerboseTrapFrameRecognizer.h"
#include "llvm/ADT/StringRef.h"
@@ -32,6 +33,7 @@
#include "lldb/Target/StackFrameRecognizer.h"
#include "lldb/Target/ThreadPlanRunToAddress.h"
#include "lldb/Target/ThreadPlanStepInRange.h"
+#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Timer.h"
using namespace lldb;
@@ -110,7 +112,7 @@ class LibCXXFrameRecognizer : public StackFrameRecognizer {
};
CPPLanguageRuntime::CPPLanguageRuntime(Process *process)
- : LanguageRuntime(process), m_itanium_runtime(process) {
+ : LanguageRuntime(process) {
if (process) {
process->GetTarget().GetFrameRecognizerManager().AddRecognizer(
StackFrameRecognizerSP(new LibCXXFrameRecognizer()), {},
@@ -120,6 +122,7 @@ CPPLanguageRuntime::CPPLanguageRuntime(Process *process)
RegisterVerboseTrapFrameRecognizer(*process);
}
+ m_abi_runtimes.emplace_back(std::make_unique<ItaniumABIRuntime>(process));
}
bool CPPLanguageRuntime::IsAllowedRuntimeValue(ConstString name) {
@@ -524,8 +527,15 @@ bool CPPLanguageRuntime::GetDynamicTypeAndAddress(
if (!CouldHaveDynamicValue(in_value))
return false;
- return m_itanium_runtime.GetDynamicTypeAndAddress(
- in_value, use_dynamic, class_type_or_name, dynamic_address, value_type);
+ llvm::Expected<VTableInfoEntry> entry =
+ GetVTableInfoEntry(in_value, /*check_type=*/false);
+ if (!entry) {
+ llvm::consumeError(entry.takeError());
+ return false;
+ }
+
+ return entry->runtime->GetDynamicTypeAndAddress(
+ in_value, use_dynamic, entry->info, class_type_or_name, dynamic_address);
}
TypeAndOrName
@@ -588,7 +598,11 @@ void CPPLanguageRuntime::Terminate() {
llvm::Expected<LanguageRuntime::VTableInfo>
CPPLanguageRuntime::GetVTableInfo(ValueObject &in_value, bool check_type) {
- return m_itanium_runtime.GetVTableInfo(in_value, check_type);
+ llvm::Expected<VTableInfoEntry> entry =
+ GetVTableInfoEntry(in_value, check_type);
+ if (!entry)
+ return entry.takeError();
+ return entry->info;
}
BreakpointResolverSP
@@ -602,8 +616,10 @@ CPPLanguageRuntime::CreateExceptionResolver(const BreakpointSP &bkpt,
bool catch_bp, bool throw_bp,
bool for_expressions) {
std::vector<const char *> exception_names;
- m_itanium_runtime.AppendExceptionBreakpointFunctions(
- exception_names, catch_bp, throw_bp, for_expressions);
+ for (const auto &runtime : m_abi_runtimes) {
+ runtime->AppendExceptionBreakpointFunctions(exception_names, catch_bp,
+ throw_bp, for_expressions);
+ }
BreakpointResolverSP resolver_sp(new BreakpointResolverName(
bkpt, exception_names.data(), exception_names.size(),
@@ -616,8 +632,9 @@ lldb::SearchFilterSP CPPLanguageRuntime::CreateExceptionSearchFilter() {
Target &target = m_process->GetTarget();
FileSpecList filter_modules;
- m_itanium_runtime.AppendExceptionBreakpointFilterModules(filter_modules,
- target);
+ for (const auto &runtime : m_abi_runtimes)
+ runtime->AppendExceptionBreakpointFilterModules(filter_modules, target);
+
return target.GetSearchFilterForModuleList(&filter_modules);
}
@@ -684,5 +701,127 @@ bool CPPLanguageRuntime::ExceptionBreakpointsExplainStop(
lldb::ValueObjectSP
CPPLanguageRuntime::GetExceptionObjectForThread(lldb::ThreadSP thread_sp) {
- return m_itanium_runtime.GetExceptionObjectForThread(std::move(thread_sp));
+ for (auto &runtime : m_abi_runtimes) {
+ ValueObjectSP valobj = runtime->GetExceptionObjectForThread(thread_sp);
+ if (valobj)
+ return valobj;
+ }
+ return {};
+}
+
+static llvm::Error typeHasVTable(CompilerType type) {
+ // Check to make sure the class has a vtable.
+ CompilerType original_type = type;
+ if (type.IsPointerOrReferenceType()) {
+ CompilerType pointee_type = type.GetPointeeType();
+ if (pointee_type)
+ type = pointee_type;
+ }
+
+ // Make sure this is a class or a struct first by checking the type class
+ // bitfield that gets returned.
+ if ((type.GetTypeClass() & (eTypeClassStruct | eTypeClassClass)) == 0) {
+ return llvm::createStringError(
+ std::errc::invalid_argument,
+ "type \"%s\" is not a class or struct or a pointer to one",
+ original_type.GetTypeName().AsCString("<invalid>"));
+ }
+
+ // Check if the type has virtual functions by asking it if it is polymorphic.
+ if (!type.IsPolymorphicClass()) {
+ return llvm::createStringError(std::errc::invalid_argument,
+ "type \"%s\" doesn't have a vtable",
+ type.GetTypeName().AsCString("<invalid>"));
+ }
+ return llvm::Error::success();
+}
+
+// This function can accept both pointers or references to classes as well as
+// instances of classes. If you are using this function during dynamic type
+// detection, only valid ValueObjects that return true to
+// CouldHaveDynamicValue(...) should call this function and \a check_type
+// should be set to false. This function is also used by ValueObjectVTable
+// and is can pass in instances of classes which is not suitable for dynamic
+// type detection, these cases should pass true for \a check_type.
+llvm::Expected<CPPLanguageRuntime::VTableInfoEntry>
+CPPLanguageRuntime::GetVTableInfoEntry(ValueObject &in_value, bool check_type) {
+ CompilerType type = in_value.GetCompilerType();
+ if (check_type) {
+ if (llvm::Error err = typeHasVTable(type))
+ return std::move(err);
+ }
+ ExecutionContext exe_ctx(in_value.GetExecutionContextRef());
+ Process *process = exe_ctx.GetProcessPtr();
+ if (process == nullptr)
+ return llvm::createStringError(std::errc::invalid_argument,
+ "invalid process");
+
+ auto [original_ptr, address_type] =
+ type.IsPointerOrReferenceType()
+ ? in_value.GetPointerValue()
+ : in_value.GetAddressOf(/*scalar_is_load_address=*/true);
+ if (original_ptr == LLDB_INVALID_ADDRESS || address_type != eAddressTypeLoad)
+ return llvm::createStringError(std::errc::invalid_argument,
+ "failed to get the address of the value");
+
+ Status error;
+ lldb::addr_t vtable_load_addr =
+ process->ReadPointerFromMemory(original_ptr, error);
+
+ if (!error.Success() || vtable_load_addr == LLDB_INVALID_ADDRESS)
+ return llvm::createStringError(
+ std::errc::invalid_argument,
+ "failed to read vtable pointer from memory at 0x%" PRIx64,
+ original_ptr);
+
+ // The vtable load address can have authentication bits with
+ // AArch64 targets on Darwin.
+ vtable_load_addr = process->FixDataAddress(vtable_load_addr);
+
+ // Find the symbol that contains the "vtable_load_addr" address
+ Address vtable_addr;
+ if (!process->GetTarget().ResolveLoadAddress(vtable_load_addr, vtable_addr))
+ return llvm::createStringError(std::errc::invalid_argument,
+ "failed to resolve vtable pointer 0x%" PRIx64
+ " to a section",
+ vtable_load_addr);
+
+ // Check our cache first to see if we already have this info
+ {
+ std::lock_guard<std::mutex> locker(m_vtable_mutex);
+ auto pos = m_vtable_info_map.find(vtable_addr);
+ if (pos != m_vtable_info_map.end())
+ return pos->second;
+ }
+
+ Symbol *symbol = vtable_addr.CalculateSymbolContextSymbol();
+ if (symbol == nullptr)
+ return llvm::createStringError(std::errc::invalid_argument,
+ "no symbol found for 0x%" PRIx64,
+ vtable_load_addr);
+ Mangled &mangled = symbol->GetMangled();
+ Log *log = GetLog(LLDBLog::Object);
+ for (const auto &runtime : m_abi_runtimes) {
+ if (runtime->IsVTableSymbol(mangled)) {
+ LLDB_LOG(log, "{0:x16} ({1}): symbol='{2}' matches {3}", original_ptr,
+ in_value.GetTypeName(), mangled.GetDemangledName(),
+ runtime->GetName());
+
+ VTableInfoEntry entry{
+ /*info=*/VTableInfo{vtable_addr, symbol},
+ /*runtime=*/runtime.get(),
+ };
+ std::lock_guard<std::mutex> locker(m_vtable_mutex);
+ m_vtable_info_map[vtable_addr] = entry;
+ return entry;
+ }
+ }
+
+ LLDB_LOG(log, "{0:x16} ({1}): symbol='{2}' does not match any runtime",
+ original_ptr, in_value.GetTypeName(), mangled.GetDemangledName());
+
+ return llvm::createStringError(std::errc::invalid_argument,
+ "symbol found that contains 0x%" PRIx64
+ " is not a vtable symbol",
+ vtable_load_addr);
}
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h
index 7c3dade76d703..823a968cbad8c 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h
@@ -13,7 +13,7 @@
#include "llvm/ADT/StringMap.h"
-#include "ItaniumABIRuntime.h"
+#include "CommonABIRuntime.h"
#include "lldb/Core/PluginInterface.h"
#include "lldb/Target/LanguageRuntime.h"
#include "lldb/lldb-private.h"
@@ -143,7 +143,18 @@ class CPPLanguageRuntime : public LanguageRuntime {
OperatorStringToCallableInfoMap CallableLookupCache;
lldb::BreakpointSP m_cxx_exception_bp_sp;
- ItaniumABIRuntime m_itanium_runtime;
+ std::vector<std::unique_ptr<CommonABIRuntime>> m_abi_runtimes;
+
+ struct VTableInfoEntry {
+ VTableInfo info;
+ CommonABIRuntime *runtime;
+ };
+
+ llvm::Expected<VTableInfoEntry> GetVTableInfoEntry(ValueObject &in_value,
+ bool check_type);
+
+ std::map<Address, VTableInfoEntry> m_vtable_info_map;
+ std::mutex m_vtable_mutex;
};
} // namespace lldb_private
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.cpp
new file mode 100644
index 0000000000000..e1241c0b583aa
--- /dev/null
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.cpp
@@ -0,0 +1,139 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "CommonABIRuntime.h"
+
+#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Utility/LLDBLog.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+CommonABIRuntime::CommonABIRuntime(Process *process) : m_process(process) {}
+
+bool CommonABIRuntime::IsVTableSymbol(Mangled &mangled) const { return false; }
+
+bool CommonABIRuntime::GetDynamicTypeAndAddress(
+ ValueObject &in_value, lldb::DynamicValueType use_dynamic,
+ const LanguageRuntime::VTableInfo &vtable_info,
+ TypeAndOrName &class_type_or_name, Address &dynamic_address) {
+ return false;
+}
+
+void CommonABIRuntime::AppendExceptionBreakpointFunctions(
+ std::vector<const char *> &names, bool catch_bp, bool throw_bp,
+ bool for_expressions) {}
+
+void CommonABIRuntime::AppendExceptionBreakpointFilterModules(
+ FileSpecList &list, const Target &target) {}
+
+lldb::ValueObjectSP
+CommonABIRuntime::GetExceptionObjectForThread(lldb::ThreadSP thread_sp) {
+ return {};
+}
+
+lldb::TypeSP
+CommonABIRuntime::LookupTypeByName(llvm::StringRef type_name,
+ lldb::ModuleSP preferred_module) const {
+ Log *log = GetLog(LLDBLog::Object);
+
+ TypeList class_types;
+ // We know the class name is absolute, so tell FindTypes that by
+ // prefixing it with the root namespace:
+ std::string lookup_name("::");
+ lookup_name.append(type_name.data(), type_name.size());
+ ConstString const_lookup_name(lookup_name);
+ // First look in the module that the vtable symbol came from and
+ // look for a single exact match.
+ TypeResults results;
+ TypeQuery query(const_lookup_name.GetStringRef(),
+ TypeQueryOptions::e_exact_match |
+ TypeQueryOptions::e_strict_namespaces |
+ TypeQueryOptions::e_find_one);
+ if (preferred_module) {
+ preferred_module->FindTypes(query, results);
+ TypeSP type_sp = results.GetFirstType();
+ if (type_sp)
+ class_types.Insert(type_sp);
+ }
+
+ // If we didn't find a symbol, then move on to the entire module
+ // list in the target and get as many unique matches as possible
+ if (class_types.Empty()) {
+ query.SetFindOne(false);
+ m_process->GetTarget().GetImages().FindTypes(nullptr, query, results);
+ for (const auto &type_sp : results.GetTypeMap().Types())
+ class_types.Insert(type_sp);
+ }
+
+ lldb::TypeSP type_sp;
+ if (class_types.Empty()) {
+ LLDB_LOG(log, "Failed to find '{0}'", type_name);
+ return {};
+ }
+
+ if (class_types.GetSize() == 1) {
+ type_sp = class_types.GetTypeAtIndex(0);
+ if (!type_sp)
+ return {};
+
+ if (!TypeSystemClang::IsCXXClassType(type_sp->GetForwardCompilerType()))
+ return {};
+ return type_sp;
+ }
+
+ size_t i;
+ if (log) {
+ LLDB_LOG(log,
+ "'{0}' has multiple matching dynamic "
+ "types:",
+ type_name);
+ for (i = 0; i < class_types.GetSize(); i++) {
+ type_sp = class_types.GetTypeAtIndex(i);
+ if (type_sp) {
+ LLDB_LOG(log, "[{0}]: uid={1:x}, type-name='{2}'", i, type_sp->GetID(),
+ type_sp->GetName());
+ }
+ }
+ }
+
+ for (i = 0; i < class_types.GetSize(); i++) {
+ type_sp = class_types.GetTypeAtIndex(i);
+ if (type_sp) {
+ if (TypeSystemClang::IsCXXClassType(type_sp->GetForwardCompilerType())) {
+ LLDB_LOG(log,
+ "'{0}' has multiple matching dynamic types, "
+ "picking this one: [{1}] uid={2:x}, type-name='{3}'\n",
+ type_name, i, type_sp->GetID(), type_sp->GetName());
+ return type_sp;
+ }
+ }
+ }
+
+ LLDB_LOG(log,
+ "'{0}' has multiple matching dynamic types, didn't find a C++ match",
+ type_name);
+ return {};
+}
+
+TypeAndOrName
+CommonABIRuntime::GetDynamicTypeInfo(const lldb_private::Address &vtable_addr) {
+ std::lock_guard<std::mutex> locker(m_mutex);
+ DynamicTypeCache::const_iterator pos = m_dynamic_type_map.find(vtable_addr);
+ if (pos == m_dynamic_type_map.end())
+ return TypeAndOrName();
+
+ return pos->second;
+}
+
+void CommonABIRuntime::SetDynamicTypeInfo(
+ const lldb_private::Address &vtable_addr, const TypeAndOrName &type_info) {
+ std::lock_guard<std::mutex> locker(m_mutex);
+ m_dynamic_type_map[vtable_addr] = type_info;
+}
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.h b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.h
new file mode 100644
index 0000000000000..b387ff0f8da8e
--- /dev/null
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CommonABIRuntime.h
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_CPLUSPLUS_COMMONABIRUNTIME_H
+#define LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_CPLUSPLUS_COMMONABIRUNTIME_H
+
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Target/Process.h"
+#include "lldb/ValueObject/ValueObject.h"
+
+#include <map>
+#include <mutex>
+
+namespace lldb_private {
+
+class CommonABIRuntime {
+public:
+ virtual ~CommonABIRuntime() = default;
+
+ virtual llvm::StringRef GetName() const = 0;
+
+ virtual bool IsVTableSymbol(Mangled &mangled) const;
+
+ virtual bool GetDynamicTypeAndAddress(
+ ValueObject &in_value, lldb::DynamicValueType use_dynamic,
+ const LanguageRuntime::VTableInfo &vtable_info,
+ TypeAndOrName &class_type_or_name, Address &dynamic_address);
+
+ virtual void
+ AppendExceptionBreakpointFunctions(std::vector<const char *> &names,
+ bool catch_bp, bool throw_bp,
+ bool for_expressions);
+
+ virtual void AppendExceptionBreakpointFilterModules(FileSpecList &list,
+ const Target &target);
+
+ virtual lldb::ValueObjectSP
+ GetExceptionObjectForThread(lldb::ThreadSP thread_sp);
+
+protected:
+ CommonABIRuntime(Process *process);
+
+ lldb::TypeSP LookupTypeByName(llvm::StringRef type_name,
+ lldb::ModuleSP preferred_module) const;
+
+ TypeAndOrName GetDynamicTypeInfo(const lldb_private::Address &vtable_addr);
+
+ void SetDynamicTypeInfo(const lldb_private::Address &vtable_addr,
+ const TypeAndOrName &type_info);
+
+protected:
+ Process *m_process;
+ std::mutex m_mutex;
+
+private:
+ using DynamicTypeCache = std::map<Address, TypeAndOrName>;
+
+ DynamicTypeCache m_dynamic_type_map;
+};
+
+} // namespace lldb_private
+
+#endif
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABIRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABIRuntime.cpp
index 4d9cf31c8904d..1fc835fa834db 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABIRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABIRuntime.cpp
@@ -19,7 +19,13 @@ using namespace lldb_private;
static const char *vtable_demangled_prefix = "vtable for ";
-ItaniumABIRuntime::ItaniumABIRuntime(Process *process) : m_process(process) {}
+ItaniumABIRuntime::ItaniumABIRuntime(Process *process)
+ : CommonABIRuntime(process) {}
+
+bool ItaniumABIRuntime::IsVTableSymbol(Mangled &mangled) const {
+ return mangled.GetDemangledName().GetStringRef().starts_with(
+ vtable_demangled_prefix);
+}
TypeAndOrName
ItaniumABIRuntime::GetTypeInfo(ValueObject &in_value,
@@ -49,94 +55,16 @@ ItaniumABIRuntime::GetTypeInfo(ValueObject &in_value,
lookup_name.append(class_name.data(), class_name.size());
type_info.SetName(class_name);
- ConstString const_lookup_name(lookup_name);
- TypeList class_types;
- ModuleSP module_sp = vtable_info.symbol->CalculateSymbolContextModule();
- // First look in the module that the vtable symbol came from and
- // look for a single exact match.
- TypeResults results;
- TypeQuery query(const_lookup_name.GetStringRef(),
- TypeQueryOptions::e_exact_match |
- TypeQueryOptions::e_strict_namespaces |
- TypeQueryOptions::e_find_one);
- if (module_sp) {
- module_sp->FindTypes(query, results);
- TypeSP type_sp = results.GetFirstType();
- if (type_sp)
- class_types.Insert(type_sp);
- }
-
- // If we didn't find a symbol, then move on to the entire module
- // list in the target and get as many unique matches as possible
- if (class_types.Empty()) {
- query.SetFindOne(false);
- m_process->GetTarget().GetImages().FindTypes(nullptr, query, results);
- for (const auto &type_sp : results.GetTypeMap().Types())
- class_types.Insert(type_sp);
+ TypeSP type_sp = LookupTypeByName(
+ class_name, vtable_info.symbol->CalculateSymbolContextModule());
+ if (type_sp) {
+ LLDB_LOG(
+ log,
+ "static-type = '{0}' has dynamic type: uid={1:x}, type-name='{2}'",
+ in_value.GetTypeName(), type_sp->GetID(), type_sp->GetName());
+ type_info.SetTypeSP(std::move(type_sp));
}
- lldb::TypeSP type_sp;
- if (class_types.Empty()) {
- LLDB_LOGF(log, "0x%16.16" PRIx64 ": is not dynamic\n",
- in_value.GetPointerValue().address);
- return TypeAndOrName();
- }
- if (class_types.GetSize() == 1) {
- type_sp = class_types.GetTypeAtIndex(0);
- if (type_sp) {
- if (TypeSystemClang::IsCXXClassType(
- type_sp->GetForwardCompilerType())) {
- LLDB_LOGF(log,
- "0x%16.16" PRIx64
- ": static-type = '%s' has dynamic type: uid={0x%" PRIx64
- "}, type-name='%s'\n",
- in_value.GetPointerValue().address,
- in_value.GetTypeName().AsCString(""), type_sp->GetID(),
- type_sp->GetName().GetCString());
- type_info.SetTypeSP(type_sp);
- }
- }
- } else {
- size_t i;
- if (log) {
- for (i = 0; i < class_types.GetSize(); i++) {
- type_sp = class_types.GetTypeAtIndex(i);
- if (type_sp) {
- LLDB_LOGF(log,
- "0x%16.16" PRIx64
- ": static-type = '%s' has multiple matching dynamic "
- "types: uid={0x%" PRIx64 "}, type-name='%s'\n",
- in_value.GetPointerValue().address,
- in_value.GetTypeName().AsCString(""), type_sp->GetID(),
- type_sp->GetName().GetCString());
- }
- }
- }
-
- for (i = 0; i < class_types.GetSize(); i++) {
- type_sp = class_types.GetTypeAtIndex(i);
- if (type_sp) {
- if (TypeSystemClang::IsCXXClassType(
- type_sp->GetForwardCompilerType())) {
- LLDB_LOGF(log,
- "0x%16.16" PRIx64 ": static-type = '%s' has multiple "
- "matching dynamic types, picking "
- "this one: uid={0x%" PRIx64 "}, type-name='%s'\n",
- in_value.GetPointerValue().address,
- in_value.GetTypeName().AsCString(""), type_sp->GetID(),
- type_sp->GetName().GetCString());
- type_info.SetTypeSP(type_sp);
- }
- }
- }
-
- LLDB_LOGF(log,
- "0x%16.16" PRIx64
- ": static-type = '%s' has multiple matching dynamic "
- "types, didn't find a C++ match\n",
- in_value.GetPointerValue().address,
- in_value.GetTypeName().AsCString(""));
- }
if (type_info)
SetDynamicTypeInfo(vtable_info.addr, type_info);
return type_info;
@@ -145,114 +73,10 @@ ItaniumABIRuntime::GetTypeInfo(ValueObject &in_value,
return TypeAndOrName();
}
-llvm::Error ItaniumABIRuntime::TypeHasVTable(CompilerType type) {
- // Check to make sure the class has a vtable.
- CompilerType original_type = type;
- if (type.IsPointerOrReferenceType()) {
- CompilerType pointee_type = type.GetPointeeType();
- if (pointee_type)
- type = pointee_type;
- }
-
- // Make sure this is a class or a struct first by checking the type class
- // bitfield that gets returned.
- if ((type.GetTypeClass() & (eTypeClassStruct | eTypeClassClass)) == 0) {
- return llvm::createStringError(
- std::errc::invalid_argument,
- "type \"%s\" is not a class or struct or a pointer to one",
- original_type.GetTypeName().AsCString("<invalid>"));
- }
-
- // Check if the type has virtual functions by asking it if it is polymorphic.
- if (!type.IsPolymorphicClass()) {
- return llvm::createStringError(std::errc::invalid_argument,
- "type \"%s\" doesn't have a vtable",
- type.GetTypeName().AsCString("<invalid>"));
- }
- return llvm::Error::success();
-}
-
-// This function can accept both pointers or references to classes as well as
-// instances of classes. If you are using this function during dynamic type
-// detection, only valid ValueObjects that return true to
-// CouldHaveDynamicValue(...) should call this function and \a check_type
-// should be set to false. This function is also used by ValueObjectVTable
-// and is can pass in instances of classes which is not suitable for dynamic
-// type detection, these cases should pass true for \a check_type.
-llvm::Expected<LanguageRuntime::VTableInfo>
-ItaniumABIRuntime::GetVTableInfo(ValueObject &in_value, bool check_type) {
-
- CompilerType type = in_value.GetCompilerType();
- if (check_type) {
- if (llvm::Error err = TypeHasVTable(type))
- return std::move(err);
- }
- ExecutionContext exe_ctx(in_value.GetExecutionContextRef());
- Process *process = exe_ctx.GetProcessPtr();
- if (process == nullptr)
- return llvm::createStringError(std::errc::invalid_argument,
- "invalid process");
-
- auto [original_ptr, address_type] =
- type.IsPointerOrReferenceType()
- ? in_value.GetPointerValue()
- : in_value.GetAddressOf(/*scalar_is_load_address=*/true);
- if (original_ptr == LLDB_INVALID_ADDRESS || address_type != eAddressTypeLoad)
- return llvm::createStringError(std::errc::invalid_argument,
- "failed to get the address of the value");
-
- Status error;
- lldb::addr_t vtable_load_addr =
- process->ReadPointerFromMemory(original_ptr, error);
-
- if (!error.Success() || vtable_load_addr == LLDB_INVALID_ADDRESS)
- return llvm::createStringError(
- std::errc::invalid_argument,
- "failed to read vtable pointer from memory at 0x%" PRIx64,
- original_ptr);
-
- // The vtable load address can have authentication bits with
- // AArch64 targets on Darwin.
- vtable_load_addr = process->FixDataAddress(vtable_load_addr);
-
- // Find the symbol that contains the "vtable_load_addr" address
- Address vtable_addr;
- if (!process->GetTarget().ResolveLoadAddress(vtable_load_addr, vtable_addr))
- return llvm::createStringError(std::errc::invalid_argument,
- "failed to resolve vtable pointer 0x%" PRIx64
- "to a section",
- vtable_load_addr);
-
- // Check our cache first to see if we already have this info
- {
- std::lock_guard<std::mutex> locker(m_mutex);
- auto pos = m_vtable_info_map.find(vtable_addr);
- if (pos != m_vtable_info_map.end())
- return pos->second;
- }
-
- Symbol *symbol = vtable_addr.CalculateSymbolContextSymbol();
- if (symbol == nullptr)
- return llvm::createStringError(std::errc::invalid_argument,
- "no symbol found for 0x%" PRIx64,
- vtable_load_addr);
- llvm::StringRef name = symbol->GetMangled().GetDemangledName().GetStringRef();
- if (name.starts_with(vtable_demangled_prefix)) {
- LanguageRuntime::VTableInfo info = {vtable_addr, symbol};
- std::lock_guard<std::mutex> locker(m_mutex);
- auto pos = m_vtable_info_map[vtable_addr] = info;
- return info;
- }
- return llvm::createStringError(std::errc::invalid_argument,
- "symbol found that contains 0x%" PRIx64
- " is not a vtable symbol",
- vtable_load_addr);
-}
-
bool ItaniumABIRuntime::GetDynamicTypeAndAddress(
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
- TypeAndOrName &class_type_or_name, Address &dynamic_address,
- Value::ValueType &value_type) {
+ const LanguageRuntime::VTableInfo &vtable_info,
+ TypeAndOrName &class_type_or_name, Address &dynamic_address) {
// For Itanium, if the type has a vtable pointer in the object, it will be at
// offset 0 in the object. That will point to the "address point" within the
// vtable (not the beginning of the vtable.) We can then look up the symbol
@@ -266,14 +90,6 @@ bool ItaniumABIRuntime::GetDynamicTypeAndAddress(
// want GetVTableInfo to check the type since we accept void * as a possible
// dynamic type and that won't pass the type check. We already checked the
// type above in CouldHaveDynamicValue(...).
- llvm::Expected<LanguageRuntime::VTableInfo> vtable_info_or_err =
- GetVTableInfo(in_value, /*check_type=*/false);
- if (!vtable_info_or_err) {
- llvm::consumeError(vtable_info_or_err.takeError());
- return false;
- }
-
- const LanguageRuntime::VTableInfo &vtable_info = vtable_info_or_err.get();
class_type_or_name = GetTypeInfo(in_value, vtable_info);
if (!class_type_or_name)
@@ -432,19 +248,3 @@ ItaniumABIRuntime::GetExceptionObjectForThread(ThreadSP thread_sp) {
return exception;
}
-
-TypeAndOrName ItaniumABIRuntime::GetDynamicTypeInfo(
- const lldb_private::Address &vtable_addr) {
- std::lock_guard<std::mutex> locker(m_mutex);
- DynamicTypeCache::const_iterator pos = m_dynamic_type_map.find(vtable_addr);
- if (pos == m_dynamic_type_map.end())
- return TypeAndOrName();
- else
- return pos->second;
-}
-
-void ItaniumABIRuntime::SetDynamicTypeInfo(
- const lldb_private::Address &vtable_addr, const TypeAndOrName &type_info) {
- std::lock_guard<std::mutex> locker(m_mutex);
- m_dynamic_type_map[vtable_addr] = type_info;
-}
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABIRuntime.h b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABIRuntime.h
index 75a8142b26d93..e44e958da4067 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABIRuntime.h
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABIRuntime.h
@@ -9,6 +9,7 @@
#ifndef LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_CPLUSPLUS_ITANIUMABIRUNTIME_H
#define LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_CPLUSPLUS_ITANIUMABIRUNTIME_H
+#include "CommonABIRuntime.h"
#include "lldb/Target/LanguageRuntime.h"
#include "lldb/ValueObject/ValueObject.h"
@@ -16,47 +17,40 @@
namespace lldb_private {
-class ItaniumABIRuntime {
+class ItaniumABIRuntime : public CommonABIRuntime {
public:
ItaniumABIRuntime(Process *process);
+ llvm::StringRef GetName() const override { return "Itanium ABI runtime"; }
+
+ bool IsVTableSymbol(Mangled &manged) const override;
+
llvm::Expected<LanguageRuntime::VTableInfo>
GetVTableInfo(ValueObject &in_value, bool check_type);
bool GetDynamicTypeAndAddress(ValueObject &in_value,
lldb::DynamicValueType use_dynamic,
+ const LanguageRuntime::VTableInfo &vtable_info,
TypeAndOrName &class_type_or_name,
- Address &dynamic_address,
- Value::ValueType &value_type);
+ Address &dynamic_address) override;
void AppendExceptionBreakpointFunctions(std::vector<const char *> &names,
bool catch_bp, bool throw_bp,
- bool for_expressions);
+ bool for_expressions) override;
void AppendExceptionBreakpointFilterModules(FileSpecList &list,
- const Target &target);
+ const Target &target) override;
- lldb::ValueObjectSP GetExceptionObjectForThread(lldb::ThreadSP thread_sp);
+ lldb::ValueObjectSP
+ GetExceptionObjectForThread(lldb::ThreadSP thread_sp) override;
private:
TypeAndOrName GetTypeInfo(ValueObject &in_value,
const LanguageRuntime::VTableInfo &vtable_info);
- llvm::Error TypeHasVTable(CompilerType type);
-
- TypeAndOrName GetDynamicTypeInfo(const lldb_private::Address &vtable_addr);
-
- void SetDynamicTypeInfo(const lldb_private::Address &vtable_addr,
- const TypeAndOrName &type_info);
-
- using DynamicTypeCache = std::map<Address, TypeAndOrName>;
using VTableInfoCache = std::map<Address, LanguageRuntime::VTableInfo>;
- DynamicTypeCache m_dynamic_type_map;
VTableInfoCache m_vtable_info_map;
- std::mutex m_mutex;
-
- Process *m_process;
};
} // namespace lldb_private
More information about the lldb-commits
mailing list