Linux Application Debugging Using DS-5
Introduction
Prerequisites
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
- Start DS-5 and from the DS-5 main menu, select File > New > C Project to display the C Project dialog.
- In the C Project dialog:
- In the Project name field, enter HelloWorld_GCC as the name of your project.
- Under Project type, select Executable > Empty Project.
- Under Toolchains, select the GCC 4.x [arm-linux-gnueabihf] (DS-5 built in)option.
- 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
- 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.
- Select C/C++ Build > Settings > Tool Settings tab.
- 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: http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html
-
- On the Properties for HelloWorld_GCC project dialog, click OK to apply the settings and close the dialog.
- You need to specify the relevant flags under GCC C Compiler 4 [arm-linux-gnueabihf] > Miscellaneous > Other flags:
Creating the Source Code and Building the Project
- In the Project Explorer view, right-click the HelloWorld_GCC project and select New > Source File.
- In the New Source File dialog, enter the file name HelloWorld_GCC.c.
- Click Finish to create the source file and open it in the code editing view.
The source file is also visible in the Project Explorer view, under the HelloWorld_GCC project.
- 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
andargv
?argc
andargv
are how command line arguments are passed tomain()
in C and C++.argc
will be the number of strings pointed to byargv
.The variables are named
argc
(argument count) andargv
(argument vector) by common convention. - 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
- From the DS-5 main menu, select Run > Debug Configurations.
- In the Debug Configurations dialog:
- Select DS-5 Debugger.
- 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.
- On the Debug Configurations dialog:
- Give a name to the debug configuration. For example, HelloWorld_Linux_FVP.
- 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.
- 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.
- Under Files, select Load symbols from file, and click Workspace.
- In the Open dialog, select the HelloWorld_GCC application in the Debug folder.
- Click OK
This sets the path to the file that contains the required symbols information.
- Select the Debugger tab, and select Debug from entry point.
- Click Debug to load the application on the target, and load the debug information into the debugger.
- 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.
- The C/C++ Editor view shows the structure of the active C, C++, or makefile. The view is updated as you edit these files.
- The Disassembly view shows the loaded program in memory as addresses and assembler instructions.
Indicates the location in the code where your program is stopped. In this case, it is at the
main()
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:- Open the Memory view.
- In the Address field enter,
0x00008440
and press Enter on your keyboard. The view displays contents of the target's memory. - Select and highlight the words
Hello World
to see their ASCII equivalents.The Memory view displays the hexadecimal values for the code, and also the ASCII character equivalent of the memory values.
- Click
to run the application.
You can view the application output in the App Console view.
Stepping Through the Application
Use the controls provided in the Debug Control view to step through the application.
- Click to continue processing code.
- Click to interrupt or pause processing code.
- Click to step through the code.
- Click to step over source line.
- Click to step out.
- 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
,
- or double-click on the selected connection.