- 论坛徽章:
- 1
|
本帖最后由 asker160 于 2016-10-25 11:17 编辑
我想让我下面的代码,当s="abc"的时候, 断到"f()"函数里面,让我能查看"i"的值。
- #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;
- }
复制代码 编译运行,没有问题。但是调试呢?
- g++ 1.cpp -g
- gdb a.out
- ...
- (gdb) b main:6 if strcmp(s.c_str(),"abc")==0
- Breakpoint 1 at 0x400979: file 1.cpp, line 9.
复制代码 然后我运行它,看起来是我的程序或者gdb自己崩溃了:
- (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) 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还是我的程序收到了段错误的信号? 原因是什么?
|
|