public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [pushed 1/4] gdb: const-ify unpack_* functions in remote.c
@ 2021-01-18  5:46 Simon Marchi
  2021-01-18  5:46 ` [pushed 2/4] gdb: const-ify remote_target::add_current_inferior_and_thread parameter Simon Marchi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Simon Marchi @ 2021-01-18  5:46 UTC (permalink / raw)
  To: gdb-patches

Const-ify the unpack_* functions, and then adjust the callers
accordingly.

gdb/ChangeLog:

	* remote.c (class remote_target)
	<remote_unpack_thread_info_response,
	parse_threadlist_response>: Constify parameter and/or return
	value and or local variable.
	(stub_unpack_int): Likewise.
	(unpack_nibble): Likewise.
	(unpack_byte): Likewise.
	(unpack_int): Likewise.
	(unpack_string): Likewise.
	(unpack_threadid): Likewise.
	(remote_target::remote_unpack_thread_info_response): Likewise.
	(remote_target::parse_threadlist_response): Likewise.

Change-Id: Ibda75f664d6e3452df00f85af7134533049171b7
---
 gdb/ChangeLog | 15 +++++++++++++++
 gdb/remote.c  | 49 ++++++++++++++++++++++++-------------------------
 2 files changed, 39 insertions(+), 25 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9ac7b46effd0..e1bf15666ceb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,18 @@
+2021-01-18  Simon Marchi  <simon.marchi@polymtl.ca>
+
+	* remote.c (class remote_target)
+	<remote_unpack_thread_info_response,
+	parse_threadlist_response>: Constify parameter and/or return
+	value and or local variable.
+	(stub_unpack_int): Likewise.
+	(unpack_nibble): Likewise.
+	(unpack_byte): Likewise.
+	(unpack_int): Likewise.
+	(unpack_string): Likewise.
+	(unpack_threadid): Likewise.
+	(remote_target::remote_unpack_thread_info_response): Likewise.
+	(remote_target::parse_threadlist_response): Likewise.
+
 2021-01-15  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	* tui/tui.c (tui_is_window_visible): Compare to nullptr, not 0.
diff --git a/gdb/remote.c b/gdb/remote.c
index 74ebbf9ab023..1df05e6cc706 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -793,12 +793,12 @@ class remote_target : public process_stratum_target
 
   char *write_ptid (char *buf, const char *endbuf, ptid_t ptid);
 
-  int remote_unpack_thread_info_response (char *pkt, threadref *expectedref,
+  int remote_unpack_thread_info_response (const char *pkt, threadref *expectedref,
 					  gdb_ext_thread_info *info);
   int remote_get_threadinfo (threadref *threadid, int fieldset,
 			     gdb_ext_thread_info *info);
 
-  int parse_threadlist_response (char *pkt, int result_limit,
+  int parse_threadlist_response (const char *pkt, int result_limit,
 				 threadref *original_echo,
 				 threadref *resultlist,
 				 int *doneflag);
@@ -1017,7 +1017,7 @@ static CORE_ADDR remote_address_masked (CORE_ADDR);
 
 static void print_packet (const char *);
 
-static int stub_unpack_int (char *buff, int fieldlength);
+static int stub_unpack_int (const char *buff, int fieldlength);
 
 struct packet_config;
 
@@ -2999,19 +2999,19 @@ struct gdb_ext_thread_info
 
 #define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
 
-static char *unpack_nibble (char *buf, int *val);
+static const char *unpack_nibble (const char *buf, int *val);
 
-static char *unpack_byte (char *buf, int *value);
+static const char *unpack_byte (const char *buf, int *value);
 
 static char *pack_int (char *buf, int value);
 
-static char *unpack_int (char *buf, int *value);
+static const char *unpack_int (const char *buf, int *value);
 
-static char *unpack_string (char *src, char *dest, int length);
+static const char *unpack_string (const char *src, char *dest, int length);
 
 static char *pack_threadid (char *pkt, threadref *id);
 
-static char *unpack_threadid (char *inbuf, threadref *id);
+static const char *unpack_threadid (const char *inbuf, threadref *id);
 
 void int_to_threadref (threadref *id, int value);
 
@@ -3121,7 +3121,7 @@ stubhex (int ch)
 }
 
 static int
-stub_unpack_int (char *buff, int fieldlength)
+stub_unpack_int (const char *buff, int fieldlength)
 {
   int nibble;
   int retval = 0;
@@ -3137,15 +3137,15 @@ stub_unpack_int (char *buff, int fieldlength)
   return retval;
 }
 
-static char *
-unpack_nibble (char *buf, int *val)
+static const char *
+unpack_nibble (const char *buf, int *val)
 {
   *val = fromhex (*buf++);
   return buf;
 }
 
-static char *
-unpack_byte (char *buf, int *value)
+static const char *
+unpack_byte (const char *buf, int *value)
 {
   *value = stub_unpack_int (buf, 2);
   return buf + 2;
@@ -3161,8 +3161,8 @@ pack_int (char *buf, int value)
   return buf;
 }
 
-static char *
-unpack_int (char *buf, int *value)
+static const char *
+unpack_int (const char *buf, int *value)
 {
   *value = stub_unpack_int (buf, 8);
   return buf + 8;
@@ -3192,8 +3192,8 @@ pack_string (char *pkt, char *string)
 }
 #endif /* 0 (unused) */
 
-static char *
-unpack_string (char *src, char *dest, int length)
+static const char *
+unpack_string (const char *src, char *dest, int length)
 {
   while (length--)
     *dest++ = *src++;
@@ -3215,11 +3215,11 @@ pack_threadid (char *pkt, threadref *id)
 }
 
 
-static char *
-unpack_threadid (char *inbuf, threadref *id)
+static const char *
+unpack_threadid (const char *inbuf, threadref *id)
 {
   char *altref;
-  char *limit = inbuf + BUF_THREAD_ID_SIZE;
+  const char *limit = inbuf + BUF_THREAD_ID_SIZE;
   int x, y;
 
   altref = (char *) id;
@@ -3334,7 +3334,7 @@ pack_threadinfo_request (char *pkt, int mode, threadref *id)
 				   the process.  */
 
 int
-remote_target::remote_unpack_thread_info_response (char *pkt,
+remote_target::remote_unpack_thread_info_response (const char *pkt,
 						   threadref *expectedref,
 						   gdb_ext_thread_info *info)
 {
@@ -3342,7 +3342,7 @@ remote_target::remote_unpack_thread_info_response (char *pkt,
   int mask, length;
   int tag;
   threadref ref;
-  char *limit = pkt + rs->buf.size (); /* Plausible parsing limit.  */
+  const char *limit = pkt + rs->buf.size (); /* Plausible parsing limit.  */
   int retval = 1;
 
   /* info->threadid = 0; FIXME: implement zero_threadref.  */
@@ -3465,18 +3465,17 @@ pack_threadlist_request (char *pkt, int startflag, int threadcount,
 /* Encoding:   'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */
 
 int
-remote_target::parse_threadlist_response (char *pkt, int result_limit,
+remote_target::parse_threadlist_response (const char *pkt, int result_limit,
 					  threadref *original_echo,
 					  threadref *resultlist,
 					  int *doneflag)
 {
   struct remote_state *rs = get_remote_state ();
-  char *limit;
   int count, resultcount, done;
 
   resultcount = 0;
   /* Assume the 'q' and 'M chars have been stripped.  */
-  limit = pkt + (rs->buf.size () - BUF_THREAD_ID_SIZE);
+  const char *limit = pkt + (rs->buf.size () - BUF_THREAD_ID_SIZE);
   /* done parse past here */
   pkt = unpack_byte (pkt, &count);	/* count field */
   pkt = unpack_nibble (pkt, &done);
-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pushed 2/4] gdb: const-ify remote_target::add_current_inferior_and_thread parameter
  2021-01-18  5:46 [pushed 1/4] gdb: const-ify unpack_* functions in remote.c Simon Marchi
@ 2021-01-18  5:46 ` Simon Marchi
  2021-01-18  5:46 ` [pushed 3/4] gdb: move remote_target::start_remote variable to narrower scope Simon Marchi
  2021-01-18  5:46 ` [pushed 4/4] gdb: const-ify hostio methods parameter in remote.c Simon Marchi
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Marchi @ 2021-01-18  5:46 UTC (permalink / raw)
  To: gdb-patches

... and adjust callers / callees.

gdb/ChangeLog:

	* remote.c (class remote_target):
	<add_current_inferior_and_thread>: Constify parameter.
	(stop_reply_extract_thread): Likewise.
	(remote_target::get_current_thread): Likewise.
	(remote_target::add_current_inferior_and_thread): Likewise.

Change-Id: Ifdc6c263104b58852b532cfda81caf836437d29c
---
 gdb/ChangeLog |  8 ++++++++
 gdb/remote.c  | 10 +++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e1bf15666ceb..657e707b30ff 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2021-01-18  Simon Marchi  <simon.marchi@polymtl.ca>
+
+	* remote.c (class remote_target):
+	<add_current_inferior_and_thread>: Constify parameter.
+	(stop_reply_extract_thread): Likewise.
+	(remote_target::get_current_thread): Likewise.
+	(remote_target::add_current_inferior_and_thread): Likewise.
+
 2021-01-18  Simon Marchi  <simon.marchi@polymtl.ca>
 
 	* remote.c (class remote_target)
diff --git a/gdb/remote.c b/gdb/remote.c
index 1df05e6cc706..49181d387167 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -737,7 +737,7 @@ class remote_target : public process_stratum_target
   int remote_resume_with_vcont (ptid_t ptid, int step,
 				gdb_signal siggnal);
 
-  void add_current_inferior_and_thread (char *wait_status);
+  void add_current_inferior_and_thread (const char *wait_status);
 
   ptid_t wait_ns (ptid_t ptid, struct target_waitstatus *status,
 		  target_wait_flags options);
@@ -784,7 +784,7 @@ class remote_target : public process_stratum_target
 				 int try_open_exec);
 
   ptid_t remote_current_thread (ptid_t oldpid);
-  ptid_t get_current_thread (char *wait_status);
+  ptid_t get_current_thread (const char *wait_status);
 
   void set_thread (ptid_t ptid, int gen);
   void set_general_thread (ptid_t ptid);
@@ -4351,7 +4351,7 @@ remote_target::send_interrupt_sequence ()
    and extract the PTID.  Returns NULL_PTID if not found.  */
 
 static ptid_t
-stop_reply_extract_thread (char *stop_reply)
+stop_reply_extract_thread (const char *stop_reply)
 {
   if (stop_reply[0] == 'T' && strlen (stop_reply) > 3)
     {
@@ -4391,7 +4391,7 @@ stop_reply_extract_thread (char *stop_reply)
    method avoids a roundtrip.  */
 
 ptid_t
-remote_target::get_current_thread (char *wait_status)
+remote_target::get_current_thread (const char *wait_status)
 {
   ptid_t ptid = null_ptid;
 
@@ -4418,7 +4418,7 @@ remote_target::get_current_thread (char *wait_status)
    in in WAIT_STATUS, which may be NULL.  */
 
 void
-remote_target::add_current_inferior_and_thread (char *wait_status)
+remote_target::add_current_inferior_and_thread (const char *wait_status)
 {
   struct remote_state *rs = get_remote_state ();
   bool fake_pid_p = false;
-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pushed 3/4] gdb: move remote_target::start_remote variable to narrower scope
  2021-01-18  5:46 [pushed 1/4] gdb: const-ify unpack_* functions in remote.c Simon Marchi
  2021-01-18  5:46 ` [pushed 2/4] gdb: const-ify remote_target::add_current_inferior_and_thread parameter Simon Marchi
@ 2021-01-18  5:46 ` Simon Marchi
  2021-01-18  5:46 ` [pushed 4/4] gdb: const-ify hostio methods parameter in remote.c Simon Marchi
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Marchi @ 2021-01-18  5:46 UTC (permalink / raw)
  To: gdb-patches

The wait_status variable is only used when the target is in in all-stop
mode.  We can therefore move it in the !target_is_non_stop scope.  That
lets us remove the assert in the else, that checks that the wait status
is not set.  If the variable doesn't exist in that scope, it pretty much
guarantees that it is not set.

gdb/ChangeLog:

	* remote.c (remote_target::start_remote): Move wait_status to
	narrower scope.

Change-Id: I30979135e3f4f36d04178baa67575c4e58d3b648
---
 gdb/ChangeLog | 5 +++++
 gdb/remote.c  | 7 ++-----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 657e707b30ff..a7c8b7793833 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2021-01-18  Simon Marchi  <simon.marchi@polymtl.ca>
+
+	* remote.c (remote_target::start_remote): Move wait_status to
+	narrower scope.
+
 2021-01-18  Simon Marchi  <simon.marchi@polymtl.ca>
 
 	* remote.c (class remote_target):
diff --git a/gdb/remote.c b/gdb/remote.c
index 49181d387167..17b0cab35c61 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4636,7 +4636,6 @@ remote_target::start_remote (int from_tty, int extended_p)
 {
   struct remote_state *rs = get_remote_state ();
   struct packet_config *noack_config;
-  char *wait_status = NULL;
 
   /* Signal other parts that we're going through the initial setup,
      and so things may not be stable yet.  E.g., we don't try to
@@ -4776,6 +4775,8 @@ remote_target::start_remote (int from_tty, int extended_p)
 
   if (!target_is_non_stop_p ())
     {
+      char *wait_status = NULL;
+
       if (rs->buf[0] == 'W' || rs->buf[0] == 'X')
 	{
 	  if (!extended_p)
@@ -4903,10 +4904,6 @@ remote_target::start_remote (int from_tty, int extended_p)
 	  return;
 	}
 
-      /* In non-stop mode, any cached wait status will be stored in
-	 the stop reply queue.  */
-      gdb_assert (wait_status == NULL);
-
       /* Report all signals during attach/startup.  */
       pass_signals ({});
 
-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pushed 4/4] gdb: const-ify hostio methods parameter in remote.c
  2021-01-18  5:46 [pushed 1/4] gdb: const-ify unpack_* functions in remote.c Simon Marchi
  2021-01-18  5:46 ` [pushed 2/4] gdb: const-ify remote_target::add_current_inferior_and_thread parameter Simon Marchi
  2021-01-18  5:46 ` [pushed 3/4] gdb: move remote_target::start_remote variable to narrower scope Simon Marchi
@ 2021-01-18  5:46 ` Simon Marchi
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Marchi @ 2021-01-18  5:46 UTC (permalink / raw)
  To: gdb-patches

gdb/ChangeLog:

	* remote.c (class remote_target) <remote_hostio_send_command,
	remote_hostio_parse_result>: Constify parameter.
	(remote_hostio_parse_result): Likewise.
	(remote_target::remote_hostio_send_command): Adjust.
	(remote_target::remote_hostio_pread_vFile): Adjust.
	(remote_target::fileio_readlink): Adjust.
	(remote_target::fileio_fstat): Adjust.

Change-Id: I6b585b99937e6526a0a7e06261d2193114589912
---
 gdb/ChangeLog | 10 ++++++++++
 gdb/remote.c  | 16 ++++++++--------
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a7c8b7793833..ac13b3d010d5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2021-01-18  Simon Marchi  <simon.marchi@polymtl.ca>
+
+	* remote.c (class remote_target) <remote_hostio_send_command,
+	remote_hostio_parse_result>: Constify parameter.
+	(remote_hostio_parse_result): Likewise.
+	(remote_target::remote_hostio_send_command): Adjust.
+	(remote_target::remote_hostio_pread_vFile): Adjust.
+	(remote_target::fileio_readlink): Adjust.
+	(remote_target::fileio_fstat): Adjust.
+
 2021-01-18  Simon Marchi  <simon.marchi@polymtl.ca>
 
 	* remote.c (remote_target::start_remote): Move wait_status to
diff --git a/gdb/remote.c b/gdb/remote.c
index 17b0cab35c61..b4c6fc21083b 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -705,7 +705,7 @@ class remote_target : public process_stratum_target
 				 ULONGEST offset, int *remote_errno);
 
   int remote_hostio_send_command (int command_bytes, int which_packet,
-				  int *remote_errno, char **attachment,
+				  int *remote_errno, const char **attachment,
 				  int *attachment_len);
   int remote_hostio_set_filesystem (struct inferior *inf,
 				    int *remote_errno);
@@ -11969,8 +11969,8 @@ remote_buffer_add_int (char **buffer, int *left, ULONGEST value)
    -1 is returned, the other variables may not be initialized.  */
 
 static int
-remote_hostio_parse_result (char *buffer, int *retcode,
-			    int *remote_errno, char **attachment)
+remote_hostio_parse_result (const char *buffer, int *retcode,
+			    int *remote_errno, const char **attachment)
 {
   char *p, *p2;
 
@@ -12026,12 +12026,12 @@ remote_hostio_parse_result (char *buffer, int *retcode,
 
 int
 remote_target::remote_hostio_send_command (int command_bytes, int which_packet,
-					   int *remote_errno, char **attachment,
+					   int *remote_errno, const char **attachment,
 					   int *attachment_len)
 {
   struct remote_state *rs = get_remote_state ();
   int ret, bytes_read;
-  char *attachment_tmp;
+  const char *attachment_tmp;
 
   if (packet_support (which_packet) == PACKET_DISABLE)
     {
@@ -12242,7 +12242,7 @@ remote_target::remote_hostio_pread_vFile (int fd, gdb_byte *read_buf, int len,
 {
   struct remote_state *rs = get_remote_state ();
   char *p = rs->buf.data ();
-  char *attachment;
+  const char *attachment;
   int left = get_remote_packet_size ();
   int ret, attachment_len;
   int read_len;
@@ -12406,7 +12406,7 @@ remote_target::fileio_readlink (struct inferior *inf, const char *filename,
 {
   struct remote_state *rs = get_remote_state ();
   char *p = rs->buf.data ();
-  char *attachment;
+  const char *attachment;
   int left = get_remote_packet_size ();
   int len, attachment_len;
   int read_len;
@@ -12445,7 +12445,7 @@ remote_target::fileio_fstat (int fd, struct stat *st, int *remote_errno)
   char *p = rs->buf.data ();
   int left = get_remote_packet_size ();
   int attachment_len, ret;
-  char *attachment;
+  const char *attachment;
   struct fio_stat fst;
   int read_len;
 
-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-18  5:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-18  5:46 [pushed 1/4] gdb: const-ify unpack_* functions in remote.c Simon Marchi
2021-01-18  5:46 ` [pushed 2/4] gdb: const-ify remote_target::add_current_inferior_and_thread parameter Simon Marchi
2021-01-18  5:46 ` [pushed 3/4] gdb: move remote_target::start_remote variable to narrower scope Simon Marchi
2021-01-18  5:46 ` [pushed 4/4] gdb: const-ify hostio methods parameter in remote.c Simon Marchi

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 read-only IMAP folder(s) and NNTP newsgroup(s).