ptrace: Operation not permitted

前言

昨天改完bash, 在工控机上运行有bug. 知道怎么重现bug后,附加进程去调试。
在bash源码的编译后的主目录运行的gdb -tui -p xx
能确定确实附加上去了,因为被附加的putty或SecureCRT的控制台窗口已经被定住,不能输入命令了。
但是在gdb中输入break main 或 break xx, 都显示 Make breakpoint pending on future shared library load? (y or n)
这说明没找到源码啊.
这咋弄?在虚拟机中的debian上是可以用gdb附加调试的。
懵逼了一会,尝试将bash源码重新编译,再用gdb附加,还是显示上述提示。为啥呢?
再仔细看用gdb刚附加进程后的提示。

GNU gdb (GDB) Fedora 7.10.1-31.fc23
Copyright (C) 2015 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 "ppc64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Attaching to process 9493
ptrace: Operation not permitted.

突然发现最后提示是:ptrace: Operation not permitted.
因为gdb是用ptrace来调试的,如果ptrace没权限,那肯定调试不了。
尝试用 sudo gdb -tui -p xx
这次,再break main就好使了,然后进入正的调试流程。

再问同事,原来这台Fedora23上配过权限:

  • 配置好visudo, 配置好哪个用户可以用sudo执行程序来提权。
  • root是不能登陆的. 只能登陆其他用户(管理员组或非管理员组)
  • 登陆后,也不允许用 su - xx_user 切到想要的用户。
  • 运行程序时必须要sudo + xx_prog + xx_param才能有权限(先要输入本用户的登陆口令,才能执行)。

看来出问题时,仔细看上下文的提示是找线索的主要入口。
以前,只遇到过源码和目标程序不匹配的情况,只需要重新编译一下源码工程,在源码工程下用gdb附加目标进程就能调试。
因为我调试用的debian虚拟机,我都是以root登陆的,所以没有遇到这种问题。

今天,又学一招。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值