206v02 RVDS Introductory Tutorial 1
RVDS 2.2
Introductory
Tutorial
206v02 RVDS Introductory Tutorial 2
Introduction
Aim
This tutorial provides you with a basic introduction to the tools provided with the
RealView Developer Suite version 2.2 (RVDS). This will include the use of
command line and GUI tools, to build and debug projects.
The tutorial is split into three practical sessions:
Session 1 – Command line tools.
Session 2 – Creating projects and debugging using the CodeWarrior IDE and
RealView Debugger (RVD).
Appendix - An Introduction to AXD
Pre-requisites
This tutorial is intended for use with a Microsoft Windows version of RVDS v2.2.
You should be familiar with Microsoft DOS/Windows, and have a basic knowledge
of the C programming language.
Note: Explanation of File Extensions:
.c C source file.
.h C header file.
.o object file.
.s assembly language source file.
.prj project file, as used by RealView Debugger (RVD).
.axf ARM Executable file, as produced by armlink.
.txt ASCII text file.
Additional information
This tutorial is not designed to provide detailed documentation of RVDS. Full
documentation is provided with the product.
Further help can be accessed by pressing F1 when running RVD, from the help menu,
or by using the --help switch for a command line tool. The documentation is also
available in PDF format. This can be found by going to Start → Programs → ARM
→ RealView Developer Suite 2.2 → PDF Documentation.
206v02 RVDS Introductory Tutorial 3
Section 1: Command Line Tools
This section covers the command line tools required to create and examine executable
images from the command line. These include:
armcc ARM C compiler.
tcc Thumb C compiler.
armlink Object code linker.
armasm Assembler for ARM/Thumb source code.
armsd ARM command line debugger.
fromelf File format conversion tool.
Help is available from the command line for all of the tools covered in
this session by typing the name of the tool followed by --help.
For more details please refer to the following documentation: Compiler
and Libraries Guide, Linker and Utilities Guide.
For the exercises in this section, you will receive a warning from the
compiler: “-g defaults to –O2 if no optimisation level is specified”.
You can ignore this warning, as we will not be debugging the image
files in this section.
Consider the following simple C program which calls a subroutine. This file is
provided as hello.c in c:\rvds22_tutorial\intro\session1\
/* hello.c Example code */
#include
#include /*for size_t*/
void subroutine(const char *message)
{
printf(message);
}
int main(void)
{
const char *greeting = "Hello from subroutine\n";
printf("Hello World from main\n");
subroutine(greeting);
printf("And Goodbye from main\n\n");
return 0;
}
206v02 RVDS Introductory Tutorial 4
Exercise 1.1 - Compiling and running the example
Compile this program with the ARM C compiler:
armcc -g hello.c
The C source code is compiled and an ARM ELF object file, hello.o, is created.
The compiler also automatically invokes the linker to produce an executable with the
default executable filename __image.axf.
The -g option adds high level debugging information to the object/executable. If –g
is not specified then the program will still produce the same results when executed but
it will not be possible to perform high level language debugging operations.
Thus this command will compile the C code, link with the default C library and
produce an ARM ELF format executable called __image.axf.
The generated image will execute on an ARM core.
armsd runs the image using the ARMulator (ARM Instruction Set
Simulator).
Execute this program using armsd as follows:
armsd -exec __image.axf
This command informs the debugger to execute the image and then terminate.
armsd responds with:
Hello World from main
Hello from subroutine
And Goodbye from main
Program terminated normally at PC = 0x000089c8 (_sys_exit + 0x8)
+0008 0x000089c8: 0xef123456 V4.. : swi 0x123456
Quitting
206v02 RVDS Introductory Tutorial 5
Exercise 1.2 - Compilation options
Different arguments can be passed to the compiler from the command line to
customize the output generated. A list of the more common options, together with
their effects, can be viewed by entering armcc -help at the command line. Some of
these options are listed below:
-c Generate object code only, does not invoke the linker.
-o Name the generated output file as ‘filename’.
-S Generate an assembly language listing.
-S --interleave Generate assembly interleaved with source code.
When the compiler is asked to generate a non-object output file, for example when
using –c or -S, the linker is not invoked, and an executable image will not be created.
These arguments apply to both the ARM and Thumb C compilers.
RVCT uses a -- prefix for multi character switches like interleave.
Legacy versions of switches (eg: -fs) are still supported, but will
generate a deprecated option warning.
Use the compiler options with armcc or tcc to generate the following
output files from hello.c:
image.axf An ARM executable image.
source.s An ARM assembly source.
inter.s A listing of assembly interleaved with source code.
thumb.axf A Thumb executable image.
thumb.s A Thumb assembly source.
Run the Thumb executable image using armsd, the output generated
should be the same as before.
Use a suitable text editor to view the interleaved source file.
To use Notepad from the command line type Notepad .
Note the sections of assembly source that correspond to the interleaved C source
code.
206v02 RVDS Introductory Tutorial 6
Exercise 1.3 - armlink
In previous exercises we have seen how the compiler can be used to automatically
invoke the linker to produce an executable image. armlink can be invoked
explicitly to create an executable image by linking object files with the required
library files. This exercise will use the files, main.c and sub.c which can be linked
to produce a similar executable to the one seen in the previous exercises.
Use the compiler to produce ARM object code files from each of the
two source files.
Remember to use the -c option to prevent automatic linking
Use armlink main.o sub.o -o link.axf to create a new ARM
executable called link.axf
armlink is capable of linking both ARM and Thumb objects.
If the -o option is not used an executable with the default filename,
__image.axf, will be created.
Run the executable using armsd and check that the output is similar to
before.
The ability to link files in this way is particularly useful when link order is important,
or when different C source modules have different compilation requirements It is also
useful when linking with assembler object files.
206v02 RVDS Introductory Tutorial 7
Exercise 1.4 - fromelf
ARM ELF format objects and ARM ELF executable images that are produced by the
compilers, assembler and/or linker can be decoded using the fromelf utility, and the
output examined. Shown below is an example using the –-text option with the /c
switch to produce decoded output, showing disassembled code areas, from the file
hello.o:
fromelf –-text=/c hello.o
Alternatively re-direct the output to another file to enable viewing with a text editor:
fromelf –-text=/c hello.o > hello.txt
Use the fromelf utility to produce and view disassembled code listings from the
main.o and sub.o object files.
A complete list of options available for ‘fromelf’ can be found from
the command line using fromelf –-help, or by consulting the on-line
documentation.
The –-text=/c option can be replaced with the abbreviated –c
switch.
206v02 RVDS Introductory Tutorial 8
Section 1 - Review
We have now seen how the command line tools can be used to compile, link and
execute simple projects.
armcc The compiler can be called with many different options. The -g
option is required to enable source level debugging. The compiler can
be used to generate executable images, object files and assembly
listings.
tcc The Thumb compiler can be used in the same way as armcc.
armasm The assembler can be used to construct object files directly from
assembly source code.
armlink The linker can be used to produce executable images from ARM or
Thumb object files.
fromelf The ‘fromelf’ facility can be used to generate disassembled code
listings from ARM or Thumb object or image files.
armsd Can be used to execute applications from the command line.
Help is available from the command line. Alternatively, consult the
online documentation for further information.
206v02 RVDS Introductory Tutorial 9
Section 2: Creating projects and debugging
using CodeWarrior and RVD
In this session we will see how the CodeWarrior Integrated Development
Environment can be used with the RealView Debugger (RVD) to create and develop
projects.
Exercise 2.1 - Creating a header file
In this exercise, we will create a new header file using CodeWarrior.
Start CodeWarrior by clicking on the icon in the Windows Start Menu
folder: ARM→ RealView Developer Suite→ CodeWarrior for RVDS
Close any open project(s) by clicking the close button in their project
windows.
Select File → New from the menu. Select the File tab as shown below,
and click on Text File in the selection list. Click Ok.
206v02 RVDS Introductory Tutorial 10
Enter the following C struct definition:
/* Struct definition */
struct Date_Format
{
int day;
int month;
int year;
};
Select File→ Save As from the menu.
Navigate the directory structure to:
c:\rvds22_tutorial\intro\session2\
and save as filename date_format.h
You have now created a very simple header file. This will be used later by the
example program: month.c.
Leave the editor window open for use later in the exercise.
206v02 RVDS Introductory Tutorial 11
Exercise 2.2 - Creating a new project
We will now create a new project and add our files month.c and datetype.h to it
Select File→ New… from the menu.
The New dialog appears again:
Ensure that the Project tab is selected, and that ARM Executable Image
is highlighted in the stationery selection list.
Use the Set button next to the Location text box to navigate to the
project directory: c:\rvds22_tutorial\intro\session2\.
206v02 RVDS Introductory Tutorial 12
Clear the Create folder check box and enter calendar as the name in
the Create New Project dialog as above. Click Save. Click OK to close
the New dialog and create the project.
The project window appears for the calendar project that you have just created:
Click in a blank area of the project window to ensure that it has focus,
then select Project → Add Files… from the main menu.
The Select files to add… dialog appears.
Navigate to the directory:
c:\rvds22_tutorial\intro\session2\
Double click on the file month.c
206v02 RVDS Introductory Tutorial 13
The Add Files dialog appears showing the targets to which the files can be added:
Click OK to add the file to both of the targets in the project.
We should also add the header file that we created earlier to the project. This is so
that any changes to the header file will cause the associated modules to be rebuilt.
Click the title bar of the date_format.h window so that it has the focus.
Now select Project → Add date_format.h to Project… from the menu.
The Add Files dialog reappears.
Click OK to add the header file to the project.
Finally, we must check that the correct build target is selected.
Ensure that the Debug target is the active target in the project window,
as shown below.
206v02 RVDS Introductory Tutorial 14
The two default targets available refer to the level of debug
information contained in the resultant image.
Debug Contains full debug table information and very limited optimization.
Release Enables full optimization, resulting in a worse debug view.
It is the Debug build target that we shall use for the remainder of this tutorial.
Exercise 2.3 - Building the project (Debug target)
Select Project→ Make from the menu, or press F7.
The Errors & Warnings window appears with the several messages generated as a
result of the attempted build:
The code pane of the window opens the relevant source file and an arrow highlights
the line of code associated with the first error message. There is something wrong
with the code; a close bracket is missing. The line should read:
printf("\ne.g. 1972 02 17\n\n");
Correct the error by adding the missing bracket and then save the
updated source file.
Rebuild the project (F7).
The Errors & Warnings window again shows the errors associated with the failed
build. The first error message is:
"month.c", line 20: Error: #70: incomplete type is not allowed
scanf ("%d%d%d", &date.year, &date.month, &date.day);
206v02 RVDS Introductory Tutorial 15
Once again, the code pane of the Errors & Warnings window displays the relevant
source file and an arrow highlights the line of code associated with the first error
message. You will find that there is nothing wrong with the code on this line!
Towards the top of the file, the preprocessor directives contain a reference to the
macro INCLUDE_DATE_FORMAT, which has not been defined in any of the source
files. Normally a command line parameter would have to be supplied to the C
compiler, armcc, to specify:
-D INCLUDE_DATE_FORMAT
We must edit the command line arguments for this project’s settings:
Open the Settings window (Alt + F7), here we can use the
Target Settings Panels pane on the left to access the ARM compiler
preprocessor settings.
Note that as we are editing the Debug target, the window title and
menu option will show Debug Settings.
Select the RealView Compiler item in the Language Settings branch of
the tree. Click on the Preprocessor tab.
Click in the text box under the empty list of macro definitions. Enter
INCLUDE_DATE_FORMAT and click the Add button.
206v02 RVDS Introductory Tutorial 16
We also need to change the optimisation level to –O1. This is so that variables are
stored in registers automatically, while still retaining a reasonable debug view.
Select the Debug/Opt tab. In the list of optimisation levels, select level
1 (good debug view, good code). Click OK to close
the Target Settings dialog and save the changes.
Select File→ Save from the menu to save the changes to the project.
Finally, select Project→ Make (F7) from the menu once more. The
project should build successfully.
If a project is already up-to-date then nothing will be done by the IDE
when it is requested to build a project. If you wish to do a forced
rebuild of all the source files then select Project → Remove Object
Code… to delete the relevant object files.
206v02 RVDS Introductory Tutorial 17
Exercise 2.4 - Executing the example
Before the image can be executed it must be loaded to an appropriate target using the
debugger. This example will use the RealView Instruction Set Simulator (RVISS), as
the target to execute the image using the RealView Debugger (RVD).
In CodeWarrior, select Project → Debug from the menu. RVD is
started.
If there is no connection to a target already set up, the dialog box
below will appear and RVD will prompt you to wait for a connection
to be made. Click Yes.
Select Target → Connect to Target… from the menu to launch the
Connection Control window.
Expand the Server, Local Host branches in the Name tree, then right
click “new_arm” and select Configure Device Info.
206v02 RVDS Introductory Tutorial 18
The ARMulator Configuration window appears:
Select ARM7TDMI as shown above and click OK to return to the
Connection Control window.
Tick the new_ARM checkbox in the connection control window to
connect.
RealView Debugger is now connected to the ARM7TDMI RVISS target.
You can now close the Connection Control window..
206v02 RVDS Introductory Tutorial 19
If you were prompted to earlier wait for a connection, the image is loaded and the
Code pane shows the source code for the project image. If not, the Code pane now
prompts you to load the recently built image to the target. In this case, you need to
click on the link to load the image to the target:
Click on the Load link to load the image.
The Code pane now shows that the image is loaded and the red box indicates the
current execution position:
Select Debug → Run from the menu (F5).
Execution begins. The Output pane at the bottom of the window shows the StdIO tab
which performs console I/O operations for the current image. The program is now
awaiting user input:
Enter today’s date in the format described, e.g. 2005 01 11
206v02 RVDS Introductory Tutorial 20
The program will display the dates for the following calendar month and then
terminate.
Note that there is no source code available for the system exit routines
and RVD displays No source for context SYS_S\_sys_exit
The disassembled project code can be viewed by selecting the Dsm tab
in the Code pane.
All windows can be resized by clicking and dragging at the edges.
Docked panes can be changed to floating windows by clicking on the
Pane Content button (Alt + *) and selecting Float from the menu:
206v02 RVDS Introductory Tutorial 21
Exercise 2.5 - Debugging the example
Select Target → Reload Image to Target from the menu.
RVD will load the image ready for debugging. Again the current execution position
is shown at main.
Select Debug → Run from the menu (F5).
You will once again be prompted to enter a date.
This time enter 2005 11 30. The program will terminate after it has
output the set of dates for the following month.
Use the scroll bar at the edge of the Output Pane to view the dates at
the end of November. You will find that there is an extra day!
Reload the image into the debugger
Select View → Data Navigator from the menu to open a Data
Navigator pane. Select the Functions tab.
206v02 RVDS Introductory Tutorial 22
Enter the string @calendar\MONTH\nextday in the Filter textbox
and press Enter.
The basic filter strings are of the form:
@image_name\module_name\function_name, and you can also
use wildcards. For example, to list all of the functions in the month
module, you can specify: @calendar\MONTH\*. Full details of
additional filters that can be used can be found in the RVD User
Guide.
Highlight the nextday entry, right-click it and select Show Source
from the context menu to locate this function in the source file. Then
close the Data Navigator pane.
Select Edit → Advanced → Show Line Numbers from the menu
to display line number information in the source code:
206v02 RVDS Introductory Tutorial 23
Set a breakpoint on the switch statement on line 40 by
double-clicking to t
本文档为【RVDS使用手册】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。