参考文档
MIT6.828参考方法
MIT6.828 gdb 调试提示
GDB: The GNU Project Debugger
Debugging with gdb(PDF手册)
一、gdb常用命令
- 假定test为test.c编译后的文件
gdb test | 启动gdb并载入test |
---|---|
l | 相当于list列出代码 |
b 16 | 在第16行处打断点 |
b func | func入口打断点 |
info b | 查看断点信息 |
layout src | 拆分多一个窗口,显示gdb位于源码中的位置 |
二、运行gdb调试xv6
2.1 开启gdb
在xv6源码根目录里(xv6-labs-2023)开启两个终端窗口。
分别运行:
make qemu-gdb
gdb-multiarch
- 窗口一
root@QQQ:/home/MIT6.828/xv6-labs-2023# make qemu-gdb
*** Now run 'gdb' in another window.
qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 3 -nographic -global virtio-mmio.force-legacy=false -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 -S -gdb tcp::25000
- 窗口二
root@QQQ:/home/MIT6.828/xv6-labs-2023# gdb-multiarch
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 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".
warning: File "/home/MIT6.828/xv6-labs-2023/.gdbinit" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
add-auto-load-safe-path /home/MIT6.828/xv6-labs-2023/.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"
按照提示
cd /root/
ls -a
此时并未找到.gdbinit文件
用vim新建一个
vi .gdbinit
打开后添加
add-auto-load-safe-path /home/MIT6.828/xv6-labs-2023/.gdbinit
保存并退出
在窗口二重新打开gdb
root@QQQ:/home/MIT6.828/xv6-labs-2023# gdb-multiarch
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 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".
The target architecture is assumed to be riscv:rv64
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0x0000000000001000 in ?? ()
(gdb)
警告消失