글쎄, 이상하다. gdb를 사용하여 내 프로그램 중 하나를 디버깅하려고했다. 여기 GDB가 지정된 중단 점 대신 함수 끝에서 중단됩니다.
내가하지만, 내가 라인 149에 중단 점을 설정이었다 않았다 그래서g++ -g -O2 -std=gnu++0x -static -Wall -Wextra -std=c++11 -Isrc -rdynamic -fomit-frame-pointer -o addrev.out addrev.cpp
을 사용하여 파일을 컴파일 된 스크립트가
137
138 void solve() {
139 string input1, input2;
140 cin >> input1;
141 cin >> input2;
142 reverse(input1.begin(), input1.end());
143 reverse(input2.begin(), input2.end());
144 ll i1 = atoi(input1.c_str());
145 ll i2 = atoi(input2.c_str());
146 cout << i1<<" "<<i2;
147 ll out = i1+i2;
148 while(out%10 == 0) {
149 out = out%10;
150 cout << out;
151 cout <<"per: "<< out%10<<endl;
152 }
153 cout << "Sum: "<<out;
154 string output = to_string(out);
155 reverse(output.begin(), output.end());
156 cout << endl;
157 cout << output << '\n';
158 }
159
160 int main(int argc, char **argv) {
161 //string s = (argc == 1) ? argv[0] : "file.test";
162 //freopen(s.substr(s.find("/") + 1,s.rfind(".")-2).append(".test").c_str(),"r",stdin);
163 ll t,j;
164 scanf("%lld",&t);
165 while(t--) {
166 solve();
167 }
168 return 0;
169 }
코드의 관련 부분입니다 내가 그것을 실행할 때, 나는 결코 언급하지 않은 158에서 깨진다.
-rw-r--r--. 1 chaudhary chaudhary 5.4K Nov 15 23:17 addrev.cpp
-rwxrwxr-x. 1 chaudhary chaudhary 87K Nov 15 23:17 addrev.out*
[email protected]:~/code/codpro/spoj$ gdb addrev.out
GNU gdb (GDB) Fedora 7.7.1-21.fc20
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from addrev.out...done.
(gdb) b 149
Breakpoint 1 at 0x40186c: file addrev.cpp, line 149.
(gdb) l 149
144 ll i1 = atoi(input1.c_str());
145 ll i2 = atoi(input2.c_str());
146 cout << i1<<" "<<i2;
147 ll out = i1+i2;
148 while(out%10 == 0) {
149 out = out%10;
150 cout << out;
151 cout <<"per: "<< out%10<<endl;
152 }
153 cout << "Sum: "<<out;
(gdb) r < addrev.test
Starting program: /home/chaudhary/code/codpro/spoj/addrev.out < addrev.test
42 1Sum: 43
34
Breakpoint 1, solve() at addrev.cpp:158
158 }
(gdb) c
Continuing.
8534 457Sum: 8991
1998
Breakpoint 1, solve() at addrev.cpp:158
158 }
(gdb) c
Continuing.
503 4970per: 0
0per: 0
0per: 0
0per: 0
0per: 0
0per: 0
.
.
.
Infinite loop
대신 중단 점의 함수의 끝에서 휴식 왜 어떤 특별한 이유가 여기있다 :
은 GDB의 출력됩니다.
최적화를 사용하여 디버깅해서는 안됩니다. '-O0' 또는'-Og' 사용 – Rapptz
디버깅을 목표로 할 때 컴파일러 명령 줄에서 대부분의 최적화 플래그를 제거 할 것입니다.'-fomit-frame-pointer'도 삭제해야합니다. – didierc