From: Vladimír Čunát Date: Tue, 8 Aug 2023 10:13:22 +0000 (+0200) Subject: scripts/gen-cdefs.sh: allow generating variables X-Git-Tag: v6.0.3~7^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=288dfb3142ff110e2a6c2d6d52431769aa7c4e92;p=thirdparty%2Fknot-resolver.git scripts/gen-cdefs.sh: allow generating variables Sometimes it is useful to access a global variable from lua. --- diff --git a/daemon/lua/kres-gen.sh b/daemon/lua/kres-gen.sh index 0672dbcc8..d4052cc03 100755 --- a/daemon/lua/kres-gen.sh +++ b/daemon/lua/kres-gen.sh @@ -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, diff --git a/scripts/gen-cdefs.sh b/scripts/gen-cdefs.sh index ddb0aa7f6..d56ab86d0 100755 --- a/scripts/gen-cdefs.sh +++ b/scripts/gen-cdefs.sh @@ -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')"