xiaoxiang781216 commented on code in PR #18538:
URL: https://github.com/apache/nuttx/pull/18538#discussion_r2932215085


##########
tools/stackusage.py:
##########
@@ -0,0 +1,407 @@
+#!/usr/bin/env python3
+# tools/stackusage.py
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# 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.
+#
+
+"""Static stack usage analyzer combining GCC .su files with objdump call 
graphs.
+
+Reports per-function self stack usage and worst-case total stack depth through
+the call chain. Estimates and flags uncertain cases such as alloca/VLA,
+recursion, and indirect calls (function pointers).
+"""
+
+import argparse
+import csv
+import io
+import os
+import re
+import subprocess
+import sys
+
+# GCC .su file format: file.c:line:col:function_name\tsize\tqualifier
+SU_LINE_RE = re.compile(r"^(.*?\.[a-zA-Z]+):(\d+):(\d+):(.+)\t(\d+)\t(\S+)$")
+
+# objdump function header: 00000000 <function_name>:
+FUNC_RE = re.compile(r"^[0-9a-fA-F]+\s+<(.+)>:\s*$")
+
+# Universal call instruction regex covering all NuttX architectures:
+#   ARM:      bl, blx, b.w          ARM64:    bl, blr
+#   x86:      call, callq           RISC-V:   jal, jalr
+#   Xtensa:   call0/4/8/12,         MIPS:     jal, jalr
+#             callx0/4/8/12
+#   AVR:      rcall, call           z80/z16:  call
+#   OR1K:     l.jal, l.jalr         SPARC:    call, jmpl
+#   TriCore:  call, calli           HC/Ren:   bsr, jsr
+CALL_RE = re.compile(
+    r"\t"
+    r"(?:"
+    r"bl[rx]?|b\.w"  # ARM / ARM64
+    r"|callx?(?:0|4|8|12)"  # Xtensa
+    r"|callq?|calli?"  # x86 / TriCore
+    r"|jalr?|l\.jalr?"  # RISC-V / MIPS / OR1K
+    r"|rcall"  # AVR
+    r"|jmpl"  # SPARC
+    r"|[bj]sr"  # HC / Renesas
+    r")"
+    r"\s+(.*)"
+)

Review Comment:
   Fixed. Changed `CALL_RE` from requiring a literal tab (`\t`) to using `\s+` 
which accepts any whitespace before the mnemonic. This handles different 
toolchain/arch `objdump -d` output formats correctly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to