Skip to content

Instantly share code, notes, and snippets.

@oneshadab
Created May 28, 2021 18:38
Show Gist options
  • Save oneshadab/45249316352de9d1d26369b766cf273c to your computer and use it in GitHub Desktop.
Save oneshadab/45249316352de9d1d26369b766cf273c to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
# Helper functions
log() {
echo >&2 -e "${1-}"
}
# Setup vars
source_file=$1
executable_file=/tmp/$(basename $1).out
coredump_file=$executable_file.core
# Remove previous coredumps if any
rm -f $coredump_file
# Build
log "> Build started..."
g++ -O2 --std=c++11 -g -o $executable_file $source_file
log "> Build successful"
# Run
log "> Running..."
time $executable_file
# Print stacktrace if coredump was created
if [ -e $coredump_file ]; then
gdb \
-q \
-batch \
-ex "log \n---STACKTRACE---\n" \
-ex "bt -frame-info source-and-location" \
$executable_file $coredump_file
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment