public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: "Bloch, Jack" <jack.bloch@siemens.com>
To: gdb@sources.redhat.com
Subject: Reading target registers
Date: Mon, 09 May 2005 19:44:00 -0000	[thread overview]
Message-ID: <2DA8F872430BE8469BF0F403A6103F9205CFC9@stca20aa.bocc.icn.siemens.com> (raw)

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

   


             reply	other threads:[~2005-05-09 19:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-09 19:44 Bloch, Jack [this message]
2005-05-09 19:49 ` Daniel Jacobowitz
2005-05-09 19:53 Bloch, Jack
2005-05-09 21:02 ` 'Daniel Jacobowitz'
     [not found] <2DA8F872430BE8469BF0F403A6103F9205CFCF@stca20aa.bocc.icn.siemens.com>
2005-05-09 21:22 ` 'Daniel Jacobowitz'

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2DA8F872430BE8469BF0F403A6103F9205CFC9@stca20aa.bocc.icn.siemens.com \
    --to=jack.bloch@siemens.com \
    --cc=gdb@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).