下一条命令中gdb的奇怪行为

时间:2018-09-24 16:58:57

标签: c++ gdb

我是gdb的新手,并且有一个包含以下代码的cpp文件

function Sun(x,y,w,h,c1,c2){
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    this.c1 = c1;
    this.c2 = c2;

    this.center = createVector(width/2,height/2);
    this.pos = createVector(this.x,this.y);
    var dx = this.center.x - this.pos.x;
    var dy = this.center.y - this.pos.y;
    var initAngle = atan2(dx,dy);
    this.angle =  initAngle;
    this.constant = height/2;
    this.radius = dist(this.center.x,this.center.y,this.pos.x,this.pos.y);

    this.display = function(){
        noStroke();
        fill(red(c1),green(c1),blue(c1));

        //draw center point
        ellipse(this.center.x,this.center.y,10,10);

        var x = this.constant + sin(this.angle) * this.radius;
        var y = this.constant + cos(this.angle) * this.radius;
        ellipse(x,y,50,50);

        this.angle = map(mouseX,0, width, initAngle, initAngle + PI);
    }
}

编译#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; }

然后我运行了gdb g++ -g main.cpp -o main

使用命令gdb mainb mainr ...

我得到以下输出

n

对我来说,gdb可以正常工作,直到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 上的return 0为止。之后,该控件移至line no 16,然后移至line 14

为什么会这样,所以在line 12之后按n时,它先移到line 16,然后移到line 14。根据第一条评论line 12。但是,为什么它不适用于it is due to destruction of set_int and vec_int。为什么不调用它的析构函数?

请解释我在哪里缺少东西。向我推荐一些可以使我了解点点知识的地方。

0 个答案:

没有答案