]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
Various improvements how we use gdb and sed in gen-cdefs.sh (requires GNU sed)
authorOndřej Surý <ondrej@sury.org>
Mon, 19 Dec 2016 10:26:43 +0000 (11:26 +0100)
committerOndřej Surý <ondrej@sury.org>
Mon, 19 Dec 2016 10:27:53 +0000 (11:27 +0100)
scripts/gen-cdefs.sh

index 20341a450b1c987fe50ed92ab2b818c0f8c4a579..fea3dc6f907a3e79d436cf0d6691fc42415121c0 100755 (executable)
@@ -12,9 +12,20 @@ if ! command -v gdb >/dev/null; then
        exit 1
 fi
 
+if ! command -v sed >/dev/null; then
+       echo "Failed to find GNU sed" >&2
+       exit 1
+fi
+
+if ! sed --version | head -1 | grep -q "GNU sed"; then
+       echo "GNU sed required to run this script" >&2
+fi
+
+# be very precise with the directories for libraries to not pick wrong library
 case "$1" in
-    libknot) library="$(PATH="$(pkg-config libknot --variable=libdir)" command -v "$1.so")" ;;
-    *) library="$(PATH="$(pwd)/lib" command -v "$1.so")"
+       libknot) library="$(PATH="$(pkg-config libknot --variable=libdir)" command -v "$1.so")" ;;
+       libzscanner) library="$(PATH="$(pkg-config libzscanner --variable=libdir)" command -v "$1.so")" ;;
+       *) library="$(PATH="$(pwd)/lib" command -v "$1.so")"
 esac
 
 if [ -z "$library" ]; then
@@ -22,31 +33,28 @@ if [ -z "$library" ]; then
        exit 1
 fi
 
-GDB="gdb -quiet -symbols=$library"
+GDB="gdb -n -quiet -batch -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
+       if [ "$2" = functions ]; then
+               output=$($GDB -iex "set width unlimited" --ex "info functions ^$ident\$" \
+                               | sed '0,/^All functions/ d; /^File .*:$/ d')
+       else # types
                case "$ident" in
                        struct\ *|union\ *|enum\ *)
-                               $GDB --ex "ptype $ident" --ex quit \
-                                       | sed '1d; 2s/type = /\n/'
-                               echo ";"
+                               output=$($GDB -iex "set width unlimited" --ex "ptype $ident" \
+                                               | sed '0,/^type = /s/^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
+                               output=$($GDB -iex "set width unlimited" --ex "info types ^$ident\$" \
+                                               | sed -e '0,/^File .*:$/ d' -e '/^File .*:$/,$ d')
+                                               # we need to stop early to remove ^^ multiple matches
                                ;;
                esac
-       )"
+       fi
+
        # abort on empty output
-       if [ -z "$(echo "$output" | tr -d \n)" ]; then
+       if [ -z "$(echo "$output" | tr -d "\n;")" ]; then
                echo "Failed to find cdef of $ident" >&2
                exit 1
        fi