Skip to content

Conversation

@kastiglione
Copy link
Contributor

@kastiglione kastiglione commented Sep 9, 2025

Some type systems require an execution context be available when working with types (ex: Swift). This fixes memory read --type to support such type systems, by passing in an execution context to GetByteSize(), instead of passing null.

rdar://158968545

@kastiglione kastiglione changed the title [lldb] Pass exe_scope to CompilerType::GetByteSize - in CommandObjectMemoryRead (NFC) [lldb] Pass execution context to CompilerType::GetByteSize - in CommandObjectMemoryRead (NFC) Sep 9, 2025
@kastiglione
Copy link
Contributor Author

I'll have to test this downstream in the Swift repo.

@kastiglione kastiglione marked this pull request as ready for review September 9, 2025 23:28
@llvmbot llvmbot added the lldb label Sep 9, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2025

@llvm/pr-subscribers-lldb

Author: Dave Lee (kastiglione)

Changes

Some type systems require an execution context be available when working with types (ex: Swift). This fixes memory read --type to support such type systems, by passing in an execution context to GetByteSize(), instead of passing null.

rdar://158968545


Full diff: https://github.com/llvm/llvm-project/pull/157750.diff

1 Files Affected:

  • (modified) lldb/source/Commands/CommandObjectMemory.cpp (+4-3)
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index af1ff3e845109..5786e757ef7ea 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -365,6 +365,8 @@ class CommandObjectMemoryRead : public CommandObjectParsed {
       return;
     }
 
+    ExecutionContextScope *exe_scope = m_exe_ctx.GetBestExecutionContextScope();
+
     CompilerType compiler_type;
     Status error;
 
@@ -520,7 +522,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",
@@ -640,7 +642,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;
@@ -800,7 +802,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);

@kastiglione kastiglione merged commit b574e63 into llvm:main Sep 10, 2025
13 checks passed
@kastiglione kastiglione deleted the lldb-Pass-exe_scope-to-CompilerType-GetByteSize-in-CommandObjectMemoryRead-NFC branch September 10, 2025 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants