Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Debugger: values returned from function
Debugger: values returned from function [message #546061] Sat, 10 July 2010 15:50 Go to next message
Nobody Mising name is currently offline Nobody Mising nameFriend
Messages: 75
Registered: July 2010
Member
How can I see what value was returned by some function?

For example in this line of code:
int val = func(f(1), g(2));

I would like to see what values were returned by functions f and g. Without stepping inside this functions, I am interested only in returned values.

[Updated on: Sat, 10 July 2010 18:16]

Report message to a moderator

Re: Debugger: values returned from function [message #546330 is a reply to message #546061] Mon, 12 July 2010 13:40 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
The discussion might help you
http://stackoverflow.com/questions/992406/examining-function -return-value-in-gdb
In short, the return value of a function is stored in the EAX register (on Intel architecture only).


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Debugger: values returned from function [message #546395 is a reply to message #546330] Mon, 12 July 2010 15:55 Go to previous messageGo to next message
Nobody Mising name is currently offline Nobody Mising nameFriend
Messages: 75
Registered: July 2010
Member
Axel Mueller wrote on Mon, 12 July 2010 09:40
The discussion might help you
http://stackoverflow.com/questions/992406/examining-function -return-value-in-gdb
In short, the return value of a function is stored in the EAX register (on Intel architecture only).



Probably that discussion can help me, but I can't understand how to use it with Eclipse. And assumption about EAX is rather strange to me because returned values are not always just int.

For example consider this small program:
struct point {
  double x, y;
  point(double x_, double y_) : x(x_), y(y_) {}
};

double operator*(const point& p0, const point& p1)
{
  return p0.x*p1.x + p0.y*p1.y;
}

point f(int i) {
  return point(i*i, i);
}

point g(int i) {
  return point(3*i, -i);
}

int main()
{
  double c = f(2) * g(2); // <= breakpoint here
  return 0;
}

In debugger I have set the breakpoint on the line with "f(2) * g(2)" expression. Now I would like to do "Step Over" and see what values were returned by functions f and g. In MSVC this values are showed like this:
http://omploader.org/vNHdwbw/MSVC2008-Debugger-Returned-Values.png
How can I see this values in Eclipse? Is it possible?
Re: Debugger: values returned from function [message #546529 is a reply to message #546395] Tue, 13 July 2010 09:44 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
You can see the return values for f(2) and g(2) when you create an expression for them in the Expressions View. Unfortunately, the debug hover does not support expressions directly.

However, I was not able to inspect the return value of the operator*. It seems that gdb does not support this.



Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Debugger: values returned from function [message #558900 is a reply to message #546061] Tue, 14 September 2010 19:09 Go to previous message
Eclipse UserFriend
Originally posted by: kgold.watson.ibm.com

Nobody wrote:
> How can I see what value was returned by some function?
>
> For example in this line of code:
>
> int val = func(f(1), g(2);
>
> I would like to see what values were returned by functions f and g.
> Without stepping inside this functions, I am interested only in returned
> values.

IMHO, the answer is "don't do that". As you found, it is hard to debug.
It also isn't very clear code.

Try instead:

x = f(1);
y = f(2);
val = func(x,y);

It's easier to understand (assuming descriptive names) and debug.

My coding style also precludes:

return func();

for the same reasons.
Previous Topic:pkg-config, eclipse, cdt, linux, gtk+
Next Topic:does CDT support CRTP
Goto Forum:
  


Current Time: Wed Sep 25 01:38:18 GMT 2024

Powered by FUDForum. Page generated in 0.04368 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top