|
|
 |
Using STWorkbench with STLinux
Building and debugging a userspace application
|
|
Overview
This describes how to create projects to automatically manage builds and how to debug applications
using STWorkbench as a remote debugger.
STLinux applications have no intrinsic links to specific target boards, therefore this is
applicable to any supported board. However, the following host and target features must be available.
- The Linux kernel must be booting and running on the target board.
- When building for an ST40,
sh4-linux-gcc and
sh4-linux-gdb must be accessable through the host's path.
- When building for an ST200,
st231-linux-gcc and
st231-linux-gdb must be accessable through the host's path.
gdbserver must be present on the target filesystem.
- The root user must be able to log in to the target using SSH with an empty password or
without being prompted for a password. This is the default, provided the root user has remotely
logged in at least once previously.
Creating and building the project
Click File > New > Project.... The New Project window appears.
Select C > C Project from the Wizards tree/list and click Next.
The C Project dialog appears.
Enter 'HelloWorld' into the Project name text box
Select Executable from the Project types list
Select ST40 Linux GCC from the Toolchain list.
Click Finish. This bypasses the final page of the wizard but the default values are
correct. If an alert appears to confirm a perspective switch, click Yes.
Select HelloWorld from the STWorkbench C/C++ Projects view.
Click File > New > File. The New File window appears.
Enter 'hello.c' into the File name text box and click
Finish.
Copy the following into the editor.
#include <stdio.h>
int main()
{
int i;
for (i=0; i<25; i++) {
printf("Hello world\n");
}
return 0;
}
|
|
|
- Select File > Save.
- Select Project > Build Project. The application is built.
If the console output is not displayed automatically, select HelloWorld
from the STWorkbench Navigator window.
To explore further, try the following.
- Add extra source files to your project. These are
automatically included in subsequent builds.
- Introduce warnings or errors into your code. STWorkbench highlights them in the editor
and maintains a list of issues in its Problems window.
- Examine C/C++ Build from Project > Properties. This allows you to
switch between Debug and Release builds as well as tweaking other C compiler and
linker arguments.
Debugging the project
Select HelloWorld from the STWorkbench Navigator window.
Click Run > Debug.... The Create, manage, and run configurations window appears.

From the Configurations list, select STLinux Target Application and click New.
A HelloWorld configuration is automatically created from the selected project.
In the Debug window, select the Debugger tab.
Check that ST40 Linux GDB Debugger or ST200 Linux GDB Debugger is selected in
the Debugger list.
Enter the name or IP address of the target board into the Target name or IP address
text box.
Click Debug. The application is copied to the target and executed, and the debugger
stops at a breakpoint on main(). If an alert is displayed to confirm a
perspective switch, choose Yes.
Click Run > Step Over twice. The value of i, shown in
the STWorkbench Variables window becomes 0.
Click Run > Step Over again. Hello world appears in
the STWorkbench Console window.
Note: The Console window shows the console output of multiple processes.
Switch between them using the terminal icon at the top right of the Console
window.
Click Run > Resume. The program runs to completion and is marked
<terminated> in the STWorkbench Debug window.
To explore further, try the following.
- Add extra functions to allow you to become familiar with the stack traces in the STWorkbench
Debug window.
- Use
pthread_create() to spawn new threads to help understand the
concept of multiple threads in the STWorkbench Debug window.
- Supplement this introduction with tutorials from the generic C/C++ Development
User Guide.
|