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 Fri, Mar 13, 2015 at 6:03 AM, Mark Wielaard <mjw@redhat.com> wrote:
> On Thu, 2015-03-12 at 16:28 -0700, H.J. Lu wrote:
>> 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.
>
> That looks fine.
>
> Would you mind reading the CONTRIBUTING document and adding a
> Signed-off-by line to your commit if you agree with that?
> https://git.fedorahosted.org/cgit/elfutils.git/plain/CONTRIBUTING
>

Here it is.


-- 
H.J.
From af53f1320894777e7de87ac8356dcee3f94ba1d1 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 5/5] 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.

Signed-off-by: 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.
---
 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]