title: How to assign a value returned from a function to a variable in GDB script?
body: <p>For example, consider the following debugging session:</p>
  
  <pre><code>(gdb) break foo
  Breakpoint 1 at 0x4004f1: file tst.c, line 5.
  
  (gdb) run
  Starting program: /tmp/tst 
  Breakpoint 1, foo () at tst.c:5
  5         return ary[i++];
  
  (gdb) finish
  Run till exit from #0  foo () at tst.c:5
  Value returned is $1 = 1
  
  (gdb) cont
  Continuing.
  Breakpoint 1, foo () at tst.c:5
  5         return ary[i++];
  
  (gdb) finish
  Run till exit from #0  foo () at tst.c:5
  Value returned is $2 = 3
  </code></pre>
  
  <p>After executing a <code>finish</code> command, I get the return value assigned to a
  convenience variable (e.g. <code>$1</code> or <code>$2</code>). Unfortunately, every time the command
  is executed, the value is assigned to a different variable. That's the problem,
  I cannot write a script which examines the returned value cause I don't know
  what variable the value was assigned to.</p>
  
  <p>Why do I need that? I want to set a breakpoint at a certain function but to
  stop program execution only if the function has returned a specific value. Something
  like this:</p>
  
  <pre><code>break foo
  commands
    finish
    if ($return_value != 42)
      continue;
    end
  end
  </code></pre>
  
  <p>So the question is: Is there any way to examine in a script the value returned
  from a function?</p>