add option to not generate a trace when making checkpoints

This commit is contained in:
bbracker 2022-03-01 03:13:01 +00:00
parent a8e8cfb838
commit da4d7de2bd
2 changed files with 31 additions and 12 deletions

View File

@ -1,7 +1,7 @@
#! /usr/bin/python3 #! /usr/bin/python3
import sys import sys
if len(sys.argv) != 8: if len(sys.argv) != 9:
sys.exit("""Error createGenCheckpointScript.py expects 7 args: sys.exit("""Error createGenCheckpointScript.py expects 7 args:
<TCP port number> <TCP port number>
<path to vmlinux> <path to vmlinux>
@ -9,7 +9,8 @@ if len(sys.argv) != 8:
<path to GDB checkpoint state dump> <path to GDB checkpoint state dump>
<path to GDB ram dump> <path to GDB ram dump>
<checkpoint pc address> <checkpoint pc address>
<number of times pc has already been hit before checkpoint>""") <number of times pc has already been hit before checkpoint>
<whether to generate a trace after hitting checkpoint>""")
tcpPort=sys.argv[1] tcpPort=sys.argv[1]
vmlinux=sys.argv[2] vmlinux=sys.argv[2]
@ -18,6 +19,7 @@ statePath=sys.argv[4]
ramPath=sys.argv[5] ramPath=sys.argv[5]
checkPC=sys.argv[6] checkPC=sys.argv[6]
checkPCoccurences=sys.argv[7] checkPCoccurences=sys.argv[7]
genTrace=sys.argv[8]
GDBscript = f""" GDBscript = f"""
# GDB config # GDB config
@ -54,7 +56,10 @@ set logging off
# Log main memory to a file # Log main memory to a file
print "GDB storing RAM to {ramPath}\\n" print "GDB storing RAM to {ramPath}\\n"
dump binary memory {ramPath} 0x80000000 0xffffffff dump binary memory {ramPath} 0x80000000 0xffffffff
"""
if (genTrace=="1"):
GDBscript+=\
"""
# Generate Trace Until End # Generate Trace Until End
maintenance packet Qqemu.Logging:1 maintenance packet Qqemu.Logging:1
# Do this by setting an impossible breakpoint # Do this by setting an impossible breakpoint
@ -62,6 +67,12 @@ b *0x1000
del 1 del 1
c c
""" """
else:
GDBscript+=\
"""
kill
q
"""
GDBscriptFile = open("genCheckpoint.gdb",'w') GDBscriptFile = open("genCheckpoint.gdb",'w')
GDBscriptFile.write(GDBscript) GDBscriptFile.write(GDBscript)
GDBscriptFile.close() GDBscriptFile.close()

View File

@ -6,11 +6,12 @@ recordFile="$tvDir/all.qemu"
traceFile="$tvDir/all.txt" traceFile="$tvDir/all.txt"
# Parse Commandline Arg # Parse Commandline Arg
if [ "$#" -ne 1 ]; then if [ "$#" -ne 2 ]; then
echo "genCheckpoint requires 1 argument: <num instrs>" >&2 echo "genCheckpoint requires 2 arguments: <num instrs> <whether to genTrace>" >&2
exit 1 exit 1
fi fi
instrs=$1 instrs=$1
genTrace=$2
if ! [ "$instrs" -eq "$instrs" ] 2> /dev/null if ! [ "$instrs" -eq "$instrs" ] 2> /dev/null
then then
echo "Error expected integer number of instructions, got $instrs" >&2 echo "Error expected integer number of instructions, got $instrs" >&2
@ -24,8 +25,14 @@ rawStateFile="$checkPtDir/stateGDB.txt"
rawRamFile="$checkPtDir/ramGDB.bin" rawRamFile="$checkPtDir/ramGDB.bin"
ramFile="$checkPtDir/ram.bin" ramFile="$checkPtDir/ram.bin"
if [ $genTrace -eq "1" ]; then
read -p "This scripts is going to create a checkpoint at $instrs instrs.
AND it's going to start generating a trace at that checkpoint.
Is that what you wanted? (y/n) " -n 1 -r
else
read -p "This scripts is going to create a checkpoint at $instrs instrs. read -p "This scripts is going to create a checkpoint at $instrs instrs.
Is that what you wanted? (y/n) " -n 1 -r Is that what you wanted? (y/n) " -n 1 -r
fi
echo echo
if [[ $REPLY =~ ^[Yy]$ ]] if [[ $REPLY =~ ^[Yy]$ ]]
then then
@ -36,8 +43,10 @@ then
sudo mkdir -p $checkPtDir sudo mkdir -p $checkPtDir
sudo chown -R cad:users $checkPtDir sudo chown -R cad:users $checkPtDir
sudo chmod -R a+rw $checkPtDir sudo chmod -R a+rw $checkPtDir
if [ $genTrace -eq "1" ]; then
sudo touch $outTraceFile sudo touch $outTraceFile
sudo chmod a+rw $outTraceFile sudo chmod a+rw $outTraceFile
fi
sudo touch $interruptsFile sudo touch $interruptsFile
sudo chmod a+rw $interruptsFile sudo chmod a+rw $interruptsFile
sudo touch $rawStateFile sudo touch $rawStateFile
@ -56,8 +65,7 @@ then
echo "It occurs ${occurences} times before the ${instrs}th instr." echo "It occurs ${occurences} times before the ${instrs}th instr."
# Create GDB script because GDB is terrible at handling arguments / variables # Create GDB script because GDB is terrible at handling arguments / variables
./createGenCheckpointScript.py $tcpPort $imageDir/vmlinux $instrs $rawStateFile $rawRamFile $pc $occurences ./createGenCheckpointScript.py $tcpPort $imageDir/vmlinux $instrs $rawStateFile $rawRamFile $pc $occurences $genTrace
# GDB+QEMU # GDB+QEMU
echo "Starting QEMU in replay mode with attached GDB script at $(date +%H:%M:%S)" echo "Starting QEMU in replay mode with attached GDB script at $(date +%H:%M:%S)"
(qemu-system-riscv64 \ (qemu-system-riscv64 \
@ -77,7 +85,7 @@ then
./fixBinMem "$rawRamFile" "$ramFile" ./fixBinMem "$rawRamFile" "$ramFile"
#echo "Creating truncated trace at $(date +%H:%M:%S)" #echo "Creating truncated trace at $(date +%H:%M:%S)"
#tail -n+$instrs "$tvDir/$traceFile" > "$checkPtDir/$traceFile" #tail -n+$instrs "$tvDir/$traceFile" > "$checkPtDir/$traceFile"
echo "Checkpoint completed at $(date +%H:%M:%S)" read -p "Checkpoint completed at $(date +%H:%M:%S)" -n 1 -r
# Cleanup # Cleanup
echo "Elevating permissions to restrict write access to $checkPtDir" echo "Elevating permissions to restrict write access to $checkPtDir"