All Projects → cifkao → nopdb

cifkao / nopdb

Licence: BSD-3-Clause license
NoPdb: Non-interactive Python Debugger

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to nopdb

docker-pudb
Debug Python code within a Docker container remotely from your terminal using pudb
Stars: ✭ 18 (-73.13%)
Mutual labels:  debugger, pdb, debugging-tools, debugging-tool
Gdb Frontend
☕ GDBFrontend is an easy, flexible and extensionable gui debugger.
Stars: ✭ 2,104 (+3040.3%)
Mutual labels:  debugger, debugging-tools, debugging-tool
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging 🤗
Stars: ✭ 20 (-70.15%)
Mutual labels:  debugger, debugging-tools, debugging-tool
Pytest Pudb
Pytest PuDB debugger integration
Stars: ✭ 45 (-32.84%)
Mutual labels:  debugger, pdb
jsish
Jsi is a small, C-embeddable javascript interpreter with tightly woven Web and DB support.
Stars: ✭ 32 (-52.24%)
Mutual labels:  debugger, tracing
Pdb Tutorial
A simple tutorial about effectively using pdb
Stars: ✭ 720 (+974.63%)
Mutual labels:  debugger, pdb
Cocoadebug
iOS Debugging Tool 🚀
Stars: ✭ 3,769 (+5525.37%)
Mutual labels:  debugger, debugging-tool
Pdbr
pdb + Rich library
Stars: ✭ 96 (+43.28%)
Mutual labels:  debugger, pdb
Ios Sdk
AppSpector is a debugging service for mobile apps
Stars: ✭ 56 (-16.42%)
Mutual labels:  debugger, debugging-tool
Frodo
Android Library for Logging RxJava Observables and Subscribers.
Stars: ✭ 1,496 (+2132.84%)
Mutual labels:  debugger, debugging-tool
Frodo2
Android Library for Logging RxJava2 Components
Stars: ✭ 142 (+111.94%)
Mutual labels:  debugger, debugging-tool
Pudb
Full-screen console debugger for Python
Stars: ✭ 2,267 (+3283.58%)
Mutual labels:  debugger, pdb
Pdbpp
pdb++, a drop-in replacement for pdb (the Python debugger)
Stars: ✭ 693 (+934.33%)
Mutual labels:  debugger, pdb
Erlyberly
erlang tracing for the masses
Stars: ✭ 642 (+858.21%)
Mutual labels:  debugger, tracing
Vim Padre
Debugger plugin for VIM
Stars: ✭ 42 (-37.31%)
Mutual labels:  debugger, debugging-tool
Vuetron
A tool for testing and debugging your Vue + Vuex applications. 是一個可以幫助您 Vue.js 的項目測試及偵錯的工具, 也同時支持 Vuex及 Vue-Router.
Stars: ✭ 531 (+692.54%)
Mutual labels:  debugger, debugging-tool
Strongod
StrongOD(anti anti-debug plugin) driver source code.
Stars: ✭ 76 (+13.43%)
Mutual labels:  debugger, debugging-tool
heaptrace
helps visualize heap operations for pwn and debugging
Stars: ✭ 252 (+276.12%)
Mutual labels:  debugger, debugging-tools
edd
Erlang Declarative Debugger
Stars: ✭ 20 (-70.15%)
Mutual labels:  debugger, tracing
madbomber
Backtrace-on-throw C++ exception logger
Stars: ✭ 17 (-74.63%)
Mutual labels:  debugger, debugging-tool

NoPdb: Non-interactive Python Debugger

PyPI Package Documentation Status Lint Status Lint Status

NoPdb is a programmatic (non-interactive) debugger for Python. This means it gives you access to debugger-like superpowers directly from your code. With NoPdb, you can:

  • capture function calls, including arguments, local variables, return values and stack traces
  • set "breakpoints" that trigger user-defined actions when hit, namely:
    • evaluate expressions to retrieve their values later
    • execute arbitrary code, including modifying local variables
    • enter an interactive debugger like pdb

NoPdb is also a convenient tool for inspecting machine learning model internals. For example, this notebook, this post on Towards Data Science and this notebook (SciPy 2022 virtual poster) show how to use it to visualize Transformer attention in PyTorch.

NoPdb should run at least under CPython and PyPy. Most features should work under any implementation as long as it has sys.settrace().

Note: This project is in its early development stage. Contributions and improvement ideas are welcome.

Capturing function calls

The functions capture_call() and capture_calls() allow capturing useful information about calls to a given function. They are typically used as context managers, e.g.:

with nopdb.capture_calls(fn) as calls:
    some_code_that_calls_fn()

    print(calls)  # see details about how fn() was called

The information we can retrieve includes the function's arguments, return value, local variables and stack trace. For example:

>>> with nopdb.capture_call(f) as call:
...     g(1)
>>> call
CallCapture(name='f', args=OrderedDict(x=1, y=1), return_value=4)
>>> call.print_stack()
  File "<stdin>", line 2, in <module>
  File "<stdin>", line 2, in g
  File "<stdin>", line 1, in f
>>> call.args['x']
1
>>> call.return_value
4
>>> call.locals
{'y': 1, 'x': 1, 'z': 2}

Setting breakpoints

Like conventional debuggers, NoPdb can set breakpoints. However, because NoPdb is a non-interactive debugger, its breakpoints do not actually stop the execution of the program. Instead, they allow executing actions scheduled in advance, such as evaluating expressions.

To set a breakpoint, call the breakpoint() function. A breakpoint object is returned, allowing to schedule actions using its methods such as eval() and exec(). For example:

# Break at line 3 of the file or notebook cell where f is defined
with nopdb.breakpoint(function=f, line=3) as bp:
    x = bp.eval("x")             # Schedule an expression
    type_y = bp.eval("type(y)")  # Another one
    bp.exec("print(y)")          # Schedule a print statement

    some_code_that_calls_f()

print(x, type_y)  # Retrieve the captured values

There are other ways to specify the breakpoint location. For example:

# Break at any line with the given source code in the given file
with nopdb.breakpoint(file="pathlib.py", line="return obj") as bp:
    ...

# Break as soon as any function with the given name is called
with nopdb.breakpoint(function="myfunc") as bp:
    ...

Not only can we capture values, we can also modify them!

>>> with nopdb.breakpoint(function=f, line=3) as bp:
...     # Get the value of x, then increment it, then get the new value
...     x_before = bp.eval('x')
...     bp.exec('x += 1')
...     x_after = bp.eval('x')
...
...     some_code_that_calls_f()
>>> x_before
[2]
>>> x_after
[3]

Planned features

Functionalities that do not exist, but could be added in the future:

  • Breakpoint.callback() for calling a given callback function, passing information about the current frame as an argument.
  • Breakpoint.jump() for jumping to a different line in the same function.

Limitations

  • Like Pdb, NoPdb only works with pure-Python functions. Calls to built-ins and C extensions cannot be captured. This also applies to ML frameworks that compile models into static graphs; for NoPdb to work, this feature needs to be disabled, e.g. with tf.config.run_functions_eagerly(True) in TensorFlow and with the jax.disable_jit() context manager in JAX.
  • Local variable assignment in Breakpoint.exec() is only supported under CPython and PyPy.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].