Use the -g flag to enable debugging information
gcc -g test.c -o test
gdb test
To set breakpoints in gdb, you can use the break command. For example, to set a breakpoint in the main function of the program, you can execute the following command:
(gdb) break main
This will set a breakpoint at the first line of the program's main function. You can also set breakpoints at filenames and line numbers, like this:
(gdb) break test.c:10
This will set a breakpoint at line 10 of the filename.c file.
To view all breakpoints currently set, use the info breakpoints command:
(gdb) info breakpoints
This will list all currently set breakpoints. If you want to delete a specific breakpoint, you can use the delete command and specify the number of the breakpoint you want to delete. For example, to delete breakpoint number 1, you can execute the following command:
(gdb) delete 1
If you want to delete all breakpoints, use the delete command without specifying a breakpoint number:
(gdb) delete
To run the program and stop it at a breakpoint, use the run command:
(gdb) run
When the program reaches the set breakpoint, gdb stops program execution and waits for further commands at the gdb prompt. You can use the print command to view the value of a variable, or the step command to execute the program line by line. To continue executing the program, use the continue command.