Skip to content

Commit

Permalink
Add dump_op_array command
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-lb committed Jan 20, 2025
1 parent 10f08a7 commit d36624a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
28 changes: 25 additions & 3 deletions main/debug_gdb_scripts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ asm(
".ascii \" def __init__ (self, type):\\n\"\n"
".ascii \" self.type = type\\n\"\n"
".ascii \" name = 'print_%s_flags' % type\\n\"\n"
".ascii \" super(PrintAccFlagsCommand, self).__init__(name, gdb.COMMAND_USER)\\n\"\n"
".ascii \" super(PrintAccFlagsCommand, self).__init__(name, gdb.COMMAND_USER, gdb.COMPLETE_EXPRESSION)\\n\"\n"
".ascii \"\\n\"\n"
".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
".ascii \" arg = int(gdb.parse_and_eval(arg))\\n\"\n"
Expand All @@ -1219,7 +1219,7 @@ asm(
".ascii \" \\\"Pretty print opcode\\\"\\n\"\n"
".ascii \"\\n\"\n"
".ascii \" def __init__ (self):\\n\"\n"
".ascii \" super(PrintOpcodeCommand, self).__init__(\\\"print_opcode\\\", gdb.COMMAND_USER)\\n\"\n"
".ascii \" super(PrintOpcodeCommand, self).__init__(\\\"print_opcode\\\", gdb.COMMAND_USER, gdb.COMPLETE_EXPRESSION)\\n\"\n"
".ascii \"\\n\"\n"
".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
".ascii \" arg = int(gdb.parse_and_eval(arg))\\n\"\n"
Expand All @@ -1231,14 +1231,36 @@ asm(
".ascii \" \\\"Pretty print zend_refcounted.gc.u.type_info\\\"\\n\"\n"
".ascii \"\\n\"\n"
".ascii \" def __init__ (self):\\n\"\n"
".ascii \" super(PrintRefTypeInfoCommand, self).__init__(\\\"print_ref_type_info\\\", gdb.COMMAND_USER)\\n\"\n"
".ascii \" super(PrintRefTypeInfoCommand, self).__init__(\\\"print_ref_type_info\\\", gdb.COMMAND_USER, gdb.COMPLETE_EXPRESSION)\\n\"\n"
".ascii \"\\n\"\n"
".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
".ascii \" arg = int(gdb.parse_and_eval(arg))\\n\"\n"
".ascii \" print(ZendRefTypeInfo.format(arg))\\n\"\n"
".ascii \"\\n\"\n"
".ascii \"PrintRefTypeInfoCommand()\\n\"\n"
".ascii \"\\n\"\n"
".ascii \"class DumpOpArrayCommand(gdb.Command):\\n\"\n"
".ascii \" \\\"Dump an op_array\\\"\\n\"\n"
".ascii \"\\n\"\n"
".ascii \" def __init__ (self):\\n\"\n"
".ascii \" super(DumpOpArrayCommand, self).__init__(\\\"dump_op_array\\\", gdb.COMMAND_USER, gdb.COMPLETE_EXPRESSION)\\n\"\n"
".ascii \"\\n\"\n"
".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
".ascii \" op_array = gdb.parse_and_eval(arg)\\n\"\n"
".ascii \" if op_array.type.code != gdb.TYPE_CODE_PTR:\\n\"\n"
".ascii \" print(\\\"Must pass a zend_op_array* (got a %s)\\\" % op_array.type)\\n\"\n"
".ascii \" return\\n\"\n"
".ascii \" if str(gdb.types.get_basic_type(op_array.type.target())) != 'struct _zend_op_array':\\n\"\n"
".ascii \" print(\\\"Must pass a zend_op_array* (got a %s)\\\" % op_array.type)\\n\"\n"
".ascii \" return\\n\"\n"
".ascii \" if int(op_array) == 0:\\n\"\n"
".ascii \" print(\\\"NULL\\\")\\n\"\n"
".ascii \" return\\n\"\n"
".ascii \" gdb.execute(\\\"call zend_dump_op_array((zend_op_array*)0x%x, 0, 0, 0)\\\" % (int(op_array)))\\n\"\n"
".ascii \" return\\n\"\n"
".ascii \"\\n\"\n"
".ascii \"DumpOpArrayCommand()\\n\"\n"
".ascii \"\\n\"\n"
".ascii \"class ZendTypeBits:\\n\"\n"
".ascii \" _bits = None\\n\"\n"
".ascii \"\\n\"\n"
Expand Down
28 changes: 25 additions & 3 deletions scripts/gdb/php_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ class PrintAccFlagsCommand(gdb.Command):
def __init__ (self, type):
self.type = type
name = 'print_%s_flags' % type
super(PrintAccFlagsCommand, self).__init__(name, gdb.COMMAND_USER)
super(PrintAccFlagsCommand, self).__init__(name, gdb.COMMAND_USER, gdb.COMPLETE_EXPRESSION)

def invoke (self, arg, from_tty):
arg = int(gdb.parse_and_eval(arg))
Expand All @@ -549,7 +549,7 @@ class PrintOpcodeCommand(gdb.Command):
"Pretty print opcode"

def __init__ (self):
super(PrintOpcodeCommand, self).__init__("print_opcode", gdb.COMMAND_USER)
super(PrintOpcodeCommand, self).__init__("print_opcode", gdb.COMMAND_USER, gdb.COMPLETE_EXPRESSION)

def invoke (self, arg, from_tty):
arg = int(gdb.parse_and_eval(arg))
Expand All @@ -561,14 +561,36 @@ class PrintRefTypeInfoCommand(gdb.Command):
"Pretty print zend_refcounted.gc.u.type_info"

def __init__ (self):
super(PrintRefTypeInfoCommand, self).__init__("print_ref_type_info", gdb.COMMAND_USER)
super(PrintRefTypeInfoCommand, self).__init__("print_ref_type_info", gdb.COMMAND_USER, gdb.COMPLETE_EXPRESSION)

def invoke (self, arg, from_tty):
arg = int(gdb.parse_and_eval(arg))
print(ZendRefTypeInfo.format(arg))

PrintRefTypeInfoCommand()

class DumpOpArrayCommand(gdb.Command):
"Dump an op_array"

def __init__ (self):
super(DumpOpArrayCommand, self).__init__("dump_op_array", gdb.COMMAND_USER, gdb.COMPLETE_EXPRESSION)

def invoke (self, arg, from_tty):
op_array = gdb.parse_and_eval(arg)
if op_array.type.code != gdb.TYPE_CODE_PTR:
print("Must pass a zend_op_array* (got a %s)" % op_array.type)
return
if str(gdb.types.get_basic_type(op_array.type.target())) != 'struct _zend_op_array':
print("Must pass a zend_op_array* (got a %s)" % op_array.type)
return
if int(op_array) == 0:
print("NULL")
return
gdb.execute("call zend_dump_op_array((zend_op_array*)0x%x, 0, 0, 0)" % (int(op_array)))
return

DumpOpArrayCommand()

class ZendTypeBits:
_bits = None

Expand Down

0 comments on commit d36624a

Please sign in to comment.