-
Notifications
You must be signed in to change notification settings - Fork 1
/
grade-functions.sh
59 lines (50 loc) · 1.36 KB
/
grade-functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
verbose=false
if [ "x$1" = "x-v" ]
then
verbose=true
out=/dev/stdout
err=/dev/stderr
else
out=/dev/null
err=/dev/null
fi
if gmake --version >/dev/null 2>&1; then make=gmake; else make=make; fi
pts=5
timeout=30
preservefs=n
qemu=`$make -s --no-print-directory which-qemu`
echo_n () {
# suns can't echo -n, and Mac OS X can't echo "x\c"
# assume argument has no doublequotes
awk 'BEGIN { printf("'"$*"'"); }' </dev/null
}
run () {
# Find the address of the kernel readline function,
# which the kernel monitor uses to read commands interactively.
brkaddr=`grep 'readline$' obj/kern/kernel.sym | sed -e's/ .*$//g'`
#echo "brkaddr $brkaddr"
# Generate a unique GDB port
port=$(expr `id -u` % 5000 + 25000)
# Run qemu, setting a breakpoint at readline(),
# and feeding in appropriate commands to run, then quit.
t0=`date +%s.%N 2>/dev/null`
(
ulimit -t $timeout
$qemu -nographic $qemuopts -serial file:jos.out -monitor null -s -S -p $port
) >$out 2>$err &
(
echo "target remote localhost:$port"
if [ "x$qemuphys" = "x" ]; then
echo "br *0x$brkaddr"
else
echo "br *(0x$brkaddr-0xf0000000)"
fi
echo c
) > jos.in
sleep 1
gdb -batch -nx -x jos.in > /dev/null 2>&1
t1=`date +%s.%N 2>/dev/null`
time=`echo "scale=1; ($t1-$t0)/1" | sed 's/.N/.0/g' | bc 2>/dev/null`
time="(${time}s)"
rm jos.in
}