Skip to content

Instantly share code, notes, and snippets.

@cls
Last active June 1, 2018 20:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cls/1677af8f05df1cee445042a8942b060a to your computer and use it in GitHub Desktop.
Save cls/1677af8f05df1cee445042a8942b060a to your computer and use it in GitHub Desktop.
Script to grep objects' symbol tables
#!/bin/sh
pattern="$1"
shift
if [ $# -gt 1 ]
then
GREP_OPTIONS="$GREP_OPTIONS --with-filename"
export GREP_OPTIONS
fi
for file in "$@"
do
nm -P "$file" | awk '{print $2,$1}' | c++filt | grep --label="$file" --regexp="$pattern"
done
@cls
Copy link
Author

cls commented Jan 31, 2017

This script requires GNU grep, and an optional C++ demangler, but is otherwise POSIX compatible.

The GNU dependency can be removed by doing something like the following.

nm -P "$file" | awk '{print $2,$1}' | c++filt | grep "$pattern" | while read match
do
	printf '%s:%s\n' "$file" "$match"
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment