在用gdb调试程序的时候出现这样一种错误:
program received signal sigtrap, trace/breakpoint trap.
在网上查到ag真人官方网的解决方案了,在这mark一下,以后有时间好好研究。
找到解决问题的办法了
在kernel mode改写了watchpoint的值以后,cpu把eflags的tf位置1了,照理说gdb应该清0这一位,但由于未知原因,gdb没清0该位,
(gdb) info registers
eax 0x1 1
ecx 0xbfa4fc93 -1079706477
edx 0x1 1
ebx 0x0 0
esp 0xbfa4fc64 0xbfa4fc64
ebp 0xbfa4fc98 0xbfa4fc98
esi 0x92dca0 9624736
edi 0x0 0
eip 0x978402 0x978402 <__kernel_vsyscall 2>
eflags 0x200346 [ pf zf tf if id ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb)
只需手动清楚该位即可:
(gdb) set $ps&=~(1<<8) 【on x86-based machines $ps is an alias for the eflags register,tf is the 9th bit of eflags】
(gdb) info registers
eax 0x1 1
ecx 0xbf90f353 -1081019565
edx 0x1 1
ebx 0x0 0
esp 0xbf90f324 0xbf90f324
ebp 0xbf90f358 0xbf90f358
esi 0x92dca0 9624736
edi 0x0 0
eip 0xe66402 0xe66402 <__kernel_vsyscall 2>
eflags 0x200246 [ pf zf if id ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb)
再continue,gdb就不会不停收到sigtrap了