having the type Eigen::Matrix<double, 4, 1, 2, 4, 1> Executing template_argument(1) on the type gdb object (when doing a pretty printer), I get the following: Traceback (most recent call last): File "/home/bschindl/software/gdb-printer/eigen/printers.py", line 53, in lookup_function return pretty_printers_dict[function](val) File "/home/bschindl/software/gdb-printer/eigen/printers.py", line 28, in <lambda> pretty_printers_dict[re.compile('^Eigen::Matrix<.*>$')] = lambda val: EigenMatrixPrinter(val) File "/home/bschindl/software/gdb-printer/eigen/printers.py", line 18, in __init__ self.rows = self.type.template_argument(1) RuntimeError: No type named 4.
Repro: // gdb-pr11060.cc template <int N> struct Foo { }; int main() { Foo<42> f; return 0; } // --- cut --- g++ -g -o gdb-pr11060 gdb-pr11060.cc gdb64-cvs gdb-pr11060 GNU gdb (GDB) 7.0.50.20091203-cvs ... This GDB was configured as "x86_64-unknown-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /tmp/gdb-pr11060...done. (gdb) b main Breakpoint 1 at 0x40053c: file gdb-pr11060.cc, line 6. (gdb) r Breakpoint 1, main () at gdb-pr11060.cc:6 6 return 0; (gdb) p f $1 = {<No data fields>} (gdb) py t = gdb.history(1) (gdb) py print t.type.template_argument(0) Traceback (most recent call last): File "<string>", line 1, in <module> RuntimeError: No type named 42. Error while executing Python code. Same problem on archer-tromey-python.
*** Bug 10476 has been marked as a duplicate of this bug. ***
*** Bug 11546 has been marked as a duplicate of this bug. ***
I'm working on a fix.
Subject: Bug 11060 CVSROOT: /cvs/src Module name: src Changes by: tromey@sourceware.org 2010-07-28 20:50:17 Modified files: gdb : ChangeLog gdb/python : py-type.c gdb/testsuite : ChangeLog gdb/testsuite/gdb.python: py-type.c py-type.exp Log message: gdb PR python/11060: * python/py-type.c (typy_legacy_template_argument): New function, extracted from typy_template_argument. (typy_template_argument): Use TYPE_TEMPLATE_ARGUMENT. Return a value when needed. gdb/testsuite PR python/11060: * gdb.python/py-type.c (Temargs): New template. (temvar): New variable. * gdb.python/py-type.exp (test_template): New proc. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.12042&r2=1.12043 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/python/py-type.c.diff?cvsroot=src&r1=1.10&r2=1.11 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.2395&r2=1.2396 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.python/py-type.c.diff?cvsroot=src&r1=1.2&r2=1.3 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.python/py-type.exp.diff?cvsroot=src&r1=1.5&r2=1.6
I checked in a fix for this, but it only works if you have a new version of GCC.
I think this is fixed in 7.2. You could use something like the following as workaround: def numericTemplateArgument(type, position): try: return int(type.template_argument(position)) except RuntimeError, error: # ": No type named 30." msg = str(error) return int(msg[14:-1])
Fixed.