MIT 6.828 Lab1 exercise11

exercise1.11

对我这种汇编很差的人来说,这个练习也太难了点吧,一卡卡了我两天半。。。。先是看那个read_ebp()“会很有用”,于是去研究了内联汇编格式,一直看不懂,花了一天才知道这个内联汇编函数是在做什么;之后又去搜汇编函数调用栈过程,才知道栈中那一条条指令如何算,如何看;然后又复习了一下gdb汇编的单步调试命令,用这个一步步调,跟踪栈的变化,才理解了这个五层调用函数栈的变化过程;最后发现还需要考虑C指针的语法,仔细思考了一阵子,才改掉了死循环的bug,写出了正确代码。


下面是正确的输出结果。

qemu-system-i386 -drive file=obj/kern/kernel.img,index=0,media=disk,format=raw -serial mon:stdio -gdb tcp::25000 -D qemu.log  -S
VNC server running on `127.0.0.1:5900'
6828 decimal is XXX octal!
entering test_backtrace 5
entering test_backtrace 4
entering test_backtrace 3
entering test_backtrace 2
entering test_backtrace 1
entering test_backtrace 0
ebp f010ff18 eip f010007b args 00000000 00000000 00000000 00000000 f01008ef
ebp f010ff38 eip f0100068 args 00000000 00000001 f010ff78 00000000 f01008ef
ebp f010ff58 eip f0100068 args 00000001 00000002 f010ff98 00000000 f01008ef
ebp f010ff78 eip f0100068 args 00000002 00000003 f010ffb8 00000000 f01008ef
ebp f010ff98 eip f0100068 args 00000003 00000004 00000000 00000000 00000000
ebp f010ffb8 eip f0100068 args 00000004 00000005 00000000 00010094 00010094
ebp f010ffd8 eip f01000d4 args 00000005 00001aac 00000640 00000000 00000000
ebp f010fff8 eip f010003e args 00111021 00000000 00000000 00000000 00000000
leaving test_backtrace 0
leaving test_backtrace 1
leaving test_backtrace 2
leaving test_backtrace 3
leaving test_backtrace 4
leaving test_backtrace 5
Welcome to the JOS kernel monitor!
Type 'help' for a list of commands.

下面是mon_backtrace()代码。

int
mon_backtrace(int argc, char **argv, struct Trapframe *tf)
{
	// Your code here.

	//My answer
	uint32_t _ebp = read_ebp();
	uint32_t *p;
	p = (uint32_t*)_ebp;
	while (_ebp != 0)	{
		cprintf("ebp %08x eip %08x args %08x %08x %08x %08x %08x\n", _ebp, p[1], p[2], p[3], p[4], p[5], p[6]);
		p = (uint32_t*)(*p);
		_ebp = (uint32_t)p;
	}
	return 0;
}

先不打算讲解了,我先歇一会儿。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值