Checkbox
Checkbox
Status
Done
Summary : learn how to use command line to code, compile and debug.
- Compile
program
into executable file:gcc -o program program.c
Execute:./program
- Install local C Compiler:
sudo apt install build-essential cgdb valgrind
gcc -g -o program program.c
will causegcc
to store information in the executable program for debugging.
- use
gdb program
to usegdb
to debug; - print the information of the program:
list
list m, n
: print the code from line m to line n;- Set a breakpoint:
break ...
(line number) info breakpoints
: show the information of all breakpoints;delete
: delete all the breakpoints;delete ...
: delete breakpoint of line …;run
: usegdb
to run program;step
andnext
will cause the program to execute a single line. The difference is that when coming up with functions,step
will enter it whilenext
will not.- If the program needs interactive input, then enter inputs while using
gdb
to run the program, or redirection:(gdb) run < input.txt
or./program < input.txt
continue
: jump to the next breakpoint;p variable
orprint variable
: print the information of the variable;- Display the value of a variable after every step:
display variable
; - show a list of all variables an their values in the current function:
info locals
;