What debugger to buy to debug arduino code line by line?

What are some hardware debuggers that one can buy to debug arduino code line by line? I am using Atmega328. My code can also work on Atmel Studio 6. Which are the hardware debugger that you have used before and recommend?

None. There are no hardware debuggers for the ATmega328P. What do you want to debug ?

[EDIT] as Coding Badly writes in Reply #10, there is debugWire.

Peter_n:
None. There are no hardware debuggers for the ATmega328P. What do you want to debug ?

Is it because there is no JTAG interface on Atmega328?

No JTAG, no nothing.

[EDIT] as Coding Badly writes in Reply #10, there is debugWire.

I was musing on this question, but holding fire.

The debugger is the IDE.

Because the download process is so fast, you insert "breakpoints" into the source and use the serial monitor to gauge the effect. It is as they say, "not rocket science". I venture to say if you have to debug line-by line with a hardware debugger, you must have a very poor grasp on your code.


{Do people really de-bugger "C" code with hardware debuggers? }

I have found debugging with simple Serial.print() or Serial.println() statements to be sufficient for most projects. Add some statements to confirm your code is reaching the sections you think it is, if not look at variable values before that to see what is occurring or not. Comment them out as you get things fixed up.
Sometimes monitoring serial activity with a SPI/I2C/Serial protocol analyzer or a logic analyzer (www.saleae.com Logic 8 is good for both) or an oscilloscope is needed to confirm signal conditions. I have a 4-channel 200 MHz digital storage scope for that, you can get by with a lot less tho (and I did for a long time) with a simple 2-channel analog scope too.

You can write Debug Macros then keep them handy and use them as required.
These can be disabled by commenting out a single line i.e.
// #define DEBUG

/*
  Blink
 Turns on an LED on for one second, then off for one second, repeatedly.
 
 This example code is in the public domain.
 */

//***************************************************************

#define DEBUG       //If you comment this line the DPRINT & DPRINTLN

//lines are defined as blank.
//examples:
//DPRINTLN("Testing123");    
//DPRINTLN(0xC0FFEEul,DEC);
//DPRINTLN(12648430ul,HEX);

#ifdef DEBUG
#define DPRINT(...)              Serial.print(__VA_ARGS__)
//OR, #define DPRINT(args...)    Serial.print(args)
#define DPRINTLN(...)            Serial.println(__VA_ARGS__)
#define DPRINTF(...)              Serial.print(F(__VA_ARGS__))
#define DPRINTLNF(...)           Serial.println(F(__VA_ARGS__))
#define DBEGIN(...)              Serial.begin(__VA_ARGS__)
#define DDELAY(...)              delay(__VA_ARGS__)

#else
#define DPRINT(...)              //blank line
#define DPRINTLN(...)            //blank line
#define DPRINTF(...)             //blank line
#define DPRINTLNF(...)           //blank line
#define DBEGIN(...)              //blank line
#define DDELAY(...)              //blank line


#endif
//***************************************************************


// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

int z = 123;

void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
  Serial.begin(9600);

}

void loop() {
  digitalWrite(led, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(led, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second

  DPRINTLN("Testing123");
  DPRINTLN(0xC0FFEEul,DEC);
  DPRINTLN(12648430ul,HEX);
  DPRINTLNF("This is in your flash");
  DPRINTLN( z );
  DPRINTLN();
}

Maybe put the macros in a library TAB

Peter_n:
None. There are no hardware debuggers for the ATmega328P. What do you want to debug ?

  1. debugWIRE On-chip Debug System
    25.1 Features
    • Complete Program Flow Control
    • Emulates All On-chip Functions, Both Digital and Analog, except RESET Pin
    • Real-time Operation
    • Symbolic Debugging Support (Both at C and Assembler Source Level, or for Other HLLs)
    • Unlimited Number of Program Break Points (Using Software Break Points)
    • Non-intrusive Operation
    • Electrical Characteristics Identical to Real Device
    • Automatic Configuration System
    • High-Speed Operation
    • Programming of Non-volatile Memories

If debugWIRE is not "hardware debugging" then what is it?

O, I totally forgot about debugWire. You are right Coding Badly. It seems that some can make it work with Arduino.

The preferred reasonable-cost ($50 to $100)e debugger for Atmel MCUs these days is the "Atmel ICE"
http://www.atmel.com/tools/atatmel-ice.aspx (The "Basic" version is the cheap one.)
Unlike earlier debug hardware (Dragon, JTAG-ICE 3), the Atmel ICE supports ALL of the several protocols (DebugWire, TPI, awire, Jtag, PDI, etc) and several device families (AVR, SAM, AVR32) that Atmel manufactures.

The Arduino auto-reset circuitry interferes with debugwire, so some hardware modifications will be needed to get it working.

Atmel debugging protocols are proprietary and undocumented, so there is no 3rd party debugging hardware that I know of. And of course, the Arduino IDE does not support debugging, so you'll have to figure our Atmel Studio, or gdb, or something.

It might be easier to get something like a Atmega328 Xplained Mini, which is sort-of like an arduino, but has a debugging chip included (like the Arduino Zero is supposed to.) And it's only about $10. As of recently, Atmel IS documented in the "host side" of the debugger interface chips used on these boards.

lightaiyee:
What are some hardware debuggers that one can buy to debug arduino code line by line? I am using Atmega328. My code can also work on Atmel Studio 6. Which are the hardware debugger that you have used before and recommend?

It is virtually impossible to debug time-dependent code using a debugger, because it ... well ... takes time.

As for non-time dependent code, put in serial prints. Or send debugging info to another processor. Or use debugging pins.

It might be easier to get something like a Atmega328 Xplained Mini

Downside is it does not intergrate with Arduino.

The Xplained Mini ought to be pretty close to being exactly an Uno, so you can program it with the IDE (perhaps after adding a bootloader.)

For debugging ... It's not impossible to point something like Atmel Studio at the Arduino object and source files, and debug a sketch that was compiled with the IDE. I've done it. It's not EASY, as it really needs to be to attract the arduino audience, but it is possible. And then there is the Visual Micro addon for Atmel Studio, which lets you compile and debug Arduino sketches from AS. And there's gdb - there should be a mebdg-gdb bridge soon, if there isn't already (AVRICE?)

I was hoping that some Arduino Team Member had had some brilliant insight into making debugging more approachable than what we usually see. But apparently not :frowning:

The Xplained Mini appears to have the same pinout as an UNO. But the EBDG chip is on there too. There is also a ICSP header block.

And the EBDG chip is a 32u4!

gcc does allow running optimized code when built & linked for debugging.
Yes single stepping and breakpoints obviously disrupt the time flow, but when the code is normally running you aren't stuck with sub optimized code like with some other compilers.

On processors that execute in RAM you don't need extra ice type h/w to do source code debugging. You just have to compile in gdbmon and then have a way to communicate with it from your host running gdb.
Unfortunately, that doesn't work with the AVR h/w.

I have used an AVR dragon to source level debug arduino code on a m328 and tiny85 using ddd, gdb, and avrice.
It is pretty cool to be able to source level debug to an 8 pin chip.
It isn't that bad if you write your own makefiles but with Arduino,
it can be a bear to get it working with the Arduino IDE because the IDE is pretty hostile towards real embedded tool sets since so much is hard coded inside the IDE.
The 1.5x IDE is better now as you can modify your core's platform file and create wrapper scripts to set things up automatically.

If I were going to continue using AVRs and buying something today for source level debugging, I'd buy the atmel AVR ICE and not a dragon.
I think the ice is a better product and is a finished product vs the dragon which in my view was kind of a half asssed product that didn't even come with a case or cables.

--- bill

gcc does allow running optimized code

But optimized code tends to drift so far from source code that I would say that if you are a beginner, debugging optimized code with gdb/etc may be more confusing than more primitive debugging techniques (print/etc) "it's executing lines out of order and says my variable doesn't exist." (it's not always clear for advanced programmers either...)