From aef929023e3f9c68126564a96431935d35ce032e Mon Sep 17 00:00:00 2001 From: Markus Metzger Date: Tue, 20 May 2014 15:53:44 +0200 Subject: [PATCH] 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 the following assertion: gdb/regcache.c:1034: internal-error: regcache_raw_supply: Assertion `regnum >= 0 && regnum < regcache->descr->nr_raw_registers' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) FAIL: gdb.btrace/gcore.exp: generate-core-file core (GDB internal error) Resyncing due to internal error. 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. gdb/ * record-btrace.c (record_btrace_generating_corefile) (record_btrace_prepare_to_generate_core) (record_btrace_done_generating_core): 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. (record_btrace_open): Set record_btrace_generating_corefile to zero. (init_record_btrace_ops): Set to_prepare_to_generate_core and to_done_generating_core. testsuite/ * gdb.btrace/gcore.exp: New. --- gdb/ChangeLog | 12 +++++++++ gdb/record-btrace.c | 29 ++++++++++++++++++--- gdb/testsuite/ChangeLog | 4 +++ gdb/testsuite/gdb.btrace/gcore.exp | 41 ++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 gdb/testsuite/gdb.btrace/gcore.exp diff --git a/gdb/ChangeLog b/gdb/ChangeLog index bc20aeed0b5..462afed1f24 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,15 @@ +2014-06-25 Markus Metzger + + * record-btrace.c (record_btrace_generating_corefile) + (record_btrace_prepare_to_generate_core) + (record_btrace_done_generating_core): 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. + (record_btrace_open): Set record_btrace_generating_corefile to zero. + (init_record_btrace_ops): Set to_prepare_to_generate_core and + to_done_generating_core. + 2014-06-25 Markus Metzger * target.h (target_ops) diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index 6a9bfe11879..5ba4e0619b2 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -68,6 +68,9 @@ static enum exec_direction_kind record_btrace_resume_exec_dir = EXEC_FORWARD; /* The async event handler for reverse/replay execution. */ static struct async_event_handler *record_btrace_async_inferior_event_handler; +/* A flag indicating that we are currently generating a core file. */ +static int record_btrace_generating_corefile; + /* Print a record-btrace debug message. Use do ... while (0) to avoid ambiguities when used in if statements. */ @@ -221,6 +224,7 @@ record_btrace_open (char *args, int from_tty) record_btrace_async_inferior_event_handler = create_async_event_handler (record_btrace_handle_async_inferior_event, NULL); + record_btrace_generating_corefile = 0; observer_notify_record_changed (current_inferior (), 1); @@ -854,6 +858,7 @@ record_btrace_xfer_partial (struct target_ops *ops, enum target_object object, /* Filter out requests that don't make sense during replay. */ if (replay_memory_access == replay_memory_access_read_only + && !record_btrace_generating_corefile && record_btrace_is_replaying (ops)) { switch (object) @@ -969,7 +974,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; @@ -1010,7 +1015,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); @@ -1033,7 +1038,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) @@ -1939,6 +1944,22 @@ record_btrace_execution_direction (struct target_ops *self) return record_btrace_resume_exec_dir; } +/* The to_prepare_to_generate_core target method. */ + +static void +record_btrace_prepare_to_generate_core (struct target_ops *self) +{ + record_btrace_generating_corefile = 1; +} + +/* The to_done_generating_core target method. */ + +static void +record_btrace_done_generating_core (struct target_ops *self) +{ + record_btrace_generating_corefile = 0; +} + /* Initialize the record-btrace target ops. */ static void @@ -1983,6 +2004,8 @@ init_record_btrace_ops (void) ops->to_can_execute_reverse = record_btrace_can_execute_reverse; ops->to_decr_pc_after_break = record_btrace_decr_pc_after_break; ops->to_execution_direction = record_btrace_execution_direction; + ops->to_prepare_to_generate_core = record_btrace_prepare_to_generate_core; + ops->to_done_generating_core = record_btrace_done_generating_core; ops->to_stratum = record_stratum; ops->to_magic = OPS_MAGIC; } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 2c8f159ed5c..b21c4016075 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-06-25 Markus Metzger + + * gdb.btrace/gcore.exp: New. + 2014-06-23 Pedro Alves * gdb.base/watchpoint-reuse-slot.c: New file. diff --git a/gdb/testsuite/gdb.btrace/gcore.exp b/gdb/testsuite/gdb.btrace/gcore.exp new file mode 100644 index 00000000000..1ff4f27f453 --- /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. +# +# 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 . + +# 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" -- 2.30.2