diff --git a/gdb/NEWS b/gdb/NEWS
index b0f5447..00c14ad 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -186,6 +186,11 @@
   TYPE_REGEXP matches against the variable type, and REGEXP matches
   against the variable name.
 
+set debug remote-log-length
+show debug remote-log-length
+  Controls the amount of characters to output when using "set debug remote".
+  The default is 512 bytes.
+
 * Changed commands
 
 help
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index c66a39c..4713b29 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -26274,6 +26274,19 @@
 @item show debug remote
 Displays the state of display of remote packets.
 
+@item set debug remote-log-length
+Sets the number of characters to display for each remote packet when
+@code{set debug remote} is on. This is useful to prevent @value{GDBN} from
+displaying lengthy remote packets and polluting the console.
+
+The default value is @code{512}, which means @value{GDBN} will truncate each
+remote packet after 512 bytes.
+
+Setting this option to @code{unlimited} will disable truncation and will output
+the full length of the remote packets.
+@item show debug remote-log-length
+Displays the number of bytes to output for remote packet debugging.
+
 @item set debug separate-debug-file
 Turns on or off display of debug output about separate debug file search.
 @item show debug separate-debug-file
diff --git a/gdb/remote.c b/gdb/remote.c
index 1ac9013..97fdd54 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1044,8 +1044,6 @@
 /* The max number of chars in debug output.  The rest of chars are
    omitted.  */
 
-#define REMOTE_DEBUG_MAX_CHAR 512
-
 /* Private data that we'll store in (struct thread_info)->priv.  */
 struct remote_thread_info : public private_thread_info
 {
@@ -1712,6 +1710,20 @@
 			    "breakpoints is %s.\n"), value);
 }
 
+static int debug_remote_log_length = 512;
+
+/* Show the maximum number of characters to display for a remote packet when
+   remote debugging is enabled.  */
+
+static void
+show_debug_remote_log_length (struct ui_file *file, int from_tty,
+			      struct cmd_list_element *c,
+			      const char *value)
+{
+  fprintf_filtered (file, _("Remote packet output will be truncated at %s "
+			    "characters.\n"), value);
+}
+
 long
 remote_target::get_memory_write_packet_size ()
 {
@@ -9119,15 +9131,21 @@
 	  *p = '\0';
 
 	  int len = (int) (p - buf2);
+	  int max_chars;
+
+	  if (debug_remote_log_length < 0)
+	    max_chars = len;
+	  else
+	    max_chars = debug_remote_log_length;
 
 	  std::string str
-	    = escape_buffer (buf2, std::min (len, REMOTE_DEBUG_MAX_CHAR));
+	    = escape_buffer (buf2, std::min (len, max_chars));
 
 	  fprintf_unfiltered (gdb_stdlog, "Sending packet: %s", str.c_str ());
 
-	  if (len > REMOTE_DEBUG_MAX_CHAR)
+	  if (len > max_chars)
 	    fprintf_unfiltered (gdb_stdlog, "[%d bytes omitted]",
-				len - REMOTE_DEBUG_MAX_CHAR);
+				len - max_chars);
 
 	  fprintf_unfiltered (gdb_stdlog, "...");
 
@@ -9563,16 +9581,23 @@
 	{
 	  if (remote_debug)
 	    {
+	      int max_chars;
+
+	      if (debug_remote_log_length < 0)
+		max_chars = val;
+	      else
+		max_chars = debug_remote_log_length;
+
 	      std::string str
 		= escape_buffer (buf->data (),
-				 std::min (val, REMOTE_DEBUG_MAX_CHAR));
+				 std::min (val, max_chars));
 
 	      fprintf_unfiltered (gdb_stdlog, "Packet received: %s",
 				  str.c_str ());
 
-	      if (val > REMOTE_DEBUG_MAX_CHAR)
+	      if (val > max_chars)
 		fprintf_unfiltered (gdb_stdlog, "[%d bytes omitted]",
-				    val - REMOTE_DEBUG_MAX_CHAR);
+				    val - max_chars);
 
 	      fprintf_unfiltered (gdb_stdlog, "\n");
 	    }
@@ -14723,6 +14748,14 @@
 			    show_watchdog,
 			    &setlist, &showlist);
 
+  add_setshow_zuinteger_unlimited_cmd ("remote-log-length", no_class,
+				       &debug_remote_log_length, _("\
+Set the maximum number of characters to display for remote packet debugging."), _("\
+Show the maximum number of characters to display for remote packet debugging."), _("\
+Specify \"unlimited\" to display all the characters."),
+				       NULL, show_debug_remote_log_length,
+				       &setdebuglist, &showdebuglist);
+
   /* Eventually initialize fileio.  See fileio.c */
   initialize_remote_fileio (remote_set_cmdlist, remote_show_cmdlist);
 }
