Andrew JohnsonJun 32 min read
C / C++ Debuggers on Linux : CLion setup and Initial Impressions
I’m attempting to find a decent linux C/C++ debugging solution. I’m going to try documenting my quest on this blog.
First up is CLion. I believe CLion is intended to be used as a full IDE for building CMake based projects, but using CMake on your project is not required in order to use it as a debugger.
I was able to set up CLion to debug a non-CMake built executable like this:
- Start CLion, Create a new project
- Name it whatever you want and put it where ever you want. This is just a throwaway project to allow you to use CLion’s interface to debug an executable of your choosing, so doesn’t even have to live inside your project’s directory. In fact, unless you want a cmake file in your project’s directory, don’t put it in there.
- Once in CLion, Run Menu > Edit Configurations. Click the “Build All” item on the left and hit the delete key. This step is not strictly necessary, but I find it makes things less confusing.
- You should now have just one configuration in the list with the same name as your project. Make sure it’s selected.
- On the right, select the Executable dropdown and choose Select Other. Set it to the debug build of your executable. Click Ok to close the dialog.
- Run Menu > Debug ‘yourprojectname’ will now launch your executable under the CLion debugger.
- Drag source files in or File > Open them and set breakpoints and it should work. Click on the Debugger tab at the bottom and there will be a callstack navigator as well as locals and watches, etc.
Like basically all current graphical linux debuggers, CLion is just a frontend for GDB .
My first impressions?
- Updates to the watch window when stepping are quite slow. Every time you step, it seems to remove all the items in the watch list and (very) lazily re-add them instead of just updating the values in-place. It can take a full second or more to see an update.
- There are emacs keybindings available in the settings, and a vim plugin. I tried the vim plugin and it seems decent enough for the basics.
- I can’t find a CPU registers view of any kind, which sucks. Hopefully I’m just missing it.
- No way to attach to an already running process yet
- No way to view assembly yet, it’s on their list
- Ability to inspect structures and arrays seems decent. In addition to the Watch view, you can also hover over a variable in the source code, wait for the tooltip to appear, then hit Ctrl+F1 to inspect it, including expanding its members, etc.
- During debugging, it shows the current value of any stack local variables next to their declarations, which can be handy.