MCPcopy Create free account
hub / github.com/ipython/ipython / debug

Method debug

IPython/core/magics/execution.py:441–480  ·  view source on GitHub ↗

Activate the interactive debugger. This magic command support two ways of activating debugger. One is to activate debugger before executing code. This way, you can set a break point, to step through the code from the point. You can use this mode by giving statements

(self, line='', cell=None)

Source from the content-addressed store, hash-verified

439 @no_var_expand
440 @line_cell_magic
441 def debug(self, line='', cell=None):
442 """Activate the interactive debugger.
443
444 This magic command support two ways of activating debugger.
445 One is to activate debugger before executing code. This way, you
446 can set a break point, to step through the code from the point.
447 You can use this mode by giving statements to execute and optionally
448 a breakpoint.
449
450 The other one is to activate debugger in post-mortem mode. You can
451 activate this mode simply running %debug without any argument.
452 If an exception has just occurred, this lets you inspect its stack
453 frames interactively. Note that this will always work only on the last
454 traceback that occurred, so you must call this quickly after an
455 exception that you wish to inspect has fired, because if another one
456 occurs, it clobbers the previous one.
457
458 If you want IPython to automatically do this on every exception, see
459 the %pdb magic for more details.
460
461 .. versionchanged:: 7.3
462 When running code, user variables are no longer expanded,
463 the magic line is always left unmodified.
464
465 """
466 args = magic_arguments.parse_argstring(self.debug, line)
467
468 if not (args.breakpoint or args.statement or cell):
469 self._debug_post_mortem()
470 elif not (args.breakpoint or cell):
471 # If there is no breakpoints, the line is just code to execute
472 self._debug_exec(line, None)
473 else:
474 # Here we try to reconstruct the code from the output of
475 # parse_argstring. This might not work if the code has spaces
476 # For example this fails for `print("a b")`
477 code = "\n".join(args.statement)
478 if cell:
479 code += "\n" + cell
480 self._debug_exec(code, args.breakpoint)
481
482 def _debug_post_mortem(self):
483 self.shell.debugger(force=True)

Callers 9

startMethod · 0.80
_ipython_dir_changedMethod · 0.80
load_config_fileMethod · 0.80
init_profile_dirMethod · 0.80
init_extensionsMethod · 0.80
_run_exec_linesMethod · 0.80
_run_startup_filesMethod · 0.80
_run_exec_filesMethod · 0.80
loadTestsFromModuleMethod · 0.80

Calls 3

_debug_post_mortemMethod · 0.95
_debug_execMethod · 0.95
parse_argstringMethod · 0.80

Tested by 1

loadTestsFromModuleMethod · 0.64