Commit graph

25 commits

Author SHA1 Message Date
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
xuxingliang
d3c4f4ec52 gdb/workqueue: add basic workqueue dump support
(gdb) worker
hpwork@0x40424b40, idle, 2 threads, 0 work
lpwork@0x40424a80, idle, 2 threads, 0 work
test@0x4045a8c0, running, 2 threads, 2 work
    Running:
    kworker_s@0x4045a908 work_s@0x406cf330: 0x0 arg=0x406cf300
    Queued:
    work_s@0x406cf370: 0x402f1954 <count_worker> arg=0x406cf318
    work_s@0x406cf3b0: 0x402f1954 <count_worker> arg=0x406cf318
(gdb)

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2025-01-30 13:45:41 +08:00
xuxingliang
8031c9c1de gdb/mm: cache global variables to save time of memleak check
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-25 13:37:42 +08:00
Xu Xingliang
412644fcf2 gdb: optimize memory commands
Tested on a complex project, results are promising.

Command                 Time cost(s)           Time saving(s)   Peformance Boost
                        Before      After
memleak                 39.494172   22.366415   17.127757       1.8
memdump                 41.872441   26.458386   15.414055       1.6
memdump -a 0x1234       28.116294   1.114119    27.002175       25.2
memdump --no-backtrace    N/A       1.114119
memmap                  7.973809    6.836468    1.137341        1.2

Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
2024-11-25 00:42:34 +08:00
xuxingliang
a59a28de5b gdb/utils: enhance utils.Value
Added __format__ method to support format spec like {:>10} that gdb.Value doesn't support. For such case, gdb.Value is converted to python value firstly and then format natively.
Override all methods/attributes could return gdb.Value to return utils.Value instead.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-24 17:52:42 +08:00
xuxingliang
3a2d4584c7 gdb/utils: cache backtrace result for better performance
GDB is slow to look up symbols, cache the result to speed up commands like memdump etc.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-24 03:03:40 +08:00
xuxingliang
f5371e92f3 gdb/backtrace: optimize backtrace formatting
Use a class Bactrace to support convert address to backtrace, format to string, accessing element and iterate though them.
Adjust usage in fs and addr2line to make full use of it.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-24 03:03:40 +08:00
xuxingliang
38b5dcd42c gdb/register: register name sp, pc are always available
GDB provides four “standard” register names sp, pc, fp and ps. Those can be used in most of the cases.

See https://sourceware.org/gdb/current/onlinedocs/gdb.html/Registers.html

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-24 03:03:40 +08:00
xuxingliang
73467989c5 gdb: move profiling commands to profile.py
Add simple time command to test time cost of a command.
Usage:
(gdb) time memleak
...
(gdb) Time elapsed: 1.23456s

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-24 03:03:40 +08:00
Xu Xingliang
6949ff6a7d gdb: add sizeof helper
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
2024-11-24 03:03:40 +08:00
xuxingliang
84c66505aa tools/gdb: add function to convert C enum to python Enum class
Usage:
(gdb) py NX_INITSTATE = utils.enum("enum nx_initstate_e")
(gdb) py print(list(NX_INITSTATE))
[<NX_INITSTATE_E.POWERUP: 0>, <NX_INITSTATE_E.BOOT: 1>, <NX_INITSTATE_E.TASKLISTS: 2>, <NX_INITSTATE_E.MEMORY: 3>, <NX_INITSTATE_E.HARDWARE: 4>, <NX_INITSTATE_E.OSREADY: 5>, <NX_INITSTATE_E.IDLELOOP: 6>, <NX_INITSTATE_E.PANIC: 7>]
(gdb) py print(NX_INITSTATE.POWERUP)
NX_INITSTATE_E.POWERUP
(gdb) py print(NX_INITSTATE.POWERUP.value)
0
(gdb) py print(NX_INITSTATE(1))

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-24 03:03:40 +08:00
xuxingliang
379eee2f4e tools/gdb: fix hexdump expression parse
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-24 03:03:40 +08:00
yangao1
40efe1af11 nuttxgdb/utils.py:add ArrayIterator reverse iterate.
Signed-off-by: yangao1 <yangao1@xiaomi.com>
2024-11-24 03:03:40 +08:00
xuxingliang
e3b3da3bd1 tools/gdb: support string type in offset_of
1. Support any type of value as pointer address in container_of
2. Support string as type in offset_of
3. Make sure type is a pointer in container_of, and not a pointer in
   offset_of

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-24 03:03:40 +08:00
xuxingliang
d02dc3893c tools/gdb: decode backtrace of crashlog
Now crash log can be directly pass to addr2line tool to get all backtraces.

E.g.
(gdb) addr2line -f crash.log -p 485
Address              Symbol                           Source

Backtrace of 485
0x402cc0ac           <up_switch_context+84>           /home/work/ssd1/workspace/MiRTOS-X4b-Stable-Build/nuttx/include/arch/syscall.h:179
0x40291276           <nxsig_timedwait+386>            signal/sig_timedwait.c:365
0x4028fc7e           <nxsig_nanosleep+106>            signal/sig_nanosleep.c:141
0x4028fdba           <clock_nanosleep+26>             signal/sig_nanosleep.c:333
0x402c3736           <usleep+62>                      unistd/lib_usleep.c:108
0x415018c0           <cs2p2p_mSecSleep+24>            Src/PPPP_Common.c:1139
0x414fabde           <cs2p2p_Run_send_DRW+258>        Src/PPPP_API.c:5577
0x414fac62           <cs2p2p_PPPP_thread_send_DRW+18> Src/PPPP_API.c:5616
0x40446f62           <pthread_startup+10>             pthread/pthread_create.c:59
0x41094f4a           <pthread_start+106>              pthread/pthread_create.c:139

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-24 03:03:40 +08:00
huangyin5
1e265af8eb tools/gdb: add utils.get_tid(tcb)
Signed-off-by: huangyin5 <huangyin5@xiaomi.com>
2024-11-24 03:03:40 +08:00
xuxingliang
69613d5199 tools/gdb: add array iterator
Use array iterator where possible.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-24 03:03:40 +08:00
Zhe Weng
0cda6278d3 tools/gdb: Use ptr's value instead of ptr's adderess in container_of
We're using `ptr.cast(get_long_type())` a week ago to get the pointer's value, it's alright, but `ptr.address` is not, the `ptr.address` will return **the address of the pointer**.

These values are the address of first element in the queue:
    - `int(g_sigfreeaction["head"])`
    - `g_sigfreeaction["head"].cast(get_long_type())`
    - `g_sigfreeaction["head"].dereference().address`
But:
    `int(g_sigfreeaction["head"].address)` is the address of the "head" member, which equals to the address of `g_sigfreeaction`

It's happening in NxSQueue:
    g_sigfreeaction = gdb.parse_and_eval("g_sigfreeaction")
    print(["%x" % (node) for node in NxSQueue(g_sigfreeaction)])
    print(["%x" % (node) for node in NxSQueue(g_sigfreeaction, "sigactq_t", "flink")])
Without this patch:
    ['f3c0aa10', 'f3c0aa2c', 'f3c0aa48']
    ['55db90a0', 'f3c0aa10', 'f3c0aa2c']
With this patch:
    ['f3c0aa10', 'f3c0aa2c', 'f3c0aa48']
    ['f3c0aa10', 'f3c0aa2c', 'f3c0aa48']

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-11-24 03:03:40 +08:00
Zhe Weng
a4e5689c7f tools/gdb: Allow utils.container_of with str input
After we introduced NxDQueue and NxSQueue, we're using them like `NxDQueue(g_active_connections, "struct socket_conn_s", "node")` and leads to `utils.container_of(ptr, str, str)`, so maybe we need to allow str input for `utils.container_of`

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-11-24 03:03:40 +08:00
buxiasen
bb461b532b nuttxgdb: fix container_of pointer offset calc problem
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-11-24 03:03:40 +08:00
xuxingliang
b296b1debe gdb/macro: cache macro info to json and load directly
Use json module to save macro info to json file and load directly. It can save 2seconds for x4b projects to load plugin

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-24 03:03:40 +08:00
xuxingliang
96a518af35 tools/gdb: fix elf file with special character
Make sure file name is surrounded by \"

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-24 03:03:40 +08:00
xuxingliang
8b4a4f8539 tools/gdb: add get_task_tls and get_thread_tls
Signed-off-by: rongyichang <rongyichang@xiaomi.com>
2024-11-23 13:09:16 +08:00
xuxingliang
5d86bee5c7 tools/gdb: add diagnose commands
Run diagnostic related commands anytime to generate report.

E.g `diag report -o systemreport.json`

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-23 13:09:16 +08:00
xuxingliang
04b35a2e8f tools/gdb: add pyproject.toml to build as a package
Now the GDB tool can be built with python -m build . to generate a
package.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-23 13:09:16 +08:00
Renamed from tools/gdb/utils.py (Browse further)