I am new at gdb and have a cpp file with the following code
#include <set>
#include <vector>
struct A{
int a;
A(int aa) {a = aa;}
};
int main () {
A aa(2);
aa.a = 1;
std::set<int> set_int;
set_int.insert(1);
std::vector<int> vec_int;
vec_int.push_back(1);
return 0;
}
compiled it g++ -g main.cpp -o main
then i ran gdb gdb main
using commands b main
, r
,n
...
I got following output
Reading symbols from a.out...done.
(gdb) b main
Breakpoint 1 at 0x400aaf: file main.cpp, line 9.
(gdb) r
Starting program: /home/srb/Desktop/a.out
Breakpoint 1, main () at main.cpp:9
9 int main () {
(gdb) n
10 A aa(2);
(gdb)
11 aa.a = 1;
(gdb)
12 std::set<int> set_int;
(gdb)
13 set_int.insert(1);
(gdb)
14 std::vector<int> vec_int;
(gdb)
15 vec_int.push_back(1);
(gdb)
16 return 0;
(gdb)
14 std::vector<int> vec_int;
(gdb)
12 std::set<int> set_int;
(gdb)
17 }
(gdb)
__libc_start_main (main=0x400aa6 <main()>, argc=1, argv=0x7fffffffdbf8, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7fffffffdbe8) at ../csu/libc-start.c:325
325 ../csu/libc-start.c: No such file or directory.
(gdb) q
for me gdb was working fine till return 0
which is on line no 16
. after that control moved to line 14
and then line 12
.
why was this happening that on pressing n after line 16
it moved to line 14
and then line 12
. According to the first comment it is due to destruction of set_int and vec_int
. But then why is it not working for aa
. why is its destructor not called ?
Please explain where I am missing the things. suggest me some place where I can get proper knoweledge to connect the dots.