Page MenuHomePhabricator

[lldb] Add AllocateMemory/DeallocateMemory to the SBProcess API

Authored by housel on Jul 2 2021, 9:23 PM.



This change adds AllocateMemory and DeallocateMemory methods to the SBProcess API, so that clients can allocate and deallocate memory blocks within the process being debugged (for storing JIT-compiled code or other uses).

(I am developing a debugger + REPL using the API; it will need to store JIT-compiled code within the target.)

Diff Detail

Event Timeline

housel requested review of this revision.Jul 2 2021, 9:23 PM
housel created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJul 2 2021, 9:23 PM
housel updated this revision to Diff 356324.Jul 2 2021, 11:01 PM
jingham added a subscriber: jingham.Jul 6 2021, 2:07 PM

Could you put a docstring describing the API's in the SBProcess.i file. It is annoying to have to do this in two places but given the way SWIG works we don't have a better alternative. This is where the help in the Python REPL comes from so it's useful to have it there. There are other example of how to do this in the .i file. Thanks!

It might also be good to test that the program can read from the newly allocated memory by, for instance, having a function in the program that returns the first character from a pointer passed in. You could call that using expr and you should also get 'a'... You could write another function that tries to write to that memory to test that setting the permissions to not writable works.


This can all be done more compactly by using lldbutil.run_to_source_breakpoint. The other tests in this test file are using the by-hand way of doing this, if you want to fix them as well, that would be great. But at least, we're trying not to write new tests this way.

clayborg added inline comments.Jul 7 2021, 2:06 PM

Add doc string that describes this function for python users. Something about "permissions" is an integer formed by combining logical OR'ing "lldb.ePermissionsWritable" "lldb.ePermissionsReadable" and "lldb.ePermissionsExecutable".


doc string would be nice here too specifying that the address should have come from a call to "AllocateMemory(...)"

housel updated this revision to Diff 357131.Jul 7 2021, 10:18 PM

Updated based on reviewer suggestions, thanks.

clayborg accepted this revision.Jul 8 2021, 10:32 AM

LGTM. Jim, chime in soon if you have any other objections!

This revision is now accepted and ready to land.Jul 8 2021, 10:32 AM
jingham accepted this revision.Jul 8 2021, 10:39 AM


LGTM. Jim, chime in soon if you have any other objections!

I don't have commit access, could some one take care of committing this for me? Thanks!

This revision was landed with ongoing or failed builds.Jul 15 2021, 3:45 PM
This revision was automatically updated to reflect the committed changes.