Skip to content

Instantly share code, notes, and snippets.

@fcamel
Created July 18, 2013 13:43
Show Gist options
  • Save fcamel/6029402 to your computer and use it in GitHub Desktop.
Save fcamel/6029402 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Ref. http://sourceware.org/gdb/onlinedocs/gdb/Index-Files.html
if [ $# -ne 1 ]; then
echo -e "$0 <binary>\n"
echo -e "Add gdb index to <binary>\n"
exit 1
fi
binary="$1"
dir="${binary%/*}"
echo "> Getting gdb index from $binary ..."
time gdb -nx --batch-silent -ex "file $binary" -ex "save gdb-index $dir"
echo -e "\n> Insert gdb index into $binary ..."
if [ -f "${binary}.gdb-index" ]; then
time objcopy --add-section .gdb_index="${binary}.gdb-index" --set-section-flags .gdb_index=readonly "$binary" "$binary"
rm -f "${binary}.gdb-index"
fi
echo -e "\n> Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment