pynuttx 0.0.6a7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. pynuttx-0.0.6a7/PKG-INFO +665 -0
  2. pynuttx-0.0.6a7/README.md +626 -0
  3. pynuttx-0.0.6a7/etm2human.py +211 -0
  4. pynuttx-0.0.6a7/etm2trace.py +294 -0
  5. pynuttx-0.0.6a7/gdbrpc/__init__.py +64 -0
  6. pynuttx-0.0.6a7/gdbrpc/__main__.py +36 -0
  7. pynuttx-0.0.6a7/gdbrpc/cli.py +65 -0
  8. pynuttx-0.0.6a7/gdbrpc/client.py +170 -0
  9. pynuttx-0.0.6a7/gdbrpc/commands.py +180 -0
  10. pynuttx-0.0.6a7/gdbrpc/examples/getheaps.py +54 -0
  11. pynuttx-0.0.6a7/gdbrpc/examples/memleak.py +67 -0
  12. pynuttx-0.0.6a7/gdbrpc/server.py +285 -0
  13. pynuttx-0.0.6a7/gdbrpc/tests/stresstest.py +168 -0
  14. pynuttx-0.0.6a7/gdbrpc/utils.py +168 -0
  15. pynuttx-0.0.6a7/nxelf/__init__.py +19 -0
  16. pynuttx-0.0.6a7/nxelf/elf.py +640 -0
  17. pynuttx-0.0.6a7/nxelf/macros.py +294 -0
  18. pynuttx-0.0.6a7/nxgdb/__init__.py +86 -0
  19. pynuttx-0.0.6a7/nxgdb/autocompeletion.py +165 -0
  20. pynuttx-0.0.6a7/nxgdb/backtrace.py +263 -0
  21. pynuttx-0.0.6a7/nxgdb/circbuf.py +200 -0
  22. pynuttx-0.0.6a7/nxgdb/critmon.py +165 -0
  23. pynuttx-0.0.6a7/nxgdb/debug.py +67 -0
  24. pynuttx-0.0.6a7/nxgdb/diagnose.py +131 -0
  25. pynuttx-0.0.6a7/nxgdb/dmesg.py +90 -0
  26. pynuttx-0.0.6a7/nxgdb/elf.py +99 -0
  27. pynuttx-0.0.6a7/nxgdb/fs/__init__.py +62 -0
  28. pynuttx-0.0.6a7/nxgdb/fs/command.py +500 -0
  29. pynuttx-0.0.6a7/nxgdb/fs/fatfs.py +47 -0
  30. pynuttx-0.0.6a7/nxgdb/fs/fs.py +115 -0
  31. pynuttx-0.0.6a7/nxgdb/fs/inode.py +238 -0
  32. pynuttx-0.0.6a7/nxgdb/fs/littlefs.py +41 -0
  33. pynuttx-0.0.6a7/nxgdb/fs/lrofs.py +68 -0
  34. pynuttx-0.0.6a7/nxgdb/fs/romfs.py +68 -0
  35. pynuttx-0.0.6a7/nxgdb/fs/utils.py +53 -0
  36. pynuttx-0.0.6a7/nxgdb/fs/yaffs.py +98 -0
  37. pynuttx-0.0.6a7/nxgdb/gcore.py +144 -0
  38. pynuttx-0.0.6a7/nxgdb/gdbrpc.py +54 -0
  39. pynuttx-0.0.6a7/nxgdb/irq.py +91 -0
  40. pynuttx-0.0.6a7/nxgdb/kasan.py +215 -0
  41. pynuttx-0.0.6a7/nxgdb/libuv.py +164 -0
  42. pynuttx-0.0.6a7/nxgdb/lists.py +453 -0
  43. pynuttx-0.0.6a7/nxgdb/memcheck.py +264 -0
  44. pynuttx-0.0.6a7/nxgdb/memclassifier/default.py +179 -0
  45. pynuttx-0.0.6a7/nxgdb/memclassifier/size.py +28 -0
  46. pynuttx-0.0.6a7/nxgdb/memclassifier/utils.py +41 -0
  47. pynuttx-0.0.6a7/nxgdb/memclassify.py +410 -0
  48. pynuttx-0.0.6a7/nxgdb/memdump.py +1098 -0
  49. pynuttx-0.0.6a7/nxgdb/memleak.py +296 -0
  50. pynuttx-0.0.6a7/nxgdb/mm.py +895 -0
  51. pynuttx-0.0.6a7/nxgdb/net.py +333 -0
  52. pynuttx-0.0.6a7/nxgdb/noteram.py +180 -0
  53. pynuttx-0.0.6a7/nxgdb/notesnap.py +119 -0
  54. pynuttx-0.0.6a7/nxgdb/nxcrash/busyloop.py +85 -0
  55. pynuttx-0.0.6a7/nxgdb/nxcrash/deadlock.py +95 -0
  56. pynuttx-0.0.6a7/nxgdb/nxcrash/stackoverflow.py +91 -0
  57. pynuttx-0.0.6a7/nxgdb/nxcrash/thread.py +108 -0
  58. pynuttx-0.0.6a7/nxgdb/pginfo.py +130 -0
  59. pynuttx-0.0.6a7/nxgdb/pm.py +115 -0
  60. pynuttx-0.0.6a7/nxgdb/prefix.py +58 -0
  61. pynuttx-0.0.6a7/nxgdb/profile.py +98 -0
  62. pynuttx-0.0.6a7/nxgdb/protocols/circbuf.py +35 -0
  63. pynuttx-0.0.6a7/nxgdb/protocols/fs.py +72 -0
  64. pynuttx-0.0.6a7/nxgdb/protocols/irq.py +35 -0
  65. pynuttx-0.0.6a7/nxgdb/protocols/mm.py +122 -0
  66. pynuttx-0.0.6a7/nxgdb/protocols/thread.py +141 -0
  67. pynuttx-0.0.6a7/nxgdb/protocols/uorb.py +103 -0
  68. pynuttx-0.0.6a7/nxgdb/protocols/value.py +67 -0
  69. pynuttx-0.0.6a7/nxgdb/protocols/wdog.py +35 -0
  70. pynuttx-0.0.6a7/nxgdb/protocols/wqueue.py +63 -0
  71. pynuttx-0.0.6a7/nxgdb/quickjs.py +99 -0
  72. pynuttx-0.0.6a7/nxgdb/rpmsg.py +327 -0
  73. pynuttx-0.0.6a7/nxgdb/rpmsgtrace2pcap.py +113 -0
  74. pynuttx-0.0.6a7/nxgdb/stack.py +256 -0
  75. pynuttx-0.0.6a7/nxgdb/target.py +124 -0
  76. pynuttx-0.0.6a7/nxgdb/thread.py +698 -0
  77. pynuttx-0.0.6a7/nxgdb/tlsdump.py +153 -0
  78. pynuttx-0.0.6a7/nxgdb/tricore.py +166 -0
  79. pynuttx-0.0.6a7/nxgdb/uname.py +156 -0
  80. pynuttx-0.0.6a7/nxgdb/uorb.py +174 -0
  81. pynuttx-0.0.6a7/nxgdb/utils.py +1412 -0
  82. pynuttx-0.0.6a7/nxgdb/wdog.py +78 -0
  83. pynuttx-0.0.6a7/nxgdb/wqueue.py +196 -0
  84. pynuttx-0.0.6a7/nxgdbmcp/__init__.py +22 -0
  85. pynuttx-0.0.6a7/nxgdbmcp/__main__.py +29 -0
  86. pynuttx-0.0.6a7/nxgdbmcp/gmcp/__init__.py +24 -0
  87. pynuttx-0.0.6a7/nxgdbmcp/gmcp/context.py +25 -0
  88. pynuttx-0.0.6a7/nxgdbmcp/gmcp/main.py +84 -0
  89. pynuttx-0.0.6a7/nxgdbmcp/gmcp/session/__init__.py +26 -0
  90. pynuttx-0.0.6a7/nxgdbmcp/gmcp/session/context.py +75 -0
  91. pynuttx-0.0.6a7/nxgdbmcp/gmcp/session/gdb_session.py +66 -0
  92. pynuttx-0.0.6a7/nxgdbmcp/gmcp/tools/__init__.py +38 -0
  93. pynuttx-0.0.6a7/nxgdbmcp/gmcp/tools/command.py +41 -0
  94. pynuttx-0.0.6a7/nxgdbmcp/gmcp/tools/controlflow.py +216 -0
  95. pynuttx-0.0.6a7/nxgdbmcp/gmcp/tools/memory.py +246 -0
  96. pynuttx-0.0.6a7/nxgdbmcp/gmcp/tools/session.py +280 -0
  97. pynuttx-0.0.6a7/nxgdbmcp/gmcp/tools/shell.py +60 -0
  98. pynuttx-0.0.6a7/nxgdbmcp/gmcp/tools/utils.py +66 -0
  99. pynuttx-0.0.6a7/nxgdbmcp/gmcp/tools/value.py +113 -0
  100. pynuttx-0.0.6a7/nxgdbmcp/gmcp/utils.py +53 -0
  101. pynuttx-0.0.6a7/nxreg/__init__.py +19 -0
  102. pynuttx-0.0.6a7/nxreg/register.py +573 -0
  103. pynuttx-0.0.6a7/nxstub/__init__.py +398 -0
  104. pynuttx-0.0.6a7/nxstub/__main__.py +24 -0
  105. pynuttx-0.0.6a7/nxstub/gdbstub.py +299 -0
  106. pynuttx-0.0.6a7/nxstub/proxy.py +165 -0
  107. pynuttx-0.0.6a7/nxstub/target.py +347 -0
  108. pynuttx-0.0.6a7/nxstub/utils.py +136 -0
  109. pynuttx-0.0.6a7/nxtrace/__init__.py +19 -0
  110. pynuttx-0.0.6a7/nxtrace/etmv4_decoder.py +1944 -0
  111. pynuttx-0.0.6a7/nxtrace/general_rtt.py +346 -0
  112. pynuttx-0.0.6a7/nxtrace/perfetto_trace.py +456 -0
  113. pynuttx-0.0.6a7/nxtrace/perfetto_trace_pb2.py +2556 -0
  114. pynuttx-0.0.6a7/nxtrace/rtt.py +144 -0
  115. pynuttx-0.0.6a7/nxtrace/trace.py +907 -0
  116. pynuttx-0.0.6a7/pynuttx.egg-info/PKG-INFO +665 -0
  117. pynuttx-0.0.6a7/pynuttx.egg-info/SOURCES.txt +133 -0
  118. pynuttx-0.0.6a7/pynuttx.egg-info/dependency_links.txt +1 -0
  119. pynuttx-0.0.6a7/pynuttx.egg-info/entry_points.txt +5 -0
  120. pynuttx-0.0.6a7/pynuttx.egg-info/requires.txt +17 -0
  121. pynuttx-0.0.6a7/pynuttx.egg-info/top_level.txt +11 -0
  122. pynuttx-0.0.6a7/pyproject.toml +64 -0
  123. pynuttx-0.0.6a7/rpmsgtrace2pcap.py +360 -0
  124. pynuttx-0.0.6a7/setup.cfg +4 -0
  125. pynuttx-0.0.6a7/tests/test_mock_stack.py +201 -0
  126. pynuttx-0.0.6a7/tests/test_mock_thread.py +101 -0
  127. pynuttx-0.0.6a7/tests/test_mock_utils.py +159 -0
  128. pynuttx-0.0.6a7/tests/test_runtime_dmesg.py +33 -0
  129. pynuttx-0.0.6a7/tests/test_runtime_fs.py +58 -0
  130. pynuttx-0.0.6a7/tests/test_runtime_memory.py +76 -0
  131. pynuttx-0.0.6a7/tests/test_runtime_net.py +51 -0
  132. pynuttx-0.0.6a7/tests/test_runtime_profile.py +63 -0
  133. pynuttx-0.0.6a7/tests/test_runtime_stack.py +42 -0
  134. pynuttx-0.0.6a7/tests/test_runtime_thread.py +102 -0
  135. pynuttx-0.0.6a7/traceparse.py +129 -0
@@ -0,0 +1,665 @@
1
+ Metadata-Version: 2.4
2
+ Name: pynuttx
3
+ Version: 0.0.6a7
4
+ Summary: Comprehensive Python debugging and analysis toolkit for NuttX RTOS - includes GDB extensions, memory analysis, crash diagnostics, trace parsing, and remote debugging capabilities
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://nuttx.apache.org/
7
+ Project-URL: Documentation, https://nuttx.apache.org/docs/latest/
8
+ Project-URL: Repository, https://github.com/apache/nuttx
9
+ Project-URL: Issues, https://github.com/apache/nuttx/issues
10
+ Project-URL: Changelog, https://github.com/apache/nuttx/tags
11
+ Keywords: nuttx,rtos,embedded,gdb,debugging,memory-analysis,crash-analysis,trace,profiling
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Debuggers
14
+ Classifier: Topic :: Software Development :: Embedded Systems
15
+ Classifier: Topic :: System :: Operating System Kernels
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: angr>=0.0.0
23
+ Requires-Dist: capstone>=0.0.0
24
+ Requires-Dist: cloudpickle>=0.0.0
25
+ Requires-Dist: construct>=0.0.0
26
+ Requires-Dist: debugpy>=0.0.0
27
+ Requires-Dist: lauterbach-trace32-rcl>=0.0.0
28
+ Requires-Dist: lief>=0.0.0
29
+ Requires-Dist: matplotlib>=0.0.0
30
+ Requires-Dist: mcp>=0.0.0
31
+ Requires-Dist: numpy>=0.0.0
32
+ Requires-Dist: pandas>=0.0.0
33
+ Requires-Dist: pillow>=0.0.0
34
+ Requires-Dist: plotly>=0.0.0
35
+ Requires-Dist: prettytable>=0.0.0
36
+ Requires-Dist: pyelftools>=0.0.0
37
+ Requires-Dist: pylink-square>=0.0.0
38
+ Requires-Dist: viztracer>=0.0.0
39
+
40
+ # PyNuttX - NuttX/Vela GDB Extension Toolkit
41
+
42
+ [![Python Version](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/downloads/)
43
+ [![License](https://img.shields.io/badge/license-Apache%202.0-green)](https://www.apache.org/licenses/LICENSE-2.0)
44
+ [![Version](https://img.shields.io/badge/version-0.0.6a3-orange)](https://pypi.org/project/pynuttx/)
45
+
46
+ A comprehensive Python-based GDB debugging toolkit for **NuttX RTOS**, providing powerful extensions for thread analysis, memory debugging, crash diagnostics, filesystem inspection, and much more.
47
+
48
+ > **Production Ready**: Extensively used in Xiaomi Vela OS for embedded systems debugging, crash analysis, and performance profiling.
49
+
50
+ ---
51
+
52
+ ## 📋 Table of Contents
53
+
54
+ - [Introduction](#-introduction)
55
+ - [Installation & Setup](#-installation--setup)
56
+ - [Loading GDB Extensions](#-loading-gdb-extensions)
57
+ - [Usage Scenarios](#-usage-scenarios)
58
+ - [Command Reference](#-command-reference)
59
+ - [Quick Start Examples](#-quick-start-examples)
60
+ - [Advanced Features](#-advanced-features)
61
+ - [FAQ](#-faq)
62
+ - [Contributing](#-contributing)
63
+
64
+ ---
65
+
66
+ ## 🎯 Introduction
67
+
68
+ PyNuttX implements numerous custom GDB commands under `nuttx/tools/pynuttx/`, primarily focused on:
69
+ - **Thread Management**: Thread inspection, backtrace, context switching
70
+ - **Memory Analysis**: Memory dumps, leak detection, heap validation
71
+ - **System Inspection**: Process status, filesystem, network, sensors, and more
72
+
73
+ ### Key Features
74
+
75
+ ✅ **100+ Custom GDB Commands** covering all aspects of embedded debugging
76
+ ✅ **Post-Mortem Analysis** via coredump and memory dump files
77
+ ✅ **Multi-Architecture Support**: ARM, RISC-V, Xtensa, Tricore, and more
78
+ ✅ **Production Tested** in commercial IoT products (Xiaomi Vela OS)
79
+ ✅ **Extensible Framework** for custom command development
80
+
81
+ ---
82
+
83
+ ## 🚀 Installation & Setup
84
+
85
+ ### Prerequisites
86
+
87
+ **GDB Version Requirement**:
88
+ - GDB **11 or higher** with python enabled is required
89
+
90
+ ```bash
91
+ # Use prebuilt gdb-multiarch (recommended)
92
+ trunk/prebuilts/gcc/linux/gdb-multiarch/bin/gdb-multiarch
93
+
94
+ # Special architectures require specific GDB:
95
+ # - Tricore: prebuilts/gcc/linux/tricore/bin/tricore-gdb
96
+ # - Xtensa: xtensa-esp32s3-elf-gdb (xt-gdb does NOT support Python extensions)
97
+ ```
98
+
99
+ > ⚠️ **Note**: Some vendor toolchains may have compilation issues causing missing `libpython` support, preventing Python module usage.
100
+
101
+ ### Install Dependencies
102
+
103
+ Install required Python packages:
104
+
105
+ ```bash
106
+ # Install dependencies (Linux)
107
+ /usr/bin/python3 -m pip install -r nuttx/tools/pynuttx/requirements.txt
108
+
109
+ # Or via pip if pynuttx is installed
110
+ pip install pynuttx
111
+ ```
112
+
113
+ ### Important Notes
114
+
115
+ 1. **Code-Tool Compatibility**: ⚠️ Always match your code version with tool version
116
+ - Don't use `stable` tools to analyze `dev` branch code
117
+ - Keep tool and firmware in sync
118
+
119
+ 2. **Architecture-Specific Tools**: Use the correct GDB for your target architecture
120
+ - Tricore: `tricore-gdb`
121
+ - Xtensa: `xtensa-esp32s3-elf-gdb` (see [reference](https://gerrit.pt.mioffice.cn/c/vela/prebuilts/gcc/linux/xtensa-esp-elf-gdb/+/5279361))
122
+ - ARM: `gdb-multiarch` or `arm-none-eabi-gdb`
123
+
124
+ ---
125
+
126
+ ## 📥 Loading GDB Extensions
127
+
128
+ ### Method 1: Load via `-ex` Parameter (Recommended)
129
+
130
+ ```bash
131
+ # Start GDB with automatic loading
132
+ gdb-multiarch nuttx/vela_ap.elf -ex "source nuttx/tools/pynuttx/gdbinit.py"
133
+
134
+ # Or load manually in GDB shell
135
+ (gdb) source nuttx/tools/pynuttx/gdbinit.py
136
+ ```
137
+
138
+ ### Method 2: Import as Python Module
139
+
140
+ ```bash
141
+ # Set PYTHONPATH so Python can find the module
142
+ export PYTHONPATH=/myworkspace/nuttx/tools/pynuttx:$PYTHONPATH
143
+
144
+ # Option 1: Load during GDB startup
145
+ gdb-multiarch nuttx/nuttx.elf -ex "py import nxgdb"
146
+
147
+ # Option 2: Import after GDB starts
148
+ (gdb) py import nxgdb
149
+ ```
150
+
151
+ ### Verify Installation
152
+
153
+ ```gdb
154
+ # Check available custom commands
155
+ (gdb) help user-defined
156
+
157
+ # Get help for specific command
158
+ (gdb) memdump --help
159
+ (gdb) info nxthread --help
160
+ ```
161
+
162
+ ---
163
+
164
+ ## 🎪 Usage Scenarios
165
+
166
+ PyNuttX works in multiple debugging contexts:
167
+
168
+ | Scenario | Description | Use Case |
169
+ |----------|-------------|----------|
170
+ | **Online Debugging** | Live device via JTAG/SWD | JLink, OpenOCD, TRACE32 |
171
+ | **GDB Stub** | Serial/USB debugging | Embedded GDB stub on target |
172
+ | **Post-Mortem** | Crash dump analysis | Load memory dumps via `gdbserver.py` |
173
+ | **Coredump** | ELF coredump files | Analyze with `gdb <elf> <coredump>` |
174
+
175
+ ### Example: Connect to Live Target
176
+
177
+ ```bash
178
+ # Via OpenOCD (JTAG/SWD)
179
+ openocd -f interface/jlink.cfg -f target/stm32f4x.cfg &
180
+ gdb-multiarch nuttx -ex "target remote :3333" -ex "source tools/pynuttx/gdbinit.py"
181
+
182
+ # Via Serial GDB Stub
183
+ gdb-multiarch nuttx -ex "target remote /dev/ttyUSB0" -ex "source tools/pynuttx/gdbinit.py"
184
+ ```
185
+
186
+ ### Example: Post-Mortem Analysis
187
+
188
+ ```bash
189
+ # Start gdbserver with memory dumps
190
+ python3 tools/pynuttx/gdbserver.py \
191
+ -a arm \
192
+ -e nuttx.elf \
193
+ -r ram.bin:0x20000000 psram.bin:0x60000000 \
194
+ -p 6667
195
+
196
+ # Connect and analyze
197
+ gdb-multiarch nuttx.elf -ex "target remote :6667" -ex "source tools/pynuttx/gdbinit.py"
198
+ ```
199
+
200
+ ---
201
+
202
+ ## 📚 Command Reference
203
+
204
+ ### 🧵 Thread & Scheduling
205
+
206
+ | Command | Description |
207
+ |---------|-------------|
208
+ | `info nxthread` | Display NuttX threads with Vela-specific data (replaces `info threads` for better NuttX integration) |
209
+ | `nxthread <id>` | Switch to specific thread context |
210
+ | `setregs <addr>` | Restore register context from saved state |
211
+ | `deadlock` | Detect deadlock conditions |
212
+ | `critmon` | Critical section monitor (same as device `critmon`) |
213
+ | `ps` | Process status (same as device `ps`) |
214
+ | `crash busyloop` | Detect busy-loop threads |
215
+
216
+ **Example:**
217
+ ```gdb
218
+ (gdb) info nxthread
219
+ PID GROUP PRI POLICY TYPE NPX STATE EVENT SIGMASK STACKBASE STACKSIZE USED FILLED COMMAND
220
+ 0 0 0 FIFO Kthread - Running 00000000 0x00000000 0 0 0.0%! Idle_Task
221
+ 1 1 100 RR Task - Waiting Semaphore 00000000 0x20600000 2048 824 40.2% nsh_main
222
+
223
+ (gdb) nxthread 1
224
+ (gdb) bt
225
+ ```
226
+
227
+ ### 💾 Memory Management
228
+
229
+ | Command | Description |
230
+ |---------|-------------|
231
+ | `memdump` | Dump memory allocation info (same as device `memdump`) |
232
+ | `memleak` | Detect memory leaks by analyzing unreachable allocations |
233
+ | `memcheck` | Verify heap integrity and core data structures |
234
+ | `memfind <pattern>` | Search for pattern in heap/bss/data (auto address range) |
235
+ | `kasan` | KASAN helper to check address tag accessibility |
236
+ | `memclassify` | Classify memory by backtrace to identify module usage |
237
+ | `mm visualize` | Visualize memory state with size distribution charts |
238
+ | `dump ram` | Export memory data to file |
239
+ | `mm range` | Show memory regions in current system |
240
+ | `crash stackoverflow` | Detect stack overflow conditions |
241
+
242
+ **Example:**
243
+ ```gdb
244
+ # Show top 20 memory consumers without backtrace (faster)
245
+ (gdb) memdump --top 20 --no-backtrace
246
+
247
+ # Detect memory leaks
248
+ (gdb) memleak
249
+ Searching for leaked memory, please wait a moment...
250
+ Leak catch!, use '*' mark pid is not exist:
251
+ CNT PID Size Sequence Address Callstack
252
+ 34 30 256 8810 0x3d52f080 [0x00c3210e0] <malloc+12>
253
+ ...
254
+
255
+ # Check heap integrity
256
+ (gdb) mm check
257
+
258
+ # Visualize memory fragmentation
259
+ (gdb) mm visualize
260
+ ```
261
+
262
+ ### 🖥️ System & Diagnostics
263
+
264
+ | Command | Description |
265
+ |---------|-------------|
266
+ | `foreach list` | Traverse NuttX linked lists |
267
+ | `tlsdump` | Dump and verify TLS info / task info integrity |
268
+ | `nxgcore` | Pull device coredump (wraps GDB's `gcore`) |
269
+ | `free` | Show memory info (same as device `free`) |
270
+ | `uname` | Display firmware version |
271
+ | `irqinfo` | Show IRQ statistics (same as device `irqinfo`) |
272
+ | `dmesg` | Display kernel log (ramlog) |
273
+ | `wdog` | Show registered watchdog timer info |
274
+ | `worker` | Show registered worker info |
275
+ | `noteram` | View note trace data, perform `notedump` operations |
276
+ | `notesnap` | View task switching state before crash |
277
+ | `target nxstub` | Connect to gdbserver via Vela proxy (native GDB thread support) |
278
+ | `diagnose` | Run all diagnostic commands, generate JSON report |
279
+ | `circbuf` | View circular buffer state (`libc/misc/lib_circbuf.c`) |
280
+ | `pmconfig` | View PM configuration info |
281
+ | `elfimport` | Import ELF symbols |
282
+ | `crash thread` | Identify which thread caused the crash |
283
+
284
+ **Example:**
285
+ ```gdb
286
+ # View kernel log
287
+ (gdb) dmesg
288
+
289
+ # Generate comprehensive diagnostic report
290
+ (gdb) diagnose
291
+
292
+ # Check system info
293
+ (gdb) uname
294
+ (gdb) free
295
+ ```
296
+
297
+ ### 🗂️ Filesystem
298
+
299
+ | Command | Description |
300
+ |---------|-------------|
301
+ | `fdinfo` | Show open file descriptors per task |
302
+ | `mount` | Display mount information |
303
+ | `foreach inode` | Traverse inode tree |
304
+ | `info shm` | Show shared memory usage |
305
+ | `info yaffs` | View YAFFS partition context |
306
+ | `info romfs` | View ROMFS partition context |
307
+ | `info fatfs` | View FAT filesystem partition context |
308
+ | `info lrofs` | View LROFS partition context |
309
+
310
+ **Example:**
311
+ ```gdb
312
+ # Check open files
313
+ (gdb) fdinfo
314
+
315
+ # View mount points
316
+ (gdb) mount
317
+
318
+ # Inspect filesystem partition
319
+ (gdb) info fatfs /dev/mmcsd0
320
+ ```
321
+
322
+ ### 🌐 Network & Connectivity
323
+
324
+ | Command | Description |
325
+ |---------|-------------|
326
+ | `netstats` | Print IOB and protocol/socket info |
327
+ | `netcheck` | Run network diagnostics |
328
+ | `btsocket` | Print Bluetooth IPC server/client cache queue |
329
+ | `btdev` | Print Bluetooth adapter BLE/BREDR device info |
330
+ | `bttimeval` | Print Bluetooth thread peak timestamp |
331
+ | `btstack` | Print protocol stack list (e.g., GATT pending list) |
332
+ | `btsnoop` | Convert Bluetooth `/dev/tty` circular buffer to HCI log |
333
+ | `lyrainfo` | Display Lyra Lite connection, mesh, and transmission info |
334
+
335
+ **Example:**
336
+ ```gdb
337
+ # Network statistics
338
+ (gdb) netstats
339
+
340
+ # Bluetooth diagnostics
341
+ (gdb) btdev
342
+ (gdb) btsnoop /dev/ttyBT0 output.hci
343
+ ```
344
+
345
+ ### 🎨 Graphics (LVGL)
346
+
347
+ See [GDB Plug-In](https://docs.lvgl.io/master/details/debugging/gdb_plugin.html)
348
+
349
+ | Command | Description |
350
+ |---------|-------------|
351
+ | `dump cache image` | View image cache memory |
352
+ | `dump cache image_header` | View image header cache memory |
353
+ | `info draw_unit` | View current draw unit info, verify rendering context |
354
+ | `info style` | View LVGL object style and type information |
355
+ | `dump obj` | Display LVGL object tree |
356
+ | `show fb` | Display framebuffer content |
357
+
358
+ ### 📡 RPC & IPC
359
+
360
+ | Command | Description |
361
+ |---------|-------------|
362
+ | `rpmsgservice` | View RPMSG service information |
363
+
364
+
365
+ ### 📊 Sensors
366
+
367
+ | Command | Description |
368
+ |---------|-------------|
369
+ | `uorb` | View `/dev/uorb/` node subscriptions and publications |
370
+
371
+ ### 🎬 Media
372
+
373
+ | Command | Description |
374
+ |---------|-------------|
375
+ | `mediadump` | View pipeline filter EOF state and internal dump data |
376
+
377
+ ### 📱 Application Frameworks
378
+
379
+ | Command | Description |
380
+ |---------|-------------|
381
+ | `dump aiotmemory` | Print Quick App JS memory usage |
382
+
383
+ ### 🔧 Development Tools
384
+
385
+ | Command | Description |
386
+ |---------|-------------|
387
+ | `profile` | Analyze Python function call time (performance profiling) |
388
+ | `viztracer` | Capture Python trace data, view with Perfetto |
389
+ | `time` | Measure Python tool execution time (like shell `time`) |
390
+ | `addr2line` | Convert addresses/variables/expressions to backtrace |
391
+ | `hexdump` | Dump memory at address with printable characters |
392
+ | `debugpy` | Debug Python code in IDE |
393
+
394
+ ---
395
+
396
+ ## 🚀 Quick Start Examples
397
+
398
+ ### Example 1: Memory Leak Detection
399
+
400
+ ```gdb
401
+ # Connect to target or load memory dump
402
+ gdb-multiarch nuttx.elf -ex "target remote :3333" -ex "source tools/pynuttx/gdbinit.py"
403
+
404
+ # Run memory leak detection
405
+ (gdb) memleak
406
+ Searching for leaked memory, please wait a moment
407
+ Searching global symbol in: /path/to/nuttx.elf
408
+ Search all memory use 28.98 seconds
409
+
410
+ Leak catch!, use '*' mark pid is not exist:
411
+ CNT PID Size Sequence Address Callstack
412
+ 34 30 256 8810 0x3d52f080
413
+ [0x00c3210e0] <malloc+12>
414
+ [0x00c47c904] <lv_malloc+6>
415
+ ...
416
+
417
+ Alloc 44 count, have 8 some backtrace leak, total leak memory is 10112 bytes
418
+ ```
419
+
420
+ ### Example 2: Crash Analysis
421
+
422
+ ```gdb
423
+ # After a crash, connect to device
424
+ gdb-multiarch nuttx.elf -ex "target remote /dev/ttyUSB0" -ex "source tools/pynuttx/gdbinit.py"
425
+
426
+ # View kernel log
427
+ (gdb) dmesg
428
+ [ 123.456] Assertion failed at file:line
429
+
430
+ # Check thread status
431
+ (gdb) info nxthread
432
+
433
+ # Identify crashing thread
434
+ (gdb) crash thread
435
+
436
+ # Run comprehensive diagnostics
437
+ (gdb) diagnose
438
+
439
+ # Check for memory corruption
440
+ (gdb) memcheck
441
+
442
+ # Detect stack overflow
443
+ (gdb) crash stackoverflow
444
+ ```
445
+
446
+ ### Example 3: Post-Mortem Analysis
447
+
448
+ ```bash
449
+ # 1. Collect memory dumps from crashed device
450
+ (gdb) dump memory ram.bin 0x20000000 0x20100000
451
+ (gdb) dump memory psram.bin 0x60000000 0x64000000
452
+
453
+ # 2. Start gdbserver with memory files
454
+ python3 tools/pynuttx/gdbserver.py \
455
+ -a arm \
456
+ -e nuttx.elf \
457
+ -r ram.bin:0x20000000 psram.bin:0x60000000 \
458
+ -p 6667
459
+
460
+ # 3. Connect and analyze
461
+ gdb-multiarch nuttx.elf \
462
+ -ex "target remote :6667" \
463
+ -ex "source tools/pynuttx/gdbinit.py"
464
+
465
+ # 4. Analyze the crash
466
+ (gdb) info nxthread
467
+ (gdb) bt
468
+ (gdb) memdump --top 20
469
+ ```
470
+
471
+ ### Example 4: Filesystem Debugging
472
+
473
+ ```gdb
474
+ # Check open file descriptors
475
+ (gdb) fdinfo
476
+
477
+ # View mount points
478
+ (gdb) mount
479
+
480
+ # Inspect filesystem details
481
+ (gdb) info fatfs /dev/mmcsd0
482
+
483
+ # Traverse inode tree
484
+ (gdb) foreach inode
485
+ ```
486
+
487
+ ### Example 5: Network Debugging
488
+
489
+ ```gdb
490
+ # View network statistics
491
+ (gdb) netstats
492
+
493
+ # Run network diagnostics
494
+ (gdb) netcheck
495
+
496
+ # Check Bluetooth status
497
+ (gdb) btdev
498
+ (gdb) btsocket
499
+ ```
500
+
501
+ ---
502
+
503
+ ## 🎓 Advanced Features
504
+
505
+ ### Save Command Output to File
506
+
507
+ ```gdb
508
+ # Use pipe to save output
509
+ (gdb) pipe info nxthread | tee output.log
510
+ (gdb) pipe memdump | tee memdump.txt
511
+ ```
512
+
513
+ ### View All Custom Commands
514
+
515
+ ```gdb
516
+ # List all user-defined commands
517
+ (gdb) help user-defined
518
+
519
+ # Get help for specific command
520
+ (gdb) <command> --help
521
+ ```
522
+
523
+ ### GDB Proxy for Native Thread Support
524
+
525
+ ```gdb
526
+ # Connect via nxstub for better thread awareness
527
+ (gdb) target nxstub --proxy :1234 # For example, connect to qemu
528
+ (gdb) info threads # Now shows NuttX threads correctly
529
+ ```
530
+
531
+ ### Comprehensive Diagnostics
532
+
533
+ ```gdb
534
+ # Run all diagnostic commands and generate JSON report
535
+ (gdb) diagnose
536
+
537
+ # This automatically runs:
538
+ # - Thread analysis
539
+ # - Memory checks
540
+ # - System state inspection
541
+ # - Network diagnostics
542
+ # - And more...
543
+ ```
544
+
545
+ ---
546
+
547
+ ## ❓ FAQ
548
+
549
+ ### Q: How do I add my own custom commands?
550
+
551
+ **A:** Follow the [GDB Python API]([docs/gdb-plugin.md](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Python-API.html)) to create custom commands.
552
+
553
+ Example:
554
+ ```python
555
+ import gdb
556
+
557
+ class MyCommand(gdb.Command):
558
+ """My custom command description"""
559
+
560
+ def __init__(self):
561
+ super().__init__("mycommand", gdb.COMMAND_USER)
562
+
563
+ def invoke(self, arg, from_tty):
564
+ print("Hello from my command!")
565
+
566
+ MyCommand()
567
+ ```
568
+
569
+ Save as `mycommand.py` and load:
570
+ ```gdb
571
+ (gdb) source mycommand.py
572
+ (gdb) mycommand
573
+ ```
574
+
575
+ ### Q: Can thread functionality display in VSCode or other frontends?
576
+
577
+ **A:** Not yet perfectly. Current implementation replaces same-named commands which doesn't perfectly adapt to frontend tools. Frontend adaptation is under development.
578
+
579
+
580
+ ### Q: GDB version error or Python module not found?
581
+
582
+ **A:**
583
+ 1. Ensure GDB 11+ is installed
584
+ 2. Check GDB Python support: `gdb --batch -ex "python import sys; print(sys.version)"`
585
+ 3. Use prebuilt GDB from Vela repository
586
+ 4. Install dependencies: `pip install -r requirements.txt`
587
+
588
+ ### Q: Commands are slow on embedded target?
589
+
590
+ **A:** Use post-mortem analysis instead:
591
+ 1. Dump memory from target
592
+ 2. Use `gdbserver.py` to load dumps
593
+ 3. Analyze offline (much faster!)
594
+
595
+ ### Q: How to debug multi-core systems?
596
+
597
+ **A:**
598
+ 1. Dump memory from each core separately
599
+ 2. Load each core's memory with corresponding ELF file
600
+ 3. Use separate GDB sessions or load all in one gdbserver instance
601
+
602
+ ### Q: Code and tool version mismatch?
603
+
604
+ **A:** ⚠️ Always keep tool and firmware versions synchronized!
605
+ - Use same branch for both code and tools
606
+ - Don't mix stable branch tools with dev branch code
607
+
608
+ ---
609
+
610
+ ## 🤝 Contributing
611
+
612
+ Contributions are welcome! PyNuttX is part of the Apache NuttX project.
613
+
614
+ ### Development Setup
615
+
616
+ ```bash
617
+ # Clone repository
618
+ git clone https://github.com/apache/nuttx.git
619
+ cd nuttx/tools/pynuttx
620
+
621
+ # Install in development mode
622
+ pip install -e .
623
+
624
+ # Install development dependencies
625
+ pip install -r requirements.txt
626
+ ```
627
+
628
+ ### Adding New Commands
629
+
630
+ 1. Create your command in appropriate module under `nxgdb/`
631
+ 2. Add documentation in `docs/`
632
+ 3. Add tests in `tests/`
633
+ 4. Submit pull request
634
+
635
+ See [Contributing Guide](CONTRIBUTING.md) for details.
636
+
637
+ ---
638
+
639
+ ## 📖 Resources
640
+
641
+ - **Documentation**: See `docs/` directory for detailed command documentation
642
+ - **NuttX Website**: https://nuttx.apache.org/
643
+ - **Issue Tracker**: https://github.com/apache/nuttx/issues
644
+ - **Mailing List**: https://nuttx.apache.org/community/
645
+
646
+ ---
647
+
648
+ ## 📄 License
649
+
650
+ Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for details.
651
+
652
+ ---
653
+
654
+ ## 🙏 Acknowledgments
655
+
656
+ Maintained by the Apache NuttX community and extensively developed by the Xiaomi Vela team.
657
+
658
+ **Special Thanks To:**
659
+ - All contributors and maintainers
660
+ - Xiaomi Vela OS team for production testing and enhancements
661
+ - The embedded systems community
662
+
663
+ ---
664
+
665
+ **For support and questions, please refer to the [NuttX Documentation](https://nuttx.apache.org/docs/latest/) or contact the community via [mailing lists](https://nuttx.apache.org/community/).**