gdb如何检测到比函数中的出口更多的条目?

时间:2019-05-27 15:41:54

标签: c++ gdb

我目前正在处理这段代码:

16 functionResult function::applyfunction(const molecule m[2])const{
// \func compute the results of the application of the function on m
 17         functionResult fr;
 18         if (this->inst()==assemble){
 19                 fr.cut=false;
 20                 fr.del[0]=m[0];
 21                 fr.del[1]=m[1];
 22                 fr.add[0]=(this->id==0)? m[1]+m[0] : m[0]+m[1];
 23                 }
 24         else{
 25                 std::pair<molecule,molecule> p;
 26                 p=m[0].split(this->id-2);
 27                 fr.cut=true;
 28                 fr.del[0] = m[0];
 29                 fr.add[0] = p.first;
 30                 fr.add[1] = p.second;
 31                 }       
 32         return fr;
 33         }

使用gdb调试器,我设置了两个断点,如下所示:

(gdb) break function.cpp:17
Breakpoint 1 at 0x7324: file function.cpp, line 17.
(gdb) break function.cpp:32
Breakpoint 2 at 0x741b: file function.cpp, line 32.
(gdb) ignore 1 10000
Will ignore next 10000 crossings of breakpoint 1.
(gdb) ignore 2 10000
Will ignore next 10000 crossings of breakpoint 2.

问题: 当我运行该程序时,由于某种原因它停止了,但这不是我在这里发布的原因。我发布的原因是,当程序停止时,我会寻找断点:

(gdb) info break 1
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x000055555555b324 in function::applyfunction(molecule const*) const at function.cpp:17
    breakpoint already hit 326 times
    ignore next 9674 hits
(gdb) info break 2
Num     Type           Disp Enb Address            What
2       breakpoint     keep y   0x000055555555b41b in function::applyfunction(molecule const*) const at function.cpp:32
    breakpoint already hit 261 times
    ignore next 9739 hits

那么,我的程序如何在函数中输入多次而不是退出?我精确地指出,我的整个程序都是单线程的。

edit:我已经编译为使用gcc -S -fverbose-asm function.cpp获取汇编代码,并且得到:

  1 # function.cpp:16: functionResult function::applyfunction(const molecule m[2])const{    // \func compute the results of th    e application of the function on m
  2         movq    %fs:40, %rax    #, tmp141
  3         movq    %rax, -24(%rbp) # tmp141, D.69134
  4         xorl    %eax, %eax      # tmp141
  5 # function.cpp:17:      functionResult fr;
  6         movq    -168(%rbp), %rax        # <retval>, tmp102
  7         movq    %rax, %rdi      # tmp102,
  8         call    _ZN14functionResultC1Ev #
  9 # function.cpp:18:      if (this->inst()==assemble){
 10         movq    -176(%rbp), %rax        # this, tmp103
 11         movq    %rax, %rdi      # tmp103,
 12         call    _ZNK8function4instEv    #
 13         cmpl    $1, %eax        #, _1
 14         sete    %al     #, retval.0_23
 15         testb   %al, %al        # retval.0_23
 16         je      .L25    #,
 17 # function.cpp:19:              fr.cut=false;
 18         movq    -168(%rbp), %rax        # <retval>, tmp104
 19         movb    $0, (%rax)      #, fr_19(D)->cut
 20 # function.cpp:20:              fr.del[0]=m[0];
 21         movq    -168(%rbp), %rax        # <retval>, tmp105
 22         leaq    72(%rax), %rdx  #, _2
 23         movq    -184(%rbp), %rax        # m, tmp106
 24         movq    %rax, %rsi      # tmp106,
 25         movq    %rdx, %rdi      # _2,
 26 .LEHB0:
 27         call    _ZN8moleculeaSERKS_     #
 28 # function.cpp:21:              fr.del[1]=m[1];
 29         movq    -184(%rbp), %rax        # m, tmp107
 30         leaq    32(%rax), %rdx  #, _3
 31         movq    -168(%rbp), %rax        # <retval>, tmp108
 32         addq    $104, %rax      #, _4
 33         movq    %rdx, %rsi      # _3,
 34         movq    %rax, %rdi      # _4,
 35         call    _ZN8moleculeaSERKS_     #
 36 # function.cpp:22:              fr.add[0]=(this->id==0)? m[1]+m[0] : m[0]+m[1];
 37         movq    -176(%rbp), %rax        # this, tmp109
 38         movl    (%rax), %eax    # this_21(D)->id, _5
 39         testl   %eax, %eax      # _5
 40         jne     .L26    #,
 41 # function.cpp:22:              fr.add[0]=(this->id==0)? m[1]+m[0] : m[0]+m[1];
 42         movq    -184(%rbp), %rax        # m, tmp110
 43         leaq    32(%rax), %rcx  #, _6
 44         leaq    -160(%rbp), %rax        #, tmp111
 45         movq    -184(%rbp), %rdx        # m, tmp112
 46         movq    %rcx, %rsi      # _6,
 47         movq    %rax, %rdi      # tmp111,
 48         call    _ZNK8moleculeplERKS_@PLT        #
 49         jmp     .L27    #
 50 .L26:
 51 # function.cpp:22:              fr.add[0]=(this->id==0)? m[1]+m[0] : m[0]+m[1];
 52         movq    -184(%rbp), %rax        # m, tmp113
 53         leaq    32(%rax), %rdx  #, _7
 54         leaq    -160(%rbp), %rax        #, tmp114
 55         movq    -184(%rbp), %rcx        # m, tmp115
 56         movq    %rcx, %rsi      # tmp115,
 57         movq    %rax, %rdi      # tmp114,
 58         call    _ZNK8moleculeplERKS_@PLT        #
 59 .LEHE0:
 60 .L27:
 61 # function.cpp:22:              fr.add[0]=(this->id==0)? m[1]+m[0] : m[0]+m[1];
 62         movq    -168(%rbp), %rax        # <retval>, tmp116
 63         leaq    8(%rax), %rdx   #, _8
 64         leaq    -160(%rbp), %rax        #, tmp117
 65         movq    %rax, %rsi      # tmp117,
 66         movq    %rdx, %rdi      # _8,
 67         call    _ZN8moleculeaSEOS_      #
 68         leaq    -160(%rbp), %rax        #, tmp118
 69         movq    %rax, %rdi      # tmp118,
 70         call    _ZN8moleculeD1Ev        #
 71 # function.cpp:32:      return fr;
 72         jmp     .L24    #
 73 .L25:
 74 # function.cpp:25:              std::pair<molecule,molecule> p;
 75         leaq    -160(%rbp), %rax        #, tmp119
 76         movq    %rax, %rdi      # tmp119,
 77         call    _ZNSt4pairI8moleculeS0_EC1IS0_S0_Lb1EEEv        #
 78 # function.cpp:26:              p=m[0].split(this->id-2);
 79         movq    -176(%rbp), %rax        # this, tmp120
 80         movl    (%rax), %eax    # this_21(D)->id, _9
 81         leal    -2(%rax), %edx  #, _10
 82         leaq    -96(%rbp), %rax #, tmp121
 83         movq    -184(%rbp), %rcx        # m, tmp122
 84         movq    %rcx, %rsi      # tmp122,
 85         movq    %rax, %rdi      # tmp121,
 86 .LEHB1:
 87         call    _ZNK8molecule5splitEj@PLT       #
 88 # function.cpp:26:              p=m[0].split(this->id-2);
 89         leaq    -96(%rbp), %rdx #, tmp123
 90         leaq    -160(%rbp), %rax        #, tmp124
 91         movq    %rdx, %rsi      # tmp123,
 92         movq    %rax, %rdi      # tmp124,
 93         call    _ZNSt4pairI8moleculeS0_EaSEOS1_ #
 94         leaq    -96(%rbp), %rax #, tmp125
 95         movq    %rax, %rdi      # tmp125,
 96         call    _ZNSt4pairI8moleculeS0_ED1Ev    #
 97 # function.cpp:27:              fr.cut=true;
 98         movq    -168(%rbp), %rax        # <retval>, tmp126
 99         movb    $1, (%rax)      #, fr_19(D)->cut
100 # function.cpp:28:              fr.del[0] = m[0];
101         movq    -168(%rbp), %rax        # <retval>, tmp127
102         leaq    72(%rax), %rdx  #, _11
103         movq    -184(%rbp), %rax        # m, tmp128
104         movq    %rax, %rsi      # tmp128,
105         movq    %rdx, %rdi      # _11,
106         call    _ZN8moleculeaSERKS_     #
107 # function.cpp:29:              fr.add[0] = p.first;
108         movq    -168(%rbp), %rax        # <retval>, tmp129
109         leaq    8(%rax), %rdx   #, _12
110         leaq    -160(%rbp), %rax        #, tmp130
111         movq    %rax, %rsi      # tmp130,
112         movq    %rdx, %rdi      # _12,
113         call    _ZN8moleculeaSERKS_     #
114 # function.cpp:30:              fr.add[1] = p.second;
115         movq    -168(%rbp), %rax        # <retval>, tmp131
116         addq    $40, %rax       #, _13
117         leaq    -160(%rbp), %rdx        #, tmp132
118         addq    $32, %rdx       #, tmp133
119         movq    %rdx, %rsi      # tmp133,
120         movq    %rax, %rdi      # _13,
121         call    _ZN8moleculeaSERKS_     #
122 .LEHE1:
123 # function.cpp:25:              std::pair<molecule,molecule> p;
124         leaq    -160(%rbp), %rax        #, tmp134
125         movq    %rax, %rdi      # tmp134,
126         call    _ZNSt4pairI8moleculeS0_ED1Ev    #
127 # function.cpp:32:      return fr;
128         jmp     .L24    #
129 .L34:
130         movq    %rax, %rbx      #, tmp137
131 # function.cpp:25:              std::pair<molecule,molecule> p;
132         leaq    -160(%rbp), %rax        #, tmp135
133         movq    %rax, %rdi      # tmp135,
134         call    _ZNSt4pairI8moleculeS0_ED1Ev    #
135         jmp     .L31    #
136 .L33:
137         movq    %rax, %rbx      #, tmp136
138 .L31:
139         movq    -168(%rbp), %rax        # <retval>, tmp140
140         movq    %rax, %rdi      # tmp140,
141         call    _ZN14functionResultD1Ev #
142         movq    %rbx, %rax      # tmp136, D.69132
143         movq    %rax, %rdi      # D.69132,
144 .LEHB2:
145         call    _Unwind_Resume@PLT      #
146 .LEHE2:
147 .L24:
148 # function.cpp:33:      }
149         movq    -168(%rbp), %rax        # <retval>,
150         movq    -24(%rbp), %rbx # D.69134, tmp142
151         xorq    %fs:40, %rbx    #, tmp142
152         je      .L32    #,
153         call    __stack_chk_fail@PLT    #
154 .L32:
155         addq    $184, %rsp      #,
156         popq    %rbx    #
157         popq    %rbp    #
158         .cfi_def_cfa 7, 8
159         ret
160         .cfi_endproc

我不是汇编代码专家,我看不出哪里出错了...

0 个答案:

没有答案