#171836 - Gordin - Mon Dec 28, 2009 11:47 pm
Currently there's only a video for the setup (+compiling of libs) of devkitARM, and for extending the Makefile, other steps will follow!
Videos online:
Setting up devkitARM - http://is.gd/5J3pm
Extending the Makefile - http://is.gd/5LU7o
I just managed to setup devkitARM, libnds, eclipse and gdb so I can build, run, use code completion AND debug with Eclipse (stepping through code, viewing variables n stuff) and I figured this could be helpful to some people so here is a little (maybe not that little 0o) tutorial on how to set this up. Keep in mind though that this is probably not the best way to set this up, it's just my way and it works for me and I think it will work for other people too. If you want to improve this in any way please post suggestions. Note that I done this under linux but I don't see why this wouldn't work on windows or mac.
So this is what you need before you can setup eclipse for debugging:
1. You need to know where to put your devkitpro folder and how/where to set up the DEVKITPRO and DEVKITARM environment variables. This is different for windows/mac/linux but there are enough other tutorials for that.
2. Eclipse CDT
I'm not going to explain how to install that (use google). I don't know which versions are needed, I'm using Eclipse 3.5.1 with CDT 6.0.1 (the newest versions I think). It shouldn't really matter as far as functionality goes but because the Eclipse interface tends to randomly change with version numbers I think it's best to use the same versions...
Also you should know a little bit about the interface of eclipse e.g. if you have to open the c++ perspective you should to be able to do it (there aren't any screenshots in this tutorial...)
3. Desmume compiled with --enable-gdb-stub and glade or cli interface
Note that you CANNOT use the normal gtk-interface of desmume (at least it doesn't work for me, maybe it works on windows? 0o), so you will have to use desmume-glade or desmume-cli when debugging
first run desmume-glade --arm9gdb=2159 SOME_NDS_FILE.nds
if desmume tells you, that it doesn't know what to do with the arm9gdb thing AND/OR you don't have either desmume-glade or desmume-cli you will need to get the desmume source and compile it yourself with
./configure --enable-gdb-stub && make && make install
(or whatever you do to compile and install stuff on your system)
if this is working and you run desmume with the arm9gdb parameter desmume should open, but the rom will not start to run until you tell it to with a debugger.
4. gdb compiled for NDS architecture
this is actually already included in devkitARM, I just wanted to point out that you shouldn't try to use a standard gdb
5. libs with debug information, that is correct for your system
basically that means that you have to get the source for libnds and the other libs that you want to use and compile them yourself. (This may sound complicated to some people but it's really just a few simple steps, figuring out how to configure Eclipse was A LOT harder...) The reason that you need to do that is, when you step through the code, the debugger needs to know where the source files are that you wanna step through, but libnds e.g. was compiled in the folder /Users/davem/something... and that is where your debugger is going to seach for the source when you try to step through code from libnds. (besides that if you do not compile from source you probably do not even have the source at all...) So the easiest way is to just compile all your libs where you are going to use them.
=== Setting up devkitARM + libs ===
Video for this step: http://is.gd/5J3pm
To make sure, that everything we use will have correct debug information, we are going to compile all libs provided by devkitPro for ds-development from source.
So go and grab devkitARM, the nds-examples and the sources for libnds, dswifi, maxmod, libfat, libfilesystem and default-arm7 from sourceforge. You will also need to compile other libs yourself as well if you want to steph through their code but the stuff provided by devkitPro is enough for now.
When you downloaded everything do NOT extract it in your download folder, extract it directly to the folder, WHERE YOU WANT IT TO BE WHEN YOU ARE DONE setting everything up. For me this is /opt/devkitpro. It might be good to start with a clean devkitpro folder so backup/rename/delete your old one.
After extracting your devkitpro folder should look like this:
(besides devkitARM the folder names and versions do not matter, just make sure everything has it's own folder and that you don't rename/move anything after compiling)
default_arm7-src-0.5.8/
devkitARM/
dswifi-src-0.3.11/
libfat-src-1.0.6/
libfilesystem-src-0.9.4/
libnds-src-1.4.0/
maxmod-src-1.0.6/
nds-examples-20091201/
Now setup the Environment variables DEVKITPRO and DEVKITARM to their respective folders so we can start compiling things for our devkit. After that:
The order here IS important, because some libs bepend on a lib that has to be compiled first
1. go into the libnds folder and do 'make install'
2. go into the dswifi folder and do 'make install'
3. go into the maxmod folder and do 'make install-nds'
4. go into the defaull-arm7 folder and do 'make install'
5. go into the libfat folder and do 'make nds-install'
6. go into the libfilesystem folder and do 'make install'
Now we compiled everything we need to test the toolchain and the install options already put the libs where they belong, so try to compile the HelloWorld thing with the toolchain you just set up. If it works and you can successfully run the nds file in desmume we are almost ready to set up Eclipse.
=== Extending an examle-makefile for easier debugging ===
If you never use the command line and want to do everything in Eclipse from now on you can leave this step out
Video for this step: http://is.gd/5LU7o
We are going to change one of the Makefiles from the examples so you can use it as a template to debug other projects. To do that we are going to add the options run and debug to the Makefile. First go to the line that starts with .PHONY and add the words run and debug at the end like this:
.PHONY: $(BUILD) clean run debug
then search for the clean: block
below the 2 lines that follow add some code so it looks like this:
(the free space in front of the lines has to be 1 tab!)
So what does this do? We now can call 'make run' to compile our project and start the program in desmume and we can do 'make debug' to compile and start our program in desmume waiting and listening in "debug mode" on port 2159 (Which is according to google the standard port for gdb debugging, so it shouldn't interfere with any other ports you might be using.)
In the run: block you can replace desmume-glade with desmume-cli or just desmume if you don't like the glade interface but do NOT use just desmume in the debug: block because you won't be able to debug if you do! (again it SHOULD work with just desmume but for me it just doesn't, so to be sure just use the glade interface)
=== Setting up Eclipse ===
/// Getting Eclipse to build nds projects\\\
Assuming you are starting from a clean workspace first make sure that you are in the c++ perspective. Than create a new c++ project (c project should work too I guess) and choose Makefile project-> Empty Project and select -- Other Toolchain --.
Click Next and then on 'Advanced settings...' because there are a few settings we have to change
1. C/C++ Build: In the Behaviour tab remove the 'all' in the 'Build (incremental build)' field
2. C/C++ Build/Environment: Add the variables DEVKITPRO and DEVKITARM there (the values should be the same values that you used to compile the toolchain) depending on your system and where you have set up your Environment you may not need to do this step (I didn't have to) You can check if eclipse already knows the variables at 'build variablas' tab when you click on 'Show system variables'. If DEVKITPRO and DEVKITARM are there and set correctly you shouldn't need to set them again in Eclipse
3. C/C++ Build/Settings: select GNU Elf Parser (maybe you can leave this out, not sure here)
Click OK and then Finish to finish the creation of the project.
Now take the files from one of the examples and copy them over to the folder of your empty new project (you should use the modified Makefile, Eclipse doesn't need it but you will have less to type when starting a debug session).
Click on your project in the project view and press F5 to refresh the files. Try to build to project in eclipse now (the little hammer symbol in the toolbar). Look at the console view. the project should have been compiled correctly. If it tells you to set one of the DEVKIT variables go to the project Properties and play around with with the environment variables, Eclipse sometimes does strange things with them.... (set them, delete them, use the whole path in DEVKITARM, etc.) DO NOT CONTINUE UNTIL THIS WORKS.
/// Set up code completion \\\
If you do not care about code completion you can skip this but I think it's nice to have this :)
To make code completion work we have to tell eclipse where the libraries we are using are located we are using. (If you are wondering why you can build stuff without eclipse knowing the libraries thats because we dont use the eclipse compiler but the devkitARM one)
To tell Eclipse where to look for the libraries go again to the project properties and then to C/C++ General-> Paths and Symbols.
Go to the include tab and click 'Add...'
Use 'File system...' and Browse to DEVKITPRO-FOLDER/devkitARM/arm-eabi/include, click on 'Add to all languages' and click OK
do the same for DEVKITPRO-FOLDER/libnds/include
Now click OK, Eclipse should tell you that it needs to rebuild its idnex. click OK again.
If you added the right folders eclipse now knows all the includes from devkitARM and libnds and code-completion should be working.
/// Set up debugging \\\
Now we are going to set up a debug-configuration for gdb-remote debugging, so Eclipse can connect to a running desmume with open debug port. First Open up Run->Debug Configurations
There should already be one configuration named after the .elf file that is created besides the .nds file when you do 'make' e.g. hello_wold.elf. If there is no configuration, select C/C++ Application and create one.
Then in the main tab Project should be your project-name and the application should be the .elf file
Lets go to the debugger tab
Set the debugger to 'gdbserver Debugger'. In the Debugger Options 'Main' tab remove the .gdbinit from the 'GDB command file' field and (this is important) set 'GDB debugger' to DEVKITPRO-FOLDER/devkitARM/bin/arm-eabi-gdb. In the Debugger Option 'Connection' tab set Type to TCP and then the Port Number to 2159
If you like you can go to the 'Common' tab and put this configuration in the favorites menu.
You can now close the debug configuration.
we have now set up everything we need to do debugging and step through the code!
But we will make the process of starting a debugging-session a bit simpler before we test the final setup.
(thanks to cyril_sy for the idea)
Go to Run->External Tools-> External Tools configurations and create a new Launch configuration under Program
Name it desmume debug-mode (or something else that indicates that desmume is going to be started in debug mode)
In the Main tab:
in Location choose Browse File System and point to the desmume executable. For me this is /usr/bin/desmume-glade (remember to NOT choose just desmume...)
in Working Directory put ${project_loc} as the nds-file will be located there
in Arguments put --arm9gdb=2159 ${project_name}.nds
(the nds file is named after the folder you compile it in which is named after the project. if you changed this somehow you might have to put something different in front of .nds)
In the Build tab:
choose 'The project containing...' instead of 'The entire workspace'
In the Common tab you can check the 'Display in favorites menu' if you want
Now press Apply and close and go to Debug configurations one last time
This time Create create a new Launch Group and name it something...
in the Launches tab:
click 'Add...' and choose Launch Mode: run->Program->desmume debug-mode and click OK
Then add Launch Mode: debug->C/C++ Application->SOMETHING.elf
if you want you can add this to a favorites menu in the common tab (you should do that because you will use this to start debugging...)
NOW we really set up everything we need to start debugging :)
/// Actually DO debugging \\\
To start debugging now all we have to do is go to the debug or run favorites menu and click on the Launch Group we just created. (It's the one with the green arrow) Note that you have to be somewhere IN the project e.g. inside the editor with code from your project or eclipse will tell you that a problem occurred and ${project_loc} is empty.
Now if you click on the Launch group Eclipse will automatically compile the project, start desmume with your nds file in debug mode and after about 5-20 seconds (don't know where that delay comes from) go in debug mode and connect to desmume.
You should now be ably to step through the code, set breakpoints, view variables and all the other cool stuff you can do with gdb :)
Note that after you are done debugging and terminated the session you will need to close desmume yourself
If someone actually read through this and done this please tell me if it worked ^^
Last edited by Gordin on Sun Jan 17, 2010 9:23 pm; edited 13 times in total
Videos online:
Setting up devkitARM - http://is.gd/5J3pm
Extending the Makefile - http://is.gd/5LU7o
I just managed to setup devkitARM, libnds, eclipse and gdb so I can build, run, use code completion AND debug with Eclipse (stepping through code, viewing variables n stuff) and I figured this could be helpful to some people so here is a little (maybe not that little 0o) tutorial on how to set this up. Keep in mind though that this is probably not the best way to set this up, it's just my way and it works for me and I think it will work for other people too. If you want to improve this in any way please post suggestions. Note that I done this under linux but I don't see why this wouldn't work on windows or mac.
So this is what you need before you can setup eclipse for debugging:
1. You need to know where to put your devkitpro folder and how/where to set up the DEVKITPRO and DEVKITARM environment variables. This is different for windows/mac/linux but there are enough other tutorials for that.
2. Eclipse CDT
I'm not going to explain how to install that (use google). I don't know which versions are needed, I'm using Eclipse 3.5.1 with CDT 6.0.1 (the newest versions I think). It shouldn't really matter as far as functionality goes but because the Eclipse interface tends to randomly change with version numbers I think it's best to use the same versions...
Also you should know a little bit about the interface of eclipse e.g. if you have to open the c++ perspective you should to be able to do it (there aren't any screenshots in this tutorial...)
3. Desmume compiled with --enable-gdb-stub and glade or cli interface
Note that you CANNOT use the normal gtk-interface of desmume (at least it doesn't work for me, maybe it works on windows? 0o), so you will have to use desmume-glade or desmume-cli when debugging
first run desmume-glade --arm9gdb=2159 SOME_NDS_FILE.nds
if desmume tells you, that it doesn't know what to do with the arm9gdb thing AND/OR you don't have either desmume-glade or desmume-cli you will need to get the desmume source and compile it yourself with
./configure --enable-gdb-stub && make && make install
(or whatever you do to compile and install stuff on your system)
if this is working and you run desmume with the arm9gdb parameter desmume should open, but the rom will not start to run until you tell it to with a debugger.
4. gdb compiled for NDS architecture
this is actually already included in devkitARM, I just wanted to point out that you shouldn't try to use a standard gdb
5. libs with debug information, that is correct for your system
basically that means that you have to get the source for libnds and the other libs that you want to use and compile them yourself. (This may sound complicated to some people but it's really just a few simple steps, figuring out how to configure Eclipse was A LOT harder...) The reason that you need to do that is, when you step through the code, the debugger needs to know where the source files are that you wanna step through, but libnds e.g. was compiled in the folder /Users/davem/something... and that is where your debugger is going to seach for the source when you try to step through code from libnds. (besides that if you do not compile from source you probably do not even have the source at all...) So the easiest way is to just compile all your libs where you are going to use them.
=== Setting up devkitARM + libs ===
Video for this step: http://is.gd/5J3pm
To make sure, that everything we use will have correct debug information, we are going to compile all libs provided by devkitPro for ds-development from source.
So go and grab devkitARM, the nds-examples and the sources for libnds, dswifi, maxmod, libfat, libfilesystem and default-arm7 from sourceforge. You will also need to compile other libs yourself as well if you want to steph through their code but the stuff provided by devkitPro is enough for now.
When you downloaded everything do NOT extract it in your download folder, extract it directly to the folder, WHERE YOU WANT IT TO BE WHEN YOU ARE DONE setting everything up. For me this is /opt/devkitpro. It might be good to start with a clean devkitpro folder so backup/rename/delete your old one.
After extracting your devkitpro folder should look like this:
(besides devkitARM the folder names and versions do not matter, just make sure everything has it's own folder and that you don't rename/move anything after compiling)
default_arm7-src-0.5.8/
devkitARM/
dswifi-src-0.3.11/
libfat-src-1.0.6/
libfilesystem-src-0.9.4/
libnds-src-1.4.0/
maxmod-src-1.0.6/
nds-examples-20091201/
Now setup the Environment variables DEVKITPRO and DEVKITARM to their respective folders so we can start compiling things for our devkit. After that:
The order here IS important, because some libs bepend on a lib that has to be compiled first
1. go into the libnds folder and do 'make install'
2. go into the dswifi folder and do 'make install'
3. go into the maxmod folder and do 'make install-nds'
4. go into the defaull-arm7 folder and do 'make install'
5. go into the libfat folder and do 'make nds-install'
6. go into the libfilesystem folder and do 'make install'
Now we compiled everything we need to test the toolchain and the install options already put the libs where they belong, so try to compile the HelloWorld thing with the toolchain you just set up. If it works and you can successfully run the nds file in desmume we are almost ready to set up Eclipse.
=== Extending an examle-makefile for easier debugging ===
If you never use the command line and want to do everything in Eclipse from now on you can leave this step out
Video for this step: http://is.gd/5LU7o
We are going to change one of the Makefiles from the examples so you can use it as a template to debug other projects. To do that we are going to add the options run and debug to the Makefile. First go to the line that starts with .PHONY and add the words run and debug at the end like this:
.PHONY: $(BUILD) clean run debug
then search for the clean: block
below the 2 lines that follow add some code so it looks like this:
(the free space in front of the lines has to be 1 tab!)
Code: |
#--------------------------------------------------------------------------------- clean: @echo clean ... @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba ######################### CODE TO ADD STARTS HERE ############################# #--------------------------------------------------------------------------------- run: $(BUILD) @echo running in desmume ... @desmume-glade $(OUTPUT).nds #--------------------------------------------------------------------------------- debug: $(BUILD) @echo debugging in desmume ... @desmume-glade --arm9gdb=2159 $(OUTPUT).nds ######################### CODE TO ADD ENDS HERE ############################## #--------------------------------------------------------------------------------- else |
So what does this do? We now can call 'make run' to compile our project and start the program in desmume and we can do 'make debug' to compile and start our program in desmume waiting and listening in "debug mode" on port 2159 (Which is according to google the standard port for gdb debugging, so it shouldn't interfere with any other ports you might be using.)
In the run: block you can replace desmume-glade with desmume-cli or just desmume if you don't like the glade interface but do NOT use just desmume in the debug: block because you won't be able to debug if you do! (again it SHOULD work with just desmume but for me it just doesn't, so to be sure just use the glade interface)
=== Setting up Eclipse ===
/// Getting Eclipse to build nds projects\\\
Assuming you are starting from a clean workspace first make sure that you are in the c++ perspective. Than create a new c++ project (c project should work too I guess) and choose Makefile project-> Empty Project and select -- Other Toolchain --.
Click Next and then on 'Advanced settings...' because there are a few settings we have to change
1. C/C++ Build: In the Behaviour tab remove the 'all' in the 'Build (incremental build)' field
2. C/C++ Build/Environment: Add the variables DEVKITPRO and DEVKITARM there (the values should be the same values that you used to compile the toolchain) depending on your system and where you have set up your Environment you may not need to do this step (I didn't have to) You can check if eclipse already knows the variables at 'build variablas' tab when you click on 'Show system variables'. If DEVKITPRO and DEVKITARM are there and set correctly you shouldn't need to set them again in Eclipse
3. C/C++ Build/Settings: select GNU Elf Parser (maybe you can leave this out, not sure here)
Click OK and then Finish to finish the creation of the project.
Now take the files from one of the examples and copy them over to the folder of your empty new project (you should use the modified Makefile, Eclipse doesn't need it but you will have less to type when starting a debug session).
Click on your project in the project view and press F5 to refresh the files. Try to build to project in eclipse now (the little hammer symbol in the toolbar). Look at the console view. the project should have been compiled correctly. If it tells you to set one of the DEVKIT variables go to the project Properties and play around with with the environment variables, Eclipse sometimes does strange things with them.... (set them, delete them, use the whole path in DEVKITARM, etc.) DO NOT CONTINUE UNTIL THIS WORKS.
/// Set up code completion \\\
If you do not care about code completion you can skip this but I think it's nice to have this :)
To make code completion work we have to tell eclipse where the libraries we are using are located we are using. (If you are wondering why you can build stuff without eclipse knowing the libraries thats because we dont use the eclipse compiler but the devkitARM one)
To tell Eclipse where to look for the libraries go again to the project properties and then to C/C++ General-> Paths and Symbols.
Go to the include tab and click 'Add...'
Use 'File system...' and Browse to DEVKITPRO-FOLDER/devkitARM/arm-eabi/include, click on 'Add to all languages' and click OK
do the same for DEVKITPRO-FOLDER/libnds/include
Now click OK, Eclipse should tell you that it needs to rebuild its idnex. click OK again.
If you added the right folders eclipse now knows all the includes from devkitARM and libnds and code-completion should be working.
/// Set up debugging \\\
Now we are going to set up a debug-configuration for gdb-remote debugging, so Eclipse can connect to a running desmume with open debug port. First Open up Run->Debug Configurations
There should already be one configuration named after the .elf file that is created besides the .nds file when you do 'make' e.g. hello_wold.elf. If there is no configuration, select C/C++ Application and create one.
Then in the main tab Project should be your project-name and the application should be the .elf file
Lets go to the debugger tab
Set the debugger to 'gdbserver Debugger'. In the Debugger Options 'Main' tab remove the .gdbinit from the 'GDB command file' field and (this is important) set 'GDB debugger' to DEVKITPRO-FOLDER/devkitARM/bin/arm-eabi-gdb. In the Debugger Option 'Connection' tab set Type to TCP and then the Port Number to 2159
If you like you can go to the 'Common' tab and put this configuration in the favorites menu.
You can now close the debug configuration.
we have now set up everything we need to do debugging and step through the code!
But we will make the process of starting a debugging-session a bit simpler before we test the final setup.
(thanks to cyril_sy for the idea)
Go to Run->External Tools-> External Tools configurations and create a new Launch configuration under Program
Name it desmume debug-mode (or something else that indicates that desmume is going to be started in debug mode)
In the Main tab:
in Location choose Browse File System and point to the desmume executable. For me this is /usr/bin/desmume-glade (remember to NOT choose just desmume...)
in Working Directory put ${project_loc} as the nds-file will be located there
in Arguments put --arm9gdb=2159 ${project_name}.nds
(the nds file is named after the folder you compile it in which is named after the project. if you changed this somehow you might have to put something different in front of .nds)
In the Build tab:
choose 'The project containing...' instead of 'The entire workspace'
In the Common tab you can check the 'Display in favorites menu' if you want
Now press Apply and close and go to Debug configurations one last time
This time Create create a new Launch Group and name it something...
in the Launches tab:
click 'Add...' and choose Launch Mode: run->Program->desmume debug-mode and click OK
Then add Launch Mode: debug->C/C++ Application->SOMETHING.elf
if you want you can add this to a favorites menu in the common tab (you should do that because you will use this to start debugging...)
NOW we really set up everything we need to start debugging :)
/// Actually DO debugging \\\
To start debugging now all we have to do is go to the debug or run favorites menu and click on the Launch Group we just created. (It's the one with the green arrow) Note that you have to be somewhere IN the project e.g. inside the editor with code from your project or eclipse will tell you that a problem occurred and ${project_loc} is empty.
Now if you click on the Launch group Eclipse will automatically compile the project, start desmume with your nds file in debug mode and after about 5-20 seconds (don't know where that delay comes from) go in debug mode and connect to desmume.
You should now be ably to step through the code, set breakpoints, view variables and all the other cool stuff you can do with gdb :)
Note that after you are done debugging and terminated the session you will need to close desmume yourself
If someone actually read through this and done this please tell me if it worked ^^
Last edited by Gordin on Sun Jan 17, 2010 9:23 pm; edited 13 times in total