mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 20:08:15 +08:00
tools/parsetrace.py: Fix get_typesize bug in parsetrace.py
Build Documentation / build-html (push) Has been cancelled
Build Documentation / build-html (push) Has been cancelled
For the following code, we need to check 'type_attr.form'. type_attr = DIE.attributes["DW_AT_type"] base_type_die = dwarfinfo.get_DIE_from_refaddr(xxx) When type_attr.form==DW_FORM_ref_addr, 'type_attr.value' means global reference (across compilation units). When type_attr.form==DW_FORM_ref4, 'type_attr.value' means local reference (within the same compilation unit). Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
This commit is contained in:
@@ -7,6 +7,11 @@ This page discusses the contents of the NuttX tools/ directory.
|
|||||||
The tools/ directory contains miscellaneous scripts and host C programs
|
The tools/ directory contains miscellaneous scripts and host C programs
|
||||||
that are necessary parts of the NuttX build system.
|
that are necessary parts of the NuttX build system.
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 2
|
||||||
|
|
||||||
|
parsetrace
|
||||||
|
|
||||||
cmpconfig.c
|
cmpconfig.c
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
@@ -1225,6 +1230,11 @@ Binaries for both Windows and Linux are available at:
|
|||||||
|
|
||||||
See also indent.sh and nxstyle.c
|
See also indent.sh and nxstyle.c
|
||||||
|
|
||||||
|
parsetrace.py
|
||||||
|
-------------
|
||||||
|
|
||||||
|
``parsetrace.py`` is a Python script for parsing and converting NuttX trace logs. See :doc:`parsetrace` for details.
|
||||||
|
|
||||||
zds
|
zds
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
parsetrace.py
|
||||||
|
=============
|
||||||
|
|
||||||
|
`parsetrace.py` is a trace log parsing tool for the NuttX RTOS. It supports converting binary or text trace logs into a human-readable systrace format, and can resolve symbols and type information from ELF files. The tool also supports real-time trace data parsing via serial port.
|
||||||
|
|
||||||
|
Features
|
||||||
|
--------
|
||||||
|
- Supports parsing both binary and text trace log formats.
|
||||||
|
- Integrates with ELF files to resolve symbols and type information for improved log readability.
|
||||||
|
- Supports real-time trace data parsing from a serial device.
|
||||||
|
- Outputs systrace-compatible format for performance analysis and debugging.
|
||||||
|
|
||||||
|
Dependencies
|
||||||
|
------------
|
||||||
|
- Python 3
|
||||||
|
- pyelftools
|
||||||
|
- cxxfilt
|
||||||
|
- pydantic
|
||||||
|
- parse
|
||||||
|
- pycstruct
|
||||||
|
- colorlog
|
||||||
|
- serial
|
||||||
|
|
||||||
|
Install dependencies:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
pip install pyelftools cxxfilt pydantic parse pycstruct colorlog serial
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
python3 tools/parsetrace.py -t <trace_file> -e <elf_file> [-o <output_file>] [-v]
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
- ``-t, --trace``: Path to the original trace file (supports binary or text format)
|
||||||
|
- ``-e, --elf``: Path to the NuttX ELF file (for symbol resolution)
|
||||||
|
- ``-o, --output``: Output file path, default is ``trace.systrace``
|
||||||
|
- ``-v, --verbose``: Enable verbose output
|
||||||
|
- ``-d, --device``: Serial device name (for real-time trace parsing)
|
||||||
|
- ``-b, --baudrate``: Serial baud rate, default is 115200
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
Parse a text trace log and output as systrace format:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
python3 tools/parsetrace.py -t trace.log -e nuttx.elf -o trace.systrace
|
||||||
|
|
||||||
|
Parse a binary trace log:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
python3 tools/parsetrace.py -t trace.bin -e nuttx.elf
|
||||||
|
|
||||||
|
Parse trace data from a serial device in real time:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
python3 tools/parsetrace.py -d /dev/ttyUSB0 -e nuttx.elf
|
||||||
|
|
||||||
|
Main Classes and Functions
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
- ``SymbolTables``: Handles ELF symbol and type information parsing.
|
||||||
|
- ``Trace``: Parses text trace logs.
|
||||||
|
- ``ParseBinaryLogTool``: Parses binary trace logs.
|
||||||
|
- ``TraceDecoder``: Parses real-time trace data from serial port.
|
||||||
|
|
||||||
|
For more details, refer to the source code in ``tools/parsetrace.py``.
|
||||||
+8
-3
@@ -133,9 +133,14 @@ class SymbolTables(object):
|
|||||||
if name == type_name:
|
if name == type_name:
|
||||||
if "DW_AT_type" in DIE.attributes:
|
if "DW_AT_type" in DIE.attributes:
|
||||||
type_attr = DIE.attributes["DW_AT_type"]
|
type_attr = DIE.attributes["DW_AT_type"]
|
||||||
base_type_die = dwarfinfo.get_DIE_from_refaddr(
|
if type_attr.form == "DW_FORM_ref_addr":
|
||||||
type_attr.value + CU.cu_offset
|
base_type_die = dwarfinfo.get_DIE_from_refaddr(
|
||||||
)
|
type_attr.value
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
base_type_die = dwarfinfo.get_DIE_from_refaddr(
|
||||||
|
type_attr.value + CU.cu_offset
|
||||||
|
)
|
||||||
if base_type_die.tag == "DW_TAG_base_type":
|
if base_type_die.tag == "DW_TAG_base_type":
|
||||||
size = base_type_die.attributes["DW_AT_byte_size"].value
|
size = base_type_die.attributes["DW_AT_byte_size"].value
|
||||||
elif base_type_die.tag == "DW_TAG_typedef":
|
elif base_type_die.tag == "DW_TAG_typedef":
|
||||||
|
|||||||
Reference in New Issue
Block a user