[Lldb-commits] [lldb] ea95da1 - [lldb] Add an overload to SetModuleLoadAddress that takes an unsigned value

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 6 10:44:05 PDT 2023


Author: Jonas Devlieghere
Date: 2023-04-06T10:43:54-07:00
New Revision: ea95da1809008abd9b81b0fb2cc6ec6438c4c0e0

URL: https://github.com/llvm/llvm-project/commit/ea95da1809008abd9b81b0fb2cc6ec6438c4c0e0
DIFF: https://github.com/llvm/llvm-project/commit/ea95da1809008abd9b81b0fb2cc6ec6438c4c0e0.diff

LOG: [lldb] Add an overload to SetModuleLoadAddress that takes an unsigned value

Currently, SBTarget::SetModuleLoadAddress does not accept large slides
needed to load images in high memory. This function should always have
taken an unsigned as the slide, as it immediately passes it to
Target::SetSectionLoadAddress which takes an unsigned.

This patch adds an overload and exposes that to SWIG instead of the
signed variant. I've marked the signed variant as deprecated and added
check that the slide is positive.

rdar://101355155

Differential revision: https://reviews.llvm.org/D147482

Added: 
    

Modified: 
    lldb/include/lldb/API/SBTarget.h
    lldb/source/API/SBTarget.cpp
    lldb/test/API/functionalities/multiple-slides/TestMultipleSlides.py

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 072cf31994819..404e9059c2bca 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -371,6 +371,7 @@ class LLDB_API SBTarget {
   ///     failure.
   lldb::SBError ClearSectionLoadAddress(lldb::SBSection section);
 
+#ifndef SWIG
   /// Slide all file addresses for all module sections so that \a module
   /// appears to loaded at these slide addresses.
   ///
@@ -389,8 +390,31 @@ class LLDB_API SBTarget {
   /// \return
   ///     An error to indicate success, fail, and any reason for
   ///     failure.
+  [[deprecated("Use SetModuleLoadAddress(lldb::SBModule, uint64_t)")]]
   lldb::SBError SetModuleLoadAddress(lldb::SBModule module,
                                      int64_t sections_offset);
+#endif
+
+  /// Slide all file addresses for all module sections so that \a module
+  /// appears to loaded at these slide addresses.
+  ///
+  /// When you need all sections within a module to be loaded at a
+  /// rigid slide from the addresses found in the module object file,
+  /// this function will allow you to easily and quickly slide all
+  /// module sections.
+  ///
+  /// \param[in] module
+  ///     The module to load.
+  ///
+  /// \param[in] sections_offset
+  ///     An offset that will be applied to all section file addresses
+  ///     (the virtual addresses found in the object file itself).
+  ///
+  /// \return
+  ///     An error to indicate success, fail, and any reason for
+  ///     failure.
+  lldb::SBError SetModuleLoadAddress(lldb::SBModule module,
+                                     uint64_t sections_offset);
 
   /// Clear the section base load addresses for all sections in a module.
   ///

diff  --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index ddde1ba6ab8a3..301602c543f2a 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -2093,6 +2093,18 @@ SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
                                        int64_t slide_offset) {
   LLDB_INSTRUMENT_VA(this, module, slide_offset);
 
+  if (slide_offset < 0) {
+    SBError sb_error;
+    sb_error.SetErrorStringWithFormat("slide must be positive");
+    return sb_error;
+  }
+
+  return SetModuleLoadAddress(module, static_cast<uint64_t>(slide_offset));
+}
+
+SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
+                                               uint64_t slide_offset) {
+
   SBError sb_error;
 
   TargetSP target_sp(GetSP());

diff  --git a/lldb/test/API/functionalities/multiple-slides/TestMultipleSlides.py b/lldb/test/API/functionalities/multiple-slides/TestMultipleSlides.py
index c54c4010cda7b..2a2e795629053 100644
--- a/lldb/test/API/functionalities/multiple-slides/TestMultipleSlides.py
+++ b/lldb/test/API/functionalities/multiple-slides/TestMultipleSlides.py
@@ -36,14 +36,14 @@ def test_mulitple_slides(self):
         self.assertEqual(first_sym.GetStartAddress().GetLoadAddress(target), lldb.LLDB_INVALID_ADDRESS)
         self.assertEqual(second_sym.GetStartAddress().GetLoadAddress(target), lldb.LLDB_INVALID_ADDRESS)
 
-
         # View the first element of `first` and `second` with
         # no slide applied, but with load address set.
         #
         # In memory, we have something like
         #    0x1000 - 0x17ff  first[]
         #    0x1800 - 0x1fff  second[]
-        target.SetModuleLoadAddress(module, 0)
+        error = target.SetModuleLoadAddress(module, 0)
+        self.assertSuccess(error)
         self.expect("expression/d ((int*)&first)[0]", substrs=['= 5'])
         self.expect("expression/d ((int*)&second)[0]", substrs=['= 6'])
         self.assertEqual(first_sym.GetStartAddress().GetLoadAddress(target), 
@@ -60,7 +60,8 @@ def test_mulitple_slides(self):
         # but if the original entries are still present in lldb, 
         # the beginning address of second[] will get a load address
         # of 0x1800, instead of 0x17c0 (0x1800-64) as we need to get.
-        target.SetModuleLoadAddress(module, first_size - 64)
+        error = target.SetModuleLoadAddress(module, first_size - 64)
+        self.assertSuccess(error)
         self.expect("expression/d ((int*)&first)[0]", substrs=['= 5'])
         self.expect("expression/d ((int*)&second)[0]", substrs=['= 6'])
         self.assertNotEqual(first_sym.GetStartAddress().GetLoadAddress(target), 
@@ -69,7 +70,8 @@ def test_mulitple_slides(self):
                          second_sym.GetStartAddress().GetFileAddress())
 
         # Slide it back to the original vmaddr.
-        target.SetModuleLoadAddress(module, 0)
+        error = target.SetModuleLoadAddress(module, 0)
+        self.assertSuccess(error)
         self.expect("expression/d ((int*)&first)[0]", substrs=['= 5'])
         self.expect("expression/d ((int*)&second)[0]", substrs=['= 6'])
         self.assertEqual(first_sym.GetStartAddress().GetLoadAddress(target), 
@@ -77,3 +79,6 @@ def test_mulitple_slides(self):
         self.assertEqual(second_sym.GetStartAddress().GetLoadAddress(target),
                          second_sym.GetStartAddress().GetFileAddress())
 
+        # Make sure we can use a slide > INT64_MAX.
+        error = target.SetModuleLoadAddress(module, 0xffffffff12345678)
+        self.assertSuccess(error)


        


More information about the lldb-commits mailing list