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 rl78-elf toolchain. If you are using a different toolchain, use appropriate commands.
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;
}
4. Compile the program with the following command:
> rl78-elf-gcc hello.c -o hello.out -g -msim
An executable file called hello.out is generated.
5. Run the executable file using the rl78-elf simulator with the following command:
> rl78-elf-run hello.out
The string "Hello World!" is displayed on the console.
6. Debug the program using the rl78-elf debugger with the following command:
> rl78-elf-gdb hello.out
The GDB prompt (gdb) appears on the console.
7. 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
8. Set the break point at the main with the following commands:
<gdb> b main
<gdb> run
The program stops at the break point 'main'.
9. 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.
$ export PATH=$PATH:/usr/share/gnurl78_v14.03_elf-1/bin/
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;
}
$rl78-elf-gcc hello.c -o hello.out -g -msim
An executable file called hello.out is generated.
$rl78-elf-run hello.out
The "Hello World!" string is displayed on the console.
$rl78-elf-gdb hello.out
The GDB prompt (gdb) appears on the console.
target sim
The message "Connected to target simulator" is displayed.
load
A message indicating that the program is loaded is displayed.
b main
The message "Breakpoint 1 at 0x1516: file hello.c, line 5." is displayed.
run
The program stops at breakpoint in 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");
----------------------------------------------------------
11.
Press
'N' to go to the next line. The string "Hello World!" is displayed on
the console, and the program stops at line 7.
12.
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