From nobody Tue May 23 14:19:48 2023 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 4QQc044Z3kz4CXSx; Tue, 23 May 2023 14:19:48 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QQc0447Ghz42xD; Tue, 23 May 2023 14:19:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684851588; 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=nzZu3lFIsgESrcIhi0hDJWjqvv29bh+PcFudtew9WsY=; b=rcyxhmeywVyOIfNaJ9wm4wuMJgsoHTe9hPXMnRoTXCjdrb7z3E4iwDXDzdhO2quQFCNtjF qulfiaRkOtnHPP8tI2/dGCcqscH0xMcdr0x9nV/gK/ySXSIhJwsYdbDc/aHpuKf/OhQvPD fK/UkcNG8pitSqo7Ina+mWYwIYlcg/QKzKkUHPKL6VOeJrSytcCS6J/FQTeREx9jJBOsvf 6v2bILypKiaxEw6HtWgfnh+t6FjY/srxwncA+RDktcfpwGcgFvxpfs0a0M7TCDglmdhM+H grjAUq6PeENi3xA3PVCuvYQ/4xnYSuUYYZXLLyaiQaqqnAPUY6F1Wq5+0Yr9nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684851588; 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=nzZu3lFIsgESrcIhi0hDJWjqvv29bh+PcFudtew9WsY=; b=CpAe8idjfoQ+wgywXh58Rht3Ppi602ZM8vpLteeVYWsh0kwAh/W1dds9HFZLkeIB11hPH5 WyljwGGlCAFbzXHwJott1muGCFCrGF586RHifeJ528iO3oER4uwZxs+mw1zSsf7YZWbJA/ v0s42lCoffJXUI/YLdUwuccZFiSoBGwMkPlFFGBwOpGfy9hb9iK0mmeFiFRevvk3rzDE58 fZd99FYWY06q6At0aU+7YzNCbjgCprP+L+JcwcSOY/6NVfjCY9uI05wuJ4YCX2ZemOXa/A i8SY/FWWzXLU0ngxCOgpDKUu1eobnQwYrv+vk21X2UBcqEItMjcL6uCMSiR8fA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684851588; a=rsa-sha256; cv=none; b=G3T0k9trcuv/4gz4ARfu/kJZ6STXAab89OyytDwdIG5cAf6rezW+8XCpfjWFv+S6GwEmXK W87Zyqds8rUydMSxLTxN5BpNW4aMYNAs8wSALyQ6F5QhNk+6mds39gAwQtOUbjM62wKwe5 bf/N64gazB8KzZqGPGd0CkAxjzP9mv4ykasCTGUttXHxSxeOzy2s2eE/SH97h0UHIGrAGj fqpK1ry12yZOB7/29Mp/uymKCvrShE2liQm3HuZe7Zwq2ZtqSTp3wapTOOSYyV2iu/Hu/5 CuBaYYqXTDgYXPFlm6D4BBkqUgZ7a8l5UNTkETSBSBca6fK3lazRzhjDHHIR2g== 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 4QQc043BbLz13QP; Tue, 23 May 2023 14:19:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34NEJmxo099876; Tue, 23 May 2023 14:19:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34NEJm9T099875; Tue, 23 May 2023 14:19:48 GMT (envelope-from git) Date: Tue, 23 May 2023 14:19:48 GMT Message-Id: <202305231419.34NEJm9T099875@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 1e136a9cbd3a - main - dtrace(1): add -d flag to dump D script post-dt_sugar 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1e136a9cbd3a9d137037e47a53c1dba3be7f6925 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=1e136a9cbd3a9d137037e47a53c1dba3be7f6925 commit 1e136a9cbd3a9d137037e47a53c1dba3be7f6925 Author: Christos Margiolis AuthorDate: 2023-05-23 14:18:39 +0000 Commit: Christos Margiolis CommitDate: 2023-05-23 14:18:39 +0000 dtrace(1): add -d flag to dump D script post-dt_sugar By specifying the -d flag, libdtrace will dump the D script after it has applied syntactical sugar transformations (e.g if/else). This is useful for both understanding what dt_sugar does, as well as debugging it. Reviewed by: markj Approved by: markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D38732 --- cddl/contrib/opensolaris/cmd/dtrace/dtrace.1 | 10 ++++++++-- cddl/contrib/opensolaris/cmd/dtrace/dtrace.c | 9 +++++++-- cddl/contrib/opensolaris/lib/libdtrace/common/dt_cc.c | 16 +++++++++++----- cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h | 3 ++- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/cddl/contrib/opensolaris/cmd/dtrace/dtrace.1 b/cddl/contrib/opensolaris/cmd/dtrace/dtrace.1 index 8724b27f4cbb..c3c7b4cdc818 100644 --- a/cddl/contrib/opensolaris/cmd/dtrace/dtrace.1 +++ b/cddl/contrib/opensolaris/cmd/dtrace/dtrace.1 @@ -20,7 +20,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 7, 2021 +.Dd February 24, 2023 .Dt DTRACE 1 .Os .Sh NAME @@ -29,7 +29,7 @@ .Sh SYNOPSIS .Nm .Op Fl 32 | Fl 64 -.Op Fl aACeFGhHlqSvVwZ +.Op Fl aACdeFGhHlqSvVwZ .Op Fl b Ar bufsz .Op Fl c Ar cmd .Op Fl D Ar name Op Ns = Ns value @@ -195,6 +195,12 @@ option. For a description of the set of tokens defined by the D compiler when invoking the C preprocessor, see .Fl X . +.It Fl d +Dump the D script to standard output, after syntactic transformations have been +applied. +For example, if-statements in D are implemented using such transformations: a +conditional clause in a probe body is replaced at compile-time by a separate +probe predicated on the original condition. .It Fl D Ar name Op Ns = Ns value Define .Ar name diff --git a/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c b/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c index 06eff2055c17..cdc476a43b08 100644 --- a/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c +++ b/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c @@ -77,7 +77,7 @@ typedef struct dtrace_cmd { #define E_USAGE 2 static const char DTRACE_OPTSTR[] = - "3:6:aAb:Bc:CD:ef:FGhHi:I:lL:m:n:o:p:P:qs:SU:vVwx:X:Z"; + "3:6:aAb:Bc:CdD:ef:FGhHi:I:lL:m:n:o:p:P:qs:SU:vVwx:X:Z"; static char **g_argv; static int g_argc; @@ -130,7 +130,7 @@ usage(FILE *fp) { static const char predact[] = "[[ predicate ] action ]"; - (void) fprintf(fp, "Usage: %s [-32|-64] [-aACeFGhHlqSvVwZ] " + (void) fprintf(fp, "Usage: %s [-32|-64] [-aACdeFGhHlqSvVwZ] " "[-b bufsz] [-c cmd] [-D name[=def]]\n\t[-I path] [-L path] " "[-o output] [-p pid] [-s script] [-U name]\n\t" "[-x opt[=val]] [-X a|c|s|t]\n\n" @@ -152,6 +152,7 @@ usage(FILE *fp) "\t-b set trace buffer size\n" "\t-c run specified command and exit upon its completion\n" "\t-C run cpp(1) preprocessor on script files\n" + "\t-d dump script after syntactic transformations\n" "\t-D define symbol when invoking preprocessor\n" "\t-e exit after compiling request but prior to enabling probes\n" "\t-f enable or list probes matching the specified function name\n" @@ -1559,6 +1560,10 @@ main(int argc, char *argv[]) g_cflags |= DTRACE_C_CPP; break; + case 'd': + g_cflags |= DTRACE_C_SUGAR; + break; + case 'D': if (dtrace_setopt(g_dtp, "define", optarg) != 0) dfatal("failed to set -D %s", optarg); diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_cc.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_cc.c index e63771c91e08..f3fda4af834e 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_cc.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_cc.c @@ -2478,10 +2478,7 @@ dt_compile(dtrace_hdl_t *dtp, int context, dtrace_probespec_t pspec, void *arg, "not referenced)\n", yypcb->pcb_sargv[argc - 1], argc - 1); } - /* - * Perform sugar transformations (for "if" / "else") and replace the - * existing clause chain with the new one. - */ + /* Perform sugar transformations. */ if (context == DT_CTX_DPROG) { dt_node_t *dnp, *next_dnp; dt_node_t *new_list = NULL; @@ -2492,8 +2489,17 @@ dt_compile(dtrace_hdl_t *dtp, int context, dtrace_probespec_t pspec, void *arg, next_dnp = dnp->dn_list; dnp->dn_list = NULL; - if (dnp->dn_kind == DT_NODE_CLAUSE) + if (dnp->dn_kind == DT_NODE_CLAUSE) { dnp = dt_compile_sugar(dtp, dnp); + if (cflags & DTRACE_C_SUGAR) { + dt_node_t *p; + + dt_printd(dnp, stdout, 0); + for (p = dnp->dn_list; p != NULL; + p = p->dn_list) + dt_printd(p, stdout, 0); + } + } /* append node to the new list */ new_list = dt_node_link(new_list, dnp); } diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h b/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h index f0bc83a7fc7b..af0213695f32 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h @@ -119,10 +119,11 @@ typedef struct dtrace_proginfo { #define DTRACE_C_PSPEC 0x0080 /* Interpret ambiguous specifiers as probes */ #define DTRACE_C_ETAGS 0x0100 /* Prefix error messages with error tags */ #define DTRACE_C_ARGREF 0x0200 /* Do not require all macro args to be used */ +#define DTRACE_C_SUGAR 0x0400 /* Dump D script post-dt_sugar */ #define DTRACE_C_DEFARG 0x0800 /* Use 0/"" as value for unspecified args */ #define DTRACE_C_NOLIBS 0x1000 /* Do not process D system libraries */ #define DTRACE_C_CTL 0x2000 /* Only process control directives */ -#define DTRACE_C_MASK 0x3bff /* mask of all valid flags to dtrace_*compile */ +#define DTRACE_C_MASK 0x3fff /* mask of all valid flags to dtrace_*compile */ extern dtrace_prog_t *dtrace_program_strcompile(dtrace_hdl_t *, const char *, dtrace_probespec_t, uint_t, int, char *const []);