Search code examples
tclopenocd

read register value into variable - e.g. control location of pc


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?


Solution

  • 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!