Debugging C++ with VSCode and GDB

Truth Hacker
Sep 9, 2016 · 2 min read

I still love VIM but I’ve got use to using VSCode for doing my Fullstack development, so I figured I use VSCode integrated debugger on Linux. I mean GDB console or DDD is so old school, VSCode is so much better!!!

If you’re using Linux with the KDE Windows manager I have a workaround on how to get VSCode working with GDB below.

To get started with setting up VSCode with GDB, simply click on the “Debugger” ICON shown along the left (it may be on your right side).

Next click on the “Debug” button along the top, this will create a file called “launch.json” under your project folder.

Change the JSON property “program” to be the path to your executable.

In my case, I have something like this,

“program”: “/home/<User>/tmp/bits/build/bits”,

You can also variables, since I have a build folder under my project I could change the above to:

“program”: “${workspaceRoot}/build/bits”,

I just hard-coded the absolute path to the executable “bits” that I want to debug. Make sure to put the value in quotes.

If you’re using Gnome or have an Xterm installed you’re good to go! If however you’re like me using KDE, you will get an error message saying:

“Unable to start debugging. No terminal is available to launch the debugger. Please install Gnome Terminal or XTerm.”

This is a bug with VSCode as it’s looking for either Gnome terminal or Xterm, but on KDE it’s called konsole. Well we can’t wait around for Microsoft to fix the bug, we got to get stuff done yesterday!!!

The fix is easy, open up a terminal and type the following commands.

cd /usr/bin
sudo ln -s ./konsole xterm

What we just did is create a symbolic link from xterm to konsole, this fools VSCode and keeps it happy.

Now hit the “Debug” button already and watch it work…..sweeet!!!!

You should see a terminal window popup and GDB running inside VSCode (remember to do a debug build and set your breakpoints).

Happy Debugging :D

Truth Hacker

Computer Scientist

More From Medium

Related reads

Related reads

Related reads

Josh Samuel
Aug 7, 2019 · 8 min read

109

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade