Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7187867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:56:29+00:00 2026-05-28T18:56:29+00:00

#include <iostream> using namespace std; class dummyA { int x; public: dummyA () {

  • 0
#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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:56:30+00:00Added an answer on May 28, 2026 at 6:56 pm

    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?

    The backtrace shows the current function, then the function that called that, and so on, all the way back to main(). Each “stack frame” is the section of stack used by a particular function, so there’s one frame per function. Since the current function is main(), there is only one frame to show.

    (Perhaps you were hoping the the backtrace would allow you to see every line of code that was executed. Unfortunately, when running code normally (which is what gdb does, apart from adding breakpoints), there isn’t enough available information to do that; the best you can do is look at the history of function calls.)

    bt full shows the inner works, how can it read the ‘obj’ when the control is not on that line (dummyA obj;) yet?

    Space has been allocated (in the local stack frame) for the object; it just hasn’t been initialised yet. You’re seeing whatever happens to be in that space, and it should become {x = 0} if you step over the initialisation line.

    The above output shows nothing because the callee function testB has zero local variables? Is that correct?

    It shows nothing because you asked it to show nothing; the argument to bt specifies how many stack frames to show, and you said zero.

    What do frames 1 and 2 show exactly?

    In the first case, you asked for one stack frame; that of the current function. It tells you that you’re in the function dummyA::testB, that the address of the object it was called on (this) is 0x7fffffffdc50, and that the corresponding source line is line 20 of backtrace.cpp.

    In the second case, you asked for two frames, so it also shows where the current function was called from: the function main(), source line 31 of backtrace.cpp.

    Why does x have two different values here, assuming that the breakpoint is on main?

    Each is the member of a different object (obj1.x and obj2.x), and neither has been initialised; so each is showing some random value that happens to be in that memory location. Again, both will become zero if you step over the initialisers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<iostream> using namespace std; class A { int a; int b; public: void eat()
#include iostream using namespace std; class A { public: void mprint() { cout<<\n TESTING
include stdafx.h #include <iostream> using namespace std; class Foo{ public: void func() { cout<<Hello!!<<endl;
#include<iostream> using namespace std; class test { int a; public: test() { a=0; }
#include<iostream> using namespace std; class test { int a, b; public: test() { a=4;
#include<iostream> using namespace std; class base { public: virtual void add() { cout <<
#include<iostream> using namespace std; class A { private: const int a=9; public: void display()
#include<iostream> using namespace std; class Something { public: int j; Something():j(20) {cout<<Something initialized. j=<<j<<endl;}
#include<iostream> using namespace std; class A { public: int i; A() {cout<<A()<<endl;} ~A() {cout<<~A()<<endl;}
#include <iostream> using namespace std; class Base { public: Base(){cout <<Base<<endl;} virtual ~Base(){cout<<~Base<<endl;} virtual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.