Message ID | 1596122076-341293-13-git-send-email-steven.sistare@oracle.com |
---|---|
State | New |
Headers | show |
Series | [V1,01/32] savevm: add vmstate handler iterators | expand |
On 9/11/2020 1:59 PM, Dr. David Alan Gilbert wrote: > * Steven Sistare (steven.sistare@oracle.com) wrote: >> On 7/30/2020 1:03 PM, Alex Bennée wrote: >>> >>> Steve Sistare <steven.sistare@oracle.com> writes: >>> >>>> Provide the -pause command-line parameter and the QEMU_PAUSE environment >>>> variable to briefly pause QEMU in main and allow a developer to attach gdb. >>>> Useful when the developer does not invoke QEMU directly, such as when using >>>> libvirt. >>> >>> How does this differ from -S? >> >> The -S flag runs qemu to the main loop but does not start the guest. Lots of code >> that you may need to debug runs before you get there. > > You might try the '--preconfig' option - that's pretty early on. > The other one is adding a chardev and telling it to wait for a server; > that'll wait until you telnet to the port. > > (Either way, this patch shouldn't really be part of this series, it's a > separate discussion) Sure, I will pull it from the series. - Steve >> - Steve >>>> Usage: >>>> qemu -pause <seconds> >>>> or >>>> export QEMU_PAUSE=<seconds> >>>> >>>> Signed-off-by: Steve Sistare <steven.sistare@oracle.com> >>>> --- >>>> qemu-options.hx | 9 +++++++++ >>>> softmmu/vl.c | 15 ++++++++++++++- >>>> 2 files changed, 23 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/qemu-options.hx b/qemu-options.hx >>>> index 708583b..8505cf2 100644 >>>> --- a/qemu-options.hx >>>> +++ b/qemu-options.hx >>>> @@ -3668,6 +3668,15 @@ SRST >>>> option is experimental. >>>> ERST >>>> >>>> +DEF("pause", HAS_ARG, QEMU_OPTION_pause, \ >>>> + "-pause secs Pause for secs seconds on entry to main.\n", QEMU_ARCH_ALL) >>>> + >>>> +SRST >>>> +``--pause secs`` >>>> + Pause for a number of seconds on entry to main. Useful for attaching >>>> + a debugger after QEMU has been launched by some other entity. >>>> +ERST >>>> + >>> >>> It seems like having an option to race with the debugger is just asking >>> for trouble. >>> >>>> 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 8478778..951994f 100644 >>>> --- a/softmmu/vl.c >>>> +++ b/softmmu/vl.c >>>> @@ -2844,7 +2844,7 @@ static void create_default_memdev(MachineState *ms, const char *path) >>>> >>>> void qemu_init(int argc, char **argv, char **envp) >>>> { >>>> - int i; >>>> + int i, seconds; >>>> int snapshot, linux_boot; >>>> const char *initrd_filename; >>>> const char *kernel_filename, *kernel_cmdline; >>>> @@ -2882,6 +2882,13 @@ void qemu_init(int argc, char **argv, char **envp) >>>> QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list); >>>> int mem_prealloc = 0; /* force preallocation of physical target memory */ >>>> >>>> + if (getenv("QEMU_PAUSE")) { >>>> + seconds = atoi(getenv("QEMU_PAUSE")); >>>> + printf("Pausing %d seconds for debugger. QEMU PID is %d\n", >>>> + seconds, getpid()); >>>> + sleep(seconds); >>>> + } >>>> + >>>> os_set_line_buffering(); >>>> >>>> error_init(argv[0]); >>>> @@ -3204,6 +3211,12 @@ void qemu_init(int argc, char **argv, char **envp) >>>> case QEMU_OPTION_gdb: >>>> add_device_config(DEV_GDB, optarg); >>>> break; >>>> + case QEMU_OPTION_pause: >>>> + seconds = atoi(optarg); >>>> + printf("Pausing %d seconds for debugger. QEMU PID is %d\n", >>>> + seconds, getpid()); >>>> + sleep(seconds); >>>> + break; >>>> case QEMU_OPTION_L: >>>> if (is_help_option(optarg)) { >>>> list_data_dirs = true; >>> >>> >>
diff --git a/qemu-options.hx b/qemu-options.hx index 708583b..8505cf2 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3668,6 +3668,15 @@ SRST option is experimental. ERST +DEF("pause", HAS_ARG, QEMU_OPTION_pause, \ + "-pause secs Pause for secs seconds on entry to main.\n", QEMU_ARCH_ALL) + +SRST +``--pause secs`` + Pause for a number of seconds on entry to main. Useful for attaching + a debugger after QEMU has been launched by some other entity. +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 8478778..951994f 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2844,7 +2844,7 @@ static void create_default_memdev(MachineState *ms, const char *path) void qemu_init(int argc, char **argv, char **envp) { - int i; + int i, seconds; int snapshot, linux_boot; const char *initrd_filename; const char *kernel_filename, *kernel_cmdline; @@ -2882,6 +2882,13 @@ void qemu_init(int argc, char **argv, char **envp) QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list); int mem_prealloc = 0; /* force preallocation of physical target memory */ + if (getenv("QEMU_PAUSE")) { + seconds = atoi(getenv("QEMU_PAUSE")); + printf("Pausing %d seconds for debugger. QEMU PID is %d\n", + seconds, getpid()); + sleep(seconds); + } + os_set_line_buffering(); error_init(argv[0]); @@ -3204,6 +3211,12 @@ void qemu_init(int argc, char **argv, char **envp) case QEMU_OPTION_gdb: add_device_config(DEV_GDB, optarg); break; + case QEMU_OPTION_pause: + seconds = atoi(optarg); + printf("Pausing %d seconds for debugger. QEMU PID is %d\n", + seconds, getpid()); + sleep(seconds); + break; case QEMU_OPTION_L: if (is_help_option(optarg)) { list_data_dirs = true;
Provide the -pause command-line parameter and the QEMU_PAUSE environment variable to briefly pause QEMU in main and allow a developer to attach gdb. Useful when the developer does not invoke QEMU directly, such as when using libvirt. Usage: qemu -pause <seconds> or export QEMU_PAUSE=<seconds> Signed-off-by: Steve Sistare <steven.sistare@oracle.com> --- qemu-options.hx | 9 +++++++++ softmmu/vl.c | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-)