This is the mail archive of the gdb@sources.redhat.com 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]

Reading target registers


While this is not a direct GDB question, I'm hoping someone can answer me. I
have an application which uses the ptrace interface to attach to a target
process and read the target registers (I'm specifically interested in the
EIP). It will run on a SuSE 2.6 Kernel x86 based machine. My code is below.


#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <sys/reg.h>
#include <sys/user.h>
#include <linux/stddef.h>
#include <linux/version.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <link.h>
#include <fcntl.h>
#include <limits.h>
#include <dirent.h>
#include <pthread.h>
#ifndef BFD64
   #define BFD64
#endif
#include <bfd.h>
#include <signal.h>
#include "tracer.h"


int main (int     p_argc,
          char    **p_argv)

{

   int             l_ret;
   pid_t           l_pid
   unsigned long   l_regs[17];
   
   /***********************************************************************/
   /* i have ommitted the code which retrieves the command line arguments */
   /***********************************************************************/

   if ((l_ret = ptrace(PTRACE_ATTACH,l_pid,NULL,NULL)) < 0)
   { 
      l_ret = errno; 
      printf("ERROR %s ATTACHING TO TARGET !!!\n",strerror(l_ret);
      return(l_ret);
   }
   if ((l_ret = ptrace(PTRACE_GETREGS,l_pid,NULL,&l_regs)) < 0)
   { 
      l_ret = errno; 
      printf("ERROR %s READING TARGET REGISTERS !!!\n",strerror(l_ret);
      return(l_ret);
   }
   printf("CURRENT EIP 0x%x\n",l_regs[EIP]);
   return(l_ret);
}


The EIP value is always incorrect. Any ideas. Please CC me directly on any
response.


Regards,


Jack

   



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