Please enable JavaScript to view this site.

winIDEA Help

Version: 9.21.253

Navigation: Debugging > Windows > Watches

Scroll Prev Top Next More

Watch Expressions

In this topic:

Registers and absolute memory locations in Expressions

Overriding default scope

Watch expression type modifiers

Array offset and number of elements displayed

Display of char type arrays




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'
a[3]            third element of array 'a'
a[c+3]*2          can you figure it out?



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.



Registers and absolute memory locations in Expressions

The expression syntax has been extended to allow usage of registers and absolute memory locations in expressions.


Register name

Use the '@' prefix to specify a register by the register name:

@R1 (value of R1 register)



Full path to a register / bit field

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




Same syntax can be used to access SFR registers via winIDEA SDK.



Absolute memory

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)
XDATA:0x30                (byte on XDATA 30h)


I/O module pins

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



Overriding default scope

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>



Example 1:

To access gs_byCount variable in the testfile.c module



To access a variable that is static on a function scope:

<function name>##<var name>



Example 2:

To access s_byCount variable in the main function




Using several download files

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




Watch expression type modifiers

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



Example 1:

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.




Example 2:

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



Array offset and number of elements displayed

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.



<watch expression>,a[<first element][.<number of elements>]



sz,a3            // display array elements starting from sz[3]
sz,a3.2          // display 2 array elements, starting at sz[3]
sz,a.2                  // display first 2 array elements


Same can be achieved by selecting Set array offset format option in the context menu.



Display of char type arrays

Arrays of type char can be displayed in watch window as zero terminated strings. Enable Debug | Debug Options | Symbols | Display char arrays as zero terminated strings option 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.



Copyright © 2024 TASKING