Skip to content

Commit 5e30ea2

Browse files
Return a SwiftArrayEmptyBufferHandler if loc points to an EmptyArray Symbol.
If we have a ValueObjectSP who's storage_location points to a S_swiftEmptyArrayStorage symbol, return a SwiftArrayEmptyBufferHandler
1 parent 106fe98 commit 5e30ea2

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

lldb/source/Plugins/Language/Swift/SwiftArray.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
1616
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
1717
#include "Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h"
18+
#include "lldb/Core/Address.h"
1819
#include "lldb/DataFormatters/FormattersHelpers.h"
1920
#include "lldb/Target/Process.h"
2021
#include "lldb/Target/Target.h"
@@ -460,6 +461,21 @@ SwiftArrayBufferHandler::CreateBufferHandler(ValueObject &static_valobj) {
460461
lldb::addr_t storage_location =
461462
buffer_sp->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
462463

464+
lldb_private::Address addr = Address();
465+
addr.SetLoadAddress(storage_location, exe_ctx.GetTargetPtr());
466+
467+
// If the storage_location points to a swiftEmptyArrayStorage symbol, return
468+
// a SwiftArrayEmptyBufferHandler.
469+
if (auto *symbol = addr.CalculateSymbolContextSymbol()) {
470+
auto mangledName = symbol->GetMangled().GetMangledName().GetStringRef();
471+
if (mangledName == "$ss19__EmptyArrayStorageCN") {
472+
CompilerType elem_type(
473+
valobj.GetCompilerType().GetArrayElementType(exe_scope));
474+
return std::unique_ptr<SwiftArrayBufferHandler>(
475+
new SwiftArrayEmptyBufferHandler(elem_type));
476+
}
477+
}
478+
463479
if (storage_location != LLDB_INVALID_ADDRESS) {
464480
ProcessSP process_sp(valobj.GetProcessSP());
465481
if (!process_sp)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
3+
include Makefile.rules
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
7+
class TestSwiftGlobalEmptyArray(lldbtest.TestBase):
8+
@swiftTest
9+
def test(self):
10+
"""Test that printing a global swift array of type SwiftEmptyArrayStorage uses the correct data formatter"""
11+
12+
self.build()
13+
filespec = lldb.SBFileSpec("main.swift")
14+
target, process, thread, breakpoint1 = lldbutil.run_to_source_breakpoint(
15+
self, "break here", filespec
16+
)
17+
self.expect("p x", substrs=["([a.P]) 0 values {}"])
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
protocol P {}
2+
3+
func go() {
4+
let x: [any P] = []
5+
print("break here")
6+
}
7+
8+
go()

0 commit comments

Comments
 (0)