PDB: exception when the console has a full stack trace

If at the pdb console entering the instruction that causes the exception results in one trace of the line stack, for example.

(Pdb) someFunc() *** TypeError: __init__() takes exactly 2 arguments (1 given) 

However, I would like to find out exactly where in someFunc an error occurs. that is, in this case, it joins the __init__ class.

Is there a way to get a full stack trace in Pdb?

+4
source share
2 answers

The easiest way is to define a function in your code that calls someFunc () and prints a trace, and then call it from Pdb.

Alternatively, you can print a trace for yourself. Given this source code:

 def foo(a): pass def bar(b): foo(b, 2) def some_func(): bar(3) if __name__=='__main__': import pdb pdb.set_trace() 

Then we can do this:

 C:\temp>test.py --Return-- > c:\temp\test.py(12)<module>()->None -> pdb.set_trace() (Pdb) import traceback (Pdb) exec "try: some_func()\nexcept: traceback.print_exc()" Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\temp\test.py", line 8, in some_func bar(3) File "C:\temp\test.py", line 5, in bar foo(b, 2) TypeError: foo() takes exactly 1 argument (2 given) (Pdb) 
+6
source

pdb supports debug statements for recursive invocation:

 $ nosetests xxxx -x --pdb -> some code line with error (Pdb) debug os.sdfafa() # something that raises exception ENTERING RECURSIVE DEBUGGER > <string>(1)<module>() # new line that raised excetion ((Pdb)) # number of parentheses indicates debugger recusion depth ((Pdb)) debug os.someothersdfsdf() ENTERING RECURSIVE DEBUGGER > <string>(1)<module>() (((Pdb))) 
+1
source

Source: https://habr.com/ru/post/1308609/


All Articles