Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/c++/gdb-class-layout.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Steps

4. Build the ``gdb-ex-1.cc`` to get all debugging information in ``gdb``::

c++ -ggdb -O2 -W -Wall gdb-ex-1.cc -o gdb-ex-1
c++ -ggdb -O1 -W -Wall gdb-ex-1.cc -o gdb-ex-1

5. Run the code under ``gdb``, insert a break point at ``main`` and
inspect its assembly::
Expand Down
2 changes: 1 addition & 1 deletion exercises/c++/gdb-ex-1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int f( int x ) { return x*x; }

int main(int, char **)
{
int y, x = 5, z = 6;
int y = 4, x = 5, z = 6;
printf("y= %d\n", y);
y = f(x);
printf("y= %d\n", y);
Expand Down
10 changes: 5 additions & 5 deletions exercises/c++/gdb-ex-2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ main(int, char **)
B b;

std::cout << "size of a: " << sizeof(a)
<< " offset of ad: " << offsetof(A, ad)
<< std::endl;
<< " offset of ad: " << offsetof(A, ad)
<< std::endl;

std::cout << "size of b: " << sizeof(b)
<< " offset of ad: " << offsetof(B, ad)
<< " offset of bd: " << offsetof(B, bd)
<< std::endl;
<< " offset of ad: " << offsetof(B, ad)
<< " offset of bd: " << offsetof(B, bd)
<< std::endl;

f(&a);
f(&b);
Expand Down
12 changes: 6 additions & 6 deletions exercises/c++/gdb-ex-3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class A
{
public:
virtual void m1() { std::cout << "A::m1()" << std::endl; }
virtual void m2() { std::cout << "A::m1()" << std::endl; }
virtual void m2() { std::cout << "A::m2()" << std::endl; }
int ad;
};

Expand Down Expand Up @@ -47,13 +47,13 @@ int main(int, char **)
B b2;

std::cout << "size of a: " << sizeof(a)
<< " offset of ad: " << offsetof(A, ad)
<< std::endl;
//<< " offset of ad: " << offsetof(A, ad)
<< std::endl;

std::cout << "size of b: " << sizeof(b1)
<< " offset of ad: " << offsetof(B, ad)
<< " offset of bd: " << offsetof(B, bd)
<< std::endl;
//<< " offset of ad: " << offsetof(B, ad)
//<< " offset of bd: " << offsetof(B, bd)
<< std::endl;


std::cout << "a: " << std::endl; print_vtable(&a);
Expand Down