pdb-attach


Namepdb-attach JSON
Version 3.0.1 PyPI version JSON
download
home_pagehttps://github.com/smitchell556/pdb-attach
SummaryA python debugger that can attach to running processes.
upload_time2023-09-23 23:13:11
maintainer
docs_urlNone
authorSpencer Mitchell
requires_python>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <4
licenseBSD 3-Clause
keywords pdb debug debugger process
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pdb-attach #

![Test](https://github.com/smitchell556/pdb-attach/workflows/Test/badge.svg)

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](https://wiki.python.org/moin/DebuggingWithGdb). 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`.

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 ##

```bash
$ pip install pdb-attach
```

## Requirements ##

### OS ###

Supports OSes that implement POSIX only.

Unfortunately pdb-attach doesn't work on Windows. It's an artifact of the implementation using signals to prompt the remote debugger to accept a socket connection. I would like to support Windows in the future, but because of how Windows handles signals, it will require a different implementation that doesn't rely on signals.

> :warning: On Windows, pdb-attach is still importable, but `listen` won't do anything. Instead a warning will be raised on import and when `listen` is called.

### Python versions ###

Currently supports:

- 2.7 (Github no longer supports CI workflows for 2.7; support will be dropped in the future)
- 3.3
- 3.4
- 3.5
- 3.6
- 3.7
- 3.8
- 3.9

The policy on python version support is to support all active versions of python. For any version that has reached end of life, that version will continue to be supported for the last major release of pdb-attach it was a part of. New major releases of pdb-attach after a python version has been end of lifed may drop support for that version of python.

## Usage ##

> :warning: pdb-attach uses sockets to communicate with the running process where `pdb` is actually being executed. 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.
> 1. 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.

```python
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()`.

```bash
$ 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.

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



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/smitchell556/pdb-attach",
    "name": "pdb-attach",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <4",
    "maintainer_email": "",
    "keywords": "pdb debug debugger process",
    "author": "Spencer Mitchell",
    "author_email": "smitchell556@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e1/ec/d015ab193f6f9a017cf24f5727bfcb21a5238384c104c92cfca020037352/pdb-attach-3.0.1.tar.gz",
    "platform": null,
    "description": "# pdb-attach #\n\n![Test](https://github.com/smitchell556/pdb-attach/workflows/Test/badge.svg)\n\nA python debugger that can attach to running processes.\n\n> :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](https://wiki.python.org/moin/DebuggingWithGdb). 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`.\n\nThis 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.\n\n## Installation ##\n\n```bash\n$ pip install pdb-attach\n```\n\n## Requirements ##\n\n### OS ###\n\nSupports OSes that implement POSIX only.\n\nUnfortunately pdb-attach doesn't work on Windows. It's an artifact of the implementation using signals to prompt the remote debugger to accept a socket connection. I would like to support Windows in the future, but because of how Windows handles signals, it will require a different implementation that doesn't rely on signals.\n\n> :warning: On Windows, pdb-attach is still importable, but `listen` won't do anything. Instead a warning will be raised on import and when `listen` is called.\n\n### Python versions ###\n\nCurrently supports:\n\n- 2.7 (Github no longer supports CI workflows for 2.7; support will be dropped in the future)\n- 3.3\n- 3.4\n- 3.5\n- 3.6\n- 3.7\n- 3.8\n- 3.9\n\nThe policy on python version support is to support all active versions of python. For any version that has reached end of life, that version will continue to be supported for the last major release of pdb-attach it was a part of. New major releases of pdb-attach after a python version has been end of lifed may drop support for that version of python.\n\n## Usage ##\n\n> :warning: pdb-attach uses sockets to communicate with the running process where `pdb` is actually being executed. 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.\n>\n> Having said that, there are a few planned features that can mitigate this problem.\n> 1. Using a secret key known to the running process and the user so that only messages signed with that key will be executed.\n> 1. 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.\n\n`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.\n\n```python\nimport pdb_attach\npdb_attach.listen(50000)  # Listen on port 50000.\n\ndef do_stuff():\n    ...\n\nif __name__ == '__main__:\n    do_stuff()\n```\n\nWhen 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()`.\n\n```bash\n$ python -m pdb_attach <PID> 50000\n(Pdb)  # Interact with pdb as you normally would\n```\n\nWhen done, entering `detach` at the pdb prompt will detach pdb and the program will continue running from that point.\n\n```bash\n(Pdb) detach\n$  # Back at the command line and the original process is still running!\n```\n\n\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause",
    "summary": "A python debugger that can attach to running processes.",
    "version": "3.0.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/smitchell556/pdb-attach/issues",
        "Documentation": "https://github.com/smitchell556/pdb-attach",
        "Homepage": "https://github.com/smitchell556/pdb-attach",
        "Source": "https://github.com/smitchell556/pdb-attach"
    },
    "split_keywords": [
        "pdb",
        "debug",
        "debugger",
        "process"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bdd8a603d7367f0ac021fbd331cec28421a619e460305fa8ba9c904ab4561d10",
                "md5": "4f2fd39a75bae4114ba2e390a4ca6e82",
                "sha256": "d2fa3e6f5b3b3779ab3d394703aad2e98e204467046647636f1fbf1b9bccf5a9"
            },
            "downloads": -1,
            "filename": "pdb_attach-3.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4f2fd39a75bae4114ba2e390a4ca6e82",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <4",
            "size": 11986,
            "upload_time": "2023-09-23T23:13:10",
            "upload_time_iso_8601": "2023-09-23T23:13:10.210945Z",
            "url": "https://files.pythonhosted.org/packages/bd/d8/a603d7367f0ac021fbd331cec28421a619e460305fa8ba9c904ab4561d10/pdb_attach-3.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e1ecd015ab193f6f9a017cf24f5727bfcb21a5238384c104c92cfca020037352",
                "md5": "f1608461aa26cd88bed1084a1c66bdf8",
                "sha256": "9b588d6877c87f7fc8ee1f0b2042fd1ca9f45aceae1d5ca6238521e614ed21b9"
            },
            "downloads": -1,
            "filename": "pdb-attach-3.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f1608461aa26cd88bed1084a1c66bdf8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, <4",
            "size": 15960,
            "upload_time": "2023-09-23T23:13:11",
            "upload_time_iso_8601": "2023-09-23T23:13:11.685557Z",
            "url": "https://files.pythonhosted.org/packages/e1/ec/d015ab193f6f9a017cf24f5727bfcb21a5238384c104c92cfca020037352/pdb-attach-3.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-23 23:13:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "smitchell556",
    "github_project": "pdb-attach",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pdb-attach"
}
        
Elapsed time: 0.13819s