设置断点后,读出的EPC不对

4 views
Skip to first unread message

彭建章

unread,
Oct 26, 2009, 6:28:53 AM10/26/09
to hell...@googlegroups.com
大家好,我写了一个测试设置断点的程序,发下到了断点以后,读出的EPC不正确。
代码如下:

//test.c
int main()
{

        int foo, bar;

        foo = 1;
        bar = 2;

        __asm("break 7");

        return 0;
}

//preace_break.c
int main()
{
        pid_t child;
        int status;
        unsigned long regs[LEN];
        unsigned long addr;
        unsigned long insn;

        child = fork();
        if(child == 0)
        {
                ptrace(PTRACE_TRACEME,0,NULL,NULL);
                execl("./test","test",NULL);
        }

        int i;
        for(i = 0; i< 5; i++)
        {
                wait(&status);

                //read child's EPC,and get the instruction pointed by EPC
                ptrace(PTRACE_GETREGS,child,NULL,&regs);
                addr = regs[EF_CP0_EPC - EF_REG0];
                insn = ptrace(PTRACE_PEEKDATA, child, addr, NULL);
                printf("addr:%x\tcode:%x\n",addr,insn);

                ptrace(PTRACE_CONT,child,NULL,NULL);

                if(WIFEXITED(status))
                {
                        printf("child exit\n");
                        break;
                }

        }
        return 0;
}

==========
结果为:
addr:8  code:ffffffff
addr:400520     code:3e00021
addr:400520     code:3e00021
addr:400520     code:3e00021
addr:400520     code:3e00021

而break的地址和指令码是:
400690:       0007000d        break   0x7

为什么我读出的EPC不是break的那条指令呢?
谢谢!
Reply all
Reply to author
Forward
0 new messages