diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index 4ee91be52346e..56baafb2bbb1c 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -364,6 +364,8 @@ class CommandObjectMemoryRead : public CommandObjectParsed { return; } + ExecutionContextScope *exe_scope = m_exe_ctx.GetBestExecutionContextScope(); + CompilerType compiler_type; Status error; @@ -460,6 +462,13 @@ class CommandObjectMemoryRead : public CommandObjectParsed { TypeResults results; target->GetImages().FindTypes(search_first.get(), query, results); TypeSP type_sp = results.GetFirstType(); + if (!type_sp) { + // Retry, searching for typename as a mangled name. + query.SetSearchByMangledName(true); + TypeResults results; + target->GetImages().FindTypes(search_first.get(), query, results); + type_sp = results.GetFirstType(); + } if (!type_sp && lookup_type_name.GetCString()) { LanguageType language_for_type = @@ -519,7 +528,7 @@ class CommandObjectMemoryRead : public CommandObjectParsed { --pointer_count; } - auto size_or_err = compiler_type.GetByteSize(nullptr); + auto size_or_err = compiler_type.GetByteSize(exe_scope); if (!size_or_err) { result.AppendErrorWithFormat( "unable to get the byte size of the type '%s'\n%s", @@ -639,7 +648,7 @@ class CommandObjectMemoryRead : public CommandObjectParsed { if (!m_format_options.GetFormatValue().OptionWasSet()) m_format_options.GetFormatValue().SetCurrentValue(eFormatDefault); - auto size_or_err = compiler_type.GetByteSize(nullptr); + auto size_or_err = compiler_type.GetByteSize(exe_scope); if (!size_or_err) { result.AppendError(llvm::toString(size_or_err.takeError())); return; @@ -799,7 +808,6 @@ class CommandObjectMemoryRead : public CommandObjectParsed { output_stream_p = &result.GetOutputStream(); } - ExecutionContextScope *exe_scope = m_exe_ctx.GetBestExecutionContextScope(); if (compiler_type.GetOpaqueQualType()) { for (uint32_t i = 0; i < item_count; ++i) { addr_t item_addr = addr + (i * item_byte_size); diff --git a/lldb/test/API/lang/swift/command_memory_read/Makefile b/lldb/test/API/lang/swift/command_memory_read/Makefile new file mode 100644 index 0000000000000..cca30b939e652 --- /dev/null +++ b/lldb/test/API/lang/swift/command_memory_read/Makefile @@ -0,0 +1,3 @@ +SWIFT_SOURCES := main.swift +SWIFTFLAGS_EXTRAS := -parse-as-library +include Makefile.rules diff --git a/lldb/test/API/lang/swift/command_memory_read/TestSwiftMemoryRead.py b/lldb/test/API/lang/swift/command_memory_read/TestSwiftMemoryRead.py new file mode 100644 index 0000000000000..ad607398664ee --- /dev/null +++ b/lldb/test/API/lang/swift/command_memory_read/TestSwiftMemoryRead.py @@ -0,0 +1,58 @@ +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +import lldbsuite.test.lldbutil as lldbutil + + +class TestCase(TestBase): + @swiftTest + def test_scalar_types(self): + self.build() + _, _, thread, _ = lldbutil.run_to_source_breakpoint( + self, "break here", lldb.SBFileSpec("main.swift") + ) + frame = thread.selected_frame + + child = frame.var("name") + for t in ("String", "$sSSD"): + self.expect( + f"memory read -t {t} {child.load_addr}", + substrs=[f'(String) 0x{child.load_addr:x} = "dirk"'], + ) + + child = frame.var("number") + for t in ("Int", "$sSiD"): + self.expect( + f"memory read -t {t} {child.load_addr}", + substrs=[f"(Int) 0x{child.load_addr:x} = 41"], + ) + + child = frame.var("fact") + for t in ("Bool", "$sSbD"): + self.expect( + f"memory read -t {t} {child.load_addr}", + substrs=[f"(Bool) 0x{child.load_addr:x} = true"], + ) + + @swiftTest + @expectedFailureAll + def test_generic_types(self): + self.build() + _, _, thread, _ = lldbutil.run_to_source_breakpoint( + self, "break here", lldb.SBFileSpec("main.swift") + ) + frame = thread.selected_frame + + child = frame.var("maybe") + for t in ("UInt64?", "$ss6UInt64VSgD"): + self.expect( + f"memory read -t {t} {child.load_addr}", + substrs=[f"(UInt64?) 0x{child.load_addr:x} = nil"], + ) + + child = frame.var("bytes") + for t in ("[UInt8]", "$sSays5UInt8VGD"): + self.expect( + f"memory read -t {t} {child.load_addr}", + substrs=[f"([UInt8]) 0x{child.load_addr:x} = [1, 2, 4, 8]"], + ) diff --git a/lldb/test/API/lang/swift/command_memory_read/main.swift b/lldb/test/API/lang/swift/command_memory_read/main.swift new file mode 100644 index 0000000000000..8b9e757090ac8 --- /dev/null +++ b/lldb/test/API/lang/swift/command_memory_read/main.swift @@ -0,0 +1,10 @@ +@main enum Entry { + static func main() { + var name: String = "dirk" + var number: Int = 41 + var fact: Bool = true + var maybe: UInt64? = nil + var bytes: [UInt8] = [1, 2, 4, 8] + print("break here", name, number, fact, maybe, bytes) + } +}