]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
scripts/gen-cdefs.sh: allow generating variables
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 8 Aug 2023 10:13:22 +0000 (12:13 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 12 Sep 2023 10:12:55 +0000 (12:12 +0200)
Sometimes it is useful to access a global variable from lua.

daemon/lua/kres-gen.sh
scripts/gen-cdefs.sh

index 0672dbcc8922373f977fbe9e003883c710f02b76..d4052cc0300153c9c9d5f93b0657d02bb7357a5a 100755 (executable)
@@ -149,12 +149,11 @@ ${CDEFS} ${LIBKRES} types <<-EOF
        struct kr_query_data_src
 EOF
 
-# static variables; these lines might not be simple to generate
-printf "
-kr_layer_t kr_layer_t_static;
-_Bool kr_dbg_assertion_abort;
-int kr_dbg_assertion_fork;
-"
+${CDEFS} ${LIBKRES} variables <<-EOF
+       kr_layer_t_static
+       kr_dbg_assertion_abort
+       kr_dbg_assertion_fork
+EOF
 
 printf "
 typedef int32_t (*kr_stale_cb)(int32_t ttl, const knot_dname_t *owner, uint16_t type,
index ddb0aa7f60974f0050512ae7b90d746d74f5ad54..d56ab86d04901a6b0f0ec2aa10796fd4a7b5e146 100755 (executable)
@@ -2,8 +2,8 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 set -o pipefail -o errexit
 
-if [ "$2" != types ] && [ "$2" != functions ]; then
-       echo "Usage: $0 libkres (types|functions)" >&2
+if [ "$2" != types ] && [ "$2" != functions ] && [ "$2" != variables ]; then
+       echo "Usage: $0 libkres (types|functions|variables)" >&2
        echo "    and input identifiers, one per line." >&2
        echo "    You need debug symbols in the library." >&2
        echo
@@ -47,7 +47,7 @@ grep -v '^#\|^$' | while read -r ident; do
        if [ "$2" = functions ]; then
                output="$("${GDB[@]}" --ex "info functions ^$ident\$" \
                                | sed '0,/^All functions/ d; /^File .*:$/ d')"
-       else # types
+       elif [ "$2" = types ]; then
                case "$ident" in
                        struct\ *|union\ *|enum\ *)
                                output="$("${GDB[@]}" --ex "ptype $ident" \
@@ -63,6 +63,11 @@ grep -v '^#\|^$' | while read -r ident; do
                                                | sed "0,/^type = /s/^type = /typedef /; $ s/$/ $ident;/")"
                                ;;
                esac
+       elif [ "$2" = variables ]; then
+               output="$("${GDB[@]}" --ex "info variables -q ^$ident\$" \
+                               | sed -e '0,/^File .*:$/ d' -e '/^File .*:$/,$ d')"
+       else
+               exit 1
        fi
        # LuaJIT FFI blows up on "uint" type
        output="$(echo "$output" | sed 's/\buint\b/unsigned int/g')"