From: Steve Sistare <steven.sistare@oracle.com>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
"Daniel P. Berrange" <berrange@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Steve Sistare" <steven.sistare@oracle.com>
Subject: [PATCH v3] vl: pause option
Date: Wed, 6 Jan 2021 12:07:36 -0800 [thread overview]
Message-ID: <1609963656-417889-1-git-send-email-steven.sistare@oracle.com> (raw)
Provide the -pause command-line parameter and the QEMU_PAUSE environment
variable to pause QEMU during process startup and allow a developer to
attach a debugger, or observe the process using tools such as strace.
Useful when QEMU has been launched with some other entity, such as libvirt.
QEMU_PAUSE is checked in a constructor at the highest priority, and can
be used to debug other constructors. The -pause option is checked later,
during argument processing in main, but is useful if passing an environment
variable from a launcher to qemu is awkard.
Usage:
qemu -pause, or QEMU_PAUSE=1
After attaching a debugger, send SIGCONT to the qemu process to continue.
Example:
$ QEMU_PAUSE=1 qemu-system-x86_64 ...
QEMU pid 18371 is stopped.
$ gdb -p 18371
(gdb) break rcu_init
(gdb) signal SIGCONT
Breakpoint 1, rcu_init () at util/rcu.c:380
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
qemu-options.hx | 14 ++++++++++++++
softmmu/vl.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/qemu-options.hx b/qemu-options.hx
index 708583b..212a270 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -3668,6 +3668,20 @@ SRST
option is experimental.
ERST
+DEF("pause", 0, QEMU_OPTION_pause, \
+ "-pause pause the qemu process in main. to continue, send SIGCONT.\n"
+ " to pause earlier, before constructors are run, set the\n"
+ " environment variable QEMU_PAUSE=1 before starting qemu.\n",
+ QEMU_ARCH_ALL)
+
+SRST
+``-pause``
+ Pause the qemu process in main. This is useful for attaching a debugger
+ after QEMU has been launched by some other entity. After attaching, send
+ SIGCONT to continue. To pause earlier, before constructors are run, set
+ the environment variable QEMU_PAUSE=1 before starting qemu.
+ERST
+
DEF("S", 0, QEMU_OPTION_S, \
"-S freeze CPU at startup (use 'c' to start execution)\n",
QEMU_ARCH_ALL)
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 4eb9d1f..251465d 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2829,6 +2829,35 @@ static void create_default_memdev(MachineState *ms, const char *path)
&error_fatal);
}
+static void pause_me(void)
+{
+ int sig;
+ sigset_t set, oldset;
+
+ sigemptyset(&set);
+ sigaddset(&set, SIGCONT);
+ printf("QEMU pid %d is stopped. Send SIGCONT to continue.\n", getpid());
+ sigprocmask(SIG_BLOCK, &set, &oldset);
+ sigwait(&set, &sig);
+ sigprocmask(SIG_SETMASK, &oldset, 0);
+}
+
+static __attribute__((constructor(101))) void maybe_pause(void)
+{
+ const char *pause = getenv("QEMU_PAUSE");
+
+ if (pause) {
+ if (!pause[0] || !strcmp(pause, "1")) {
+ pause_me();
+ } else if (strcmp(pause, "0")) {
+ fprintf(stderr, "error: QEMU_PAUSE bad value %s. Must be 1 or "
+ "null to enable, 0 or unset to disable.\n",
+ pause);
+ exit(1);
+ }
+ }
+}
+
void qemu_init(int argc, char **argv, char **envp)
{
int i;
@@ -3191,6 +3220,9 @@ void qemu_init(int argc, char **argv, char **envp)
case QEMU_OPTION_gdb:
add_device_config(DEV_GDB, optarg);
break;
+ case QEMU_OPTION_pause:
+ pause_me();
+ break;
case QEMU_OPTION_L:
if (is_help_option(optarg)) {
list_data_dirs = true;
--
1.8.3.1
reply other threads:[~2021-01-06 20:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1609963656-417889-1-git-send-email-steven.sistare@oracle.com \
--to=steven.sistare@oracle.com \
--cc=alex.bennee@linaro.org \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=qemu-devel@nongnu.org \
/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;
as well as URLs for NNTP newsgroup(s).