Run `code` in debugger with a break point. Parameters ---------- code : str Code to execute. code_ns : dict A namespace in which `code` is executed. filename : str `code` is ran as if it is in `filename`. b
(self, code, code_ns, filename=None,
bp_line=None, bp_file=None)
| 873 | return stats |
| 874 | |
| 875 | def _run_with_debugger(self, code, code_ns, filename=None, |
| 876 | bp_line=None, bp_file=None): |
| 877 | """ |
| 878 | Run `code` in debugger with a break point. |
| 879 | |
| 880 | Parameters |
| 881 | ---------- |
| 882 | code : str |
| 883 | Code to execute. |
| 884 | code_ns : dict |
| 885 | A namespace in which `code` is executed. |
| 886 | filename : str |
| 887 | `code` is ran as if it is in `filename`. |
| 888 | bp_line : int, optional |
| 889 | Line number of the break point. |
| 890 | bp_file : str, optional |
| 891 | Path to the file in which break point is specified. |
| 892 | `filename` is used if not given. |
| 893 | |
| 894 | Raises |
| 895 | ------ |
| 896 | UsageError |
| 897 | If the break point given by `bp_line` is not valid. |
| 898 | |
| 899 | """ |
| 900 | deb = self.shell.InteractiveTB.pdb |
| 901 | if not deb: |
| 902 | self.shell.InteractiveTB.pdb = self.shell.InteractiveTB.debugger_cls() |
| 903 | deb = self.shell.InteractiveTB.pdb |
| 904 | |
| 905 | # deb.checkline() fails if deb.curframe exists but is None; it can |
| 906 | # handle it not existing. https://github.com/ipython/ipython/issues/10028 |
| 907 | if hasattr(deb, 'curframe'): |
| 908 | del deb.curframe |
| 909 | |
| 910 | # reset Breakpoint state, which is moronically kept |
| 911 | # in a class |
| 912 | bdb.Breakpoint.next = 1 |
| 913 | bdb.Breakpoint.bplist = {} |
| 914 | bdb.Breakpoint.bpbynumber = [None] |
| 915 | deb.clear_all_breaks() |
| 916 | if bp_line is not None: |
| 917 | # Set an initial breakpoint to stop execution |
| 918 | maxtries = 10 |
| 919 | bp_file = bp_file or filename |
| 920 | checkline = deb.checkline(bp_file, bp_line) |
| 921 | if not checkline: |
| 922 | for bp in range(bp_line + 1, bp_line + maxtries + 1): |
| 923 | if deb.checkline(bp_file, bp): |
| 924 | break |
| 925 | else: |
| 926 | msg = ("\nI failed to find a valid line to set " |
| 927 | "a breakpoint\n" |
| 928 | "after trying up to line: %s.\n" |
| 929 | "Please set a valid breakpoint manually " |
| 930 | "with the -b option." % bp) |
| 931 | raise UsageError(msg) |
| 932 | # if we find a good linenumber, set the breakpoint |
no test coverage detected