学习使用GDB时说可以通过编辑.gdbinit文件来方便下次调试相同的程序,于是直接在当前目录下编辑了一个.gdbinit的文件,如下所示:
[root@bogon base]# ll -a
total 28
drwxr-xr-x. 2 root root 4096 Jun 26 04:48 .
drwxr-xr-x. 3 root root 4096 Jun 26 02:16 ..
-rwxr-xr-x. 1 root root 16 Jun 26 04:48 .gdbinit
-rw-r--r--. 1 root root 865 Jun 26 04:32 ins.c
-rwxr-xr-x. 1 root root 9486 Jun 26 04:32 insert_sort
运行GDB,提示加载不成功:
[root@bogon base]# gdb
warning: File "/home/xyy/debug_test/base/.gdbinit" auto-loading has been declined by your `auto-load safe-path' set to "/usr/share/gdb/auto-load:/usr/lib/debug:/usr/bin/mono-gdb.py".
To enable execution of this file add
add-auto-load-safe-path /home/xyy/debug_test/base/.gdbinit
line to your configuration file "/root/.gdbinit".
To completely disable this security protection add
set auto-load safe-path /
line to your configuration file "/root/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
info "(gdb)Auto-loading safe path"
根据上面的提示可知,加载不成功是由于
warning: File "/home/xyy/debug_test/base/.gdbinit" auto-loading has been declined by your `auto-load safe-path' set to "/usr/share/gdb/auto-load:/usr/lib/debug:/usr/bin/mono-gdb.py".
可以通过
1、添加“add-auto-load-safe-path /home/xyy/debug_test/base/.gdbinit”到/root/.gdbinit文件中,使该文件可以被加载;
To enable execution of this file add
add-auto-load-safe-path /home/xyy/debug_test/base/.gdbinit
line to your configuration file "/root/.gdbinit".
或者
2、添加“set auto-load safe-path /”到/root/.gdbinit文件中,相当于禁用了安全路径的保护;
To completely disable this security protection add
set auto-load safe-path /
line to your configuration file "/root/.gdbinit".
3、也可以先运行GDB在给出上面的提示后,运行gdb命令“source .gdbinit”,临时导入.gdbinit文件。
[root@bogon base]# gdb insert_sort
...
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
info "(gdb)Auto-loading safe path"
(gdb) source .gdbinit
Breakpoint 1 at 0x4006a7: file ins.c, line 62.
Breakpoint 2 at 0x4005b7: file ins.c, line 29.
(gdb)
4、调用GDB时指定启动文件。
[root@bogon base]# gdb -command=.gdbinit insert_sort