scripts: checkstack: Convert to Python
PATCH 1/1 scripts: checkstack: Convert to Python
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 <[email protected]>
--- scripts/checkstack.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
scripts/checkstack.py +14 -2
@@ -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:
Signature · 1 line
2.43.0