Instructables

Arduino Debugging - Breakpoints, Tracepoints and Expressions

video Arduino Debugging - Breakpoints, Tracepoints and Expressions
This tutorial shows how to get started with the Arduino debug tools from Visual Micro. The debug tool is integrated into the Microsoft Visual Studio Professional development system which also provides 100% compatible Arduino programming, compile and upload.

Programming with a debugger has long been considered an important tool for every software developer. Arduino does not normally provide debug facilities, so this tool is, in some ways, breaking new ground.

In this video we demonstrate how to add breakpoints that allow us to inspect expressions while an Arduino is running.

This video tutorial also demonstrates how to add conditions to breakpoints. Conditions are very useful when looking for exceptions to the "norm".

The tutorial also shows how to switch between normal Arduino compilation and debug compilation, how to compile and how to upload to any Arduino board.

The Arduino plugin for Visual Studio is free, the debug tool, which is in final beta, will be an optional low cost upgrade but is currently available for free to anyone who wants to try it. We expect this offer to end in December 2012. To obtain a free copy of the debug tool simply join the Visual Micro Forum and request to join the debug beta team.

If you do not have a copy of Visual Studio 

Microsoft Visual Studio Professional is available free to everyone for 90 days and can also be obtained free for 3 years by many groups of users ranging from Students, Private Individuals and Small Companies.
visualmicro (author) 1 year ago
I forgot to mention one other point related to the comment by maewert.

We found a slightly different but related issue that affected new users to Arduino.

The first thing new users tend to do is to add a debugger TracePoint in the main loop() of the Arduino without any conditions and without any form of delay.

The problem with that was that the Arduino can send messages faster than some slower computers can process them. This would cause the debugger display on the pc to drop behind real-time and be out of sync with what is really happening on the Arduino..

So many messages is not very useful for real world debugging but we wanted the debugger to handle this situation and prevent users from loosing confidence in the tool.

As a result we implemented an intelligent throttling system on the Arduino that blocks and forces the Arduino to wait for up to 40 milliseconds if two Tracepoints are hit within a 40 millisecond time span.

The throttle delay is On by default, the delay is configurable in the project configuration properties window and can be disabled entirely (set to false) if required.
maewert1 year ago
Wow, a very nice and needed tool set for the Arduino!

In a nutshell breakpoints are compiled into the code and are implemented as serial data exchanged between the PC and the Arduino. The downsides of this approach include larger code size (which could make it too large to load into some chips) and is disruptive to actual code timing.

Very beautiful and useful but the user must be aware of the tool's limitations (which is always true:-)

I assume the tool treats all of the Arduino library calls as atomic calls and can not step into (provide visibility into) those. Might be interesting to see how the tool works with both older and newer serial calls which are now non blocking - would the message ordering change?

Too bad the tools are closed PC-centric tools. Maybe someone will create an open source IDE for the debugger.

Thanks again!
visualmicro (author)  maewert1 year ago
Thanks for the feed back. Initially we thought the memory overhead of the debug commands might not be practical but in reality it is very small and works well. So far none of the 100 testers have encountered a memory limit issues.

However, it turned out that debugging with this tool takes a lot less memory than using normal serial debug messages because, with the debugger, none of the string messages are compiled onto the Arduino.

It is the strings that suck the Arduino memory. Instead, each breakpoint is allocated a number staring at 1 allowing the tool to show the correct text message in the trace windows when required.

We found that new users tended to litter their code with serial debug text messages. One user had 1600 bytes of "old style" manual debug messages which caused his Arduino to crash. He switched all of his debug messages to breakpoints using the new tool which consumed less than 200 bytes. A happy user was he :) You will find more examples similar to this on our forum.

The more advanced an arduino program is then the less memory the debugger uses. This is a result not of our code but of how the Arduino compiler works. For example, if you are already using Serial in an Arduino program then the debugger will appear to consume very little memory. If not then it will consume the normal overhead associated with use of the Arduino Serial object.

Stepping is only between breakpoints, you can not step line by line unless you add a breakpoint to every line you want to step. This is a compromise that seems to work nicely for everyone who has tested it so far.

Debugging .Ino and cpp files is supported, libraries in the next release due in a few weeks.

A restriction of this system is that you are only able to add breakpoints where you would normally be able to add Serial commands. But that is a lot better than nothing and will satisfy most users!

The system is unaffected by serial methods, the Arduino streams the messages in the correct order even when not blocking.

We have also tested with SoftwareSerial on random digital pins and it works really well. Actually if you do not want to enable break/pause/continue and you work in trace/report only mode then you only need 1 digital pin, 1 wire and an FDTI cable. The debugger is just as smooth with software serial.

One upside of serial transports for debugging is that is works over radios such as xbee, so this means we also have remote debugging. Another upside is that is doesn't require additional hardware or a rocket scientist to make it work :)

Yes we would like to add this feature to other IDE's, hopefully open source.

However if you investigate the open source debugger visualization extensions on visualmicro.com you will see that they are built using C#. So in this case Visual Studio Professional provides Arduino Compilation, Arduino Debug and also the ability to build new Windows Controls as Graphical Debug Data Visualizations.

Visual Studio also manages the docking and layout capabilities of all debug monitor and tool windows. So it won't easy to find another IDE that does it all!

However, the basic debugger doesn't need the visualizations to work and I know how this community loves a chellenge :)

Thanks again for your good observations. I know that Arduino are working on a new IDE due over the next year or two. If the tool provides some of the features we feel are important for micro-controller development such as intellisense and code completion then we will be excited to help bring this debug tool to a more open world.