-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtkwave.sh
executable file
·86 lines (78 loc) · 2.1 KB
/
gtkwave.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
if [[ "$#" == 0 || "$1" =~ ^-.*$ ]]
then
echo "usage:$0 trace_file [gtkwave options ...]" >&2
exit 1
fi
trace=$1
shift
gtkwave=gtkwave
shmidcat=shmidcat
if [ -n "$GTKWAVE_PATH" ]
then
gtkwave=${GTKWAVE_PATH}/gtkwave
shmidcat=${GTKWAVE_PATH}/shmidcat
fi
if [ ! -e "$trace" ]
then
echo "Trace file '$trace' does not exist"
echo "Attempting to create it..."
mkdir -p $(dirname "$trace") || exit 1
mkfifo "$trace" || exit 1
echo "Trace file successfully created."
fi
if [ ! -p "$trace" ]
then
echo "Error: '$trace' is not a pipe, live view will not work properly." >&2
echo "Please create it using mkfifo" >&2
exit 1
fi
# kill coporoc on sigterm
# so that no pending process remain
gtkwave_pid=
COPROC_PID=
term()
{
if [ -n "${COPROC_PID}" ]
then
echo "Terminating shmidcat process"
if kill -0 ${COPROC_PID} 2>/dev/null
then
kill -9 "${COPROC_PID}"
fi
fi
if [ -n "${gtkwave_pid}" ]
then
echo "Terminating gtkwave process"
if kill -0 ${gtkwave_pid} 2>/dev/null
then
kill -9 "${gtkwave_pid}"
fi
fi
exit 0
}
trap 'term' SIGTERM SIGINT
# run shmidcat in background but gets 1st stdout line which contains
# the shared memory id
# shmidcat will stop when the tracing side stops iff trace has been started
echo "Opening the trace file '$trace'."
coproc $shmidcat $trace
echo "Waiting for shared memory creation..."
read SHMID <&${COPROC[0]}
# launch gtkwave if we got an ID
if [[ -n "$SHMID" ]]
then
echo "Created shared memory trace with id $SHMID"
echo "Starting $gtkwave -I $SHMID $@"
echo "Warning: if gtkwave fails because of unknown option '-p', you might"
echo " to check that you have the modified gtkwave with remote tcl"
echo " control over a tcp socket wich adds this option. You can also"
echo " edit the gtkwave launch configuration to remove the '-p 6789'"
echo " argument"
$gtkwave -I $SHMID "$@" &
gtkwave_pid=$!
wait
else
echo "Failed to create shared memory trace." >&2
exit 1
fi