This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 2/5] Support x32 sigtramp
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: GDB <gdb-patches at sourceware dot org>, Mark Kettenis <kettenis at gnu dot org>
- Date: Wed, 13 Jun 2012 16:01:50 -0700
- Subject: [PATCH 2/5] Support x32 sigtramp
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
Hi,
This patch adds x32 sigtramp support. The sigtramp codes for amd64 and
x32 are very similiar. The only difference is __NR_rt_sigreturn:
[hjl@gnu-6 x32]$ grep rt_sigreturn /usr/include/asm/unistd_x32.h
#define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)
[hjl@gnu-6 x32]$ grep rt_sigreturn /usr/include/asm/unistd_64.h
#define __NR_rt_sigreturn 15
[hjl@gnu-6 tmp]$ cat x.S
#include <asm/unistd.h>
.text
mov $__NR_rt_sigreturn, %rax
[hjl@gnu-6 tmp]$ gcc -c x.S
[hjl@gnu-6 tmp]$ objdump -dw x.o
x.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <.text>:
0: 48 c7 c0 0f 00 00 00 mov $0xf,%rax
[hjl@gnu-6 tmp]$ gcc -c x.S -mx32
[hjl@gnu-6 tmp]$ objdump -dw x.o
x.o: file format elf32-x86-64
Disassembly of section .text:
00000000 <.text>:
0: 48 c7 c0 01 02 00 40 mov $0x40000201,%rax
[hjl@gnu-6 tmp]$
OK to install?
Thanks.
H.J.
* amd64-linux-tdep.c (linux_sigtramp_code): Renamed to ...
(amd64_linux_sigtramp_code): This.
(x32_linux_sigtramp_code): New.
(LINUX_SIGTRAMP_LEN): Updated.
(amd64_linux_sigtramp_start): Check x32 sigtramp.
---
gdb/amd64-linux-tdep.c | 21 ++++++++++++++++++---
1 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 0adc22b..4e64e72 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -107,7 +107,7 @@ int amd64_linux_gregset_reg_offset[] =
#define LINUX_SIGTRAMP_INSN1 0x0f /* syscall */
#define LINUX_SIGTRAMP_OFFSET1 7
-static const gdb_byte linux_sigtramp_code[] =
+static const gdb_byte amd64_linux_sigtramp_code[] =
{
/* mov $__NR_rt_sigreturn, %rax */
LINUX_SIGTRAMP_INSN0, 0xc7, 0xc0, 0x0f, 0x00, 0x00, 0x00,
@@ -115,7 +115,15 @@ static const gdb_byte linux_sigtramp_code[] =
LINUX_SIGTRAMP_INSN1, 0x05
};
-#define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
+static const gdb_byte x32_linux_sigtramp_code[] =
+{
+ /* mov $__NR_rt_sigreturn, %rax. */
+ LINUX_SIGTRAMP_INSN0, 0xc7, 0xc0, 0x01, 0x02, 0x00, 0x40,
+ /* syscall */
+ LINUX_SIGTRAMP_INSN1, 0x05
+};
+
+#define LINUX_SIGTRAMP_LEN (sizeof amd64_linux_sigtramp_code)
/* If PC is in a sigtramp routine, return the address of the start of
the routine. Otherwise, return 0. */
@@ -123,6 +131,8 @@ static const gdb_byte linux_sigtramp_code[] =
static CORE_ADDR
amd64_linux_sigtramp_start (struct frame_info *this_frame)
{
+ struct gdbarch *gdbarch;
+ const gdb_byte *sigtramp_code;
CORE_ADDR pc = get_frame_pc (this_frame);
gdb_byte buf[LINUX_SIGTRAMP_LEN];
@@ -146,7 +156,12 @@ amd64_linux_sigtramp_start (struct frame_info *this_frame)
return 0;
}
- if (memcmp (buf, linux_sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
+ gdbarch = get_frame_arch (this_frame);
+ if (gdbarch_ptr_bit (gdbarch) == 32)
+ sigtramp_code = x32_linux_sigtramp_code;
+ else
+ sigtramp_code = amd64_linux_sigtramp_code;
+ if (memcmp (buf, sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
return 0;
return pc;
--
1.7.6.5