Quick Start Guide

 

The following procedure describes how to debug a program using the command line GDB. Refer to the GDB Manual for information about various GDB commands and the Insight Manual for operational commands.

Note: This procedure is applicable if you are using the rx-elf toolchain. If you are using a different toolchain, use appropriate commands.

For Windows Users

For GNU/Linux Users

 

Windows Users

  1. Click the "toolchain" shortcut in the Windows Start menu.

  2. Create a new folder named "test". 

  3. In the "test" folder, write a "Hello World!" program in file hello.c.

#include <stdio.h>

  int main(void)

  {   

    int ret;

    ret = printf("Hello World!\r\n");

    return ret;

  }

  1. Compile the program with the following command:

> rx-elf-gcc hello.c -o hello.out -g -msim

An executable file called hello.out is generated.

  1. Run the executable file using the rx-elf simulator with the following command:

> rx-elf-run hello.out

The string "Hello World!" is displayed on the console.

  1. Debug the program using the rx-elf debugger with the following command:

> rx-elf-gdb hello.out

The GDB prompt (gdb) appears on the console.

  1. Connect the GDB to the target simulator with the following command:

<gdb> target sim

The message "Connected to the simulator" is displayed.

Load the symbols with the following command:

<gdb> load

  1.  Set the break point at the main with the following commands:

<gdb> b main

<gdb> run

The program stops at the break point 'main'.

  1. You can step the program with the following command:

<gdb> s

Note: You can also try various gdb options such as "p" for printing a variable, "watch " for watching a variable, and so on. For more information, refer to the "gdb.html" document.

 

GNU/Linux Users

  1. Add the toolchain path to the current path with the following command:

$ export PATH=$PATH:/usr/share/gnurx_v0901_elf-1/bin/

  1. Create a new folder named "test".

  2. In the "test" folder, write a "Hello World!" program in file hello.c.

#include <stdio.h>
  int main(void)
  {     
    int ret;
    ret = printf("Hello World!\r\n");
    return ret;
  }

  1. Compile the program with the following command:

$rx-elf-gcc hello.c -o hello.out -g -msim

An executable file called hello.out is generated.

  1. Run the executable file using the rx-elf simulator with the following command:

$rx-elf-run hello.out

The "Hello World!" string is displayed on the console.

  1. Debug the program using the rx-elf debugger with the following command:

$rx-elf-gdb hello.out

The GDB prompt (gdb) appears on the console.

  1. Connect the GDB to the target simulator with the following command:

target sim

The message "Connected to target simulator" is displayed.

  1. Load the program in the memory with the following command:

load

A message indicating that the program is loaded is displayed.

  1. Set the break point at the main with the following command:

b main

The message "Breakpoint 1 at 0x4000101: file hello.c, line 5." is displayed.

  1. Run the program with the following command:

run

The program stops at line 6 of hello.c, and the following messages are displayed:

    ----------------------------------------------------------
    Starting program: /home/user/test/hello.out
    Breakpoint 1, main () at hello.c:5
    5 ret = printf("Hello World!\r\n");
    ----------------------------------------------------------

  1. Press 'N' to go to the next line. The string "Hello World!" is displayed on the console, and the program stops at line 7.

  2. To view the value of "ret", execute the following command:

disp ret

Note: You can also view the source and all the break points with the following command:
     gdbgui