Re: casting in gdb

Daniel Jacobowitz
2002-12-14T07:34:36Z

On Fri, Dec 13, 2002 at 02:43:17PM -0500, Jacques Le Normand wrote:
> here you go, thanks for lending a hand...
>
> [countchocula@chocoland countchocula]$ g++ -ggdb test.cpp -o test.o
> [countchocula@chocoland countchocula]$ gdb test.o
> GNU gdb Red Hat Linux (5.2.1-4)
> Copyright 2002 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you are
> welcome to change it and/or distribute copies of it under certain
> conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB. Type "show warranty" for details.
> This GDB was configured as "i386-redhat-linux"...
> (gdb) b 10
> Breakpoint 1 at 0x80486f5: file test.cpp, line 10.
> (gdb) r
> Starting program: /home/countchocula/test.o
>
> Breakpoint 1, main () at test.cpp:10
> 10 a.push_back(2);
> (gdb) p a[0]
> One of the arguments you tried to pass to operator[] could not be converted
> to w
> hat the function wants.
> (gdb)

This one's pretty simple once you figure it out. The error message is
really bad; I'll hold on to this and try to improve it.

Your program doesn't _use_ operator[]. So it doesn't get compiled into
the program, and GDB can't call it to figure out what to do.

What happens if you add a call to the operator?

[I noticed some other quirks; for instance, if your program only uses
the mutable version and GDB finds the const version first, it may get
confused...]

--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer