Google Answers Logo
View Question
 
Q: computer program debugging ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: computer program debugging
Category: Computers > Programming
Asked by: ignorant-ga
List Price: $5.00
Posted: 12 Jul 2004 11:32 PDT
Expires: 11 Aug 2004 11:32 PDT
Question ID: 373108
Using ddd (the gnu Data Display Debugger front end for gdb),
how does one see the return value of a C function that one has
stepped into and then out of (*without* modifying the program)?
It is inconcievable that the return value is not automagically
available somewhere!
Answer  
Subject: Re: computer program debugging
Answered By: maniac-ga on 12 Jul 2004 16:41 PDT
Rated:5 out of 5 stars
 
Hello Ignorant-ga,

Hmm. The return value is available but the description of how to find
it is buried pretty deeply. The most simple way to get the return
value is to...
 - stop execution within the function you want to check the return
value (e.g., breakpoint)
 - if the function you want the return value is not the current
function, select the proper function (using the GUI or from the gdb
command line) using the frame command. For example, using the menu
Status -> Backtrace... will bring up a window showing the functions
called. Make sure the right function is selected before the next step.
 - enter the "finish" command to gdb [using the GDB console window]
The program will continue execution until the selected function (stack
frame) is completed and the return value will be printed (if any). At
this point, you are  stopped at the point after the return from the
function call.

From the gdb online help...
  (gdb) help finish
  Execute until selected stack frame returns.
  Upon return, the value returned is printed and put in the value history.
I found this by entering:
  apropos return
and checking the likely commands until I found the one that appears to
do what you are asking for.

This is also documented in the (huge) "Debugging with GDB" which
should be provided with your system. If you can't find a copy, check
out a version in HTML format at
  http://www.eelab.usyd.edu.au/tornado/docs/gnugdb4.18/gdb.html
or more specifically:
  http://www.eelab.usyd.edu.au/tornado/docs/gnugdb4.18/gdb.html#SEC37
and scroll down a little for the description of finish [basically the same text].

Most of the other methods are pretty advanced (e.g., reading the
assembly code / printing the appropriate memory location / register).
Let me know if you have any problems with the answer I've provided
with a request for question clarification. I'll be glad to expand on
the answer if needed.

Good luck with your work.
  --Maniac
ignorant-ga rated this answer:5 out of 5 stars
Great answer, I appreciate the help (too bad, though, that return values
are not automagically available...).

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy