2016-10-21 7 views
0

私は以下のプログラムでテストしたいと思っています:s = "abc"のときは "f()"の中で壊れ、 "i"ならば値を見てください。gdbの条件付きブレークで使用されるSTL型/関数は、プログラムをクラッシュさせますか?

#include<string> 
using namespace std; 
int i=0; 
void f(const string& s1) 
{ 
    ++i; // line 6 
} 
int main() 
{ 
    string s="a"; 
    s+="b"; 
    s+="c"; 
    s+="d"; 
    s+="e"; 
    s+="f"; 
    return 0; 
} 

a.outをコンパイルして実行しても問題はありません。そうです、

(gdb) b main:6 if s.compare("abc")==0 
Breakpoint 1 at 0x400979: file 1.cpp, line 9. 

その後、私はクラッシュの別の種類を取得:

(gdb) r 
Starting program: /home/dev/a.out 

Program received signal SIGSEGV, Segmentation fault. 
__memcmp_sse4_1() at ../sysdeps/x86_64/multiarch/memcmp-sse4.S:1024 
1024 ../sysdeps/x86_64/multiarch/memcmp-sse4.S: No such file or directory. 
Error in testing breakpoint condition: 
The program being debugged was signaled while in a function called from GDB. 
GDB remains in the frame where the signal was received. 
To change this behavior use "set unwindonsignal on". 
Evaluation of the expression containing the function 
(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(char const*) const) will be abandoned. 
When the function is done executing, GDB will silently stop. 

Program received signal SIGSEGV, Segmentation fault. 

Breakpoint 1, __memcmp_sse4_1() at ../sysdeps/x86_64/multiarch/memcmp-sse4.S:1024 
1024 in ../sysdeps/x86_64/multiarch/memcmp-sse4.S 

は、GDBによって引き起こされ、このクラッシュです私はその後、私はにブレークポイントの宣言を変更した場合は、それを

g++ 1.cpp -g 
gdb a.out 
... 
(gdb) b main if strcmp(s.c_str(),"abc")==0 
Breakpoint 1 at 0x400979: file 1.cpp, line 9. 
(gdb) r 
Starting program: /home/dev/a.out 

Program received signal SIGSEGV, Segmentation fault. 
__strcmp_sse2_unaligned() at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:31 
31 ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S: No such file or directory. 
Error in testing breakpoint condition: 
The program being debugged was signaled while in a function called from GDB. 
GDB remains in the frame where the signal was received. 
To change this behavior use "set unwindonsignal on". 
Evaluation of the expression containing the function 
(__strcmp_sse2_unaligned) will be abandoned. 
When the function is done executing, GDB will silently stop. 

Program received signal SIGSEGV, Segmentation fault. 

Breakpoint 1, __strcmp_sse2_unaligned() at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:31 
31 in ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S 

をデバッグ、または私の命令?私のコマンドにランタイムの問題がある場合、なぜgdbはエラーを報告するだけでなく、プログラムをクラッシュさせるのでしょうか?

私はこのエラーの原因がなかったので、いくつかの説明を得ることを望みます。

(gdb) break main:6 

... break mainと同じようにgdbによって解釈されます

答えて

1

は何ここで起こっていることはあなたのコマンドがあることです。あなたにも、後者を入力することで、これを見ることができます:

(gdb) b main:6 
Breakpoint 1 at 0x400919: file q.cc, line 10. 
(gdb) b main 
Note: breakpoint 1 also set at pc 0x400919. 
Breakpoint 2 at 0x400919: file q.cc, line 10. 

、GDBはおそらく末尾の:6が無視されていることを警告するべきであるので、これは特有のものです。 (これは構文エラーになることを尋ねるバグを提出することをお勧めします)。

ファイルの特定の行で中断したい場合は、ソースファイル名を使用する必要があります。おそらくあなたは次のように入力することを意図していました:

(gdb) break main.cc:6 
関連する問題