From f465760d1f822e98cdc5c7099e692d65ae8080f5 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 28 Sep 2018 23:38:59 -0400 Subject: [PATCH] Add a tool to locate global variables --- build_tools/find_globals.fish | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 build_tools/find_globals.fish diff --git a/build_tools/find_globals.fish b/build_tools/find_globals.fish new file mode 100755 index 000000000..24338bca4 --- /dev/null +++ b/build_tools/find_globals.fish @@ -0,0 +1,19 @@ +#!/usr/bin/env fish + +# Finds global variables by parsing the output of 'nm' +# for object files in this directory. +# This was written for macOS nm. + +set total_globals 0 + +for file in ./**.o + set filename (basename $file) + for line in (nm -p -P -U $file) + # Look in data (dD) and bss (bB) segments. + set matches (string match --regex '^([^ ]+) ([dDbB])' -- $line) ; or continue + echo $filename (echo $matches[2] | c++filt) $matches[3] + set total_globals (math $total_globals + 1) + end +end + +echo "Total: $total_globals" \ No newline at end of file