# Working Within Eclipse

The Eclipse IDE is a popular development environment and it fully supports development using Yocto Project. When you install and configure the Eclipse Yocto Project Plug-in into the Eclipse IDE, you maximize your Yocto Project design experience. Installing and configuring the Plug-in results in an environment that has extensions specifically designed to let you more easily develop software. These extensions allow for cross-compilation, deployment, and execution of your output into a QEMU emulation session. You can also perform cross-debugging and profiling. The environment also supports a suite of tools that allows you to perform remote profiling, tracing, collection of power data, collection of latency data, and collection of performance data.

This section describes how to install and configure the Eclipse IDE Yocto Plug-in and how to use it to develop your Yocto Project.

## Setting Up the Eclipse IDE

To develop within the Eclipse IDE, you need to do the following:

1. Be sure the optimal version of the Eclipse IDE is installed.

2. Configure the Eclipse IDE.

3. Install the Eclipse Yocto Plug-in.

4. Configure the Eclipse Yocto Plug-in.

### Installing the Eclipse IDE

It is recommended that you have the Indigo 3.7 version of the Eclipse IDE installed on your development system. If you don’t have this version, you can find it at . From that site, choose the Eclipse Classic version particular to your development host. This version contains the Eclipse Platform, the Java Development Tools (JDT), and the Plug-in Development Environment.

Once you have downloaded the tarball, extract it into a clean directory. For example, the following command unpacks and installs the Eclipse IDE into a clean directory named `eclipse`:

         $ tar -xzvf ~/Downloads/Eclipse-SDK-3.7-linux-gtk-x86_64.tar.gz

One issue exists that you need to be aware of regarding the Java Virtual machine’s garbage collection (GC) process. The GC process does not clean up the permanent generation space (PermGen). This space stores metadata descriptions of classes. The default value is set too small and it could trigger an out-of-memory error such as the following:

         Java.lang.OutOfMemoryError: PermGen space

This error causes the application to hang.

To fix this issue, you can use the `--vmargs` option when you start Eclipse to increase the size of the permanent generation space:

         eclipse --vmargs --XX:PermSize=256M

### Configuring the Eclipse IDE

Before installing and configuring the Eclipse Yocto Plug-in, you need to configure the Eclipse IDE. Follow these general steps to configure Eclipse:

1. Start the Eclipse IDE.

2. Select "Install New Software" from the "Help" pull-down menu.

3. Select `Indego - http://download.eclipse.org/releases/indego` from the "Work with:" pull-down menu.

4. Expand the box next to `Programming Languages` and select the `Autotools Support for CDT (incubation)` and `C/C++ Development Tools` boxes.

5. Complete the installation and restart the Eclipse IDE.

6. Select "Install New Software" from the "Help" pull-down menu.

7. After the Eclipse IDE restarts, click the "Available Software Sites" link.

8. Check the box next to `http://download.eclipse.org/tm/updates/3.3` and click "OK".

9. Select `http://download.eclipse.org/tm/updates/3.3` from the "Work with:" pull-down menu.

10. Check the box next to `TM and RSE Main Features`.

11. Expand the box next to `TM and RSE Optional Add-ons` and select every item except `RSE Unit Tests` and `RSE WinCE Services (incubation)`.

12. Complete the installation and restart the Eclipse IDE.

13. After the Eclipse IDE restarts, click the "Available Software Sites" link.

14. Check the box next to `http://download.eclipse.org/tools/cdt/releases/indego` and click "OK".

15. Select `http://download.eclipse.org/tools/cdt/releases/indego` from the "Work with:" pull-down menu.

16. Check the box next to `CDT Main Features`.

17. Expand the box next to `CDT Optional Features` and select `C/C++ Remote Launch` and `Target Communication Framework (incubation)`.

18. Complete the installation and restart the Eclipse IDE.

### Installing the Eclipse Yocto Plug-in

To install the Eclipse Yocto Plug-in, follow these special steps. The steps are WIP and are not final. Once they are final they will be replaced with the actual steps:

1. Open a shell and create a Git repository with:

            $ git clone git://git.yoctoproject.org/yocto-eclipse yocto-eclipse

2. In Eclipse, select "Import" from the "File" menu.

3. Expand the "General" box and pick "existing projects into workspace".

4. Select the root directory and browse to "~/yocto-eclipse/plugins".

5. There will be three things there. Select each one and install one at a time. Do all three.

6. Restart everything.

At this point I should be able to invoke Eclipse from the shell using the following:

         $ cd ~/eclipse
         $ ./eclipse -vmargs -XX:PermSize=256M

What is shown is the default projects in the left pane. I should be able to right-click on one of these and run as an Eclipse application to bring up the Eclipse instance again with the Eclipse Yocto Plug-in working.

### Configuring the Eclipse Yocto Plug-in

Configuring the Eclipse Yocto Plug-in involves setting the Cross Compiler options and the Target options. The configurations you choose become the default settings for all projects. You do have opportunities to change them later when you configure the project (see the following section).

To start, you need to do the following from within the Eclipse IDE:

- Choose `Windows -> Preferences` to display the Preferences Dialog

- Click `Yocto ADT`

#### Configuring the Cross-Compiler Options

To configure the Cross Compiler Options, you must select the type of toolchain, point to the toolchain, specify the sysroot location, and select the target architecture.

- Selecting the Toolchain Type: Choose between `Standalone pre-built toolchain` and `Build system derived toolchain` for Cross Compiler Options.

  - `Standalone Pre-built Toolchain:` Select this mode when you are using a stand-alone cross-toolchain. For example, suppose you are an application developer and do not need to build a target image. Instead, you just want to use an architecture-specific toolchain on an existing kernel and target root filesystem.

  - `Build System Derived Toolchain:` Select this mode if the cross-toolchain has been installed and built as part of the Yocto Project build tree. When you select `Build system derived toolchain`, you are using the toolchain bundled inside the Yocto Project build tree.

- Point to the Toolchain: If you are using a stand-alone pre-built toolchain, you should be pointing to the `/opt/poky/$SDKVERSION` directory. This is the location for toolchains installed by the ADT Installer or by hand. Sections Configuring and Running the ADT Installer Script and Using a Cross-Toolchain Tarball describe two ways to install a stand-alone cross-toolchain in the `/opt/poky` directory.

  It is possible to install a stand-alone cross-toolchain in a directory other than `/opt/poky`. However, doing so is discouraged.

  If you are using a system-derived toolchain, the path you provide for the `Toolchain Root Location` field is the Yocto Project's build directory. See section Using BitBake and the Yocto Project Build Tree for information on how to install the toolchain into the Yocto Project build tree.

- Specify the Sysroot Location: This location is where the root filesystem for the target hardware is created on the development system by the ADT Installer. The QEMU user-space tools, the NFS boot process, and the cross-toolchain all use the sysroot location.

- Select the Target Architecture: The target architecture is the type of hardware you are going to use or emulate. Use the pull-down `Target Architecture` menu to make your selection. The pull-down menu should have the supported architectures. If the architecture you need is not listed in the menu, you will need to build the image. See the Building an Image section of the The Yocto Project Quick Start for more information.

#### Configuring the Target Options

You can choose to emulate hardware using the QEMU emulator, or you can choose to run your image on actual hardware.

- `QEMU:` Select this option if you will be using the QEMU emulator. If you are using the emulator, you also need to locate the kernel and specify any custom options.

  If you selected `Build system derived toolchain`, the target kernel you built will be located in the Yocto Project build tree in `tmp/deploy/images` directory. If you selected `Standalone pre-built toolchain`, the pre-built image you downloaded is located in the directory you specified when you downloaded the image.

  Most custom options are for advanced QEMU users to further customize their QEMU instance. These options are specified between paired angled brackets. Some options must be specified outside the brackets. In particular, the options `serial`, `nographic`, and `kvm` must all be outside the brackets. Use the `man qemu` command to get help on all the options and their use. The following is an example:

          serial ‘<-m 256 -full-screen>’

  Regardless of the mode, Sysroot is already defined as part of the Cross Compiler Options configuration in the `Sysroot Location:` field.

- `External HW:` Select this option if you will be using actual hardware.

Click the `OK` button to save your plug-in configurations.

## Creating the Project

You can create two types of projects: Autotools-based, or Makefile-based. This section describes how to create Autotools-based projects from within the Eclipse IDE. For information on creating Makefile-based projects in a terminal window, see the section "Using the Command Line".

To create a project based on a Yocto template and then display the source code, follow these steps:

1. Select `File -> New -> Project`.

2. Double click `CC++`.

3. Double click `C Project` to create the project.

4. Expand `Yocto ADT Project`.

5. Select `Hello World ANSI C Autotools Project`. This is an Autotools-based project based on a Yocto Project template.

6. Put a name in the `Project name:` field. Do not use hyphens as part of the name.

7. Click `Next`.

8. Add information in the `Author` and `Copyright notice` fields.

9. Be sure the `License` field is correct.

10. Click `Finish`.

11. If the "open perspective" prompt appears, click "Yes" so that you in the C/C++ perspective.

12. The left-hand navigation pane shows your project. You can display your source by double clicking the project's source file.

## Configuring the Cross-Toolchains

The previous section, " Configuring the Eclipse Yocto Plug-in", set up the default project configurations. You can change these settings for a given project by following these steps:

1. Select `Window -> Preferences`: This selection brings up the `Preferences` Dialog. If the Yocto ADT Preferences are not automatically displayed, you can navigate to that dialog by selection `Yocto ADT` in the left-hand panel.

   Yocto ADT Settings are inherited from the default project configuration. The information in this dialog is identical to that chosen earlier for the Cross Compiler Options and Target Options as described in Configuring the Eclipse Yocto Plug-in section.

2. Select `Project -> Reconfigure Project`: This selection reconfigures the project by running `autogen.sh` in the workspace for your project. The script also runs `libtoolize`, `aclocal`, `autoconf`, `autoheader`, `automake --a`, and `./configure`.

## Building the Project

To build the project, select `Project -> Build Project`. The console should update and you can note the cross-compiler you are using.

## Starting QEMU in User Space NFS Mode

To start the QEMU emulator from within Eclipse, follow these steps:

1. Expose the `Run -> External Tools -> External Tools Configurations...` menu. Your image should appear as a selectable menu item.

2. Select your image from the menu. Doing so launches a new window.

3. Enter your host root password in the shell window at the prompt. This sets up a `Tap 0` connection needed for running in user-space NFS mode.

4. Wait for QEMU to launch.

5. Once QEMU launches you need to determine the IP Address for the user-space NFS. You can do that by going to a terminal in the QEMU and entering the `ifconfig` command.

## Deploying and Debugging the Application

Once the QEMU emulator is running the image, you can deploy your application and use the emulator to perform debugging. Follow these steps to deploy the application.

1. Select `Run -> Debug Configurations...`

2. In the left area, expand `C/C++Remote Application`.

3. Locate your project and select it to bring up a new tabbed view in the `Debug Configurations` Dialog.

4. Enter the absolute path into which you want to deploy the application. Use the `Remote Absolute File Path for C/C++Application:` field. For example, enter `/usr/bin/<programname>`.

5. Click on the `Debugger` tab to see the cross-tool debugger you are using.

6. Click on the `Main` tab.

7. Create a new connection to the QEMU instance by clicking on `new`.

8. Select `TCF`, which means Target Communication Framework.

9. Click `Next`.

10. Clear out the `host name` field and enter the IP Address determined earlier.

11. Click `Finish` to close the new connections Dialog.

12. Use the drop-down menu now in the `Connection` field and pick the IP Address you entered.

13. Click `Debug` to bring up a login screen and login.

14. Accept the debug perspective.

## Running User-Space Tools

As mentioned earlier in the manual, several tools exist that enhance your development experience. These tools are aids in developing and debugging applications and images. You can run these user-space tools from within the Eclipse IDE through the `Window -> YoctoTools` menu.

Once you pick a tool, you need to configure it for the remote target. Every tool needs to have the connection configured. You must select an existing TCF-based RSE connection to the remote target. If one does not exist, click `New` to create one.

Here are some specifics about the remote tools:

- `OProfile`: Selecting this tool causes the `oprofile-server` on the remote target to launch on the local host machine. The `oprofile-viewer` must be installed on the local host machine and the `oprofile-server` must be installed on the remote target, respectively, in order to use. You must compile and install the `oprofile-viewer` from the source code on your local host machine. Furthermore, in order to convert the target's sample format data into a form that the host can use, you must have `oprofile` version 0.9.4 or greater installed on the host.

  You can locate both the viewer and server from .

  The `oprofile-server` is installed by default on the `core-image-sato-sdk` image.

- `Lttng-ust`: Selecting this tool runs `usttrace` on the remote target, transfers the output data back to the local host machine, and uses `lttv-gui` to graphically display the output. The `lttv-gui` must be installed on the local host machine to use this tool. For information on how to use `lttng` to trace an application, see .

  For `Application`, you must supply the absolute path name of the application to be traced by user mode `lttng`. For example, typing `/path/to/foo` triggers `usttrace /path/to/foo` on the remote target to trace the program `/path/to/foo`.

  `Argument` is passed to `usttrace` running on the remote target.

- `PowerTOP`: Selecting this tool runs `powertop` on the remote target machine and displays the results in a new view called `powertop`.

  `Time to gather data(sec):` is the time passed in seconds before data is gathered from the remote target for analysis.

  `show pids in wakeups list:` corresponds to the `-p` argument passed to `powertop`.

- `LatencyTOP and Perf`: `latencytop` identifies system latency, while `perf` monitors the system's performance counter registers. Selecting either of these tools causes an RSE terminal view to appear from which you can run the tools. Both tools refresh the entire screen to display results while they run.