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