diff options
author | Matt Valentine-House <matt@eightbitraptor.com> | 2023-02-22 19:26:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-22 14:26:28 -0500 |
commit | 220cdbeea52c4681fb0ba52d24e5b28a0b877e0f (patch) | |
tree | f670b47822009b3d41f377e0ac0fbaab7116b4e2 /misc | |
parent | 4edb2a29f67957fc7027eaad0c08e8003cfde609 (diff) |
[lldb] Add a print_flags command (#7358)
Notes
Notes:
Merged-By: peterzhu2118 <peter@peterzhu.ca>
Diffstat (limited to 'misc')
-rw-r--r-- | misc/lldb_rb/commands/print_flags_command.py | 31 | ||||
-rw-r--r-- | misc/lldb_rb/rb_base_command.py | 5 |
2 files changed, 33 insertions, 3 deletions
diff --git a/misc/lldb_rb/commands/print_flags_command.py b/misc/lldb_rb/commands/print_flags_command.py new file mode 100644 index 0000000000..00da4834bf --- /dev/null +++ b/misc/lldb_rb/commands/print_flags_command.py @@ -0,0 +1,31 @@ +import lldb +import re + +from lldb_rb.constants import * +from lldb_rb.rb_base_command import RbBaseCommand + +class PrintFlagsCommand(RbBaseCommand): + program = "print_flags" + + help_string = "Print out the individial flags of an RVALUE object in human readable format" + + # call is where our command logic will be implemented + def call(self, debugger, command, exe_ctx, result): + rclass_t = self.target.FindFirstType("struct RBasic") + rcass_ptr = self.target.EvaluateExpression(command).Cast(rclass_t.GetPointerType()) + obj_flags = rcass_ptr.GetValueForExpressionPath("->flags").GetValueAsUnsigned() + + flags = [ + "RUBY_FL_WB_PROTECTED", "RUBY_FL_PROMOTED0", "RUBY_FL_PROMOTED1", "RUBY_FL_FINALIZE", + "RUBY_FL_SHAREABLE", "RUBY_FL_EXIVAR", "RUBY_FL_FREEZE", + "RUBY_FL_USER0", "RUBY_FL_USER1", "RUBY_FL_USER2", "RUBY_FL_USER3", "RUBY_FL_USER4", + "RUBY_FL_USER5", "RUBY_FL_USER6", "RUBY_FL_USER7", "RUBY_FL_USER8", "RUBY_FL_USER9", + "RUBY_FL_USER10", "RUBY_FL_USER11", "RUBY_FL_USER12", "RUBY_FL_USER13", "RUBY_FL_USER14", + "RUBY_FL_USER15", "RUBY_FL_USER16", "RUBY_FL_USER17", "RUBY_FL_USER18" + ] + + types_index = {v: k for k, v in self.ruby_globals.items() if re.match(r'RUBY_T_', k)} + print("TYPE: {}".format(types_index[obj_flags & self.ruby_globals["RUBY_T_MASK"]])) + for flag in flags: + output = "{} : {}".format(flag, "1" if (obj_flags & self.ruby_globals[flag]) else "0") + print(output, file=result) diff --git a/misc/lldb_rb/rb_base_command.py b/misc/lldb_rb/rb_base_command.py index de90a1617c..dd58d59b97 100644 --- a/misc/lldb_rb/rb_base_command.py +++ b/misc/lldb_rb/rb_base_command.py @@ -34,14 +34,13 @@ class RbBaseCommand: if name.startswith("RUBY_T_"): value_types.append(name) g["value_types"] = value_types + return g def __init__(self, debugger, _internal_dict): + self.ruby_globals = RbBaseCommand.lldb_init(debugger) self.internal_dict = _internal_dict def __call__(self, debugger, command, exe_ctx, result): - if not ("RUBY_Qfalse" in globals()): - RbBaseCommand.lldb_init(debugger) - self.build_environment(debugger) self.call(debugger, command, exe_ctx, result) |