Eclipse CDT: Showing the Return Value of a Function with Step-Return

I recently discovered a nice feature in Eclipse CDT: the ability to show the return value of a function:

Return Value shown as Variable

Return Value shown as Variable

That feature exists since Eclipse CDT 8.4, but it is easy to miss.

It solves the problem that usually it is not possible to ‘see’ the function return value if it is not assigned to a local variable.

Consider the following example:

int computeValue(int i) {
  return i*3;
}

int foo(int i) {
  if (computeValue(i)!=0) {
    return 1;
  } else {
    return 1;
  }
}

In the above simplified case, the return value of computeValue() is returned in a register and not stored as a local variable. That way i cannot inspect the local variable view while stepping through the code. What I did in the past was doing assembly stepping and inspecting the registers view, knowing that the return value will be passed back in register R0. Which is really painful.

Eclipse CDT 8.4 has added the nice feature to show the return value after a step-return in the Variables view.

Here is how it works.

  1. Step into the function for which you are interested to see the return value. Or set a breakpoint inside that function.
  2. From there, perform a ‘step-return’ action:
    inside returning function
  3. Eclipse CDT now shows the return value to the caller function as a pseudo-local variable inside the Variables view, at the beginning of the variables list.

    Return Value shown as Variable

    Return Value shown as Variable

πŸ’‘ In my case (NXP MCUXpresso IDE 10.2 (Eclipse Oxygen with CDT 9.4.3) it shows the variable with a ‘$’ and a number, while the Eclipse help page indicates that it could show a more descriptive text (e.g. ‘computeValue() returned’), and I’m not sure why this is not the case for me.

With this, I’m able to see the function return value without checking the registers view :-).

Happy Step-Returning πŸ™‚

Links

5 thoughts on “Eclipse CDT: Showing the Return Value of a Function with Step-Return

  1. Thanks for that when nested function inside if condition using. In Code Warrior for MCU 11.0 I see Step Return function as well, however It using Eclipse CDT 8.1.1

    Liked by 1 person

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.