Commit graph

156 commits

Author SHA1 Message Date
xuxingliang
4e2ad314d7 tools/gdb: avoid building a full list
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-22 12:30:12 +08:00
yangao1
ab3aa41f39 tools/gdb/fs.py: add print fdinfo,modify the print format
Execute fdinfo or fdinfo -p pid.

(gdb) fdinfo
PID: 0
FD  OFLAGS  POS   PATH                  BACKTRACE
0   3       0     /dev/console          0x4028ff0c <sched_backtrace+48>                 /home/neo/projects/vela2/nuttx/sched/sched/sched_backtrace.c:105
                                        0x402888f8 <file_allocate_from_tcb+236>         /home/neo/projects/vela2/nuttx/fs/inode/fs_files.c:615
                                        0x402979d0 <nx_vopen+104>                       /home/neo/projects/vela2/nuttx/fs/vfs/fs_open.c:326
                                        0x40297ad4 <nx_open+116>                        /home/neo/projects/vela2/nuttx/fs/vfs/fs_open.c:449
                                        0x40291eb4 <group_setupidlefiles+28>            /home/neo/projects/vela2/nuttx/sched/group/group_setupidlefiles.c:75
                                        0x4028df94 <nx_start+628>                       /home/neo/projects/vela2/nuttx/sched/init/nx_start.c:651
                                        0x4028119c <arm64_boot_primary_c_routine+16>    /home/neo/projects/vela2/nuttx/arch/arm64/src/common/arm64_boot.c:205

1   3       0     /dev/console          0x4028ff0c <sched_backtrace+48>                 /home/neo/projects/vela2/nuttx/sched/sched/sched_backtrace.c:105
                                        0x40289574 <file_dup3+248>                      /home/neo/projects/vela2/nuttx/fs/vfs/fs_dup2.c:177
                                        0x40288b88 <nx_dup3_from_tcb+176>               /home/neo/projects/vela2/nuttx/fs/inode/fs_files.c:314
                                        0x40288c64 <nx_dup2_from_tcb+16>                /home/neo/projects/vela2/nuttx/fs/inode/fs_files.c:901
                                        0x40288c88 <nx_dup2+28>                         /home/neo/projects/vela2/nuttx/fs/inode/fs_files.c:924
                                        0x40291ec4 <group_setupidlefiles+44>            /home/neo/projects/vela2/nuttx/sched/group/group_setupidlefiles.c:84
                                        0x4028df94 <nx_start+628>                       /home/neo/projects/vela2/nuttx/sched/init/nx_start.c:651
                                        0x4028119c <arm64_boot_primary_c_routine+16>    /home/neo/projects/vela2/nuttx/arch/arm64/src/common/arm64_boot.c:205

2   3       0     /dev/console          0x4028ff0c <sched_backtrace+48>                 /home/neo/projects/vela2/nuttx/sched/sched/sched_backtrace.c:105
                                        0x40289574 <file_dup3+248>                      /home/neo/projects/vela2/nuttx/fs/vfs/fs_dup2.c:177
                                        0x40288b88 <nx_dup3_from_tcb+176>               /home/neo/projects/vela2/nuttx/fs/inode/fs_files.c:314
                                        0x40288c64 <nx_dup2_from_tcb+16>                /home/neo/projects/vela2/nuttx/fs/inode/fs_files.c:901
                                        0x40288c88 <nx_dup2+28>                         /home/neo/projects/vela2/nuttx/fs/inode/fs_files.c:924
                                        0x40291ed0 <group_setupidlefiles+56>            /home/neo/projects/vela2/nuttx/sched/group/group_setupidlefiles.c:117
                                        0x4028df94 <nx_start+628>                       /home/neo/projects/vela2/nuttx/sched/init/nx_start.c:651
                                        0x4028119c <arm64_boot_primary_c_routine+16>    /home/neo/projects/vela2/nuttx/arch/arm64/src/common/arm64_boot.c:205

Signed-off-by: yangao1 <yangao1@xiaomi.com>
2024-11-22 12:30:12 +08:00
zhengyu9
136b7065b7 gdb tools: print inode info
go through each inode and print its structure info
in the form like below:
├── i_name: bin, i_ino: 51
│   i_parent: , i_peer: data, i_child: , i_crefs: 1, i_flags: 3
│   ......(other info)
│   ├── i_name: audio, i_ino: 5
│   │   i_parent: dev, i_peer: binder, i_child: mixer......

Signed-off-by: zhengyu9 <zhengyu9@xiaomi.com>
2024-11-22 12:30:12 +08:00
zhengyu9
fab9670857 gdb tools: mount command
support mount command in gdb, print mount information
test result:
/bin type binfs
/data type hostfs
/etc type romfs
/proc type procfs
/resource type hostfs
/tmp type tmpfs

Signed-off-by: zhengyu9 <zhengyu9@xiaomi.com>
2024-11-22 12:30:12 +08:00
Neo Xu
1518f8bdb8 tools/gdb: fix type and comments
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-11-21 23:08:55 +08:00
anjiahao
cd78de7c63 memleak:Add reminder information
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-21 23:08:55 +08:00
anjiahao
b507a57158 thread.py: fix bug that ARM-A TCB info register offset is discontinuous
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-21 23:08:55 +08:00
xuxingliang
0f1e2cc7dc tools/gdb: make it compatible with older gdb
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-21 23:08:55 +08:00
anjiahao
f53869f86f memleak:use global symbol to search all global variables
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-21 23:08:55 +08:00
anjiahao
8575f11e1e memdump.py:use import_check inside of once_init
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-21 23:08:55 +08:00
anjiahao
e71d45ce86 utils.py:support import check and requirements.txt
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-21 23:08:55 +08:00
buxiasen
bf2d6a3554 tools/gdb/memdump: add biggest/orphon dump.
information prefer from gdb to python class

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-11-21 23:08:55 +08:00
xuxingliang
fc0f7365bb tools/gdb: fix import error for certain gdb
For the prebuilt arm-none-eabi-gdb, there's no python builtin module
available.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-21 23:08:55 +08:00
xuxingliang
de5f70b3c8 tools/gdb: remove 'Nx' prefix for unique commands
1. Remove Nx prefix for nuttx unique commands.
2. Add docstring for most of the commands in order to show help message.
3. Add 'init_once' method for Memmap command. The prerequisite is checked the moment it's used.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-21 23:08:55 +08:00
xuxingliang
3a46b6e6af tools/gdb: cache gdb.Type result
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-21 23:08:55 +08:00
xuxingliang
1d25eed55c tools/gdb: fix CONFIG_SMP_NCPUS could be none
The macro could be eliminated by optimization.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-21 23:08:55 +08:00
xuxingliang
715c3ab079 tools/gdb: fix notification suppress not working
"on" string is always in the word 'notification'. Should use "is on" instead.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-21 23:08:55 +08:00
xuxingliang
ad1be85be7 tools/gdb: catch exception when there's no selected frame
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-21 23:08:55 +08:00
xuxingliang
bbf51ba071 tools/gdb: no need to read the whole memory firstly
Read the whole memory costs additional time. When the number memory nodes is
small, test on qemu shows that read memory directly is faster.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-21 23:08:55 +08:00
xuxingliang
12783c031c tools/gdb: only define c and s when thread comands enabled
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-21 23:08:55 +08:00
yinshengkai
b81212e96f tools/gdb: Add memory fragmentation rate calculation
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-11-21 23:08:55 +08:00
xuxingliang
9dbf58f1be tools/gdb: optimize memleak speed
1. Avoid to_bytes by using memoryview directly.
2. No need to call gdb to cast to char *.
3. Cache the memory data without invoke gdb in every iteration.
4. Do code cleanup.

memleak speed improved from 261.93 seconds to 29.9 seconds for x4b
usecase.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-21 23:08:55 +08:00
xuxingliang
4e067fd762 tool/gdb: use second inferior to get symbol
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-21 23:08:55 +08:00
yinshengkai
614e07c8f0 tools/gdb: supports generating memory map images
Display all memory nodes in a picture, which can be used to help analyze memory fragmentation

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-11-21 23:08:55 +08:00
xuxingliang
2f8c9070c5 tools/gdb: use native thread command
For coredump, gdb-stub, the thread command is natively supported.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-21 23:08:55 +08:00
anjiahao
089877c693 memleak:support use gdb to catching absolute memory leaks
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-21 23:08:55 +08:00
Neo Xu
edc410f26f format code to pass CI
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-11-20 09:04:22 +08:00
buxiasen
96a3bc2b5c tools/gdb: fix if restore_regs failed script abort
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-11-20 09:04:22 +08:00
anjiahao
eded2017d4 memdump.py:Enhance the printing function of memdump
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-20 09:04:22 +08:00
anjiahao
477f7b92ee tools/gdb/memdump.py:fix mempool memory traversal missing nodes
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-20 09:04:22 +08:00
xuxingliang
8264c05c15 tools/gdb: use f string where possible
misc update.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-11-20 09:04:22 +08:00
Gao Jiawei
06d640a677 implement ps nx shell utility for ez debugging with GDB
Signed-off-by: Gao Jiawei <gaojiawei@xiaomi.com>
2024-11-20 09:04:22 +08:00
Gao Jiawei
e31fe0fb55 add custom command and APIs for retrieving/displaying stack statistics
Signed-off-by: Gao Jiawei <gaojiawei@xiaomi.com>
2024-11-20 09:04:22 +08:00
Gao Jiawei
8edb9283ba trivial modification on the utility module
1. add get macro related inteface, for now we have't fully implemented
the way to expand and evalute macros at runtime. We just deal with some macros that can be expand and evaluate into essential constants that will be needed later.
2. rearrange utility functions in a different order
3. reimplment the get register API to make it more commonly used

Signed-off-by: Gao Jiawei <gaojiawei@xiaomi.com>
2024-11-20 09:04:22 +08:00
Gao Jiawei
76db3c8939 enable stack trace printing on excpetion
Signed-off-by: Gao Jiawei <gaojiawei@xiaomi.com>
2024-11-20 09:04:22 +08:00
anjiahao
e0bea987d1 gdb python plugin:support dump list member
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-20 09:04:22 +08:00
anjiahao
daac426f79 gdb python plugin:add hexdump command support
hexdump useful to debug

format such as:

(gdb) hexdump 0x0062fd30 500
0062fd30  73 68 6f 77 5f 76 61 72 69 61 62 6c 65 3a 20 45  show_variable: E
0062fd40  52 52 4f 52 20 56 61 72 69 61 62 6c 65 3d 25 73  RROR Variable=%s
0062fd50  20 68 61 73 20 74 68 65 20 77 72 6f 6e 67 20 76   has the wrong v
0062fd60  61 6c 75 65 0a 00 6f 73 74 65 73 74 5f 6d 61 69  alue..ostest_mai
0062fd70  6e 2e 63 00 73 68 6f 77 5f 76 61 72 69 61 62 6c  n.c.show_variabl
0062fd80  65 3a 20 45 52 52 4f 52 20 56 61 72 69 61 62 6c  e: ERROR Variabl
0062fd90  65 3d 25 73 20 68 61 73 20 61 20 76 61 6c 75 65  e=%s has a value
0062fda0  20 77 68 65 6e 20 69 74 20 73 68 6f 75 6c 64 20   when it should
0062fdb0  6e 6f 74 0a 00 73 68 6f 77 5f 76 61 72 69 61 62  not..show_variab

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-20 09:04:22 +08:00
anjiahao
635e324e9a gdb/thread.py:simplify the logic of nxsetregs
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-20 09:04:22 +08:00
wangmingrong
8eb1047595 gdb python tools: fix command "info thread" echo error
Signed-off-by: wangmingrong <wangmingrong@xiaomi.com>
2024-11-20 09:04:22 +08:00
anjiahao
eccd26a162 gdb/thread.py:Print colorful
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-20 09:04:22 +08:00
anjiahao
5aaa31337a gdb/thread.py:fix a bug when use 'up' then use 'thread'
Python Exception <class 'gdb.error'>: Attempt to assign to an unmodifiable value.
Python Exception <class 'gdb.error'>: Error occurred in Python: Attempt to assign to an unmodifiable value.
Error occurred in Python: Error occurred in Python: Attempt to assign to an unmodifiable value.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-20 09:04:22 +08:00
anjiahao
2292a36983 gdb/thread.py:change show gdb index/tid/pid format
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-20 09:04:22 +08:00
anjiahao
852e683fa3 python/gdb:fix use thread command on running task bug
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-11-20 09:04:22 +08:00
ligd
5c939d8140 gdb: devide tid & pid, add holder logout when waiting mutex
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-11-20 09:04:22 +08:00
hujun5
19b4911d7f arch: remove up_current_regs in common code
reason:

When entering an exception or interrupt, there are two sets of registers:
one is the "running regs", which we need to save,
and the other is the "ready to running regs", which we may soon use.
For consistency in logic, we can always store the "running regs" in the regs field of g_running_tasks,
otherwise it may lead to errors in the storage location of the "running regs."

When we need to access the "running regs," we should uniformly retrieve them from the regs field of g_running_tasks.

As the next step, we will rename the set_current_regs/up_current_regs functions
for each architecture to more appropriate names, solely for the purpose of identifying interrupts.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-11-15 18:25:35 +08:00
anjiahao
fb176c02ca gdb/thread.py:Remove dependence on g_current_regs
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-08 23:55:59 +08:00
wangmingrong1
b5c5e4b850 gdb plugin: Encapsulate the gdb native command gcore as nxgcore
Modify elf with nxgcore and call gcore:
(gdb) nxgcore --help
usage: [-h] [-o OUTPUT] [-t OBJCOPY] [-r MEMRANGE]

options:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        Gcore output file
  -t OBJCOPY, --objcopy OBJCOPY
                        Select the appropriate architecture for the objcopy
                        tool
  -r MEMRANGE, --memrange MEMRANGE

examples:
	(gdb) nxgcore -t arm-none-eabi-objcopy -r 0x40200000,0x48000000,0x07

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-20 22:07:29 +08:00
Alin Jerpelea
c9eef2d697 tools: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-09-10 23:11:11 +08:00
anjiahao
9eadf61e90 toos/gdb:sync mempool memdump method
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-08-21 18:01:24 +08:00
anjiahao
9478f5b6d4 tools/gdb:add get_symbol_value api
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-08-21 18:01:24 +08:00
wangmingrong
52a349ab13 memdump: Enhance memdump
The method of passing in parameters to memdump is modified and the
incoming address is added. After traversing the node to which the
address belongs, the memdump command will end.

Signed-off-by: wangmingrong <wangmingrong@xiaomi.com>
2024-03-15 17:46:48 +08:00
anjiahao
749655d785 tcbinfo:remove total_num form tcbinfo.
total_num is not required
test:

make -f tools/Makefile.host
cp tools/jlink-nuttx /opt/SEGGER/JLink_V786a/libnuttxplugin.so
JLinkGDBServer -if SWD -speed 5000 -device STM32F429ZI -NoGui 1 -rtos libnuttxplugin

can run normally

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-11-21 21:52:24 -08:00
Bowen Wang
320b73818b tools/gdb/memdump.py: fix the wrap line output indentation
1. always output the wrap line when dump main heap memory node;
2. format the memdump.py;

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-09-21 13:49:43 +08:00
chenxiaoyi
917764857a gdb/thread.py: fix typo
Signed-off-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
2023-09-19 09:35:55 +08:00
anjiahao
d63a36e0f3 toos/gdb/thread:Support thread command on nuttx
support arch:
  sim x86
  sim x86_64
  arm32 all series

  If we need to support more architectures in the future,
  just add the 'g_tcbinfo' of the corresponding architecture

support thread command:
  1. thread <id>
    switch thread
  2. info thread
    list all thread info
  3. thread apply [all | id list] command
    like this:
      thread apply all bt
      thread apply all bt full
      thread apply 1 2 4 bt
      thread apply all info r
  4. nxsetregs
      Set registers to the specified values.
      Usage: nxsetregs [regs]

      Etc: nxsetregs
           nxsetregs g_current_regs[0]
           nxsetregs tcb->xcp.regs
           Nxsetregs g_pidhash[0].tcb->xcp.regs

      Default regs is g_current_regs[0],if regs is NULL,
      it will not set registers.

    Because NuttX enters exception_common during a crash,
    this assembly function manipulates the stack pointer (sp),
    causing GDB to be unable to trace back to the first context of the crash.
    Instead, it shows the context of the interrupt stack. By using nxsetregs,
    it is possible to forcefully set the first context to
    the one before the interrupt occurred.

Notice:
  Switching threads is achieved by setting registers,
  so registers need to be restored before continue,
  please use 'c' to continue instead of 'continue'

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-07-23 21:59:35 -07:00
anjiahao
adc5c8b5ac Debug:support python script auto debug nuttx kernel
This patch add an example and pyhton base modules:
1.add memdump.py is an example to analyze memory
usage by python script.
2.add The most basic data structure analysis, like list, etc.

future ideas:
Maybe we can add modules related to "sched, drivers, arch, fs.." to
automatically analyze scripts to debug some problems

References:
linux kernel (https://github.com/torvalds/linux/tree/master/scripts/gdb)
The official manual of gdb (https://sourceware.org/gdb/onlinedocs/gdb/Python-API.html)

Change-Id: Ib9025a0a141cb89f3813526f7c55dcb28de31ed9
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-06-25 18:17:30 +08:00