aboutsummaryrefslogtreecommitdiff
path: root/lldb/examples/python/templates/operating_system.py
blob: d83019079ee90f28110c09b7ec5a0c59602dddd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from abc import abstractmethod

import lldb
import struct

from lldb.plugins.scripted_process import ScriptedThread


class OperatingSystem(ScriptedThread):
    """
    Class that provides data for an instance of a LLDB 'OperatingSystemPython' plug-in class.

    .. code-block:: python

        thread_info = {
            "tid": tid,
            "name": "four",
            "queue": "queue4",
            "state": "stopped",
            "stop_reason": "none",
            "core" : 2
        }

    - tid : thread ID (mandatory)
    - name : thread name (optional key/value pair)
    - queue : thread dispatch queue name (optional key/value pair)
    - state : thread state (mandatory, set to 'stopped' for now)
    - core : the index of the core (lldb) thread that this OS Thread should shadow
    - stop_reason : thread stop reason. (mandatory, usually set to 'none')
        Possible values include:
        - 'breakpoint': thread is stopped at a breakpoint
        - 'none': thread is stopped because the process is stopped
        - 'trace': thread is stopped after single stepping
        The usual value for this while threads are in memory is 'none'
    - register_data_addr : the address of the register data in memory (optional key/value pair)
        Specifying this key/value pair for a thread will avoid a call to get_register_data()
        and can be used when your registers are in a thread context structure that is contiguous
        in memory. Don't specify this if your register layout in memory doesn't match the layout
        described by the dictionary returned from a call to the get_register_info() method.
    """

    def __init__(self, process):
        """Initialization needs a valid lldb.SBProcess object. This plug-in
        will get created after a live process is valid and has stopped for the
        first time.

        Args:
            process (lldb.SBProcess): The process owning this thread.
        """
        self.registers = None
        super().__init__(process, None)
        self.registers = self.register_info
        self.threads = []

    def create_thread(self, tid, context):
        """Lazily create an operating system thread using a thread information
        dictionary and an optional operating system thread context address.
        This method is called manually, using the SBAPI
        `lldb.SBProcess.CreateOSPluginThread` affordance.

        Args:
            tid (int): Thread ID to get `thread_info` dictionary for.
            context (int): Address of the operating system thread struct.

        Returns:
            Dict: The `thread_info` dictionary containing the various information
            for lldb to create a Thread object and add it to the process thread list.
        """
        return None

    @abstractmethod
    def get_thread_info(self):
        """Get the list of operating system threads. This method gets called
        automatically every time the process stops and it needs to update its
        thread list.

        Returns:
            List[thread_info]: A list of `os_thread` dictionaries
                containing at least for each entry, the thread id, it's name,
                queue, state, stop reason. It can also contain a
                `register_data_addr`. The list can be empty.
        """
        pass

    @abstractmethod
    def get_register_data(self, tid):
        """Get the operating system thread register context for given a thread
        id. This method is called when unwinding the stack of one of the
        operating system threads.

        Args:
            tid (int): Thread ID to get register context for.

        Returns:
            str: A byte representing all register's value.
        """
        pass

    def get_register_context(self):
        pass

    def get_stop_reason(self):
        pass