Warm tip: This article is reproduced from stackoverflow.com, please click
openocd tcl

read register value into variable

发布于 2020-05-06 11:20:52

Aim is to check if my controller has halted at the correct position.

I'm using tcl-script. The commend reg pc outputs the value of the register pc to the console. So in theory following command should store something in a variable.

set x [ reg pc ]

But the resulting variable xremains empty.

How can I retrieve the value of a register and store it into a variable?

Questioner
Cutton Eye
Viewed
35
Cutton Eye 2020-02-21 01:39

Kind of a tricky thing. reg pc does not return anything... Why even should it?^^ would be useful -.-

How ever, this one works with credit to the mailinglist!

set real_pc  [lindex [ocd_reg pc] 2]

# following executed returns the pc at (here) 0x1FC
ocd_reg pc
# returns: "pc (/32): 0x000001FC "

# Now I can check for my pc in tcl =)!
if { $expected_pc == $real_pc } { \
    echo "reg pc is correct! at $real_pc"
}

This looks to me like the string is split in 3 chunks. Taken is chunk 2, count starts by 0. In tcl everything is a string. So this works!