This is a cheatsheet of how to utilize GDB for cs50 and other applications through the command line

NOTES:

  • GDB stands for global debugger
  • It works on Linux OS, sometimes used with VI or VIM
  • GDB only works on executable, not source files like .c
  • Runs on the terminal, cmd prompt, bash, etc

Running GDB is done by the following, navigate to the file first using cd

1
$ GDB ./copy

At this point, can specify any argv[1] or argv[2] things to add on (inputs)

1
$

./copy, where copy is the executable file

1
break main

add a break in the main function

1
$ r

R stands for run, runs the program

1
$ quit

CTRL+C does not work to exit out of GDB


Debugger vs GDB

Debugger through CS50 is more-so on the IDE side

  • Works on source file
  • Compiles the program in real time

Resources

  • http://cs50.stackexchange.com/questions/21681/how-do-you-pass-arguments-into-gdb-argv1-argv2/21682#21682, my question on stackoverflow great answer
  • https://www.reddit.com/r/cs50/comments/44x3dy/program_command_line_args_using_ide_gdb/

Vincent Tang

Comments