File: print_flags_command.py

package info (click to toggle)
ruby3.4 3.4.5-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 154,784 kB
  • sloc: ruby: 1,259,653; ansic: 829,955; yacc: 28,233; pascal: 7,359; sh: 3,864; python: 1,799; cpp: 1,158; asm: 808; makefile: 801; javascript: 414; lisp: 109; perl: 62; awk: 36; sed: 4; xml: 4
file content (31 lines) | stat: -rw-r--r-- 1,555 bytes parent folder | download | duplicates (2)
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
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)