From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: sw@weilnetz.de, lprosek@redhat.com, dovgaluk@ispras.ru,
rkagan@virtuozzo.com, pbonzini@redhat.com, den@openvz.org
Subject: Re: [Qemu-devel] [PATCH 2 30/39] windbg: debug exception subscribing
Date: Wed, 05 Dec 2018 14:36:32 +0000 [thread overview]
Message-ID: <87zhtk11n3.fsf@linaro.org> (raw)
In-Reply-To: <154401449112.8440.1747971561547810226.stgit@Misha-PC.lan02.inno>
Mikhail Abakumov <mikhail.abakumov@ispras.ru> writes:
> Add handler registration of gdb debug exception. Its exception also can be used
> for windbg.
>
> Signed-off-by: Mikhail Abakumov <mikhail.abakumov@ispras.ru>
> Signed-off-by: Pavel Dovgalyuk <dovgaluk@ispras.ru>
> ---
> cpus.c | 19 ++++++++++++++++++-
> gdbstub.c | 4 ++++
> include/sysemu/sysemu.h | 2 ++
> windbgstub.c | 14 ++++++++++++++
> 4 files changed, 38 insertions(+), 1 deletion(-)
>
> diff --git a/cpus.c b/cpus.c
> index a2b33ccb29..c8b05260b4 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -79,6 +79,8 @@ int64_t max_advance;
> static QEMUTimer *throttle_timer;
> static unsigned int throttle_percentage;
>
> +static void (*excp_debug_handler)(CPUState *cpu);
> +
> #define CPU_THROTTLE_PCT_MIN 1
> #define CPU_THROTTLE_PCT_MAX 99
> #define CPU_THROTTLE_TIMESLICE_NS 10000000
> @@ -1103,9 +1105,24 @@ static bool cpu_can_run(CPUState *cpu)
> return true;
> }
>
> +bool register_excp_debug_handler(void (*handler)(CPUState *cpu))
> +{
> + if (excp_debug_handler == NULL) {
> + excp_debug_handler = handler;
> + return true;
> + } else {
> + error_report("Something debugger is already in use. '-gdb' and "
> + "'-windbg' cannot be used at the same time");
> + return false;
> + }
> +}
> +
> static void cpu_handle_guest_debug(CPUState *cpu)
> {
> - gdb_set_stop_cpu(cpu);
If we are going to have a handler approach we can make gdb_set_stop_cpu
static and remove the gdbstub.h reference from cpus.c as well.
> + if (excp_debug_handler != NULL) {
> + excp_debug_handler(cpu);
> + }
> +
> qemu_system_debug_request();
> cpu->stopped = true;
> }
> diff --git a/gdbstub.c b/gdbstub.c
> index c4e4f9f082..9ed4fe2e8e 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -2074,6 +2074,10 @@ int gdbserver_start(const char *device)
> s->mon_chr = mon_chr;
> s->current_syscall_cb = NULL;
>
> + if (!register_excp_debug_handler(gdb_set_stop_cpu)) {
> + exit(1);
> + }
> +
> return 0;
> }
>
> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
> index 8d6095d98b..826b701bfa 100644
> --- a/include/sysemu/sysemu.h
> +++ b/include/sysemu/sysemu.h
> @@ -203,6 +203,8 @@ QemuOpts *qemu_get_machine_opts(void);
>
> bool defaults_enabled(void);
>
> +bool register_excp_debug_handler(void (*handler)(CPUState *cpu));
> +
> extern QemuOptsList qemu_legacy_drive_opts;
> extern QemuOptsList qemu_common_drive_opts;
> extern QemuOptsList qemu_drive_opts;
> diff --git a/windbgstub.c b/windbgstub.c
> index a1c013cd8c..0e4ad6d009 100644
> --- a/windbgstub.c
> +++ b/windbgstub.c
> @@ -129,9 +129,19 @@ static void windbg_send_control_packet(WindbgState *state, uint16_t type,
> qemu_chr_fe_write(&state->chr, PTR(packet), sizeof(packet));
> }
>
> +static void windbg_bp_handler(CPUState *cs)
> +{
> + DBGKD_ANY_WAIT_STATE_CHANGE *sc = kd_state_change_exc(cs);
> + windbg_send_data_packet(windbg_state, (uint8_t *) sc,
> + sizeof(DBGKD_ANY_WAIT_STATE_CHANGE),
> + PACKET_TYPE_KD_STATE_CHANGE64);
> +}
> +
> static void windbg_vm_stop(void)
> {
> + CPUState *cs = qemu_get_cpu(0);
This can fail - although I guess it's unlikely someone has hotplugged cpu0.
> vm_stop(RUN_STATE_PAUSED);
> + windbg_bp_handler(cs);
> }
>
> static void windbg_process_manipulate_packet(WindbgState *state)
> @@ -481,6 +491,10 @@ int windbg_server_start(const char *device)
>
> qemu_register_reset(windbg_handle_reset, NULL);
>
> + if (!register_excp_debug_handler(windbg_bp_handler)) {
> + exit(1);
> + }
> +
> atexit(windbg_exit);
> return 0;
> }
--
Alex Bennée
next prev parent reply other threads:[~2018-12-05 14:36 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-05 12:52 [Qemu-devel] [PATCH 2 00/39] Windbg supporting Mikhail Abakumov
2018-12-05 12:52 ` [Qemu-devel] [PATCH 2 01/39] windbg: add empty windbgstub files Mikhail Abakumov
2018-12-05 12:52 ` [Qemu-devel] [PATCH 2 02/39] windbg: add windbg's KD header file Mikhail Abakumov
2018-12-05 12:52 ` [Qemu-devel] [PATCH 2 03/39] windbg: add -windbg option Mikhail Abakumov
2018-12-05 12:52 ` [Qemu-devel] [PATCH 2 04/39] windbg: add helper features Mikhail Abakumov
2018-12-05 12:52 ` [Qemu-devel] [PATCH 2 05/39] windbg: add WindbgState Mikhail Abakumov
2018-12-05 12:52 ` [Qemu-devel] [PATCH 2 06/39] windbg: add chardev Mikhail Abakumov
2018-12-05 12:52 ` [Qemu-devel] [PATCH 2 07/39] windbg: hook to wrmsr operation Mikhail Abakumov
2018-12-05 12:52 ` [Qemu-devel] [PATCH 2 08/39] windbg: implement windbg_on_load Mikhail Abakumov
2018-12-05 12:52 ` [Qemu-devel] [PATCH 2 09/39] windbg: implement find_KPCR Mikhail Abakumov
2018-12-05 12:52 ` [Qemu-devel] [PATCH 2 10/39] windbg: implement find_kdVersion Mikhail Abakumov
2018-12-05 12:53 ` [Qemu-devel] [PATCH 2 11/39] windbg: add windbg_search_vmaddr Mikhail Abakumov
2018-12-05 12:53 ` [Qemu-devel] [PATCH 2 12/39] windbg: implement find_kdDebuggerDataBlock Mikhail Abakumov
2018-12-05 12:53 ` [Qemu-devel] [PATCH 2 13/39] windbg: parsing data stream Mikhail Abakumov
2018-12-05 12:53 ` [Qemu-devel] [PATCH 2 14/39] windbg: send data and control packets Mikhail Abakumov
2018-12-05 12:53 ` [Qemu-devel] [PATCH 2 15/39] windbg: handler of parsing context Mikhail Abakumov
2018-12-05 12:53 ` [Qemu-devel] [PATCH 2 16/39] windbg: init DBGKD_ANY_WAIT_STATE_CHANGE Mikhail Abakumov
2018-12-05 12:53 ` [Qemu-devel] [PATCH 2 17/39] windbg: generate ExceptionStateChange and LoadSymbolsStateChange Mikhail Abakumov
2018-12-05 12:53 ` [Qemu-devel] [PATCH 2 18/39] windbg: implement windbg_process_control_packet Mikhail Abakumov
2018-12-05 12:53 ` [Qemu-devel] [PATCH 2 19/39] windbg: implement windbg_process_data_packet Mikhail Abakumov
2018-12-05 12:53 ` [Qemu-devel] [PATCH 2 20/39] windbg: implement windbg_process_manipulate_packet Mikhail Abakumov
2018-12-05 12:54 ` [Qemu-devel] [PATCH 2 21/39] windbg: implement kd_api_read_virtual_memory and kd_api_write_virtual_memory Mikhail Abakumov
2018-12-05 12:54 ` [Qemu-devel] [PATCH 2 22/39] windbg: some kernel structures Mikhail Abakumov
2018-12-05 12:54 ` [Qemu-devel] [PATCH 2 23/39] windbg: add helper functions Mikhail Abakumov
2018-12-05 12:54 ` [Qemu-devel] [PATCH 2 24/39] windbg: [de]serialization cpu context Mikhail Abakumov
2018-12-05 12:54 ` [Qemu-devel] [PATCH 2 25/39] windbg: [de]serialization cpu spec registers Mikhail Abakumov
2018-12-05 12:54 ` [Qemu-devel] [PATCH 2 26/39] windbg: implement kd_api_get_context and kd_api_set_context Mikhail Abakumov
2018-12-05 12:54 ` [Qemu-devel] [PATCH 2 27/39] windbg: implement kd_api_get_context_ex and kd_api_set_context_ex Mikhail Abakumov
2018-12-05 12:54 ` [Qemu-devel] [PATCH 2 28/39] windbg: implement kd_api_read_control_space and kd_api_write_control_space Mikhail Abakumov
2018-12-05 12:54 ` [Qemu-devel] [PATCH 2 29/39] windbg: implement kd_api_write_breakpoint and kd_api_restore_breakpoint Mikhail Abakumov
2018-12-05 12:54 ` [Qemu-devel] [PATCH 2 30/39] windbg: debug exception subscribing Mikhail Abakumov
2018-12-05 14:36 ` Alex Bennée [this message]
2018-12-05 12:54 ` [Qemu-devel] [PATCH 2 31/39] windbg: implement kd_api_continue Mikhail Abakumov
2018-12-05 12:55 ` [Qemu-devel] [PATCH 2 32/39] windbg: implement kd_api_read_io_space and kd_api_write_io_space Mikhail Abakumov
2018-12-05 12:55 ` [Qemu-devel] [PATCH 2 33/39] windbg: implement kd_api_read_physical_memory and kd_api_write_physical_memory Mikhail Abakumov
2018-12-05 12:55 ` [Qemu-devel] [PATCH 2 34/39] windbg: implement kd_api_get_version Mikhail Abakumov
2018-12-05 12:55 ` [Qemu-devel] [PATCH 2 35/39] windbg: implement kd_api_read_msr and kd_api_write_msr Mikhail Abakumov
2018-12-05 12:55 ` [Qemu-devel] [PATCH 2 36/39] windbg: implement kd_api_search_memory Mikhail Abakumov
2018-12-05 12:55 ` [Qemu-devel] [PATCH 2 37/39] windbg: implement kd_api_fill_memory Mikhail Abakumov
2018-12-05 12:55 ` [Qemu-devel] [PATCH 2 38/39] windbg: implement kd_api_query_memory Mikhail Abakumov
2018-12-05 12:55 ` [Qemu-devel] [PATCH 2 39/39] windbg: maintainers Mikhail Abakumov
2018-12-05 14:30 ` [Qemu-devel] [PATCH 2 00/39] Windbg supporting no-reply
2018-12-05 14:37 ` no-reply
2018-12-05 14:38 ` no-reply
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=87zhtk11n3.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=den@openvz.org \
--cc=dovgaluk@ispras.ru \
--cc=lprosek@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rkagan@virtuozzo.com \
--cc=sw@weilnetz.de \
/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).