-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lldb] Add ScriptedPlatform python implementation
This patch introduces both the Scripted Platform python base implementation and an example for it. The base implementation is embedded in lldb python module under `lldb.plugins.scripted_platform`. This patch also refactor the various SWIG methods to create scripted objects into a single method, that is now shared between the Scripted Platform, Process and Thread. It also replaces the target argument by a execution context object. Differential Revision: https://reviews.llvm.org/D139250 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
- Loading branch information
1 parent
2d53527
commit bb4ccc6
Showing
13 changed files
with
176 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
lldb/examples/python/scripted_process/scripted_platform.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from abc import ABCMeta, abstractmethod | ||
|
||
import lldb | ||
|
||
class ScriptedPlatform(metaclass=ABCMeta): | ||
|
||
""" | ||
The base class for a scripted platform. | ||
Most of the base class methods are `@abstractmethod` that need to be | ||
overwritten by the inheriting class. | ||
DISCLAIMER: THIS INTERFACE IS STILL UNDER DEVELOPMENT AND NOT STABLE. | ||
THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE. | ||
""" | ||
|
||
processes = None | ||
|
||
@abstractmethod | ||
def __init__(self, exe_ctx, args): | ||
""" Construct a scripted platform. | ||
Args: | ||
exe_ctx (lldb.SBExecutionContext): The execution context for the scripted platform | ||
args (lldb.SBStructuredData): A Dictionary holding arbitrary | ||
key/value pairs used by the scripted platform. | ||
""" | ||
processes = [] | ||
|
||
@abstractmethod | ||
def list_processes(self): | ||
""" Get a list of processes that are running or that can be attached to on the platform. | ||
processes = { | ||
420: { | ||
name: a.out, | ||
arch: aarch64, | ||
pid: 420, | ||
parent_pid: 42 (optional), | ||
uid: 0 (optional), | ||
gid: 0 (optional), | ||
}, | ||
} | ||
Returns: | ||
Dict: The processes represented as a dictionary, with at least the | ||
process ID, name, architecture. Optionally, the user can also | ||
provide the parent process ID and the user and group IDs. | ||
The dictionary can be empty. | ||
""" | ||
pass | ||
|
||
def get_process_info(self, pid): | ||
""" Get the dictionary describing the process. | ||
Returns: | ||
Dict: The dictionary of process info that matched process ID. | ||
None if the process doesn't exists | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def attach_to_process(self, attach_info): | ||
""" Attach to a process. | ||
Args: | ||
attach_info (lldb.SBAttachInfo): The information related to attach to a process. | ||
Returns: | ||
lldb.SBError: A status object notifying if the attach succeeded. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def launch_process(self, launch_info): | ||
""" Launch a process. | ||
Args: | ||
launch_info (lldb.SBLaunchInfo): The information related to the process launch. | ||
Returns: | ||
lldb.SBError: A status object notifying if the launch succeeded. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def kill_process(self, pid): | ||
""" Kill a process. | ||
Args: | ||
pid (int): Process ID for the process to be killed. | ||
Returns: | ||
lldb.SBError: A status object notifying if the shutdown succeeded. | ||
""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
lldb/test/API/functionalities/scripted_platform/my_scripted_platform.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
|
||
import lldb | ||
from lldb.plugins.scripted_platform import ScriptedPlatform | ||
|
||
class MyScriptedPlatform(ScriptedPlatform): | ||
|
||
def __init__(self, exe_ctx, args): | ||
self.processes = {} | ||
|
||
proc = {} | ||
proc['name'] = 'a.out' | ||
proc['arch'] = 'arm64-apple-macosx' | ||
proc['pid'] = 420 | ||
proc['parent'] = 42 | ||
proc['uid'] = 501 | ||
proc['gid'] = 20 | ||
self.processes[420] = proc | ||
|
||
def list_processes(self): | ||
return self.processes | ||
|
||
def get_process_info(self, pid): | ||
return self.processes[pid] | ||
|
||
def launch_process(self, launch_info): | ||
return lldb.SBError() | ||
|
||
def kill_process(self, pid): | ||
return lldb.SBError() | ||
|
||
def __lldb_init_module(debugger, dict): | ||
if not 'SKIP_SCRIPTED_PLATFORM_SELECT' in os.environ: | ||
debugger.HandleCommand( | ||
"platform select scripted-platform -C %s.%s" % (__name__, MyScriptedPlatform.__name__)) | ||
else: | ||
print("Name of the class that will manage the scripted platform: '%s.%s'" | ||
% (__name__, MyScriptedPlatform.__name__)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters