31 Commits

Author SHA1 Message Date
guoshengyuan1 2dae11461d nxgdb: change the symbol g_statenames to nxsched_get_stateinfo::g_statenames
I0680e48d8ff8847c8712e1a54efe32d320e7c84d changes the scope of the symbol definition.
So nxgdb needs to synchronize this modification.

Signed-off-by: guoshengyuan1 <guoshengyuan1@xiaomi.com>
2026-03-02 08:06:18 -03:00
Lars Kruse 2cca9a2bdf pynuttx: update
Commit 6ed4ea63d renamed the function `mm_initialize` to
`mm_initialize_heap`.

This caused the pynuttx modules (e.g. `mm dump`) to be missing.

Signed-off-by: Lars Kruse <devel@sumpfralle.de>
2026-03-02 10:25:21 +08:00
hujun5 5051721298 sched/pthread: move pthread mutex from syscall to user-space
Move pthread mutex operations from kernel-space syscall
interface to user-space implementations
to reduce syscall overhead. Relocate mutex holder list
tracking from task control block (tcb) to
thread local storage (tls) to improve memory layout and
cache efficiency. Add helper macros for
conditional mutex implementations and update syscall
interface accordingly.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-22 12:40:49 -03:00
hujun5 a50737a75f tools/pynuttx/nxgdb: fix semaphore field access in debugging scripts
Fix incorrect direct access to semcount field by using val intermediate
field in memory pool and network stats debugging scripts. This corrects
the data structure navigation to match actual kernel semaphore layout.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-21 20:05:18 +08:00
anjiahao 0e92053bd9 pynuttx:remove pthread_tcb_s cast
Just remove cast

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2025-12-22 17:55:45 +08:00
dependabot[bot] dd5f562b58 build(deps): bump fonttools from 4.54.1 to 4.60.2 in /tools/pynuttx
Bumps [fonttools](https://github.com/fonttools/fonttools) from 4.54.1 to 4.60.2.
- [Release notes](https://github.com/fonttools/fonttools/releases)
- [Changelog](https://github.com/fonttools/fonttools/blob/main/NEWS.rst)
- [Commits](https://github.com/fonttools/fonttools/compare/4.54.1...4.60.2)

---
updated-dependencies:
- dependency-name: fonttools
  dependency-version: 4.60.2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-10 22:43:44 +08:00
wangchengdong d8304979b4 tools/nxgdb: Add gdb and statenames for TSTATE_WAIT_EVENT
This patch add new taskstate entry in tools/pynuttx/nxgdb/thread.py
   and in sched_get_stateinfo.c/g_statenames for the new added task
   state: TSTATE_WAIT_EVENT

   test log is:
     nsh> ps
       PID  PPID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK    USED FILLED COMMAND
         0     0     0   0 FIFO     Kthread   - Ready              0000000000000000 0001008 0000196  19.4%  Idle_Task
         1     0     0 192 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0001984 0000016   0.8%  hpwork 0x70000100 0x7000014c
         2     0     2 100 FIFO     Task      - Running            0000000000000000 0002008 0000740  36.8%  nsh_main
         4     0     0 100 FIFO     Kthread   - Waiting  Event     0000000000000000 0000984 0000012   1.2%  event_wait_task

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-10-31 19:56:32 -03:00
Karel Kočí 29d44e5227 nxgdb: fix remote-register regular expression match
The code clearly expects the output of the 'maint print
remote-registers' to be indented by white-space character but at least
in my case it is not. This changes the match to consume any number of
white-space characters before it encounteres the register name.

Signed-off-by: Karel Kočí <cynerd@email.cz>
2025-10-16 12:48:31 +08:00
xuxingliang 28b2e01c22 nxgdb: fix style issue
Fix style issue reported after upgrading flake8 to 7.2.0

1 file would be left unchanged.
/home/nuttx/tools/pynuttx/nxgdb/utils.py:237:5: F824  is unused: name is never assigned in scope
    global g_type_cache
    ^
/home/nuttx/tools/pynuttx/nxgdb/utils.py:294:5: F824  is unused: name is never assigned in scope
    global long_type
    ^

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-06-13 20:37:04 +08:00
chenzhijia 341292064d nxgdb/utils.py: Fix source gdbinit.py script error report
Registering NuttX GDB commands from /home/mi/code/stable_oh2/nuttx/tools/pynuttx/nxgdb
set pagination off
set python print-stack full
"handle SIGUSR1 "nostop" "pass" "noprint"
Load macro: /tmp/6024dea73606400ae39a7b7da42cecbf.json
Please pip install debugpyIgnore module: elf, error: 'NoneType' object has no attribute 'code'
Traceback (most recent call last):
  File "/home/mi/code/stable_oh2/nuttx/tools/pynuttx/nxgdb/_init_.py", line 54, in init_gdb_commands
    module = importlib.import_module(f"{_package_}.{m}")
  File "/usr/lib/python3.10/importlib/_init_.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/mi/code/stable_oh2/nuttx/tools/pynuttx/nxgdb/elf.py", line 35, in <module>
    CONFIG_ARCH_USE_SEPARATED_SECTION = has_field("struct module_s", "sectalloc")
  File "/home/mi/code/stable_oh2/nuttx/tools/pynuttx/nxgdb/utils.py", line 488, in has_field
    return get_type_field(obj, field) is not None
  File "/home/mi/code/stable_oh2/nuttx/tools/pynuttx/nxgdb/utils.py", line 267, in get_type_field
    while t.code in (gdb.TYPE_CODE_PTR, gdb.TYPE_CODE_ARRAY, gdb.TYPE_CODE_TYPEDEF):
AttributeError: 'NoneType' object has no attribute 'code'
No symbol g_version found in memory, skipping version check

Signed-off-by: chenzhijia <chenzhijia@xiaomi.com>
2025-06-13 20:37:04 +08:00
xuxingliang 00304a18ed nxgdb/fs: fix exception when failed to parse symbol
Parse struct fields to determine array length.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-06-13 20:37:04 +08:00
dongjiuzhu1 7927c8d105 tools/pynuttx: update fs.py base on new structure fd and file
Update the Python script based on the PR "Separate file
descriptors from file descriptions" in fs/vfs.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
dongjiuzhu1 9ca5c1d9c6 fs/file: unify prefix f_ for member locked
update locked to f_locked

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
Lars Kruse e5b675d4dc refactor: fix spelling in private field names
Fix some misspelled field names.
These field names seem to be used only in private contexts.
Thus, the probability of external code accessing these fields is very
low.
In the rare case of external usage, compile time errors will easily
direct users to the new field name.
2025-05-24 09:44:22 -03:00
Lars Kruse 3ce85ca54e style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
Lars Kruse 4568110d63 fix misspelled names in locally scoped code
These misspelled words are used in strictly local scopes.
Renaming these variables should not cause any problems.
2025-05-15 10:12:12 +08:00
yangao1 ded5a6aae5 nxgdb/dmesg.py:add use gdb dump rpmsg_syslog
(gdb) dmesg
RAM log:
[01/06 02:27:05] [ 1] [cp] reset mode:1
...
[01/06 02:27:05] [ 1] [cp] Dump board_reset backtrace:
[01/06 02:27:05] [ 1] [cp] sched_dumpstack: backtrace| 1: 0x10a0d880 0x10a0a78e 0x10a0d8b6 0x10a0f29e 0x10a0f182
[01/06 02:27:05] [ 1] [cp] Time: Mon Jan  6 02:27:05 2025
---END of RAMLOG

RPMSG syslog:
dumpstack: backtrace|10: 0x10a0d880 0x10a0a78e 0x10a110de 0x10a3a482 0x10a3c4fa 0x10a23358 0x10a4aaee 0x10a34a7c
[01/06 02:27:05] [ 1] [cp] sched_dumpstack: backtrace|10: 0x10a2330a 0x10a0f1f4
[01/06 02:27:05] [ 1] [cp] sched_dumpstack: backtrace|11: 0x10a0d880 0x10a0a78e 0x10a110de 0x10a3a482 0x10a15152 0x10a0f182
[01/06 02:27:05] [ 1] [cp] sched_dumpstack: backtrace|15: 0x10a0d880 0x10a0a78e 0x10a0d8b6 0x10a174d0 0x10a3a482 0x10a3c4fa 0x10a222ee 0x10a18c66
[01/06 02:27:05] [ 1] [cp] Time: Mon Jan  6 02:27:05 2025
---END of RPMSG SYSLOG---

Signed-off-by: yangao1 <yangao1@xiaomi.com>
2025-03-27 02:18:37 +08:00
xuxingliang 1bfb42d127 nxgdb/irq: add irqinfo command
(gdb) irqinfo
IRQ  COUNT      TIME   RATE   HANDLER                                          ARGUMENT
0    0          0      N/A    mps_reserved                             0x0 <sensor_unregister>
2    0          0      N/A    mps_nmi                                  0x0 <sensor_unregister>
3    0          0      N/A    arm_hardfault                            0x0 <sensor_unregister>
4    0          0      N/A    arm_memfault                             0x0 <sensor_unregister>
5    0          0      N/A    arm_busfault                             0x0 <sensor_unregister>
6    0          0      N/A    arm_usagefault                           0x0 <sensor_unregister>
11   1          0      N/A    arm_svcall                               0x0 <sensor_unregister>
12   0          0      N/A    arm_dbgmonitor                           0x0 <up_debugpoint_remove>
14   0          0      N/A    mps_pendsv                               0x0 <up_debugpoint_remove>
15   6581421    0      N/A    systick_interrupt                        0x100010c <g_systick_lower>
49   2          0      N/A    uart_cmsdk_tx_interrupt                  0x1000010 <g_uart0port>
50   0          0      N/A    uart_cmsdk_rx_interrupt                  0x1000010 <g_uart0port>
59   2          0      N/A    uart_cmsdk_ov_interrupt                  0x1000010 <g_uart0port>
(gdb)

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-02-18 11:16:17 -03:00
xuxingliang 06c7e2a02e nxgdb/utils: add has_field and fix ArrayIterator
1. Add method to check if an object has specified field.
2. Fix Array iterator that walrus expression should store result of the
   function, instead of the compare result.

Note that walrus operation has lowest priority except ','.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-02-18 11:16:17 -03:00
xuxingliang 1b94d0e2cf nxgdb/mm: show pool expand queue size
nqueue has been added to output.

E.g.
(gdb) mm pool
Total 16 pools
                      total blocksize     bsize  overhead     nused     nfree    nifree   nwaiter    nqueue
 Umem@0x10048dc        4068        16        16         0         3       251         0         0         1
 Umem@0x100493c        4068        32        32         0         3       124         0         0         1
 Umem@0x100499c        4036        48        48         0        10        74         0         0         1
 Umem@0x10049fc        4036        64        64         0         1        62         0         0         1
 Umem@0x1004a5c           0        80        80         0         0         0         0         0         0
 Umem@0x1004abc           0        96        96         0         0         0         0         0         0
 Umem@0x1004b1c           0       112       112         0         0         0         0         0         0
 Umem@0x1004b7c           0       128       128         0         0         0         0         0         0
 Umem@0x1004bdc           0       144       144         0         0         0         0         0         0
 Umem@0x1004c3c           0       160       160         0         0         0         0         0         0
 Umem@0x1004c9c           0       176       176         0         0         0         0         0         0
 Umem@0x1004cfc           0       192       192         0         0         0         0         0         0
 Umem@0x1004d5c        3956       208       208         0         1        18         0         0         1
 Umem@0x1004dbc           0       224       224         0         0         0         0         0         0
 Umem@0x1004e1c           0       240       240         0         0         0         0         0         0
 Umem@0x1004e7c           0       256       256         0         0         0         0         0         0
(gdb)

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-02-16 11:23:38 -03:00
xuxingliang c319863834 nxgdb/mm: fix regular expression to parse log
There could be only one space ahead of address.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-02-07 08:18:14 +08:00
xuxingliang 1577fe3160 nxgdb/mm: warning if corrupted memory node found
If the nodesize is 0, we cannot iterate to next node, siliently return None will cause memleak command to generate false positive report with no warnings.
Add log to indicate such case.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-02-07 08:18:14 +08:00
xuxingliang ef52c68e06 nxgdb/mm: add prenode, nextnode property for mempool
So it looks like a memory node in heap thus we can process it in a unified way

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-02-07 08:18:14 +08:00
xuxingliang 04bd00f80a pynuttx: optimize memory leak check by skipping previously checked pointers
Reduce leak analysis time from 12s to 7.8s, achieving a 35% performance improvement that tested on an internal project.

1. Use memoryview to avoid creating int objects, reducing overhead
2. Store checked pointers in a dictionary for efficient lookups, improving performance.
3. While dictionary operations have some cost, the overall speedup is significant.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-02-05 09:15:27 -03:00
xuxingliang b90638493a pynuttx: fix memleak
Only need to check used node, excluding free nodes.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-02-05 09:15:27 -03:00
xuxingliang f9d8cdcca2 nxgdb/memdump: add free command
(gdb) free
name            total      used       free       maxused    maxfree    nused      nfree
GImageCache     10485756   10411964   73792      10602184   62328      217        7
uncache         10485756   127812     10357944   270512     10350560   4          2
Umem            26879516   17458732   9420784    20957888   9260768    1211       234
(gdb)

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-02-04 09:32:07 -03:00
xuxingliang 8995e5a66e nxgdb/fs: simplify inode print and add more options
Use Inode.__repr__ for print and use single line for all information.
Add 'verbose' and 'nodetype' option to show more details and only print specifiy node type like PIPE.
Add / to name for pseudodir.
Catch memory error when accessing node element.

E.g.

(gdb) foreach inode --nodetype pipe
        ├── run/ 0x41a27a50 PSEUDODIR
        │   ├── bt:bluetoothCS1fd26 0x4530c510 PIPE
        │   ├── bt:bluetoothCS20 0x42daae40 PIPE
        │   ├── socketpair0x457fd2e0SC20540 0x44ea27b0 PIPE
        │   └── tmp/ 0x42dd7cf0 PSEUDODIR
        │       │   └── usock/ 0x42dd6c10 PSEUDODIR
        │       │       └── speech.usockHD 0x42dc8270 PIPE
        │       ├── central_lite.socketCS5e 0x42e1e7b0 PIPE
        │       ├── central_service_lite.socketSC86 0x432ee6d0 PIPE
        │       │   └── usock/ 0x43d6ed60 PSEUDODIR
        │       │       └── speech.usockHD 0x43da2ba0 PIPE
        │       ├── uv-feature-sockSC8d 0x43540430 PIPE
        │       ├── uv-miot-sockCS54 0x42e272e0 PIPE
        │       └── uv-miot-sockSC54 0x42e270b0 PIPE

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-02-03 09:21:26 +01:00
xuxingliang dc5251f9c8 nxgdb/fs: use default args
Instead of storing it to self

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-02-03 09:21:26 +01:00
Neo Xu 698b2e00e6 nxgdb: include all files to package
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2025-02-02 14:02:24 +08:00
xuxingliang 14cc23f42a nxgdb: add missing protocols definitions
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-02-02 14:02:24 +08:00
yinshengkai 50fb43e23b tools: rename tools/gdb/nuttxgdb to tools/pynuttx/nxgdb
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2025-02-02 14:02:24 +08:00