circuitpython/tools/stack-loc-to-pc.py
Scott Shawcroft dd71ae10b9
Slim down stack frames
This reduces the stack frame size of mp_builtin___import__ by
limiting the support path length of files from 256 to 96. This
function can be called recursively for nested imports so it adds up.

Also reduce mp_execute_bytecode (vm.c) from 206 a bc call to 124.
This too is recursive and adds up. It is reduced by preventing
some inlining. It may decrease performance slightly when importing
and unpacking.

Adds two new scripts for debugging. One is used from gdb to print
frame sizes in a backtrace. The other prints what pcs use a
particular stack offset. This helps find infrequently used stack
space.

Fixes #8053.
2023-06-06 16:20:47 -07:00

29 lines
741 B
Python

"""Prints the pcs that access each stack location in a function. Useful for finding
infrequently used stack space.
Pipe in disassembly like so:
arm-none-eabi-objdump --disassemble=mp_execute_bytecode build-metro_m0_express/firmware.elf | python ../../tools/stack-loc-to-pc.py
"""
import sys
import re
offset = re.compile(r"sp, #(\d+)")
offsets = {}
for line in sys.stdin:
if "sp" in line:
m = offset.search(line)
o = int(m.groups()[0])
pc = line.split(":")[0]
if o not in offsets:
offsets[o] = []
offsets[o].append(pc.strip())
print("Offset", "Size", "PCs", sep="\t")
last_o = 0
for o in sorted(offsets):
print(o, o - last_o, offsets[o], sep="\t")
last_o = o