[Lldb-commits] [lldb] 3f196e0 - [lldb][core] Fix getting summary of a variable pointing to r/o memory (#139196)
via lldb-commits
lldb-commits at lists.llvm.org
Tue May 20 13:50:28 PDT 2025
Author: Igor Kudrin
Date: 2025-05-20T13:50:24-07:00
New Revision: 3f196e029314e3ccb429413a5f38ad241e50f3c5
URL: https://github.com/llvm/llvm-project/commit/3f196e029314e3ccb429413a5f38ad241e50f3c5
DIFF: https://github.com/llvm/llvm-project/commit/3f196e029314e3ccb429413a5f38ad241e50f3c5.diff
LOG: [lldb][core] Fix getting summary of a variable pointing to r/o memory (#139196)
Motivation example:
```
> lldb -c altmain2.core
...
(lldb) var F
(const char *) F = 0x0804a000 ""
```
The variable `F` points to a read-only memory page not dumped to the
core file, so `Process::ReadMemory()` cannot read the data. The patch
switches to `Target::ReadMemory()`, which can read data both from the
process memory and the application binary.
Added:
lldb/test/API/functionalities/postmortem/elf-core/altmain2.core
lldb/test/API/functionalities/postmortem/elf-core/altmain2.out
Modified:
lldb/source/ValueObject/ValueObject.cpp
lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
Removed:
################################################################################
diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp
index 46426ae499be9..487c95ca03a69 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -734,11 +734,13 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx,
} break;
case eAddressTypeLoad: {
ExecutionContext exe_ctx(GetExecutionContextRef());
- Process *process = exe_ctx.GetProcessPtr();
- if (process) {
+ if (Target *target = exe_ctx.GetTargetPtr()) {
heap_buf_ptr->SetByteSize(bytes);
- size_t bytes_read = process->ReadMemory(
- addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
+ Address target_addr;
+ target_addr.SetLoadAddress(addr + offset, target);
+ size_t bytes_read =
+ target->ReadMemory(target_addr, heap_buf_ptr->GetBytes(), bytes,
+ error, /*force_live_memory=*/true);
if (error.Success() || bytes_read > 0) {
data.SetData(data_sp);
return bytes_read;
diff --git a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
index a287fd19ba352..a68175dc4e4d7 100644
--- a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
+++ b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
@@ -977,6 +977,34 @@ def test_get_core_file_api(self):
self.assertEqual(process.GetCoreFile().GetFilename(), core_file_name)
self.dbg.DeleteTarget(target)
+ @skipIfLLVMTargetMissing("X86")
+ def test_read_only_cstring(self):
+ """
+ Test that we can show the summary for a cstring variable that points
+ to a read-only memory page which is not dumped to a core file.
+ """
+ target = self.dbg.CreateTarget("altmain2.out")
+ process = target.LoadCore("altmain2.core")
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ frame = process.GetSelectedThread().GetFrameAtIndex(0)
+ self.assertEqual(frame.GetFunctionName(), "_start")
+
+ var = frame.FindVariable("F")
+
+ # The variable points to a read-only segment that is not dumped to
+ # the core file and thus 'process.ReadCStringFromMemory()' cannot get
+ # the value.
+ error = lldb.SBError()
+ cstr = process.ReadCStringFromMemory(var.GetValueAsUnsigned(), 256, error)
+ self.assertFailure(error, error_str="core file does not contain 0x804a000")
+ self.assertEqual(cstr, "")
+
+ # Nevertheless, when getting the summary, the value can be read from the
+ # application binary.
+ cstr = var.GetSummary()
+ self.assertEqual(cstr, '"_start"')
+
def check_memory_regions(self, process, region_count):
region_list = process.GetMemoryRegions()
self.assertEqual(region_list.GetSize(), region_count)
diff --git a/lldb/test/API/functionalities/postmortem/elf-core/altmain2.core b/lldb/test/API/functionalities/postmortem/elf-core/altmain2.core
new file mode 100755
index 0000000000000..b9dd8de08b813
Binary files /dev/null and b/lldb/test/API/functionalities/postmortem/elf-core/altmain2.core
diff er
diff --git a/lldb/test/API/functionalities/postmortem/elf-core/altmain2.out b/lldb/test/API/functionalities/postmortem/elf-core/altmain2.out
new file mode 100755
index 0000000000000..e930c3d8055e1
Binary files /dev/null and b/lldb/test/API/functionalities/postmortem/elf-core/altmain2.out
diff er
More information about the lldb-commits
mailing list