Skip to content

Commit 098a41c

Browse files
committed
gdbhooks: Handle references to vec* in VecPrinter
vec.h has this method: template<typename T, typename A> inline T * vec_safe_push (vec<T, A, vl_embed> *&v, const T &obj CXX_MEM_STAT_INFO) where v is a reference to a pointer to vec. This matches the regex for VecPrinter, so gdbhooks.py attempts to print it but chokes on the reference. I see the following: #1 0x0000000002b84b7b in vec_safe_push<edge_def*, va_gc> (v=Traceback (most recent call last): File "$SRC/gcc/gcc/gdbhooks.py", line 486, in to_string return '0x%x' % intptr(self.gdbval) File "$SRC/gcc/gcc/gdbhooks.py", line 168, in intptr return long(gdbval) if sys.version_info.major == 2 else int(gdbval) gdb.error: Cannot convert value to long. This patch makes VecPrinter handle such references by stripping them (dereferencing) at the top of the relevant functions. gcc/ChangeLog: * gdbhooks.py (strip_ref): New. Use it ... (VecPrinter.to_string): ... here, (VecPrinter.children): ... and here.
1 parent a22dfe2 commit 098a41c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gcc/gdbhooks.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ def get_vec_kind(val):
472472
else:
473473
assert False, f"unexpected vec kind {kind}"
474474

475+
def strip_ref(gdbval):
476+
if gdbval.type.code == gdb.TYPE_CODE_REF:
477+
return gdbval.referenced_value ()
478+
return gdbval
479+
475480
class VecPrinter:
476481
# -ex "up" -ex "p bb->preds"
477482
def __init__(self, gdbval):
@@ -483,10 +488,10 @@ def display_hint (self):
483488
def to_string (self):
484489
# A trivial implementation; prettyprinting the contents is done
485490
# by gdb calling the "children" method below.
486-
return '0x%x' % intptr(self.gdbval)
491+
return '0x%x' % intptr(strip_ref(self.gdbval))
487492

488493
def children (self):
489-
val = self.gdbval
494+
val = strip_ref(self.gdbval)
490495
if intptr(val) != 0 and get_vec_kind(val) == VEC_KIND_PTR:
491496
val = val['m_vec']
492497

0 commit comments

Comments
 (0)