This is the mail archive of the gdb@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]
Other format: [Raw text]

Breakpoints in constructor/destructor


Hi,

	I just downloaded gdb onto cygwin. I found it pretty
wonderful, but there's one thing I'm completely baffled by. I
can't seem to set breakpoints in constructors or destructors
in my C++ programs. I wrote a simple program that does nothing but
create and destroy a simple object. When I step through it, I can see
my cout statements in the constructors and destructors being called.
But if I set breakpoints at these lines, the gdb doesn't stop there.
The program is reproduced below, but it's pretty simple---there's
not much to see. I read the gdb manual, but saw no mention of 
any special issues related to constructors and destructors. And
I see that there was a thread earlier this year on "breakpoints
in constructors," but unfortunately, I found it incomprehensible.

	Any help would be appreciated. Or, any suggestion on how
I could have figured this out on my own, from the gdb manual
or other source. 

Momo




------------ Program below ------------

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

// ----- START OF CLASS MyNumber -----

class MyNumber{
public:
	MyNumber(int y);
	~MyNumber();
private:
	int x;
};

MyNumber::MyNumber(int y)
{
   cout << "\nConstructor called with number " << y << endl;
   x=y;
}

MyNumber::~MyNumber()
{
   cout << "\nDestructor called for number" << x << endl;
}

// ----- END OF CLASS MyNumber -----

void APointlessFunction(void)
{
   MyNumber c(42);
}

int main()
{
   MyNumber a(100);
   APointlessFunction();
   return 0;
}


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