From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCHv3 6/9] gdbarch: improve generation of validation in gdbarch getters
Date: Fri, 10 Mar 2023 18:43:15 +0000 [thread overview]
Message-ID: <e972a5d4ebc3b7b9ba966827923fd46f2acac433.1678473293.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1678473293.git.aburgess@redhat.com>
We currently generate some validation code within the gdbarch getter
methods.
This commit adjusts the algorithm used to generate this validation
slightly to make the gdbarch.py code (I think) clearer; there's no
significant changes to what is generated.
The validation algorithm for gdbarch values is now:
- If the Value has an 'invalid' field that is a string, use that for
validation,
- If the Value has its 'predicate' field set to true, then check the
predicate returns true, this ensures the predicate has been
called,
- If the Value has its 'invalid' field set to True, or the Value has
'postdefault' field, then check the fields has changed from its
initial value,
- Otherwise no validation is performed.
The only changes after this commit are:
- Some comments change slightly, and
- For 'gcore_bfd_target' and 'max_insn_length' we now validate by
calling the predicate rather than checking the field value
directly, the underlying check being performed is unchanged
though.
There should be no user visible changes after this commit.
---
gdb/gdbarch.c | 18 +++++++++---------
gdb/gdbarch.py | 16 +++++++---------
2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 064afd7c226..6018c632f91 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -1658,7 +1658,7 @@ int
gdbarch_wchar_signed (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
- /* Check variable changed from pre-default. */
+ /* Check variable changed from its initial value. */
gdb_assert (gdbarch->wchar_signed != -1);
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_wchar_signed called\n");
@@ -1710,7 +1710,7 @@ int
gdbarch_addr_bit (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
- /* Check variable changed from pre-default. */
+ /* Check variable changed from its initial value. */
gdb_assert (gdbarch->addr_bit != 0);
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_addr_bit called\n");
@@ -1728,7 +1728,7 @@ int
gdbarch_dwarf2_addr_size (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
- /* Check variable changed from pre-default. */
+ /* Check variable changed from its initial value. */
gdb_assert (gdbarch->dwarf2_addr_size != 0);
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_dwarf2_addr_size called\n");
@@ -1746,7 +1746,7 @@ int
gdbarch_char_signed (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
- /* Check variable changed from pre-default. */
+ /* Check variable changed from its initial value. */
gdb_assert (gdbarch->char_signed != -1);
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_char_signed called\n");
@@ -1901,7 +1901,7 @@ int
gdbarch_num_regs (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
- /* Check variable changed from pre-default. */
+ /* Check variable changed from its initial value. */
gdb_assert (gdbarch->num_regs != -1);
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_num_regs called\n");
@@ -3919,8 +3919,8 @@ const char *
gdbarch_gcore_bfd_target (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
- /* Check variable changed from pre-default. */
- gdb_assert (gdbarch->gcore_bfd_target != 0);
+ /* Check predicate was used. */
+ gdb_assert (gdbarch_gcore_bfd_target_p (gdbarch));
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_gcore_bfd_target called\n");
return gdbarch->gcore_bfd_target;
@@ -3995,8 +3995,8 @@ ULONGEST
gdbarch_max_insn_length (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
- /* Check variable changed from pre-default. */
- gdb_assert (gdbarch->max_insn_length != 0);
+ /* Check predicate was used. */
+ gdb_assert (gdbarch_max_insn_length_p (gdbarch));
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_max_insn_length called\n");
return gdbarch->max_insn_length;
diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py
index 7ff2cabe2e8..62592c1b13e 100755
--- a/gdb/gdbarch.py
+++ b/gdb/gdbarch.py
@@ -351,15 +351,13 @@ with open("gdbarch.c", "w") as f:
if isinstance(c.invalid, str):
print(" /* Check variable is valid. */", file=f)
print(f" gdb_assert (!({c.invalid}));", file=f)
- elif c.postdefault is not None and c.predefault is not None:
- print(" /* Check variable changed from pre-default. */", file=f)
- print(f" gdb_assert (gdbarch->{c.name} != {c.predefault});", file=f)
- elif c.invalid:
- if c.predefault:
- print(" /* Check variable changed from pre-default. */", file=f)
- print(
- f" gdb_assert (gdbarch->{c.name} != {c.predefault});", file=f
- )
+ elif c.predicate:
+ print(" /* Check predicate was used. */", file=f)
+ print(f" gdb_assert (gdbarch_{c.name}_p (gdbarch));", file=f)
+ elif c.invalid or c.postdefault is not None:
+ init_value = c.predefault or "0"
+ print(" /* Check variable changed from its initial value. */", file=f)
+ print(f" gdb_assert (gdbarch->{c.name} != {init_value});", file=f)
else:
print(f" /* Skip verify of {c.name}, invalid_p == 0 */", file=f)
print(" if (gdbarch_debug >= 2)", file=f)
--
2.25.4
next prev parent reply other threads:[~2023-03-10 18:43 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-28 16:51 [PATCH 0/2] Add new gdbarch::displaced_step_max_buffer_length field Andrew Burgess
2023-02-28 16:51 ` [PATCH 1/2] gdb: updates to gdbarch.py algorithm Andrew Burgess
2023-03-01 3:09 ` Simon Marchi
2023-03-02 10:13 ` Andrew Burgess
2023-03-02 16:49 ` Simon Marchi
2023-03-01 15:58 ` Tom Tromey
2023-02-28 16:51 ` [PATCH 2/2] gdb: add gdbarch::displaced_step_max_buffer_length Andrew Burgess
2023-03-02 18:28 ` Simon Marchi
2023-03-06 15:31 ` [PATCHv2 0/5] Add new gdbarch::displaced_step_buffer_length field Andrew Burgess
2023-03-06 15:31 ` [PATCHv2 1/5] gdb/gdbarch: remove unused 'invalid=True' from gdbarch_components.py Andrew Burgess
2023-03-06 15:31 ` [PATCHv2 2/5] gdb/gdbarch: remove yet more " Andrew Burgess
2023-03-06 15:31 ` [PATCHv2 3/5] gdb/gdbarch: split postdefault setup from invalid check in gdbarch.py Andrew Burgess
2023-03-06 18:26 ` Simon Marchi
2023-03-06 15:31 ` [PATCHv2 4/5] gdb/gdbarch: remove the 'invalid=None' state from gdbarch_components.py Andrew Burgess
2023-03-06 20:13 ` Simon Marchi
2023-03-07 15:17 ` Tom Tromey
2023-03-07 15:20 ` Simon Marchi
2023-03-06 15:31 ` [PATCHv2 5/5] gdb: add gdbarch::displaced_step_buffer_length Andrew Burgess
2023-03-06 21:15 ` Simon Marchi
2023-03-10 18:43 ` [PATCHv3 0/9] Add new gdbarch::displaced_step_buffer_length field Andrew Burgess
2023-03-10 18:43 ` [PATCHv3 1/9] gdb/gdbarch: remove unused 'invalid=True' from gdbarch_components.py Andrew Burgess
2023-03-10 18:43 ` [PATCHv3 2/9] gdb/gdbarch: remove yet more " Andrew Burgess
2023-03-10 18:43 ` [PATCHv3 3/9] gdb/gdbarch: split postdefault setup from invalid check in gdbarch.py Andrew Burgess
2023-03-10 18:43 ` [PATCHv3 4/9] gdb/gdbarch: remove the 'invalid=None' state from gdbarch_components.py Andrew Burgess
2023-03-10 18:43 ` [PATCHv3 5/9] gdbarch: use predefault for more value components within gdbarch Andrew Burgess
2023-03-10 18:43 ` Andrew Burgess [this message]
2023-03-11 2:57 ` [PATCHv3 6/9] gdbarch: improve generation of validation in gdbarch getters Simon Marchi
2023-03-10 18:43 ` [PATCHv3 7/9] gdbarch: remove some unneeded predefault="0" from gdbarch_components.py Andrew Burgess
2023-03-10 18:43 ` [PATCHv3 8/9] gdbarch: make invalid=True the default for all Components Andrew Burgess
2023-03-10 18:43 ` [PATCHv3 9/9] gdb: add gdbarch::displaced_step_buffer_length Andrew Burgess
2023-03-11 2:57 ` [PATCHv3 0/9] Add new gdbarch::displaced_step_buffer_length field Simon Marchi
2023-03-13 22:01 ` Andrew Burgess
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=e972a5d4ebc3b7b9ba966827923fd46f2acac433.1678473293.git.aburgess@redhat.com \
--to=aburgess@redhat.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).