Created
May 28, 2021 18:38
-
-
Save oneshadab/45249316352de9d1d26369b766cf273c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -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