Skip to main content

A python debugger that can attach to running processes.

Project description

pdb-attach

Test

A python debugger that can attach to running processes.

:exclamation: pdb-attach does not work on processes where it hasn't been imported and set up. If you just discovered this package and hope to use it on an already running process, you will need to restart the program with pdb-attach listening. Another option is to use gdb which can attach to a running python process, more information can be found here. The catch with using gdb is that it doesn't step through the python source code, but instead steps through the C code running the python program. Your mileage may vary with gdb.

:exclamation: This code is in alpha phase. The basic functionality is tested, but corner cases haven't been. If this causes your program to exit prematurely I'm sorry. Fault tolerance is the next step on the road map.

This package was made in response to frustration over debugging long running processes. Wouldn't it be nice to just attach pdb to a running python program and see what's going on? Well that's exactly what pdb-attach does.

Installation

$ pip install pdb-attach

Usage

:warning: pdb-attach uses sockets to communicate with the running process where pdb is actually being executed. While the window to connect to that process is very small, there is always the possibility that a bad actor that has access to your machine can connect to that port before you do. Since pdb is an interactive session with the process, this would give them the ability to inspect the source code of the running process, modify state of the running process, and run python code as you! That is bad and now you've been warned.

Having said that, there are a few planned features that can mitigate this problem.

  1. Using a secret key known to the running process and the user so that only messages signed with that key will be executed.
  2. Modifying pdb such that it can only inspect the state of the program and execute the program as-is. Granted a bad actor could still read the source code and the state of the program, but they would not be able to change the state of the program or run arbitrary python code.

pdb_attach must be imported and set up in the python program of interest in order for a user to attach to the running program.

import pdb_attach
pdb_attach.listen(50000)  # Listen on port 50000.

def do_stuff():
    ...

if __name__ == '__main__:
    do_stuff()

When the program is running, attach to it by calling pdb_attach from the command line with the PID of the program to inspect and the port passed to pdb_attach.listen().

$ python -m pdb_attach <PID> 50000
(Pdb)  # Interact with pdb as you normally would

When done, entering detach at the pdb prompt will detach pdb and the program will continue running from that point.

(Pdb) detach
$  # Back at the command line and the original process is still running!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdb-attach-1.0.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdb_attach-1.0.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file pdb-attach-1.0.0.tar.gz.

File metadata

  • Download URL: pdb-attach-1.0.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.3

File hashes

Hashes for pdb-attach-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9d09a697225c6447c641d90892786ce1169211b53dc6a0609b82501b40b971e9
MD5 6d1f43e08ee6a88fd7cb4fde7b378edc
BLAKE2b-256 55ab3e614312c78eec116de0264ae6be34b117e8c42dc8a4b39b68622eac736a

See more details on using hashes here.

File details

Details for the file pdb_attach-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pdb_attach-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.3

File hashes

Hashes for pdb_attach-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 896114c3550db409efcad94444de499da331117cd6a021a54508be89a8963b1c
MD5 2809f75c58a649056623a700722ed4a5
BLAKE2b-256 90114b01bcbaa155a96a08ce864184de46163188464fdeaffefe697c1f054d12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page