From: Luis Machado <lgustavo@codesourcery.com>
To: Simon Marchi <simon.marchi@ericsson.com>, <gdb-patches@sourceware.org>
Cc: <markus.t.metzger@intel.com>
Subject: Re: [PATCH] Prevent turning record on while threads are running (PR 20869)
Date: Tue, 29 Nov 2016 15:58:00 -0000 [thread overview]
Message-ID: <fef2bdd4-d5c8-14a8-73ed-329b27961f1b@codesourcery.com> (raw)
In-Reply-To: <20161129150758.29912-1-simon.marchi@ericsson.com>
On 11/29/2016 09:07 AM, Simon Marchi wrote:
> As stated in the bug description, trying to do "record" while threads
> are running leads to a broken state. I tried to see in the code if
> there was anything to try to support the use case of enabling record
> while the program is running, but didn't find anything.
>
> When full/software recording is active, we are single stepping each
> instruction. Transitioning from the state where threads are running
> freely (no recording) to recording enabled should therefore involve a
> step where we stop them to initiate the single stepping. I can't find
> anything that looks like this, so my conclusion is that this was never a
> supported use case (please correct me if I'm wrong).
>
> The easy solution is to prevent the user for enabling record if a thread
> is running.
>
> I also wanted to know whether it was supported to start btrace bts/pt
> recording with threads running. When I try it with btrace bts, it works
> halfway. "record btrace bts" gives me the error:
>
> Couldn't get registers: No such process.
>
> If I do the command again, gdb doesn't complain and then I'm able to
> interrupt the target and use reverse-next. However, since the
> initialization function was interrupted halfway, I am not sure that
> everything is setup correctly. If we want to allow it, we would first
> need to look into this issue.
>
> I have therefore put a check for running threads in record_preopen,
> which affects all recording methods. It can always be moved to
> record_full_open if we only want to affect record full.
>
> No regression on the buildbot.
>
> gdb/ChangeLog:
>
> * record.c: Include gdbthread.h.
> (record_preopen): Check if any thread is running.
>
> gdb/testsuite:
>
> * gdb.reverse/record-while-running.c: New file.
> * gdb.reverse/record-while-running.exp: New file.
> ---
> gdb/record.c | 11 ++++++
> gdb/testsuite/gdb.reverse/record-while-running.c | 29 ++++++++++++++++
> gdb/testsuite/gdb.reverse/record-while-running.exp | 40 ++++++++++++++++++++++
> 3 files changed, 80 insertions(+)
> create mode 100644 gdb/testsuite/gdb.reverse/record-while-running.c
> create mode 100644 gdb/testsuite/gdb.reverse/record-while-running.exp
>
> diff --git a/gdb/record.c b/gdb/record.c
> index 34ebd1b..e0bc133 100644
> --- a/gdb/record.c
> +++ b/gdb/record.c
> @@ -26,6 +26,7 @@
> #include "common/common-utils.h"
> #include "cli/cli-utils.h"
> #include "disasm.h"
> +#include "gdbthread.h"
>
> #include <ctype.h>
>
> @@ -89,6 +90,16 @@ record_preopen (void)
> if (find_record_target () != NULL)
> error (_("The process is already being recorded. Use \"record stop\" to "
> "stop recording first."));
> +
> + iterate_over_threads([] (struct thread_info *tp, void *) -> int {
> + if (tp->state == thread_state::THREAD_RUNNING)
> + error (_ ("Can't enable record while the program is running. Use "
> + "\"interrupt\" to stop it first."));
> +
> + return 0;
> + }, NULL);
> +
> +
> }
>
> /* See record.h. */
> diff --git a/gdb/testsuite/gdb.reverse/record-while-running.c b/gdb/testsuite/gdb.reverse/record-while-running.c
> new file mode 100644
> index 0000000..f00ceb6
> --- /dev/null
> +++ b/gdb/testsuite/gdb.reverse/record-while-running.c
> @@ -0,0 +1,29 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> + Copyright 2016 Free Software Foundation, Inc.
> +
> + 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/>. */
> +
> +#include <unistd.h>
> +
> +int
> +main ()
> +{
> + int i;
> +
> + for (i = 0; i < 30; i++)
> + sleep (1);
> +
> + return 0;
> +}
> diff --git a/gdb/testsuite/gdb.reverse/record-while-running.exp b/gdb/testsuite/gdb.reverse/record-while-running.exp
> new file mode 100644
> index 0000000..57e1df3
> --- /dev/null
> +++ b/gdb/testsuite/gdb.reverse/record-while-running.exp
> @@ -0,0 +1,40 @@
> +# Copyright 2016 Free Software Foundation, Inc.
> +
> +# 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/>. */
> +
> +# Test that trying to turn on recording while the target is running is correctly
> +# handled.
> +
> +if ![supports_reverse] {
Add an explicit untested call here?
> + return
> +}
> +
> +standard_testfile
> +
> +if { [prepare_for_testing $testfile.exp $testfile $srcfile] } {
> + fail "failed to compile"
> + return
> +}
> +
> +if { ![runto_main] } {
> + fail "couldn't run to main"
> + return
> +}
> +
> +proc test_record_while_running { } {
> + gdb_test "continue &" "Continuing."
> + gdb_test "record" "Can't enable record while the program is running. Use \"interrupt\" to stop it first."
I have mixed feelings with the above test names. I'd know what to look
for in case of failure, but more explicit test names wouldn't hurt for a
quick inspection of the logs.
"move thread"
"switch record on when thread is moving"
Feel free to pick it up though. Not a hard requirement.
next prev parent reply other threads:[~2016-11-29 15:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-29 15:08 Simon Marchi
2016-11-29 15:58 ` Luis Machado [this message]
2016-11-29 16:42 ` Simon Marchi
2016-11-29 16:47 ` Luis Machado
2016-11-30 15:36 ` Pedro Alves
2016-11-30 16:11 ` Luis Machado
2016-11-30 16:27 ` Simon Marchi
2016-11-30 9:54 ` Metzger, Markus T
2016-11-30 16:04 ` Simon Marchi
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=fef2bdd4-d5c8-14a8-73ed-329b27961f1b@codesourcery.com \
--to=lgustavo@codesourcery.com \
--cc=gdb-patches@sourceware.org \
--cc=markus.t.metzger@intel.com \
--cc=simon.marchi@ericsson.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