#include <iostream>
using namespace std;
class dummyA
{
int x;
public:
dummyA ()
{
x = 0;
}
void test ()
{
x++;
}
};
int main ()
{
cout << "\nG'Morning";
dummyA obj;
obj.test ();
return 0;
}
The backtrace output:
(gdb) bt
#0 main () at backtrace.cpp:21
(gdb) bt full
#0 main () at backtrace.cpp:21
obj = {x = -8896}
(gdb) n
22 dummyA obj;
(gdb)
Questions:
bt
is said to be printing a backtrace of the entire stack: one line per frame for all frames in the stack, but I see only the name of the function in the output? Why is that so?bt full
shows the inner works, how can it read the 'obj' when the control is not on that line (dummyA obj;
) yet?
EDIT 1:
Breakpoint 1, dummyA::testB (this=0x7fffffffdc50) at backtrace.cpp:20
20 x = x + 2;
(gdb) bt 0
(More stack frames follow...)
- The above output shows nothing because the callee function testB has zero local variables? Is that correct?
(gdb) bt 1 #0 dummyA::testB (this=0x7fffffffdc50) at backtrace.cpp:20 (More stack frames follow...) (gdb) bt 2 #0 dummyA::testB (this=0x7fffffffdc50) at backtrace.cpp:20 #1 0x000000000040078b in main () at backtrace.cpp:31
- What do frames 1 and 2 show exactly?
(gdb) bt full
#0 main () at backtrace.cpp:26
obj1 = {x = -8896}
obj2 = {x = 0}
- Why does x have two different values here, assuming that the breakpoint is on main?
WRT the following code:
#include <iostream>
using namespace std;
class dummyA
{
int x;
public:
dummyA ()
{
x = 0;
}
void testA ()
{
x = x + 1;
}
void testB ()
{
x = x + 2;
}
};
int main ()
{
cout << "\nG'Morning";
dummyA obj1;
dummyA obj2;
obj1.testA ();
obj1.testB ();
obj2.testA ();
obj2.testB ();
return 0;
}