]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
tests: Use PTRACE_GETREGS/PTRACE_SETREGS to update rip
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 12 Mar 2015 19:14:43 +0000 (12:14 -0700)
committerMark Wielaard <mjw@redhat.com>
Fri, 13 Mar 2015 15:06:23 +0000 (16:06 +0100)
Use PTRACE_POKEUSER to update rip is unsupported for x32.  We should use
PTRACE_GETREGS/PTRACE_SETREGS to update rip.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
tests/ChangeLog
tests/backtrace.c

index 6ae5e53258f2d3f6d44c35dd2f531f13e00eebe4..0162b85e2d4bc86f6cdcd6d0831243b6403999ff 100644 (file)
@@ -1,3 +1,10 @@
+2015-03-13  H.J. Lu  <hjl.tools@gmail.com>
+
+       * backtrace.c (prepare_thread): Use PTRACE_GETREGS/PTRACE_SETREGS
+       instead of PTRACE_POKEUSER.
+       (exec_dump): Check EM_X86_64 instead of ELFCLASS64 for
+       is_x86_64_native.
+
 2015-02-18  Mark Wielaard  <mjw@redhat.com>
 
        * newdata.c (check_section_data): Use PRId64 for printing loff_t.
index e109654f5e41dca2acf0261c1236bc67c58a0107..8b19b9474c7a51b6c07f1c13d73a122884df5bf4 100644 (file)
@@ -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);
@@ -375,7 +379,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)