Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lldb/source/Commands/CommandObjectMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
return;
}

ExecutionContextScope *exe_scope = m_exe_ctx.GetBestExecutionContextScope();

CompilerType compiler_type;
Status error;

Expand Down Expand Up @@ -519,7 +521,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",
Expand Down Expand Up @@ -639,7 +641,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;
Expand Down Expand Up @@ -799,7 +801,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);
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/lang/swift/command_memory_read/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SWIFT_SOURCES := main.swift
SWIFTFLAGS_EXTRAS := -parse-as-library
include Makefile.rules
Original file line number Diff line number Diff line change
@@ -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]"],
)
10 changes: 10 additions & 0 deletions lldb/test/API/lang/swift/command_memory_read/main.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}