Watch Expressions
In this topic:
•Registers and absolute memory locations in Expressions
•Watch expression type modifiers
•Array offset and number of elements displayed
A watch expression can be any legal C expression, with exception of the ternary '?' operator. Here are some examples of legal expressions:
c variable 'c' |
The value of the watch can be further formatted using the ANSI C printf syntax: ifloat,"%4.2f" - ifloat variable printed 4 characters wide, with two decimal digits
The type of the expression must match the format string type, otherwise an Incompatible format type result is displayed as value. |
The expression syntax has been extended to allow usage of registers and absolute memory locations in expressions.
Use the '@' prefix to specify a register by the register name:
@R1 (value of R1 register)
Use the '@' prefix to specify full path to a register / bit field. This allows display of SFRs with identical names belonging to different CPU modules:
@"PCU Power Control Unit"\PCU_PCONF0\STBY0 |
Use quotes to wrap the module names separated by spaces.
Path can be placed to the SFR window by:
•typing the full SFR path
•either SFR or a specific bit field can be dragged from the SFR Window to the Watch window. In this case the path separator is '\' and quotes are required.
Example - Following syntax is valid:
@"STM\STM2_TIM0" - Drag & dropped from the SFR window
@STM\STM2_TIM0
@STM2_TIM0
Same syntax can be used to access SFR registers via winIDEA SDK.
Use the ':' prefix to access absolute memory. If the CPU has more than one memory area, use memory area specifier before the colon:
:0x1000 (byte on address 1000h) |
Use the '`' prefix to access I/O module pins.
Character is a grave accent (ASCII code 96), not an apostrophe: |
`DIN.DIN0 (value on DIN.DIN0 pin)
I/O module pins can be renamed in the Hardware | Options | I/O tab and in such case the new user-defined names must be used (e.g. DIN.myPinName). |
The ANSI C expression evaluator was extended to allow accessing static variables (file or function scope) even when program execution is out of the relevant scope.
The syntax is as follows:
To access a variable that is static on a file scope:
"<module name>"#<var name> |
To access gs_byCount variable in the testfile.c module
"testfile.c#"gs_byCount |
To access a variable that is static on a function scope:
<function name>##<var name> |
To access s_byCount variable in the main function
main##s_byCount |
If there are several download files in the workspace, the default file for debugging will be used to gather information on the variables added to the watch list.
To access a variable (for example iCounter) that is defined in a non-default download file (secondOutput.elf) use the following syntax (two commas):
iCounter,,secondOutput.elf |
winIDEA will display high level variable values formatted according to their type. If you wish to override default formatting or to enforce a type to a typeless expression, you can use type modifiers.
A type modifier is a comma followed by a set of characters after the expression:
<expression>,<type modifier> |
:0x1000,I (7281) |
Same can be also selected via Format command in context menu.
The following type modifiers are available:
•c - force 8 bit signed integer type
•z - force 8 bit unsigned integer type
•i - force 16 bit signed integer type
•w - force 16 bit unsigned integer type
•l - force 32 bit signed integer type
•u - force 32 bit unsigned integer type
•ll - force 64 bit signed integer type
•ull - force 64 bit unsigned integer type
•f - force 32 bit float type
•e - force 64 bit float type
•s - force string interpretation
•a - force array interpretation
•d - decimal formatting
•x or h - hexadecimal formatting
•b - binary formatting
•m - hexadecimal dump
•UTF16 - UTF-16 formatting
•r - display struct member names
•<number> - repeat <number> times
Displays locations 0x1000-0x1001 as a signed 16-bit integer.
:0x1000,I -> 7281 |
Displays locations 0x1000-0x1007 as an array of two 32-bit floats.
:0x1000,F2 -> (4.01,3.14) |
Displays variable 'structure', showing member names and their values formatted hexadecimal.
structure,rx -> (a:0x3,y:0x55) |
Displays the array 'largearray', starting from the 500th element in the array. This enables watching arrays greater than 256 bytes.
largearray,a500 |
When trying to monitor stack pointer content, it is very convenient to monitor it in the Watch window.
To monitor SP content, use following syntax in the watch pane:
:(@SP-8),8m displays 8 bytes down from current SP
:(@SP),6m displays 6 bytes up from current SP
Displaying elements of large arrays would slow down the debug experience, so it is advised to limit the part of the array you wish to display by using the appropriate type modifiers.
Format:
<watch expression>,a[<first element][.<number of elements>] |
sz,a3 // display array elements starting from sz[3] |
Same can be achieved by selecting Set array offset format option in the context menu.
Arrays of type char can be displayed in watch window as zero terminated strings. Enable the Display char arrays as zero terminated strings option in Debug | Debug Options | Symbols to do so.
If the option is not checked, the string is displayed as an array of 8-bit characters. Individual elements are displayed according to Character display configuration in the same dialog.
The global setting can be explicitly overridden for individual watches with watch modifiers as described in the chapter above.