[Dwarf-Discuss] Location of a returned value?

Andrew Cagney andrew.cagney at gmail.com
Tue Jan 6 07:41:42 PST 2009

Is there an ABI independent way to describe the location of a value
returned by a function?  For instance:

struct ret {
  int i;
  int j;

struct ret callee() {
  struct ret r = { 1, 2 };
  return r;

caller() {
  struct ret r = callee(); // <- HERE

When stepping, out of callee() debuggers like to display the returned
value.  Traditionally, this as been implemented using ABI specific
code which, due to the nature of some ABIs it may not be possible to
determine the location of that return value even though the compiler
is fully aware of its location.  For instance, an ABI that passes in
the return value's destination as a hidden address parameter:

    ALLOC "sizeof struct ret for r"
    ALLOC "sizeof struct ret for return value"
    PUSH "address of return value"
    // user does a step -over this call leaving the debugger ...
    CALLL caller
    // <- ... here
    MOVE "return value" to "r"
    PUSH "address of r"
    CALL use

After the return while the compiler knows where the result has been
stored that information isn't always available to the debugger (other
than using ABI heuristics such as trusting that the result's address
is in a specific register).

Several thoughts:

- as part of the "step -over", the debugger could capture the return
value's address using ABI knowledge; but this may not work when
there's a "step -finish"
- the callee function's debug info could describe the return value's
address, if known
- the caller could, at the return point ("... here", above) describe
the returned value some how




More information about the Dwarf-Discuss mailing list