anchao commented on code in PR #15623:
URL: https://github.com/apache/nuttx/pull/15623#discussion_r1923112060


##########
libs/libc/gdbstub/lib_gdbstub.c:
##########
@@ -283,9 +287,43 @@ static int gdb_putchar(FAR struct gdb_state_s *state, int 
ch)
       return ret;
     }
 
+  if (csum)
+    {
+      *csum += tmp;
+    }
+
   return tmp;
 }
 
+/****************************************************************************
+ * Name: gdb_escapechar
+ *
+ * Description:
+ *   Send out a char, do escaping if necessary.
+ *   Do note that for RLE encoded data, the length byte should NOT escape.
+ *   See gdb src of remote.c remote_target::read_frame
+ *
+ * Input Parameters:
+ *   state   - The pointer to the GDB state structure.
+ *   ch      - The character to be sent.
+ *   csum    - The checksum.
+ *
+ ****************************************************************************/
+
+static void gdb_escapechar(FAR struct gdb_state_s *state, char c,
+                           FAR char *csum)
+{
+  if (c == '#' || c == '$' || c == '}' || c == '*')
+    {
+      gdb_putchar(state, '}', csum);
+      gdb_putchar(state, c ^ 0x20, csum); /* See 
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Overview.html#Binary-Data
 */

Review Comment:
   ```suggestion
         /* See 
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Overview.html#Binary-Data
 */
         
         gdb_putchar(state, c ^ 0x20, csum); 
   ```



##########
libs/libc/gdbstub/lib_gdbstub.c:
##########
@@ -347,43 +387,83 @@ static int gdb_send_packet(FAR struct gdb_state_s *state)
     {
       size_t p;
       GDB_DEBUG(state, "-> ");
-      for (p = 0; p < state->pkt_len; p++)
+      for (p = 0; p < len; p++)
         {
-          if (isprint(state->pkt_buf[p]))
+          if (isprint(buf[p]))
             {
-              GDB_DEBUG(state, "%c", state->pkt_buf[p]);
+              GDB_DEBUG(state, "%c", buf[p]);
             }
           else
             {
-              GDB_DEBUG(state, "\\x%02x", state->pkt_buf[p] & 0xff);
+              GDB_DEBUG(state, "\\x%02x", buf[p] & 0xff);
             }
         }
 
       GDB_DEBUG(state, "\n");
     }
 #endif
 
-  state->pkt_len = gdb_encode_rle(state->pkt_buf, state->pkt_len);
+  while (i < len)
+    {
+      const char c = buf[i];
+      size_t count = gdb_count_repeat(&buf[i], len - i);
 
-  /* Send packet data */
+      i += count;
 
-  ret = state->send(state->priv, state->pkt_buf, state->pkt_len);
-  if (ret < 0)
-    {
-      return ret;
-    }
+      /* GDB cannot process repeated special characters. */
+
+      if (c == '*' || c == '}' || c == '#' || c == '$')

Review Comment:
   ditto



##########
libs/libc/gdbstub/lib_gdbstub.c:
##########
@@ -55,12 +55,8 @@
 
 #define BUFSIZE CONFIG_LIB_GDBSTUB_PKTSIZE
 
-#ifdef CONFIG_BOARD_MEMORY_RANGE
-static const struct memory_region_s g_memory_region[] =
-  {
-    CONFIG_BOARD_MEMORY_RANGE
-  };
-#endif
+#define REPBIAS 29

Review Comment:
   What is REPBIAS?



##########
libs/libc/gdbstub/lib_gdbstub.c:
##########
@@ -283,9 +287,43 @@ static int gdb_putchar(FAR struct gdb_state_s *state, int 
ch)
       return ret;
     }
 
+  if (csum)
+    {
+      *csum += tmp;
+    }
+
   return tmp;
 }
 
+/****************************************************************************
+ * Name: gdb_escapechar
+ *
+ * Description:
+ *   Send out a char, do escaping if necessary.
+ *   Do note that for RLE encoded data, the length byte should NOT escape.
+ *   See gdb src of remote.c remote_target::read_frame
+ *
+ * Input Parameters:
+ *   state   - The pointer to the GDB state structure.
+ *   ch      - The character to be sent.
+ *   csum    - The checksum.
+ *
+ ****************************************************************************/
+
+static void gdb_escapechar(FAR struct gdb_state_s *state, char c,
+                           FAR char *csum)
+{
+  if (c == '#' || c == '$' || c == '}' || c == '*')

Review Comment:
   define special characters to macro, eg:
   #define IS_SPECIAL_CHARACTERS(c) (...)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to