This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Get wrong EPC ON MIPS


I write a program using ptrace. I put a "break point", but I can't get
EPC successfully.
The following are my codes.

++++++++++test.c , be traced process
int main()
{
        int foo, bar;

        foo = 1;
        bar = 2;
        __asm("break");
        return 0;
}

+++++++++++my_ptrace.c
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/user.h>
#include <sys/syscall.h>
#include <stdio.h>
#include <stdlib.h>

#define LEN 80

int main(int argc, char ** argv)
{
        pid_t child;
        int status,i;
        unsigned long regs[LEN];
        unsigned long addr,insn;

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

        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;
}

+++++++++++++++++results
addr:8  code:ffffffff
addr:400520     code:3e00021
addr:400520     code:3e00021
addr:400520     code:3e00021
addr:400520     code:3e00021

But the "break" 's address and binary code is
  400690:       0007000d        break   0x7

Thanks!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]