Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Debugger: values returned from function
Debugger: values returned from function [message #546061] Sat, 10 July 2010 11:50 Go to next message
Eclipse UserFriend
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 14:16] by Moderator

Re: Debugger: values returned from function [message #546330 is a reply to message #546061] Mon, 12 July 2010 09:40 Go to previous messageGo to next message
Eclipse UserFriend
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).
Re: Debugger: values returned from function [message #546395 is a reply to message #546330] Mon, 12 July 2010 11:55 Go to previous messageGo to next message
Eclipse UserFriend
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 05:44 Go to previous messageGo to next message
Eclipse UserFriend
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.

Re: Debugger: values returned from function [message #558900 is a reply to message #546061] Tue, 14 September 2010 15: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: Sat Jul 05 00:43:53 EDT 2025

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

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

Back to the top