How do I inspect return values in the Winpdb Python debugger, without having to modify the source code?

StackOverflow https://stackoverflow.com/questions/18089899

  •  23-06-2022
  •  | 
  •  

Question

pdb, the default Python debugger, has an undocumented (?) retval command that prints the return value of the current function if you already computed it and are one step away from returning back to the caller frame.

Is there similar functionality in the graphical Winpdb debugger? I can't find the return value anywhere and it does not recognize retval as a command.


By the way, I know I could just add an intermediary variable and inspect that instead but I would like to avoid having to edit the code I'm debugging, specially when its from a third party library.

#original code
def f(x):
    return x+1

#debugging code
def f(x):
   r = x+1
   return r

Finally, I'm also open to alternative debuggers as long as they have a GUI, run on Linux and don't come bundled inside an IDE.

Was it helpful?

Solution

Does a curses GUI count? The PuDB debugger runs in the terminal, but has a curses-based GUI. See the screenshot

(don't be turned off by the blue, there are other themes as well).

It has the feature you want, when you step over a return statement, it stops and shows you the return value. See the screenshot below enter image description here

OTHER TIPS

In the console

  • use bp filename.py:f to set a breakpoint on f
  • use go and wait for breakpoint to be triggered.
  • step in and use r or return
  • use v or eval to get the value, e.g v x+1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top