]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gdbhooks.py: Implement a prettyprinter for vec<>*
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Nov 2013 03:57:35 +0000 (03:57 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 20 Nov 2013 03:57:35 +0000 (03:57 +0000)
gcc/
* gdbhooks.py (VecPrinter): New class, for prettyprinting pointers
to "vec<>" instances.
(build_pretty_printer): Register the vec<>* prettyprinter.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@205086 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/gdbhooks.py

index eb39253d89f02148abc8265073cf68a51cd56ac1..18b435d8c5bb88e4800a3b70d3ce488b2841ac42 100644 (file)
@@ -1,3 +1,9 @@
+2013-11-19  David Malcolm  <dmalcolm@redhat.com>
+
+       * gdbhooks.py (VecPrinter): New class, for prettyprinting pointers
+       to "vec<>" instances.
+       (build_pretty_printer): Register the vec<>* prettyprinter.
+
 2013-11-19  David Malcolm  <dmalcolm@redhat.com>
 
        * gdbhooks.py (GdbSubprinter.__init__): Drop str_type_ field.
index 3afa7961feb1ea43f4a9c96818299593f063f795..baccd6b783e1d8011bd3f2f300abaa5a775bc963 100644 (file)
@@ -109,6 +109,26 @@ available:
   1594   execute_pass_list (g->get_passes ()->all_passes);
   (gdb) p node
   $1 = <cgraph_node* 0x7ffff0312720 "foo">
+
+vec<> pointers are printed as the address followed by the elements in
+braces.  Here's a length 2 vec:
+  (gdb) p bb->preds
+  $18 = 0x7ffff0428b68 = {<edge 0x7ffff044d380 (3 -> 5)>, <edge 0x7ffff044d3b8 (4 -> 5)>}
+
+and here's a length 1 vec:
+  (gdb) p bb->succs
+  $19 = 0x7ffff0428bb8 = {<edge 0x7ffff044d3f0 (5 -> EXIT)>}
+
+You cannot yet use array notation [] to access the elements within the
+vector: attempting to do so instead gives you the vec itself (for vec[0]),
+or a (probably) invalid cast to vec<> for the memory after the vec (for
+vec[1] onwards).
+
+Instead (for now) you must access m_vecdata:
+  (gdb) p bb->preds->m_vecdata[0]
+  $20 = <edge 0x7ffff044d380 (3 -> 5)>
+  (gdb) p bb->preds->m_vecdata[1]
+  $21 = <edge 0x7ffff044d3b8 (4 -> 5)>
 """
 import re
 
@@ -349,8 +369,29 @@ class PassPrinter:
 
 ######################################################################
 
+class VecPrinter:
+    #    -ex "up" -ex "p bb->preds"
+    def __init__(self, gdbval):
+        self.gdbval = gdbval
+
+    def display_hint (self):
+        return 'array'
+
+    def to_string (self):
+        # A trivial implementation; prettyprinting the contents is done
+        # by gdb calling the "children" method below.
+        return '0x%x' % long(self.gdbval)
+
+    def children (self):
+        m_vecpfx = self.gdbval['m_vecpfx']
+        m_num = m_vecpfx['m_num']
+        m_vecdata = self.gdbval['m_vecdata']
+        for i in range(m_num):
+            yield ('[%d]' % i, m_vecdata[i])
+
+######################################################################
+
 # TODO:
-#   * vec
 #   * hashtab
 #   * location_t
 
@@ -423,6 +464,10 @@ def build_pretty_printer():
     pp.add_printer_for_types(['rtx_def *'], 'rtx_def', RtxPrinter)
     pp.add_printer_for_types(['opt_pass *'], 'opt_pass', PassPrinter)
 
+    pp.add_printer_for_regex(r'vec<(\S+), (\S+), (\S+)> \*',
+                             'vec',
+                             VecPrinter)
+
     return pp
 
 gdb.printing.register_pretty_printer(