From: Breno Rodrigues Alves <breno3011alves@gmail.com>
To: Heiko Carstens <hca@linux.ibm.com>
Cc: linux-kernel@vger.kernel.org, Jonathan Corbet <corbet@lwn.net>,
Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>,
Dwaipayan Ray <dwaipayanray1@gmail.com>,
Lukas Bulwahn <lukas.bulwahn@gmail.com>,
Breno Rodrigues Alves <breno3011alves@gmail.com>
Subject: [PATCH] scripts: checkstack: Convert to Python
Date: Mon, 19 Oct 2026 10:45:27 -0300 [thread overview]
Message-ID: <20261019134527.5384-1-breno3011alves@gmail.com> (raw)
Convert checkstack.pl to Python to unify kernel tooling in a single
language. This reduces the maintenance burden of dealing with two
different sets of idioms for the same class of scripts.
The conversion introduces a robust parse_size helper to handle dynamic
stack adjustments (e.g., sub %eax, %esp). In Perl, hex() silently
evaluates non-numeric strings to 0; Python's int() raises a ValueError.
The new helper ensures 1:1 behavioral parity without crashing on valid
objdump output.
Tested by comparing the output of checkstack.pl and checkstack.py
against a full objdump of /bin/bash on x86_64; the outputs were identical.
Assisted-by: DeepSeek
Signed-off-by: Breno Rodrigues Alves <breno3011alves@gmail.com>
---
scripts/checkstack.py | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/scripts/checkstack.py b/scripts/checkstack.py
index 8be3861b3..c3821c860 100755
--- a/scripts/checkstack.py
+++ b/scripts/checkstack.py
@@ -65,7 +65,18 @@ def config_for(arch):
def parse_size(s):
- return int(s, 16) if s.startswith('0x') else int(s)
+ """
+ Mimics Perl's implicit numeric conversion.
+ In Perl, hex("%eax") silently evaluates to 0.
+ In Python, int("%eax") raises ValueError, so we catch it
+ to maintain 1:1 parity and prevent script crashes.
+ """
+ if not s:
+ return 0
+ try:
+ return int(s, 16) if s.startswith('0x') else int(s)
+ except ValueError:
+ return 0
def main(argv):
@@ -81,7 +92,8 @@ def main(argv):
total = 0
for raw in sys.stdin:
- line = raw.rstrip('\n')
+ # Fix: Use rstrip('\r\n') to handle Windows-formatted objdump files safely
+ line = raw.rstrip('\r\n')
m = RE_FUNC.match(line)
if m:
--
2.43.0
reply other threads:[~2026-10-19 13:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261019134527.5384-1-breno3011alves@gmail.com \
--to=breno3011alves@gmail.com \
--cc=apw@canonical.com \
--cc=corbet@lwn.net \
--cc=dwaipayanray1@gmail.com \
--cc=hca@linux.ibm.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas.bulwahn@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®