Anjuta Manual version 0.1

Copyright (c) Kh. Naba Kumar Singh

Contents Index Shortcuts
PREV:Compiling, Building and executing Project UP:Contents(Debugging) NEXT:Breakpoints

Debugging:

To debug is human. To fix it is divine

Well, the human part is what I am going to deal here. The Divine part is yours. When a program does not behave according to what it is suppose to, we say the program contains bug or bugs. By bugs we don't mean the compilation errors. The compilation errors are simply errors and they are relatively easier to clear (because compiler tells you where they are). On the other hand, Bugs refer to those errors that happen during the execution of the program and they are hard, sometimes very hard, to detect.

Any program that you think is bug-free is never always bug-free. What we try to do is reduce the number of bugs contained in the program. The process of removing bugs is, therefore, called Debugging. And the tool that is used for debugging is called Debugger. Anjuta provides a very userfriendly and powerfull debugging environment (actually, a GUI wrappig over Gdb, a powerfull command line debugging tool).

A debugger tracks and traces the execution of the program and provides you the various information needed to study the execution of the program.

Debugger Targets:

Before we actually start debugging, let me briefly summarize what the debugging targets are. Debbuging targets refer to those entities that the debugger interacts during its operation. There are four types debugging targets. Namely:

  1. Executable
  2. Symbol table
  3. Core file
  4. Process

There can be, at most, only one target active for each of the four types of targets at any give time instance. All the targets may not be necessarily active for the debugger to work. But there are certain combinations of the above targets which are required to be active for a meaningful debugging session. Such as the combination of [ executable, symbol table, and Process ] or [ executable, symbol-table and core-file ].

The target Executable become active when you load an executable file into the debugger.

The target Symbol table is automatically loaded from the executable file, therefore you don't need to worry about it. The symbol table is necessary for the debugger to identify the various symbols in the source code of the program. The information is included into the executable during the compilation (You need to compile the program with the debug option enabled. See Setting Compiler options for details).

The target Core file becomes active when you load the core file into the debugger. Core file is the memory image of the program which was core-dumped by the kernel, usually because it had performed an illigal operation. The core file can give various information such as variable contents, register values, stack trace etc of the program at the time of core-dump. By studying the core file you can easily know which part of the program has misbehaved resulting in core-dump.

The target Process becomes active when you execute the program under the debugger or when you attach to an already running process.

Starting and Stoping Debugger:

To start the debugger, activate Debug->Start Debugger. This will start the debugger with the executable of the currently opened project. If there is no project opened, then it will load the executable of the currently active file. Otherwise, if there is neither a project opened or a file opened, then it won't load any executable, though the debugger will be started. You will have to load the executable yourself (see the next part: Loading executable).

Once the debugger is started, you will enter into debugging session. When you are done with the debugging session, you can exit the debugger by activating Debug->Stop Debugger.

Loading executable:

As mentioned above, debugger will automatically load the executable, if you have a project or a file opened. Later, if you want to load a different executable, activate the menu item Debug->Load Executable. A fileselection dialog box will appear. Select the executable you want to debug and click OK.

Loading Core file:

Activate Debug->Load Core file to load the core file. Select the core file in the fileselection dialog box and click OK. When you load the core file, make sure you have already loaded its executable file (and hence the symbol table). Otherwise, you won't feel happy while debugging.

If you get lots of question marks (??) during the debugging session, then the core file you have just loaded and the executable aren't matching.

Attaching and detaching a process:

You can attach to an already running process for debugging. Activate Debug->Attach to Process. You will be given a list of all the process running on your computer. Select the process you want to attach to and click OK. In this case also make sure you have first loaded the executabe (and hence the symbol table) into the debugger.

If you get lots of question marks (??) during the debugging session, then the process you are attaching to and the executable aren't matching.