Creating a Simple Arduino Debug Tracepoint

by Visual Micro 5. May 2012 09:09

In this example we create a simple debug trace point using the main Arduino serial port and the default Visual Micro settings. This article assumes that arduino debugging in Visual Studio has been enabled (see this post for a how to).

The Visual Studio Debugger Breakpoints Window is opened using CTRL+ALT+B or by clicking the menu item Debug>Windows>Breakpoints. Alternatively you can right mouse click the tool bars and show the "Debug" bar as shown below above the source code.

In the example below the breakpoints window is displayed below the source code. A single breakpoint has been added by clicking the left margin of the source.

During compilation - How are breakpoints added to a temporary copy of the code?

During compilation, breakpoints are added to the end of the selected code line, can not be added to comment lines but can be added to empty source lines. Adding breakpoints to empty source lines is recommended because it ensures you are happy with the exact position the debug code will be added to a copy of the code. For example, consider the following line of code:-

if (foo) {a=0;}

In the above example the debug engine would compile the following code which involves a significant code change and might, in a more complex example, lead to unexpected results. The debug engine tries a few tests to attempt a code injection and might fail or produce the wrong code. Hence the rule, add breakpoints to empty or simple lines of codes.

if (foo)
//some debug commands will be inserted here

SUGGESTION: Add debugger breakpoints to empty or simple lines of codes, see why at the end of this section

Other Pages