Skip to content

Commit 8581c69

Browse files
committed
replace match statements with if statements in gdb debug script so it works with lower GDB versions
1 parent 0943b8b commit 8581c69

File tree

2 files changed

+120
-130
lines changed

2 files changed

+120
-130
lines changed

main/debug_gdb_scripts.c

Lines changed: 60 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -782,28 +782,27 @@ asm(
782782
".ascii \" for bit in range(0, type_mask_size):\\n\"\n"
783783
".ascii \" if type_mask & (1 << bit):\\n\"\n"
784784
".ascii \" type_name = ZendTypeBits.zendTypeName(bit)\\n\"\n"
785-
".ascii \" match type_name:\\n\"\n"
786-
".ascii \" case None:\\n\"\n"
787-
".ascii \" parts.append('(1<<%d)' % bit)\\n\"\n"
788-
".ascii \" case 'list':\\n\"\n"
789-
".ascii \" list = t['ptr'].cast(gdb.lookup_type('zend_type_list').pointer())\\n\"\n"
790-
".ascii \" num_types = int(list['num_types'])\\n\"\n"
791-
".ascii \" types = list['types'].dereference().cast(gdb.lookup_type('zend_type').array(num_types))\\n\"\n"
792-
".ascii \" for i in range(0, num_types):\\n\"\n"
793-
".ascii \" str = self.format_type(types[i])\\n\"\n"
794-
".ascii \" if any((c in set('|&()')) for c in str):\\n\"\n"
795-
".ascii \" str = '(%s)' % str\\n\"\n"
796-
".ascii \" parts.append(str)\\n\"\n"
797-
".ascii \" case 'union' | 'arena':\\n\"\n"
798-
".ascii \" meta.append(type_name)\\n\"\n"
799-
".ascii \" case 'intersection':\\n\"\n"
800-
".ascii \" meta.append(type_name)\\n\"\n"
801-
".ascii \" separator = '&'\\n\"\n"
802-
".ascii \" case 'name':\\n\"\n"
803-
".ascii \" str = t['ptr'].cast(gdb.lookup_type('zend_string').pointer())\\n\"\n"
804-
".ascii \" parts.append(format_zstr(str))\\n\"\n"
805-
".ascii \" case _:\\n\"\n"
806-
".ascii \" parts.append(type_name)\\n\"\n"
785+
".ascii \" if type_name is None:\\n\"\n"
786+
".ascii \" parts.append('(1<<%d)' % bit)\\n\"\n"
787+
".ascii \" elif type_name == 'list':\\n\"\n"
788+
".ascii \" list_ptr = t['ptr'].cast(gdb.lookup_type('zend_type_list').pointer())\\n\"\n"
789+
".ascii \" num_types = int(list_ptr['num_types'])\\n\"\n"
790+
".ascii \" types = list_ptr['types'].dereference().cast(gdb.lookup_type('zend_type').array(num_types))\\n\"\n"
791+
".ascii \" for i in range(0, num_types):\\n\"\n"
792+
".ascii \" type_str = self.format_type(types[i])\\n\"\n"
793+
".ascii \" if any((c in set('|&()')) for c in type_str):\\n\"\n"
794+
".ascii \" type_str = '(%s)' % type_str\\n\"\n"
795+
".ascii \" parts.append(type_str)\\n\"\n"
796+
".ascii \" elif type_name == 'union' or type_name == 'arena':\\n\"\n"
797+
".ascii \" meta.append(type_name)\\n\"\n"
798+
".ascii \" elif type_name == 'intersection':\\n\"\n"
799+
".ascii \" meta.append(type_name)\\n\"\n"
800+
".ascii \" separator = '&'\\n\"\n"
801+
".ascii \" elif type_name == 'name':\\n\"\n"
802+
".ascii \" name_str = t['ptr'].cast(gdb.lookup_type('zend_string').pointer())\\n\"\n"
803+
".ascii \" parts.append(format_zstr(name_str))\\n\"\n"
804+
".ascii \" else:\\n\"\n"
805+
".ascii \" parts.append(type_name)\\n\"\n"
807806
".ascii \"\\n\"\n"
808807
".ascii \" str = separator.join(parts)\\n\"\n"
809808
".ascii \"\\n\"\n"
@@ -1073,15 +1072,15 @@ asm(
10731072
".ascii \" self.val = val\\n\"\n"
10741073
".ascii \"\\n\"\n"
10751074
".ascii \" def to_string(self):\\n\"\n"
1076-
".ascii \" match int(self.val['type']):\\n\"\n"
1077-
".ascii \" case ZendFnTypes.ZEND_INTERNAL_FUNCTION:\\n\"\n"
1078-
".ascii \" typestr = 'internal'\\n\"\n"
1079-
".ascii \" case ZendFnTypes.ZEND_USER_FUNCTION:\\n\"\n"
1080-
".ascii \" typestr = 'user'\\n\"\n"
1081-
".ascii \" case ZendFnTypes.ZEND_EVAL_CODE:\\n\"\n"
1082-
".ascii \" typestr = 'eval'\\n\"\n"
1083-
".ascii \" case _:\\n\"\n"
1084-
".ascii \" typestr = '\?\?\?'\\n\"\n"
1075+
".ascii \" val_type = int(self.val['type'])\\n\"\n"
1076+
".ascii \" if val_type == ZendFnTypes.ZEND_INTERNAL_FUNCTION:\\n\"\n"
1077+
".ascii \" typestr = 'internal'\\n\"\n"
1078+
".ascii \" elif val_type == ZendFnTypes.ZEND_USER_FUNCTION:\\n\"\n"
1079+
".ascii \" typestr = 'user'\\n\"\n"
1080+
".ascii \" elif val_type == ZendFnTypes.ZEND_EVAL_CODE:\\n\"\n"
1081+
".ascii \" typestr = 'eval'\\n\"\n"
1082+
".ascii \" else:\\n\"\n"
1083+
".ascii \" typestr = '\?\?\?'\\n\"\n"
10851084
".ascii \"\\n\"\n"
10861085
".ascii \" if self.val['common']['function_name']:\\n\"\n"
10871086
".ascii \" namestr = format_zstr(self.val['common']['function_name'])\\n\"\n"
@@ -1501,13 +1500,12 @@ asm(
15011500
".ascii \"\\n\"\n"
15021501
".ascii \" bits = self._bits\\n\"\n"
15031502
".ascii \" type_bits = None\\n\"\n"
1504-
".ascii \" match type_name:\\n\"\n"
1505-
".ascii \" case 'string':\\n\"\n"
1506-
".ascii \" type_bits = self._str_bits\\n\"\n"
1507-
".ascii \" case 'array':\\n\"\n"
1508-
".ascii \" type_bits = self._array_bits\\n\"\n"
1509-
".ascii \" case 'object':\\n\"\n"
1510-
".ascii \" type_bits = self._obj_bits\\n\"\n"
1503+
".ascii \" if type_name == 'string':\\n\"\n"
1504+
".ascii \" type_bits = self._str_bits\\n\"\n"
1505+
".ascii \" elif type_name == 'array':\\n\"\n"
1506+
".ascii \" type_bits = self._array_bits\\n\"\n"
1507+
".ascii \" elif type_name == 'object':\\n\"\n"
1508+
".ascii \" type_bits = self._obj_bits\\n\"\n"
15111509
".ascii \"\\n\"\n"
15121510
".ascii \" type_flags = flags & self._flags_mask\\n\"\n"
15131511
".ascii \" for i in range(0, 31):\\n\"\n"
@@ -1530,15 +1528,14 @@ asm(
15301528
".ascii \"\\n\"\n"
15311529
".ascii \" if (flags & (1<<self.bit('GC_NOT_COLLECTABLE'))) == 0:\\n\"\n"
15321530
".ascii \" gc_color = (flags >> self._info_shift) & self._gc_color\\n\"\n"
1533-
".ascii \" match gc_color:\\n\"\n"
1534-
".ascii \" case self._gc_black:\\n\"\n"
1535-
".ascii \" names.append('GC_BLACK')\\n\"\n"
1536-
".ascii \" case self._gc_white:\\n\"\n"
1537-
".ascii \" names.append('GC_WHITE')\\n\"\n"
1538-
".ascii \" case self._gc_grey:\\n\"\n"
1539-
".ascii \" names.append('GC_GREY')\\n\"\n"
1540-
".ascii \" case self._gc_purple:\\n\"\n"
1541-
".ascii \" names.append('GC_PURPLE')\\n\"\n"
1531+
".ascii \" if gc_color == self._gc_black:\\n\"\n"
1532+
".ascii \" names.append('GC_BLACK')\\n\"\n"
1533+
".ascii \" elif gc_color == self._gc_white:\\n\"\n"
1534+
".ascii \" names.append('GC_WHITE')\\n\"\n"
1535+
".ascii \" elif gc_color == self._gc_grey:\\n\"\n"
1536+
".ascii \" names.append('GC_GREY')\\n\"\n"
1537+
".ascii \" elif gc_color == self._gc_purple:\\n\"\n"
1538+
".ascii \" names.append('GC_PURPLE')\\n\"\n"
15421539
".ascii \"\\n\"\n"
15431540
".ascii \" gc_address = (flags >> self._info_shift) & self._gc_address\\n\"\n"
15441541
".ascii \" if gc_address != 0:\\n\"\n"
@@ -1577,17 +1574,16 @@ asm(
15771574
".ascii \" pattern = re.compile(r'#define (GC_[^\\\\s]+)\\\\s+((0x)\?[0-9a-f]+)')\\n\"\n"
15781575
".ascii \" matches = pattern.findall(content)\\n\"\n"
15791576
".ascii \" for name, bit, _ in matches:\\n\"\n"
1580-
".ascii \" match name:\\n\"\n"
1581-
".ascii \" case 'GC_TYPE_MASK':\\n\"\n"
1582-
".ascii \" self._type_mask = int(bit, 0)\\n\"\n"
1583-
".ascii \" case 'GC_FLAGS_MASK':\\n\"\n"
1584-
".ascii \" self._flags_mask = int(bit, 0)\\n\"\n"
1585-
".ascii \" case 'GC_INFO_MASK':\\n\"\n"
1586-
".ascii \" self._info_mask = int(bit, 0)\\n\"\n"
1587-
".ascii \" case 'GC_INFO_SHIFT':\\n\"\n"
1588-
".ascii \" self._info_shift = int(bit, 0)\\n\"\n"
1589-
".ascii \" case 'GC_FLAGS_SHIFT':\\n\"\n"
1590-
".ascii \" self._flags_shift = int(bit, 0)\\n\"\n"
1577+
".ascii \" if name == 'GC_TYPE_MASK':\\n\"\n"
1578+
".ascii \" self._type_mask = int(bit, 0)\\n\"\n"
1579+
".ascii \" elif name == 'GC_FLAGS_MASK':\\n\"\n"
1580+
".ascii \" self._flags_mask = int(bit, 0)\\n\"\n"
1581+
".ascii \" elif name == 'GC_INFO_MASK':\\n\"\n"
1582+
".ascii \" self._info_mask = int(bit, 0)\\n\"\n"
1583+
".ascii \" elif name == 'GC_INFO_SHIFT':\\n\"\n"
1584+
".ascii \" self._info_shift = int(bit, 0)\\n\"\n"
1585+
".ascii \" elif name == 'GC_FLAGS_SHIFT':\\n\"\n"
1586+
".ascii \" self._flags_shift = int(bit, 0)\\n\"\n"
15911587
".ascii \"\\n\"\n"
15921588
".ascii \" # IS_STR_INTERNED GC_IMMUTABLE\\n\"\n"
15931589
".ascii \" # IS_STR_PERMANENT (1<<8)\\n\"\n"
@@ -1598,13 +1594,12 @@ asm(
15981594
".ascii \" bit = bits.get(val)\\n\"\n"
15991595
".ascii \" if bit == None:\\n\"\n"
16001596
".ascii \" continue\\n\"\n"
1601-
".ascii \" match type:\\n\"\n"
1602-
".ascii \" case 'STR':\\n\"\n"
1603-
".ascii \" target = str_bits\\n\"\n"
1604-
".ascii \" case 'ARRAY':\\n\"\n"
1605-
".ascii \" target = array_bits\\n\"\n"
1606-
".ascii \" case 'OBJ':\\n\"\n"
1607-
".ascii \" target = obj_bits\\n\"\n"
1597+
".ascii \" if type == 'STR':\\n\"\n"
1598+
".ascii \" target = str_bits\\n\"\n"
1599+
".ascii \" elif type == 'ARRAY':\\n\"\n"
1600+
".ascii \" target = array_bits\\n\"\n"
1601+
".ascii \" elif type == 'OBJ':\\n\"\n"
1602+
".ascii \" target = obj_bits\\n\"\n"
16081603
".ascii \" target[name] = int(bit)\\n\"\n"
16091604
".ascii \"\\n\"\n"
16101605
".ascii \" # Hard coded because these are not exposed in header files\\n\"\n"

scripts/gdb/php_gdb.py

Lines changed: 60 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -112,28 +112,27 @@ def format_type(self, t):
112112
for bit in range(0, type_mask_size):
113113
if type_mask & (1 << bit):
114114
type_name = ZendTypeBits.zendTypeName(bit)
115-
match type_name:
116-
case None:
117-
parts.append('(1<<%d)' % bit)
118-
case 'list':
119-
list = t['ptr'].cast(gdb.lookup_type('zend_type_list').pointer())
120-
num_types = int(list['num_types'])
121-
types = list['types'].dereference().cast(gdb.lookup_type('zend_type').array(num_types))
122-
for i in range(0, num_types):
123-
str = self.format_type(types[i])
124-
if any((c in set('|&()')) for c in str):
125-
str = '(%s)' % str
126-
parts.append(str)
127-
case 'union' | 'arena':
128-
meta.append(type_name)
129-
case 'intersection':
130-
meta.append(type_name)
131-
separator = '&'
132-
case 'name':
133-
str = t['ptr'].cast(gdb.lookup_type('zend_string').pointer())
134-
parts.append(format_zstr(str))
135-
case _:
136-
parts.append(type_name)
115+
if type_name is None:
116+
parts.append('(1<<%d)' % bit)
117+
elif type_name == 'list':
118+
list_ptr = t['ptr'].cast(gdb.lookup_type('zend_type_list').pointer())
119+
num_types = int(list_ptr['num_types'])
120+
types = list_ptr['types'].dereference().cast(gdb.lookup_type('zend_type').array(num_types))
121+
for i in range(0, num_types):
122+
type_str = self.format_type(types[i])
123+
if any((c in set('|&()')) for c in type_str):
124+
type_str = '(%s)' % type_str
125+
parts.append(type_str)
126+
elif type_name == 'union' or type_name == 'arena':
127+
meta.append(type_name)
128+
elif type_name == 'intersection':
129+
meta.append(type_name)
130+
separator = '&'
131+
elif type_name == 'name':
132+
name_str = t['ptr'].cast(gdb.lookup_type('zend_string').pointer())
133+
parts.append(format_zstr(name_str))
134+
else:
135+
parts.append(type_name)
137136

138137
str = separator.join(parts)
139138

@@ -403,15 +402,15 @@ def __init__(self, val):
403402
self.val = val
404403

405404
def to_string(self):
406-
match int(self.val['type']):
407-
case ZendFnTypes.ZEND_INTERNAL_FUNCTION:
408-
typestr = 'internal'
409-
case ZendFnTypes.ZEND_USER_FUNCTION:
410-
typestr = 'user'
411-
case ZendFnTypes.ZEND_EVAL_CODE:
412-
typestr = 'eval'
413-
case _:
414-
typestr = '???'
405+
val_type = int(self.val['type'])
406+
if val_type == ZendFnTypes.ZEND_INTERNAL_FUNCTION:
407+
typestr = 'internal'
408+
elif val_type == ZendFnTypes.ZEND_USER_FUNCTION:
409+
typestr = 'user'
410+
elif val_type == ZendFnTypes.ZEND_EVAL_CODE:
411+
typestr = 'eval'
412+
else:
413+
typestr = '???'
415414

416415
if self.val['common']['function_name']:
417416
namestr = format_zstr(self.val['common']['function_name'])
@@ -831,13 +830,12 @@ def format(self, flags):
831830

832831
bits = self._bits
833832
type_bits = None
834-
match type_name:
835-
case 'string':
836-
type_bits = self._str_bits
837-
case 'array':
838-
type_bits = self._array_bits
839-
case 'object':
840-
type_bits = self._obj_bits
833+
if type_name == 'string':
834+
type_bits = self._str_bits
835+
elif type_name == 'array':
836+
type_bits = self._array_bits
837+
elif type_name == 'object':
838+
type_bits = self._obj_bits
841839

842840
type_flags = flags & self._flags_mask
843841
for i in range(0, 31):
@@ -860,15 +858,14 @@ def format(self, flags):
860858

861859
if (flags & (1<<self.bit('GC_NOT_COLLECTABLE'))) == 0:
862860
gc_color = (flags >> self._info_shift) & self._gc_color
863-
match gc_color:
864-
case self._gc_black:
865-
names.append('GC_BLACK')
866-
case self._gc_white:
867-
names.append('GC_WHITE')
868-
case self._gc_grey:
869-
names.append('GC_GREY')
870-
case self._gc_purple:
871-
names.append('GC_PURPLE')
861+
if gc_color == self._gc_black:
862+
names.append('GC_BLACK')
863+
elif gc_color == self._gc_white:
864+
names.append('GC_WHITE')
865+
elif gc_color == self._gc_grey:
866+
names.append('GC_GREY')
867+
elif gc_color == self._gc_purple:
868+
names.append('GC_PURPLE')
872869

873870
gc_address = (flags >> self._info_shift) & self._gc_address
874871
if gc_address != 0:
@@ -907,17 +904,16 @@ def _load(self):
907904
pattern = re.compile(r'#define (GC_[^\s]+)\s+((0x)?[0-9a-f]+)')
908905
matches = pattern.findall(content)
909906
for name, bit, _ in matches:
910-
match name:
911-
case 'GC_TYPE_MASK':
912-
self._type_mask = int(bit, 0)
913-
case 'GC_FLAGS_MASK':
914-
self._flags_mask = int(bit, 0)
915-
case 'GC_INFO_MASK':
916-
self._info_mask = int(bit, 0)
917-
case 'GC_INFO_SHIFT':
918-
self._info_shift = int(bit, 0)
919-
case 'GC_FLAGS_SHIFT':
920-
self._flags_shift = int(bit, 0)
907+
if name == 'GC_TYPE_MASK':
908+
self._type_mask = int(bit, 0)
909+
elif name == 'GC_FLAGS_MASK':
910+
self._flags_mask = int(bit, 0)
911+
elif name == 'GC_INFO_MASK':
912+
self._info_mask = int(bit, 0)
913+
elif name == 'GC_INFO_SHIFT':
914+
self._info_shift = int(bit, 0)
915+
elif name == 'GC_FLAGS_SHIFT':
916+
self._flags_shift = int(bit, 0)
921917

922918
# IS_STR_INTERNED GC_IMMUTABLE
923919
# IS_STR_PERMANENT (1<<8)
@@ -928,13 +924,12 @@ def _load(self):
928924
bit = bits.get(val)
929925
if bit == None:
930926
continue
931-
match type:
932-
case 'STR':
933-
target = str_bits
934-
case 'ARRAY':
935-
target = array_bits
936-
case 'OBJ':
937-
target = obj_bits
927+
if type == 'STR':
928+
target = str_bits
929+
elif type == 'ARRAY':
930+
target = array_bits
931+
elif type == 'OBJ':
932+
target = obj_bits
938933
target[name] = int(bit)
939934

940935
# Hard coded because these are not exposed in header files

0 commit comments

Comments
 (0)