From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 6/6] Make aop_map 'static'
Date: Mon, 19 Jun 2023 15:06:44 -0600 [thread overview]
Message-ID: <20230619-ax-new-v1-6-b26175d997a9@tromey.com> (raw)
In-Reply-To: <20230619-ax-new-v1-0-b26175d997a9@tromey.com>
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);
/* Disassemble the expression EXPR, writing to F. */
void
@@ -317,12 +349,6 @@ ax_print (struct ui_file *f, struct agent_expr *x)
gdb_printf (f, _(" %02x"), i);
gdb_printf (f, _("\n"));
- /* Check the size of the name array against the number of entries in
- the enum, to catch additions that people didn't sync. */
- if ((sizeof (aop_map) / sizeof (aop_map[0]))
- != aop_last)
- error (_("GDB bug: ax-general.c (ax_print): opcode map out of sync"));
-
for (i = 0; i < x->buf.size ();)
{
enum agent_op op = (enum agent_op) x->buf[i];
diff --git a/gdb/ax.h b/gdb/ax.h
index 0e82ed9e313..1fdecb2f9e5 100644
--- a/gdb/ax.h
+++ b/gdb/ax.h
@@ -221,36 +221,6 @@ extern void ax_string (struct agent_expr *x, const char *str, int slen);
/* Disassemble the expression EXPR, writing to F. */
extern void ax_print (struct ui_file *f, struct agent_expr * EXPR);
-/* 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. */
-extern struct aop_map aop_map[];
-
/* Given an agent expression AX, analyze and update its requirements. */
extern void ax_reqs (struct agent_expr *ax);
--
2.39.2
next prev parent reply other threads:[~2023-06-19 21:06 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-19 21:06 [PATCH 0/6] C++-ify and simplify agent expressions Tom Tromey
2023-06-19 21:06 ` [PATCH 1/6] Remove mem2hex Tom Tromey
2023-06-19 21:06 ` [PATCH 2/6] Use gdb::byte_vector in agent_expr Tom Tromey
2023-06-19 21:06 ` [PATCH 3/6] Use std::vector<bool> for agent_expr::reg_mask Tom Tromey
2023-06-20 15:30 ` John Baldwin
2023-06-20 17:04 ` Tom Tromey
2023-06-19 21:06 ` [PATCH 4/6] Simplify agent_expr constructor Tom Tromey
2023-06-19 21:06 ` [PATCH 5/6] Use bool for agent_expr::tracing Tom Tromey
2023-06-20 15:31 ` John Baldwin
2023-06-20 17:04 ` Tom Tromey
2023-06-19 21:06 ` Tom Tromey [this message]
2023-06-20 15:39 ` [PATCH 6/6] Make aop_map 'static' John Baldwin
2023-06-20 17:12 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230619-ax-new-v1-6-b26175d997a9@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).