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

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

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

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

or click on the
icon,
that appears when you mouse cursor hovers over the red
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:

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:

Note:

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

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:

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:

Example::

"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.

Example:

"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::

Examples:

"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:

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.

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:

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.

Example:

If you enter this message string: "Hello from the $FUNCTION function",
then you will get this string in the
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.

{@ReportDigital}

Updates the status of the digital I/O lines of your board and opens
the "Report Digitals" diagram window

{@ReportAnalog}

Updates the status of the analog I/O lines of your board and opens
the "Report Analogs" 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:

Note:

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