From ec456ba9ca0a097da63daafbb031cb2024f5513a Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Mon, 23 Oct 2023 15:42:59 -0700 Subject: [lldb] Add OperatingSystem base class to the lldb python module This patch introduces an `OperatingSystem` base implementation in the `lldb` python module to make it easier for lldb users to write their own implementation. The `OperatingSystem` base implementation is derived itself from the `ScriptedThread` base implementation since they share some common grounds. To achieve that, this patch makes changes to the `ScriptedThread` initializer since it gets called by the `OperatingSystem` initializer. I also took the opportunity to document the `OperatingSystem` base class and methods. Differential Revision: https://reviews.llvm.org/D159315 Signed-off-by: Med Ismail Bennani --- .../plugins/python_os_plugin/operating_system.py | 40 +++------------------- 1 file changed, 4 insertions(+), 36 deletions(-) (limited to 'lldb/test/API/functionalities/plugins/python_os_plugin') diff --git a/lldb/test/API/functionalities/plugins/python_os_plugin/operating_system.py b/lldb/test/API/functionalities/plugins/python_os_plugin/operating_system.py index 52c678fac2ef..f4404d78492f 100644 --- a/lldb/test/API/functionalities/plugins/python_os_plugin/operating_system.py +++ b/lldb/test/API/functionalities/plugins/python_os_plugin/operating_system.py @@ -1,29 +1,14 @@ -#!/usr/bin/env python - import lldb import struct +from lldb.plugins.operating_system import OperatingSystem + -class OperatingSystemPlugIn(object): +class OperatingSystemPlugIn(OperatingSystem): """Class that provides data for an instance of a LLDB 'OperatingSystemPython' plug-in class""" def __init__(self, process): - """Initialization needs a valid.SBProcess object. - - This plug-in will get created after a live process is valid and has stopped for the - first time.""" - self.process = None - self.registers = None - self.threads = None - if isinstance(process, lldb.SBProcess) and process.IsValid(): - self.process = process - self.threads = None # Will be an dictionary containing info for each thread - - def get_target(self): - # NOTE: Don't use "lldb.target" when trying to get your target as the "lldb.target" - # tracks the current target in the LLDB command interpreter which isn't the - # correct thing to use for this plug-in. - return self.process.target + super().__init__(process) def create_thread(self, tid, context): if tid == 0x444444444: @@ -40,23 +25,6 @@ class OperatingSystemPlugIn(object): def get_thread_info(self): if not self.threads: - # The sample dictionary below shows the values that can be returned for a thread - # tid => thread ID (mandatory) - # name => thread name (optional key/value pair) - # queue => thread dispatch queue name (optional key/value pair) - # state => thred state (mandatory, set to 'stopped' for now) - # stop_reason => thread stop reason. (mandatory, usually set to 'none') - # Possible values include: - # 'breakpoint' if the thread is stopped at a breakpoint - # 'none' thread is just stopped because the process is stopped - # 'trace' the thread just single stepped - # 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. self.threads = [ { "tid": 0x111111111, -- cgit v1.2.3