27、驱动调试之修改系统时钟中断定位系统僵死问题
该调试方法用于处理运行驱动的时候系统进入僵死状态,即无反应了,也不能输出信息
利用每时每刻系统时钟都会尝试中断的原理来处理,在该中断函数中加入打印一些信息保存信息来定位僵死的原因(中断发生的时候会保存现场,找到现场就知道僵死的函数地址)
(2.6的内核中断总入口函数是asm_do_IRQ(),其形参有个pt_regs的结构体,其保存现场,就是各个寄存器)
在内核中搜索“S3C210_Timer_Tick”可以发现中断函数是s3c2410_timer_interrupt()
在该函数中加入"如果10秒钟之内都是同一个进程在运行,就打印"的代码
方法1、修改s3c2410_timer_interrupt
static pid_t pre_pid;
static int cnt = 0;
if(irq == 30)//"30"表示定时器中断号,可以通过查找在注册中断函数s3c2410_timer_interrupt的时候一起传入的参数确认
{
if(pre_pid == current->pid)
{
cnt++;
}
else
{
cnt = 0;
pre_pid == current->pid
}
if(cnt == 10*HZ)
{
cnt = 0;
printk("s3c2410_timer_interrupt:pid = %d,task name = %s\n",current->pid,current->comm)
}
}
方法2、修改asm_do_IRQ()
static pid_t pre_pid;
static int cnt = 0;
if(irq == 30)//"30"表示定时器中断号,可以通过查找在注册中断函数s3c2410_timer_interrupt的时候一起传入的参数确认
{
if(pre_pid == current->pid)
{
cnt++;
}
else
{
cnt = 0;
pre_pid == current->pid
}
if(cnt == 10*HZ)
{
cnt = 0;
printk("s3c2410_timer_interrupt:pid = %d,task name = %s\n",current->pid,current->comm)
printk("pc = %08x\n",regs->ARM_pc);
}
}
./firstdrvtest on 
asm_do_IRQ => s3c2410_timer_interrupt : pid = 752, task name = firstdrvtest
pc = bf000084
asm_do_IRQ => s3c2410_timer_interrupt : pid = 752, task name = firstdrvtest
pc = bf000084   // 对于中断, pc-4才是发生中断瞬间的地址
看/proc/kallsyms                                
first_drv.dis
00000000 <first_drv_open>:                     bf000000 t first_drv_open	[first_drv]         
0000003c <first_drv_write>:
  3c:	e1a0c00d 	mov	ip, sp
  40:	e92dd800 	stmdb	sp!, {fp, ip, lr, pc}
  44:	e24cb004 	sub	fp, ip, #4	; 0x4
  48:	e24dd004 	sub	sp, sp, #4	; 0x4
  4c:	e3cd3d7f 	bic	r3, sp, #8128	; 0x1fc0
  50:	e3c3303f 	bic	r3, r3, #63	; 0x3f
  54:	e5933008 	ldr	r3, [r3, #8]
  58:	e0910002 	adds	r0, r1, r2
  5c:	30d00003 	sbcccs	r0, r0, r3
  60:	33a03000 	movcc	r3, #0	; 0x0
  64:	e3530000 	cmp	r3, #0	; 0x0
  68:	e24b0010 	sub	r0, fp, #16	; 0x10
  6c:	1a00001c 	bne	e4 <init_module+0x5c>
  70:	ebfffffe 	bl	70 <first_drv_write+0x34>
  74:	ea00001f 	b	f8 <init_module+0x70>
  78:	e3520000 	cmp	r2, #0	; 0x0
  7c:	11a01002 	movne	r1, r2
  80:	1bfffffe 	blne	80 <first_drv_write+0x44>       // 卡死的地方
  84:	ea00001f 	b	108 <init_module+0x80>
 
                    
                 
                
            
         
 浙公网安备 33010602011771号
浙公网安备 33010602011771号