qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: "Alex Bennée" <alex.bennee@linaro.org>, qemu-devel@nongnu.org
Subject: Re: [PATCH v1 09/14] gdbstub: eliminate gdbserver_fd global
Date: Thu, 23 Apr 2020 22:30:27 +0200	[thread overview]
Message-ID: <fccbc7d7-f370-5aed-0258-3507184ccff4@redhat.com> (raw)
In-Reply-To: <20200423170557.31106-10-alex.bennee@linaro.org>

On 4/23/20 7:05 PM, Alex Bennée wrote:
> We don't really need to track this fd beyond the initial creation of
> the socket. We already know if the system has been initialised by
> virtue of the gdbserver_state so lets remove it. This makes the later
> re-factoring easier.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   gdbstub.c | 23 ++++++++++-------------
>   1 file changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/gdbstub.c b/gdbstub.c
> index 171e150950..8c53cc0e1c 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -398,8 +398,6 @@ static void reset_gdbserver_state(void)
>   bool gdb_has_xml;
>   
>   #ifdef CONFIG_USER_ONLY
> -/* XXX: This is not thread safe.  Do we care?  */
> -static int gdbserver_fd = -1;
>   
>   static int get_char(void)
>   {
> @@ -2964,7 +2962,7 @@ void gdb_exit(CPUArchState *env, int code)
>         return;
>     }
>   #ifdef CONFIG_USER_ONLY
> -  if (gdbserver_fd < 0 || gdbserver_state.fd < 0) {
> +  if (gdbserver_state.fd < 0) {
>         return;
>     }
>   #endif
> @@ -3011,7 +3009,7 @@ gdb_handlesig(CPUState *cpu, int sig)
>       char buf[256];
>       int n;
>   
> -    if (gdbserver_fd < 0 || gdbserver_state.fd < 0) {
> +    if (!gdbserver_state.init || gdbserver_state.fd < 0) {
>           return sig;
>       }
>   
> @@ -3060,7 +3058,7 @@ void gdb_signalled(CPUArchState *env, int sig)
>   {
>       char buf[4];
>   
> -    if (gdbserver_fd < 0 || gdbserver_state.fd < 0) {
> +    if (!gdbserver_state.init || gdbserver_state.fd < 0) {
>           return;
>       }
>   
> @@ -3068,7 +3066,7 @@ void gdb_signalled(CPUArchState *env, int sig)
>       put_packet(buf);
>   }
>   
> -static bool gdb_accept(void)
> +static bool gdb_accept(int gdb_fd)
>   {
>       struct sockaddr_in sockaddr;
>       socklen_t len;
> @@ -3076,7 +3074,7 @@ static bool gdb_accept(void)
>   
>       for(;;) {
>           len = sizeof(sockaddr);
> -        fd = accept(gdbserver_fd, (struct sockaddr *)&sockaddr, &len);
> +        fd = accept(gdb_fd, (struct sockaddr *)&sockaddr, &len);
>           if (fd < 0 && errno != EINTR) {
>               perror("accept");
>               return false;
> @@ -3137,13 +3135,12 @@ static int gdbserver_open(int port)
>   
>   int gdbserver_start(int port)
>   {
> -    gdbserver_fd = gdbserver_open(port);
> -    if (gdbserver_fd < 0)
> +    int gdb_fd = gdbserver_open(port);
> +    if (gdb_fd < 0)
>           return -1;
>       /* accept connections */
> -    if (!gdb_accept()) {
> -        close(gdbserver_fd);
> -        gdbserver_fd = -1;
> +    if (!gdb_accept(gdb_fd)) {
> +        close(gdb_fd);
>           return -1;
>       }
>       return 0;
> @@ -3152,7 +3149,7 @@ int gdbserver_start(int port)
>   /* Disable gdb stub for child processes.  */
>   void gdbserver_fork(CPUState *cpu)
>   {
> -    if (gdbserver_fd < 0 || gdbserver_state.fd < 0) {
> +    if (!gdbserver_state.init || gdbserver_state.fd < 0) {
>           return;
>       }
>       close(gdbserver_state.fd);
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



  reply	other threads:[~2020-04-23 20:31 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-23 17:05 [PATCH for 5.1 v1 00/14] guest_base, gdbstub and Travis Alex Bennée
2020-04-23 17:05 ` [PATCH v1 01/14] linux-user: completely re-write init_guest_space Alex Bennée
2020-04-23 17:05 ` [PATCH v1 02/14] exec/cpu-all: Use bool for have_guest_base Alex Bennée
2020-04-23 17:05 ` [PATCH v1 03/14] accel/tcg: Relax va restrictions on 64-bit guests Alex Bennée
2020-04-23 17:05 ` [PATCH v1 04/14] .gitignore: include common build sub-directories Alex Bennée
2020-04-23 17:05 ` [PATCH v1 05/14] configure: favour gdb-multiarch if we have it Alex Bennée
2020-04-23 20:28   ` Philippe Mathieu-Daudé
2020-04-23 17:05 ` [PATCH v1 06/14] gdbstub: Introduce gdb_get_float64() to get 64-bit float registers Alex Bennée
2020-04-23 17:05 ` [PATCH v1 07/14] tests/tcg: better trap gdb failures Alex Bennée
2020-04-23 17:05 ` [PATCH v1 08/14] tests/tcg: drop inferior.was_attached() test Alex Bennée
2020-04-23 17:05 ` [PATCH v1 09/14] gdbstub: eliminate gdbserver_fd global Alex Bennée
2020-04-23 20:30   ` Philippe Mathieu-Daudé [this message]
2020-04-23 17:05 ` [PATCH v1 10/14] gdbstub/linux-user: support debugging over a unix socket Alex Bennée
2020-04-23 17:05 ` [PATCH v1 11/14] tests/guest-debug: use the unix socket for linux-user tests Alex Bennée
2020-04-23 17:05 ` [PATCH v1 12/14] tests/tcg: add a multiarch linux-user gdb test Alex Bennée
2020-04-23 17:05 ` [PATCH v1 13/14] .travis.yml: show free disk space at end of run Alex Bennée
2020-04-23 20:27   ` Philippe Mathieu-Daudé
2020-04-23 17:05 ` [PATCH v1 14/14] .travis.yml: drop MacOSX Alex Bennée
2020-04-23 20:28   ` Philippe Mathieu-Daudé
2020-04-23 18:15 ` [PATCH for 5.1 v1 00/14] guest_base, gdbstub and Travis no-reply
2020-04-23 18:17 ` 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=fccbc7d7-f370-5aed-0258-3507184ccff4@redhat.com \
    --to=philmd@redhat.com \
    --cc=alex.bennee@linaro.org \
    --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).