跳转到主要内容

Shamiko ga waruindayo

项目描述

shamiko

PyPI PyPI Supported Python Versions GitHub license

shamiko是一个用于检查运行中的Python进程的库。

它可以

  • 检查Python进程
    • 获取当前运行进程的帧和线程的信息
  • 将任意代码注入到进程的指定帧和线程
  • 将pdb附加到运行进程

安装

pip install shamiko

命令行界面

shamiko提供了命令行界面。

shamiko --help
Usage: shamiko [OPTIONS] PID COMMAND [ARGS]...

Arguments:
  PID (int): PID of target Python process

Options:
  -e, --executable (str):  executable path of given PID
  -c, --context (str):     context directory of given PID
  --help                   show help message

Commands:
  inspect     inspect the running process
  attach      attach a debugger to the running process
  run-file    inject a python script file into the running process
  run-script  inject a python code into the running process
  shell       launch an interactive shell

检查

检查运行中的进程

Usage: shamiko PID inspect

附加

将调试器附加到运行进程

Usage: shamiko PID attach [OPTIONS]

Options:
  --thread (int): thread id where you can obtain by `inspect` command
  --frame (int): frame id where you can obtain by `inspect` command
  --debugger (str): debugger type. available debuggers: [pdb]

运行文件

将Python脚本文件注入到运行进程

Usage: shamiko PID run-file [OPTIONS] FILE_PATH

Arguments:
  FILE_PATH (str): a path of the python script that you want to inject into given PID

Options:
  --thread (int): thread id where you can obtain by `inspect` command
  --frame (int): frame id where you can obtain by `inspect` command

运行脚本

将Python代码注入到运行进程

Usage: shamiko PID run-script [OPTIONS] SCRIPT

Arguments:
  SCRIPT (str): a python code that you want to inject into given PID

Options:
  --thread (int): thread id where you can obtain by `inspect` command
  --frame (int): frame id where you can obtain by `inspect` command

shell

启动交互式shell

Usage: shamiko PID shell

常见问题解答

ptrace: 操作不允许

Could not attach to process.  If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.

在大多数发行版中,非超级用户执行非子进程的ptrace操作是不允许的。您可以通过以下方式临时禁用此功能:

echo 0 > /proc/sys/kernel/yama/ptrace_scope

auto-loading已被您的`auto-load safe-path'设置为"$debugdir:$datadir/auto-load"拒绝

warning: File "/home/user/.pyenv/versions/3.6.9/bin/python3.6-gdb.py" auto-loading has been declined by your `auto-load safe
-path' set to "$debugdir:$datadir/auto-load".

shamiko使用gdb Python扩展脚本python-gdb.py。要允许自动加载此文件,请执行

echo "add-auto-load-safe-path [path to python-gdb.py]" >> ~/.gdbinit

要简单允许自动加载所有路径,请执行

echo "add-auto-load-safe-path /" >> ~/.gdbinit

示例

  • 要允许Python 3.6,您可以通过pyenv安装
echo "add-auto-load-safe-path ~/.pyenv/shims/python3.6-gdb.py" >> ~/.gdbinit

项目详情


下载文件

下载适合您平台的项目文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

此版本没有可用的源分发文件。请参阅有关生成分发归档的教程。

构建的分发

shamiko-0.1.0-py3-none-any.whl (19.9 kB 查看哈希值)

上传时间 Python 3

支持