This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[python] [patch] Fix prettyprinter of std::map<const char *, ...>


Greetings,

This is something I have seen before, but forgot about :(

/// --- cut ---
#include <map>

int main()
{
  std::map<const char *, int> m;
  m["hello"] = 1;
  return 0;
}
/// --- cut ---

g++ -g -o stl2 stl2.cc

gdb -q ./stl2
(gdb) b 7
Breakpoint 1 at 0x40033b: file stl2.cc, line 7.
(gdb) r

Breakpoint 1, main () at stl2.cc:7
7         return 0;
(gdb) source python/lib/gdb/libstdcxx/v6/printers.py
(gdb) print m
$1 = std::map with 1 elementsTraceback (most recent call last):
  File "python/lib/gdb/libstdcxx/v6/printers.py", line 284, in children
    nodetype = gdb.Type('std::_Rb_tree_node< std::pair< const %s, %s > >' % (keytype, valuetype))
RuntimeError: No type named std::_Rb_tree_node< std::pair< const const char *, int > >.


This is happening because there really is no "pair<const const char *, int>" type.

Attached patch fixes this by brute force :(
Not sure if there is a better fix.

Thanks,

--
Paul Pluzhnikov

diff --git a/gdb/python/lib/gdb/libstdcxx/v6/printers.py b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
index c03c682..9fb26b4 100644
--- a/gdb/python/lib/gdb/libstdcxx/v6/printers.py
+++ b/gdb/python/lib/gdb/libstdcxx/v6/printers.py
@@ -234,7 +234,10 @@ class StdMapPrinter:
     def children (self):
         keytype = self.val.type().template_argument(0)
         valuetype = self.val.type().template_argument(1)
-        nodetype = gdb.Type('std::_Rb_tree_node< std::pair< const %s, %s > >' % (keytype, valuetype))
+        try:
+            nodetype = gdb.Type('std::_Rb_tree_node< std::pair< const %s, %s > >' % (keytype, valuetype))
+        except:
+            nodetype = gdb.Type('std::_Rb_tree_node< std::pair< %s const, %s > >' % (keytype, valuetype))
         nodetype = nodetype.pointer()
         return self._iter (self.iter, nodetype)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]