Usage practice of clion debug mode


1、 Background

Recently, in order to take the postgraduate entrance examination, I began to use C language and data structureVisual Studio 2019As an editor, but I’m not used to it;

I’ve been using the editor of JetBrains company before, and I just found that C language can be usedCLionHowever, it is found that it will not use its debugging function. Sometimes, in order to debug the code, you need to copy the code toVisual Studio 2019In the editor; Later, I felt it was too troublesome. After groping for some time, I finally found the debugging method of clion. Record the method and give it to the students who need it.

2、 Start debugging

Open clion and create a new project; Then select the following menu from the menu
file->settings->Build、Execution、Deployment->Debugger->Data Views->C/C++

findEnable NatVis renderes for LLDB DiagnosticschoiceVerbose, as shown in the figure below
Usage practice of clion debug mode

After selecting, click the button belowOKButton to confirm.

3、 Compile code

Now you need to edit some code randomly in the code. There needs to be variable assignment operation in the code to observe the debug mode. The reference code is as follows

#include <stdio.h>

int main() {
    int i = 0;
    while (i < 5) {
    return 0;

After writing the code, mark the variables to be observed. The marking method is to click the right side of the line number with the mouse, and a small red dot will appear, as shown in the figure below.
Usage practice of clion debug mode

Next, you can use the debug mode to observe the variable data. There is a green bug icon at the top right of the editor. Click this icon to enter the debug mode.

4、 Debug code

In the debug mode, you can see the current value of the variable in memory, as shown in the following figure
Usage practice of clion debug mode

When you need to continue the program, you need to click the red box in the middle, so that the program will execute next. At the same time, you can see that the value of the variable is also changing. At the bottom, you can see the variable list of the whole program and the corresponding value.

  • Author: Tang Qingsong
  • Date: September 14, 2021
  • Wechat: songboy8888

This work adoptsCC agreement, reprint must indicate the author and the link to this article