-g flag:gcc -g main.c -o main # for C
g++ -g main.cpp -o main # for C++
gdb ./maingdb --args ./main arg1 arg2
-tui will start it looking like GUI in the terminal.set tui mouse on to activate mouse support.(gdb) run [arguments]break mainbreak foo.c:42break *0x004012abbreak *mainbreak *main + 12break *($pc + 4)
info break or info breakpointsdisable: disable all breakpoints.disable <id> or disable <start-id>-<end-id>: disable specific breakpoint(s).enable: enable all breakpoints.enable <id> or enable <start-id>-<end-id>: enable specific breakpoint(s).delete: delete all breakpoints.delete <id> or delete <start-id>-<end-id>: delete specific breakpoint(s).(gdb) clear foo.c:42(gdb) clear my_func
break foo if i > 10 && p != NULLignore 5 10step [n]: To execute one line of code, if the current line calls a function, stops at the first line inside it.next [n]: To execute one line of code, executing any called functions completely.stepi [n]: executes exactly one machine instruction and then stops.nexti [n]: executes one machine instruction but if that instruction is a call, GDB runs the entire call and stops at the instruction after the call.(gdb) print i
(gdb) print &i
(gdb) print a + b
(gdb) print *ptr
(gdb) print arr[3]
(gdb) print *(struct node*)ptr
(gdb) print ((int*)buf)[3]
(gdb) p /x i # hex
(gdb) p /d i # signed dec
(gdb) p /u i # unsigned dec
(gdb) p /t i # binary
(gdb) p /c ch # char
set print pretty on(gdb) info locals # Shows all local variables in the current stack frame.
(gdb) info args # Lists all function arguments for the current stack frame.
(gdb) info registers
(gdb) print $pc, print $sp, print $fp # architecture-specific names valid
(gdb) set var i = 42
(gdb) set {int}0x7fffffffde20 = 123
x/[COUNT][FORMAT][SIZE] <ADDRESS>x: hex.d: dec.u: unsigned.t: binary.c: char.s: c-string (prints chars until '\0').i: instruction.f: float.b: 1h: 2w: 4g: 80x7fff, ptr, &arr[0]).continue: resumes until any stop condition.continue N: resumes after ignoring N breakpoints.