Author: cem
Date: Wed Sep 30 14:55:54 2020
New Revision: 366291
URL: https://svnweb.freebsd.org/changeset/base/366291

Log:
  gdb(4): Don't escape GDB special characters at application layer
  
  In r351368, we introduced this XML- and GDB-encoded data.  The protocol
  'offset' should reflex the logical XML data offset, but unfortunately we
  counted the GDB escapes as well.
  
  In fact, we cannot safely do GDB character escaping at this layer at
  all, because we don't know what will be flushed in a packet.  It is
  bogus to send only the first character of a two-character escape
  sequence.
  
  This patch "corrects" the problem by squashing these characters in the
  transmitted XML document.  It would be nice to transmit the characters
  faithfully, but that is a more complicated change.  Thread names are a
  nice convenience feature for the GDB client, but one can always inspect
  td_name or p_comm directly to find the true name.
  
  Reported by:  Ka Ho Ng <khng300 AT gmail.com>
  Tested by:    Ka Ho Ng
  Reviewed by:  emaste, markj, rlibby
  Differential Revision:        https://reviews.freebsd.org/D26599

Modified:
  head/sys/gdb/gdb_main.c

Modified: head/sys/gdb/gdb_main.c
==============================================================================
--- head/sys/gdb/gdb_main.c     Wed Sep 30 13:33:28 2020        (r366290)
+++ head/sys/gdb/gdb_main.c     Wed Sep 30 14:55:54 2020        (r366291)
@@ -361,9 +361,7 @@ init_qXfer_ctx(struct qXfer_context *qx, uintmax_t len
 }
 
 /*
- * dst must be 2x strlen(max_src) + 1.
- *
- * Squashes invalid XML characters down to _.  Sorry.  Then escapes for GDB.
+ * Squashes special XML and GDB characters down to _.  Sorry.
  */
 static void
 qXfer_escape_xmlattr_str(char *dst, size_t dstlen, const char *src)
@@ -384,8 +382,18 @@ qXfer_escape_xmlattr_str(char *dst, size_t dstlen, con
 
                /* GDB escape. */
                if (strchr(forbidden, c) != NULL) {
+                       /*
+                        * It would be nice to escape these properly, but to do
+                        * it correctly we need to escape them in the transmit
+                        * layer, potentially doubling our buffer requirements.
+                        * For now, avoid breaking the protocol by squashing
+                        * them to underscore.
+                        */
+#if 0
                        *dst++ = '}';
                        c ^= 0x20;
+#endif
+                       c = '_';
                }
                *dst++ = c;
        }
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to