Skip to content

Commit 0c837b9

Browse files
committed
[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 (cherry picked from commit ea95da1)
1 parent cce90ed commit 0c837b9

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

lldb/include/lldb/API/SBTarget.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,30 @@ class LLDB_API SBTarget {
377377
/// failure.
378378
lldb::SBError ClearSectionLoadAddress(lldb::SBSection section);
379379

380+
#ifndef SWIG
381+
/// Slide all file addresses for all module sections so that \a module
382+
/// appears to loaded at these slide addresses.
383+
///
384+
/// When you need all sections within a module to be loaded at a
385+
/// rigid slide from the addresses found in the module object file,
386+
/// this function will allow you to easily and quickly slide all
387+
/// module sections.
388+
///
389+
/// \param[in] module
390+
/// The module to load.
391+
///
392+
/// \param[in] sections_offset
393+
/// An offset that will be applied to all section file addresses
394+
/// (the virtual addresses found in the object file itself).
395+
///
396+
/// \return
397+
/// An error to indicate success, fail, and any reason for
398+
/// failure.
399+
[[deprecated("Use SetModuleLoadAddress(lldb::SBModule, uint64_t)")]]
400+
lldb::SBError SetModuleLoadAddress(lldb::SBModule module,
401+
int64_t sections_offset);
402+
#endif
403+
380404
/// Slide all file addresses for all module sections so that \a module
381405
/// appears to loaded at these slide addresses.
382406
///
@@ -398,7 +422,7 @@ class LLDB_API SBTarget {
398422
LLDB_DEPRECATED_FIXME("Use SetModuleLoadAddress(lldb::SBModule, uint64_t)",
399423
"SetModuleLoadAddress(lldb::SBModule, uint64_t)")
400424
lldb::SBError SetModuleLoadAddress(lldb::SBModule module,
401-
int64_t sections_offset);
425+
uint64_t sections_offset);
402426

403427
/// Clear the section base load addresses for all sections in a module.
404428
///

lldb/source/API/SBTarget.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,18 @@ SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
22062206
int64_t slide_offset) {
22072207
LLDB_INSTRUMENT_VA(this, module, slide_offset);
22082208

2209+
if (slide_offset < 0) {
2210+
SBError sb_error;
2211+
sb_error.SetErrorStringWithFormat("slide must be positive");
2212+
return sb_error;
2213+
}
2214+
2215+
return SetModuleLoadAddress(module, static_cast<uint64_t>(slide_offset));
2216+
}
2217+
2218+
SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
2219+
uint64_t slide_offset) {
2220+
22092221
SBError sb_error;
22102222

22112223
TargetSP target_sp(GetSP());

lldb/test/API/functionalities/multiple-slides/TestMultipleSlides.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def test_mulitple_slides(self):
5353
# In memory, we have something like
5454
# 0x1000 - 0x17ff first[]
5555
# 0x1800 - 0x1fff second[]
56-
target.SetModuleLoadAddress(module, 0)
56+
error = target.SetModuleLoadAddress(module, 0)
57+
self.assertSuccess(error)
5758
self.expect("expression/d ((int*)&first)[0]", substrs=["= 5"])
5859
self.expect("expression/d ((int*)&second)[0]", substrs=["= 6"])
5960
self.assertEqual(
@@ -74,7 +75,8 @@ def test_mulitple_slides(self):
7475
# but if the original entries are still present in lldb,
7576
# the beginning address of second[] will get a load address
7677
# of 0x1800, instead of 0x17c0 (0x1800-64) as we need to get.
77-
target.SetModuleLoadAddress(module, first_size - 64)
78+
error = target.SetModuleLoadAddress(module, first_size - 64)
79+
self.assertSuccess(error)
7880
self.expect("expression/d ((int*)&first)[0]", substrs=["= 5"])
7981
self.expect("expression/d ((int*)&second)[0]", substrs=["= 6"])
8082
self.assertNotEqual(
@@ -87,7 +89,8 @@ def test_mulitple_slides(self):
8789
)
8890

8991
# Slide it back to the original vmaddr.
90-
target.SetModuleLoadAddress(module, 0)
92+
error = target.SetModuleLoadAddress(module, 0)
93+
self.assertSuccess(error)
9194
self.expect("expression/d ((int*)&first)[0]", substrs=["= 5"])
9295
self.expect("expression/d ((int*)&second)[0]", substrs=["= 6"])
9396
self.assertEqual(
@@ -98,3 +101,7 @@ def test_mulitple_slides(self):
98101
second_sym.GetStartAddress().GetLoadAddress(target),
99102
second_sym.GetStartAddress().GetFileAddress(),
100103
)
104+
105+
# Make sure we can use a slide > INT64_MAX.
106+
error = target.SetModuleLoadAddress(module, 0xFFFFFFFF12345678)
107+
self.assertSuccess(error)

0 commit comments

Comments
 (0)