This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Get wrong EPC ON MIPS
- From: 彭建章 <jianzhangpeng at gmail dot com>
- To: gdb at sourceware dot org
- Date: Mon, 26 Oct 2009 21:15:28 +0800
- Subject: 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,®s);
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!