I am also very interested to hear from you all of other debugging techniques people are using inside or outside of various emulators.
For example, the author of FatFS has a nice little packages called "suart" for using the hardware ISP channel as a serial port for debugging: http://elm-chan.org
Here is my emulator patch to apply to avr8.cpp within avr8::exec():
Code: Select all
*** avr8.cpp.orig 2009-08-06 17:23:03.000000000 -0700
--- avr8.cpp 2009-08-06 17:31:03.000000000 -0700
***************
*** 1317,1322 ****
--- 1317,1335 ----
break;
}
+ /* Check for "magic" debug output */
+ {
+ const int magicAddr = 0xffe;
+ static int gotMagic=0;
+ unsigned char v = sram[magicAddr - SRAMBASE];
+ if (gotMagic && v != (unsigned char) '\xba') {
+ printf("%c", v);
+ gotMagic = 0;
+ } else if (v == (unsigned char) '\xba') {
+ gotMagic = 1;
+ }
+ }
+
#if DISASM
// Don't spew disassembly during interrupts
if (singleStep && !interruptLevel)
This hack is harmless if run on real hardware, and the emulator is uneffected if running a program which actually uses 0xffe (except for the slight chance that a spurious byte might be written to the stdout occassionally).
I then created a little set of inline wrapper print routines for printing strings, ints, hex, etc which are easily added to the project.
Code: Select all
#ifndef EMUDEBUG_H_
#define EMUDEBUG_H_ 1
#ifndef USE_EMU_DBG
# define USE_EMU_DBG 1
#endif
#ifndef DBG_ADDR
# define DBG_ADDR 0xffe
#endif
#define DBG_MAGIC '\xba'
#define DBG_PTR ((char volatile *) DBG_ADDR)
#if !USE_EMU_DBG
inline void DBGc(char value) {};
inline void DBGs(const char *s) {};
inline void DBGx(unsigned char byte) {};
inline void DBGi(int val) {};
#else
inline void DBGc(char value) {
*DBG_PTR = DBG_MAGIC;
*DBG_PTR = value;
}
inline void DBGs(const char *s) {
for (; *s != 0x0; s++)
DBGc(*s);
}
inline void DBGx(unsigned char byte) {
unsigned char nibble;
nibble=(byte>>4);
DBGc(nibble + (nibble < 10 ? '0' : '7'));
nibble=(byte&0xf);
DBGc(nibble + (nibble < 10 ? '0' : '7'));
}
inline void DBGi(int val) {
unsigned char c;
int v2,p,vlen;
if (val < 0) {
DBGc('-');
val = -val;
} else if (val == 0) {
DBGc('0');
return;
}
/* Determine number of digits */
v2 = val;
p = 1;
for (vlen=0; v2 != 0; v2 = v2 / 10)
p *= 10;
do {
p = p/10;
c = (val / p) % 10;
DBGc(c + '0');
val = val - c*p;
} while (p != 1);
}
#endif // USE_EMU_DBG
#endif //EMUDEBUG_H_