Skip to content

Instantly share code, notes, and snippets.

@Proteas
Forked from dominik-hadl/gdbGetStrippedSymbols.sh
Created December 7, 2013 01:46
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 Proteas/7836313 to your computer and use it in GitHub Desktop.
Save Proteas/7836313 to your computer and use it in GitHub Desktop.
#!/bin/sh
# gdbGetStrippedSymbols.sh
# @author Dominik Hadl (@dominikhadl)
# @description This script automates the setup of gdb on a stripped applicaiton adds symbols. It uses objc-symbols to get the symbols,
# then SymTabCreator and finally creates a command that is automatically loaded into gdb on start.
# @license Licensed under WTFPL license (see http://www.wtfpl.net/txt/copying/ for full license).
# @dependencies
# 1. objc-symbols
# 2. SymTabCreator
# 3. gdb (really non-obvious)
# @usage This script can by used by running this command.
# gdb_symbols_script.sh <application>
############################################################
################################
# Helpers
function usage
{
DDP_FILENAME=`basename ${0##*/}`
echo "usage: ${DDP_FILENAME} <application>"
}
function dependencyIsMissing
{
if [[ $# == 1 ]]; then
echo "Dependency (${1}) is missing. Please install it - preferably into /usr/bin."
fi
exit 1
}
################################
## Main Execution
################################
# Check if there is a correct number of arguments
if [[ $# == 1 ]]; then
# Check if specified file exists
if [ -e "$1" ]; then
# Check if commands/dependencies exists
# 1. gdb (essential)
# 2. class-dump (almost essential)
# 3. objc-symbols (class-dump extension)
# 4. SymTabCreator (for loading symbols into gdb)
command -v gdb > /dev/null || dependencyIsMissing "gdb"
command -v objc-symbols > /dev/null || dependencyIsMissing "objc-symbols"
command -v SymTabCreator > /dev/null || dependencyIsMissing "SymTabCreator"
# Create Variables
# 1. Set temporary directory path with .stabs and gdb commands
# 2. Get the file name without extension
# 3. Create the path for the .stabs file in temporary dir
DDP_TMPDIR="/tmp/ddp_gdbcommand"
DDP_FILENAME=`basename "${1%.*}"`
DDP_SYMBOL_FILE="${DDP_TMPDIR}/${DDP_FILENAME}.stabs"
# Execute commands
# 1. Create the temporary directory
# 2. Create the symbolic table
# 3. Save commands for gdb to file
mkdir "${DDP_TMPDIR}"
objc-symbols "${1}" | SymTabCreator -o "$DDP_SYMBOL_FILE"
echo "symbol-file ${DDP_SYMBOL_FILE}" > "${DDP_TMPDIR}/gdbcommands"
# Start gdb with the symbol file
gdb --silent --command="${DDP_TMPDIR}/gdbcommands" "${1}"
# Cleanup
# Delete the temporary directory including its contents
rm -rf "${DDP_TMPDIR}"
else
echo "File does not exist. Please provide a valid file."
exit 1
fi
elif [[ $# > 1 ]]; then
# Too many arguments specified
echo "Too many arguments."
usage
exit 1
else
# No argument specified
usage
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment