在linux下,我可以使用GDB调试当前正在运行的进程吗?

推荐答案

对使用attach命令.查看this link了解更多信息.在GDB控制台上键入help attach可提供以下信息:

(gdb) help attach

附加到GDB之外的进程或文件.


注意:由于improved security in the Linux kernel,您可能很难连接到进程,例如从一个shell 连接到另一个shell 的子shell .

根据您的要求,您可能需要设置/proc/sys/kernel/yama/ptrace_scope.许多系统现在默认为1或更高.

The sysctl settings (writable only with CAP_SYS_PTRACE) are:

0 - classic ptrace permissions: a process can PTRACE_ATTACH to any other
    process running under the same uid, as long as it is dumpable (i.e.
    did not transition uids, start privileged, or have called
    prctl(PR_SET_DUMPABLE...) already). Similarly, PTRACE_TRACEME is
    unchanged.

1 - restricted ptrace: a process must have a predefined relationship
    with the inferior it wants to call PTRACE_ATTACH on. By default,
    this relationship is that of only its descendants when the above
    classic criteria is also met. To change the relationship, an
    inferior can call prctl(PR_SET_PTRACER, debugger, ...) to declare
    an allowed debugger PID to call PTRACE_ATTACH on the inferior.
    Using PTRACE_TRACEME is unchanged.

2 - admin-only attach: only processes with CAP_SYS_PTRACE may use ptrace
    with PTRACE_ATTACH, or through children calling PTRACE_TRACEME.

3 - no attach: no processes may use ptrace with PTRACE_ATTACH nor via
    PTRACE_TRACEME. Once set, this sysctl value cannot be changed.

Linux相关问答推荐

一个bash脚本,用于基于2列映射文件替换多个文件名中的模式

在Zenity进度窗口上单击取消后如何停止bash脚本

如何调试tokio任务挂起的位置?

在 bash 中使用 tee 时如何返回错误代码

如何将一个变量的 2 行添加到另一个变量的特定行?

erlang 格式的 utf8 变为 \x(反斜杠 x)ascii 编码

为什么`__vfprintf_internal`(`stdio.h`中的`printfn`)强制`$rbp`在我的x86-64机器上向前跳转6313864字节?

如何拆分多个分隔符但将它们保留在方括号之间?

如何在初始化脚本中以特定用户身份运行命令?

Linux/Unix 手册页语法约定

使用 AWS CLI 进行 Bash - 无法找到凭证

将 awk 输出保存到变量

yum 可以告诉我哪些存储库提供了特定的包吗?

通过 VM 的 Centos - 镜像列表中没有 URL

如何在 Bash 中对齐空格分隔表的列?

如何在 Linux 上查找不包含文本的文本文件?

cmake : 从脚本设置环境变量

判断环境变量是否已经设置

事件驱动和异步有什么区别?在 epoll 和 AIO 之间?

在tmux中绑定Ctrl+Tab和Ctrl+Shift+Tab