Pass stream to remote_console_output

Message ID 20240506211035.1751940-1-tromey@adacore.com
State New
Headers
Series Pass stream to remote_console_output |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Tom Tromey May 6, 2024, 9:10 p.m. UTC
  I noticed that remote_target::rcmd did not pass its ui_file argument
down to remote_console_output.  This patch fixes this oversight.
---
 gdb/remote.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
  

Comments

Ciaran Woodward May 8, 2024, 3:21 p.m. UTC | #1
> From: Tom Tromey <tromey@adacore.com>
> 
> I noticed that remote_target::rcmd did not pass its ui_file argument
> down to remote_console_output.  This patch fixes this oversight.
> ---
>  gdb/remote.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)

Nice, I had a similar patch that was much messier (I'd been meaning to clean it
up and send it to the list). But this does the same job - I agree this is a good
change. The command now matches what the RSP documentation already claimed and
works more nicely with the python API.

I applied the patch to my build and it behaves exactly as I would expect. I've run
it through our test suite (which uses RSP for a custom architecture and some monitor
commands) and it passes.

Tested-By: Ciaran Woodward <ciaranwoodward@xmos.com>

Thanks,
Ciaran
  
Andrew Burgess May 10, 2024, 11:01 a.m. UTC | #2
Tom Tromey <tromey@adacore.com> writes:

> I noticed that remote_target::rcmd did not pass its ui_file argument
> down to remote_console_output.  This patch fixes this oversight.

LGTM.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

> ---
>  gdb/remote.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/gdb/remote.c b/gdb/remote.c
> index 55069559a60..6e568eb47b2 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -1521,7 +1521,7 @@ static ptid_t read_ptid (const char *buf, const char **obuf);
>  
>  static bool remote_read_description_p (struct target_ops *target);
>  
> -static void remote_console_output (const char *msg);
> +static void remote_console_output (const char *msg, ui_file *stream);
>  
>  static void remote_btrace_reset (remote_state *rs);
>  
> @@ -1750,7 +1750,10 @@ remote_target::remote_get_noisy_reply ()
>  	    }
>  	}
>        else if (buf[0] == 'O' && buf[1] != 'K')
> -	remote_console_output (buf + 1);	/* 'O' message from stub */
> +	{
> +	  /* 'O' message from stub */
> +	  remote_console_output (buf + 1, gdb_stdtarg);
> +	}
>        else
>  	return buf;		/* Here's the actual reply.  */
>      }
> @@ -7642,7 +7645,7 @@ remote_target::terminal_ours ()
>  }
>  
>  static void
> -remote_console_output (const char *msg)
> +remote_console_output (const char *msg, ui_file *stream)
>  {
>    const char *p;
>  
> @@ -7653,9 +7656,9 @@ remote_console_output (const char *msg)
>  
>        tb[0] = c;
>        tb[1] = 0;
> -      gdb_stdtarg->puts (tb);
> +      stream->puts (tb);
>      }
> -  gdb_stdtarg->flush ();
> +  stream->flush ();
>  }
>  
>  /* Return the length of the stop reply queue.  */
> @@ -8583,7 +8586,7 @@ remote_target::wait_ns (ptid_t ptid, struct target_waitstatus *status,
>  	    warning (_("Remote failure reply: %s"), rs->buf.data ());
>  	    break;
>  	  case 'O':		/* Console output.  */
> -	    remote_console_output (&rs->buf[1]);
> +	    remote_console_output (&rs->buf[1], gdb_stdtarg);
>  	    break;
>  	  default:
>  	    warning (_("Invalid remote reply: %s"), rs->buf.data ());
> @@ -8717,7 +8720,7 @@ remote_target::wait_as (ptid_t ptid, target_waitstatus *status,
>  	    break;
>  	  }
>  	case 'O':		/* Console output.  */
> -	  remote_console_output (buf + 1);
> +	  remote_console_output (buf + 1, gdb_stdtarg);
>  	  break;
>  	case '\0':
>  	  if (rs->last_sent_signal != GDB_SIGNAL_0)
> @@ -11993,7 +11996,8 @@ remote_target::rcmd (const char *command, struct ui_file *outbuf)
>        buf = rs->buf.data ();
>        if (buf[0] == 'O' && buf[1] != 'K')
>  	{
> -	  remote_console_output (buf + 1); /* 'O' message from stub.  */
> +	  /* 'O' message from stub.  */
> +	  remote_console_output (buf + 1, outbuf);
>  	  continue;
>  	}
>        packet_result result = packet_check_result (buf, false);
> -- 
> 2.44.0
  

Patch

diff --git a/gdb/remote.c b/gdb/remote.c
index 55069559a60..6e568eb47b2 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1521,7 +1521,7 @@  static ptid_t read_ptid (const char *buf, const char **obuf);
 
 static bool remote_read_description_p (struct target_ops *target);
 
-static void remote_console_output (const char *msg);
+static void remote_console_output (const char *msg, ui_file *stream);
 
 static void remote_btrace_reset (remote_state *rs);
 
@@ -1750,7 +1750,10 @@  remote_target::remote_get_noisy_reply ()
 	    }
 	}
       else if (buf[0] == 'O' && buf[1] != 'K')
-	remote_console_output (buf + 1);	/* 'O' message from stub */
+	{
+	  /* 'O' message from stub */
+	  remote_console_output (buf + 1, gdb_stdtarg);
+	}
       else
 	return buf;		/* Here's the actual reply.  */
     }
@@ -7642,7 +7645,7 @@  remote_target::terminal_ours ()
 }
 
 static void
-remote_console_output (const char *msg)
+remote_console_output (const char *msg, ui_file *stream)
 {
   const char *p;
 
@@ -7653,9 +7656,9 @@  remote_console_output (const char *msg)
 
       tb[0] = c;
       tb[1] = 0;
-      gdb_stdtarg->puts (tb);
+      stream->puts (tb);
     }
-  gdb_stdtarg->flush ();
+  stream->flush ();
 }
 
 /* Return the length of the stop reply queue.  */
@@ -8583,7 +8586,7 @@  remote_target::wait_ns (ptid_t ptid, struct target_waitstatus *status,
 	    warning (_("Remote failure reply: %s"), rs->buf.data ());
 	    break;
 	  case 'O':		/* Console output.  */
-	    remote_console_output (&rs->buf[1]);
+	    remote_console_output (&rs->buf[1], gdb_stdtarg);
 	    break;
 	  default:
 	    warning (_("Invalid remote reply: %s"), rs->buf.data ());
@@ -8717,7 +8720,7 @@  remote_target::wait_as (ptid_t ptid, target_waitstatus *status,
 	    break;
 	  }
 	case 'O':		/* Console output.  */
-	  remote_console_output (buf + 1);
+	  remote_console_output (buf + 1, gdb_stdtarg);
 	  break;
 	case '\0':
 	  if (rs->last_sent_signal != GDB_SIGNAL_0)
@@ -11993,7 +11996,8 @@  remote_target::rcmd (const char *command, struct ui_file *outbuf)
       buf = rs->buf.data ();
       if (buf[0] == 'O' && buf[1] != 'K')
 	{
-	  remote_console_output (buf + 1); /* 'O' message from stub.  */
+	  /* 'O' message from stub.  */
+	  remote_console_output (buf + 1, outbuf);
 	  continue;
 	}
       packet_result result = packet_check_result (buf, false);