沙米科·沃林达约
shamiko的Python项目详细描述
沙弥子
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
- 项目
标签: