Uzebox Developement Under Eclipse: Difference between revisions

From Uzebox Wiki
Jump to navigation Jump to search
Line 1: Line 1:
==Windows==
==Setup for Windows==
* Install the [http://sourceforge.net/projects/winavr/files/ latest WinAVR] -- Currently WinAVR-20100110
* Install the [http://sourceforge.net/projects/winavr/files/ latest WinAVR] -- Currently WinAVR-20100110
* Install [http://www.eclipse.org/cdt/downloads.php Eclipe CDT (C Developement Toolkit)] -- Currently 6.0.x. Be sure to install the GDB options.
* Install [http://www.eclipse.org/cdt/downloads.php Eclipe CDT (C Developement Toolkit)] -- Currently 6.0.x. Be sure to install the GDB options.

Revision as of 23:51, 20 March 2013

Setup for Windows

Preparing the IDE

To fully use the code editor's features, setup the path to the Uzebox kernel:

  • In Eclipse select Windows->preferences
  • Expand C/C++->Build->Build Variables
  • Click Add... For variable name enter: UZEBOX_KERNEL_DIR and for variable value enter the path to the uzebox kernel checked out from SVN, i.e: c:/work/uzebox/trunk/kernel . IMPORTANT: enter the path with forward slashes, or it will not be recognized in eclipse. Click Apply and Ok.
  • In the project explorer, right click your project and select Properties.
  • Expand C/C++ General->Paths and Symbols
  • Under the Includes tab, insure GNU C is selected and click Add...
  • Click the Variables... button and select UZEBOX_KERNEL_DIR from the list. Click Ok.
  • Click Apply, Ok and rebuild the project

Debugging

Create an Eclipse project from an AVR Studio project

This procedure requires that you already have a Uzebox project created with AVR Studio.

  • Launch Eclipse and select your workspace location. If it's the first project you create, choose the "trunk" folder were you checked out the sources from SVN.
  • Select File->New->C Project
  • Enter a project name, the same name as the AVR Studio's project's folder
  • Uncheck the "Use default location" check box and browse to your AVR Studio's project folder (i.e: Megatris)
  • Click next twice, then choose Atmega644 for processor type and 28636360 as frequency. Click finish.
  • Right-Click your new project a select Properties...
  • Click C/C++ Build from the left property pane
  • Uncheck the "Use default build command" check box
  • Uncheck the "Generate Makefiles automatically" check box
  • In the build location section, click the "Workspace..." button and select your new project and then the "default" folder where the makefile resides.
  • Click apply, your project should build normally

Setting up Eclipse for Debugging

These settings are made for Eclipse IDE for C/C++ developers (Build id: 20100218-1602). More recent version may slightly vary. The setup involves creating a launch group that will, in turn, start the emulator in debug mode with your game and then start the gdb client debugger. We will use Megatris as an example.

Create the emulator launch configuration

  • Open menu Run->External Tools->External Tools Configuration...
  • Press the New button to create a new launch configuration
  • Name the configuration like "Run in emulator (Megatris)"
  • Click the "Variables" button and select "uzem_loc" from the list. Click Ok.
    • If "uzem_loc" does not exist, click "Edit Variables"
    • Click "New". For variable name enter "uzem_loc" (without the double-quotes). For the Value, click "Browse" then locate the directory on your system that contains the uzem executable (i.e: uzem.exe).
  • In the "Location" field, append the executable name to the substitution variable such as: ${uzem_loc}/uzem.exe
  • In working directory, browse to the "default" directory (i.e: ${workspace_loc:/Megatris/default})
  • In "Arguments", enter the "-d" switch followed with your game's HEX file (i.e: -d Megatris.hex)
  • Click apply

Create the GDB debugger client configuration

  • Open menu Run->Debug Configuration...
  • Select the "C/C++ Application" group in the left panel and press the new button
  • Name your configuration such as "Megatris Debug configuration"
  • Choose you project. "Build configuration" should be set to "Debug" and "C/C++ Application" should point to "default\megatris.elf"
  • Click the debugger tab
  • In the "Debugger" drop-down, choose "gdbserver Debugger"
  • Uncheck "Stop on startup" if you do not want the debugged to stop in main() when you start debugging
  • Under the debugger options, in the "Main" tab, set GDB debugger to "avr-gdb" or browse to your local copy (i.e: C:\winavr\bin\avr-gdb.exe)
  • Clear the field "GDB command file"
  • Enter the "Connection" tab.
    • If you don't see a "Connection tab", look at the bottom of the pane for the string "Using GDB (DSF) Create Process Laucher".
    • Click "Select Other", then check box "Use configuration specific settings.
    • Select "Standard Create Process Laucher", click Ok.
  • For type choose TCP, set hostname to "localhost" and port to "1284"
  • If you get a red "X" with something mentionning a process launcher, click "select other..." , check "use configuration specific settings" and choose the "standard create process laucher"
  • Click Apply

Create the launch group

  • Within the same Debug Configurations window, select "Lauch Group" in the left panel and click the new button
  • Name you configuration like "Debug on uzem (Megatris)"
  • In the right panel, click the "Add..." button
  • In the "Launch mode" drop-down, select "run"
  • Expand "Program", select "Run in emulator (Megatris)" and click Ok
  • Click "Add..." again
  • Expand "C/C++ Application", select "Megatris Debug configuration" and click Ok
  • Click Apply

Makefile parameters

To be able to fully use the uzem GDB debugging features (like variable visualization) your must set these debugging options in the Makefile:

ASMFLAGS += -g3 -Wa,-gdwarf2

CFLAGS += -g3 -gdwarf-2


Click the debug icon's little down arrow and select "Debug on uzem (Megatris)" from the list. Uzem will launch your game, then the debugger will start. You are now ready to debug!

From here you can set breakpoints (I personally, can't see any variables in the variables tab, but I can see the values of all the CPU registers, which is super useful);

Terminating the debugger will close the session, and the emulator.

Beware the optimizing compiler! Compiler optomizations will often, strip out of reorder code you have written. This can cause strange behavior in the debugger if you set a breakpoint to a piece of code that was removed, or want to check the value of a variable that was removed. This is especially bad if your fond of writing test functions that perform computations but don't return a value. In this case you may want to set the optimization to -O0 instead of -Os in the makefile. But beware, this will make your code much bigger and slower.


External Links

TODO: add screen shots of the steps