Skip to content

Commit 094a84b

Browse files
authored
Merge pull request #7327 from apple/🍒/navy/ea95da180900
[lldb] Add an overload to SetModuleLoadAddress that takes an unsigned…
2 parents 3d4ba0c + 8e09c3c commit 094a84b

File tree

5 files changed

+54
-11
lines changed

5 files changed

+54
-11
lines changed

‎lldb/bindings/python/static-binding/LLDBWrapPython.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61056,12 +61056,12 @@ SWIGINTERN PyObject *_wrap_SBTarget_SetModuleLoadAddress(PyObject *self, PyObjec
6105661056
PyObject *resultobj = 0;
6105761057
lldb::SBTarget *arg1 = (lldb::SBTarget *) 0 ;
6105861058
lldb::SBModule arg2 ;
61059-
int64_t arg3 ;
61059+
uint64_t arg3 ;
6106061060
void *argp1 = 0 ;
6106161061
int res1 = 0 ;
6106261062
void *argp2 ;
6106361063
int res2 = 0 ;
61064-
long long val3 ;
61064+
unsigned long long val3 ;
6106561065
int ecode3 = 0 ;
6106661066
PyObject *swig_obj[3] ;
6106761067
lldb::SBError result;
@@ -61085,11 +61085,11 @@ SWIGINTERN PyObject *_wrap_SBTarget_SetModuleLoadAddress(PyObject *self, PyObjec
6108561085
if (SWIG_IsNewObj(res2)) delete temp;
6108661086
}
6108761087
}
61088-
ecode3 = SWIG_AsVal_long_SS_long(swig_obj[2], &val3);
61088+
ecode3 = SWIG_AsVal_unsigned_SS_long_SS_long(swig_obj[2], &val3);
6108961089
if (!SWIG_IsOK(ecode3)) {
61090-
SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "SBTarget_SetModuleLoadAddress" "', argument " "3"" of type '" "int64_t""'");
61090+
SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "SBTarget_SetModuleLoadAddress" "', argument " "3"" of type '" "uint64_t""'");
6109161091
}
61092-
arg3 = static_cast< int64_t >(val3);
61092+
arg3 = static_cast< uint64_t >(val3);
6109361093
{
6109461094
SWIG_PYTHON_THREAD_BEGIN_ALLOW;
6109561095
result = (arg1)->SetModuleLoadAddress(arg2,arg3);
@@ -90556,7 +90556,7 @@ static PyMethodDef SwigMethods[] = {
9055690556
{ "SBTarget_GetMaximumNumberOfChildrenToDisplay", _wrap_SBTarget_GetMaximumNumberOfChildrenToDisplay, METH_O, "SBTarget_GetMaximumNumberOfChildrenToDisplay(SBTarget self) -> uint32_t"},
9055790557
{ "SBTarget_SetSectionLoadAddress", _wrap_SBTarget_SetSectionLoadAddress, METH_VARARGS, "SBTarget_SetSectionLoadAddress(SBTarget self, SBSection section, lldb::addr_t section_base_addr) -> SBError"},
9055890558
{ "SBTarget_ClearSectionLoadAddress", _wrap_SBTarget_ClearSectionLoadAddress, METH_VARARGS, "SBTarget_ClearSectionLoadAddress(SBTarget self, SBSection section) -> SBError"},
90559-
{ "SBTarget_SetModuleLoadAddress", _wrap_SBTarget_SetModuleLoadAddress, METH_VARARGS, "SBTarget_SetModuleLoadAddress(SBTarget self, SBModule module, int64_t sections_offset) -> SBError"},
90559+
{ "SBTarget_SetModuleLoadAddress", _wrap_SBTarget_SetModuleLoadAddress, METH_VARARGS, "SBTarget_SetModuleLoadAddress(SBTarget self, SBModule module, uint64_t sections_offset) -> SBError"},
9056090560
{ "SBTarget_ClearModuleLoadAddress", _wrap_SBTarget_ClearModuleLoadAddress, METH_VARARGS, "SBTarget_ClearModuleLoadAddress(SBTarget self, SBModule module) -> SBError"},
9056190561
{ "SBTarget_FindFunctions", _wrap_SBTarget_FindFunctions, METH_VARARGS, "\n"
9056290562
"SBTarget_FindFunctions(SBTarget self, char const * name, uint32_t name_type_mask=eFunctionNameTypeAny) -> SBSymbolContextList\n"

‎lldb/bindings/python/static-binding/lldb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10639,7 +10639,7 @@ def ClearSectionLoadAddress(self, section):
1063910639
return _lldb.SBTarget_ClearSectionLoadAddress(self, section)
1064010640

1064110641
def SetModuleLoadAddress(self, module, sections_offset):
10642-
r"""SetModuleLoadAddress(SBTarget self, SBModule module, int64_t sections_offset) -> SBError"""
10642+
r"""SetModuleLoadAddress(SBTarget self, SBModule module, uint64_t sections_offset) -> SBError"""
1064310643
return _lldb.SBTarget_SetModuleLoadAddress(self, module, sections_offset)
1064410644

1064510645
def ClearModuleLoadAddress(self, module):

‎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)