50a6238
2006-10-01  Jan Kratochvil  <jan.kratochvil@redhat.com>
50a6238
	    Fujitsu
50a6238
50a6238
	* amd64-linux-nat.c: Support new linux_elfcore_write_prpsinfo,
50a6238
	linux_elfcore_write_prstatus, linux_elfcore_write_prfpreg.
50a6238
	(i386_linux_gregset32_reg_offset): New mapping for i386 on amd64.
50a6238
	* gcore.c (gcore_create_callback): Comment vdso Linux kernel bug.
50a6238
	* configure.ac: Check for <sys/user32.h>, <sys/procfs32.h>.
50a6238
	* configure, config.in: Regenerated.
50a6238
	* gdb_user32.h, gdb_procfs32.h: Define 32-bit core files even for
50a6238
	64-bit gdb, provide fallbacks for <sys/user32.h> and <sys/procfs32.h>.
50a6238
	* linux-nat.c: Virtualize `elfcore_*' by (*`linux_elfcore_*').
50a6238
	(linux_nat_do_thread_registers): Likewise.
50a6238
	(linux_nat_make_corefile_notes): Likewise.
50a6238
	* linux-nat.h: Likewise.
50a6238
	* Makefile.in: Dependencies updated.
50a6238
eb9d945
2007-10-16  Jan Kratochvil  <jan.kratochvil@redhat.com>
50a6238
eb9d945
	Port to GDB-6.7.
eb9d945
25ff8a1
2008-02-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
25ff8a1
25ff8a1
	Port to GDB-6.8pre.
25ff8a1
25ff8a1
Index: gdb-6.8cvs20080219/gdb/Makefile.in
50a6238
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/Makefile.in	2008-02-19 16:52:21.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/Makefile.in	2008-02-20 13:39:08.000000000 +0100
25ff8a1
@@ -785,6 +785,7 @@ gdb_expat_h = gdb_expat.h
50a6238
 gdb_locale_h = gdb_locale.h
50a6238
 gdb_obstack_h = gdb_obstack.h $(obstack_h)
50a6238
 gdb_proc_service_h = gdb_proc_service.h $(gregset_h)
50a6238
+gdb_procfs32_h = gdb_procfs32.h $(gdb_user32_h)
50a6238
 gdb_ptrace_h = gdb_ptrace.h
50a6238
 gdb_regex_h = gdb_regex.h $(xregex_h)
50a6238
 gdb_select_h = gdb_select.h
25ff8a1
@@ -794,6 +795,7 @@ gdb_string_h = gdb_string.h
50a6238
 gdb_thread_db_h = gdb_thread_db.h
50a6238
 gdbthread_h = gdbthread.h $(breakpoint_h) $(frame_h)
50a6238
 gdbtypes_h = gdbtypes.h $(hashtab_h)
50a6238
+gdb_user32_h = gdb_user32.h $(gdb_stdint_h)
50a6238
 gdb_vfork_h = gdb_vfork.h
50a6238
 gdb_wait_h = gdb_wait.h
50a6238
 glibc_tdep_h = glibc-tdep.h
25ff8a1
@@ -1888,7 +1890,8 @@ amd64fbsd-tdep.o: amd64fbsd-tdep.c $(def
50a6238
 amd64-linux-nat.o: amd64-linux-nat.c $(defs_h) $(inferior_h) $(gdbcore_h) \
50a6238
 	$(regcache_h) $(linux_nat_h) $(gdb_assert_h) $(gdb_string_h) \
50a6238
 	$(gdb_proc_service_h) $(gregset_h) $(amd64_tdep_h) \
eb9d945
-	$(i386_linux_tdep_h) $(amd64_nat_h) $(amd64_linux_tdep_h)
eb9d945
+	$(i386_linux_tdep_h) $(amd64_nat_h) $(amd64_linux_tdep_h) \
50a6238
+	$(i387_tdep_h) $(elf_bfd_h) $(gdb_procfs32_h)
50a6238
 amd64-linux-tdep.o: amd64-linux-tdep.c $(defs_h) $(frame_h) $(gdbcore_h) \
50a6238
 	$(regcache_h) $(osabi_h) $(symtab_h) $(gdb_string_h) $(amd64_tdep_h) \
aefb0e1
 	$(solib_svr4_h) $(gdbtypes_h) $(reggroups_h) $(amd64_linux_tdep_h)
25ff8a1
Index: gdb-6.8cvs20080219/gdb/amd64-linux-nat.c
50a6238
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/amd64-linux-nat.c	2008-02-16 19:10:27.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/amd64-linux-nat.c	2008-02-20 13:39:08.000000000 +0100
25ff8a1
@@ -50,6 +50,9 @@
50a6238
 #include "amd64-tdep.h"
50a6238
 #include "i386-linux-tdep.h"
50a6238
 #include "amd64-nat.h"
50a6238
+#include "i387-tdep.h"
eb9d945
+#include "elf-bfd.h"
50a6238
+#include "gdb_procfs32.h"
50a6238
 
50a6238
 /* Mapping between the general-purpose registers in GNU/Linux x86-64
50a6238
    `struct user' format and GDB's register cache layout.  */
25ff8a1
@@ -84,6 +87,35 @@ static int amd64_linux_gregset64_reg_off
50a6238
    GNU/Linux i386 registers are all 32-bit, but since we're
50a6238
    little-endian we get away with that.  */
50a6238
 
50a6238
+/* This info is not reusable from "i386-linux-nat.c" as gdb itself runs in
50a6238
+   64-bit mode and so ptrace(2) has 64-bit structure layout.
50a6238
+   Just the corefile being generated has 32-bit layout so we need to do
50a6238
+   a conversion specific to the i386-on-amd64 compatibility mode.  */
50a6238
+static int i386_linux_gregset32_reg_offset[] =
50a6238
+{
50a6238
+  6 * 4,			/* %eax */
50a6238
+  1 * 4,			/* %ecx */
50a6238
+  2 * 4,			/* %edx */
50a6238
+  0 * 4,			/* %ebx */
50a6238
+  15 * 4,			/* %esp */
50a6238
+  5 * 4,			/* %ebp */
50a6238
+  3 * 4,			/* %esi */
50a6238
+  4 * 4,			/* %edi */
50a6238
+  12 * 4,			/* %eip */
50a6238
+  14 * 4,			/* %eflags */
50a6238
+  13 * 4,			/* %cs */
50a6238
+  16 * 4,			/* %ss */
50a6238
+  7 * 4,			/* %ds */
50a6238
+  8 * 4,			/* %es */
50a6238
+  9 * 4,			/* %fs */
50a6238
+  10 * 4,			/* %gs */
50a6238
+  -1, -1, -1, -1, -1, -1, -1, -1,
50a6238
+  -1, -1, -1, -1, -1, -1, -1, -1,
50a6238
+  -1, -1, -1, -1, -1, -1, -1, -1,
50a6238
+  -1,
50a6238
+  11 * 4			/* "orig_eax" */
50a6238
+};
50a6238
+
50a6238
 /* From <sys/reg.h> on GNU/Linux i386.  */
50a6238
 static int amd64_linux_gregset32_reg_offset[] =
50a6238
 {
25ff8a1
@@ -102,6 +134,96 @@ static int amd64_linux_gregset32_reg_off
50a6238
 };
50a6238
 
50a6238
 
50a6238
+/* This functions make ELF32 32-bit elfcore note sections
50a6238
+   on amd64 environment. */
50a6238
+
50a6238
+static char *
50a6238
+amd64_linux_elfcore_write_prpsinfo (bfd *abfd, char *buf, int *bufsiz,
50a6238
+				    const char *fname, const char *psargs)
50a6238
+{
50a6238
+  if (gdbarch_ptr_bit(current_gdbarch) == 32)
50a6238
+    {
50a6238
+      int note_type;
50a6238
+      char *note_name = "CORE";
50a6238
+      struct elf_prpsinfo32 data;
50a6238
+      note_type = NT_PRPSINFO;
50a6238
+
50a6238
+      memset (&data, 0, sizeof (data));
50a6238
+      strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
50a6238
+      strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
50a6238
+      return elfcore_write_note (abfd, buf, bufsiz,
50a6238
+				 note_name, note_type, &data, sizeof (data));
50a6238
+    }
50a6238
+  else
50a6238
+    return elfcore_write_prpsinfo (abfd, buf, bufsiz, fname, psargs);
50a6238
+}
50a6238
+
50a6238
+static void
50a6238
+amd64_linux_set_registers (const gdb_byte *gregs, gdb_byte *buf)
50a6238
+{
50a6238
+  int i;
50a6238
+  /* Copy the i386 registers in the amd64 layout into i386 layout.  */
50a6238
+  for (i = 0; i < I386_NUM_GREGS; i++)
50a6238
+    memcpy(buf + i386_linux_gregset32_reg_offset[i],
50a6238
+	   gregs + amd64_linux_gregset32_reg_offset[i], 4);
50a6238
+  for (i = I386_CS_REGNUM; i <= I386_GS_REGNUM; i++)
50a6238
+    memcpy(buf + i386_linux_gregset32_reg_offset[i],
50a6238
+	   gregs + amd64_linux_gregset32_reg_offset[i], 4);
50a6238
+}
50a6238
+
50a6238
+static char *
50a6238
+amd64_linux_elfcore_write_prstatus (bfd *abfd, char *buf, int *bufsiz,
50a6238
+			      long pid, int cursig, const void *gregs)
50a6238
+{
50a6238
+  if (gdbarch_ptr_bit(current_gdbarch) == 32)
50a6238
+    {
50a6238
+      char *note_name = "CORE";
50a6238
+      struct elf_prstatus32 prstat;
50a6238
+      memset (&prstat, 0, sizeof (prstat));
50a6238
+      prstat.pr_pid = pid;
50a6238
+      prstat.pr_cursig = cursig;
50a6238
+      amd64_linux_set_registers (gregs, (gdb_byte *) &prstat.pr_reg);
50a6238
+      return elfcore_write_note (abfd, buf, bufsiz, note_name,
50a6238
+				 NT_PRSTATUS, &prstat, sizeof (prstat));
50a6238
+    }
50a6238
+  else
50a6238
+    return elfcore_write_prstatus (abfd, buf, bufsiz, pid, cursig, gregs);
50a6238
+}
50a6238
+
50a6238
+static char *
eb9d945
+amd64_elfcore_write_prxfpreg32 (bfd *abfd, char *buf, int *bufsiz,
eb9d945
+				struct regcache *regcache)
50a6238
+{
50a6238
+  char *note_name = "LINUX";
50a6238
+  elf_fpxregset32_t fpxregs32;
50a6238
+
eb9d945
+  i387_collect_fxsave (regcache, -1, &fpxregs32);
50a6238
+  return elfcore_write_note(abfd, buf, bufsiz,
50a6238
+				     note_name, NT_PRXFPREG, &fpxregs32,
50a6238
+				     sizeof(fpxregs32));
50a6238
+}
50a6238
+
50a6238
+static char *
50a6238
+amd64_linux_elfcore_write_prfpreg (bfd *abfd, char *buf,
eb9d945
+				   int *bufsiz, const void *fpregs, int size,
eb9d945
+				   struct regcache *regcache)
50a6238
+{
50a6238
+  if (gdbarch_ptr_bit(current_gdbarch) == 32)
50a6238
+    {
50a6238
+      char *note_name = "CORE";
50a6238
+      elf_fpregset32_t fpregs32;
50a6238
+  
eb9d945
+      i387_collect_fsave (regcache, -1, &fpregs32);
50a6238
+      buf = elfcore_write_note(abfd, buf, bufsiz, note_name,
50a6238
+			       NT_FPREGSET, &fpregs32, sizeof(fpregs32));
50a6238
+
eb9d945
+      return amd64_elfcore_write_prxfpreg32 (abfd, buf, bufsiz, regcache);
50a6238
+    }
50a6238
+  else
50a6238
+    return elfcore_write_prfpreg (abfd, buf, bufsiz, fpregs, size);
50a6238
+}
50a6238
+
50a6238
+
50a6238
 /* Transfering the general-purpose registers between GDB, inferiors
50a6238
    and core files.  */
50a6238
 
25ff8a1
@@ -429,6 +551,11 @@ _initialize_amd64_linux_nat (void)
50a6238
   t->to_fetch_registers = amd64_linux_fetch_inferior_registers;
50a6238
   t->to_store_registers = amd64_linux_store_inferior_registers;
50a6238
 
50a6238
+  /* This functions make elfcore note sections. */
50a6238
+  linux_elfcore_write_prpsinfo = amd64_linux_elfcore_write_prpsinfo;
50a6238
+  linux_elfcore_write_prstatus = amd64_linux_elfcore_write_prstatus;
50a6238
+  linux_elfcore_write_prfpreg = amd64_linux_elfcore_write_prfpreg;
50a6238
+
50a6238
   /* Register the target.  */
50a6238
   linux_nat_add_target (t);
25ff8a1
   linux_nat_set_new_thread (t, amd64_linux_new_thread);
25ff8a1
Index: gdb-6.8cvs20080219/gdb/config.in
50a6238
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/config.in	2008-01-10 19:17:06.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/config.in	2008-02-20 13:39:08.000000000 +0100
eb9d945
@@ -385,6 +385,9 @@
50a6238
 /* Define to 1 if you have the <sys/poll.h> header file. */
50a6238
 #undef HAVE_SYS_POLL_H
50a6238
 
50a6238
+/* Define to 1 if you have the <sys/procfs32.h> header file. */
50a6238
+#undef HAVE_SYS_PROCFS32_H
50a6238
+
50a6238
 /* Define to 1 if you have the <sys/procfs.h> header file. */
50a6238
 #undef HAVE_SYS_PROCFS_H
50a6238
 
eb9d945
@@ -412,6 +415,9 @@
50a6238
 /* Define to 1 if you have the <sys/types.h> header file. */
50a6238
 #undef HAVE_SYS_TYPES_H
50a6238
 
50a6238
+/* Define to 1 if you have the <sys/user32.h> header file. */
50a6238
+#undef HAVE_SYS_USER32_H
50a6238
+
50a6238
 /* Define to 1 if you have the <sys/user.h> header file. */
50a6238
 #undef HAVE_SYS_USER_H
50a6238
 
25ff8a1
Index: gdb-6.8cvs20080219/gdb/configure
50a6238
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/configure	2008-02-14 23:03:56.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/configure	2008-02-20 13:39:08.000000000 +0100
25ff8a1
@@ -11140,6 +11140,157 @@ done
50a6238
 
50a6238
 
50a6238
 
50a6238
+for ac_header in sys/user32.h sys/procfs32.h
50a6238
+do
50a6238
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
50a6238
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
50a6238
+  echo "$as_me:$LINENO: checking for $ac_header" >&5
50a6238
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
50a6238
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
50a6238
+  echo $ECHO_N "(cached) $ECHO_C" >&6
50a6238
+fi
50a6238
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
50a6238
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
50a6238
+else
50a6238
+  # Is the header compilable?
50a6238
+echo "$as_me:$LINENO: checking $ac_header usability" >&5
50a6238
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
50a6238
+cat >conftest.$ac_ext <<_ACEOF
50a6238
+/* confdefs.h.  */
50a6238
+_ACEOF
50a6238
+cat confdefs.h >>conftest.$ac_ext
50a6238
+cat >>conftest.$ac_ext <<_ACEOF
50a6238
+/* end confdefs.h.  */
50a6238
+$ac_includes_default
50a6238
+#include <$ac_header>
50a6238
+_ACEOF
50a6238
+rm -f conftest.$ac_objext
50a6238
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
50a6238
+  (eval $ac_compile) 2>conftest.er1
50a6238
+  ac_status=$?
50a6238
+  grep -v '^ *+' conftest.er1 >conftest.err
50a6238
+  rm -f conftest.er1
50a6238
+  cat conftest.err >&5
50a6238
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
50a6238
+  (exit $ac_status); } &&
50a6238
+	 { ac_try='test -z "$ac_c_werror_flag"
50a6238
+			 || test ! -s conftest.err'
50a6238
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
50a6238
+  (eval $ac_try) 2>&5
50a6238
+  ac_status=$?
50a6238
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
50a6238
+  (exit $ac_status); }; } &&
50a6238
+	 { ac_try='test -s conftest.$ac_objext'
50a6238
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
50a6238
+  (eval $ac_try) 2>&5
50a6238
+  ac_status=$?
50a6238
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
50a6238
+  (exit $ac_status); }; }; then
50a6238
+  ac_header_compiler=yes
50a6238
+else
50a6238
+  echo "$as_me: failed program was:" >&5
50a6238
+sed 's/^/| /' conftest.$ac_ext >&5
50a6238
+
50a6238
+ac_header_compiler=no
50a6238
+fi
50a6238
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
50a6238
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
50a6238
+echo "${ECHO_T}$ac_header_compiler" >&6
50a6238
+
50a6238
+# Is the header present?
50a6238
+echo "$as_me:$LINENO: checking $ac_header presence" >&5
50a6238
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
50a6238
+cat >conftest.$ac_ext <<_ACEOF
50a6238
+/* confdefs.h.  */
50a6238
+_ACEOF
50a6238
+cat confdefs.h >>conftest.$ac_ext
50a6238
+cat >>conftest.$ac_ext <<_ACEOF
50a6238
+/* end confdefs.h.  */
50a6238
+#include <$ac_header>
50a6238
+_ACEOF
50a6238
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
50a6238
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
50a6238
+  ac_status=$?
50a6238
+  grep -v '^ *+' conftest.er1 >conftest.err
50a6238
+  rm -f conftest.er1
50a6238
+  cat conftest.err >&5
50a6238
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
50a6238
+  (exit $ac_status); } >/dev/null; then
50a6238
+  if test -s conftest.err; then
50a6238
+    ac_cpp_err=$ac_c_preproc_warn_flag
50a6238
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
50a6238
+  else
50a6238
+    ac_cpp_err=
50a6238
+  fi
50a6238
+else
50a6238
+  ac_cpp_err=yes
50a6238
+fi
50a6238
+if test -z "$ac_cpp_err"; then
50a6238
+  ac_header_preproc=yes
50a6238
+else
50a6238
+  echo "$as_me: failed program was:" >&5
50a6238
+sed 's/^/| /' conftest.$ac_ext >&5
50a6238
+
50a6238
+  ac_header_preproc=no
50a6238
+fi
50a6238
+rm -f conftest.err conftest.$ac_ext
50a6238
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
50a6238
+echo "${ECHO_T}$ac_header_preproc" >&6
50a6238
+
50a6238
+# So?  What about this header?
50a6238
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
50a6238
+  yes:no: )
50a6238
+    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
50a6238
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
50a6238
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
50a6238
+echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
50a6238
+    ac_header_preproc=yes
50a6238
+    ;;
50a6238
+  no:yes:* )
50a6238
+    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
50a6238
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
50a6238
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
50a6238
+echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
50a6238
+    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
50a6238
+echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
50a6238
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
50a6238
+echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
50a6238
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
50a6238
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
50a6238
+    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
50a6238
+echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
50a6238
+    (
50a6238
+      cat <<\_ASBOX
50a6238
+## ------------------------------------------ ##
50a6238
+## Report this to the AC_PACKAGE_NAME lists.  ##
50a6238
+## ------------------------------------------ ##
50a6238
+_ASBOX
50a6238
+    ) |
50a6238
+      sed "s/^/$as_me: WARNING:     /" >&2
50a6238
+    ;;
50a6238
+esac
50a6238
+echo "$as_me:$LINENO: checking for $ac_header" >&5
50a6238
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
50a6238
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
50a6238
+  echo $ECHO_N "(cached) $ECHO_C" >&6
50a6238
+else
50a6238
+  eval "$as_ac_Header=\$ac_header_preproc"
50a6238
+fi
50a6238
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
50a6238
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
50a6238
+
50a6238
+fi
50a6238
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
50a6238
+  cat >>confdefs.h <<_ACEOF
50a6238
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
50a6238
+_ACEOF
50a6238
+
50a6238
+fi
50a6238
+
50a6238
+done
50a6238
+
50a6238
+
50a6238
+
50a6238
 for ac_header in sys/wait.h wait.h
50a6238
 do
50a6238
 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
25ff8a1
Index: gdb-6.8cvs20080219/gdb/configure.ac
50a6238
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/configure.ac	2008-02-14 23:03:56.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/configure.ac	2008-02-20 13:39:08.000000000 +0100
25ff8a1
@@ -523,6 +523,7 @@ AC_CHECK_HEADERS(sys/user.h, [], [],
50a6238
 # include <sys/param.h>
50a6238
 #endif
50a6238
 ])
50a6238
+AC_CHECK_HEADERS(sys/user32.h sys/procfs32.h)
50a6238
 AC_CHECK_HEADERS(sys/wait.h wait.h)
50a6238
 AC_CHECK_HEADERS(termios.h termio.h sgtty.h)
50a6238
 AC_CHECK_HEADERS(unistd.h)
25ff8a1
Index: gdb-6.8cvs20080219/gdb/gcore.c
50a6238
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/gcore.c	2008-02-19 16:52:21.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/gcore.c	2008-02-20 13:39:08.000000000 +0100
eb9d945
@@ -317,6 +317,11 @@ gcore_create_callback (CORE_ADDR vaddr, 
50a6238
   asection *osec;
50a6238
   flagword flags = SEC_ALLOC | SEC_HAS_CONTENTS | SEC_LOAD;
50a6238
 
50a6238
+  /* Some Linux kernel versions around 2.6.17 have for i386 inferiors running
50a6238
+     in compatibility mode on amd64 kernel their VSYSCALL page (at 0xffffe000)
50a6238
+     protected as RWX==000 by default and gdb fails to read the library header
50a6238
+     upon loading the core.  This is a Linux kernel bug being fixed.  */
50a6238
+
50a6238
   /* If the memory segment has no permissions set, ignore it, otherwise
50a6238
      when we later try to access it for read/write, we'll get an error
50a6238
      or jam the kernel.  */
25ff8a1
Index: gdb-6.8cvs20080219/gdb/gdb_procfs32.h
50a6238
===================================================================
aefb0e1
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
25ff8a1
+++ gdb-6.8cvs20080219/gdb/gdb_procfs32.h	2008-02-20 13:39:08.000000000 +0100
50a6238
@@ -0,0 +1,128 @@
50a6238
+#ifdef HAVE_SYS_PROCFS32_H
50a6238
+#include <sys/procfs32.h>
50a6238
+#else
50a6238
+
50a6238
+/* Copyright (C) 2006 Free Software Foundation, Inc.
50a6238
+   This file is part of the GNU C Library.
50a6238
+
50a6238
+   The GNU C Library is free software; you can redistribute it and/or
50a6238
+   modify it under the terms of the GNU Lesser General Public
50a6238
+   License as published by the Free Software Foundation; either
50a6238
+   version 2.1 of the License, or (at your option) any later version.
50a6238
+
50a6238
+   The GNU C Library is distributed in the hope that it will be useful,
50a6238
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
50a6238
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
50a6238
+   Lesser General Public License for more details.
50a6238
+
50a6238
+   You should have received a copy of the GNU Lesser General Public
50a6238
+   License along with the GNU C Library; if not, write to the Free
50a6238
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
50a6238
+   02111-1307 USA.  */
50a6238
+
50a6238
+#ifndef _SYS_PROCFS32_H
50a6238
+#define _SYS_PROCFS32_H	1
50a6238
+
50a6238
+/* This is somewhat modelled after the file of the same name on SVR4
50a6238
+   systems.  It provides a definition of the core file format for ELF
50a6238
+   used on Linux.  It doesn't have anything to do with the /proc file
50a6238
+   system, even though Linux has one.
50a6238
+
50a6238
+   Anyway, the whole purpose of this file is for GDB and GDB only.
50a6238
+   Don't read too much into it.  Don't use it for anything other than
50a6238
+   GDB unless you know what you are doing.  */
50a6238
+
50a6238
+#include <features.h>
50a6238
+#include <sys/time.h>
50a6238
+#include <sys/types.h>
50a6238
+#include "gdb_user32.h"
50a6238
+
50a6238
+/* We define here only the symbols differing from their 64-bit variant.  */
50a6238
+#include <sys/procfs.h>
50a6238
+
50a6238
+__BEGIN_DECLS
50a6238
+
50a6238
+/* Type for a general-purpose register.  */
50a6238
+typedef unsigned int elf_greg32_t;
50a6238
+
50a6238
+/* And the whole bunch of them.  We could have used `struct
50a6238
+   user_regs_struct' directly in the typedef, but tradition says that
50a6238
+   the register set is an array, which does have some peculiar
50a6238
+   semantics, so leave it that way.  */
50a6238
+#define ELF_NGREG32 (sizeof (struct user_regs32_struct) / sizeof(elf_greg32_t))
50a6238
+typedef elf_greg32_t elf_gregset32_t[ELF_NGREG32];
50a6238
+
50a6238
+/* Register set for the floating-point registers.  */
50a6238
+typedef struct user_fpregs32_struct elf_fpregset32_t;
50a6238
+
50a6238
+/* Register set for the extended floating-point registers.  Includes
50a6238
+   the Pentium III SSE registers in addition to the classic
50a6238
+   floating-point stuff.  */
50a6238
+typedef struct user_fpxregs32_struct elf_fpxregset32_t;
50a6238
+
50a6238
+
50a6238
+/* Definitions to generate Intel SVR4-like core files.  These mostly
50a6238
+   have the same names as the SVR4 types with "elf_" tacked on the
50a6238
+   front to prevent clashes with Linux definitions, and the typedef
50a6238
+   forms have been avoided.  This is mostly like the SVR4 structure,
50a6238
+   but more Linuxy, with things that Linux does not support and which
50a6238
+   GDB doesn't really use excluded.  */
50a6238
+
50a6238
+struct prstatus32_timeval
50a6238
+  {
50a6238
+    int tv_sec;
50a6238
+    int tv_usec;
50a6238
+  };
50a6238
+
50a6238
+struct elf_prstatus32
50a6238
+  {
50a6238
+    struct elf_siginfo pr_info;		/* Info associated with signal.  */
50a6238
+    short int pr_cursig;		/* Current signal.  */
50a6238
+    unsigned int pr_sigpend;		/* Set of pending signals.  */
50a6238
+    unsigned int pr_sighold;		/* Set of held signals.  */
50a6238
+    __pid_t pr_pid;
50a6238
+    __pid_t pr_ppid;
50a6238
+    __pid_t pr_pgrp;
50a6238
+    __pid_t pr_sid;
50a6238
+    struct prstatus32_timeval pr_utime;		/* User time.  */
50a6238
+    struct prstatus32_timeval pr_stime;		/* System time.  */
50a6238
+    struct prstatus32_timeval pr_cutime;	/* Cumulative user time.  */
50a6238
+    struct prstatus32_timeval pr_cstime;	/* Cumulative system time.  */
50a6238
+    elf_gregset32_t pr_reg;		/* GP registers.  */
50a6238
+    int pr_fpvalid;			/* True if math copro being used.  */
50a6238
+  };
50a6238
+
50a6238
+
50a6238
+struct elf_prpsinfo32
50a6238
+  {
50a6238
+    char pr_state;			/* Numeric process state.  */
50a6238
+    char pr_sname;			/* Char for pr_state.  */
50a6238
+    char pr_zomb;			/* Zombie.  */
50a6238
+    char pr_nice;			/* Nice val.  */
50a6238
+    unsigned int pr_flag;		/* Flags.  */
50a6238
+    unsigned short int pr_uid;
50a6238
+    unsigned short int pr_gid;
50a6238
+    int pr_pid, pr_ppid, pr_pgrp, pr_sid;
50a6238
+    /* Lots missing */
50a6238
+    char pr_fname[16];			/* Filename of executable.  */
50a6238
+    char pr_psargs[ELF_PRARGSZ];	/* Initial part of arg list.  */
50a6238
+  };
50a6238
+
50a6238
+
50a6238
+/* The rest of this file provides the types for emulation of the
50a6238
+   Solaris <proc_service.h> interfaces that should be implemented by
50a6238
+   users of libthread_db.  */
50a6238
+
50a6238
+/* Register sets.  Linux has different names.  */
50a6238
+typedef elf_gregset_t prgregset32_t;
50a6238
+typedef elf_fpregset_t prfpregset32_t;
50a6238
+
50a6238
+/* Process status and info.  In the end we do provide typedefs for them.  */
50a6238
+typedef struct elf_prstatus32 prstatus32_t;
50a6238
+typedef struct elf_prpsinfo32 prpsinfo32_t;
50a6238
+
50a6238
+__END_DECLS
50a6238
+
50a6238
+#endif	/* _SYS_PROCFS32_H */
50a6238
+
50a6238
+#endif /* HAVE_SYS_PROCFS32_H */
25ff8a1
Index: gdb-6.8cvs20080219/gdb/gdb_user32.h
50a6238
===================================================================
aefb0e1
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
25ff8a1
+++ gdb-6.8cvs20080219/gdb/gdb_user32.h	2008-02-20 13:39:08.000000000 +0100
50a6238
@@ -0,0 +1,108 @@
50a6238
+#ifdef HAVE_SYS_USER32_H
50a6238
+#include <sys/user32.h>
50a6238
+#else
50a6238
+
50a6238
+#ifdef HAVE_STDINT_H
50a6238
+#include <stdint.h>
50a6238
+typedef  int32_t  gdb_int32_t;
50a6238
+typedef uint32_t gdb_uint32_t;
50a6238
+#else
50a6238
+typedef   signed int gdb_uint32_t;
50a6238
+typedef unsigned int gdb_uint32_t;
50a6238
+#endif
50a6238
+
50a6238
+/* Copyright (C) 2006 Free Software Foundation, Inc.
50a6238
+   This file is part of the GNU C Library.
50a6238
+
50a6238
+   The GNU C Library is free software; you can redistribute it and/or
50a6238
+   modify it under the terms of the GNU Lesser General Public
50a6238
+   License as published by the Free Software Foundation; either
50a6238
+   version 2.1 of the License, or (at your option) any later version.
50a6238
+
50a6238
+   The GNU C Library is distributed in the hope that it will be useful,
50a6238
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
50a6238
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
50a6238
+   Lesser General Public License for more details.
50a6238
+
50a6238
+   You should have received a copy of the GNU Lesser General Public
50a6238
+   License along with the GNU C Library; if not, write to the Free
50a6238
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
50a6238
+   02111-1307 USA.  */
50a6238
+
50a6238
+#ifndef _SYS_USER32_H
50a6238
+#define _SYS_USER32_H	1
50a6238
+
50a6238
+/* These are the 32-bit x86 structures.  */
50a6238
+
50a6238
+struct user_fpregs32_struct
50a6238
+{
50a6238
+  int32_t cwd;
50a6238
+  int32_t swd;
50a6238
+  int32_t twd;
50a6238
+  int32_t fip;
50a6238
+  int32_t fcs;
50a6238
+  int32_t foo;
50a6238
+  int32_t fos;
50a6238
+  int32_t st_space [20];
50a6238
+};
50a6238
+
50a6238
+struct user_fpxregs32_struct
50a6238
+{
50a6238
+  unsigned short int cwd;
50a6238
+  unsigned short int swd;
50a6238
+  unsigned short int twd;
50a6238
+  unsigned short int fop;
50a6238
+  int32_t fip;
50a6238
+  int32_t fcs;
50a6238
+  int32_t foo;
50a6238
+  int32_t fos;
50a6238
+  int32_t mxcsr;
50a6238
+  int32_t reserved;
50a6238
+  int32_t st_space[32];   /* 8*16 bytes for each FP-reg = 128 bytes */
50a6238
+  int32_t xmm_space[32];  /* 8*16 bytes for each XMM-reg = 128 bytes */
50a6238
+  int32_t padding[56];
50a6238
+};
50a6238
+
50a6238
+struct user_regs32_struct
50a6238
+{
50a6238
+  int32_t ebx;
50a6238
+  int32_t ecx;
50a6238
+  int32_t edx;
50a6238
+  int32_t esi;
50a6238
+  int32_t edi;
50a6238
+  int32_t ebp;
50a6238
+  int32_t eax;
50a6238
+  int32_t xds;
50a6238
+  int32_t xes;
50a6238
+  int32_t xfs;
50a6238
+  int32_t xgs;
50a6238
+  int32_t orig_eax;
50a6238
+  int32_t eip;
50a6238
+  int32_t xcs;
50a6238
+  int32_t eflags;
50a6238
+  int32_t esp;
50a6238
+  int32_t xss;
50a6238
+};
50a6238
+
50a6238
+struct user32
50a6238
+{
50a6238
+  struct user_regs32_struct	regs;
50a6238
+  int				u_fpvalid;
50a6238
+  struct user_fpregs32_struct	i387;
50a6238
+  uint32_t			u_tsize;
50a6238
+  uint32_t			u_dsize;
50a6238
+  uint32_t			u_ssize;
50a6238
+  uint32_t			start_code;
50a6238
+  uint32_t			start_stack;
50a6238
+  int32_t			signal;
50a6238
+  int				reserved;
50a6238
+  struct user_regs32_struct*	u_ar0;
50a6238
+  struct user_fpregs32_struct*	u_fpstate;
50a6238
+  uint32_t			magic;
50a6238
+  char				u_comm [32];
50a6238
+  int				u_debugreg [8];
50a6238
+};
50a6238
+
50a6238
+#endif	/* _SYS_USER32_H */
50a6238
+
50a6238
+#endif /* HAVE_SYS_USER32_H */
25ff8a1
Index: gdb-6.8cvs20080219/gdb/linux-nat.c
50a6238
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/linux-nat.c	2008-02-19 17:27:21.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/linux-nat.c	2008-02-20 13:39:08.000000000 +0100
25ff8a1
@@ -104,6 +104,21 @@ static LONGEST (*super_xfer_partial) (st
50a6238
 				      const gdb_byte *,
50a6238
 				      ULONGEST, LONGEST);
50a6238
 
50a6238
+/* This functions make elfcore note sections.
50a6238
+   They may get overriden by code adjusting data for multi-target builds.  */
50a6238
+char *(*linux_elfcore_write_prpsinfo)
50a6238
+  (bfd *, char *, int *, const char *, const char *) = elfcore_write_prpsinfo;
50a6238
+char *(*linux_elfcore_write_prstatus)
50a6238
+  (bfd *, char *, int *, long, int, const void *) = elfcore_write_prstatus;
eb9d945
+static char *
eb9d945
+linux_elfcore_write_prfpreg_bfd (bfd *abfd, char *buf, int *bufsiz,
eb9d945
+				 const void *fpregs, int size, struct regcache *regcache)
eb9d945
+{
eb9d945
+  return elfcore_write_prfpreg (abfd, buf, bufsiz, fpregs, size);
eb9d945
+}
eb9d945
+char *(*linux_elfcore_write_prfpreg) (bfd *, char *, int *, const void *, int,
eb9d945
+			   struct regcache *) = linux_elfcore_write_prfpreg_bfd;
50a6238
+
50a6238
 static int debug_linux_nat;
50a6238
 static void
50a6238
 show_debug_linux_nat (struct ui_file *file, int from_tty,
25ff8a1
@@ -2716,11 +2731,11 @@ linux_nat_do_thread_registers (bfd *obfd
50a6238
   else
eb9d945
     fill_gregset (regcache, &gregs, -1);
50a6238
 
50a6238
-  note_data = (char *) elfcore_write_prstatus (obfd,
50a6238
-					       note_data,
50a6238
-					       note_size,
50a6238
-					       lwp,
50a6238
-					       stop_signal, &gregs);
50a6238
+  note_data = (char *) linux_elfcore_write_prstatus (obfd,
50a6238
+						     note_data,
50a6238
+						     note_size,
50a6238
+						     lwp,
50a6238
+						     stop_signal, &gregs);
50a6238
 
50a6238
   if (core_regset_p
50a6238
       && (regset = gdbarch_regset_from_core_section (gdbarch, ".reg2",
25ff8a1
@@ -2731,10 +2746,11 @@ linux_nat_do_thread_registers (bfd *obfd
50a6238
   else
eb9d945
     fill_fpregset (regcache, &fpregs, -1);
50a6238
 
50a6238
-  note_data = (char *) elfcore_write_prfpreg (obfd,
50a6238
-					      note_data,
50a6238
-					      note_size,
50a6238
-					      &fpregs, sizeof (fpregs));
50a6238
+  note_data = (char *) linux_elfcore_write_prfpreg (obfd,
50a6238
+						    note_data,
50a6238
+						    note_size,
eb9d945
+						    &fpregs, sizeof (fpregs),
eb9d945
+						    regcache);
50a6238
 
50a6238
 #ifdef FILL_FPXREGSET
50a6238
   if (core_regset_p
25ff8a1
@@ -2828,9 +2844,9 @@ linux_nat_make_corefile_notes (bfd *obfd
eb9d945
 		       psargs_end - string_end);
eb9d945
 	    }
50a6238
 	}
50a6238
-      note_data = (char *) elfcore_write_prpsinfo (obfd,
50a6238
-						   note_data,
50a6238
-						   note_size, fname, psargs);
50a6238
+      note_data = (char *) linux_elfcore_write_prpsinfo (obfd, note_data,
50a6238
+							 note_size, fname,
50a6238
+							 psargs);
50a6238
     }
50a6238
 
50a6238
   /* Dump information for threads.  */
25ff8a1
Index: gdb-6.8cvs20080219/gdb/linux-nat.h
50a6238
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/linux-nat.h	2008-02-19 14:26:32.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/linux-nat.h	2008-02-20 13:39:37.000000000 +0100
25ff8a1
@@ -124,3 +124,12 @@ void linux_nat_switch_fork (ptid_t new_p
25ff8a1
 
25ff8a1
 /* Return the saved siginfo associated with PTID.  */
25ff8a1
 struct siginfo *linux_nat_get_siginfo (ptid_t ptid);
50a6238
+
25ff8a1
+/* These functions make elfcore note sections.
50a6238
+   They may get overriden by code adjusting data for multi-target builds.  */
50a6238
+extern char *(*linux_elfcore_write_prpsinfo)
50a6238
+  (bfd *, char *, int *, const char *, const char *);
50a6238
+extern char *(*linux_elfcore_write_prstatus)
50a6238
+  (bfd *, char *, int *, long, int, const void *);
50a6238
+extern char *(*linux_elfcore_write_prfpreg)
eb9d945
+  (bfd *, char *, int *, const void *, int, struct regcache *);