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 3/3] btrace: pretend we're not replaying when generating a core file


When generating a core file using the "generate-core-file" command while
replaying with the btrace record target, we won't be able to access all
registers and all memory.  This leads to an assertion.

Use the gcore_start and gcore_end observers to pretend that we are not
replaying while generating a core file.  This will forward fetch and store
registers as well as xfer memory calls to the target beneath.

2014-05-22  Markus Metzger  <markus.t.metzger@intel.com>

	* record-btrace.c (before_corefile_observer)
	(after_corefile_observer, record_btrace_generating_corefile)
	(do_before_corefile, do_after_corefile): New.
	(record_btrace_xfer_partial, record_btrace_fetch_registers)
	(record_btrace_store_registers, record_btrace_prepare_to_store):
	Forward request when generating a core file.
	(_initialize_record_btrace): Attach before_corefile_observer and
	after_corefile_observer.

testsuite/
	* gdb.btrace/gcore.exp: New.
---
 gdb/record-btrace.c                | 35 ++++++++++++++++++++++++++++----
 gdb/testsuite/gdb.btrace/gcore.exp | 41 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 4 deletions(-)
 create mode 100644 gdb/testsuite/gdb.btrace/gcore.exp

diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index d768225..1265154 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -42,6 +42,13 @@ static struct target_ops record_btrace_ops;
 /* A new thread observer enabling branch tracing for the new thread.  */
 static struct observer *record_btrace_thread_observer;
 
+/* A pair of make_corefile_notes observers.  */
+static struct observer *before_corefile_observer;
+static struct observer *after_corefile_observer;
+
+/* A flag indicating that we are currently generating a core file.  */
+static int record_btrace_generating_corefile;
+
 /* Temporarily allow memory accesses.  */
 static int record_btrace_allow_memory_access;
 
@@ -815,7 +822,8 @@ record_btrace_xfer_partial (struct target_ops *ops, enum target_object object,
   struct target_ops *t;
 
   /* Filter out requests that don't make sense during replay.  */
-  if (!record_btrace_allow_memory_access && record_btrace_is_replaying (ops))
+  if (!record_btrace_allow_memory_access && !record_btrace_generating_corefile
+      && record_btrace_is_replaying (ops))
     {
       switch (object)
 	{
@@ -928,7 +936,7 @@ record_btrace_fetch_registers (struct target_ops *ops,
   gdb_assert (tp != NULL);
 
   replay = tp->btrace.replay;
-  if (replay != NULL)
+  if (replay != NULL && !record_btrace_generating_corefile)
     {
       const struct btrace_insn *insn;
       struct gdbarch *gdbarch;
@@ -969,7 +977,7 @@ record_btrace_store_registers (struct target_ops *ops,
 {
   struct target_ops *t;
 
-  if (record_btrace_is_replaying (ops))
+  if (!record_btrace_generating_corefile && record_btrace_is_replaying (ops))
     error (_("This record target does not allow writing registers."));
 
   gdb_assert (may_write_registers != 0);
@@ -992,7 +1000,7 @@ record_btrace_prepare_to_store (struct target_ops *ops,
 {
   struct target_ops *t;
 
-  if (record_btrace_is_replaying (ops))
+  if (!record_btrace_generating_corefile && record_btrace_is_replaying (ops))
     return;
 
   for (t = ops->beneath; t != NULL; t = t->beneath)
@@ -1938,6 +1946,22 @@ cmd_record_btrace_start (char *args, int from_tty)
   execute_command ("target record-btrace", from_tty);
 }
 
+/* The before_corefile_observer function.  */
+
+static void
+do_before_corefile (void)
+{
+  record_btrace_generating_corefile = 1;
+}
+
+/* The after_corefile_observer function.  */
+
+static void
+do_after_corefile (void)
+{
+  record_btrace_generating_corefile = 0;
+}
+
 void _initialize_record_btrace (void);
 
 /* Initialize btrace commands.  */
@@ -1945,6 +1969,9 @@ void _initialize_record_btrace (void);
 void
 _initialize_record_btrace (void)
 {
+  before_corefile_observer = observer_attach_gcore_start (do_before_corefile);
+  after_corefile_observer = observer_attach_gcore_end (do_after_corefile);
+
   add_cmd ("btrace", class_obscure, cmd_record_btrace_start,
 	   _("Start branch trace recording."),
 	   &record_cmdlist);
diff --git a/gdb/testsuite/gdb.btrace/gcore.exp b/gdb/testsuite/gdb.btrace/gcore.exp
new file mode 100644
index 0000000..1ff4f27
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/gcore.exp
@@ -0,0 +1,41 @@
+# This testcase is part of GDB, the GNU debugger.
+#
+# Copyright 2014 Free Software Foundation, Inc.
+#
+# Contributed by Intel Corp. <markus.t.metzger@intel.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# check for btrace support
+if { [skip_btrace_tests] } { return -1 }
+
+# start inferior
+standard_testfile x86-record_goto.S
+if [prepare_for_testing gcore.exp $testfile $srcfile] {
+    return -1
+}
+
+if ![runto_main] {
+    return -1
+}
+
+# trace the call to the test function
+gdb_test_no_output "record btrace"
+gdb_test "next" ".*main\.3.*"
+
+# start replaying
+gdb_test "record goto begin" ".*main\.2.*"
+
+# generate a core file - this used to assert
+gdb_test "generate-core-file core" "Saved corefile core"
-- 
1.8.3.1


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