Git Product home page Git Product logo

debugging-intro-clion's Introduction

Debugging in CLion

CLion

CLion is an IDE for editing C code, it's a lot more powerful than a traditional text editor, and includes a lot of features. CLion can be downloaded and used for FREE with a student license (MAKE USE OF THIS!!!). For this demonstration we will only be considering some of the basic debugging tools offered in CLion, and only looking at the main.c file. To setting up CLion for the first time can be confusing, so I would suggest watching a youtube video going through it.

These notes are largely based on the video series from the official JetBrains YouTube channel which can be found here:

There is another video in this series, but it covers very advanced debugging, and likely won't be very useful, but if you are interested on debugging not only locally, then the video can be found here.

Breakpoints

Represented by dots in your IDE, next to line numbers. Click next to the line number to set a breakpoint to set the breakpoint.

Screenshot 2022-02-20 at 20 29 07

When a breakpoint is reached whilst running your program in debug mode (bug icon in the top right), your program will halt and you will be able to inspect all the data in your program. This is useful for monitoring and checking the state of variables, as well as structures which we can expand out to view all their information.

Screenshot 2022-02-20 at 20 31 13

Screenshot 2022-02-20 at 20 31 45

Step Over, Step Into, and Step Out

  • Step Over: Performs a single-line step over through your code
  • Step Into: Allows you to go into a function call deeper, and step through that function
  • Step Out: Will leave the current function you are in to go to the above level

Screenshot 2022-02-20 at 20 32 38

We are also able to 'run to cursor' which will make the code run until where your cursor is to save time.

Force: Force step over and force run to cursor will ignore breakpoints. Force step into will step into a function even if we don't have the source code for it, so we can see the 'disassembly' view.

Exception Breakpoints

Allow us to halt the program when an exception is found. Go to Run > View Breakpoints. Look at the Exception Breakpoints, and enable the setting for 'whenever an exception is thrown/caught'.

Screenshot 2022-02-20 at 20 33 36

Variable View

We can actively change the values of our variable during execution to see what happens in different events etc, by right clicking it and using Set Value. We can add watches to variables, pinning them to our view, even when they are out of scope, and we can also jump to variables, by right clicking and 'jump to source'.

Screenshot 2022-02-20 at 20 34 14

Advanced Breakpoints

We can make breakpoints conditional by using boolean expressions. Right click on a breakpoint and set the expression. Here is where we can also enable/disable breakpoints without removing them.

Non-Suspending Breakpoints

We can set breakpoints that don't break, which is useful for when we want to ensure a line passes, or check a value without manually passing through the breakpoint. We can log messages here. 'Remove once hit' allows us to have the breakpoint only break the flow once, and we can also set conditions for when this breakpoint should become active. These tips will save a lot of manual work time.

Screenshot 2022-02-20 at 20 35 24

Watchpoints

These are like breakpoints, but these break when data is read from or written to. So if we are trying to track down why our variable is changing in an unexpected way. Use the stack-trace to find where our variable has been changed from. These can be set again from right-clicking onto variables.

Screenshot 2022-02-20 at 20 36 18

There are more techniques not covered here, and if you want to check them out then do have a look at the videos linked above.

debugging-intro-clion's People

Contributors

jakedves avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.