xref: /openbsd-src/gnu/llvm/lldb/examples/python/scripted_process/scripted_platform.py (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1*f6aab3d8Srobertfrom abc import ABCMeta, abstractmethod
2*f6aab3d8Srobert
3*f6aab3d8Srobertimport lldb
4*f6aab3d8Srobert
5*f6aab3d8Srobertclass ScriptedPlatform(metaclass=ABCMeta):
6*f6aab3d8Srobert
7*f6aab3d8Srobert    """
8*f6aab3d8Srobert    The base class for a scripted platform.
9*f6aab3d8Srobert
10*f6aab3d8Srobert    Most of the base class methods are `@abstractmethod` that need to be
11*f6aab3d8Srobert    overwritten by the inheriting class.
12*f6aab3d8Srobert
13*f6aab3d8Srobert    DISCLAIMER: THIS INTERFACE IS STILL UNDER DEVELOPMENT AND NOT STABLE.
14*f6aab3d8Srobert                THE METHODS EXPOSED MIGHT CHANGE IN THE FUTURE.
15*f6aab3d8Srobert    """
16*f6aab3d8Srobert
17*f6aab3d8Srobert    processes = None
18*f6aab3d8Srobert
19*f6aab3d8Srobert    @abstractmethod
20*f6aab3d8Srobert    def __init__(self, exe_ctx, args):
21*f6aab3d8Srobert        """ Construct a scripted platform.
22*f6aab3d8Srobert
23*f6aab3d8Srobert        Args:
24*f6aab3d8Srobert            exe_ctx (lldb.SBExecutionContext): The execution context for the scripted platform
25*f6aab3d8Srobert            args (lldb.SBStructuredData): A Dictionary holding arbitrary
26*f6aab3d8Srobert                key/value pairs used by the scripted platform.
27*f6aab3d8Srobert        """
28*f6aab3d8Srobert        processes = []
29*f6aab3d8Srobert
30*f6aab3d8Srobert    @abstractmethod
31*f6aab3d8Srobert    def list_processes(self):
32*f6aab3d8Srobert        """ Get a list of processes that are running or that can be attached to on the platform.
33*f6aab3d8Srobert
34*f6aab3d8Srobert        processes = {
35*f6aab3d8Srobert            420: {
36*f6aab3d8Srobert                    name: a.out,
37*f6aab3d8Srobert                    arch: aarch64,
38*f6aab3d8Srobert                    pid: 420,
39*f6aab3d8Srobert                    parent_pid: 42 (optional),
40*f6aab3d8Srobert                    uid: 0 (optional),
41*f6aab3d8Srobert                    gid: 0 (optional),
42*f6aab3d8Srobert            },
43*f6aab3d8Srobert        }
44*f6aab3d8Srobert
45*f6aab3d8Srobert        Returns:
46*f6aab3d8Srobert            Dict: The processes represented as a dictionary, with at least the
47*f6aab3d8Srobert                process ID, name, architecture. Optionally, the user can also
48*f6aab3d8Srobert                provide the parent process ID and the user and group IDs.
49*f6aab3d8Srobert                The dictionary can be empty.
50*f6aab3d8Srobert        """
51*f6aab3d8Srobert        pass
52*f6aab3d8Srobert
53*f6aab3d8Srobert    def get_process_info(self, pid):
54*f6aab3d8Srobert        """ Get the dictionary describing the process.
55*f6aab3d8Srobert
56*f6aab3d8Srobert        Returns:
57*f6aab3d8Srobert            Dict: The dictionary of process info that matched process ID.
58*f6aab3d8Srobert            None if the process doesn't exists
59*f6aab3d8Srobert        """
60*f6aab3d8Srobert        pass
61*f6aab3d8Srobert
62*f6aab3d8Srobert    @abstractmethod
63*f6aab3d8Srobert    def attach_to_process(self, attach_info):
64*f6aab3d8Srobert        """ Attach to a process.
65*f6aab3d8Srobert
66*f6aab3d8Srobert        Args:
67*f6aab3d8Srobert            attach_info (lldb.SBAttachInfo): The information related to attach to a process.
68*f6aab3d8Srobert
69*f6aab3d8Srobert        Returns:
70*f6aab3d8Srobert            lldb.SBError: A status object notifying if the attach succeeded.
71*f6aab3d8Srobert        """
72*f6aab3d8Srobert        pass
73*f6aab3d8Srobert
74*f6aab3d8Srobert    @abstractmethod
75*f6aab3d8Srobert    def launch_process(self, launch_info):
76*f6aab3d8Srobert        """ Launch a process.
77*f6aab3d8Srobert
78*f6aab3d8Srobert        Args:
79*f6aab3d8Srobert            launch_info (lldb.SBLaunchInfo): The information related to the process launch.
80*f6aab3d8Srobert
81*f6aab3d8Srobert        Returns:
82*f6aab3d8Srobert            lldb.SBError: A status object notifying if the launch succeeded.
83*f6aab3d8Srobert        """
84*f6aab3d8Srobert        pass
85*f6aab3d8Srobert
86*f6aab3d8Srobert    @abstractmethod
87*f6aab3d8Srobert    def kill_process(self, pid):
88*f6aab3d8Srobert        """ Kill a process.
89*f6aab3d8Srobert
90*f6aab3d8Srobert        Args:
91*f6aab3d8Srobert            pid (int): Process ID for the process to be killed.
92*f6aab3d8Srobert
93*f6aab3d8Srobert        Returns:
94*f6aab3d8Srobert            lldb.SBError: A status object notifying if the shutdown succeeded.
95*f6aab3d8Srobert        """
96*f6aab3d8Srobert        pass
97