-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathsymbols_gen_common.sh
executable file
·50 lines (39 loc) · 1.19 KB
/
symbols_gen_common.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
#!/bin/bash
# This script is intended to be sourced from the other symbols_gen scripts.
# SCRIPT_DIR must be defined before sourcing this script.
DF_VER="$1"
DF_TYPE="$2"
DF_DIR="$3"
SYMBOLS_XML="${SCRIPT_DIR}/symbols.xml"
if [ -z "${DF_VER}" ]; then
echo "DF version (arg 1) must be specified"
exit 1
elif [ -z "${DF_TYPE}" ]; then
echo "DF distribution type (arg 2) must be specified"
exit 1
elif [ ! -w "${SYMBOLS_XML}" ]; then
echo "DFHack symbols not found or not writable: ${SYMBOLS_XML}"
exit 1
fi
write_symbol_table() {
platform="$1"
os_type="$2"
id_elem="$3"
offsets="$4"
vtables="$5"
tmpfile=`mktemp`
formatted_offsets=`echo "${offsets}" | sed "s/^/ /"`
formatted_vtables=`echo "${vtables}" | sed "s/^/ /"`
cat >${tmpfile} <<EOF
<symbol-table name='v0.${DF_VER} ${platform} ${DF_TYPE}' os-type='${os_type}'>
${id_elem}
${formatted_offsets}
${formatted_vtables}
</symbol-table>
EOF
start_pattern="<symbol-table.*${platform} ${DF_TYPE}"
end_pattern="<\/symbol-table>"
sed -i "/${start_pattern}/,/${end_pattern}/{/${end_pattern}/{x;r ${tmpfile}
D};d}" "${SYMBOLS_XML}"
rm "${tmpfile}"
}