Set a breakpoint The first step in setting a conditional breakpoint is to set a breakpoint as you normally would. I.e. (gdb) break <file_name> : <line_number> (gdb) break <function_name> This will set a breakpoint and output the breakpoint number Check breakpoints If you forget which breakpoints you can add a condition to, you can list the breakpoints using: (gdb) info breakpoints Set a condition for a breakpoint Set an existing breakpoint to only break if a certain condition is true: (gdb) condition <breakpoint_number> condition The condition is written in syntax similar to c using operators such as == != and <. |
break 줄여서 br
$ gdb factorial Reading symbols from factorial...done. (gdb) br 28 Breakpoint 1 at 0x11bf: file factorial.c, line 28. (gdb) condition 1 i > 5 |
아래 소스에서 28라인 i++ 에 break를 걸고, 해당 라인에서 i > 5 인 조건에서 잡히게 한다.
반복문의 경우 확실히 디버깅 할 때 편할 듯.
//This program calculates and prints out the factorials of 5 and 17 #include <stdio.h> #include <stdlib.h> int factorial(int n); int main(void) { int n = 5; int f = factorial(n); printf("The factorial of %d is %d.\n", n, f); n = 17; f = factorial(n); printf("The factorial of %d is %d.\n", n, f); return 0; } //A factorial is calculated by n! = n * (n - 1) * (n - 2) * ... * 1 //E.g. 5! = 5 * 4 * 3 * 2 * 1 = 120 int factorial(int n) { int f = 1; int i = 1; while (i <= n) { f = f * i; i++; // 28 line } return f; } |
[링크 : https://www.cse.unsw.edu.au/~learn/debugging/modules/gdb_conditional_breakpoints/]
'프로그램 사용 > gdb & insight' 카테고리의 다른 글
gdbserver taget (0) | 2023.07.19 |
---|---|
gdb 디버깅 타겟을 인자와 함께 실행하기 (0) | 2022.10.17 |
gdb break (0) | 2021.04.09 |
gdb/insight target window (0) | 2010.05.19 |
insight/gdb 우분투에서 컴파일하기 실패 - insight/gdb compiling on ubuntu failed (2) | 2010.05.18 |