How To Create and Debugging Linux Applications Using Sourcery Codebench For Arm Gnu Linux
How To Create and Debugging Linux Applications Using Sourcery Codebench For Arm Gnu Linux
w w w.m e n t o r.c o m
H O W - T O W H I T E P A P E R
Creating and Debugging Linux Applications Using Sourcery CodeBench for ARM GNU/Linux
INTRODUCTION
These steps give an example of using Mentor Embedded Sourcery CodeBench Professional to create and debug an application that will run on a target running Linux. These steps were tested on a PandaBoard using the Mentor Embedded Linux Kit for PandaBoard kernel image, rootfs, u-boot, and MLO.
PREREQUISITES
Install CodeBench for ARM GNU/Linux Professional 2011.09 on Linux. Download and install the free Mentor Embedded Linux Kit for PandaBoard from http://www.mentor.com/embedded-software/downloads/linux-kits/. Follow the instructions in the PandaBoard Installation and Getting Started Guide to configure your SD card and boot the PandaBoard using the Mentor Embedded Linux Kit for PandaBoard images.
PROCEDURE
1. From the Host machine, start CodeBench for ARM GNU/Linux. 2. Create and build an application. 3. Set up your debug launch configuration and debug your application.
PROCEDURE
1. From CodeBench, select File > New > C or C++ Project. The New Project wizard opens.
a. Give your project a name and select the type of project to create. To start with example code, from the Project type area, select Executable > Factorial C Project. b. Click Next. This opens the Configuration page of the Project wizard. c. From the Processor list, select Cortex-A9. Note: We are using sysroot from the Mentor Embedded Linux Kit for PandaBoard, which is at the file system root location. If the sysroot on the target is not at the file system root location, enter the pathname to the location of the installed sysroot on the target. See also: Installing runtime support files on the target. d. Click Finish to create the project. 2. Add files to your project.
w w w. m e nto r. co m
Creating and Debugging Linux Applications Using Sourcery CodeBench for ARM GNU/Linux
3. Add the path to the include files and libraries in your project: a. From the Project Explorer, right-click the project and select Properties. This opens the Properties dialog box for the project. b. On the left of the Properties dialog box, expand C/C++ Build and select Settings. This displays the Settings pane on the right side of the Properties window.
c. From the Settings pane, select the Tool Settings tab. i. To add include paths, expand Sourcery CodeBench C/C++ Compiler and select Includes. ii. To add library paths, expand Sourcery CodeBench C Linker and select Libraries. Add any libraries that your project uses to the Libraries list. d. Click Apply to apply your changes. e. Click OK to close the Properties dialog box. 4. To build your project, right-click the project and select Build Project.
w w w. m e nto r. co m
Creating and Debugging Linux Applications Using Sourcery CodeBench for ARM GNU/Linux
NEXT STEP
Set up your debug launch configuration and debug your applications.
PREREQUISITES
Create and build an application. See Creating and Building an Application for the PandaBoard Using CodeBench. The PandaBoard must be booted and running Linux which is configured to support SSH and gdbserver. NOTE: If youre using the rootfs that ships with MEL-Lite for PandaBoard, this requirement is already met.
PROCEDURE
1. Select your project in the C/C++ Projects view. 2. Create a Debug launch configuration for your project: a. Select Run > Debug Configurations. This opens the Debug Configurations dialog box.
3. Select the Sourcery CodeBench Debug launch group and click New launch configuration.
w w w. m e nto r. co m
Creating and Debugging Linux Applications Using Sourcery CodeBench for ARM GNU/Linux
a. Enter a Name. b. Select Copy and launch application on remote system. c. Select the Connection for the target. If a connection to the remote system does not exist, click New to create one. This opens the New Connection dialog box. i. Enter the IP address for the target in the Host name field and enter a Connection name to label this connection.
Creating and Debugging Linux Applications Using Sourcery CodeBench for ARM GNU/Linux
d. Optionally, in the Remote path field, enter the path to the location to download your application to on the target with a filename for the application. If you dont do this, your application is downloaded to $HOME. e. Click Apply. 5. Select the Debugger tab for the launch configuration. a. Select the Shared Libraries tab and do the following: i. Select the Translate the specified shared library pathnames and set the pathname on target to the location of the sysroot that you setup on the PandaBoard. See Installing runtime support files on the target. ii. If you have additional shared libraries, click Add to add them to the Additional shared library directories list. iii. Click Apply. b. Select the Connection tab and to the following. i. Enter the Host name or IP address for the target. ii. Set the Port number to 10000. iii. Click Apply.
6. Click Debug to download your application to the target and begin debugging.
w w w. m e nto r. co m
Creating and Debugging Linux Applications Using Sourcery CodeBench for ARM GNU/Linux
7. If the Enter Password dialog box opens, enter the user ID and password for your kernel. For the MEL-Lite for PandaBoard kernel, the User ID is Root and there is no password, so leave the password field blank:
RESULTS
This copies your application to the target and starts your debugging session, which opens the Debug Launch Configuration. Refer to the Sourcery CodeBench Debugger documentation (Help > Help Contents) for more information about debugging with GDB.
w w w. m e nto r. co m
Creating and Debugging Linux Applications Using Sourcery CodeBench for ARM GNU/Linux
You have these choices for installing the sysroot on the target: You can install the files in the filesystem root on the target (that is, installing the files directly in /etc/, /lib/, and so on). All applications on the target then automatically use the Sourcery CodeBench libraries. This method is primarily useful when you are building a GNU/Linux root filesystem from scratch. If your target board already has a GNU/Linux filesystem installed, overwriting the existing C library files is not recommended, as this may break other applications on your system, or cause it to fail to boot. You can install the sysroot in an alternate location and invoke your application through the sysroot-run utility. If you are just getting started with Sourcery CodeBench, this may be the easiest way to get your application running on the target. The QEMU user-space emulator, which runs on GNU/Linux host systems, can likewise be invoked as sysroot-qemu to access the sysroot files from your Sourcery CodeBench installation directory on the host system. This is the recommended way to run QEMU and is also used when running user-space QEMU from the Sourcery CodeBench IDE. You can install the sysroot in an alternate location and build your application with the -rpath and --dynamic-linker linker options to specify the sysroot location. Setting the environment variable LD_LIBRARY_PATH on the target is not sufficient, since executables produced by Sourcery CodeBench depend on the Sourcery CodeBench dynamic linker included in the sysroot as well as the Sourcery CodeBench runtime libraries.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.
w w w.m e n t o r.c o m
2012 Mentor Graphics Corporation, all rights reserved. This document contains information that is proprietary to Mentor Graphics Corporation and may be duplicated in whole or in part by the original recipient for internal business purposes only, provided that this entire notice appears in all copies. In accepting this document, the recipient agrees to make every reasonable effort to prevent unauthorized use of this information. All trademarks mentioned in this document are the trademarks of their respective owners.
MGC 02-12
TECH10530-w