Author Topic: view function return value  (Read 7212 times)

Offline roshi

  • Multiple posting newcomer
  • *
  • Posts: 20
view function return value
« on: December 07, 2008, 07:18:33 pm »
Hi,
is it possible to see the return value of a function?
Something better than register views.

Thanks

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: view function return value
« Reply #1 on: December 08, 2008, 06:57:51 am »
is it possible to see the return value of a function?
What's wrong with:
myRetVal = MyFunc();
...and inspecting "myRetVal"?!
Guess you need to explain a little more. You did not even mention if you are debugging or not... Probably you can inspect the values in memory during runtime with certain tools.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline roshi

  • Multiple posting newcomer
  • *
  • Posts: 20
Re: view function return value
« Reply #2 on: December 08, 2008, 01:14:11 pm »
Hi,
I'm sorry for being ambiguous.

While debugging if I want to check the return value of a function what can I do?

For example the value will most likely be in the ebx if I remember well. (or was it eax), but this is not very useful if were talking about a class pointer...
Most of the time you can't reevaluate the function, so changing the code works only in a very strict number of situations.
In most cases, even if you don't use it, (I think) it would be really useful to have access to the return value.
This would be like the "Function Arguments" (in the watches) but it would be called "Return Value". If it was a pointer of a complex data type, one should be able to browse it's internal state just like in the case of "watch *this".

I think, for those who know and remember, visual studio 6 had this functionality.
I remember using it some 10 years ago. The return value would be shown in red, and you could browse it's state (if one existed) in a table view.

Cheers
Merry Christmas

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: view function return value
« Reply #3 on: December 08, 2008, 10:42:48 pm »
I don't think there is a better way than the one suggested by MortenMacFly (which should work just fine, and doesn't re-evaluate anything).
To my knowledge, there is no such thing under gdb, and I could only imagine it implemented if compiler and debugger agreed on a few rules, which they don't. Note that gdb debugs optimized code -- within some obvious technical limits -- just fine, however it can't do magic.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline roshi

  • Multiple posting newcomer
  • *
  • Posts: 20
Re: view function return value
« Reply #4 on: December 09, 2008, 01:35:18 pm »
hi
I googled once
http://www.google.com/search?hl=en&rlz=1C1GGLS_enJP305&q=gdb+watch+function+return+value&btnG=Search

and found this
http://www.unknownroad.com/rtfm/gdbtut/gdbstep.html#RETURN
2.8 How do I return from a function? [top]   [toc]

Use the finish command to have a function finish executing and return to it's caller. This command also shows you what value the function returned.

(gdb) finish
Run till exit from #0  fun1 () at test.c:5
main (argc=1, argv=0xbffffaf4) at test.c:17
17        return 0;
Value returned is $1 = 1

which might be helpful implementing this functionality.
Actually I was wondering how could VC6 10 years ago have such functionality and not gdb in 2008.

Now is it possible to send commands to gdb from within C::B? (will google for it)
Cheers

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: view function return value
« Reply #5 on: December 09, 2008, 04:53:49 pm »
Now is it possible to send commands to gdb from within C::B? (will google for it)

If execution stopped at a breakpoint, you can send a command to gdb with "Debug -> Send user command to debugger" .

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: view function return value
« Reply #6 on: December 10, 2008, 10:59:09 am »
That's a nice find, btw... didn't know about this command. Seems to work ok too, at least in non-optimized builds.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline roshi

  • Multiple posting newcomer
  • *
  • Posts: 20
Re: view function return value
« Reply #7 on: December 10, 2008, 02:04:09 pm »
How about integrating that one into the watch view?
Some in charge of that part / gdb part.

Cheers

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: view function return value
« Reply #8 on: December 10, 2008, 08:26:45 pm »
Integrating it into the watch window so it's automatically visible with the other watches won't work because it runs up to after the next return statement in the current frame, so it would be impossible to set breakpoints anywhere.

However, it should be easy to implement it as a button, similar to "step out". Actually it could replace "step out", since you can see "finish" as "step out with return value", kind of.
Yiannis?
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: view function return value
« Reply #9 on: December 11, 2008, 09:40:58 am »
However, it should be easy to implement it as a button, similar to "step out". Actually it could replace "step out", since you can see "finish" as "step out with return value", kind of.
Yiannis?

Yes, that's true. The reason I didn't use it originally was because at the time I was writing those parts of the debugger, gdb 5.x was used by most people, which didn't support 'finish' from what I recall.
Be patient!
This bug will be fixed soon...