This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: setfault calling functions within gdb
- From: Daniel Jacobowitz <drow at mvista dot com>
- To: Faheem Mitha <faheem at email dot unc dot edu>
- Cc: gdb at sources dot redhat dot com
- Date: Tue, 10 Sep 2002 09:28:02 -0400
- Subject: Re: setfault calling functions within gdb
- References: <Pine.LNX.4.44.0209092345270.13388-100000@Chrestomanci>
On Mon, Sep 09, 2002 at 11:55:53PM -0400, Faheem Mitha wrote:
>
> Dear People,
>
> I'm having problems calling functions from within gdb. Can someone tell me
> what I am doing wrong? Consider the following innocuous program
>
> ---------------------------------------------------------
> #include<vector>
> #include <iostream>
>
> using std::vector;
> using std::cout;
>
> typedef vector<double> Point;
> void print(Point pt);
>
> int main()
> {
> Point foo(3,1.0);
> //print(foo);
> }
>
> void print(Point pt)
> {
> unsigned int i;
> cout << "[";
> for(i=0; i < pt.size(); i++)
> {
> cout << pt[i];
> cout << ",";
> }
> cout << "]";
> }
> -----------------------------------------------------------
>
> When I set a breakpoint after the definition of foo and call
> print(foo) I get a segfault. There appears to be nothing wrong with
> this function, since print(foo) when compiled into the function works
> as expected. Also, "print foo[0]" works fine. There seem to be two
> possibilities; a) I am doing something wrong, b) this is a bug in
> gdb. I'm hoping it is the former. I dimly recall calling functions
> successfully sometime in the past, but I can't remember whether it was
> in C or C++ code.
>
> Any help would be greatly appreciated. This is really frustrating!
> Output from gdb follows. I'm using gdb, gcc-3.0 on Debian Sarge. The
> respective versions are
Thanks for the great testcase. It may be a couple days before I have
time to look at it, but I know roughly what's wrong: we're trying to
pass foo as a structure-by-value, as if this were C, and in C++ we are
required to do this by the copy constructor. Or something similar.
When it calls the destructor, as the argument goes out of scope, it is
crashing trying to free something already freed.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer