“Unhandled Page fault" 是在内核代码里输出的 (arch/arm/mm/fault.c):
static void
__do_user_fault(struct task_struct *tsk, unsigned long addr,
unsigned int fsr, unsigned int sig, int code,
struct pt_regs *regs)
{
struct siginfo si;
#ifdef CONFIG_DEBUG_USER
if (user_debug & UDBG_SEGV) {
printk(KERN_DEBUG "%s: unhandled page fault (%d) at 0x%08lx, code 0x%03x\n",
tsk->comm, sig, addr, fsr);
show_pte(tsk->mm, addr);
show_regs(regs);
}
#endif
从代码可以看出,需要配置 CONFIG_DEBUG_USER和设置 user_debug。user_debug可以在内核启动参数里设置。
在qemu上,可以以如下的方式启动:
qemu-system-arm -M vexpress-a9 -kernel ./linux-3.2/arch/arm/boot/zImage -sd rootfs.img --append "root=/dev/mmcblk0 rw rootfs=ext3 rootdelay=3 physmap.enabled=0 console=tty0 user_debug=0xff" -net nic,vlan=0 -net tap,vlan=0
如果"unhandled page fault"不能看到,执行下:
echo 8 > /proc/sys/kernel/printk
可以根据pc寄存器的信息调试:
~$ arm-linux-gnueabi-addr2line -f -e test20 0x000083a2
main
/home/charles/test20.c:4
或者:
arm-linux-gnueabi-objdump -S -l -z -j .text test20 >1.txt
在输出文件里查找 pc值对应的代码