The usual path in debugging a C/C++ program would be to use
gdb. Embedded devices can be a challenge. So… we have http://avarice.sourceforge.net/. I haven’t tried using this with a microcontroller, and there are probably other solutions. Your best bet in any debugging that at all involves see situation is to look to GDB, so try googling “arduino gdb”, “avr gdb”, “avr-gcc gdb” etc. Somewhere you find a solution to step through your program and view the registers, view code as you step, that sort of thing, which is all built into gdb.
If anyone tries it, please share your results.