Skip to content

Instantly share code, notes, and snippets.

@kamalmarhubi
Last active October 18, 2016 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamalmarhubi/f23bd119f399c94034720ef7865f1dc3 to your computer and use it in GitHub Desktop.
Save kamalmarhubi/f23bd119f399c94034720ef7865f1dc3 to your computer and use it in GitHub Desktop.
Dump debug info for an ELF file
#!/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