This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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]

[PATCH] gcore registers storing fix


The attached patch attempts to solve a bug that caused the gcore command to produce core files containing incorrect registers information. The problem caused incomplete backtraces when the files were read back into GDB.

I tested this patch with the gdb testsuite, and my addition to the gcore-thread.exp test case.

If OK, please commit it for me since I don't have write access.

Thanks,
	Daniel.

2009-11-06 Daniel Gutson <dgutson@codesourcery.com>

	gdb/
	* procfs.c (procfs_do_thread_registers): Added a call to fetch
	register values before saving them in the core file
	through the gcore command.
	(procfs_corefile_thread_callback): removed the backup of
	inferior_ptid before calling procfs_do_thread_registers since
	the function already saves and restores it before returning.

	gdb/testsuite/gdb.threads/
	* gcore-thread.exp: Added a test case in order to check
	if the core dump contains the registers values, and symbol
	lookup is working properly.

--
Daniel Gutson
CodeSourcery
www.codesourcery.com
Index: gdb/procfs.c
===================================================================
RCS file: /cvs/src/src/gdb/procfs.c,v
retrieving revision 1.119
diff -u -p -r1.119 procfs.c
--- gdb/procfs.c	21 Oct 2009 08:27:25 -0000	1.119
+++ gdb/procfs.c	6 Nov 2009 22:30:54 -0000
@@ -6060,9 +6060,19 @@ procfs_do_thread_registers (bfd *obfd, p
   gdb_gregset_t gregs;
   gdb_fpregset_t fpregs;
   unsigned long merged_pid;
+  struct cleanup *old_chain;
 
   merged_pid = TIDGET (ptid) << 16 | PIDGET (ptid);
 
+  /* This part is the old method for fetching registers.
+     It should be replaced by the newer one using regsets
+     once it is implemented in this platform:
+     gdbarch_regset_from_core_section() and regset->collect_regset(). */
+
+  old_chain = save_inferior_ptid ();
+  inferior_ptid = ptid;
+  target_fetch_registers (regcache, -1);
+
   fill_gregset (regcache, &gregs, -1);
 #if defined (UNIXWARE)
   note_data = (char *) elfcore_write_lwpstatus (obfd,
@@ -6085,6 +6095,9 @@ procfs_do_thread_registers (bfd *obfd, p
 					      note_size,
 					      &fpregs,
 					      sizeof (fpregs));
+
+  do_cleanups (old_chain);
+
   return note_data;
 }
 
@@ -6102,13 +6115,11 @@ procfs_corefile_thread_callback (procinf
 
   if (pi != NULL)
     {
-      ptid_t saved_ptid = inferior_ptid;
-      inferior_ptid = MERGEPID (pi->pid, thread->tid);
-      args->note_data = procfs_do_thread_registers (args->obfd, inferior_ptid,
+      ptid_t ptid = MERGEPID (pi->pid, thread->tid);
+      args->note_data = procfs_do_thread_registers (args->obfd, ptid,
 						    args->note_data,
 						    args->note_size,
 						    args->stop_signal);
-      inferior_ptid = saved_ptid;
     }
   return 0;
 }
Index: gdb/testsuite/gdb.threads/gcore-thread.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.threads/gcore-thread.exp,v
retrieving revision 1.13
diff -u -p -r1.13 gcore-thread.exp
--- gdb/testsuite/gdb.threads/gcore-thread.exp	3 Jan 2009 05:58:07 -0000	1.13
+++ gdb/testsuite/gdb.threads/gcore-thread.exp	6 Nov 2009 22:30:54 -0000
@@ -154,11 +154,7 @@ gdb_expect {
     }
 }
 
-# FIXME: now what can we test about the thread state?
-# We do not know for certain that there should be at least 
-# three threads, because who knows what kind of many-to-one
-# mapping various OS's may do?  Let's assume that there must
-# be at least two threads:
+# There must be at least two threads.
 
 gdb_test "info threads" ".*${nl}  2 ${horiz}${nl}\\* 1 .*" \
 	"corefile contains at least two threads"
@@ -173,3 +169,16 @@ gdb_test "info threads" ".* thread2 .*" 
 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
 	"thread2 is current thread in corefile"
 
+# The threads should be standing at a known function, rather than ??.
+
+gdb_test_multiple "info threads" \
+	"corefile contains good register values and enables symbols lookup" \
+{
+    -re ".* in \\?\\? .*" {
+        fail "corefile contains good register values and enables symbols lookup"
+    }
+    -re ".* in \[_a-zA-Z0-9]+ \\(.*" {
+        pass "corefile contains good register values and enables symbols lookup"
+    }
+}
+

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]