Emulator: Difference between revisions

From Uzebox Wiki
Jump to navigation Jump to search
No edit summary
Line 146: Line 146:
===Gdb Problems===
===Gdb Problems===


====1. Starting a debug session with 'steps'.====
====Starting a debug session with 'steps'.====
If you connect to your target and try to step, you may get some errors or gdb will even crash. This happens because gdb client is trying to read an invalid address from SRAM. To avoid this, use a breakpoint into main() (or other function you want) and give a 'continue'.<br>
If you connect to your target and try to step, you may get some errors or gdb will even crash. This happens because gdb client is trying to read an invalid address from SRAM. To avoid this, use a breakpoint into main() (or other function you want) and give a 'continue'.<br>
Filipe's note: It looks like an GDB bug, but I'm getting more details before submit a bug report.
Filipe's note: It looks like an GDB bug, but I'm getting more details before submit a bug report.


====2. The debugger says a variable defined with PROGMEM is 'out of bounds' and will shows it with a SRAM address (over 0x800000).====
====The debugger says a variable defined with PROGMEM is 'out of bounds' and will shows it with a SRAM address (over 0x800000).====
Gdb can get the variable value, so it knows the variable is in flash, but if you get the variable address and try to overwrite it, GDB thinks it is in SRAM. If you want the real flash address, just subtract 0x800000. If you want overwrite a value, use the gdb command '''set {type} addr = value'''.<br>
Gdb can get the variable value, so it knows the variable is in flash, but if you get the variable address and try to overwrite it, GDB thinks it is in SRAM. If you want the real flash address, just subtract 0x800000. If you want overwrite a value, use the gdb command '''set {type} addr = value'''.<br>
Example using the global variable ''const char strEnd2[] PROGMEM = "THAT WAS THE LAST LEVEL"'' declared in Arkanoid.c:
Example using the global variable ''const char strEnd2[] PROGMEM = "THAT WAS THE LAST LEVEL"'' declared in Arkanoid.c:
Line 163: Line 163:
(gdb) print strEnd2
(gdb) print strEnd2
$5 = "@HAT WAS THE LAST LEVEL"
$5 = "@HAT WAS THE LAST LEVEL"
</pre><code>
</pre></code>
Filipe's note: Again this looks like a GDB bug. I tried change types like 'char *' to 'prog_char *' but gdb still get crazy. I will file a bug report as soon I get finished more tests.
Filipe's note: Again this looks like a GDB bug. I tried change types like 'char *' to 'prog_char *' but gdb still get crazy. I will send a bug report as soon I get finished more tests.


==FAQ==
==FAQ==

Revision as of 14:15, 6 January 2010

Description

Uzebox has its own emulator called Uzem. You can use it for both kernel and games development.

Features:

  • Multi-platform (Linux, Windows and MacOS)
  • Implements the CPU atmega644 used by Uzebox
  • Video and Sound using [www.libsdl.org/ SDL]
  • Mouse (Uzebox supports SNES mouse)
  • SDCard (for the Gameloader)
  • GDB Server

Building

Pre-requisites

Download

Get the last Uzebox version from http://code.google.com/p/uzebox/

Note: If you are going to download from the SVN server, the current development tree is the branch rev_beta5

Compiling

  • Unpack it
  • Open a command line terminal, go to the tools/emulator/ directory
  • To see the available options, type make help
  • Type make for the default options

This process will create two executables: uzem and uzemdbg.
Important: The uzemdbg is only used for the Emulator development, it generates a lot of debugging messages and is very slow.


Using

Just run the emulator in the command line and pass the game (iHex file) as parameter: uzem path/to/your/game.hex

To see all the options available run: uzem --help


GDB

Uzem implements an internal GDB server (originally based on simulavr) making it an important tool to develop Uzebox games.

Running Uzem in debug mode

The following examples are using the game Arkanoid.
Windows users: Don't forget to use backslash "\"

Execute uzem with the option -d and the game file:

$ uzem -d  ../../demos/Arkanoid/default/Arkanoid.hex

NOTE THIS IS AN EXPERIMENTAL BRANCH OF THE UZEBOX EMULATOR
PLEASE SEE THE FORUM FOR MORE DETAILS:  http://uzebox.org/forums

Loading Hex Image...
Waiting on port 1284 for gdb client to connect...

Uzem will start and wait for the GDB client to connect.

Gdb clients

Now with Uzem running in debug mode, you need the gdb client to debug the game. Following is a list of GDB clients and front-ends you can use.

Avr-gdb


Details
Site: http://sourceware.org/gdb/  
OS: Windows, Linux and MacOS  
Type:    Command line  

This is the official gnu gdb client. Windows: It is shipped with WinAvr Linux: Check you distribution.

  • Ubuntu has the avr-gdb package but its version (6.4) has some issues about variables in flash and will crash.

If you want compile the last version visit http://www.nongnu.org/avr-libc/user-manual/install_tools.html for more details.

Build the game and from the same directory run avr-gdb passing the elf file as parameter:

1. $>cd demos/Arkanoid/default/
2. $>make
3. $>avr-gdb Arkanoid.elf

You will get a prompt like this: (gdb)
Then connect to the Uzem:

4. (gdb)target remote localhost:1284

You don't need to use the GDB command "run". You are already with the debugger session started, but still stopped at the first instruction as you can see:

Remote debugging using localhost:1284
0x00000000 in __vectors ()

Go ahead and start debugging your code.

Refer to GDB manual for more information about the available commands.
GDB cheat sheet: http://www.yolinux.com/TUTORIALS/GDB-Commands.html

Gdb supports script files to automate the tedious task. Arkanoid has a simple script (file: Arkanoid/default/gdb-script.cfg) to connect to the target, insert a breakpoint at main() and continue until it reaches main. Gsb script are text files with gdb commands, but can create new commands using an internal language and others GDB commands.

Use the option -x like: avr-gsb -x gdb-script.cfg Arkanoid.elf

KDbg


Details
Site: http://www.kdbg.org/  
OS: Linux  
Type:    Gui  

KDbg is a graphical user interface to gdb. It provides an intuitive interface for setting breakpoints, inspecting variables, and stepping through code.

Note: It is a front-end to avr-gdb, so you still need avr-gdb.

To install, user your package manager.

  • Ubuntu: sudo apt-get install kdbg

As you are going to debug an AVR target, you need first configure KDbg to use an avr-gdb:
1. Start KDbg and go to the menu option Settings/Global Options...
2. From the tab Debugger change the option in the box How to invke GDB: from the default gdb to avr-gdb.

  • Make sure your avr-gdb is in the PATH or just use the full path.

There is no option to connect a remote target from KDbg using the GUI interface, so you will need to close it and open from the shell with the option -r:
1. Start uzem with -d
2. Open a new shell
3. $>cd demos/Arkanoid/default/
4. Build if necessary
5. $>kdbg -r localhost:1284 Arkanoid.elf

The KDbg is running and connected. It is very intuitive, on the bottom you have Stack and Breakpoints and on the right variables and expressions to inspect data. From the menu option View you see Registers and Memory.

Gdb Problems

Starting a debug session with 'steps'.

If you connect to your target and try to step, you may get some errors or gdb will even crash. This happens because gdb client is trying to read an invalid address from SRAM. To avoid this, use a breakpoint into main() (or other function you want) and give a 'continue'.
Filipe's note: It looks like an GDB bug, but I'm getting more details before submit a bug report.

The debugger says a variable defined with PROGMEM is 'out of bounds' and will shows it with a SRAM address (over 0x800000).

Gdb can get the variable value, so it knows the variable is in flash, but if you get the variable address and try to overwrite it, GDB thinks it is in SRAM. If you want the real flash address, just subtract 0x800000. If you want overwrite a value, use the gdb command set {type} addr = value.
Example using the global variable const char strEnd2[] PROGMEM = "THAT WAS THE LAST LEVEL" declared in Arkanoid.c:

(gdb) print strEnd2
$3 = "THAT WAS THE LAST LEVEL"
(gdb) print strEnd2[0]=64
Cannot access memory at address 0x80a003
(gdb) print &strEnd2
$4 = (char (*)[24]) 0x80a003
(gdb) set {char}0xa003 = 64
(gdb) print strEnd2
$5 = "@HAT WAS THE LAST LEVEL"

Filipe's note: Again this looks like a GDB bug. I tried change types like 'char *' to 'prog_char *' but gdb still get crazy. I will send a bug report as soon I get finished more tests.

FAQ