Search code examples
trace32lauterbach

How to check return value of a function in Lauterbach(Trace32)?


I need to check the return value of a function from a TRACE32 script.

Reading the documentation I see a possible solution to read Program Counter(IP) register and then after executing the instruction at address where PC points to take the value from there.

Is there any other function which returns directly the value returned by a function ?


Solution

  • Every function has usually a pseudo-variable called "return". You can see that in window sYmbol.Browse.Var \\*\*\<myfunc>\* (where myfunc is the name of your function)

    Of any variable you can get its value with PRACTICE function Var.VALUE(<variable>).

    So you get the return value of function myfunc() with

    GO sYmbol.EXIT(myfunc)   // go to return statement of myfunc
    PRINT Var.VALUE(return)  // get the return value
    

    If you'd like to do a module test, another approach might be interesting for you:
    So imaging you just want to call the function int func3(int a, int b) with random arguments (e.g. 5 and 3) and get the return value. In this case, do the following:

    Var.NEWLOCAL \x        // create artificial variable on the PRACTICE stack
    Var.Set \x=func3(5,3)  // execute func3() with arguments 5 and 3 on your CPU
    PRINT Var.VALUE(\x)    // get the return value