From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.freebsd.org (mx2.freebsd.org [96.47.72.81]) by sourceware.org (Postfix) with ESMTPS id 40B1D3858C66 for ; Tue, 20 Jun 2023 15:39:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 40B1D3858C66 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 4QlrR90xkgz3KxX; Tue, 20 Jun 2023 15:39:33 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (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 "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QlrR90BLRz3nWL; Tue, 20 Jun 2023 15:39:33 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687275573; 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: in-reply-to:in-reply-to:references:references; bh=FAGqnEyg1euObc1s3QdyaH7AL2rVV1stlhbByLfxJos=; b=gXKmyU3E6s72JosyjC0pgWwcQq/h9IXAOYJoOk9yuokRwHOCgT2Nw+vVJ+SiFFOBxbgsdF a2GjdJ9RJcjtzQgMG79TgPF6Fg2HYrwqewqRPWXlpL5Zug3lB7Rmb7QK0zQNZ6DnpfkYHm p01B1cm5q25GJLMvVPg+nB6WRSAF8eKMN/FYAorBuOx4Wr1QeoBQStKzpUFPc9eQK1Kk+A TjoR3D3+APFB+Kk6Rn0vWxx6uZvu6tkXYH9f2owPqzzsGmzD27X+35xclt23qWZnfTrE1Y tvyXIKWWNvT6SWFZcwkeNVtqCnJ8+WS23C2JPH5CnHQOUn4DkS6f42j6R0mIpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687275573; 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: in-reply-to:in-reply-to:references:references; bh=FAGqnEyg1euObc1s3QdyaH7AL2rVV1stlhbByLfxJos=; b=tFxBoGX4dWqXgHwi3eiTXVl9CEHGMiH4/8CVJkIhfwGQt2i6oou4P4n315x7CjBo7XoY9m L2HvU32yCVMH8rujAZPsXaBaWw/uPpuoHLXnPUeDW0l9YZGzeStgmlvXnCZuDzklL8sHfG WUbq58jiNYfTDuGgK1rdpA9yftPoS4ok8e8ArSusBtwYN16s1kgBD7xY2VJnMv+PZ0kil2 myHYhosfKjZcVSucQ3t4dc91SIuwQTs8WAyNUQny1VBf1ceBWyBl9+c+Pzr8CGYkEnA+V1 GMBgmVPLzR12+PH1ZC+XoN0+OedRvOJ4srO/aTnkVxebLnAtWkX6ltEJdeDuQw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687275573; a=rsa-sha256; cv=none; b=Rc0s+eS/f7I7cPQ60tQyq2WlTZ+KuelRRqeAdihbDz/WISlaEETrv6nKVFbKUN/0QSX7tV KlPun3Bqx3/cwuAI9/FRhFUwUqglvPswg/ePsQyd+HbWVhD/A87UN6twAB6LVUtvgPJyJ4 zPjQ6UOdLHtEaRG0pM2Gvz+nBSYa1JPMXnBEytlaTnVzyS7N7gOW3j7JPMZ2RvtZoZ8eCd FQqL+LjF+G/VuUnLU/O5bzCab1UEG4T5y99gDNd/i9TBtofVh/ZqUk27Gqa0EmwRyJoVIu hTnKsWal5ff1ESjahZBZumou/XhpySdgNcS+d865bNt3cEMjs924QOIC5dYsUQ== Received: from [IPV6:2601:648:8680:16b0:953a:c3a0:e269:2ef9] (unknown [IPv6:2601:648:8680:16b0:953a:c3a0:e269:2ef9]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4QlrR84Hnzz1346; Tue, 20 Jun 2023 15:39:32 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: Date: Tue, 20 Jun 2023 08:39:31 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Content-Language: en-US To: Tom Tromey , gdb-patches@sourceware.org References: <20230619-ax-new-v1-0-b26175d997a9@tromey.com> <20230619-ax-new-v1-6-b26175d997a9@tromey.com> From: John Baldwin Subject: Re: [PATCH 6/6] Make aop_map 'static' In-Reply-To: <20230619-ax-new-v1-6-b26175d997a9@tromey.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 6/19/23 2:06 PM, Tom Tromey wrote: > This changes aop_map to be 'static'. > > It also changes a runtime assertion into a static assert. I'm not > sure if this assert provides much value -- by construction, it can't > really fail -- but it's clearly more useful as a static assert than a > runtime one. > --- > gdb/ax-general.c | 40 +++++++++++++++++++++++++++++++++------- > gdb/ax.h | 30 ------------------------------ > 2 files changed, 33 insertions(+), 37 deletions(-) > > diff --git a/gdb/ax-general.c b/gdb/ax-general.c > index 7a37aff3d70..b1ee2753bd8 100644 > --- a/gdb/ax-general.c > +++ b/gdb/ax-general.c > @@ -294,7 +294,36 @@ ax_string (struct agent_expr *x, const char *str, int slen) > /* Functions for disassembling agent expressions, and otherwise > debugging the expression compiler. */ > > -struct aop_map aop_map[] = > +/* An entry in the opcode map. */ > +struct aop_map > + { > + > + /* The name of the opcode. Null means that this entry is not a > + valid opcode --- a hole in the opcode space. */ > + const char *name; > + > + /* All opcodes take no operands from the bytecode stream, or take > + unsigned integers of various sizes. If this is a positive number > + n, then the opcode is followed by an n-byte operand, which should > + be printed as an unsigned integer. If this is zero, then the > + opcode takes no operands from the bytecode stream. > + > + If we get more complicated opcodes in the future, don't add other > + magic values of this; that's a crock. Add an `enum encoding' > + field to this, or something like that. */ > + int op_size; > + > + /* The size of the data operated upon, in bits, for bytecodes that > + care about that (ref and const). Zero for all others. */ > + int data_size; > + > + /* Number of stack elements consumed, and number produced. */ > + int consumed, produced; > + }; > + > +/* Map of the bytecodes, indexed by bytecode number. */ > + > +static struct aop_map aop_map[] = > { > {0, 0, 0, 0, 0} > #define DEFOP(NAME, SIZE, DATA_SIZE, CONSUMED, PRODUCED, VALUE) \ > @@ -303,6 +332,9 @@ struct aop_map aop_map[] = > #undef DEFOP > }; > > +/* Check the size of the name array against the number of entries in > + the enum, to catch additions that people didn't sync. */ > +gdb_static_assert ((sizeof (aop_map) / sizeof (aop_map[0])) == aop_last); Maybe use ARRAY_SIZE here while you are at it? Looking around in ax-general.c more, it seems we already do runtime validation of potential indices before indexing the array, so I'm not sure the assertion adds much value and I'd be tempted to remove aop_last entirely. BTW, the various other places in ax-general.c that do the assertion are all using the expanded form of ARRAY_SIZE and would be a bit more readable perhaps if they used ARRAY_SIZE instead. -- John Baldwin