summaryrefslogtreecommitdiff
path: root/lldb/examples
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/examples')
-rw-r--r--lldb/examples/python/cmdtemplate.py10
-rw-r--r--lldb/examples/python/templates/parsed_cmd.py57
-rw-r--r--lldb/examples/python/templates/scripted_process.py136
3 files changed, 190 insertions, 13 deletions
diff --git a/lldb/examples/python/cmdtemplate.py b/lldb/examples/python/cmdtemplate.py
index a9fbe0b40e19..be4c2da53ee0 100644
--- a/lldb/examples/python/cmdtemplate.py
+++ b/lldb/examples/python/cmdtemplate.py
@@ -74,6 +74,11 @@ class FrameStatCommand(ParsedCommand):
dest = "statics",
default = True,
)
+ ov_parser.add_option(
+ "t",
+ "test-flag",
+ help="test a flag value.",
+ )
def get_repeat_command(self, args):
"""As an example, make the command not auto-repeat:"""
@@ -123,6 +128,11 @@ class FrameStatCommand(ParsedCommand):
% (variables_count, total_size, average_size),
file=result,
)
+ if ov_parser.was_set("test-flag"):
+ print("Got the test flag")
+ else:
+ print("Got no test flag")
+
# not returning anything is akin to returning success
diff --git a/lldb/examples/python/templates/parsed_cmd.py b/lldb/examples/python/templates/parsed_cmd.py
index 13d6eae405c0..c1baad3ffd24 100644
--- a/lldb/examples/python/templates/parsed_cmd.py
+++ b/lldb/examples/python/templates/parsed_cmd.py
@@ -241,12 +241,18 @@ class LLDBOptionValueParser:
starts, you can override this to handle your special option. """
for key, elem in self.options_dict.items():
elem['_value_set'] = False
+ # If there's no value_type, then there can't be a dest.
+ if not "value_type" in elem:
+ continue
+
try:
object.__setattr__(self, elem["dest"], elem["default"])
except AttributeError:
# It isn't an error not to have a "dest" variable name, you'll
# just have to manage this option's value on your own.
continue
+ except KeyError:
+ continue
def set_enum_value(self, enum_values, input):
""" This sets the value for an enum option, you should not have to call this
@@ -271,7 +277,13 @@ class LLDBOptionValueParser:
elem = self.get_option_element(opt_name)
if not elem:
return False
-
+
+ # If there's no value_type in element, then it has no value, so just mark
+ # it set and return:
+ if not "value_type" in elem:
+ elem["_value_set"] = True
+ return True
+
if "enum_values" in elem:
(value, error) = self.set_enum_value(elem["enum_values"], opt_value)
else:
@@ -312,10 +324,19 @@ class LLDBOptionValueParser:
value = self.__dict__[elem["dest"]]
return value
- def add_option(self, short_option, long_option, help, default,
- dest = None, required=False, groups = None,
- value_type=lldb.eArgTypeNone, completion_type=None,
- enum_values=None):
+ def add_option(
+ self,
+ short_option,
+ long_option,
+ help,
+ default=None,
+ dest=None,
+ required=False,
+ groups=None,
+ value_type=None,
+ completion_type=None,
+ enum_values=None,
+ ):
"""
short_option: one character, must be unique, not required
long_option: no spaces, must be unique, required
@@ -340,17 +361,27 @@ class LLDBOptionValueParser:
if not completion_type:
completion_type = self.determine_completion(value_type)
-
- dict = {"short_option" : short_option,
- "required" : required,
- "help" : help,
- "value_type" : value_type,
- "completion_type" : completion_type,
- "dest" : dest,
- "default" : default}
+
+ dict = {
+ "short_option": short_option,
+ "required": required,
+ "help": help,
+ }
if enum_values:
+ if not value_type:
+ print("I am setting value type for an enum value")
+ value_type = lldb.eArgTypeNone
+ else:
+ print(f"An enum value had a type: {value_type}")
dict["enum_values"] = enum_values
+
+ if value_type:
+ dict["value_type"] = value_type
+ dict["completion_type"] = completion_type
+ dict["dest"] = dest
+ dict["default"] = default
+
if groups:
dict["groups"] = groups
diff --git a/lldb/examples/python/templates/scripted_process.py b/lldb/examples/python/templates/scripted_process.py
index b6360b851907..49059d533f38 100644
--- a/lldb/examples/python/templates/scripted_process.py
+++ b/lldb/examples/python/templates/scripted_process.py
@@ -383,6 +383,142 @@ class ScriptedThread(metaclass=ABCMeta):
"""
return self.extended_info
+ def get_scripted_frame_plugin(self):
+ """Get scripted frame plugin name.
+
+ Returns:
+ str: Name of the scripted frame plugin.
+ """
+ return None
+
+
+class ScriptedFrame(metaclass=ABCMeta):
+ """
+ The base class for a scripted frame.
+
+ Most of the base class methods are `@abstractmethod` that need to be
+ overwritten by the inheriting class.
+ """
+
+ @abstractmethod
+ def __init__(self, thread, args):
+ """Construct a scripted frame.
+
+ Args:
+ thread (ScriptedThread): The thread owning this frame.
+ args (lldb.SBStructuredData): A Dictionary holding arbitrary
+ key/value pairs used by the scripted frame.
+ """
+ self.target = None
+ self.originating_thread = None
+ self.thread = None
+ self.args = None
+ self.id = None
+ self.name = None
+ self.register_info = None
+ self.register_ctx = {}
+ self.variables = []
+
+ if (
+ isinstance(thread, ScriptedThread)
+ or isinstance(thread, lldb.SBThread)
+ and thread.IsValid()
+ ):
+ self.target = thread.target
+ self.process = thread.process
+ self.originating_thread = thread
+ self.thread = self.process.GetThreadByIndexID(thread.tid)
+ self.get_register_info()
+
+ @abstractmethod
+ def get_id(self):
+ """Get the scripted frame identifier.
+
+ Returns:
+ int: The identifier of the scripted frame in the scripted thread.
+ """
+ pass
+
+ def get_pc(self):
+ """Get the scripted frame address.
+
+ Returns:
+ int: The optional address of the scripted frame in the scripted thread.
+ """
+ return None
+
+ def get_symbol_context(self):
+ """Get the scripted frame symbol context.
+
+ Returns:
+ lldb.SBSymbolContext: The symbol context of the scripted frame in the scripted thread.
+ """
+ return None
+
+ def is_inlined(self):
+ """Check if the scripted frame is inlined.
+
+ Returns:
+ bool: True if scripted frame is inlined. False otherwise.
+ """
+ return False
+
+ def is_artificial(self):
+ """Check if the scripted frame is artificial.
+
+ Returns:
+ bool: True if scripted frame is artificial. False otherwise.
+ """
+ return True
+
+ def is_hidden(self):
+ """Check if the scripted frame is hidden.
+
+ Returns:
+ bool: True if scripted frame is hidden. False otherwise.
+ """
+ return False
+
+ def get_function_name(self):
+ """Get the scripted frame function name.
+
+ Returns:
+ str: The function name of the scripted frame.
+ """
+ return self.name
+
+ def get_display_function_name(self):
+ """Get the scripted frame display function name.
+
+ Returns:
+ str: The display function name of the scripted frame.
+ """
+ return self.get_function_name()
+
+ def get_variables(self, filters):
+ """Get the scripted thread state type.
+
+ Args:
+ filter (lldb.SBVariablesOptions): The filter used to resolve the variables
+ Returns:
+ lldb.SBValueList: The SBValueList containing the SBValue for each resolved variable.
+ Returns None by default.
+ """
+ return None
+
+ def get_register_info(self):
+ if self.register_info is None:
+ self.register_info = self.originating_thread.get_register_info()
+ return self.register_info
+
+ @abstractmethod
+ def get_register_context(self):
+ """Get the scripted thread register context
+
+ Returns:
+ str: A byte representing all register's value.
+ """
+ pass
class PassthroughScriptedProcess(ScriptedProcess):
driving_target = None