Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make ipdb show more lines of context while debugging?

By default, during debugging in IPython, ipdb shows one line above and one line below the current position in code.

Is there an easy way to make the area shown a bit bigger? I'd think it would be configurable, but haven't been able to find it.

like image 405
fastmultiplication Avatar asked Jun 05 '11 03:06

fastmultiplication


People also ask

Can the debugger execute multiple lines of code simultaneously?

Then there is the debugger command commands . It allows you to enter multiple lines of commands and then end the whole sequence with the end key word.

How do I skip a line in IPDB?

You can use j <line number> (jump) to go to another line.


2 Answers

You can type l in ipdb to show a few more lines of the current context

and you can keep hitting l and it continue revealing more lines from the file

If you want to show more lines of context around the current line you can type l to get the current line. And then type l curr_line - 10, curr_line + 10. Say I was on line 50 and I wanted to see the surrounding 20 lines. I would type: l 40,60 to see more.

As noted by @jrieke in a comment, you can also hit ll to get a bigger chunk of context. One nice thing about ll is it will print all the way back from the start of the current method (whereas consecutive ls reveal further lines below your breakpoint).

like image 51
Anentropic Avatar answered Oct 12 '22 14:10

Anentropic


You can get more context by doing:

ipdb.set_trace(context=21)

Permanent context size

To permanently set context size, find the installation directory by doing

python -c 'import ipdb; print(ipdb)'

which will show you a __init__.py file. Open that file and find the line (which may also be found in IPDB's __main__.py:

def set_trace(frame=None, context=3):

change the 3 to however many context lines you want.

like image 28
Garrett Avatar answered Oct 12 '22 16:10

Garrett