This is an automated email from the ASF dual-hosted git repository.

cederom pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 9bda244be89 tools/parsetrace.py: Fix get_typesize bug in parsetrace.py
9bda244be89 is described below

commit 9bda244be89ecfdcd4adfe2c4907dd032ea4f130
Author: yukangzhi <[email protected]>
AuthorDate: Tue Jun 3 17:23:05 2025 +0800

    tools/parsetrace.py: Fix get_typesize bug in parsetrace.py
    
    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 <[email protected]>
---
 Documentation/components/tools/index.rst      | 10 ++++
 Documentation/components/tools/parsetrace.rst | 75 +++++++++++++++++++++++++++
 tools/parsetrace.py                           | 11 ++--
 3 files changed, 93 insertions(+), 3 deletions(-)

diff --git a/Documentation/components/tools/index.rst 
b/Documentation/components/tools/index.rst
index 65ccb8e0545..78874e45560 100644
--- a/Documentation/components/tools/index.rst
+++ b/Documentation/components/tools/index.rst
@@ -7,6 +7,11 @@ This page discusses the contents of the NuttX tools/ directory.
 The tools/ directory contains miscellaneous scripts and host C programs
 that are necessary parts of the NuttX build system.
 
+.. toctree::
+   :maxdepth: 2
+
+   parsetrace
+
 cmpconfig.c
 -----------
 
@@ -1225,6 +1230,11 @@ Binaries for both Windows and Linux are available at:
 
 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
 ---
 
diff --git a/Documentation/components/tools/parsetrace.rst 
b/Documentation/components/tools/parsetrace.rst
new file mode 100644
index 00000000000..e8d71e18d6d
--- /dev/null
+++ b/Documentation/components/tools/parsetrace.rst
@@ -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``.
diff --git a/tools/parsetrace.py b/tools/parsetrace.py
index 205969fa095..351f6101d0b 100755
--- a/tools/parsetrace.py
+++ b/tools/parsetrace.py
@@ -133,9 +133,14 @@ class SymbolTables(object):
                     if name == type_name:
                         if "DW_AT_type" in DIE.attributes:
                             type_attr = DIE.attributes["DW_AT_type"]
-                            base_type_die = dwarfinfo.get_DIE_from_refaddr(
-                                type_attr.value + CU.cu_offset
-                            )
+                            if type_attr.form == "DW_FORM_ref_addr":
+                                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":
                                 size = 
base_type_die.attributes["DW_AT_byte_size"].value
                             elif base_type_die.tag == "DW_TAG_typedef":

Reply via email to