From nobody Mon Nov 04 20:31:05 2024 X-Original-To: dev-commits-src-all@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 4Xj35P73Ltz5cWWb; Mon, 04 Nov 2024 20:31:05 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xj35P6WvNz4Npx; Mon, 4 Nov 2024 20:31:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730752265; 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=IAvwRpXJUtjyUtzx37tUGf68NBIq5pHWl8WJJ2hmPJY=; b=nHumxyMKQ5R8hPQ4LtukZ/5FkjTqueLjD1AQMomKrFo2bBjk5jbDOxRw5QrZ6p8ZaPnfJG FFzSoSiWEjNm8IgfVCI1A1piEPhzraQcNksCMDqL8qAKS/yJNAnoRXIn71pRWEbl0mNp2P eGZ9BeSIh0B3YkZm4o7C+kcYjgPESSckY2qDJl7oGv5bmsvoAKAWFWIke+DdymeQowB1lr 0Ib/YTYxrWhO1Y+fGlziw0CsLNI9TyArVCOtS9aL9+A9x8WD9pFL0g1oa/akcdX1s9TH+a GsrSCTz0wAhIgdrvqC11IkTW1OuxX5i1MXBD3szQOyG+m0pCK/2C9Ku6tT4nQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730752265; 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=IAvwRpXJUtjyUtzx37tUGf68NBIq5pHWl8WJJ2hmPJY=; b=K06hjR1vnTFewTFQ9zIv1pJReP/BejappHDBgar+GzfzbPBr4RsdJf8yc3gatTPcG4JjTb mg2gTBGGFKzIH/EHPnBpHSqP6Oob+eHo4Qoe+C1SIDRHctNsiMs+PyhnJXgJqAfR3UUfwE 6MsJbFI/Qmtzbx//cFqFGDeW7OCDuWQA5PqnafE4jnd3idVyU6hLCEtrz3nFhSw0MqCjxh RV9cfDtZPdgR+Ex1vljoDoPYth+1T958fTrVEixWyKzHyly7c8OMLuXAeFWxsGGvOCTXmC TAMNrxv4COT32JQjYF2P0zlCHTxXzhZNHWddJt+OqOCZaFy376js/swESyRnKw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730752265; a=rsa-sha256; cv=none; b=SyoEyjQEsG9fenHz/zb5hTuctlTU2ezXD51pRm3J+1IhksVdpAGebc22dxlOJvaAFtVlr9 3h8yyOXoz0Vk3YK+ddXKf5+u7x/82xXtkkDSidJikafjKVoDrEsF5LzyzjRw69bwm82Xh5 WY7B0rekcmbNk1Hl92wpmyeZa/xCk7o1VR6HHYn0jUgWMi1w9B/oXxwXjAyf07guRxFRw6 nc65NrE6tm7z+4A7PtEAhOxDN34jDzR14MBfAEVisIrepVp1YsLgX+GfY9QGwCW11J6Ky1 BglPUfvBNkNlppP5+njI1cJVYxlqnRzbUUIb+wTe4WfxThxH7f1e4HFNMNeqMw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Xj35P5zXsznq5; Mon, 4 Nov 2024 20:31:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4A4KV5oY087709; Mon, 4 Nov 2024 20:31:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A4KV5Gv087706; Mon, 4 Nov 2024 20:31:05 GMT (envelope-from git) Date: Mon, 4 Nov 2024 20:31:05 GMT Message-Id: <202411042031.4A4KV5Gv087706@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Simon J. Gerraty" Subject: git: a4e7810f7137 - main - debug.sh check for :debug_add: List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: sjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a4e7810f71376ee43c47b6b092d11e582c80fe9d Auto-Submitted: auto-generated The branch main has been updated by sjg: URL: https://cgit.FreeBSD.org/src/commit/?id=a4e7810f71376ee43c47b6b092d11e582c80fe9d commit a4e7810f71376ee43c47b6b092d11e582c80fe9d Author: Simon J. Gerraty AuthorDate: 2024-11-04 20:30:01 +0000 Commit: Simon J. Gerraty CommitDate: 2024-11-04 20:30:01 +0000 debug.sh check for :debug_add: When we match a tag and turn tracing, see if we have any $DEBUG_ON:debug_add:tag in DEBUG_SH and if so add the new tag. This allows for more focused debugging during boot. Reviewed by: stevek --- libexec/rc/debug.sh | 84 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 11 deletions(-) diff --git a/libexec/rc/debug.sh b/libexec/rc/debug.sh index b098f0b359b5..db9ed8c94b6c 100755 --- a/libexec/rc/debug.sh +++ b/libexec/rc/debug.sh @@ -31,6 +31,11 @@ # If the '-o' flag is given, tracing is turned off unless there # was a matched "tag", useful for functions too noisy to tace. # +# Further; when we set "DEBUG_ON" if we find +# "$DEBUG_ON:debug_add:tag" in "DEBUG_SH" we will +# add the new "tag" to "DEBUG_SH" so it only has effect after that +# point. +# # DebugOff turns tracing on if any "tag" matches "DEBUG_OFF" or # off if any "tag" matches "DEBUG_ON". This allows nested # functions to not interfere with each other. @@ -78,7 +83,7 @@ # Simon J. Gerraty # RCSid: -# $Id: debug.sh,v 1.41 2024/10/22 17:57:22 sjg Exp $ +# $Id: debug.sh,v 1.42 2024/10/30 18:23:19 sjg Exp $ # # @(#) Copyright (c) 1994-2024 Simon J. Gerraty # @@ -97,30 +102,82 @@ _DEBUG_SH=: Myname=${Myname:-`basename $0 .sh`} -# We want to use local if we can -# if isposix-shell.sh has been sourced isPOSIX_SHELL will be set -# as will local -case "$local" in -local|:) ;; -*) +DEBUGGING= +DEBUG_DO=: +DEBUG_SKIP= +export DEBUGGING DEBUG_DO DEBUG_SKIP + +case "$isPOSIX_SHELL,$local" in +:,:|:,local|false,:) ;; # sane +*) # this is the bulk of isposix-shell.sh if (echo ${PATH%:*}) > /dev/null 2>&1; then + # true should be a builtin, : certainly is + isPOSIX_SHELL=: + # you need to eval $local var local=local + : KSH_VERSION=$KSH_VERSION + case "$KSH_VERSION" in + Version*) local=: ;; # broken + esac else + isPOSIX_SHELL=false local=: + false() { + return 1 + } fi ;; esac -DEBUGGING= -DEBUG_DO=: -DEBUG_SKIP= -export DEBUGGING DEBUG_DO DEBUG_SKIP +is_posix_shell() { + $isPOSIX_SHELL + return +} + + +## +# _debugAdd match +# +# Called from _debugOn when $match also appears in $DEBUG_SH with +# a suffix of :debug_add:tag we will add tag to DEBUG_SH +# +_debugAdd() { + eval $local tag + + for tag in `IFS=,; echo $DEBUG_SH` + do + : tag=$tag + case "$tag" in + $1:debug_add:*) + if is_posix_shell; then + tag=${tag#$1:debug_add:} + else + tag=`expr $tag : '.*:debug_add:\(.*\)'` + fi + case ",$DEBUG_SH," in + *,$tag,*) ;; + *) set -x + : _debugAdd $1 + DEBUG_SH=$DEBUG_SH,$tag + set +x + ;; + esac + ;; + esac + done + export DEBUG_SH +} + ## # _debugOn match first # # Actually turn on tracing, set $DEBUG_ON=$match # +# Check if $DEBUG_SH contains $match:debug_add:* and call _debugAdd +# to add the suffix to DEBUG_SH. This useful when we only want +# to trace some script when run under specific circumstances. +# # If we have included hooks.sh $_HOOKS_SH will be set # and if $first (the first arg to DebugOn) is suitable as a variable # name we will run ${first}_debugOn_hooks. @@ -133,6 +190,11 @@ _debugOn() { DEBUG_DO= DEBUG_SKIP=: DEBUG_X=-x + # do this firt to reduce noise + case ",$DEBUG_SH," in + *,$1:debug_add:*) _debugAdd $1;; + *,$2:debug_add:*) _debugAdd $2;; + esac set -x DEBUG_ON=$1 case "$_HOOKS_SH,$2" in