First make sure the symbols are in the execution. For GCC you should use -g flag. For letting compiler to generate more warnings, use -Wall flag.
g++ -Wall -g file.cpp
gdb a.out
gdb --args a.out arg1 arg2
set args arg1
gdb -tui
layout src
layout asm
layout reg
tui enable
tui disable
By default it's empty. You need to run the program to see the code. You can press arrow up or down to scroll the source code.
run
If you enter run again, it restart the execution.
start
backtrace full
next
n
step
finish
break line_number
break function_name
info break
clear line_number
clear function_name
watch variable
First run
info watchpoint
To see watch number, then
delete watch_number
refresh
You can also use CTRL+L shortcut
continue
Let's assume we have:
vector<int> v{1, 2, 3};
int a1[3] = {1, 2, 3};
int* a2 = int[3]{1, 2, 3};
print variable
print v[0]
print v
print a1
print *a2@3