gdb 不使用 sudo 跳过断点

gdb 不使用 sudo 跳过断点

我正在尝试使用 gdb 调试简单的 8 行程序:

$ g++ -g 1.cpp
$ gdb a.out
(gdb) break 5
Breakpoint 1 at 0x40089e: file 1.cpp, line 5.
(gdb) run

但是,gdb 将跳过断点,进程正常执行并退出。

但是,如果我运行sudo gdb a.out,那么它会像预期的那样在断点处停止。我甚至尝试在 gdb 可执行文件上设置 setuid 位,但即使这样也无济于事。

附加信息:

$ sudo sysctl --all | grep yama
kernel.yama.ptrace_scope = 0

$ stat `which gdb`
  File: '/usr/bin/gdb'
  Size: 6546408     Blocks: 12792      IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 19136921    Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-05-05 16:04:28.364144348 +0300
Modify: 2016-06-23 22:55:06.000000000 +0300
Change: 2017-05-05 16:04:16.771898651 +0300
 Birth: -

$ gdb
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
Copyright (C) 2016 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-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".
(gdb) show config
This GDB was configured as follows:
   configure --host=x86_64-linux-gnu --target=x86_64-linux-gnu
             --with-auto-load-dir=$debugdir:$datadir/auto-load
             --with-auto-load-safe-path=$debugdir:$datadir/auto-load
             --with-expat
             --with-gdb-datadir=/usr/share/gdb (relocatable)
             --with-jit-reader-dir=/usr/lib/gdb (relocatable)
             --without-libunwind-ia64
             --with-lzma
             --with-python=/usr (relocatable)
             --without-guile
             --with-separate-debug-dir=/usr/lib/debug (relocatable)
             --with-system-gdbinit=/etc/gdb/gdbinit
             --with-babeltrace

我没主意了。我做错了什么?

答案1

由于我不清楚的原因,gdb 使用 SHELL 环境变量。如果我像这样运行它:

$ env SHELL=/bin/bash gdb a.out

gdb 按预期在断点处停止。

相关内容