Contents
Getting Started
Before we start to debug our first program a short information on possible errors and their causes. More information on errors, resp. corresponding signals by the OS are available via a browser or locally displaying the corresponding manual page with the command:
The sources used are available for download. To step through the sources the compiled binaries have to contain the so called symbol table and other debug information and the execution order of statements has to match the order in the code. Therefore sources have to be compiled with the debug flag -g and it is recommended to avoid any code optimization with flag -O0 (minus capital O zero).
This holds for all compilers but we will concentrate on gcc or g++, the open source compilers for C or C++ of the GNU project.
The first example will be available for debugging after the command:
Segmentation fault
indicating a Invalid memory reference.
Debugging starts with using the Debugger gdb of the GNU project
Browsing the source code we observe squares, which is declared in line 5 as pointer without allocating memory to it. Accessing the not allocated memory location for squares[0] causes the memory violation.
Ok. That was easy.
Footnotes:
- [1] This value is random and may change from run to run, with compiler version, ...