[MIT6.828] xv6, a simple Unix-like teaching operating system

address: https://pdos.csail.mit.edu/6.828/2018/xv6.html
book: https://pdos.csail.mit.edu/6.828/2018/xv6/book-rev10.pdf
git: git clone git://github.com/mit-pdos/xv6-public.git

xv6 使用gdb调试

1.在xv6顶层目录运行xv6: make qemu-nox-gdb
2.在另一个终端(terminal)运行gdb: gdb kernel
3.在gdb接口,运行 (gdb) target remote localhost:26000 26000 是step1运行后给到的端口号
4.加载用户程序:(gdb)file user_program
5.断点(gdb) break main
6.继续(gdb) continue
7.其它命令
gdb) info reg

(gdb) x/24x $esp

(gdb)

常用的一些gdb调试方法

GDB
See the GDB manual for a full guide to GDB commands. Here are some particularly useful commands for 6.828, some of which don’t typically come up outside of OS development.
Ctrl-c
Halt the machine and break in to GDB at the current instruction. If QEMU has multiple virtual CPUs, this halts all of them.
c (or continue)
Continue execution until the next breakpoint or Ctrl-c.
si (or stepi)
Execute one machine instruction.
b function or b file:line (or breakpoint)
Set a breakpoint at the given function or line.
b *addr (or breakpoint)
Set a breakpoint at the EIP addr.
set print pretty
Enable pretty-printing of arrays and structs.
info registers
Print the general purpose registers, eip, eflags, and the segment selectors. For a much more thorough dump of the machine register state, see QEMU’s own info registers command.
x/Nx addr
Display a hex dump of N words starting at virtual address addr. If N is omitted, it defaults to 1. addr can be any expression.
x/Ni addr
Display the N assembly instructions starting at addr. Using $eip as addr will display the instructions at the current instruction pointer.
symbol-file file
(Lab 3+) Switch to symbol file file. When GDB attaches to QEMU, it has no notion of the process boundaries within the virtual machine, so we have to tell it which symbols to use. By default, we configure GDB to use the kernel symbol file, obj/kern/kernel. If the machine is running user code, say hello.c, you can switch to the hello symbol file using symbol-file obj/user/hello.
QEMU represents each virtual CPU as a thread in GDB, so you can use all of GDB’s thread-related commands to view or manipulate QEMU’s virtual CPUs.
thread n
GDB focuses on one thread (i.e., CPU) at a time. This command switches that focus to thread n, numbered from zero.
info threads
List all threads (i.e., CPUs), including their state (active or halted) and what function they’re in.


gdb调试xv6参考自: https://stackoverflow.com/questions/10534798/debugging-user-code-on-xv6-with-gdb

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值