summaryrefslogtreecommitdiff
path: root/gdb/gdbarch.c
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2023-03-06 14:39:28 +0000
committerAndrew Burgess <aburgess@redhat.com>2023-03-13 21:51:04 +0000
commit6e2d282d74bfd961e64348199b92beb1cb648f6a (patch)
tree7b70d530cd09b99de5d24f51c27943abf43e48c3 /gdb/gdbarch.c
parent74b1406e90bfa156aa324f9ecde424a5488cac51 (diff)
downloadbinutils-gdb-6e2d282d74bfd961e64348199b92beb1cb648f6a.tar.gz
gdb/gdbarch: remove the 'invalid=None' state from gdbarch_components.py
This commit ensures that the 'invalid' property of all components is either True, False, or a string. Additionally, this commit allows a component to have both a predicate and for the 'invalid' property to be a string. Removing the option for 'invalid' to be None allows us to simplify the algorithms in gdbarch.py a little. Allowing a component to have both a predicate and an 'invalid' string means that we can validate the value that a tdep sets into a field, but also allow a predicate to ensure that the field has changed from the default. This functionality isn't going to be used in this series, but I have tested it locally and believe that it would work, and this might make it easier for others to add new components in the future. In gdbarch_types.py, I've updated the type annotations to show that the 'invalid' field should not be None, and I've changed the default for this field from None to False. The change to using False as the default is temporary. Later in this series I'm going to change the default to True, but we need more fixes before that can be done. Additionally, in gdbarch_types.py I've removed an assert from Component.get_predicate. This assert ensured that we didn't have the predicate field set to True and the invalid field set to a string. However, no component currently uses this configuration, and after this commit, that combination is now supported, so the assert can be removed. As a consequence of the gdbarch_types.py changes we see some additional comments generated in gdbarch.c about verification being skipped due to the invalid field being False. This comment is inline with plenty of other getters that also have a similar comment. Plenty of the getters do have validation, so I think it is reasonable to have a comment noting that the validation has been skipped for a specific reason, rather than due to some bug. In gdbarch_components.py I've had to add 'invalid=True' for two components: gcore_bfd_target and max_insn_length, without this the validation in the gdbarch getter would disappear. And in gdbarch.py I've reworked the logic for generating the verify_gdbarch function, and for generating the getter functions. The logic for generating the getter functions is still not ideal, I ended up having to add this additional logic block: 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) which was needed to ensure we continued to generate the same code as before, without this the fact that invalid is now False when it would previously have been None, meant that we dropped the gdb_assert in favour of a comment like: print(f" /* Skip verify of {c.name}, invalid_p == 0 */", file=f) which is clearly not a good change. We could potentially look at improving this in a later commit, but I don't plan to do that in this series. Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb/gdbarch.c')
-rw-r--r--gdb/gdbarch.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 7e4e34d5aca..efd111eeabc 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -298,29 +298,38 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of bfloat16_bit, invalid_p == 0 */
if (gdbarch->bfloat16_format == 0)
gdbarch->bfloat16_format = floatformats_bfloat16;
+ /* Skip verify of bfloat16_format, invalid_p == 0 */
/* Skip verify of half_bit, invalid_p == 0 */
if (gdbarch->half_format == 0)
gdbarch->half_format = floatformats_ieee_half;
+ /* Skip verify of half_format, invalid_p == 0 */
/* Skip verify of float_bit, invalid_p == 0 */
if (gdbarch->float_format == 0)
gdbarch->float_format = floatformats_ieee_single;
+ /* Skip verify of float_format, invalid_p == 0 */
/* Skip verify of double_bit, invalid_p == 0 */
if (gdbarch->double_format == 0)
gdbarch->double_format = floatformats_ieee_double;
+ /* Skip verify of double_format, invalid_p == 0 */
/* Skip verify of long_double_bit, invalid_p == 0 */
if (gdbarch->long_double_format == 0)
gdbarch->long_double_format = floatformats_ieee_double;
+ /* Skip verify of long_double_format, invalid_p == 0 */
/* Skip verify of wchar_bit, invalid_p == 0 */
if (gdbarch->wchar_signed == -1)
gdbarch->wchar_signed = 1;
+ /* Skip verify of wchar_signed, invalid_p == 0 */
/* Skip verify of floatformat_for_type, invalid_p == 0 */
/* Skip verify of ptr_bit, invalid_p == 0 */
if (gdbarch->addr_bit == 0)
gdbarch->addr_bit = gdbarch_ptr_bit (gdbarch);
+ /* Skip verify of addr_bit, invalid_p == 0 */
if (gdbarch->dwarf2_addr_size == 0)
gdbarch->dwarf2_addr_size = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
+ /* Skip verify of dwarf2_addr_size, invalid_p == 0 */
if (gdbarch->char_signed == -1)
gdbarch->char_signed = 1;
+ /* Skip verify of char_signed, invalid_p == 0 */
/* Skip verify of read_pc, has predicate. */
/* Skip verify of write_pc, has predicate. */
/* Skip verify of virtual_frame_pointer, invalid_p == 0 */
@@ -412,6 +421,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of skip_trampoline_code, invalid_p == 0 */
if (gdbarch->so_ops == 0)
gdbarch->so_ops = &solib_target_so_ops;
+ /* Skip verify of so_ops, invalid_p == 0 */
/* Skip verify of skip_solib_resolver, invalid_p == 0 */
/* Skip verify of in_solib_return_trampoline, invalid_p == 0 */
/* Skip verify of in_indirect_branch_thunk, invalid_p == 0 */
@@ -1490,6 +1500,7 @@ const struct floatformat **
gdbarch_bfloat16_format (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
+ /* Skip verify of bfloat16_format, invalid_p == 0 */
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_bfloat16_format called\n");
return gdbarch->bfloat16_format;
@@ -1523,6 +1534,7 @@ const struct floatformat **
gdbarch_half_format (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
+ /* Skip verify of half_format, invalid_p == 0 */
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_half_format called\n");
return gdbarch->half_format;
@@ -1556,6 +1568,7 @@ const struct floatformat **
gdbarch_float_format (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
+ /* Skip verify of float_format, invalid_p == 0 */
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_float_format called\n");
return gdbarch->float_format;
@@ -1589,6 +1602,7 @@ const struct floatformat **
gdbarch_double_format (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
+ /* Skip verify of double_format, invalid_p == 0 */
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_double_format called\n");
return gdbarch->double_format;
@@ -1622,6 +1636,7 @@ const struct floatformat **
gdbarch_long_double_format (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
+ /* Skip verify of long_double_format, invalid_p == 0 */
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_long_double_format called\n");
return gdbarch->long_double_format;
@@ -3304,6 +3319,7 @@ const struct target_so_ops *
gdbarch_so_ops (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);
+ /* Skip verify of so_ops, invalid_p == 0 */
if (gdbarch_debug >= 2)
gdb_printf (gdb_stdlog, "gdbarch_so_ops called\n");
return gdbarch->so_ops;