Author Topic: How to view the return value of a function?  (Read 5176 times)

Offline wanggaoteng

  • Multiple posting newcomer
  • *
  • Posts: 30
How to view the return value of a function?
« on: March 06, 2019, 09:57:58 am »
Hi, when I debug using codeblocks, I want to view the return value of a function, for example:
Code
#include "stdio.h"
int main(void)
{
    //code
    f();
    return 0;
}

int f(void)
{
    //code
    return 1;
}
I want to view the return value of f() in the debug windows, ( do not add codes in f() or main(), such as printf ), is there any way to get it?
Best regards.

Offline wanggaoteng

  • Multiple posting newcomer
  • *
  • Posts: 30
Re: How to view the return value of a function?
« Reply #1 on: March 06, 2019, 12:33:27 pm »
This is a simple test:
Code
#include "stdio.h"

int f(int m,int n);

int main(void)
{
    int i=2,j=3,k;
    k=f(i,j);
    printf("%d\n",k);
    return 0;
}

int f(int m,int n)
{
    return m+n;
}
I find that before enter f() in debug, then f(i,j) displays 5 in watch window, but f(m,n) displays "Not available in current context!". As picture 1 illustrates. After enter f() in debug, then f(i,j) displays "Not available in current context!", and f(m,n) displays 5. As picture 2 illustrates.
According to picture 1, it seems that f(i,j) has been calculated before the debug pointer (the little yellow triangle) enters f().
« Last Edit: March 06, 2019, 12:37:50 pm by wanggaoteng »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: How to view the return value of a function?
« Reply #2 on: March 06, 2019, 08:17:46 pm »
codeblocks does not support this by some ui
but you can use the gdb feature:
in the command line at the bottom of the debugger log type
Code
finish
hit enter and inspect the debug log. There should be a line with
Code
Value returned is

Offline wanggaoteng

  • Multiple posting newcomer
  • *
  • Posts: 30
Re: How to view the return value of a function?
« Reply #3 on: March 07, 2019, 04:02:10 am »
codeblocks does not support this by some ui
but you can use the gdb feature:
in the command line at the bottom of the debugger log type
Code
finish
hit enter and inspect the debug log. There should be a line with
Code
Value returned is

Hi, BlueHazzard, thanks, when the debug pointer enters f(), type "finish" in the command line at debugger log, and hit enter, then the debug pointer goto main(), and "value returned is xxx" appears.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: How to view the return value of a function?
« Reply #4 on: March 08, 2019, 06:48:37 pm »
You probably can add a ticket on sf with a feature request for this...

But at the moment i have no idea how the ui could look like...
Some pop up at the return statement would be nice...

Offline chameleon

  • Multiple posting newcomer
  • *
  • Posts: 39
Re: How to view the return value of a function?
« Reply #5 on: June 12, 2022, 11:47:22 am »
I am here because I search for the same feature in CB after that reading https://stackoverflow.com/questions/267674/how-to-inspect-the-return-value-of-a-function-in-gdb
This is a MUST feature for CB gui.
If I want to write 'finish' in GDB console then the complete 'Watches' panel is useless because I can watch them with GDB console (I do not know GDB commands).

Propose:
In 'Watches' panel, an entry with the return value of the function exactly after return of the function. It stay in 'Watches' panel exactly for one debugging step. On next step disappear.