我遇到了分段错误,并使用gdb进行了调试。
代码是:
static char predata[0xff];
int i;
char* pointer;
for(i = 1; i < 0xff; i++)
{
pointer = 0xb6f00008 + (char*)(i<<12);
printf("ErrPtr:%p\n", pointer);
if(pointer == (char*)0xb6f57008) continue;
if(*(pointer) != predata[i] )
{
printf(" err:%p\n",pointer);
predata[i] = *(pointer);
}
}
使用gdb反汇编显示:
0x000201ee <+266>: ldr r3, [r7, #20]
=> 0x000201f0 <+268>: ldrb r2, [r3, #0]
0x000201f2 <+270>: movw r3, #34424 ; 0x8678
0x000201f6 <+274>: movt r3, #18
0x000201fa <+278>: ldr r1, [r7, #32]
0x000201fc <+280>: add r3, r1
但是它试图访问的内存似乎是合法的 这是我运行以获取寄存器的命令,我还手动从地址中读取了数据。
(gdb) info register
r0 0x12 18
r1 0x0 0
r2 0xb6f02008 3069190152
r3 0xb6f02008 3069190152
r4 0xb32db450 3006116944
r5 0xb32db450 3006116944
r6 0x0 0
r7 0xb32dae18 3006115352
r8 0xbefffbc8 3204447176
r9 0x0 0
r10 0x128670 1214064
r11 0xbefffbc8 3204447176
r12 0x0 0
sp 0xb32dae10 0xb32dae10
lr 0x201df 131551
pc 0x201f0 0x201f0 <Func(void*)+268>
cpsr 0x80070030 -2147024848
(gdb) print pointer
$10 = 0xb6f02008 ""
(gdb) print *pointer
$11 = 0 '\000'
(gdb) print *(0xb6f02008)
$12 = 0
(gdb)
有关如何继续调试的任何建议?