#!/bin/bash

set -e

JAVA="java"
JAVAC="javac"
if [ ! -z "$JAVA_HOME" ]; then
    JAVA="$JAVA_HOME/bin/java"
    JAVAC="$JAVA_HOME/bin/javac"
fi

$JAVAC Reproducer.java

GDB_SCRIPT=`cat <<EOF
set logging file gdb.log
set logging on
set args -XX:+UnlockCommercialFeatures -XX:+FlightRecorder Reproducer
file $JAVA
handle SIGUSR1 nostop noprint
handle SIGUSR2 nostop noprint
handle SIGFPE nostop noprint
handle SIGSEGV nostop noprint
set breakpoint pending on
break VMError::report_and_die
break SystemDictionary::resolve_from_stream if ((char) class_name->_body[0]) == 'F'
commands 2
  break SystemDictionary::post_class_load_event
  continue
end
run
EOF`

echo "$GDB_SCRIPT" > inspect.gdb
gdb -x inspect.gdb
