Newer
Older
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
#!/bin/sh -e
if [ "$2" != types ] && [ "$2" != functions ]; then
echo "Usage: $0 libkres (types|functions)" >&2
echo " and input identifiers, one per line." >&2
echo " You need debug symbols in the library." >&2
exit 1
fi
if type -P gdb >/dev/null; then :; else
echo "Failed to find gdb" >&2
exit 1
fi
library="$(PATH="$(pwd)/lib:$(pkg-config libknot --variable=libdir)" type -P "$1.so")"
if [ -z "$library" ]; then
echo "$1 not found. Note: only .so platforms work currently." >&2
exit 1
fi
GDB="gdb -quiet -symbols=$library"
grep -v '^#\|^$' | while read ident; do
output="$(
if [ "$2" == functions ]; then
$GDB --ex "info functions ^$ident\$" --ex quit \
| sed '1,/^All functions/ d; /^File .*:$/ d'
continue
fi
# else types
case "$ident" in
struct\ *|union\ *|enum\ *)
$GDB --ex "ptype $ident" --ex quit \
| sed '1d; 2s/type = /\n/'
echo ";"
;;
*)
$GDB --ex "info types ^$ident\$" --ex quit \
| sed -e '1,/^File .*:$/ d' -e '/^File .*:$/,$ d'
# we need to stop early to remove ^^ multiple matches
;;
esac
)"
# abort on empty output
if [ -z "$(echo "$output" | tr -d \n)" ]; then
echo "Failed to find cdef of $ident" >&2
exit 1
fi
echo "$output" | grep -v '^$'
done