Bug 11060 - the template_argument function cannot handle value arguments
Summary: the template_argument function cannot handle value arguments
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: 7.0
: P2 normal
Target Milestone: 7.2
Assignee: Tom Tromey
URL:
Keywords:
: 10476 11546 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-12-07 14:24 UTC by Benjamin Schindler
Modified: 2011-10-10 19:20 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2010-07-28 18:10:15


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Schindler 2009-12-07 14:24:39 UTC
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.
Comment 1 Paul Pluzhnikov 2009-12-07 18:04:56 UTC
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.
Comment 2 Tom Tromey 2010-01-25 20:06:10 UTC
*** Bug 10476 has been marked as a duplicate of this bug. ***
Comment 3 Tom Tromey 2010-04-27 15:25:28 UTC
*** Bug 11546 has been marked as a duplicate of this bug. ***
Comment 4 Tom Tromey 2010-07-28 18:10:15 UTC
I'm working on a fix.
Comment 5 Sourceware Commits 2010-07-28 20:50:34 UTC
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

Comment 6 Tom Tromey 2010-07-28 21:04:09 UTC
I checked in a fix for this, but it only works if you have a new version of GCC.
Comment 7 Andre' 2011-09-15 11:22:11 UTC
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])
Comment 8 Tom Tromey 2011-10-10 19:20:16 UTC
Fixed.