From nobody Mon Jul 6 19:44:13 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gvFDF5XNfz6k5V9 for ; Mon, 06 Jul 2026 19:44:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gvFDF54Ksz3nvX for ; Mon, 06 Jul 2026 19:44:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1783367053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x5WxCErwc6UXOSEp1mVXHQZDML581pxQ96DOlijXNrY=; b=kxNzYIBm46dBo95kE8s+6Mg/Cm68VOTtOgLTpQCUXeUn0EAWKl3hnwDupLO6IReW+T1aLC /q8aZcMwoaG+cufv0j/JCy2r92xbVkqdFNOOS6RivaDUEVez358M9gEK4HAu8DORkMIrFn O4iMMunFEpWSnuUHAcMZ5jRTU/IhcHTr0qi/DM+ih26iU9uMWH00L/ErBvi7Bp/L0OTcdz N5UcidKoah3qeWJSHu30QYT+2pZo5bB0ueO58wUivbTZWz4QNW8UPtVCQGwQMPCrZpD84C FHN0LPo97goYE9jljAaJRIhdMi0XW12VpraTaq9kl5EAvEnE0k7F+G8OlkOiRg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1783367053; a=rsa-sha256; cv=none; b=B757PCmn54H2oIuISyG2JWo/WlFcNGbrUdqnoOIQNnojWnQsBJa3C+T5Rdz6VnvSlglBzm JkNsHbxccTmu/dJ00LR90OQ5N6Y7X3/2NeUBdTfDn/Erzh55GrZ0kLHF9wHg07fxdNX7JW RN51vBT4yzdC+7MT4jKyCpxnmzxwJjTmNhcdWSE2fs45FY9agPkFJMIjq61A2goNbU8dvc FKqQMv7Iy6XgLtybEsb1k6LD+/nj/e6jwb3DifOB/ghmoPnPc1fHVj7CZO6s8xDqXyhM7j Bm/YgaBZ1envhCPXVXoxQV5GrtY3ogk3kKvQx+p58oc4ZBTCGase3xMrX3HwUg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1783367053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x5WxCErwc6UXOSEp1mVXHQZDML581pxQ96DOlijXNrY=; b=yiPiNfgSVS4CMi5F8S6iDSICJdFDFvP8npnjdcekS1dbaa18xnzEPcl8c3SyvW6FCRBfw+ d4yBYb2SbTuWd9wEHoXNfbVFC+parEEP24hexhq/lAKwUs1GM5BdXKXwNjhH0OVp2HTdJJ vGK+U7dbqL+BHjdkelysurO8N69ABhCkuvtlQed7qKIUqOx/ntigt2ggLpaDlIYwLFOeZc us/6JngzzEUHyGbnccjPdYLlMTQ60aq8EEI1n8ad1ia281jaM/T2ysm/PBprmQ83SGBEDj 86Q2Hz5seS3QoNTVsNY3oPcjYwGx4EQESMf+dJhzjWZEFJuPLr9xH7Sl+rNeDA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gvFDF3kMqz1HDv for ; Mon, 06 Jul 2026 19:44:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3ff3a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 06 Jul 2026 19:44:13 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: 8b197806dcdf - main - libsysdecode: Teach mktables to handle enums List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8b197806dcdff5673dd4f77a97bf46035d14db2a Auto-Submitted: auto-generated Date: Mon, 06 Jul 2026 19:44:13 +0000 Message-Id: <6a4c058d.3ff3a.44bb1175@gitrepo.freebsd.org> The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=8b197806dcdff5673dd4f77a97bf46035d14db2a commit 8b197806dcdff5673dd4f77a97bf46035d14db2a Author: Dag-Erling Smørgrav AuthorDate: 2026-07-06 19:41:15 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-07-06 19:41:15 +0000 libsysdecode: Teach mktables to handle enums While here, clean up and simplify the existing code. MFC after: 1 week Reviewed by: glebius, jhb Differential Revision: https://reviews.freebsd.org/D57993 --- lib/libsysdecode/mktables | 59 +++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/lib/libsysdecode/mktables b/lib/libsysdecode/mktables index e7dde6f8e2ff..df742ff62f39 100644 --- a/lib/libsysdecode/mktables +++ b/lib/libsysdecode/mktables @@ -48,35 +48,54 @@ fi all_headers= # -# Generate a table C #definitions. The including file can define the -# TABLE_NAME(n), TABLE_ENTRY(x), and TABLE_END macros to define what -# the tables map to. +# Generate a table from C preprocessor symbol definitions. The +# including file can define the TABLE_START(n), TABLE_ENTRY(x), and +# TABLE_END macros to define what the tables map to. # gen_table() { - local name grep file excl filter - name=$1 - grep=$2 - file=$3 - excl=$4 + local name=$1 grep=$2 file=$3 excl=$4 - if [ -z "$excl" ]; then - filter="cat" - else - filter="egrep -v" + cat <<_EOF_ +TABLE_START(${name}) +_EOF_ + if [ -e "${include_dir}/${file}" ]; then + all_headers="${all_headers:+${all_headers} }${file}" + sed -nE ${excl:+-e "/${excl}/d"} \ + -e "/^#[[:space:]]*define[[:space:]]+${grep}/p" \ + "${include_dir}/${file}" | \ + sed -Ee 's/.*define[[:space:]]+([^[:space:]]+)\>.*/TABLE_ENTRY(\1)/' fi +cat <<_EOF_ +TABLE_END + +_EOF_ +} + +# +# Generate a table from C enum definitions. The including file can +# define the TABLE_START(n), TABLE_ENTRY(x), and TABLE_END macros to +# define what the tables map to. Works with most enum definitions as +# long as each constant is on a line by itself. +# +gen_table_enum() +{ + local name=$1 grep=$2 file=$3 excl=$4 + cat <<_EOF_ TABLE_START(${name}) _EOF_ if [ -e "${include_dir}/${file}" ]; then all_headers="${all_headers:+${all_headers} }${file}" - egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \ - $include_dir/$file | ${filter} ${excl} | \ - awk '{ for (i = 1; i <= NF; i++) \ - if ($i ~ /define/) \ - break; \ - ++i; \ - printf "TABLE_ENTRY(%s)\n", $i }' + # preprocess the header + ${CPP:-${CC:-cc} -E} "${include_dir}/${file}" | + # filter out directives and apply exclusion + sed -Ee '/^#/d' ${excl:+-e "/${excl}/d"} | + # extract all enum definitions + awk '/^(typedef[[:space:]]*)?enum([[:space:]].*)?\{/, + /^\}([[:space:]].*)?;/' | + # pick out the constants we want + sed -Ene 's/^[[:space:]]*('"${grep}"')\>.*/TABLE_ENTRY(\1)/p' fi cat <<_EOF_ TABLE_END @@ -127,7 +146,7 @@ gen_table "rusage" "RUSAGE_[A-Z]+[[:space:]]+[-0-9]+" "sys/ gen_table "schedpolicy" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sys/sched.h" gen_table "sendfileflags" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h" gen_table "shmatflags" "SHM_[A-Z]+[[:space:]]+[0-9]{6}" "sys/shm.h" -gen_table "shutdownhow" "SHUT_[A-Z]+[[:space:]]+SHUT_[A-Z]+" "sys/socket.h" +gen_table_enum "shutdownhow" "SHUT_[A-Z]+" "sys/socket.h" gen_table "sigbuscode" "BUS_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h" gen_table "sigchldcode" "CLD_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h" gen_table "sigfpecode" "FPE_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"