반응형
GDB 중단 점을 지정된 횟수에 도달 한 후에 만 중단하는 방법은 무엇입니까?
여러 번 호출되는 함수가 결국 세그 폴트가 발생합니다.
그러나이 함수에 중단 점을 설정하고 호출 될 때마다 중지하고 싶지 않습니다. 몇 년 동안 여기에있을 것이기 때문입니다.
counter
중단 점에 접근 할 수 있고 중단 점이 적중 할 때마다 카운터가 감소하고 counter
= 0 일만 트리거 고 들었습니다 .
내가 어떻게해야해야합니까? 지금 중단 점을 설정하기 위해 gdb 코드를 제공하십시오.
GDB 매뉴얼의 섹션 5.1.6 을 출시했습니다 . 해야 할 일은 먼저 중단 점을 설정 한 다음 해당 중단 점 번호에 대해 '무시 개수'를 설정하는 것 ignore 23 1000
입니다.
중단 점을 무시할 횟수를 모르고 수동으로 계산하고 싶지 않은 경우 다음이 도움이 될 수 있습니다.
ignore 23 1000000 # set ignore count very high.
run # the program will SIGSEGV before reaching the ignore count.
# Once it stops with SIGSEGV:
info break 23 # tells you how many times the breakpoint has been hit,
# which is exactly the count you want
continue <n>
이 마지막 히트 중단 점 n - 1
시간 을 건너 뛰고 n 번째 히트에서 중지 하는 방법입니다 .
main.c
#include <stdio.h>
int main(void) {
int i = 0;
while (1) {
i++; /* Line 6 */
printf("%d\n", i);
}
}
용법 :
gdb -n -q main.out
GDB 세션 :
Reading symbols from main.out...done.
(gdb) start
Temporary breakpoint 1 at 0x6a8: file main.c, line 4.
Starting program: /home/ciro/bak/git/cpp-cheat/gdb/main.out
Temporary breakpoint 1, main () at main.c:4
4 int i = 0;
(gdb) b 6
Breakpoint 2 at 0x5555555546af: file main.c, line 6.
(gdb) c
Continuing.
Breakpoint 2, main () at main.c:6
6 i++; /* Line 6 */
(gdb) c 5
Will ignore next 4 crossings of breakpoint 2. Continuing.
1
2
3
4
5
Breakpoint 2, main () at main.c:6
6 i++; /* Line 6 */
(gdb) p i
$1 = 5
(gdb)
(gdb) help c
Continue program being debugged, after signal or breakpoint.
Usage: continue [N]
If proceeding from breakpoint, a number N may be used as an argument,
which means to set the ignore count of that breakpoint to N - 1 (so that
the breakpoint won't break until the Nth time it is reached).
반응형
'ProgramingTip' 카테고리의 다른 글
HTML 이메일 작성시 모범 사례 및 고려 사항 (0) | 2020.10.07 |
---|---|
HTML5를 사용하여 클라이언트 확인 파일 크기? (0) | 2020.10.07 |
Java 소켓 API : 연결이 닫혔는지 확인하는 방법은 무엇입니까? (0) | 2020.10.07 |
Amazon S3 업로드 파일 및 URL 가져 오기 (0) | 2020.10.07 |
CSS 전환 중 Webkit 텍스트 변경을 방지하는 방법 (0) | 2020.10.07 |