Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* setfault calling functions within gdb
@ 2002-09-09 20:58 Faheem Mitha
  2002-09-09 23:49 ` Jim Blandy
  2002-09-10  6:27 ` Daniel Jacobowitz
  0 siblings, 2 replies; 4+ messages in thread
From: Faheem Mitha @ 2002-09-09 20:58 UTC (permalink / raw)
  To: gdb


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

ii  gdb                   5.2.cvs20020401-6      The GNU Debugger
ii  g++-3.0               3.0.4-9                The GNU C++ compiler.

I locally compiled the slightly more recent version of gdb from August
which is in unstable, but I get the same behaviour.

                                              Faheem.

(gdb) call print(foo)
[
Program received signal SIGSEGV, Segmentation fault.
0x0804a1a4 in print(std::vector<double, std::allocator<double> >)
(pt=0x804f008) at test.cc:22
The program being debugged was signaled while in a function called
from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function
(print(std::vector<double, std::allocator<double> >)) will be
abandoned.
(gdb)


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

* Re: setfault calling functions within gdb
  2002-09-09 20:58 setfault calling functions within gdb Faheem Mitha
@ 2002-09-09 23:49 ` Jim Blandy
  2002-09-10 20:12   ` Faheem Mitha
  2002-09-10  6:27 ` Daniel Jacobowitz
  1 sibling, 1 reply; 4+ messages in thread
From: Jim Blandy @ 2002-09-09 23:49 UTC (permalink / raw)
  To: Faheem Mitha; +Cc: gdb


I don't see anything obviously wrong with what you're doing (although
someone is certain to pop up and correct me).  Could you file this as
a bug report at http://sources.redhat.com/gdb/bugs/, so it won't get
lost?

Faheem Mitha <faheem@email.unc.edu> writes:

> 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
> 
> ii  gdb                   5.2.cvs20020401-6      The GNU Debugger
> ii  g++-3.0               3.0.4-9                The GNU C++ compiler.
> 
> I locally compiled the slightly more recent version of gdb from August
> which is in unstable, but I get the same behaviour.
> 
>                                               Faheem.
> 
> (gdb) call print(foo)
> [
> Program received signal SIGSEGV, Segmentation fault.
> 0x0804a1a4 in print(std::vector<double, std::allocator<double> >)
> (pt=0x804f008) at test.cc:22
> The program being debugged was signaled while in a function called
> >From GDB.
> GDB remains in the frame where the signal was received.
> To change this behavior use "set unwindonsignal on"
> Evaluation of the expression containing the function
> (print(std::vector<double, std::allocator<double> >)) will be
> abandoned.
> (gdb)


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

* Re: setfault calling functions within gdb
  2002-09-09 20:58 setfault calling functions within gdb Faheem Mitha
  2002-09-09 23:49 ` Jim Blandy
@ 2002-09-10  6:27 ` Daniel Jacobowitz
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2002-09-10  6:27 UTC (permalink / raw)
  To: Faheem Mitha; +Cc: gdb

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


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

* Re: setfault calling functions within gdb
  2002-09-09 23:49 ` Jim Blandy
@ 2002-09-10 20:12   ` Faheem Mitha
  0 siblings, 0 replies; 4+ messages in thread
From: Faheem Mitha @ 2002-09-10 20:12 UTC (permalink / raw)
  To: Jim Blandy; +Cc: gdb



On 10 Sep 2002, Jim Blandy wrote:

>
> I don't see anything obviously wrong with what you're doing (although
> someone is certain to pop up and correct me).  Could you file this as
> a bug report at http://sources.redhat.com/gdb/bugs/, so it won't get
> lost?

I've sent it to the Debian bug tracking system, against gdb. Is that Ok?
One reason for doing so is because it is a version of gdb that is from
cvs, so is presumably unique to Debian. Also, I prefer the Debian
interface. :-) I suppose I can send a copy to
http://sources.redhat.com/gdb/bugs/ if you think that is necessary.

                                                      Faheem.


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

end of thread, other threads:[~2002-09-11  3:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-09 20:58 setfault calling functions within gdb Faheem Mitha
2002-09-09 23:49 ` Jim Blandy
2002-09-10 20:12   ` Faheem Mitha
2002-09-10  6:27 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox