[20210222]gdb ptrace Operation not permitted.txt

来源:这里教程网 时间:2026-03-03 16:28:09 作者:

[20210222]gdb ptrace Operation not permitted.txt --//尝试使用gdb调试,发现如下错误. $ gdb -p 59148 GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-119.0.1.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.  Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Attaching to process 59148 ptrace: Operation not permitted. (gdb) quit --//上网查了一下,都是报2个gdb进程attach的情况,还有就是有人使用strace.我这种情况不存在. --//还有一种情况我这里也不存在.链接 https://blog.csdn.net/fjh1997/article/details/101881649 解决gdb调试在WSL环境下报错"ptrace: Operation not permitted" 需要把下列文件里面的变量改成0(原来是1) echo 0 > /proc/sys/kernel/yama/ptrace_scope 或者 echo kernel.yama.ptrace_scope = 0 > /etc/sysctl.d/10-ptrace.conf #这个是持久化 --//主动使用strace跟踪发现: 87442 open("/proc/26016/status", O_RDONLY) = 7 87442 fstat(7, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0 87442 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6ff8db4000 87442 read(7, "Name:\toracle_26016_dy\nUmask:\t002"..., 1024) = 1024 87442 close(7)                          = 0 87442 munmap(0x7f6ff8db4000, 4096)      = 0 87442 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 87442 write(2, "ptrace: Operation not permitted.", 32) = 32 87442 write(2, "\n", 1)                 = 1 --//应该是执行到下划线时报错. $ man rt_sigprocmask SIGPROCMASK(2)           Linux Programmer's Manual      SIGPROCMASK(2) NAME        sigprocmask - examine and change blocked signals # cat /proc/76821/status  | head Name:   oracle_76821_dy Umask:  0022 State:  S (sleeping) Tgid:   76821 Ngid:   0 Pid:    76821 PPid:   1 TracerPid:      0 Uid:    1000    1001    1001    1001 Gid:    1001    1004    1004    1004 --//我对比发现多了1个Umask(与11g),注意name不再是oracle,而是变成了oracle_进程号_sid前2个字符. 49971 open("/proc/49969/status", O_RDONLY) = 7 49971 fstat(7, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0 49971 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f201cd3f000 49971 read(7, "Name:\toracle\nState:\tt (tracing s"..., 1024) = 1024 49971 close(7)                          = 0 49971 munmap(0x7f201cd3f000, 4096)      = 0 49971 wait4(49969, [{WIFSTOPPED(s) && WSTOPSIG(s) == SIGSTOP}], 0, NULL) = 49969 49971 fcntl(0, F_GETFL)                 = 0x8002 (flags O_RDWR|O_LARGEFILE) 49971 ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 49971 ioctl(0, TIOCGPGRP, [49970])      = 0 49971 ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0 49971 rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0 49971 rt_sigaction(SIGINT, {0x45daa0, [INT], SA_RESTORER|SA_RESTART, 0x3799030330}, {0x524e30, [INT], SA_RESTORER|SA_RESTART, 0x3799030330}, 8) = 0 49971 rt_sigaction(SIGINT, {0x524e30, [INT], SA_RESTORER|SA_RESTART, 0x3799030330}, {0x45daa0, [INT], SA_RESTORER|SA_RESTART, 0x3799030330}, 8) = 0 49971 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 49971 brk(0x2dd4000)                    = 0x2dd4000 49971 ptrace(PTRACE_GETREGS, 49969, 0, 0x7fff445538c0) = 0 --//换成root用户执行gdb,OK. 再次使用strace 跟踪,注不知道为什么不能加入-f参数. open("/proc/89651/status", O_RDONLY)    = 7 fstat(7, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f93c8df0000 read(7, "Name:\toracle_89651_dy\nUmask:\t002"..., 1024) = 1024 close(7)                                = 0 munmap(0x7f93c8df0000, 4096)            = 0 wait4(89651, [{WIFSTOPPED(s) && WSTOPSIG(s) == SIGSTOP}], 0, NULL) = 89651 rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0 rt_sigaction(SIGINT, {sa_handler=0x6ce6a0, sa_mask=[INT], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f93c6a0f400}, {sa_handler=0x5e5aa0, sa_mask=[INT], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f93c6a0f400}, 8) = 0 rt_sigaction(SIGINT, {sa_handler=0x5e5aa0, sa_mask=[INT], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f93c6a0f400}, {sa_handler=0x6ce6a0, sa_mask=[INT], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f93c6a0f400}, 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 --//仅仅确定执行rt_sigprocmask时报错.也许是权限的问题.

相关推荐