diff mbox series

gdbhooks: Fix printing of vec with vl_ptr layout

Message ID ZtGoNMuEYYkI2s2w@arm.com
State New
Headers show
Series gdbhooks: Fix printing of vec with vl_ptr layout | expand

Commit Message

Alex Coplan Aug. 30, 2024, 11:08 a.m. UTC
Hi,

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.

Manually tested by verifying that vl_embed vectors still print correctly
and empty vl_ptr vectors no longer trigger errors.

OK for trunk?

Thanks,
Alex

Comments

David Malcolm Aug. 30, 2024, 2:12 p.m. UTC | #1
On Fri, 2024-08-30 at 12:08 +0100, Alex Coplan wrote:
> Hi,
> 
> 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.
> 
> Manually tested by verifying that vl_embed vectors still print
> correctly
> and empty vl_ptr vectors no longer trigger errors.
> 
> OK for trunk? 

Thanks for fixing this.

+    else:
+        assert False, f"unxpected vec kind {kind}"

Typo: "unxpected" -> "unexpected"

Otherwise, looks good for trunk (with a ChangeLog).

Thanks again
Dave
Alex Coplan Aug. 30, 2024, 2:38 p.m. UTC | #2
On 30/08/2024 10:12, David Malcolm wrote:
> On Fri, 2024-08-30 at 12:08 +0100, Alex Coplan wrote:
> > Hi,
> > 
> > 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.
> > 
> > Manually tested by verifying that vl_embed vectors still print
> > correctly
> > and empty vl_ptr vectors no longer trigger errors.
> > 
> > OK for trunk? 
> 
> Thanks for fixing this.
> 
> +    else:
> +        assert False, f"unxpected vec kind {kind}"
> 
> Typo: "unxpected" -> "unexpected"
> 
> Otherwise, looks good for trunk (with a ChangeLog).

Thanks for the review, I've pushed this to trunk with the typo fixed and
a suitable ChangeLog (as g:5020f8ea80af90d8a08eff9fdef3276056df98f5).

Not entirely sure what happened to the ChangeLog as I remember writing
one, but it seems I must have lost it somewhere along the way.  Sorry
about that!

FYI there will likely be at least one follow-on patch as I found another
case where this code trips over on references to vec*.

Thanks,
Alex

> 
> Thanks again
> Dave
>
diff mbox series

Patch

diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index 7a64c03b8ac..2c0a074d0b6 100644
--- a/gcc/gdbhooks.py
+++ b/gcc/gdbhooks.py
@@ -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"unxpected 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:
+        val = self.gdbval
+        if intptr(val) != 0 and get_vec_kind(val) == VEC_KIND_PTR:
+            val = val['m_vec']
+
+        if intptr(val) == 0:
             return
-        m_vecpfx = self.gdbval['m_vecpfx']
+
+        assert get_vec_kind(val) == VEC_KIND_EMBED
+        m_vecpfx = val['m_vecpfx']
         m_num = m_vecpfx['m_num']
-        val = self.gdbval
         typ = val.type
         if typ.code == gdb.TYPE_CODE_PTR:
             typ = typ.target()