[Lldb-commits] [lldb] [llvm] [lldb] Add initial MicrosoftABIRuntime (PR #235090)
via lldb-commits
lldb-commits at lists.llvm.org
Sat Oct 31 14:31:48 PDT 2026
https://github.com/Nerixyz updated https://github.com/llvm/llvm-project/pull/235090
>From f8b061995154d88301c02a1899a014e77a8661db Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Fri, 23 Oct 2026 21:50:49 +0200
Subject: [PATCH 01/14] [lldb] Add initial MicrosoftABIRuntime
---
.../Python/lldbsuite/test/lldbinline.py | 10 +
.../LanguageRuntime/CPlusPlus/CMakeLists.txt | 1 +
.../CPlusPlus/CPPLanguageRuntime.cpp | 3 +
.../CPlusPlus/MicrosoftABIRuntime.cpp | 426 ++++++++++++++++++
.../CPlusPlus/MicrosoftABIRuntime.h | 61 +++
.../dump_dynamic/TestDumpDynamic.py | 8 +-
.../dynamic_value_child_count/Makefile | 6 +
.../TestDynamicValueChildCount.py | 4 +-
.../functionalities/value_md5_crash/Makefile | 6 +
.../value_md5_crash/TestValueMD5Crash.py | 1 -
.../lang/cpp/dynamic-value-complex/Makefile | 9 +
.../TestDynamicValueComplex.py | 282 ++++++++++++
.../lang/cpp/dynamic-value-complex/main.cpp | 110 +++++
lldb/test/API/lang/cpp/dynamic-value/Makefile | 6 +
.../cpp/dynamic-value/TestDynamicValue.py | 38 +-
.../API/lang/cpp/dynamic-value/forward-a.cpp | 4 +-
lldb/test/API/python_api/type/Makefile | 6 +
lldb/test/API/python_api/type/TestTypeList.py | 1 -
llvm/docs/ReleaseNotes.md | 1 +
19 files changed, 965 insertions(+), 18 deletions(-)
create mode 100644 lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
create mode 100644 lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h
create mode 100644 lldb/test/API/lang/cpp/dynamic-value-complex/Makefile
create mode 100644 lldb/test/API/lang/cpp/dynamic-value-complex/TestDynamicValueComplex.py
create mode 100644 lldb/test/API/lang/cpp/dynamic-value-complex/main.cpp
diff --git a/lldb/packages/Python/lldbsuite/test/lldbinline.py b/lldb/packages/Python/lldbsuite/test/lldbinline.py
index 969ba3d7eaa1ed..e0a9b5774b8736 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbinline.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbinline.py
@@ -1,6 +1,7 @@
# System modules
import os
import textwrap
+import typing
# Third-party modules
import io
@@ -84,6 +85,9 @@ def handle_breakpoint(self, test, breakpoint_id):
class InlineTest(TestBase):
+ _build_dict: typing.Dict
+ _makefile_extras: typing.Optional[str]
+
def getBuildDirBasename(self):
return self.__class__.__name__ + "." + self.testMethodName
@@ -114,6 +118,9 @@ def BuildMakefile(self):
if "CXX_SOURCES" in list(categories.keys()):
makefile.write("CXXFLAGS += -std=c++11\n")
+ if self._makefile_extras is not None:
+ makefile.write(self._makefile_extras)
+
makefile.write("include Makefile.rules\n")
def _test(self):
@@ -212,6 +219,8 @@ def MakeInlineTest(
decorators=None,
name=None,
build_dict=None,
+ *,
+ makefile_extras=None,
):
# Adjust the filename if it ends in .pyc. We want filenames to
# reflect the source python file, not the compiled variant.
@@ -235,6 +244,7 @@ def MakeInlineTest(
test=test_func,
name=name,
_build_dict=build_dict,
+ _makefile_extras=makefile_extras,
),
)
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CMakeLists.txt b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CMakeLists.txt
index dcf8fcd850db57..9a0fd46cb2b923 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CMakeLists.txt
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CMakeLists.txt
@@ -3,6 +3,7 @@ add_lldb_library(lldbPluginCPPRuntime PLUGIN
CommonABIRuntime.cpp
CPPLanguageRuntime.cpp
ItaniumABIRuntime.cpp
+ MicrosoftABIRuntime.cpp
VerboseTrapFrameRecognizer.cpp
LINK_LIBS
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
index 0a82d59a215cad..1210a121eefc68 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
@@ -14,6 +14,7 @@
#include "CPPLanguageRuntime.h"
#include "CommandObjectCPlusPlus.h"
#include "ItaniumABIRuntime.h"
+#include "MicrosoftABIRuntime.h"
#include "VerboseTrapFrameRecognizer.h"
#include "llvm/ADT/StringRef.h"
@@ -125,6 +126,8 @@ CPPLanguageRuntime::CPPLanguageRuntime(Process *process)
}
m_abi_runtimes.emplace_back(new ItaniumABIRuntime(process));
+ if (process->GetTarget().GetArchitecture().GetTriple().isOSWindows())
+ m_abi_runtimes.emplace_back(new MicrosoftABIRuntime(process));
}
bool CPPLanguageRuntime::IsAllowedRuntimeValue(ConstString name) {
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
new file mode 100644
index 00000000000000..0355311b44f58a
--- /dev/null
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
@@ -0,0 +1,426 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 "MicrosoftABIRuntime.h"
+
+#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "clang/AST/RecordLayout.h"
+
+#include <deque>
+#include <mutex>
+
+using namespace lldb;
+using namespace lldb_private;
+
+static const llvm::StringRef s_vtable_demangled_indicator = "::`vftable'";
+static const llvm::StringRef s_rtti_complete_object_locator_indicator =
+ "::`RTTI Complete Object Locator'";
+
+static llvm::StringRef StripDemangledVTableSuffix(llvm::StringRef demangled) {
+ llvm::StringRef name = demangled.split(s_vtable_demangled_indicator).first;
+ name.consume_front("const ");
+ return name;
+}
+
+static bool
+SplitVTableComponents(llvm::StringRef demangled,
+ llvm::SmallVectorImpl<llvm::StringRef> &components) {
+ llvm::StringRef suffix = demangled.split(s_vtable_demangled_indicator).second;
+ if (suffix.empty())
+ return true; // e.g. MyClass::`vftable'
+
+ // Otherwise, suffix looks like "{for `MyBase2's `MyBase1'}" or
+ // "{for `MyBase'}".
+ if (!suffix.consume_front("{for `") || !suffix.consume_back("'}"))
+ return false;
+
+ suffix.split(components, "'s `");
+ return true;
+}
+
+MicrosoftABIRuntime::MicrosoftABIRuntime(Process *process)
+ : CommonABIRuntime(process) {}
+
+bool MicrosoftABIRuntime::GetDynamicTypeAndAddress(
+ ValueObject &in_value, lldb::DynamicValueType use_dynamic,
+ const LanguageRuntime::VTableInfo &vtable_info,
+ TypeAndOrName &class_type_or_name, Address &dynamic_address) {
+ std::optional<size_t> offset_to_top =
+ GetOffsetToTop(in_value, class_type_or_name, vtable_info);
+ if (!offset_to_top)
+ return false;
+
+ lldb::addr_t dynamic_addr =
+ in_value.GetPointerValue().address - *offset_to_top;
+ if (!m_process->GetTarget().ResolveLoadAddress(dynamic_addr, dynamic_address))
+ dynamic_address.SetRawAddress(dynamic_addr);
+
+ return true;
+}
+
+bool MicrosoftABIRuntime::IsVTableSymbol(Mangled &mangled) const {
+ return mangled.GetDemangledName().GetStringRef().contains(
+ s_vtable_demangled_indicator);
+}
+
+TypeAndOrName MicrosoftABIRuntime::GetTypeInfo(
+ ValueObject &in_value, const LanguageRuntime::VTableInfo &vtable_info,
+ llvm::SmallVectorImpl<llvm::StringRef> &vtable_components) {
+ if (!vtable_info.addr.IsSectionOffset() || !vtable_info.symbol)
+ return {};
+
+ // See if we have cached info for this type already
+ TypeAndOrName type_info = GetDynamicTypeInfo(vtable_info.addr);
+ if (type_info)
+ return type_info;
+
+ Log *log = GetLog(LLDBLog::Object);
+ llvm::StringRef symbol_name =
+ vtable_info.symbol->GetMangled().GetDemangledName().GetStringRef();
+ if (!SplitVTableComponents(symbol_name, vtable_components)) {
+ LLDB_LOG(log, "{0:x16}: '{1}' is not a valid vtable symbol",
+ in_value.GetPointerValue().address, symbol_name);
+ return {};
+ }
+
+ llvm::StringRef class_name = StripDemangledVTableSuffix(symbol_name);
+
+ type_info.SetName(class_name);
+ bool any_found = false;
+ TypeSP type_sp = LookupTypeByName(
+ class_name, vtable_info.symbol->CalculateSymbolContextModule(),
+ any_found);
+ if (!any_found)
+ return TypeAndOrName(); // Type is not dynamic.
+
+ 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));
+ }
+
+ if (type_info)
+ SetDynamicTypeInfo(vtable_info.addr, type_info);
+ return type_info;
+}
+
+std::optional<int64_t> MicrosoftABIRuntime::GetOffsetToTop(
+ ValueObject &in_value, TypeAndOrName &class_type_or_name,
+ const LanguageRuntime::VTableInfo &vtable_info) {
+ Log *log = GetLog(LLDBLog::Object);
+
+ llvm::SmallVector<llvm::StringRef, 2> vtable_components;
+ class_type_or_name = GetTypeInfo(in_value, vtable_info, vtable_components);
+ if (!class_type_or_name) {
+ LLDB_LOG(log, "{0:x16}: failed to get type info",
+ in_value.GetPointerValue().address);
+ return std::nullopt;
+ }
+
+ {
+ std::scoped_lock<std::mutex> g(m_mutex);
+ auto offset_to_top_it = m_offset_to_top_map.find(vtable_info.addr);
+ if (offset_to_top_it != m_offset_to_top_map.end())
+ return offset_to_top_it->second;
+ }
+
+ CompilerType type = class_type_or_name.GetCompilerType();
+ if (!type) {
+ LLDB_LOG(log, "{0:x16}: failed to get type info (no compiler type)",
+ in_value.GetPointerValue().address);
+ return std::nullopt;
+ }
+
+ CompilerType in_type = in_value.GetCompilerType();
+ if (in_type.IsPointerOrReferenceType())
+ in_type = in_type.GetPointeeType();
+ if (!in_type.GetCompleteType()) {
+ LLDB_LOG(log, "{0:x16}: {1} is not a complete type",
+ in_value.GetPointerValue().address, in_type.GetTypeName());
+ return std::nullopt;
+ }
+ if (!type.GetCompleteType()) {
+ LLDB_LOG(log, "{0:x16}: {1} is not a complete type",
+ in_value.GetPointerValue().address,
+ type.GetTypeName().GetCString());
+ return std::nullopt;
+ }
+
+ if (TypeSystemClang::AreTypesSame(in_type, type)) {
+ LLDB_LOG(log, "{0:x16}: in type is the same as the dynamic type",
+ in_value.GetPointerValue().address);
+
+ // The dynamic type we found was the same type, so we don't have a
+ // dynamic type here, but if a derived type encounters this vtable symbol,
+ // remember that it has offset 0.
+ std::scoped_lock<std::mutex> g(m_mutex);
+ m_offset_to_top_map[vtable_info.addr] = 0;
+ return std::nullopt;
+ }
+
+ // Unlike in the Itanium ABI, the VTable itself doesn't have a field telling
+ // us the offset to the dynamic type.
+ // When compiled with RTTI, we can use the complete object locator to get this
+ // offset. This is preferred, because it can resolve types across different
+ // modules and handle virtual bases with PDB.
+ // If this fails (e.g. no RTTI available), the offset is determined from the
+ // AST. This requires the types to be from the same type system. Because PDB
+ // doesn't include the offsets of virtual bases, we don't attempt to resolve
+ // these. They're technically present in the AST, but they often have
+ // incorrect offsets.
+ std::optional<int64_t> offset = GetOffsetToTopFromRTTI(vtable_info, type);
+ llvm::StringRef strategy = "RTTI";
+ if (!offset) {
+ offset = GetOffsetToTopFromAST(in_type, in_value, type, vtable_info,
+ vtable_components);
+ strategy = "AST";
+ }
+
+ if (offset) {
+ LLDB_LOG(GetLog(LLDBLog::Object),
+ "{0:x16}: [{1}] '{2}' has offset {3} in '{4}'",
+ in_value.GetPointerValue().address, strategy,
+ in_type.GetTypeName(), *offset, type.GetTypeName());
+
+ std::scoped_lock<std::mutex> g(m_mutex);
+ m_offset_to_top_map[vtable_info.addr] = offset;
+ }
+
+ return offset;
+}
+
+std::optional<int64_t> MicrosoftABIRuntime::GetOffsetToTopFromRTTI(
+ const LanguageRuntime::VTableInfo &vtable_info,
+ const CompilerType &dynamic_type) {
+ // The pointer to the RTTI complete object locator sits one pointer size above
+ // the vftable.
+ Target &target = m_process->GetTarget();
+ const addr_t vtable_load_addr = vtable_info.addr.GetLoadAddress(&target);
+ if (vtable_load_addr == LLDB_INVALID_ADDRESS)
+ return std::nullopt;
+ const uint32_t addr_byte_size = m_process->GetAddressByteSize();
+ const lldb::addr_t complete_object_locator_load_addr =
+ vtable_load_addr - addr_byte_size;
+ // Check for underflow.
+ if (complete_object_locator_load_addr >= vtable_load_addr)
+ return std::nullopt;
+
+ Log *log = GetLog(LLDBLog::Object);
+ // Pointer to the RTTI complete object locator.
+ llvm::Expected<lldb::addr_t> rtti_locator_base_load_addr =
+ m_process->ReadPointerFromMemory(complete_object_locator_load_addr);
+ if (!rtti_locator_base_load_addr ||
+ *rtti_locator_base_load_addr == LLDB_INVALID_ADDRESS) {
+ LLDB_LOG_ERROR(log, rtti_locator_base_load_addr.takeError(),
+ "Failed to read address of RTTI complete object locator at "
+ "{1:x16}: {0}",
+ complete_object_locator_load_addr);
+ return std::nullopt;
+ }
+
+ Status error;
+ Address rtti_locator_base_addr;
+ if (!m_process->GetTarget().ResolveLoadAddress(*rtti_locator_base_load_addr,
+ rtti_locator_base_addr)) {
+ LLDB_LOG_ERROR(log, error.takeError(),
+ "Failed to resolve load address of RTTI complete object "
+ "locator at {1:x16}: {0}",
+ *rtti_locator_base_load_addr);
+ return std::nullopt;
+ }
+
+ // Check if we're actually looking at the RTTI complete object locator.
+ Symbol *symbol = rtti_locator_base_addr.CalculateSymbolContextSymbol();
+ if (symbol == nullptr)
+ return std::nullopt;
+ if (!symbol->GetName().GetStringRef().contains(
+ s_rtti_complete_object_locator_indicator))
+ return std::nullopt;
+
+ LLDB_LOG(log, "Found RTTI complete object locator: {0:x16}",
+ *rtti_locator_base_load_addr);
+
+ auto ts = dynamic_type.GetTypeSystem();
+ if (!ts)
+ return std::nullopt;
+
+ llvm::Expected<uint64_t> int_size =
+ ts->GetBasicTypeFromAST(lldb::eBasicTypeInt).GetByteSize(nullptr);
+ if (!int_size) {
+ LLDB_LOG_ERROR(log, int_size.takeError(),
+ "Failed to get size of int from AST: {0}");
+ return std::nullopt;
+ }
+
+ // See MSRTTIBuilder::getCompleteObjectLocator in Clang for the layout.
+ // We're interested in the offset which is the second int in the struct.
+ Address offset_from_top_addr = rtti_locator_base_addr;
+ offset_from_top_addr.Slide(*int_size);
+
+ error.Clear();
+ const int64_t offset_from_top = target.ReadSignedIntegerFromMemory(
+ offset_from_top_addr, *int_size, INT64_MIN, error);
+ if (offset_from_top == INT64_MIN || error.Fail()) {
+ LLDB_LOG_ERROR(log, error.takeError(),
+ "Failed to read 'offset from top' from RTTI complete object "
+ "locator at {1:x16}: {0}",
+ offset_from_top_addr.GetOffset());
+ return std::nullopt;
+ }
+
+ return offset_from_top;
+}
+
+/// Try to find the offset of `target_base` inside `haystack` while visiting all
+/// `checkpoints`.
+static std::optional<size_t>
+GetOffsetOfBaseFromAST(clang::ASTContext &ast,
+ const clang::CXXRecordDecl *haystack,
+ const clang::CXXRecordDecl *target_base,
+ const llvm::ArrayRef<llvm::StringRef> checkpoints) {
+ struct BaseEntry {
+ const clang::CXXRecordDecl *decl;
+ /// If this is `std::nullopt`, then this entry is on a path where we can't
+ /// determine the offset.
+ std::optional<size_t> offset;
+ /// Remaining checkpoints on this path.
+ llvm::ArrayRef<llvm::StringRef> checkpoints;
+ /// Was `target_base` found on this path?
+ bool found_target = false;
+ };
+
+ // This does a breadth-first search over all bases. Starting point is the root
+ // (`haystack`).
+ std::deque<BaseEntry> bases;
+ bases.emplace_back(BaseEntry{
+ /*decl=*/haystack,
+ /*offset=*/0,
+ /*checkpoints=*/checkpoints,
+ });
+
+ // Go through virtual bases first.
+ std::string base_name;
+ for (const clang::CXXBaseSpecifier &base : haystack->vbases()) {
+ const clang::CXXRecordDecl *base_decl = llvm::cast<clang::CXXRecordDecl>(
+ base.getType()->castAs<clang::RecordType>()->getDecl());
+ // Although clang gives us some offset here, this offset is not from the
+ // debug info and thus likely wrong. Neither PDB nor DWARF include it.
+ if (!checkpoints.empty()) {
+ base_name = base_decl->getDeclName().getAsString();
+ if (base_name == checkpoints.back())
+ return std::nullopt;
+ } else if (base_decl == target_base) {
+ return std::nullopt;
+ }
+
+ // We still need to keep track of this class as `target_base` might be
+ // inside this base.
+ bases.emplace_back(BaseEntry{
+ /*decl=*/base_decl,
+ /*offset=*/std::nullopt,
+ /*checkpoints=*/checkpoints,
+ });
+ }
+
+ while (!bases.empty()) {
+ BaseEntry current = bases.front();
+ assert(
+ (!current.found_target || !current.checkpoints.empty()) &&
+ "if we found the target we should only need to check the checkpoints");
+ bases.pop_front();
+ const clang::ASTRecordLayout &record_layout =
+ ast.getASTRecordLayout(current.decl);
+
+ for (const clang::CXXBaseSpecifier &base : current.decl->bases()) {
+ if (base.isVirtual())
+ continue; // We already looked through virtual bases.
+
+ const clang::CXXRecordDecl *base_decl = llvm::cast<clang::CXXRecordDecl>(
+ base.getType()->castAs<clang::RecordType>()->getDecl());
+ bool found_target = base_decl == target_base || current.found_target;
+ std::optional<size_t> offset = current.offset;
+ if (offset)
+ *offset += record_layout.getBaseClassOffset(base_decl).getQuantity();
+
+ if (!current.checkpoints.empty()) {
+ base_name = base_decl->getDeclName().getAsString();
+ if (base_name == current.checkpoints.back()) {
+ // Last component was the base we were looking for.
+ if (found_target && current.checkpoints.size() == 1)
+ return offset;
+
+ // Found a checkpoint, so we have to take this path.
+ bases.clear();
+ bases.emplace_back(BaseEntry{
+ /*decl=*/base_decl,
+ /*offset=*/offset,
+ /*checkpoints=*/current.checkpoints.drop_back(),
+ /*found_target=*/found_target,
+ });
+ }
+ } else if (found_target) {
+ return offset;
+ }
+
+ bases.emplace_back(BaseEntry{
+ /*decl=*/base_decl,
+ /*offset=*/offset,
+ /*checkpoints=*/current.checkpoints,
+ /*found_target=*/found_target,
+ });
+ }
+ }
+
+ return std::nullopt;
+}
+
+std::optional<int64_t> MicrosoftABIRuntime::GetOffsetToTopFromAST(
+ const CompilerType &in_type, ValueObject &in_value,
+ const CompilerType &dyn_type,
+ const LanguageRuntime::VTableInfo &vtable_info,
+ llvm::ArrayRef<llvm::StringRef> vtable_components) {
+ Log *log = GetLog(LLDBLog::Object);
+
+ CompilerType in_base_type = in_type;
+
+ clang::CXXRecordDecl *in_decl =
+ TypeSystemClang::GetAsCXXRecordDecl(in_base_type.GetOpaqueQualType());
+ clang::CXXRecordDecl *target_decl =
+ TypeSystemClang::GetAsCXXRecordDecl(dyn_type.GetOpaqueQualType());
+ if (!in_decl || !target_decl) {
+ LLDB_LOG(log, "{0:x16}: types are not record types (in={1}, target={2})",
+ in_value.GetPointerValue().address, in_base_type.GetTypeName(),
+ dyn_type.GetTypeName());
+ return std::nullopt;
+ }
+
+ TypeSystemClangSP ts = dyn_type.GetTypeSystem<TypeSystemClang>();
+ if (!ts || ts != in_base_type.GetTypeSystem<TypeSystemClang>()) {
+ LLDB_LOG(GetLog(LLDBLog::Object),
+ "{0:x16}: '{1}' and '{2}' are from different type systems",
+ in_value.GetPointerValue().address,
+ in_decl->getDeclName().getAsString(),
+ target_decl->getDeclName().getAsString());
+ return std::nullopt;
+ }
+
+ std::optional<size_t> offset = GetOffsetOfBaseFromAST(
+ ts->getASTContext(), target_decl, in_decl, vtable_components);
+ if (!offset) {
+ LLDB_LOG(GetLog(LLDBLog::Object),
+ "{0:x16}: failed to find offset of '{1}' in '{2}'",
+ in_value.GetPointerValue().address,
+ in_decl->getDeclName().getAsString(),
+ target_decl->getDeclName().getAsString());
+ return std::nullopt;
+ }
+
+ return offset;
+}
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h
new file mode 100644
index 00000000000000..032975bf666db4
--- /dev/null
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h
@@ -0,0 +1,61 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_MICROSOFTABIRUNTIME_H
+#define LLDB_SOURCE_PLUGINS_LANGUAGERUNTIME_CPLUSPLUS_MICROSOFTABIRUNTIME_H
+
+#include "CommonABIRuntime.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/ValueObject/ValueObject.h"
+
+namespace lldb_private {
+
+class MicrosoftABIRuntime : public CommonABIRuntime {
+public:
+ MicrosoftABIRuntime(Process *process);
+
+ llvm::StringRef GetName() const override { return "Microsoft ABI runtime"; }
+
+ bool GetDynamicTypeAndAddress(ValueObject &in_value,
+ lldb::DynamicValueType use_dynamic,
+ const LanguageRuntime::VTableInfo &vtable_info,
+ TypeAndOrName &class_type_or_name,
+ Address &dynamic_address) override;
+
+ bool IsVTableSymbol(Mangled &mangled) const override;
+
+private:
+ TypeAndOrName
+ GetTypeInfo(ValueObject &in_value,
+ const LanguageRuntime::VTableInfo &vtable_info,
+ llvm::SmallVectorImpl<llvm::StringRef> &vtable_components);
+
+ llvm::Error TypeHasVTable(CompilerType type);
+
+ std::optional<int64_t>
+ GetOffsetToTop(ValueObject &in_value, TypeAndOrName &class_type_or_name,
+ const LanguageRuntime::VTableInfo &vtable_info);
+
+ std::optional<int64_t>
+ GetOffsetToTopFromRTTI(const LanguageRuntime::VTableInfo &vtable_info,
+ const CompilerType &dynamic_type);
+
+ std::optional<int64_t>
+ GetOffsetToTopFromAST(const CompilerType &in_type, ValueObject &in_value,
+ const CompilerType &dyn_type,
+ const LanguageRuntime::VTableInfo &vtable_info,
+ llvm::ArrayRef<llvm::StringRef> vtable_components);
+
+ using OffsetToTopCache = std::map<Address, std::optional<int64_t>>;
+
+ OffsetToTopCache m_offset_to_top_map;
+};
+
+} // namespace lldb_private
+
+#endif
diff --git a/lldb/test/API/functionalities/data-formatter/dump_dynamic/TestDumpDynamic.py b/lldb/test/API/functionalities/data-formatter/dump_dynamic/TestDumpDynamic.py
index 40fdfb90c085eb..4359d757072d5e 100644
--- a/lldb/test/API/functionalities/data-formatter/dump_dynamic/TestDumpDynamic.py
+++ b/lldb/test/API/functionalities/data-formatter/dump_dynamic/TestDumpDynamic.py
@@ -3,5 +3,11 @@
lldbinline.MakeInlineTest(
__file__,
globals(),
- [lldbinline.expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24663")],
+ makefile_extras="""
+ifeq "$(OS)" "Windows_NT"
+ ifneq "$(MAKE_PDB)" "YES"
+ LD_EXTRAS += -Wl,-debug:symtab
+ endif
+endif
+""",
)
diff --git a/lldb/test/API/functionalities/dynamic_value_child_count/Makefile b/lldb/test/API/functionalities/dynamic_value_child_count/Makefile
index 2bba8e757f79b7..a4c899ba59f657 100644
--- a/lldb/test/API/functionalities/dynamic_value_child_count/Makefile
+++ b/lldb/test/API/functionalities/dynamic_value_child_count/Makefile
@@ -1,3 +1,9 @@
CXX_SOURCES := pass-to-base.cpp
+ifeq "$(OS)" "Windows_NT"
+ ifneq "$(MAKE_PDB)" "YES"
+ LD_EXTRAS += -Wl,-debug:symtab
+ endif
+endif
+
include Makefile.rules
diff --git a/lldb/test/API/functionalities/dynamic_value_child_count/TestDynamicValueChildCount.py b/lldb/test/API/functionalities/dynamic_value_child_count/TestDynamicValueChildCount.py
index bbe9ba209ad2bc..084e5028c6adb3 100644
--- a/lldb/test/API/functionalities/dynamic_value_child_count/TestDynamicValueChildCount.py
+++ b/lldb/test/API/functionalities/dynamic_value_child_count/TestDynamicValueChildCount.py
@@ -30,7 +30,6 @@ def setUp(self):
)
@add_test_categories(["pyapi"])
- @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24663")
def test_get_dynamic_vals(self):
"""Test fetching C++ dynamic values from pointers & references."""
"""Get argument vals for the call stack when stopped on a breakpoint."""
@@ -65,12 +64,13 @@ def test_get_dynamic_vals(self):
process = target.LaunchSimple(None, None, self.get_process_working_directory())
self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
-
+ self.runCmd("log enable lldb object")
b = self.frame().FindVariable("b").GetDynamicValue(lldb.eDynamicCanRunTarget)
self.assertEqual(b.GetNumChildren(), 0, "b has 0 children")
self.runCmd("continue")
self.assertEqual(b.GetNumChildren(), 0, "b still has 0 children")
self.runCmd("continue")
+ print(b)
self.assertNotEqual(b.GetNumChildren(), 0, "b now has 1 child")
self.runCmd("continue")
self.assertEqual(b.GetNumChildren(), 0, "b didn't go back to 0 children")
diff --git a/lldb/test/API/functionalities/value_md5_crash/Makefile b/lldb/test/API/functionalities/value_md5_crash/Makefile
index 99998b20bcb050..47b1a6e9342642 100644
--- a/lldb/test/API/functionalities/value_md5_crash/Makefile
+++ b/lldb/test/API/functionalities/value_md5_crash/Makefile
@@ -1,3 +1,9 @@
CXX_SOURCES := main.cpp
+ifeq "$(OS)" "Windows_NT"
+ ifneq "$(MAKE_PDB)" "YES"
+ LD_EXTRAS += -Wl,-debug:symtab
+ endif
+endif
+
include Makefile.rules
diff --git a/lldb/test/API/functionalities/value_md5_crash/TestValueMD5Crash.py b/lldb/test/API/functionalities/value_md5_crash/TestValueMD5Crash.py
index 24749b6e2fc75d..e9c38efbfe5386 100644
--- a/lldb/test/API/functionalities/value_md5_crash/TestValueMD5Crash.py
+++ b/lldb/test/API/functionalities/value_md5_crash/TestValueMD5Crash.py
@@ -16,7 +16,6 @@ def setUp(self):
# Find the line number to break at.
self.line = line_number("main.cpp", "// break here")
- @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24663")
def test_with_run_command(self):
"""Verify that the hash computing logic for ValueObject's values can't crash us."""
self.build()
diff --git a/lldb/test/API/lang/cpp/dynamic-value-complex/Makefile b/lldb/test/API/lang/cpp/dynamic-value-complex/Makefile
new file mode 100644
index 00000000000000..47b1a6e9342642
--- /dev/null
+++ b/lldb/test/API/lang/cpp/dynamic-value-complex/Makefile
@@ -0,0 +1,9 @@
+CXX_SOURCES := main.cpp
+
+ifeq "$(OS)" "Windows_NT"
+ ifneq "$(MAKE_PDB)" "YES"
+ LD_EXTRAS += -Wl,-debug:symtab
+ endif
+endif
+
+include Makefile.rules
diff --git a/lldb/test/API/lang/cpp/dynamic-value-complex/TestDynamicValueComplex.py b/lldb/test/API/lang/cpp/dynamic-value-complex/TestDynamicValueComplex.py
new file mode 100644
index 00000000000000..079c33f1f7057e
--- /dev/null
+++ b/lldb/test/API/lang/cpp/dynamic-value-complex/TestDynamicValueComplex.py
@@ -0,0 +1,282 @@
+"""
+Test that we can resolve dynamic values in complex inheritance hierarchies.
+This is mainly relevant for the Microsoft ABI where there can be multiple vtables in one type.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class DynamicValueComplexTestCase(TestBase):
+ SHARED_BUILD_TESTCASE = False
+
+ def test_rtti(self):
+ """Test with RTTI"""
+ self.build(dictionary={"CXXFLAGS_EXTRAS": ""})
+ self.do_test(True)
+
+ def test_no_rtti(self):
+ """Test without RTTI"""
+ self.build(dictionary={"CXXFLAGS_EXTRAS": "-fno-rtti"})
+ self.do_test(False)
+
+ def do_test(self, has_rtti: bool):
+ target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
+ self, "// break here", lldb.SBFileSpec("main.cpp")
+ )
+
+ frame = thread.GetFrameAtIndex(0)
+ get = lambda name: self._check_get(frame, name)
+
+ is_windows_msvc = self.getPlatform() == "windows" and "-msvc" in (
+ frame.GetModule().GetTriple() or ""
+ )
+
+ # Test 'Single'.
+ # struct Single : Base1
+ single = get("single")
+ single_base1 = get("single_base1")
+ single_addr = single.GetValueAsAddress()
+ self.assertNotEqual(single_addr, lldb.LLDB_INVALID_ADDRESS)
+ self.assertEqual(single_addr, single_base1.GetValueAsAddress())
+ self.assertEqual(single.GetTypeName(), single_base1.GetTypeName())
+
+ single_children = [
+ ValueCheck(
+ type="Base1",
+ children=[ValueCheck(type="int", name="base1", value="1")],
+ ),
+ ValueCheck(type="int", name="single", value="3"),
+ ]
+ self.expect_expr(
+ "single", result_type="Single *", result_children=single_children
+ )
+
+ # Test 'Multiple'.
+ # struct Multiple : virtual VBase, Base1, Base2
+ multi = get("multi")
+ multi_base1 = get("multi_base1")
+ multi_base2 = get("multi_base2")
+ multi_addr = multi.GetValueAsAddress()
+ self.assertNotEqual(multi_addr, lldb.LLDB_INVALID_ADDRESS)
+ self.assertEqual(multi_addr, multi_base1.GetValueAsAddress())
+ self.assertEqual(multi_addr, multi_base2.GetValueAsAddress())
+ self.assertEqual(multi.GetTypeName(), multi_base1.GetTypeName())
+ self.assertEqual(multi.GetTypeName(), multi_base2.GetTypeName())
+
+ multi_children = [
+ ValueCheck(
+ type="VBase",
+ children=[ValueCheck(type="int", name="vbase", value="5")],
+ ),
+ ValueCheck(
+ type="Base1",
+ children=[ValueCheck(type="int", name="base1", value="1")],
+ ),
+ ValueCheck(
+ type="Base2",
+ children=[ValueCheck(type="int", name="base2", value="2")],
+ ),
+ ValueCheck(type="int", name="multiple", value="4"),
+ ]
+
+ # The index of 'VBase' in 'Multiple' depends on the ABI.
+ # On Itanium, it sits at the start whereas on Microsoft it's after
+ # the non-virtual ones.
+ multiple_type = self.target().FindFirstType("Multiple")
+ self.assertTrue(multiple_type.IsValid())
+ first_base = multiple_type.GetDirectBaseClassAtIndex(0).GetName()
+ vbases_at_start = first_base == "VBase"
+ if not vbases_at_start:
+ # Move 'VBase' after 'Base2'.
+ self.assertEqual(first_base, "Base1")
+ multi_children.insert(2, multi_children.pop(0))
+
+ self.expect_expr(
+ "multi", result_type="Multiple *", result_children=multi_children
+ )
+
+ # Test 'VBaseDiamondUser'.
+ # struct VBaseDiamondUser : VBaseUser1, VBaseUser2
+ vbuser = get("vbuser")
+ vbuser_vbase = get("vbuser_vbase")
+ vbuser_addr = vbuser.GetValueAsAddress()
+ if is_windows_msvc and not has_rtti:
+ # On Windows, we have to use the AST to get the offset.
+ # But we don't know where the virtual base will be located in the object.
+ self.assertNotEqual(vbuser_addr, lldb.LLDB_INVALID_ADDRESS)
+ self.assertNotEqual(
+ vbuser_vbase.GetValueAsAddress(), lldb.LLDB_INVALID_ADDRESS
+ )
+ self.assertNotEqual(vbuser_addr, vbuser_vbase.GetValueAsAddress())
+ self.assertNotEqual(vbuser.GetTypeName(), vbuser_vbase.GetTypeName())
+ else:
+ self.assertNotEqual(vbuser_addr, lldb.LLDB_INVALID_ADDRESS)
+ self.assertEqual(vbuser_addr, vbuser_vbase.GetValueAsAddress())
+ self.assertEqual(vbuser.GetTypeName(), vbuser_vbase.GetTypeName())
+
+ vbuser_children = [
+ ValueCheck(
+ type="VBaseUser1",
+ children=[
+ ValueCheck(
+ type="VBase",
+ children=[ValueCheck(type="int", name="vbase", value="5")],
+ ),
+ ValueCheck(type="int", name="vbase_user1", value="6"),
+ ],
+ ),
+ ValueCheck(
+ type="VBaseUser2",
+ children=[
+ ValueCheck(
+ type="VBase",
+ children=[ValueCheck(type="int", name="vbase", value="5")],
+ ),
+ ValueCheck(type="int", name="vbase_user2", value="7"),
+ ],
+ ),
+ ValueCheck(type="int", name="vbase_duo_user", value="8"),
+ ]
+ self.expect_expr(
+ "vbuser", result_type="VBaseDiamondUser *", result_children=vbuser_children
+ )
+
+ # Test 'Combined'.
+ # struct Combined : MultiWrap1, VBaseDiamondUser, MultiWrap2, Single
+ combined = get("combined")
+ combined_addr = combined.GetValueAsAddress()
+ combined_name = combined.GetTypeName() or ""
+ self.assertNotEqual(combined_addr, lldb.LLDB_INVALID_ADDRESS)
+ self.assertGreater(len(combined_name), 0)
+
+ combined_mw1 = get("combined_mw1")
+ self.assertEqual(combined_addr, combined_mw1.GetValueAsAddress())
+ self.assertEqual(combined_name, combined_mw1.GetTypeName())
+ combined_mw1_multi = get("combined_mw1_multi")
+ self.assertEqual(combined_addr, combined_mw1_multi.GetValueAsAddress())
+ self.assertEqual(combined_name, combined_mw1_multi.GetTypeName())
+ combined_mw1_multi_b1 = get("combined_mw1_multi_b1")
+ self.assertEqual(combined_addr, combined_mw1_multi_b1.GetValueAsAddress())
+ self.assertEqual(combined_name, combined_mw1_multi_b1.GetTypeName())
+ combined_mw1_multi_b2 = get("combined_mw1_multi_b2")
+ self.assertEqual(combined_addr, combined_mw1_multi_b2.GetValueAsAddress())
+ self.assertEqual(combined_name, combined_mw1_multi_b2.GetTypeName())
+
+ combined_vbuser = get("combined_vbuser")
+ self.assertEqual(combined_addr, combined_vbuser.GetValueAsAddress())
+ self.assertEqual(combined_name, combined_vbuser.GetTypeName())
+
+ combined_vbuser_vbase = get("combined_vbuser_vbase")
+ if is_windows_msvc and not has_rtti:
+ vbuser_vbase_addr = combined_vbuser_vbase.GetValueAsAddress()
+ self.assertNotEqual(vbuser_vbase_addr, lldb.LLDB_INVALID_ADDRESS)
+ self.assertNotEqual(combined_addr, vbuser_vbase_addr)
+ self.assertNotEqual(combined_name, combined_vbuser_vbase.GetTypeName())
+ else:
+ self.assertEqual(combined_addr, combined_vbuser_vbase.GetValueAsAddress())
+ self.assertEqual(combined_name, combined_vbuser_vbase.GetTypeName())
+
+ combined_mw2 = get("combined_mw2")
+ self.assertEqual(combined_addr, combined_mw2.GetValueAsAddress())
+ self.assertEqual(combined_name, combined_mw2.GetTypeName())
+ combined_mw2_multi = get("combined_mw2_multi")
+ self.assertEqual(combined_addr, combined_mw2_multi.GetValueAsAddress())
+ self.assertEqual(combined_name, combined_mw2_multi.GetTypeName())
+ combined_mw2_multi_b1 = get("combined_mw2_multi_b1")
+ self.assertEqual(combined_addr, combined_mw2_multi_b1.GetValueAsAddress())
+ self.assertEqual(combined_name, combined_mw2_multi_b1.GetTypeName())
+ combined_mw2_multi_b2 = get("combined_mw2_multi_b2")
+ self.assertEqual(combined_addr, combined_mw2_multi_b2.GetValueAsAddress())
+ self.assertEqual(combined_name, combined_mw2_multi_b2.GetTypeName())
+
+ combined_single = get("combined_single")
+ self.assertEqual(combined_addr, combined_single.GetValueAsAddress())
+ self.assertEqual(combined_name, combined_single.GetTypeName())
+ combined_single_base1 = get("combined_single_base1")
+ self.assertEqual(combined_addr, combined_single_base1.GetValueAsAddress())
+ self.assertEqual(combined_name, combined_single_base1.GetTypeName())
+
+ combined_children = [
+ ValueCheck(
+ type="MultiWrap1",
+ children=[
+ ValueCheck(type="Multiple", children=multi_children),
+ ValueCheck(type="int", name="multi_wrap1", value="9"),
+ ],
+ ),
+ ValueCheck(type="VBaseDiamondUser", children=vbuser_children),
+ ValueCheck(
+ type="MultiWrap2",
+ children=[
+ ValueCheck(type="Multiple", children=multi_children),
+ ValueCheck(type="int", name="multi_wrap2", value="10"),
+ ],
+ ),
+ ValueCheck(type="Single", children=single_children),
+ ValueCheck(type="int", name="combined", value="11"),
+ ]
+ self.expect_expr(
+ "combined", result_type="Combined *", result_children=combined_children
+ )
+
+ # Test 'TwoBase1s'
+ # struct TwoBase1s : virtual VBaseWithBase, Single
+
+ tb1 = get("tb1")
+ tb1_addr = tb1.GetValueAsAddress()
+ tb1_name = tb1.GetTypeName() or ""
+ self.assertNotEqual(tb1_addr, lldb.LLDB_INVALID_ADDRESS)
+ self.assertGreater(len(tb1_name), 0)
+
+ tb1_vb = get("tb1_vb")
+ tb1_vb_b1 = get("tb1_vb_b1")
+ if is_windows_msvc and not has_rtti:
+ # Anything that goes through the virtual base is unknown to us, so
+ # it should not have a dynamic type.
+ tb1_vb_addr = tb1_vb.GetValueAsAddress()
+ tb1_vb_b1_addr = tb1_vb.GetValueAsAddress()
+ self.assertNotEqual(tb1_vb_addr, lldb.LLDB_INVALID_ADDRESS)
+ self.assertNotEqual(tb1_vb_b1_addr, lldb.LLDB_INVALID_ADDRESS)
+ self.assertNotEqual(tb1_addr, tb1_vb_addr)
+ self.assertNotEqual(tb1_addr, tb1_vb_b1_addr)
+ self.assertNotEqual(tb1_name, tb1_vb.GetTypeName())
+ self.assertNotEqual(tb1_name, tb1_vb_b1.GetTypeName())
+ else:
+ #
+ self.assertEqual(tb1_addr, tb1_vb.GetValueAsAddress())
+ self.assertEqual(tb1_name, tb1_vb.GetTypeName())
+ self.assertEqual(tb1_addr, tb1_vb_b1.GetValueAsAddress())
+ self.assertEqual(tb1_name, tb1_vb_b1.GetTypeName())
+
+ tb1_single = get("tb1_single")
+ self.assertEqual(tb1_addr, tb1_single.GetValueAsAddress())
+ self.assertEqual(tb1_name, tb1_single.GetTypeName())
+ tb1_single_b1 = get("tb1_single_b1")
+ self.assertEqual(tb1_addr, tb1_single_b1.GetValueAsAddress())
+ self.assertEqual(tb1_name, tb1_single_b1.GetTypeName())
+
+ tb1_children = [
+ ValueCheck(
+ type="VBaseWithBase",
+ children=[
+ ValueCheck(
+ type="Base1",
+ children=[ValueCheck(type="int", name="base1", value="1")],
+ ),
+ ValueCheck(type="int", name="vbase_with_base", value="12"),
+ ],
+ ),
+ ValueCheck(type="Single", children=single_children),
+ ValueCheck(type="int", name="two_base1s", value="13"),
+ ]
+ if not vbases_at_start:
+ tb1_children.insert(1, tb1_children.pop(0))
+ self.expect_expr("tb1", result_type="TwoBase1s *", result_children=tb1_children)
+
+ def _check_get(self, frame: lldb.SBFrame, name: str) -> lldb.SBValue:
+ var = frame.FindVariable(name, lldb.eDynamicCanRunTarget)
+ self.assertTrue(var, f"could not find '{name}'")
+ return var
diff --git a/lldb/test/API/lang/cpp/dynamic-value-complex/main.cpp b/lldb/test/API/lang/cpp/dynamic-value-complex/main.cpp
new file mode 100644
index 00000000000000..a55d74b1ff30b9
--- /dev/null
+++ b/lldb/test/API/lang/cpp/dynamic-value-complex/main.cpp
@@ -0,0 +1,110 @@
+struct Base1 {
+ virtual ~Base1() = default;
+ int base1 = 1;
+};
+struct Base2 {
+ virtual ~Base2() = default;
+ int base2 = 2;
+};
+struct VBase {
+ virtual ~VBase() = default;
+ int vbase = 5;
+};
+
+struct Single : public Base1 {
+ int single = 3;
+};
+struct Multiple : public virtual VBase, public Base1, public Base2 {
+ int multiple = 4;
+};
+
+struct VBaseUser1 : public virtual VBase {
+ int vbase_user1 = 6;
+};
+struct VBaseUser2 : public virtual VBase {
+ int vbase_user2 = 7;
+};
+
+struct VBaseDiamondUser : public VBaseUser1, public VBaseUser2 {
+ int vbase_duo_user = 8;
+ virtual void foo() {}
+};
+
+struct MultiWrap1 : public Multiple {
+ int multi_wrap1 = 9;
+};
+struct MultiWrap2 : public Multiple {
+ int multi_wrap2 = 10;
+};
+
+// With the Microsoft ABI, many of the vftable symbols here will have additional
+// components to disambiguate:
+// const Combined::`vftable'
+// const Combined::`vftable'{for `VBase'}
+// const Combined::`vftable'{for `Base1's `MultiWrap1'}
+// const Combined::`vftable'{for `Base2's `MultiWrap1'}
+// const Combined::`vftable'{for `VBaseDiamondUser'}
+// const Combined::`vftable'{for `Base1's `MultiWrap2'}
+// const Combined::`vftable'{for `Base2's `MultiWrap2'}
+struct Combined : public MultiWrap1,
+ public VBaseDiamondUser,
+ public MultiWrap2,
+ public Single {
+ int combined = 11;
+
+ virtual void something() {}
+};
+
+struct VBaseWithBase : public Base1 {
+ int vbase_with_base = 12;
+};
+// This has two paths to `Base1`. Through the virtual base and through `Single`.
+struct TwoBase1s : public virtual VBaseWithBase, public Single {
+ int two_base1s = 13;
+};
+
+int main() {
+ Single *single = new Single;
+ Base1 *single_base1 = single;
+
+ // --------------------------
+
+ Multiple *multi = new Multiple;
+ Base1 *multi_base1 = multi;
+ Base2 *multi_base2 = multi;
+
+ // --------------------------
+
+ VBaseDiamondUser *vbuser = new VBaseDiamondUser;
+ VBase *vbuser_vbase = vbuser;
+
+ // --------------------------
+
+ Combined *combined = new Combined;
+
+ MultiWrap1 *combined_mw1 = combined;
+ Multiple *combined_mw1_multi = combined_mw1;
+ Base1 *combined_mw1_multi_b1 = combined_mw1_multi;
+ Base2 *combined_mw1_multi_b2 = combined_mw1_multi;
+
+ VBaseDiamondUser *combined_vbuser = combined;
+ VBase *combined_vbuser_vbase = combined_vbuser;
+
+ MultiWrap2 *combined_mw2 = combined;
+ Multiple *combined_mw2_multi = combined_mw2;
+ Base1 *combined_mw2_multi_b1 = combined_mw2_multi;
+ Base2 *combined_mw2_multi_b2 = combined_mw2_multi;
+
+ Single *combined_single = combined;
+ Base1 *combined_single_base1 = combined_single;
+
+ // --------------------------
+
+ TwoBase1s *tb1 = new TwoBase1s;
+ VBaseWithBase *tb1_vb = tb1;
+ Base1 *tb1_vb_b1 = tb1_vb;
+ Single *tb1_single = tb1;
+ Base1 *tb1_single_b1 = tb1_single;
+
+ return 1; // break here
+}
diff --git a/lldb/test/API/lang/cpp/dynamic-value/Makefile b/lldb/test/API/lang/cpp/dynamic-value/Makefile
index 24346ccfae510e..ba553b6c8e1594 100644
--- a/lldb/test/API/lang/cpp/dynamic-value/Makefile
+++ b/lldb/test/API/lang/cpp/dynamic-value/Makefile
@@ -1,3 +1,9 @@
CXX_SOURCES := pass-to-base.cpp anonymous-b.cpp forward-a.cpp
+ifeq "$(OS)" "Windows_NT"
+ ifneq "$(MAKE_PDB)" "YES"
+ LD_EXTRAS += -Wl,-debug:symtab
+ endif
+endif
+
include Makefile.rules
diff --git a/lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py b/lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py
index 2c667c866d914e..a00ffd3af3519f 100644
--- a/lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py
+++ b/lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py
@@ -26,9 +26,11 @@ def setUp(self):
self.main_second_call_line = line_number(
"pass-to-base.cpp", "// Break here and get real address of reallyA."
)
+ self.forward_a_line = line_number(
+ "forward-a.cpp", "// Break here for forward declared A"
+ )
@add_test_categories(["pyapi"])
- @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24663")
def test_get_dynamic_vals(self):
"""Test fetching C++ dynamic values from pointers & references."""
self.build()
@@ -192,10 +194,14 @@ def test_get_dynamic_vals(self):
frame = thread.GetFrameAtIndex(0)
anotherA_value = frame.FindVariable("anotherA", use_dynamic)
self.assertTrue(anotherA_value)
- self.assertIn("B", anotherA_value.GetTypeName())
- anon_b_value = anotherA_value.GetChildMemberWithName("m_anon_b_value")
- self.assertTrue(anon_b_value)
- self.assertEqual(anon_b_value.GetValueAsSigned(), 47)
+ if self.getDebugInfo() == "pdb":
+ # With PDB, we don't have the vtable symbols for classes in anonymous namespaces.
+ self.assertNotIn("B", anotherA_value.GetTypeName())
+ else:
+ self.assertIn("B", anotherA_value.GetTypeName())
+ anon_b_value = anotherA_value.GetChildMemberWithName("m_anon_b_value")
+ self.assertTrue(anon_b_value)
+ self.assertEqual(anon_b_value.GetValueAsSigned(), 47)
def examine_value_object_of_this_ptr(
self, this_static, this_dynamic, dynamic_location
@@ -251,6 +257,10 @@ def examine_value_object_of_this_ptr(
contained_b = contained_auto_ptr.GetChildMemberWithName(
"__ptr_", use_dynamic
)
+ if not contained_b:
+ contained_b = contained_auto_ptr.GetChildMemberWithName(
+ "_Myptr", use_dynamic
+ )
self.assertTrue(contained_b)
contained_b_static = contained_auto_ptr.GetChildMemberWithName(
@@ -260,6 +270,10 @@ def examine_value_object_of_this_ptr(
contained_b_static = contained_auto_ptr.GetChildMemberWithName(
"__ptr_", no_dynamic
)
+ if not contained_b_static:
+ contained_b_static = contained_auto_ptr.GetChildMemberWithName(
+ "_Myptr", no_dynamic
+ )
self.assertTrue(contained_b_static)
contained_b_addr = int(contained_b.GetValue(), 16)
@@ -267,22 +281,20 @@ def examine_value_object_of_this_ptr(
self.assertLess(contained_b_addr, contained_b_static_addr)
- @no_debug_info_test
- @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24663")
def test_from_forward_decl(self):
"""Test fetching C++ dynamic values forward-declared types. It's
imperative that this is a separate test so that we don't end up parsing
a definition of A from somewhere else."""
self.build()
- lldbutil.run_to_name_breakpoint(self, "take_A")
+ lldbutil.run_to_line_breakpoint(
+ self, lldb.SBFileSpec("forward-a.cpp"), self.forward_a_line
+ )
self.expect(
"frame var -d run-target --ptr-depth=1 --show-types a",
substrs=["(B *) a", "m_b_value = 10"],
)
- @no_debug_info_test
- @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24663")
- @expectedFailureAll(archs=["arm$"]) # Minidump saving not implemented
+ @expectedFailureWindows # Can't read the RTTI locator and A is a virtual base of B, so AST strategy fails.
@skipIf(archs=["arm64e"]) # arm64e incompatible with minidump
@skipIfWasm # No core file format for Wasm
def test_from_core_file(self):
@@ -290,7 +302,9 @@ def test_from_core_file(self):
that we can determine the dynamic type of the value if the core file
does not contain the type vtable."""
self.build()
- lldbutil.run_to_name_breakpoint(self, "take_A")
+ lldbutil.run_to_line_breakpoint(
+ self, lldb.SBFileSpec("forward-a.cpp"), self.forward_a_line
+ )
# Get the address of our object and its vtable
a = self.frame().FindVariable("a")
diff --git a/lldb/test/API/lang/cpp/dynamic-value/forward-a.cpp b/lldb/test/API/lang/cpp/dynamic-value/forward-a.cpp
index 8a212d928d5c5e..b8a0f3787ad262 100644
--- a/lldb/test/API/lang/cpp/dynamic-value/forward-a.cpp
+++ b/lldb/test/API/lang/cpp/dynamic-value/forward-a.cpp
@@ -1,3 +1,5 @@
class A;
-A *take_A(A *a) { return a; }
+A *take_A(A *a) {
+ return a; // Break here for forward declared A
+}
diff --git a/lldb/test/API/python_api/type/Makefile b/lldb/test/API/python_api/type/Makefile
index 99998b20bcb050..47b1a6e9342642 100644
--- a/lldb/test/API/python_api/type/Makefile
+++ b/lldb/test/API/python_api/type/Makefile
@@ -1,3 +1,9 @@
CXX_SOURCES := main.cpp
+ifeq "$(OS)" "Windows_NT"
+ ifneq "$(MAKE_PDB)" "YES"
+ LD_EXTRAS += -Wl,-debug:symtab
+ endif
+endif
+
include Makefile.rules
diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py
index dc48fe99c5ce14..7183062a9d4c51 100644
--- a/lldb/test/API/python_api/type/TestTypeList.py
+++ b/lldb/test/API/python_api/type/TestTypeList.py
@@ -293,7 +293,6 @@ def test_nested_typedef(self):
self.assertTrue(the_typedef)
self.assertEqual(the_typedef.GetTypedefedType().GetName(), "int")
- @expectedFailureWindows # Dynamic type resolution not implemented
def test_dynamic_values(self):
"""Test FindDirectNestedType on dynamic values"""
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 48bd91c2598601..02c2b597e572ed 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -492,6 +492,7 @@ Makes programs 10x faster by doing Special New Thing.
#### Windows
+* When using the MSVC ABI, dynamic values are now resolved.
* Python 3.11 or later is now required for building LLDB 24 on Windows.
* For better performance, LLDB now turns off the Windows debug heap by default when debugging.
If you need the debug heap enabled, set `platform.plugin.windows.disable-debug-heap` to `false`.
>From 7127aea32df80653d75d70151aba25cfb6c6acb8 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sat, 31 Oct 2026 22:25:49 +0100
Subject: [PATCH 02/14] fix: outline `WINDOWS_DWARF_SYMTAB` to enable symbols
---
lldb/packages/Python/lldbsuite/test/make/Makefile.rules | 6 ++++++
.../data-formatter/dump_dynamic/TestDumpDynamic.py | 8 +-------
.../functionalities/dynamic_value_child_count/Makefile | 6 +-----
lldb/test/API/functionalities/value_md5_crash/Makefile | 6 +-----
lldb/test/API/lang/cpp/dynamic-value-complex/Makefile | 6 +-----
lldb/test/API/lang/cpp/dynamic-value/Makefile | 6 +-----
lldb/test/API/python_api/type/Makefile | 6 +-----
7 files changed, 12 insertions(+), 32 deletions(-)
diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index 30af2d9cb1930a..aaf1da3ece8d6c 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -400,6 +400,12 @@ ifeq "$(OS)" "Windows_NT"
# generated by the clang compiler.
LDFLAGS += -fuse-ld=lld
endif
+
+ ifeq (1, $(WINDOWS_DWARF_SYMTAB))
+ ifneq "$(MAKE_PDB)" "YES"
+ LDFLAGS += -Wl,-debug:symtab
+ endif
+ endif
endif
#----------------------------------------------------------------------
diff --git a/lldb/test/API/functionalities/data-formatter/dump_dynamic/TestDumpDynamic.py b/lldb/test/API/functionalities/data-formatter/dump_dynamic/TestDumpDynamic.py
index 4359d757072d5e..382bbedc3c230c 100644
--- a/lldb/test/API/functionalities/data-formatter/dump_dynamic/TestDumpDynamic.py
+++ b/lldb/test/API/functionalities/data-formatter/dump_dynamic/TestDumpDynamic.py
@@ -3,11 +3,5 @@
lldbinline.MakeInlineTest(
__file__,
globals(),
- makefile_extras="""
-ifeq "$(OS)" "Windows_NT"
- ifneq "$(MAKE_PDB)" "YES"
- LD_EXTRAS += -Wl,-debug:symtab
- endif
-endif
-""",
+ build_dict={"WINDOWS_DWARF_SYMTAB": "1"},
)
diff --git a/lldb/test/API/functionalities/dynamic_value_child_count/Makefile b/lldb/test/API/functionalities/dynamic_value_child_count/Makefile
index a4c899ba59f657..e12c08c6ec83b8 100644
--- a/lldb/test/API/functionalities/dynamic_value_child_count/Makefile
+++ b/lldb/test/API/functionalities/dynamic_value_child_count/Makefile
@@ -1,9 +1,5 @@
CXX_SOURCES := pass-to-base.cpp
-ifeq "$(OS)" "Windows_NT"
- ifneq "$(MAKE_PDB)" "YES"
- LD_EXTRAS += -Wl,-debug:symtab
- endif
-endif
+WINDOWS_DWARF_SYMTAB := 1
include Makefile.rules
diff --git a/lldb/test/API/functionalities/value_md5_crash/Makefile b/lldb/test/API/functionalities/value_md5_crash/Makefile
index 47b1a6e9342642..41ea33a976e046 100644
--- a/lldb/test/API/functionalities/value_md5_crash/Makefile
+++ b/lldb/test/API/functionalities/value_md5_crash/Makefile
@@ -1,9 +1,5 @@
CXX_SOURCES := main.cpp
-ifeq "$(OS)" "Windows_NT"
- ifneq "$(MAKE_PDB)" "YES"
- LD_EXTRAS += -Wl,-debug:symtab
- endif
-endif
+WINDOWS_DWARF_SYMTAB := 1
include Makefile.rules
diff --git a/lldb/test/API/lang/cpp/dynamic-value-complex/Makefile b/lldb/test/API/lang/cpp/dynamic-value-complex/Makefile
index 47b1a6e9342642..41ea33a976e046 100644
--- a/lldb/test/API/lang/cpp/dynamic-value-complex/Makefile
+++ b/lldb/test/API/lang/cpp/dynamic-value-complex/Makefile
@@ -1,9 +1,5 @@
CXX_SOURCES := main.cpp
-ifeq "$(OS)" "Windows_NT"
- ifneq "$(MAKE_PDB)" "YES"
- LD_EXTRAS += -Wl,-debug:symtab
- endif
-endif
+WINDOWS_DWARF_SYMTAB := 1
include Makefile.rules
diff --git a/lldb/test/API/lang/cpp/dynamic-value/Makefile b/lldb/test/API/lang/cpp/dynamic-value/Makefile
index ba553b6c8e1594..d48ff341cf9a6c 100644
--- a/lldb/test/API/lang/cpp/dynamic-value/Makefile
+++ b/lldb/test/API/lang/cpp/dynamic-value/Makefile
@@ -1,9 +1,5 @@
CXX_SOURCES := pass-to-base.cpp anonymous-b.cpp forward-a.cpp
-ifeq "$(OS)" "Windows_NT"
- ifneq "$(MAKE_PDB)" "YES"
- LD_EXTRAS += -Wl,-debug:symtab
- endif
-endif
+WINDOWS_DWARF_SYMTAB := 1
include Makefile.rules
diff --git a/lldb/test/API/python_api/type/Makefile b/lldb/test/API/python_api/type/Makefile
index 47b1a6e9342642..41ea33a976e046 100644
--- a/lldb/test/API/python_api/type/Makefile
+++ b/lldb/test/API/python_api/type/Makefile
@@ -1,9 +1,5 @@
CXX_SOURCES := main.cpp
-ifeq "$(OS)" "Windows_NT"
- ifneq "$(MAKE_PDB)" "YES"
- LD_EXTRAS += -Wl,-debug:symtab
- endif
-endif
+WINDOWS_DWARF_SYMTAB := 1
include Makefile.rules
>From 4dc4b32ad90e8532099119e0e9e4670e056bdaad Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sat, 31 Oct 2026 22:26:10 +0100
Subject: [PATCH 03/14] chore: remove debugging lines from test
---
.../dynamic_value_child_count/TestDynamicValueChildCount.py | 2 --
1 file changed, 2 deletions(-)
diff --git a/lldb/test/API/functionalities/dynamic_value_child_count/TestDynamicValueChildCount.py b/lldb/test/API/functionalities/dynamic_value_child_count/TestDynamicValueChildCount.py
index 084e5028c6adb3..3c8315f52be065 100644
--- a/lldb/test/API/functionalities/dynamic_value_child_count/TestDynamicValueChildCount.py
+++ b/lldb/test/API/functionalities/dynamic_value_child_count/TestDynamicValueChildCount.py
@@ -64,13 +64,11 @@ def test_get_dynamic_vals(self):
process = target.LaunchSimple(None, None, self.get_process_working_directory())
self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)
- self.runCmd("log enable lldb object")
b = self.frame().FindVariable("b").GetDynamicValue(lldb.eDynamicCanRunTarget)
self.assertEqual(b.GetNumChildren(), 0, "b has 0 children")
self.runCmd("continue")
self.assertEqual(b.GetNumChildren(), 0, "b still has 0 children")
self.runCmd("continue")
- print(b)
self.assertNotEqual(b.GetNumChildren(), 0, "b now has 1 child")
self.runCmd("continue")
self.assertEqual(b.GetNumChildren(), 0, "b didn't go back to 0 children")
>From e0a7936dc8fef1cd21e882e30691c38e59bf7b6a Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sat, 31 Oct 2026 22:27:43 +0100
Subject: [PATCH 04/14] fix: use function breakpoint for test
---
.../API/lang/cpp/dynamic-value/TestDynamicValue.py | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py b/lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py
index a00ffd3af3519f..8e3561c982cf41 100644
--- a/lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py
+++ b/lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py
@@ -26,9 +26,6 @@ def setUp(self):
self.main_second_call_line = line_number(
"pass-to-base.cpp", "// Break here and get real address of reallyA."
)
- self.forward_a_line = line_number(
- "forward-a.cpp", "// Break here for forward declared A"
- )
@add_test_categories(["pyapi"])
def test_get_dynamic_vals(self):
@@ -286,9 +283,7 @@ def test_from_forward_decl(self):
imperative that this is a separate test so that we don't end up parsing
a definition of A from somewhere else."""
self.build()
- lldbutil.run_to_line_breakpoint(
- self, lldb.SBFileSpec("forward-a.cpp"), self.forward_a_line
- )
+ lldbutil.run_to_name_breakpoint(self, "take_A")
self.expect(
"frame var -d run-target --ptr-depth=1 --show-types a",
substrs=["(B *) a", "m_b_value = 10"],
@@ -302,9 +297,7 @@ def test_from_core_file(self):
that we can determine the dynamic type of the value if the core file
does not contain the type vtable."""
self.build()
- lldbutil.run_to_line_breakpoint(
- self, lldb.SBFileSpec("forward-a.cpp"), self.forward_a_line
- )
+ lldbutil.run_to_name_breakpoint(self, "take_A")
# Get the address of our object and its vtable
a = self.frame().FindVariable("a")
>From 5b7f446bf79f642d2a2d99533d28f92639d2da88 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sat, 31 Oct 2026 22:28:03 +0100
Subject: [PATCH 05/14] fix: the comment is necessary but not its content
---
lldb/test/API/lang/cpp/dynamic-value/forward-a.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lldb/test/API/lang/cpp/dynamic-value/forward-a.cpp b/lldb/test/API/lang/cpp/dynamic-value/forward-a.cpp
index b8a0f3787ad262..973c2eaf11997b 100644
--- a/lldb/test/API/lang/cpp/dynamic-value/forward-a.cpp
+++ b/lldb/test/API/lang/cpp/dynamic-value/forward-a.cpp
@@ -1,5 +1,5 @@
class A;
A *take_A(A *a) {
- return a; // Break here for forward declared A
+ return a; //
}
>From c18911b678d518ea6b1036795d8a9f5d7629a757 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sat, 31 Oct 2026 22:28:14 +0100
Subject: [PATCH 06/14] fix: re-add expected failure on arm
---
lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py b/lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py
index 8e3561c982cf41..08f74c0e78b8f3 100644
--- a/lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py
+++ b/lldb/test/API/lang/cpp/dynamic-value/TestDynamicValue.py
@@ -290,6 +290,7 @@ def test_from_forward_decl(self):
)
@expectedFailureWindows # Can't read the RTTI locator and A is a virtual base of B, so AST strategy fails.
+ @expectedFailureAll(archs=["arm$"]) # Minidump saving not implemented
@skipIf(archs=["arm64e"]) # arm64e incompatible with minidump
@skipIfWasm # No core file format for Wasm
def test_from_core_file(self):
>From f28342a5005df8731ab6500d1c475ec604fdab62 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sat, 31 Oct 2026 22:28:32 +0100
Subject: [PATCH 07/14] fix: check `tb1_vb_b1`'s address
---
.../lang/cpp/dynamic-value-complex/TestDynamicValueComplex.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lldb/test/API/lang/cpp/dynamic-value-complex/TestDynamicValueComplex.py b/lldb/test/API/lang/cpp/dynamic-value-complex/TestDynamicValueComplex.py
index 079c33f1f7057e..7f044ee4e78f69 100644
--- a/lldb/test/API/lang/cpp/dynamic-value-complex/TestDynamicValueComplex.py
+++ b/lldb/test/API/lang/cpp/dynamic-value-complex/TestDynamicValueComplex.py
@@ -237,7 +237,7 @@ def do_test(self, has_rtti: bool):
# Anything that goes through the virtual base is unknown to us, so
# it should not have a dynamic type.
tb1_vb_addr = tb1_vb.GetValueAsAddress()
- tb1_vb_b1_addr = tb1_vb.GetValueAsAddress()
+ tb1_vb_b1_addr = tb1_vb_b1.GetValueAsAddress()
self.assertNotEqual(tb1_vb_addr, lldb.LLDB_INVALID_ADDRESS)
self.assertNotEqual(tb1_vb_b1_addr, lldb.LLDB_INVALID_ADDRESS)
self.assertNotEqual(tb1_addr, tb1_vb_addr)
@@ -245,7 +245,6 @@ def do_test(self, has_rtti: bool):
self.assertNotEqual(tb1_name, tb1_vb.GetTypeName())
self.assertNotEqual(tb1_name, tb1_vb_b1.GetTypeName())
else:
- #
self.assertEqual(tb1_addr, tb1_vb.GetValueAsAddress())
self.assertEqual(tb1_name, tb1_vb.GetTypeName())
self.assertEqual(tb1_addr, tb1_vb_b1.GetValueAsAddress())
>From 7478b4af2034fc5b1b86ca3362ea79c4198603bc Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sat, 31 Oct 2026 22:28:51 +0100
Subject: [PATCH 08/14] chore: remove unused method
---
.../Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h
index 032975bf666db4..60ced516c8643c 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h
@@ -35,8 +35,6 @@ class MicrosoftABIRuntime : public CommonABIRuntime {
const LanguageRuntime::VTableInfo &vtable_info,
llvm::SmallVectorImpl<llvm::StringRef> &vtable_components);
- llvm::Error TypeHasVTable(CompilerType type);
-
std::optional<int64_t>
GetOffsetToTop(ValueObject &in_value, TypeAndOrName &class_type_or_name,
const LanguageRuntime::VTableInfo &vtable_info);
>From 591b318e54b1fd36fd50110c0af3f862679855a7 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sat, 31 Oct 2026 22:30:00 +0100
Subject: [PATCH 09/14] refactor: store `int64_t` over optional int64
---
.../LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp | 5 ++++-
.../Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
index 0355311b44f58a..9cf059514e0f88 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
@@ -189,8 +189,11 @@ std::optional<int64_t> MicrosoftABIRuntime::GetOffsetToTop(
in_value.GetPointerValue().address, strategy,
in_type.GetTypeName(), *offset, type.GetTypeName());
+ // TODO: Ideally, we could also store the case where we can't find the
+ // offset. This would need to be invalidated when new modules or debug info
+ // is loaded, as those could contain info about the vtables.
std::scoped_lock<std::mutex> g(m_mutex);
- m_offset_to_top_map[vtable_info.addr] = offset;
+ m_offset_to_top_map[vtable_info.addr] = *offset;
}
return offset;
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h
index 60ced516c8643c..5c97810079c3ff 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.h
@@ -49,7 +49,7 @@ class MicrosoftABIRuntime : public CommonABIRuntime {
const LanguageRuntime::VTableInfo &vtable_info,
llvm::ArrayRef<llvm::StringRef> vtable_components);
- using OffsetToTopCache = std::map<Address, std::optional<int64_t>>;
+ using OffsetToTopCache = std::map<Address, int64_t>;
OffsetToTopCache m_offset_to_top_map;
};
>From e89667d45c5279df4349287d67e14d636c88781a Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sat, 31 Oct 2026 22:30:22 +0100
Subject: [PATCH 10/14] fix: move cache lookup
---
.../CPlusPlus/MicrosoftABIRuntime.cpp | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
index 9cf059514e0f88..a2b278f3335a16 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
@@ -124,13 +124,6 @@ std::optional<int64_t> MicrosoftABIRuntime::GetOffsetToTop(
return std::nullopt;
}
- {
- std::scoped_lock<std::mutex> g(m_mutex);
- auto offset_to_top_it = m_offset_to_top_map.find(vtable_info.addr);
- if (offset_to_top_it != m_offset_to_top_map.end())
- return offset_to_top_it->second;
- }
-
CompilerType type = class_type_or_name.GetCompilerType();
if (!type) {
LLDB_LOG(log, "{0:x16}: failed to get type info (no compiler type)",
@@ -165,6 +158,13 @@ std::optional<int64_t> MicrosoftABIRuntime::GetOffsetToTop(
return std::nullopt;
}
+ {
+ std::scoped_lock<std::mutex> g(m_mutex);
+ auto offset_to_top_it = m_offset_to_top_map.find(vtable_info.addr);
+ if (offset_to_top_it != m_offset_to_top_map.end())
+ return offset_to_top_it->second;
+ }
+
// Unlike in the Itanium ABI, the VTable itself doesn't have a field telling
// us the offset to the dynamic type.
// When compiled with RTTI, we can use the complete object locator to get this
>From 1be30473cd55d1e654ed922fb3c97f1bfd2bd847 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sat, 31 Oct 2026 22:30:43 +0100
Subject: [PATCH 11/14] fix: use correct optional type
---
.../Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
index a2b278f3335a16..0f4420c9594390 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
@@ -51,7 +51,7 @@ bool MicrosoftABIRuntime::GetDynamicTypeAndAddress(
ValueObject &in_value, lldb::DynamicValueType use_dynamic,
const LanguageRuntime::VTableInfo &vtable_info,
TypeAndOrName &class_type_or_name, Address &dynamic_address) {
- std::optional<size_t> offset_to_top =
+ std::optional<int64_t> offset_to_top =
GetOffsetToTop(in_value, class_type_or_name, vtable_info);
if (!offset_to_top)
return false;
>From 4123efd90142e7efe332892b494695d3702c4cca Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sat, 31 Oct 2026 22:31:01 +0100
Subject: [PATCH 12/14] fix: continue after checkpoint is passed
---
.../Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
index 0f4420c9594390..a878307d4a7d78 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
@@ -367,6 +367,7 @@ GetOffsetOfBaseFromAST(clang::ASTContext &ast,
/*checkpoints=*/current.checkpoints.drop_back(),
/*found_target=*/found_target,
});
+ continue;
}
} else if (found_target) {
return offset;
>From b32faf21a3d9a2bf48ce622e56fdda4a855c1070 Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sat, 31 Oct 2026 22:31:12 +0100
Subject: [PATCH 13/14] fix: hardcode int size
---
.../CPlusPlus/MicrosoftABIRuntime.cpp | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
index a878307d4a7d78..1065948875b92e 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
@@ -254,22 +254,17 @@ std::optional<int64_t> MicrosoftABIRuntime::GetOffsetToTopFromRTTI(
if (!ts)
return std::nullopt;
- llvm::Expected<uint64_t> int_size =
- ts->GetBasicTypeFromAST(lldb::eBasicTypeInt).GetByteSize(nullptr);
- if (!int_size) {
- LLDB_LOG_ERROR(log, int_size.takeError(),
- "Failed to get size of int from AST: {0}");
- return std::nullopt;
- }
+ // On all supported platforms running the MS ABI, `int` is four bytes.
+ constexpr uint32_t int_size = 4;
// See MSRTTIBuilder::getCompleteObjectLocator in Clang for the layout.
// We're interested in the offset which is the second int in the struct.
Address offset_from_top_addr = rtti_locator_base_addr;
- offset_from_top_addr.Slide(*int_size);
+ offset_from_top_addr.Slide(int_size);
error.Clear();
const int64_t offset_from_top = target.ReadSignedIntegerFromMemory(
- offset_from_top_addr, *int_size, INT64_MIN, error);
+ offset_from_top_addr, int_size, INT64_MIN, error);
if (offset_from_top == INT64_MIN || error.Fail()) {
LLDB_LOG_ERROR(log, error.takeError(),
"Failed to read 'offset from top' from RTTI complete object "
>From cc3b945c8b04258f62d8b773a88aa51733e21fbe Mon Sep 17 00:00:00 2001
From: Nerixyz <nerixdev at outlook.de>
Date: Sat, 31 Oct 2026 22:31:25 +0100
Subject: [PATCH 14/14] fix: re-use `log`
---
.../LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
index 1065948875b92e..06ec90b7eecd4a 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/MicrosoftABIRuntime.cpp
@@ -402,8 +402,7 @@ std::optional<int64_t> MicrosoftABIRuntime::GetOffsetToTopFromAST(
TypeSystemClangSP ts = dyn_type.GetTypeSystem<TypeSystemClang>();
if (!ts || ts != in_base_type.GetTypeSystem<TypeSystemClang>()) {
- LLDB_LOG(GetLog(LLDBLog::Object),
- "{0:x16}: '{1}' and '{2}' are from different type systems",
+ LLDB_LOG(log, "{0:x16}: '{1}' and '{2}' are from different type systems",
in_value.GetPointerValue().address,
in_decl->getDeclName().getAsString(),
target_decl->getDeclName().getAsString());
@@ -413,8 +412,7 @@ std::optional<int64_t> MicrosoftABIRuntime::GetOffsetToTopFromAST(
std::optional<size_t> offset = GetOffsetOfBaseFromAST(
ts->getASTContext(), target_decl, in_decl, vtable_components);
if (!offset) {
- LLDB_LOG(GetLog(LLDBLog::Object),
- "{0:x16}: failed to find offset of '{1}' in '{2}'",
+ LLDB_LOG(log, "{0:x16}: failed to find offset of '{1}' in '{2}'",
in_value.GetPointerValue().address,
in_decl->getDeclName().getAsString(),
target_decl->getDeclName().getAsString());
More information about the lldb-commits
mailing list