maxikrie opened a new pull request, #21023:
URL: https://github.com/apache/nuttx/pull/21023

   ## Summary
   
   `struct tcbinfo_s` is packed, so `g_tcbinfo` (const, placed in `.text`
   on Cortex-M boards) can end up at an odd address, depending on what
   else is linked. GDB reports such an address with bit 0 cleared, as if
   it were Thumb code, and passes that to the J-Link GDB server when the
   RTOS plugin asks for the symbol. `tools/jlink-nuttx.c` then reads every
   offset one byte off.
   
   nrf52840-dk, master b9d1d6a834, `nsh` + `DEBUG_SYMBOLS`, `FS_PROCFS`
   with tcbinfo, `EXAMPLES_HELLO` (CMake):
   
   ```
   $ readelf -s nuttx | grep g_tcbinfo
     2309: 0001987b    24 OBJECT  GLOBAL DEFAULT    1 g_tcbinfo
   (gdb) p &g_tcbinfo
   $1 = (const struct tcbinfo_s *) 0x1987a <g_tcbinfo>
   (gdb) x/8hx 0x1987a      <- what GDB and the plugin read
   0x1987a: 0x3000 0x4000 0x3400 0x0000 0x7000 0x6800 0xb000 0x1100
   (gdb) x/8hx 0x1987b      <- the real g_tcbinfo
   0x1987b: 0x0030 0x0040 0x0034 0x0000 0x0070 0x0068 0x00b0 0x0011
   ```
   
   J-Link GDB server log: `Received symbol: g_tcbinfo (0x0001987A)`.
   `info threads` shows the idle task with state 0 and priority 165, and
   no `nsh_main` thread.
   
   The fix aligns the type (`aligned_data(8)`, the way `bl602_dma.h` does
   for a packed struct). All members are naturally aligned, so the layout
   is unchanged (`ptype/o struct tcbinfo_s`: 24 bytes, same offsets),
   and the J-Link plugin and the Python tools need no change.
   
   This is likely what apache/nuttx#18109 is about: the plugin works or
   not depending on where the linker puts `g_tcbinfo` (at an even
   0x0802e940 in the stm32f429i-disco build used to try to reproduce it).
   
   ## Impact
   
   Debuggers reading `g_tcbinfo` through GDB (J-Link RTOS plugin, nxgdb)
   on Thumb targets. Up to 7 bytes of padding before `g_tcbinfo`; no
   change to the structure's contents.
   
   ## Testing
   
   nRF52840-DK, J-Link V9.82 GDB server with `tools/jlink-nuttx`,
   gdb-multiarch 13.1:
   
   | | master (g_tcbinfo at 0x1987b) | this PR (at 0x19880) |
   |---|---|---|
   | attach, `info threads` | Idle `[PRI:165]`, no nsh_main | Idle `[PRI:000]`, 
nsh_main `[PRI:100]` |
   | `thread 3`, `bt` | — | nsh_main in `nxsem_wait_slow()` on the console |
   | break in `hello_main`, run `hello`, break in `up_idle` after it exits | — 
| hello thread listed and selected at its breakpoint; after it exits GDB goes 
on with the remaining threads |
   
   `tools/checkpatch.sh -f include/nuttx/sched.h` passes; `sim:nsh` builds.
   
   Fixes #18109 (probably; the reporter's board not tested).


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to