Main Navigation

Secondary Navigation

Page Contents

Contents

Introduction

Debugging is formally a part of the software testing process and mandatory if a program misbehaves. There are of course various strategies of finding errors in a program. The simplest one is debugging by print statements placed into the code. If you have a notion of the location of the error and a limited size of code, you can insert print statements, recompile, rerun, and hope for meaningful hints in the output. But this strategy is limited in its usability, certainly if

  • the noticeable error is caused by an error previous in code,
  • the amount of data to scan for the error is too large to inspect effectively,
  • you work on a parallel program with many threads or tasks to be checked.

Therefore the best way to debug is to let the computer do it, in case of memory problems, or to use an interactive debugger, a program that allows you to control the behaviour of a running program at arbitrary points thereby monitoring variables and their values.

In this tutorial the usage of valgrind for easy to use memory debugging, of gdb, which is the open source debugger of the GNU project, and the commercial TotalView debugger, which is licensed on Elwetritsch, will be explained and demonstrated. We will use a number of simple programs which may be downloaded for own practice.

For impatient readers here a list of related websites: