Breakpoint Actions: Showing Text and Watching Expressions When a Breakpoint is Hit

VS2015 Logo
This version of the documentation page applies only to Visual Studio 2015
Read documentation page for other VS versions and Atmel Studio here.

You can specify  information from your program (values of variables etc.) that shall be transmitted to Visual Micro when the breakpoint is hit. This can be a fixed text as well as values of variables or expressions. You can also change a variable's values on your PC and then can continue execution with the new variable value.

All this can be achieved with breakpoints that have a "Breakpoint action".

Note Icon Note

After making changes to your breakpoint as shown here, you must recompile and upload your sketch in order for the changes to get become effective.

How to Create Breakpoint Actions

Read on the general Breakpoints documentation page on how to set breakpoints.

To create a breakpoint action, right click the Breakpoint Indicator marker of an existing breakpoint at the left of your code, and choose "Actions...":

Hit Count Breakpoint Context Menu

or click on the Settings icon icon, that appears when you mouse cursor hovers over the red Breakpoint Indicator breakpoint marker.

The Breakpoint Actions function is a very powerful tool of Visual Micro. It lets you show the values of variables and lets you change their values while your sketch is halted in a breakpoint.

After you selected "Actions...", the breakpoint settings window shows up, and you can enter a text in the field "Log a message to Output Window:", as shown here:

When Hit Window

In the text field, you can enter a message that will be shown when the breakpoint is hit. The message will later appear in the Output Window:

Hello Message in Output Window 

Warning 16 Note:

Please notice, that the "Continue Execution" box is checked by default:

When Hit Continue Execution Checkbox

This means that the code does not halt at this point anymore (=breakpoint), but only show a message in the output window (=tracepoint).
If you want the breakpoint to halt your code as before, make sure that this box is unchecked.

Showing variable values

You can not only print static text in your message, but also the current values of variables.
Put the name of the desired variable in curly braces inside your text, like in this example:

When Hit Variable Example

The Output Window will show the following when the breakpoint is hit:

Variable Message in Output Window

The message shows the actual value of the "hum" variable every time the breakpoint is hit.

You can mix text and variables as you like, and you can also insert more two or more variables in the Breakpoint action message text. See below for more information about the Breakpoint Action message string.

If you have an Expression Window open, then the variable value is also reported there. See below.

More on Breakpoint Action Message Texts

Showing more than one variable

You can mix static text and variables in the message text:


"Position is {position} and temperature is {currTemp}"

Changing display format

You can specify how your variables are displayed by adding a format specifier to the message string.


"Position is {position,HEX}" will show the variable in hexadecimal.
You can find a complete listing of available formats in the description of the Serial.print() function in the Arduino library reference.

Using expressions

Instead of variables, you can show expressions, like in this breakpoint action message string::


"Humidity is {humidity*22.1}"

Expressions can also include function calls:

"Humidity is {getHumidityFromSensor()}"

"Time elapsed is {millis()-startTime} milliseconds"

"Valve {valveNo} is {valvePos == V_SHUT ? "shut" : "open"}"

Tracking and Changing Variable Values Using the Expression Window

You will notice that there is an "Expression Window" while your debugging session is running. If this window is missing, make it visible by clicking the Serial Monitor button in the Visual Micro toolbar:

VM Toolbar Serial Monitor Button

The Expression Window shows the actual values of all the variables mentioned in the message strings. Every time a breakpoint is hit, the respective values will be updated in the Expression Window.

 Expression Window

In the above example, we have two breakpoints:

Breakpoint 1 is located in Blink.ino, line 25 and contains this message string: "Humidity is {humidity}, counter is {counter=?}" (We will take a closer look at that "=?" after "counter" later). This lets the values of "humidity" and "counter" appear in the Expression Window.

Breakpoint 2 is located in Blink.ino, line 35 and contains this message string: "valve position is {position}". This lets the value of "position" appear in the Expression Window.

Values shown in red have changed since the last breakpoint hit.

Changing variables

If you put a "=?" behind a variable name, then you will not only see the value in the Expression Window, but you will also be able to change the variable's value if your sketch is halted in a breakpoint.

In the above example, the variable "counter" is defined like this: "{counter=?}". In the Expression Window these variables are shown with a yellow background.

To change the value, click into the yellow cell and enter a new value. If you press [F5] to continue execution on your board, the changed variable value (in this case a "counter" value of 3) will be used.

Note IconNote:

In order to be able to change a variable, it must be part of the breakpoint action text of the current breakpoint, even though the grid cell always appears in yellow.

Showing the function name

If you put the $FUNCTION keyword into the message text, Visual Micro will replace it with the name of the function where the breakpoint is placed.


If you enter this message string: "Hello from the $FUNCTION function", then you will get this string in the Output Window:

Function Name in Output Window

The $FUNCTION placeholder was replaced by the name of the function where the breakpoint resides. Please note that this placeholder does not require curly brackets like variable placeholders.

Analog, Digital, Memory, and Performance Reporting

Visual Micro can report the current status of the analog and digital inputs/outputs of your board as well as the devices connected to the I2C bus of your CPU.

If you put the following keywords into the Breakpoint Action message text, then Visual Micro will open diagram windows when you sketch is started that show these values in real time. The values will be uploaded every time the breakpoint is hit.

Updates the status of the digital I/O lines of your board and opens the "Report Digitals" diagram window
Updates the status of the analog I/O lines of your board and opens the "Report Analogs" diagram window
Updates the diagram showing the amount of free memory and opens the "Report Free Memory" diagram window
Updates the list of connected I2C devices and sends a list of connected I2C devices to the Output Window

Changing the Expression Window's Columns

The "Min" and "Max" columns of the expression window show the minimum and maximum value the variable had over time.
If you right click on the grid header, a context menu appears where you can show/hide various columns of the table:

   Expression Window Header Context Menu

Note IconNote:

The Time column does not show the time when the last breakpoint was hit, but the last time the variable's value has changed.


Other Pages