You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/12/11 16:43:35 UTC

(nuttx) 02/04: gdbstub:convert gdb pid strat to 1

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit a423d9b4046ed7c54bec6ff037c46f055191174e
Author: anjiahao <an...@xiaomi.com>
AuthorDate: Mon Nov 13 18:16:31 2023 +0800

    gdbstub:convert gdb pid strat to 1
    
    gdb pid strat is 1, nuttx is 0, so convert it
    
    Signed-off-by: anjiahao <an...@xiaomi.com>
---
 libs/libc/gdbstub/lib_gdbstub.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/libs/libc/gdbstub/lib_gdbstub.c b/libs/libc/gdbstub/lib_gdbstub.c
index 286e5ac244..1fe0e80771 100644
--- a/libs/libc/gdbstub/lib_gdbstub.c
+++ b/libs/libc/gdbstub/lib_gdbstub.c
@@ -860,7 +860,7 @@ static void gdb_get_registers(FAR struct gdb_state_s *state)
   int i;
 
   reg = (FAR uint8_t *)tcb->xcp.regs;
-  if (state->pid == _SCHED_GETPID())
+  if (state->pid == _SCHED_GETTID())
     {
       if (up_interrupt_context())
         {
@@ -1148,10 +1148,10 @@ static void gdb_get_thread(FAR struct tcb_s *tcb, FAR void *arg)
 {
   FAR struct gdb_state_s *state = arg;
   int pid = tcb->pid;
-  size_t len;
 
-  len = sprintf(&state->pkt_buf[state->pkt_len], "%x,", pid);
-  state->pkt_len += len;
+  /* Gdb pid start from 1, so add it */
+
+  state->pkt_len += sprintf(&state->pkt_buf[state->pkt_len], "%x,", pid + 1);
 }
 
 /****************************************************************************
@@ -1211,7 +1211,7 @@ static int gdb_query(FAR struct gdb_state_s *state)
           return ret;
         }
 
-      tcb = nxsched_get_tcb(pid);
+      tcb = nxsched_get_tcb(pid - 1);
       if (tcb == NULL)
         {
           return -EINVAL;
@@ -1300,13 +1300,13 @@ static int gdb_is_thread_active(FAR struct gdb_state_s *state)
       return ret;
     }
 
-  tcb = nxsched_get_tcb(pid);
+  tcb = nxsched_get_tcb(pid - 1);
   if (tcb == NULL)
     {
       return -EINVAL;
     }
 
-  state->pid = pid;
+  state->pid = pid - 1;
   gdb_send_ok_packet(state);
   return ret;
 }
@@ -1342,13 +1342,17 @@ static int gdb_thread_context(FAR struct gdb_state_s *state)
       return ret;
     }
 
-  tcb = nxsched_get_tcb(pid);
-  if (tcb == NULL)
+  if (pid != 0)
     {
-      return -EINVAL;
+      tcb = nxsched_get_tcb(pid - 1);
+      if (tcb == NULL)
+        {
+          return -EINVAL;
+        }
+
+      state->pid = pid - 1;
     }
 
-  state->pid = pid;
   gdb_send_ok_packet(state);
   return 0;
 }