This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


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

Re: calling C++ functions from GDB


hanwen@cs.uu.nl (Han-Wen Nienhuys) writes:

> Hi,
> 
> we believe that gdb 5.0 has some shortcomings wrt calling C++
> functions.  The basic complaint is that it takes too long. (see the
> attached example.)
> 
> When I call the C++ function for the first time it takes about 7
> seconds (P-II / 266) before the result appears.  I think that this
> delay is long enough to be called a bug. 

I've fixed this (a few weeks ago), but not committed the patch to sourceware yet.
The problem was that C++ (and Java, but not C) symbol lookups always did linear symbol
searches through every symbol to find the proper one, for various
reasons (mainly to do with mangling).
With the patch, it will binary search, just like it does for C.

Calling C++ functions from GDB will always be slightly slower than
calling C functions, because of overload resolution, etc. However, it
shouldn't take seven seconds.

--Dan
> 
> /*
>    c++ -g -o display-scm display-scm.cc 
>  */
> #include <stdio.h>
> 
> extern "C" {
>   // maybe gdb 5.0 becomes quicker if it doesn't do fancy C++ typing?
> void
> c_display_scm (int k)
> {
>   printf ("foo %d\n", k);
> };
> };
> 
> void
> cc_display_scm (int k)
> {
>   printf ("foo %d\n", k);
> }
> 
> int
> main (int argc, char **argv)
> {
>   int i = 1+ 1;
>   return 0;
> }
> 
> (gdb) r
> Breakpoint 2, main (argc=1, argv=0xbffff544) at g2.cc:27
> Current language:  auto; currently c++
> (gdb) n
> (gdb) p c_display_scm(i)  # instantaneous
> foo 2
> $1 = void
> (gdb) p cc_display_scm(i) # 7 second delay
> foo 2
> $2 = void
> (gdb) p cc_display_scm(i) # 2 second delay
> foo 2
> $3 = void
> -- 
> 
> Han-Wen Nienhuys   |   hanwen@cs.uu.nl    | http://www.cs.uu.nl/~hanwen/


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