Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value of arguments passed to functions on the stack?

Using:

traceback.print_stack()

I can get:

  File "x.py", line 20, in <module>
    y(x)
  File "x.py", line 11, in y
    fun(x)
  File "x.py", line 8, in fun
    traceback.print_stack()

I there any way to get something like this:

  File "x.py", line 20, in <module>
    y(x) WHERE x == 1
  File "x.py", line 11, in y
    fun(x) WHERE x == 'str'
  File "x.py", line 8, in fun
    traceback.print_stack()

I just want to see what arguments was passed to functions.

like image 931
Adam Avatar asked May 19 '11 16:05

Adam


1 Answers

You can probably rig something up by using inspect.getargvalues() and accessing the stack frame belonging to your traceback:

 inspect.getargvalues(traceback.tb_frame)

You'll have to do some work to get the output exactly as desired. The above line is only for the innermost frame, so you'll have to walk up the stack and access the information you need for every frame. inspect.getouterframes() might come in handy.

like image 115
Sven Marnach Avatar answered Oct 01 '22 17:10

Sven Marnach