gdbhooks: Fix printing of vec with vl_ptr layout

As it stands, the pretty printing of GCC's vecs by gdbhooks.py only
handles vectors with vl_embed layout.  As such, when encountering a vec
with vl_ptr layout, GDB would print a diagnostic like:

  gdb.error: There is no member or method named m_vecpfx.

when (e.g.) any such vec occurred in a backtrace.  This patch extends
VecPrinter.children to also handle vl_ptr vectors.

gcc/ChangeLog:

	* gdbhooks.py (VEC_KIND_EMBED): New.
	(VEC_KIND_PTR): New.
	(get_vec_kind): New.
	(VecPrinter.children): Also handle vectors with vl_ptr layout.
This commit is contained in:
Alex Coplan 2024-08-30 15:29:34 +01:00
parent 3fb90724ce
commit 5020f8ea80

View file

@ -453,6 +453,25 @@ class PassPrinter:
######################################################################
VEC_KIND_EMBED = 0
VEC_KIND_PTR = 1
"""
Given a vec or pointer to vec, return its layout (embedded or space
efficient).
"""
def get_vec_kind(val):
typ = val.type
if typ.code == gdb.TYPE_CODE_PTR:
typ = typ.target()
kind = typ.template_argument(2).name
if kind == "vl_embed":
return VEC_KIND_EMBED
elif kind == "vl_ptr":
return VEC_KIND_PTR
else:
assert False, f"unexpected vec kind {kind}"
class VecPrinter:
# -ex "up" -ex "p bb->preds"
def __init__(self, gdbval):
@ -467,11 +486,16 @@ class VecPrinter:
return '0x%x' % intptr(self.gdbval)
def children (self):
if intptr(self.gdbval) == 0:
return
m_vecpfx = self.gdbval['m_vecpfx']
m_num = m_vecpfx['m_num']
val = self.gdbval
if intptr(val) != 0 and get_vec_kind(val) == VEC_KIND_PTR:
val = val['m_vec']
if intptr(val) == 0:
return
assert get_vec_kind(val) == VEC_KIND_EMBED
m_vecpfx = val['m_vecpfx']
m_num = m_vecpfx['m_num']
typ = val.type
if typ.code == gdb.TYPE_CODE_PTR:
typ = typ.target()