This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils 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]

Re: PATCH: Add x32 support to tests/backtrace.c


On Thu, Mar 12, 2015 at 3:07 PM, Roland McGrath <roland@hack.frob.com> wrote:
> GETREGS/SETREGS works fine everywhere.  Just use it unconditionally.

This patch uses PTRACE_GETREGS/PTRACE_SETREGS to update rip.

-- 
H.J.
From 75b3cb18bbc9cbe51142c9ca314c69cb54cb9bba Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 12 Mar 2015 12:14:43 -0700
Subject: [PATCH 2/3] Use PTRACE_GETREGS/PTRACE_SETREGS to update rip

Use PTRACE_POKEUSER to update rip is unsupported for x32.  We should use
PTRACE_GETREGS/PTRACE_SETREGS to update rip.
---
 tests/backtrace.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tests/backtrace.c b/tests/backtrace.c
index ab4110f..05cc0f6 100644
--- a/tests/backtrace.c
+++ b/tests/backtrace.c
@@ -260,9 +260,13 @@ prepare_thread (pid_t pid2 __attribute__ ((unused)),
   abort ();
 #else /* x86_64 */
   long l;
+  struct user_regs_struct user_regs;
   errno = 0;
-  l = ptrace (PTRACE_POKEUSER, pid2,
-	      (void *) (intptr_t) offsetof (struct user_regs_struct, rip), jmp);
+  l = ptrace (PTRACE_GETREGS, pid2, 0, (intptr_t) &user_regs);
+  assert_perror (errno);
+  assert (l == 0);
+  user_regs.rip = (intptr_t) jmp;
+  l = ptrace (PTRACE_SETREGS, pid2, 0, (intptr_t) &user_regs);
   assert_perror (errno);
   assert (l == 0);
   l = ptrace (PTRACE_CONT, pid2, NULL, (void *) (intptr_t) SIGUSR2);
@@ -381,7 +385,7 @@ exec_dump (const char *exec)
 #ifndef __x86_64__
   is_x86_64_native = false;
 #else /* __x86_64__ */
-  is_x86_64_native = ehdr->e_ident[EI_CLASS] == ELFCLASS64;
+  is_x86_64_native = ehdr->e_machine == EM_X86_64;
 #endif /* __x86_64__ */
   void (*jmp) (void) = 0;
   if (is_x86_64_native)
-- 
1.9.3


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