Chapter 2. Advanced Techniques

Table of Contents
2.1. Using the Debugger
2.2. Using Optimizations
2.3. Interrupt Handling
2.4. POSIX Multi Tasking
2.5. Using a Custom Start-file
2.6. Generating PROM Programming Files
2.7. Working with the Target
2.8. Using Atmel rdbmon Version 1.1
2.9. The Boot PROM
2.10. Working with Temic Revisions CBA and CCA
2.11. Working with the EDAC
2.12. System Calls

Once you have mastered writing and running a small program, you'll want to check out some of the more advanced techniques required to write and run real application programs. In this chapter, we cover the following topics:

2.1. Using the Debugger

Before we can make full use of the debugger, we must recompile hello.c using the debug option. This option tells the compiler to include information about the source code, and the mapping of source code to generated code. Then the debugger can operate at source code level rather than at machine code level.

The debug information does not alter the generated code in any way but it does make object code files much bigger. Normally this is not a problem, but if you wish to remove the debug information from a file, then use the object code utility erc-coff-strip.

This is how we recompile hello.c with the -g option. There are other debug options too. See the User's Guide for more information on debug options.

Example 2-1. Recompiling with the Debug Option

$ erc-coff-gcc hello.c -o hello -g

The debugger is erc-coff-gdb. By default the debugger will run an ERC32 program on the ERC32 simulator. If you prefer to run and debug on a real ERC32 then you must arrange for your target to communicate with the host using the debugger's remote debug protocol. This is described in Section 2.7.

Example 2-2. Running Under the Debugger

$ erc-coff-gdb hello
XGC gcc-erc32 Version 1.7e (debugger)
Copyright (c) 1996, 2002, XGC Software.
Based on gdb version 5.1.1
Copyright (c) 1998 Free Software Foundation...
(gdb) br main
Breakpoint 1 at 0x2001500: file hello.c, line 6.
(gdb) r
Starting program: ../examples/hello 
Connected to the simulator.
Loading sections:
Idx Name          Size      VMA       LMA       File off  Algn
  1 .text         00002c88  02000000  02000000  00002000  2**2
                  CONTENTS, ALLOC, LOAD, CODE
  2 .rodata       000003c8  02002c88  02002c88  00004c88  2**3
                  CONTENTS, ALLOC, LOAD, READONLY
  3 .data         00000008  02100000  02003050  00006000  2**3
                  CONTENTS, ALLOC, LOAD, DATA
Start address 0x2000a00
Transfer rate: 99008 bits in <1 sec.

Breakpoint 1, main () at hello.c:6
6         printf ("Hello world\n");
a(gdb)