Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save breakpoints to file

When debugging my Python code, I run a script through ipdb from the commandline, and set a number of breakpoints. Then I make some changes in one or more modules, and rerun. However, if I simply use run modules do not get reloaded. To make sure they do, I can exist and restart Python completely, but then I need to reset all breakpoints, which is tedious if I have many and if done over and over again.

Is there a way to save breakpoint to a file in (i)pdb, so that after small changes that do not change line numbers, I can dump my breakpoints, restart Python + pdb, and reload my breakpoints? The equivalent to Matlabs X = dbstatus, saving/loading X, and setting dbstop(X).

like image 286
gerrit Avatar asked Mar 03 '15 20:03

gerrit


People also ask

How do you save breakpoints?

The main way to save in Breakpoint is to wait for the autosave feature to kick in. You'll know that it has when the save icon appears in the bottom right hand corner. You can see the icon in the image below, it looks like a small box with a down-facing arrow in it.

How do I save breakpoints in Visual Studio?

To save the breakpoints, you just need to click on the “Export” button in breakpoint window as shown in the following figure. You can use the saved XML file for the future and you can pass the same to other developers. You can also save breakpoints based on the search on labels.

How do I save breakpoints in eclipse?

If you can't find the Breakpoints tab, open it on: Window > Show View > Breakpoints . Then, as said before: Ctrl+A to select all breakpoints > right click > Export Breakpoints... .


1 Answers

You can save the breakpoints to .pdbrc file in a working path or globally to your home dir. File should have something like this:

# breakpoint 1
break /path/to/file:lineno

# breakpoint 2
break /path/to/file:lineno

You can define breakpoints various ways, just like in the interactive mode. So just break 4 or break method will work too.

This file works for both, pdb and ipdb, since later has everything pdb has and more.

Bonus:

You could use alias to more easily save breakpoints. For example:

# append breakpoint to .pdbrc in current working directory
# usage: bs lineno
alias bs with open(".pdbrc", "a") as pdbrc: pdbrc.write("break " + __file__ + ":%1\n")

Put above to your global .pdbrc and use it like this:

> bs 15

This will append a breakpoint statement to a local .pdbrc file for a line 15 of current file.

It is not perfect solution, but close enough for me. Tune the command to your needs.

Read more about aliases here.

like image 188
ruuter Avatar answered Sep 28 '22 00:09

ruuter