Last active
October 18, 2016 14:04
-
-
Save kamalmarhubi/f23bd119f399c94034720ef7865f1dc3 to your computer and use it in GitHub Desktop.
Dump debug info for an ELF file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eou pipefail | |
me="$(basename $BASH_SOURCE)" | |
if [ $# -ne 1 ]; then | |
echo >&2 usage: "$me" /path/to/binary/to/dump | |
exit 1 | |
fi | |
bin=$1 | |
if [ ! -f "$bin" ]; then | |
echo >&2 "\"$bin\" does not exist" | |
exit 1 | |
fi | |
command -v objcopy >/dev/null 2>&1 || { | |
echo >&2 "objcopy not on path; try installing binutils" | |
exit 1 | |
} | |
echo >&2 "dumping debug info for $bin" | |
tmpdir=$(mktemp --directory --tmpdir dump-debuginfo.XXXXXX) | |
function rmtmp { | |
rm -r "$tmpdir" | |
} | |
trap rmtmp EXIT | |
dest="$tmpdir/sections" | |
mkdir "$dest" | |
tgz=$(mktemp --suffix=.tgz debug-info.XXXXXX) | |
for section in debug_abbrev debug_info debug_str; do | |
objcopy --dump-section ".$section=$tmpdir/sections/$section" "$bin" | |
done | |
tar czf "$tgz" --directory="$tmpdir" "sections" | |
echo >&2 "dumped debug info in $tgz" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment