프로그램 사용/gdb & insight
gdb conditional break
구차니
2023. 7. 19. 08:44
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/]