Extract Stack Usage from Map File

Medium Shell Memory Asked at STMicroelectronics
Solve this problem

Parse a linker map file and report the top stack consumers, so a stack overflow can be predicted before it happens on the bench.

Constraints

  • Stack usage lines look like 'function_name 128 static'.
  • Report the top 10 by size, largest first.
  • Skip entries marked 'dynamic' - they cannot be bounded statically.
  • Print name and size, tab separated.
  • Exit 1 if the map file is missing.
  • Use only awk, sort and standard utilities.
Starter codeShell
1#!/bin/sh2# TODO: report top stack consumers