Source file test.cpp
#include <stdio.h> int func(int n) { int sum = 0, i; for (i = 0; i < n; i++) { sum += i; } return sum; } int main () { int i; long result = 0; for (i = 1; i <= 100; i++) { result += i; } printf("result[1-100] = %ld /n", result); printf("result[1-250] = %d /n", func(250)); }
Executable files compiled with debug information
g++ -g test.cpp -o test
Start gdb
gdb test
gdb commands
r, run, run the program
q, quit, quit gdb
l, llst, source lists
References:
With the GDB debugger (b)
With the GDB debugger (c)
With the GDB debugger (d)
Reproduced in: https: //www.cnblogs.com/gattaca/p/7582398.html