public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Infcall of a template function in a C++ program
@ 2019-06-07 14:45 Aktemur, Tankut Baris
  2019-06-26  8:59 ` Aktemur, Tankut Baris
  0 siblings, 1 reply; 8+ messages in thread
From: Aktemur, Tankut Baris @ 2019-06-07 14:45 UTC (permalink / raw)
  To: gdb; +Cc: Metzger, Markus T

Dear All,

Suppose we have the following small C++ program:

~~~
#include <iostream>

template <typename T>
T foo (T t)
{
  return t;
}

int main (void)
{
  std::cout << foo (5) << std::endl;
  std::cout << foo ('a') << std::endl;

  return 0;
}
~~~

The compiler is able to do the type inference, template function
instantiation, and function invocation based on the expressions `foo (5)`
and `foo ('a')`.  When we start GDB and attempt to evaluate these
expressions, the corresponding functions are not resolved, though.
Here is a sample session:

~~~
(gdb) start
...
(gdb) print foo(5)
No symbol "foo" in current context.
(gdb) print foo<int>(5)
$1 = 5
(gdb) print foo<char>('a')
$2 = 97 'a'
~~~

The DWARF info contains DIE's for the subprograms named "foo<int>" and
"foo<char>":

0x00002849:   DW_TAG_subprogram
                DW_AT_name      ("foo<char>")
...
0x00002882:   DW_TAG_subprogram
                DW_AT_name      ("foo<int>")
...

Is there any on-going or planned work to add type inference/resolution
capability to GDB so that an expression such as `foo (5)` would be evaluated
correctly? This might not be possible in general, but does GDB try any heuristics
to find the right template instance?

Regards,
-Tankut Baris Aktemur

Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-07-23 16:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-07 14:45 Infcall of a template function in a C++ program Aktemur, Tankut Baris
2019-06-26  8:59 ` Aktemur, Tankut Baris
2019-07-19 20:12   ` Tom Tromey
2019-07-23 14:51     ` Keith Seitz
2019-07-23 15:52       ` Tom Tromey
2019-07-23 16:24       ` Aktemur, Tankut Baris
2019-07-23 16:52         ` Keith Seitz
2019-07-23 16:22     ` Aktemur, Tankut Baris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).