Introduction
Prerequisites
C or C++. You should have written C or C++ code, compiled an executable and run it.
command line interface or VS Code. You should know how to move to a folder, list files, compile
See here for an introduction to the Linux shell.
Installation
Learning Outcomes
- After this course you will
Know which tools to use to inspect your code and find problems (or know where to check which tools to use).
Know what a segmentation fault is and be able to locate it.
Be able to use a debugger (after finding references online).
Be able to find memory leaks and other memory issues.
The tools used on this course are also used to debug Fortran and other compiled languages. Each language has their own quirks and common problems, so the first sections do not apply.
Debugging
Debugging is the skill of identifying why a program does something unexpected. There is a bug when the user expects something to happen, but the program does something different. It could be something very clear, like throwing an exception, or it could be a misleading UI or weird interaction between parts of the program.
We will mainly concentrate on tools that allow you to find issues and inspect the internal state of you program as it run.
Debugging in five steps
Identify an issue
Find a problem or receive a report from a user.
Get a Segmentation Fault.
Find an issue using an analysis tool.
Isolate the bug
Reproduce the problem
Create a minimal case that causes the problem to occur.
(Turn this into a test case)
Find the erroneous logic
This can be in a single location, or an interaction between different parts of the code
Fix the bug
Replace the bad code or redo logic
Test
Check that the bug is no longer reproduced
Check that everything that used to work still works.
We will mostly concentrate on finding the problem in the code. How you find an issue or receive a report depends a lot on your project and is not language specific.
When you publish your code, make sure to include a way for users to communicate back to you. For example, if you are using a public service such as Github, Gitlab or Bitbucket enable issues.