Skip to content
Ivan edited this page Oct 9, 2018 · 21 revisions

This page is maintained by Ivan ...


Definitions

Debugging is the process of finding and resolving defects or problems within a computer program that prevent correct operation of computer software or a system.

Two tactics of debugging exists:

  1. By using debugging programs which includes user interface for step-by-step program running e.g. GNU Debugger.
  2. Output of the current state of the program using output statements located at critical points of the program on the monitor.

The GNU Project Debugger (GDB) is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, C, C++, Objective-C, Free Pascal, Fortran, Go, Java and partially others.

How to build a program to be used by GDB?

If you are using Linux, you probably already have GDB. You only have to follow the guide below. But if you are using Windows, you will need to use this guide on YouTube to install and this one to build program to be used by GDB there.

1. Open console. (Ctrl + Alt + T for Linux)

2. Open directory with your program file. (Use command "ls -al" to view your directory list. Use "cd 'path'")

3. Compile your program with "-g" key in order to include information about debugging into your running file. Write in console "gcc -g 'NameOfFile.c' -o 'NameOfRunFile'".

// GNU Debugger is usually used to debug C or C++ files.

4. And then you can upload your program into GDB. Write in console "gdb 'NameOfRunFile'" for Linux. If it works you will instantly appear in (gdb) console.

What is a breakpoint?

Breakpoint is a point in your program where GNU Debugger stops the program and then you can receive all current variables at this stage.

How to set up a breakpoint?

Type in (gdb) console:

break 'NumberOfLine' to set up the breakpoint at any line in your code;

break 'NameOfFunction' to set up the breakpoint at any function in your code you want.

and

clear 'NumberOfLine' to delete the breakpoint at any line in your code;

clear 'NameOfFunction' to delete the breakpoint at any function in your code you want.

It means that command "break" sets up the breakpoint for permanent using.

Clone this wiki locally