#3766 new enhancement

potential patch to libbsp/shared/gdbstub/rtems-stub-glue.c for gdb NONSTOP mode

Reported by: Jeffrey Hill Owned by:
Priority: normal Milestone:
Component: bsps Version:
Severity: minor Keywords:
Cc: Blocked By:
Blocking:

Description

FWIW, I am reviewing this change I made to the shared gdb stub, and perhaps it can be considered to be a good idea if supporting newer gdb modes where the threads are not all of them stopped when gdb is looking at the system.

This is against a pre-release RTEMS 4.11 in function rtems_gdb_stub_get_thread_regs

diff --git a/c/src/lib/libbsp/shared/gdbstub/rtems-stub-glue.c b/c/src/lib/libbsp/shared/gdbstub/rtems-stub-glue.c
index 06dfc8a..98fd509 100644
--- a/c/src/lib/libbsp/shared/gdbstub/rtems-stub-glue.c
+++ b/c/src/lib/libbsp/shared/gdbstub/rtems-stub-glue.c
@@ -278,16 +278,21 @@ int rtems_gdb_stub_get_thread_regs(
   unsigned int *registers
 )
 {
-   Thread_Control *th;
-
-   th= rtems_gdb_index_to_stub_id(thread);
-
-   if( th )
-   {
-      rtems_gdb_stub_get_registers_from_context( registers, th );
-      return 1;
-   }
-   return 0;
+  bool success = false;
+  Thread_Control * const pThrUnlocked = rtems_gdb_index_to_stub_id ( thread );
+  if ( pThrUnlocked ) {
+    Objects_Locations loc;
+    Thread_Control * const pThr =
+                            _Thread_Get ( pThrUnlocked->Object.id, &loc );
+    if( pThr && loc == OBJECTS_LOCAL ) {
+      if ( pThr != _Thread_Executing ) {
+        rtems_gdb_stub_get_registers_from_context( registers, pThr );
+        success = true;
+      }
+      _Thread_Enable_dispatch ();
+    }
+  }
+  return success;
 }

 /* Set thread registers, return 0 if thread does not

Change History (2)

comment:1 Changed on 07/12/19 at 15:38:17 by Jeffrey Hill

Admittedly, some kind of synchronization is probably strictly required also within rtems_gdb_index_to_stub_id if GDB isn't breaking in via some kind of trap instruction.

To put this in context, I made the above change when working on a TCP thread-aware gdb stub which typically runs in all-stop mode (all threads are stopped except the networking threads), but I have also experimented some with non-stop mode.

There is admittedly much more work to do to support non-stop mode.

comment:2 in reply to:  1 Changed on 07/12/19 at 20:34:35 by Chris Johns

Replying to Jeffrey Hill:

To put this in context, I made the above change when working on a TCP thread-aware gdb stub which typically runs in all-stop mode (all threads are stopped except the networking threads),

Have you looked at libdebugger, it does all this? It would be great if you could help effort.

but I have also experimented some with non-stop mode.

There is admittedly much more work to do to support non-stop mode.

Non-stop is possible but it is more complex.

Note: See TracTickets for help on using tickets.