jasonmolenda updated this revision to Diff 474297.
jasonmolenda added a comment.

Update the test to check all three members of the struct can be read at the 
different memory addresses, and CAN'T be read when it overlaps with 
IRMemoryMap's special address.  This final test, where we test that the values 
can't be accessed at this inaddressable location, is really only there to keep 
the test and IRMemoryMap in sync - if anyone changes how IRMemoryMap::FindSpace 
works with this setup, the test result changing will flag that this test needs 
to be revisited.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137682/new/

https://reviews.llvm.org/D137682

Files:
  lldb/source/Expression/DWARFExpression.cpp
  lldb/source/Expression/IRMemoryMap.cpp
  lldb/test/API/lang/c/high-mem-global/Makefile
  lldb/test/API/lang/c/high-mem-global/TestHighMemGlobal.py
  lldb/test/API/lang/c/high-mem-global/main.c

Index: lldb/test/API/lang/c/high-mem-global/main.c
===================================================================
--- /dev/null
+++ lldb/test/API/lang/c/high-mem-global/main.c
@@ -0,0 +1,9 @@
+
+struct mystruct {
+  int c, d, e;
+} global = {1, 2, 3};
+
+int main ()
+{
+  return global.c; // break here
+}
Index: lldb/test/API/lang/c/high-mem-global/TestHighMemGlobal.py
===================================================================
--- /dev/null
+++ lldb/test/API/lang/c/high-mem-global/TestHighMemGlobal.py
@@ -0,0 +1,62 @@
+"""Look that lldb can display a global loaded in high memory at an addressable address."""
+
+
+import lldb
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+
+class TestHighMemGlobal(TestBase):
+
+    NO_DEBUG_INFO_TESTCASE = True
+
+    @skipUnlessDarwin  # hardcoding of __DATA segment name
+    def test_command_line(self):
+        """Test that we can display a global variable loaded in high memory."""
+        self.build()
+
+        exe = self.getBuildArtifact("a.out")
+        err = lldb.SBError()
+
+        target = self.dbg.CreateTarget(exe, '', '', False, err)
+        self.assertTrue(target.IsValid())
+        module = target.GetModuleAtIndex(0)
+        self.assertTrue(module.IsValid())
+        data_segment = module.FindSection("__DATA")
+        self.assertTrue(data_segment.IsValid())
+        err.Clear()
+
+        self.expect("p global.c", substrs=[' = 1'])
+        self.expect("p global.d", substrs=[' = 2'])
+        self.expect("p global.e", substrs=[' = 3'])
+
+        err = target.SetSectionLoadAddress(data_segment, 0xffffffff00000000)
+        self.assertTrue(err.Success())
+        self.expect("p global.c", substrs=[' = 1'])
+        self.expect("p global.d", substrs=[' = 2'])
+        self.expect("p global.e", substrs=[' = 3'])
+
+        err = target.SetSectionLoadAddress(data_segment, 0x0000088100004000)
+        self.assertTrue(err.Success())
+        self.expect("p global.c", substrs=[' = 1'])
+        self.expect("p global.d", substrs=[' = 2'])
+        self.expect("p global.e", substrs=[' = 3'])
+
+        # This is an address in IRMemoryMap::FindSpace where it has an 
+        # lldb-side buffer of memory that's used in IR interpreters when
+        # memory cannot be allocated in the inferior / functions cannot
+        # be jitted.
+        err = target.SetSectionLoadAddress(data_segment, 0xdead0fff00000000)
+        self.assertTrue(err.Success())
+
+        # The global variable `global` is now overlayed by this 
+        # IRMemoryMap special buffer, and now we cannot see the variable.
+        # If the IRInterpreter some day is able to distinguish between
+        # an addr_t in its IRMemoryMap local buffer versus inferior process
+        # memory, this test would no longer pass.  We may have uninitialized
+        # data in the IRMemoryMap local buffer and one of the values could
+        # come back as "correct" by chance - pass if any of them doesn't match.
+        self.runCmd("p int $global_c = global.c")
+        self.runCmd("p int $global_d = global.d")
+        self.runCmd("p int $global_e = global.e")
+        self.expect("p $global_c != 1 || $global_d != 2 || $global_e != 3", substrs=[' = true'])
Index: lldb/test/API/lang/c/high-mem-global/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/lang/c/high-mem-global/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
Index: lldb/source/Expression/IRMemoryMap.cpp
===================================================================
--- lldb/source/Expression/IRMemoryMap.cpp
+++ lldb/source/Expression/IRMemoryMap.cpp
@@ -143,7 +143,7 @@
     if (address_byte_size != UINT32_MAX) {
       switch (address_byte_size) {
       case 8:
-        ret = 0xffffffff00000000ull;
+        ret = 0xdead0fff00000000ull;
         break;
       case 4:
         ret = 0xee000000ull;
Index: lldb/source/Expression/DWARFExpression.cpp
===================================================================
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -917,9 +917,8 @@
         stack.back().SetValueType(Value::ValueType::FileAddress);
         // Convert the file address to a load address, so subsequent
         // DWARF operators can operate on it.
-        if (frame)
-          stack.back().ConvertToLoadAddress(module_sp.get(),
-                                            frame->CalculateTarget().get());
+        if (target)
+          stack.back().ConvertToLoadAddress(module_sp.get(), target);
       }
       break;
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to