Skip to content

Commit 840bc2a

Browse files
Merge pull request #11481 from swiftlang/dl/lldb-Pass-execution-context-to-CompilerType-GetByteSize-in-CommandObjectMemoryRead-NFC
[lldb] Pass execution context to CompilerType::GetByteSize - in CommandObjectMemoryRead (NFC)
2 parents b7d164a + 50ed085 commit 840bc2a

File tree

4 files changed

+82
-3
lines changed

4 files changed

+82
-3
lines changed

lldb/source/Commands/CommandObjectMemory.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
364364
return;
365365
}
366366

367+
ExecutionContextScope *exe_scope = m_exe_ctx.GetBestExecutionContextScope();
368+
367369
CompilerType compiler_type;
368370
Status error;
369371

@@ -460,6 +462,13 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
460462
TypeResults results;
461463
target->GetImages().FindTypes(search_first.get(), query, results);
462464
TypeSP type_sp = results.GetFirstType();
465+
if (!type_sp) {
466+
// Retry, searching for typename as a mangled name.
467+
query.SetSearchByMangledName(true);
468+
TypeResults results;
469+
target->GetImages().FindTypes(search_first.get(), query, results);
470+
type_sp = results.GetFirstType();
471+
}
463472

464473
if (!type_sp && lookup_type_name.GetCString()) {
465474
LanguageType language_for_type =
@@ -519,7 +528,7 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
519528
--pointer_count;
520529
}
521530

522-
auto size_or_err = compiler_type.GetByteSize(nullptr);
531+
auto size_or_err = compiler_type.GetByteSize(exe_scope);
523532
if (!size_or_err) {
524533
result.AppendErrorWithFormat(
525534
"unable to get the byte size of the type '%s'\n%s",
@@ -639,7 +648,7 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
639648
if (!m_format_options.GetFormatValue().OptionWasSet())
640649
m_format_options.GetFormatValue().SetCurrentValue(eFormatDefault);
641650

642-
auto size_or_err = compiler_type.GetByteSize(nullptr);
651+
auto size_or_err = compiler_type.GetByteSize(exe_scope);
643652
if (!size_or_err) {
644653
result.AppendError(llvm::toString(size_or_err.takeError()));
645654
return;
@@ -799,7 +808,6 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
799808
output_stream_p = &result.GetOutputStream();
800809
}
801810

802-
ExecutionContextScope *exe_scope = m_exe_ctx.GetBestExecutionContextScope();
803811
if (compiler_type.GetOpaqueQualType()) {
804812
for (uint32_t i = 0; i < item_count; ++i) {
805813
addr_t item_addr = addr + (i * item_byte_size);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFTFLAGS_EXTRAS := -parse-as-library
3+
include Makefile.rules
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
7+
class TestCase(TestBase):
8+
@swiftTest
9+
def test_scalar_types(self):
10+
self.build()
11+
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
12+
self, "break here", lldb.SBFileSpec("main.swift")
13+
)
14+
frame = thread.selected_frame
15+
16+
child = frame.var("name")
17+
for t in ("String", "$sSSD"):
18+
self.expect(
19+
f"memory read -t {t} {child.load_addr}",
20+
substrs=[f'(String) 0x{child.load_addr:x} = "dirk"'],
21+
)
22+
23+
child = frame.var("number")
24+
for t in ("Int", "$sSiD"):
25+
self.expect(
26+
f"memory read -t {t} {child.load_addr}",
27+
substrs=[f"(Int) 0x{child.load_addr:x} = 41"],
28+
)
29+
30+
child = frame.var("fact")
31+
for t in ("Bool", "$sSbD"):
32+
self.expect(
33+
f"memory read -t {t} {child.load_addr}",
34+
substrs=[f"(Bool) 0x{child.load_addr:x} = true"],
35+
)
36+
37+
@swiftTest
38+
@expectedFailureAll
39+
def test_generic_types(self):
40+
self.build()
41+
_, _, thread, _ = lldbutil.run_to_source_breakpoint(
42+
self, "break here", lldb.SBFileSpec("main.swift")
43+
)
44+
frame = thread.selected_frame
45+
46+
child = frame.var("maybe")
47+
for t in ("UInt64?", "$ss6UInt64VSgD"):
48+
self.expect(
49+
f"memory read -t {t} {child.load_addr}",
50+
substrs=[f"(UInt64?) 0x{child.load_addr:x} = nil"],
51+
)
52+
53+
child = frame.var("bytes")
54+
for t in ("[UInt8]", "$sSays5UInt8VGD"):
55+
self.expect(
56+
f"memory read -t {t} {child.load_addr}",
57+
substrs=[f"([UInt8]) 0x{child.load_addr:x} = [1, 2, 4, 8]"],
58+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@main enum Entry {
2+
static func main() {
3+
var name: String = "dirk"
4+
var number: Int = 41
5+
var fact: Bool = true
6+
var maybe: UInt64? = nil
7+
var bytes: [UInt8] = [1, 2, 4, 8]
8+
print("break here", name, number, fact, maybe, bytes)
9+
}
10+
}

0 commit comments

Comments
 (0)