nuttx/tools/gdb/__init__.py
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

43 lines
1.5 KiB
Python

############################################################################
# tools/gdb/__init__.py
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
import glob
import os
import sys
import gdb
python_dir = os.path.abspath(__file__)
python_dir = os.path.dirname(python_dir)
sys.path.insert(1, python_dir)
# Search the python dir for all .py files, and source each
py_files = glob.glob("%s/*.py" % python_dir)
py_files.remove(os.path.abspath(__file__))
gdb.execute("set pagination off")
gdb.write("set pagination off\n")
for py_file in py_files:
gdb.execute("source %s" % py_file)
gdb.write("source %s\n" % py_file)
gdb.execute('handle SIGUSR1 "nostop" "pass" "noprint"')
gdb.write('"handle SIGUSR1 "nostop" "pass" "noprint"\n')