HW2_Boot_xv6
寻找_start
地址并设定断点
nm
命令:names, nm命令主要是用来列出文件中的某些符号(一些函数和全局变量等)。
$ nm kernel | grep _start
8010a48c D _binary_entryother_start
8010a460 D _binary_initcode_start
0010000c T _start
练习:查看栈中的内容
在运行完make qemu-gdb
后,运行make gdb
发现找不到命令。
在makefile中加入一条语句即可:
gdb:
gdb -x .gdbinit
(gdb) br *0x10000c
Breakpoint 1 at 0x10000c
(gdb) c
Continuing.
The target architecture is assumed to be i386
=> 0x10000c: mov %cr4,%eax
Thread 1 hit Breakpoint 1, 0x0010000c in ?? ()
(gdb) info reg
eax 0x0 0
ecx 0x0 0
edx 0x1f0 496
ebx 0x10074 65652
esp 0x7bdc 0x7bdc
ebp 0x7bf8 0x7bf8
esi 0x10074 65652
edi 0x0 0
eip 0x10000c 0x10000c
eflags 0x46 [ PF ZF ]
cs 0x8 8
ss 0x10 16
ds 0x10 16
es 0x10 16
fs 0x0 0
gs 0x0 0
栈中的内容, 为了解释栈中的内容都为什么,主要需要查看三个文件 bootasm.S, bootmain.c, and bootblock.asm
(gdb) x/24x $esp
0x7bdc: 0x00007db4 0x00000000 0x00000000 0x00000000
0x7bec: 0x00000000 0x00000000 0x00000000 0x00000000
0x7bfc: 0x00007c4d 0x8ec031fa 0x8ec08ed8 0xa864e4d0
0x7c0c: 0xb0fa7502 0xe464e6d1 0x7502a864 0xe6dfb0fa
0x7c1c: 0x16010f60 0x200f7c78 0xc88366c0 0xc0220f01
0x7c2c: 0x087c31ea 0x10b86600 0x8ed88e00 0x66d08ec0
- 第一行第一个地址
0x00007db4
是bootmain函数call entry的下一行代码的地址 - 第三行第一个
0x00007c4d
是_start call bootmain 的返回地址。 - 其他夹在中间的6个地址应该就是bootmain函数中的push进栈的内容.
7d3e: 57 push %edi
7d3f: 56 push %esi
7d40: 53 push %ebx
7d82: ff 73 04 pushl 0x4(%ebx)
7d85: ff 73 10 pushl 0x10(%ebx)
7d88: 57 push %edi