2023-10-29 16:40:32 +01:00
|
|
|
===============
|
2023-06-20 20:36:19 +08:00
|
|
|
GDB with Python
|
2023-10-29 16:40:32 +01:00
|
|
|
===============
|
2023-06-20 20:36:19 +08:00
|
|
|
|
|
|
|
|
Introduction
|
|
|
|
|
============
|
|
|
|
|
|
2024-11-26 00:28:31 +08:00
|
|
|
The NuttX kernel can be effectively debugged using GDB's Python extension.
|
2025-02-05 10:41:06 +08:00
|
|
|
Commonly used classes and utilities are implemented in the ``nuttx/tools/gdb/nuttxgdb`` directory.
|
2024-11-26 00:28:31 +08:00
|
|
|
Users can also create custom Python scripts tailored to their debugging needs to analyze and troubleshoot the NuttX kernel more efficiently.
|
2023-06-20 20:36:19 +08:00
|
|
|
|
|
|
|
|
Usage
|
|
|
|
|
=====
|
|
|
|
|
|
2025-02-05 10:41:06 +08:00
|
|
|
1. Compile NuttX with CONFIG_DEBUG_SYMBOLS=y enabled and change ``CONFIG_DEBUG_SYMBOLS_LEVEL`` to ``-g3``.
|
2024-11-26 00:28:31 +08:00
|
|
|
2. Use GDB to debug the NuttX ELF binary (on a real device, a simulator, or with a coredump).
|
2025-02-05 10:41:06 +08:00
|
|
|
3. Add the following argument to the GDB command line: ``-ix="nuttx/tools/pynuttx/gdbinit.py"``
|
2024-11-26 00:28:31 +08:00
|
|
|
4. GDB will automatically load the Python script, enabling the use of custom commands.
|
2023-06-20 20:36:19 +08:00
|
|
|
|
|
|
|
|
How to write a GDB python script
|
|
|
|
|
================================
|
|
|
|
|
|
2024-11-26 00:28:31 +08:00
|
|
|
Here is an article that introduces the fundamental principles of Python in GDB. Read it to gain a basic understanding.
|
2023-06-20 20:36:19 +08:00
|
|
|
`Automate Debugging with GDB Python API <https://interrupt.memfault.com/blog/automate-debugging-with-gdb-python-api>`_.
|
|
|
|
|
|
2024-11-26 00:28:31 +08:00
|
|
|
For more documentation on gdb python, please refer to the official documentation of GDB.
|
|
|
|
|
`GDB Python API <https://sourceware.org/gdb/current/onlinedocs/gdb.html/Python-API.html#Python-API>`_.
|
2025-02-05 10:41:06 +08:00
|
|
|
|
|
|
|
|
Requirements
|
|
|
|
|
============
|
|
|
|
|
|
|
|
|
|
To use GDB with Python, the following requirements must be met:
|
|
|
|
|
|
|
|
|
|
- Use GDB compiled with Python support, Python 3.8 or later
|
|
|
|
|
- Install required Python packages: ``pip install -r tools/pynuttx/requirements.txt``
|
|
|
|
|
- Compile NuttX with debug level 3: ``CONFIG_DEBUG_SYMBOLS_LEVEL="-g3"``
|
|
|
|
|
|
|
|
|
|
.. Warning::
|
|
|
|
|
The GDB Python API is not available in all versions of GDB. Make sure to use a version that supports Python.
|
|
|
|
|
|
|
|
|
|
.. Warning::
|
|
|
|
|
NuttX must be compile with ``CONFIG_DEBUG_SYMBOLS=y`` and ``CONFIG_DEBUG_SYMBOLS_LEVEL="-g3"`` to use GDB with Python.
|
|
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
|
:caption: GDB Plugin Commands
|
|
|
|
|
:maxdepth: 1
|
|
|
|
|
|
|
|
|
|
gdb/irqinfo.rst
|