From: "Alex Bennée" <alex.bennee@linaro.org>
To: Valentin Ghita <valentinghita@google.com>
Cc: qemu-devel@nongnu.org, "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Peter Maydell" <peter.maydell@linaro.org>,
qemu-arm@nongnu.org
Subject: Re: [PATCH] armv7m_nvic: set DHCSR.DEBUGEN when debugger is attached
Date: Thu, 03 Feb 2022 17:40:49 +0000 [thread overview]
Message-ID: <87tudfsv80.fsf@linaro.org> (raw)
In-Reply-To: <20220203155304.2648009-1-valentinghita@google.com>
Valentin Ghita <valentinghita@google.com> writes:
> The DEBUGEN bit is set by the debugger when it is connected to the
> core. Software can use this bit to check if a debug session is active.
>
> Add a function in gdbstub to check if the debugger is attached to a CPU
> and use this information when the DHCSR register is read in armv7m_nvic.
>
> Signed-off-by: Valentin Ghita <valentinghita@google.com>
Nack - use of the gdbstub should be transparent to the guest. It is not
trying to model any real JTAG/External debug hardware here.
> ---
> gdbstub.c | 10 ++++++++++
> hw/intc/armv7m_nvic.c | 4 ++++
> include/exec/gdbstub.h | 6 ++++++
> 3 files changed, 20 insertions(+)
>
> diff --git a/gdbstub.c b/gdbstub.c
> index 3c14c6a038..d4e39db8e7 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -3585,6 +3585,16 @@ int gdbserver_start(const char *device)
> return 0;
> }
>
> +bool gdb_attached(CPUState *cpu)
> +{
> + GDBProcess *process = gdb_get_cpu_process(cpu);
> + if (process != NULL) {
> + return process->attached;
> + }
> +
> + return false;
> +}
> +
> static void register_types(void)
> {
> type_register_static(&char_gdb_type_info);
> diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
> index 13df002ce4..d6fff94bca 100644
> --- a/hw/intc/armv7m_nvic.c
> +++ b/hw/intc/armv7m_nvic.c
> @@ -21,6 +21,7 @@
> #include "sysemu/runstate.h"
> #include "target/arm/cpu.h"
> #include "exec/exec-all.h"
> +#include "exec/gdbstub.h"
> #include "exec/memop.h"
> #include "qemu/log.h"
> #include "qemu/module.h"
> @@ -1510,6 +1511,9 @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)
> }
> /* We provide minimal-RAS only: RFSR is RAZ/WI */
> return 0;
> + case 0xdf0: /* DHCSR */
> + /* Bit 0: DEBUGEN. */
> + return gdb_attached(CPU(cpu)) ? 1 : 0;
> case 0xf34: /* FPCCR */
> if (!cpu_isar_feature(aa32_vfp_simd, cpu)) {
> return 0;
> diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
> index a024a0350d..383f4e5224 100644
> --- a/include/exec/gdbstub.h
> +++ b/include/exec/gdbstub.h
> @@ -177,6 +177,12 @@ static inline uint8_t * gdb_get_reg_ptr(GByteArray *buf, int len)
> */
> int gdbserver_start(const char *port_or_device);
>
> +/**
> + * gdb_attached: check if GDB is attached to a given CPU.
> + * @cpu: the CPU to check if GDB is attached to.
> + */
> +bool gdb_attached(CPUState *cpu);
> +
> /**
> * gdb_has_xml:
> * This is an ugly hack to cope with both new and old gdb.
--
Alex Bennée
WARNING: multiple messages have this Message-ID (diff)
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Valentin Ghita <valentinghita@google.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
qemu-arm@nongnu.org, qemu-devel@nongnu.org,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: Re: [PATCH] armv7m_nvic: set DHCSR.DEBUGEN when debugger is attached
Date: Thu, 03 Feb 2022 17:40:49 +0000 [thread overview]
Message-ID: <87tudfsv80.fsf@linaro.org> (raw)
In-Reply-To: <20220203155304.2648009-1-valentinghita@google.com>
Valentin Ghita <valentinghita@google.com> writes:
> The DEBUGEN bit is set by the debugger when it is connected to the
> core. Software can use this bit to check if a debug session is active.
>
> Add a function in gdbstub to check if the debugger is attached to a CPU
> and use this information when the DHCSR register is read in armv7m_nvic.
>
> Signed-off-by: Valentin Ghita <valentinghita@google.com>
Nack - use of the gdbstub should be transparent to the guest. It is not
trying to model any real JTAG/External debug hardware here.
> ---
> gdbstub.c | 10 ++++++++++
> hw/intc/armv7m_nvic.c | 4 ++++
> include/exec/gdbstub.h | 6 ++++++
> 3 files changed, 20 insertions(+)
>
> diff --git a/gdbstub.c b/gdbstub.c
> index 3c14c6a038..d4e39db8e7 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -3585,6 +3585,16 @@ int gdbserver_start(const char *device)
> return 0;
> }
>
> +bool gdb_attached(CPUState *cpu)
> +{
> + GDBProcess *process = gdb_get_cpu_process(cpu);
> + if (process != NULL) {
> + return process->attached;
> + }
> +
> + return false;
> +}
> +
> static void register_types(void)
> {
> type_register_static(&char_gdb_type_info);
> diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
> index 13df002ce4..d6fff94bca 100644
> --- a/hw/intc/armv7m_nvic.c
> +++ b/hw/intc/armv7m_nvic.c
> @@ -21,6 +21,7 @@
> #include "sysemu/runstate.h"
> #include "target/arm/cpu.h"
> #include "exec/exec-all.h"
> +#include "exec/gdbstub.h"
> #include "exec/memop.h"
> #include "qemu/log.h"
> #include "qemu/module.h"
> @@ -1510,6 +1511,9 @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)
> }
> /* We provide minimal-RAS only: RFSR is RAZ/WI */
> return 0;
> + case 0xdf0: /* DHCSR */
> + /* Bit 0: DEBUGEN. */
> + return gdb_attached(CPU(cpu)) ? 1 : 0;
> case 0xf34: /* FPCCR */
> if (!cpu_isar_feature(aa32_vfp_simd, cpu)) {
> return 0;
> diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
> index a024a0350d..383f4e5224 100644
> --- a/include/exec/gdbstub.h
> +++ b/include/exec/gdbstub.h
> @@ -177,6 +177,12 @@ static inline uint8_t * gdb_get_reg_ptr(GByteArray *buf, int len)
> */
> int gdbserver_start(const char *port_or_device);
>
> +/**
> + * gdb_attached: check if GDB is attached to a given CPU.
> + * @cpu: the CPU to check if GDB is attached to.
> + */
> +bool gdb_attached(CPUState *cpu);
> +
> /**
> * gdb_has_xml:
> * This is an ugly hack to cope with both new and old gdb.
--
Alex Bennée
next prev parent reply other threads:[~2022-02-03 17:42 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-03 15:53 [PATCH] armv7m_nvic: set DHCSR.DEBUGEN when debugger is attached Valentin Ghita
2022-02-03 16:13 ` Peter Maydell
2022-02-03 16:13 ` Peter Maydell
2022-02-03 17:40 ` Alex Bennée [this message]
2022-02-03 17:40 ` Alex Bennée
2022-02-04 8:33 ` Valentin Ghita
2022-02-04 9:17 ` Alex Bennée
2022-02-04 9:17 ` Alex Bennée
2022-02-04 9:42 ` Peter Maydell
2022-02-04 9:42 ` Peter Maydell
2022-02-04 12:33 ` Alex Bennée
2022-02-04 12:33 ` Alex Bennée
2022-02-04 14:03 ` Peter Maydell
2022-02-04 14:03 ` Peter Maydell
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=87tudfsv80.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=f4bug@amsat.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=valentinghita@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.