[En-Nut-Discussion] debug NutOS AVR gcc
José Vallet
jose.vallet at hut.fi
Thu Jan 19 11:41:45 CET 2006
Hello.
I am trying to debug my code, and I have not found any tutorial that
would help me in the first steps. Usually I use the printf through the
serial port, but it is time for me to get serious about it. So after
reading quite a bit, I have reached some newbie conclusions that I write
here, and that I think they will be useful for more like me. This is
written from a newbie to another newbie, trying to solve some questions
that I have had. I would like you to share your expertise here, so
please comment/complete and correct me.
HOW TO GENERATE THE DEBUG INFORMATION
First of all, for debugging we need to compile the code including
debugging information, which is done by feeding special arguments to the
compiler: -g3 -gdwarf-2. Now, what do we want to debug, the user's code
or the NutOS code?
1-In order to generate debug info of the NutOS code we have to activate
a flag in the NutOS configurator (Tools-GCC settings-Include debug
info). Once selected, the NutOS should be built again, so it is
re-compiled and the debugging information will be included.
2-In order to generate debug info of the user's code, we give to the
compiler (in my case gcc) the options by adding the line
HWDEF += -g3 -gdwarf-2
in a the file called UserConf.mk. There are two files with that name,
one in nutbld and another in nutapp directories. I supposse that the one
in nutbld is for including compiling options for the NutOS code itself,
and will not affect the user's own code. Thus, we could generate the
NutOS debug information by adding HWDEF += -g3 -gdwarf-2 to UserConf.mk
under nutbld directory instead of selecting the "Include debug info"
flag in the configurator (OK, this is just a wild guess, am I right?).
Then, rebuild NutOS.
For generating the debug info of the user's code, the compile options
should be placed in the UserConf.mk file under nutapp. This will not
affect the NutOS code.
3-For including debugging info of NutOS and the user's code, just do both.
HOW TO GENERATE THE FILES
The file that we will use for debugging has .elf or .cof extension. The
command "make myprogrmaname.elf" or "make myprogramname.cof" will
generate these files.
Question here: if we do "make all", the resulting .hex will have any
debugging info/extra stuff? I guess no, so it can be used straight for
the final executable version with no need to rebuild everything without
the -g3 -gdwarf-2 options.
HOW TO DEBUG: TOOLS
Basically, we have the following options regarding the environment.
1-One option is to use one emulator, like simulavr. This can be used
with gdb, and this one with any GUI (Insight, ddd...) The thing here is
that it seems that NutOS is too complicated for this emulator and
typically gets trapped. There are some commercial ones that are better.
2- Another option is to use an JTAG ICE. This way the code runs in the
microcontroller and the JTAG stuff controls the execution. The JTAG ICE
is connected to a computer through a serial cable, and in the computer
we need some kind of interface that "talks" to the JTAG ICE and the
debugger itself. Here we have several options.
*AVR Studio: includes both the program to talk to the JTAG and the
debugger. Accepts .cof and .elf formats. It seems that .elf is better.
*avarice+gdb+ possibly a gui. avarice is the program that talks to the
JTAG device and also acts as a server for gdb. Then, as always, we can
use one gui with gdb (for example insight or ddd again). I have read
somewhere that it has been reported to work in Linux. What about Windows
(WinAVR)?
3-The Linux emulation layer I suppose that can be used to debug as well,
right? In this case we would be debugging the code like in a normal
Linux program (gdd+gui)
That was more or less a resume of what I got from my readings. There
might be something that I do wrong, because I still get some errors. I
will post them in a new mail.
Thanks in advance.
José
More information about the En-Nut-Discussion
mailing list