#!/bin/bash

# Check for exception unwinding support within libunwind
eu-readelf -a /usr/lib/libunwind.so | grep ' _Unwind_RaiseException' > /dev/null
if [ $? -ne 0 ]
then
    echo "Your /usr/lib/libunwind.so doesn't seem to have exception unwinding support"
fi
echo "--- Compiling ---"
g++ -fnon-call-exceptions sigfpe.cpp -o sigfpe
g++ -DSHOW_IP -fnon-call-exceptions sigfpe.cpp -o sigfpe_ip

echo
echo "--- Executing ---"
echo "*** Running with gcc's unwind ***"
./sigfpe
echo "*** Running with libunwind's unwind ***"
LD_PRELOAD=/usr/lib/libunwind.so ./sigfpe

echo
echo "--- Printing ip and before flag ---"
echo "*** Running with gcc's unwind ***"
./sigfpe_ip
echo "*** Running with libunwind's unwind ***"
LD_PRELOAD=/usr/lib/libunwind.so ./sigfpe_ip

