Skip to content

Instantly share code, notes, and snippets.

@mjm522
Last active November 13, 2020 15:59
Show Gist options
  • Save mjm522/ce18ac2824f421c23479ccdadb612a89 to your computer and use it in GitHub Desktop.
Save mjm522/ce18ac2824f421c23479ccdadb612a89 to your computer and use it in GitHub Desktop.
GDB C++ Debugging

When your program runs, do the first instruction. If it is causing segmentation fault, put a while true or cin in the start of main loop, execute it. So it will be caught up in the while loop or may be waiting for the input. When it happens, run the first instruction to get the name of your executable.

First open a terminal and then type:

ps ax | grep <name of your executable>

This would list the complete path to the executable with any arguments present.

/<path to executable>/<name of the executable> --<arguments>

Next to debug using GDB, open a terminal and then type.

gdb --args "<result you got after step 1>" 

that is:

gdb --args "/<path to executable>/<name of the executable> --<arguments>"

Once, gdb opens, type hit enter to start, you can increment through the steps by pressing "r" and hitting enter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment