Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "H.J. Lu" <hongjiu.lu@intel.com>
To: GDB <gdb-patches@sourceware.org>
Subject: PATCH: Check bfd_mach_x64_32 to set tdesc for x32 binary
Date: Fri, 11 May 2012 19:30:00 -0000	[thread overview]
Message-ID: <20120511192949.GA5070@intel.com> (raw)

Hi,

This patch checks bfd_mach_x64_32 to set tdesc for x32 binary.  Tested
on Linux/x86-64.  OK to install?

Thanks.


H.J.
---
	* amd64-linux-tdep.c: Include features/i386/x32-linux.c
	and features/i386/x32-avx-linux.c.
	(amd64_linux_init_abi): Check bfd_mach_x64_32 for x32 process.
	(_initialize_amd64_linux_tdep): Register bfd_mach_x64_32.  Call
	initialize_tdesc_x32_linux and initialize_tdesc_x32_avx_linux.

	* amd64-linux-tdep.h (tdesc_x32_linux): New.
	(tdesc_x32_avx_linux): Likewise.

diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index acc7303..601ce20 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -42,6 +42,8 @@
 
 #include "features/i386/amd64-linux.c"
 #include "features/i386/amd64-avx-linux.c"
+#include "features/i386/x32-linux.c"
+#include "features/i386/x32-avx-linux.c"
 
 /* The syscall's XML filename for i386.  */
 #define XML_SYSCALL_FILENAME_AMD64 "syscalls/amd64-linux.xml"
@@ -1273,9 +1290,15 @@ amd64_linux_core_read_description (struct gdbarch *gdbarch,
   switch ((xcr0 & I386_XSTATE_AVX_MASK))
     {
     case I386_XSTATE_AVX_MASK:
-      return tdesc_amd64_avx_linux;
+      if (gdbarch_ptr_bit (gdbarch) == 32)
+	return tdesc_x32_avx_linux;
+      else
+	return tdesc_amd64_avx_linux;
     default:
-      return tdesc_amd64_linux;
+      if (gdbarch_ptr_bit (gdbarch) == 32)
+	return tdesc_x32_linux;
+      else
+	return tdesc_amd64_linux;
     }
 }
 
@@ -1302,7 +1325,13 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_num_regs (gdbarch, AMD64_LINUX_NUM_REGS);
 
   if (! tdesc_has_registers (tdesc))
-    tdesc = tdesc_amd64_linux;
+    {
+      if (info.abfd != NULL
+	  && (info.bfd_arch_info->mach & bfd_mach_x64_32))
+	tdesc = tdesc_x32_linux;
+      else
+	tdesc = tdesc_amd64_linux;
+    }
   tdep->tdesc = tdesc;
 
   feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
@@ -1323,8 +1352,12 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_OFFSET;
 
   /* GNU/Linux uses SVR4-style shared libraries.  */
-  set_solib_svr4_fetch_link_map_offsets
-    (gdbarch, svr4_lp64_fetch_link_map_offsets);
+  if (tdesc_architecture (tdesc)->mach & bfd_mach_x64_32)
+    set_solib_svr4_fetch_link_map_offsets
+      (gdbarch, svr4_ilp32_fetch_link_map_offsets);
+  else
+    set_solib_svr4_fetch_link_map_offsets
+      (gdbarch, svr4_lp64_fetch_link_map_offsets);
 
   /* Add the %orig_rax register used for syscall restarting.  */
   set_gdbarch_write_pc (gdbarch, amd64_linux_write_pc);
@@ -1545,8 +1578,12 @@ _initialize_amd64_linux_tdep (void)
 {
   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
 			  GDB_OSABI_LINUX, amd64_linux_init_abi);
+  gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x64_32,
+			  GDB_OSABI_LINUX, amd64_linux_init_abi);
 
   /* Initialize the Linux target description.  */
   initialize_tdesc_amd64_linux ();
   initialize_tdesc_amd64_avx_linux ();
+  initialize_tdesc_x32_linux ();
+  initialize_tdesc_x32_avx_linux ();
 }
diff --git a/gdb/amd64-linux-tdep.h b/gdb/amd64-linux-tdep.h
index 0338b6e..49bb95e 100644
--- a/gdb/amd64-linux-tdep.h
+++ b/gdb/amd64-linux-tdep.h
@@ -34,6 +34,8 @@
 /* Linux target description.  */
 extern struct target_desc *tdesc_amd64_linux;
 extern struct target_desc *tdesc_amd64_avx_linux;
+extern struct target_desc *tdesc_x32_linux;
+extern struct target_desc *tdesc_x32_avx_linux;
 
 /* Enum that defines the syscall identifiers for amd64 linux.
    Used for process record/replay, these will be translated into


             reply	other threads:[~2012-05-11 19:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-11 19:30 H.J. Lu [this message]
2012-05-11 20:20 ` Mark Kettenis
2012-05-11 23:13   ` H.J. Lu
2012-05-14 18:10     ` H.J. Lu
2012-05-14 18:42     ` Mark Kettenis
2012-05-14 19:02       ` H.J. Lu
2012-05-11 20:31 ` Mark Kettenis
2012-05-11 20:56   ` H.J. Lu
2012-05-12  1:38 ` Yao Qi

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=20120511192949.GA5070@intel.com \
    --to=hongjiu.lu@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=hjl.tools@gmail.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