沙米科·沃林达约

shamiko的Python项目详细描述


沙弥子

PyPIPyPI Supported Python VersionsGitHub license

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

它可以

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

安装

pip install shamiko

命令行接口

shamiko提供命令行界面。在

^{pr2}$
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

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。 您可以通过以下方式暂时禁用此功能

echo0 > /proc/sys/kernel/yama/ptrace_scope

自动加载已被设置为“$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

示例

  • 允许pyenv安装的python3.6
echo"add-auto-load-safe-path ~/.pyenv/shims/python3.6-gdb.py" >> ~/.gdbinit

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java JavaFX SwingWorker等价物?   java如何检查一个字符串只包含数字和一个小数点?   java遇到了异常组织。阿帕奇。卡塔琳娜。LifecycleException:无法启动组件   java如何从日期格式获取最低计时单位?   java应用服务器与开发过程的集成   java我无法运行Junit测试   无法在java多线程处理中维护生产者任务的顺序   java如何在CLI应用程序中“拦截”Ctrl+C?   java如何使用JSch进行原子SFTP文件传输,以便在写入过程完成之前无法访问该文件?   java当用户摆弄html范围滑块时,如何更改内容(文本)?   如何在Java中向现有文件追加文本?   JUnit测试中的java模拟Apache驼峰位置   java Maven更新项目和依赖项