Linux Application Debugging Using DS-5

This tutorial takes you through the process of creating a simple "Hello World" Linux application and then loading the application on a Cortex-A9 Fixed Virtual Platform (FVP) model running Arm embedded Linux. The Cortex-A9 Fixed Virtual Platform (FVP) model is provided with DS-5.



This tutorial assumes that you have installed Arm DS-5 and acquired the license to use it. If not, use the Getting Started with Arm DS-5 tutorial to install DS-5 and acquire a license.

Creating a Simple Hello World Linux Application using C

To create a Linux application using C in DS-5:

  • Create a new C project and use the DS-5 GCC toolchain.
  • Set up the DS-5 GCC toolchain compiler and linker options to build with the appropriate settings for Arm Embedded Linux running on a Fixed Virtual Platform (FVP) model.
  • Create the source file and build it to create an application.

Creating a New C Project

  1. Start DS-5 and from the DS-5 main menu, select File > New > C Project to display the C Project dialog.
  2. In the C Project dialog:
    1. In the Project name field, enter HelloWorld_GCC as the name of your project.
    2. Under Project type, select Executable > Empty Project.
    3. Under Toolchains, select the GCC 4.x [arm-linux-gnueabihf] (DS-5 built in)option.


    4. Click Finish to create a C project called HelloWorld_GCC.

      You can view the project in the Project Explorer view.


Configuring the Settings for New Project

  1. In the Project Explorer view, right-click the HelloWorld_GCC project, and select Properties.

    Tip: You can also access the project properties from the main DS-5 menu. From the main menu, select Project > Properties.

  2. Select C/C++ Build > Settings > Tool Settings tab.
    1. You need to specify the relevant flags under GCC C Compiler 4 [arm-linux-gnueabihf] > Miscellaneous > Other flags:
      • DS-5 v5.21.1 and earlier support a soft-float file system, so enter:

        -marm -march=armv4t -mfloat-abi=soft

      • DS-5 v5.22 and later support a hard-float file system, so enter:

        -marm -mfloat-abi=hard

      These flags instruct the GCC compiler to compile a binary that is compatible with a particular architecture and file system.

      For more information about GCC compiler options for Arm, see:

    2. On the Properties for HelloWorld_GCC project dialog, click OK to apply the settings and close the dialog.

Creating the Source Code and Building the Project

  1. In the Project Explorer view, right-click the HelloWorld_GCC project and select New > Source File.

    New Source file

  2. In the New Source File dialog, enter the file name HelloWorld_GCC.c.


  3. Click Finish to create the source file and open it in the code editing view.

    Code Editing view

    The source file is also visible in the Project Explorer view, under the HelloWorld_GCC project.


  4. Add the following code to the new source file, and press CTRL+S to save it.
    #include <stdio.h> 
    int main(int argc, char** argv) 
          printf("Hello world\n");
          return 0; 
    What is argc and argv?

    argc and argv are how command line arguments are passed to main() in C and C++.

    argc will be the number of strings pointed to by argv.

    The variables are named argc (argument count) and argv (argument vector) by common convention.

  5. In the Project Explorer view, right-click the HelloWorld_GCC project and select Build Project.

    This creates the Linux executable and required support files.


    The items in the Debug folder are additional files required for debugging.

Debug the Linux Application on a Fixed Virtual Platform (FVP) Model

Once you have created the project and built the code, launch the debugger to run the application on one of the Fixed Virtual Platform (FVP) models provided with DS-5.

For this tutorial, we use the FVP_VE_Cortex-A9x4 model provided with DS-5.

Creating a DS-5 Debug Configuration and Connecting to an FVP Model

  1. From the DS-5 main menu, select Run > Debug Configurations.
  2. In the Debug Configurations dialog:
    1. Select DS-5 Debugger.
    2. Click the New launch configurations button.


      This creates a new DS-5 debug configuration and displays the various tabs required to specify settings for loading your application on the target.

      New Debug Configuration all tabs

  3. On the Debug Configurations dialog:
    1. Give a name to the debug configuration. For example, HelloWorld_Linux_FVP.
    2. In the Connection tab, select Arm FVP (Installed with DS-5) > Cortex-A9x4 pre-configured to boot Arm Embedded Linux > Linux Application Debug > Start gdbserver and debug target resident application.


      By default, a relative path to your workspace location is specified in the Host mount point field. This location is used by the /writeable directory specified in the Remote target mount point field.
    3. In the Files tab, and under Target Configuration > Application on target field, enter /writeable/HelloWorld_GCC/Debug/HelloWorld_GCC.

      This specifies that the HelloWorld_GCC application is available under the/writeable/HelloWorld_GCC/Debug/ location on the target.

    4. Under Files, select Load symbols from file, and click Workspace.
    5. In the Open dialog, select the HelloWorld_GCC application in the Debug folder.


    6. Click OK

      This sets the path to the file that contains the required symbols information.


    7. Select the Debugger tab, and select Debug from entry point.


    8. Click Debug to load the application on the target, and load the debug information into the debugger.
    9. In the Confirm Perspective Switch dialog that appears, click Yes.

      DS-5 connects to the FVP model, loads Linux on the FVP model, and displays the connection status in the Debug Control view.

      The application is loaded on the target, and has stopped at the entry point, ready to run.

Other views display information relevant to the debug connection.

For example:

  • The Commands view displays messages output by the debugger. Also use this view to enter DS-5 commands.

    Commands view

  • The C/C++ Editor view shows the structure of the active C, C++, or makefile. The view is updated as you edit these files.

    Editor view

  • The Disassembly view shows the loaded program in memory as addresses and assembler instructions.

    Disassembly view

    At line Indicates the location in the code where your program is stopped. In this case, it is at themain() function. The view shows other information that enables you to drill down into the details of the code.

  • The Memory view shows how code is represented in the target memory. For example, to view how the string Hello World from the application is represented in memory:
    1. Open the Memory view.
    2. In the Address field enter, 0x00008440 and press Enter on your keyboard. The view displays contents of the target's memory.
    3. Select and highlight the words Hello World to see their ASCII equivalents.

      Memory view

      The Memory view displays the hexadecimal values for the code, and also the ASCII character equivalent of the memory values.

  • Click Continue Button to run the application.

    You can view the application output in the App Console view.

    App console view

Stepping Through the Application

Use the controls provided in the Debug Control view to step through the application.

Continue Button - Click to continue processing code.

Pause Button - Click to interrupt or pause processing code.

Step Through button - Click to step through the code.

Step Over button - Click to step over source line.

Step Out button - Click to step out.

Step instruction - This is a toggle. Select this if you want the above controls to step through instructions.

Disconnecting from the Debug Connection

To disconnect from a debug connection, you can:

  • Right-click the connection and select Disconnect from Target,
  • or select the connection and in the Debug Control view toolbar click Disconnect button,
  • or double-click on the selected connection.