8000 GitHub - natanael127/stack-analyzer: Analyzes the total stack consumption of functions of a code compiled by gcc
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

natanael127/stack-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Stack Analyzer

A Python tool to analyze stack usage in C/C++ programs by combining compiler-generated stack usage information (.su files) with function call graphs (generated by cflow). This helps identify potential stack overflow issues in embedded systems or resource-constrained environments.

Features

  • Recursively scans directories for .su files generated by GCC
  • Parses call graphs from cflow output
  • Calculates both direct and total stack usage for each function
  • Generates a comprehensive JSON report of stack usage analysis
  • Identifies the full call chain contributing to stack usage

Requirements

  • Python 3.6+
  • GCC with stack usage reporting capability
  • GNU cflow
sudo apt install python3 gcc cflow

Usage

To see all available options:

python stack_analyzer.py --help

Generating .su Files

To generate .su files, compile your C/C++ code with GCC using the -fstack-usage flag:

For GCC

gcc -fstack-usage -c file.c

This will produce a .su file alongside each object file, containing stack usage information.

In a Makefile

Add the flag to your CFLAGS:

CFLAGS += -fstack-usage

CMake Example

add_compile_options(-fstack-usage)

Generating cflow Output

The tool expects cflow output in the GNU format with levels printed. Generate it using:

cflow --all --format=gnu --print-level <source-files> > callgraph.txt

Output Format

The tool generates a JSON file with stack info of each found function.

About

Analyzes the total stack consumption of functions of a code compiled by gcc

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0