Debug Application


This how-to describes the process of debugging an application on the target with GDB.


Table of Contents

Task Dependencies (Pre-requisites)


Tools Required

  • GDB server on the target filesystem
  • GDB client on the host

Input Files Required

  • Application for debug

Output Files Produced

  • None

Task Description

Preparing for debug

GDB will need the application binary to contain debugging information. For this, the application needs to be compiled with the '-g' flag:
The application binary needs to be copied over to the target filesystem. If the GDB server is not present on the target filesystem, gdbserver will also need to be compiled and transferred to the target filesystem. The instructions on the Add Files to Running Linux page may be followed for this task.

The IP of the target machine will need to be used later:

Starting the debug server

In order to debug the application a GDB server must be run on the target machine. Execute the following command to start a GDB server for the given application:
The <port> used to connect to the GDB server may be set to 1234 (or any other free port).

Debugging the application

Now that the server is running a GDB client can connect to the server to perform debugging:
Once the GDB client is running instruct it to connect to a remote server:
Set a breakpoint on "main" and "cont"inue the application:
At this point the host machine terminal should look similar to the following:
The next line of code can be run with the "next" or "n" command:

Related Links