public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdbarch: remove some unneeded predefault="0" from gdbarch_components.py
@ 2023-03-13 22:01 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2023-03-13 22:01 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a3e200efc1524368937a793e02614fecf8856168

commit a3e200efc1524368937a793e02614fecf8856168
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Fri Mar 10 15:31:36 2023 +0000

    gdbarch: remove some unneeded predefault="0" from gdbarch_components.py
    
    I noticed that there are a bunch of 'predefault="0"' lines in
    gdbarch_components.py, and that some (just some, not all) of these are
    not needed.
    
    The gdbarch is already zero initialized, but these lines seem to
    exists so that we can know when to compare against "0" and when to
    compare against "NULL".  At least, this seems to be useful in some
    places in the generated code.
    
    Specifically, if we remove the predefault="0" line from the
    max_insn_length component then we end up generating a line like:
    
      gdb_assert (gdbarch->max_insn_length != NULL);
    
    which doesn't compile as we compare a ULONGEST to NULL.
    
    In this commit I remove all the predefault="0" lines that I claim are
    obviously not needed.  These are lines for components that are not
    Values (i.e. the component holds a function pointer anyway), or for
    Value components that hold a pointer type, in which case using NULL is
    fine.
    
    The only changes after this commit are some fields that have nullptr
    as their initial value, and gcore_bfd_target now compares to NULL not
    0 in gdbarch_gcore_bfd_target_p, which, given the field is of type
    'const char *', seems like an improvement.
    
    Approved-By: Simon Marchi <simon.marchi@efficios.com>

Diff:
---
 gdb/gdbarch.c             | 10 +++++-----
 gdb/gdbarch_components.py | 22 +---------------------
 2 files changed, 6 insertions(+), 26 deletions(-)

diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 6018c632f91..84f6a481885 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -88,7 +88,7 @@ struct gdbarch
   gdbarch_ecoff_reg_to_regnum_ftype *ecoff_reg_to_regnum = no_op_reg_to_regnum;
   gdbarch_sdb_reg_to_regnum_ftype *sdb_reg_to_regnum = no_op_reg_to_regnum;
   gdbarch_dwarf2_reg_to_regnum_ftype *dwarf2_reg_to_regnum = no_op_reg_to_regnum;
-  gdbarch_register_name_ftype *register_name = 0;
+  gdbarch_register_name_ftype *register_name = nullptr;
   gdbarch_register_type_ftype *register_type = nullptr;
   gdbarch_dummy_id_ftype *dummy_id = default_dummy_id;
   int deprecated_fp_regnum = -1;
@@ -115,12 +115,12 @@ struct gdbarch
   gdbarch_return_value_as_value_ftype *return_value_as_value = default_gdbarch_return_value;
   gdbarch_get_return_buf_addr_ftype *get_return_buf_addr = default_get_return_buf_addr;
   gdbarch_return_in_first_hidden_param_p_ftype *return_in_first_hidden_param_p = default_return_in_first_hidden_param_p;
-  gdbarch_skip_prologue_ftype *skip_prologue = 0;
+  gdbarch_skip_prologue_ftype *skip_prologue = nullptr;
   gdbarch_skip_main_prologue_ftype *skip_main_prologue = nullptr;
   gdbarch_skip_entrypoint_ftype *skip_entrypoint = nullptr;
-  gdbarch_inner_than_ftype *inner_than = 0;
+  gdbarch_inner_than_ftype *inner_than = nullptr;
   gdbarch_breakpoint_from_pc_ftype *breakpoint_from_pc = default_breakpoint_from_pc;
-  gdbarch_breakpoint_kind_from_pc_ftype *breakpoint_kind_from_pc = 0;
+  gdbarch_breakpoint_kind_from_pc_ftype *breakpoint_kind_from_pc = nullptr;
   gdbarch_sw_breakpoint_from_kind_ftype *sw_breakpoint_from_kind = NULL;
   gdbarch_breakpoint_kind_from_current_state_ftype *breakpoint_kind_from_current_state = default_breakpoint_kind_from_current_state;
   gdbarch_adjust_breakpoint_address_ftype *adjust_breakpoint_address = nullptr;
@@ -3912,7 +3912,7 @@ bool
 gdbarch_gcore_bfd_target_p (struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
-  return gdbarch->gcore_bfd_target != 0;
+  return gdbarch->gcore_bfd_target != NULL;
 }
 
 const char *
diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py
index 2cb700309fd..57bbf8eb7b6 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -340,7 +340,6 @@ and if Dwarf versions < 4 need to be supported.
 """,
     type="int",
     name="dwarf2_addr_size",
-    predefault="0",
     postdefault="gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT",
 )
 
@@ -567,7 +566,6 @@ should never return nullptr.
     params=[("int", "regnr")],
     param_checks=["regnr >= 0", "regnr < gdbarch_num_cooked_regs (gdbarch)"],
     result_checks=["result != nullptr"],
-    predefault="0",
     invalid=True,
 )
 
@@ -915,7 +913,6 @@ Method(
     type="CORE_ADDR",
     name="skip_prologue",
     params=[("CORE_ADDR", "ip")],
-    predefault="0",
     invalid=True,
 )
 
@@ -950,7 +947,6 @@ Function(
     type="int",
     name="inner_than",
     params=[("CORE_ADDR", "lhs"), ("CORE_ADDR", "rhs")],
-    predefault="0",
     invalid=True,
 )
 
@@ -969,7 +965,6 @@ Return the breakpoint kind for this target based on *PCPTR.
     type="int",
     name="breakpoint_kind_from_pc",
     params=[("CORE_ADDR *", "pcptr")],
-    predefault="0",
     invalid=True,
 )
 
@@ -1673,7 +1668,6 @@ BFD target to use when generating a core file.
     type="const char *",
     name="gcore_bfd_target",
     predicate=True,
-    predefault="0",
     printer="pstring (gdbarch->gcore_bfd_target)",
     invalid=True,
 )
@@ -1697,7 +1691,6 @@ significant bit of the pfn for pointers to virtual member functions.
 """,
     type="int",
     name="vbit_in_delta",
-    predefault="0",
     invalid=False,
 )
 
@@ -1718,8 +1711,8 @@ The maximum length of an instruction on this architecture in bytes.
 """,
     type="ULONGEST",
     name="max_insn_length",
-    predicate=True,
     predefault="0",
+    predicate=True,
     invalid=True,
 )
 
@@ -1991,7 +1984,6 @@ The filename of the XML syscall for this architecture.
 """,
     type="const char *",
     name="xml_syscall_file",
-    predefault="0",
     invalid=False,
     printer="pstring (gdbarch->xml_syscall_file)",
 )
@@ -2002,7 +1994,6 @@ Information about system calls from this architecture
 """,
     type="struct syscalls_info *",
     name="syscalls_info",
-    predefault="0",
     invalid=False,
     printer="host_address_to_string (gdbarch->syscalls_info)",
 )
@@ -2020,7 +2011,6 @@ in this case, this prefix would be the character `$'.
 """,
     type="const char *const *",
     name="stap_integer_prefixes",
-    predefault="0",
     invalid=False,
     printer="pstring_list (gdbarch->stap_integer_prefixes)",
 )
@@ -2032,7 +2022,6 @@ on the architecture's assembly.
 """,
     type="const char *const *",
     name="stap_integer_suffixes",
-    predefault="0",
     invalid=False,
     printer="pstring_list (gdbarch->stap_integer_suffixes)",
 )
@@ -2049,7 +2038,6 @@ in this case, this prefix would be the character `%'.
 """,
     type="const char *const *",
     name="stap_register_prefixes",
-    predefault="0",
     invalid=False,
     printer="pstring_list (gdbarch->stap_register_prefixes)",
 )
@@ -2061,7 +2049,6 @@ the architecture's assembly.
 """,
     type="const char *const *",
     name="stap_register_suffixes",
-    predefault="0",
     invalid=False,
     printer="pstring_list (gdbarch->stap_register_suffixes)",
 )
@@ -2081,7 +2068,6 @@ displacement, e.g., `4(%eax)' on x86.
 """,
     type="const char *const *",
     name="stap_register_indirection_prefixes",
-    predefault="0",
     invalid=False,
     printer="pstring_list (gdbarch->stap_register_indirection_prefixes)",
 )
@@ -2101,7 +2087,6 @@ displacement, e.g., `4(%eax)' on x86.
 """,
     type="const char *const *",
     name="stap_register_indirection_suffixes",
-    predefault="0",
     invalid=False,
     printer="pstring_list (gdbarch->stap_register_indirection_suffixes)",
 )
@@ -2117,7 +2102,6 @@ register would be represented as `r10' internally.
 """,
     type="const char *",
     name="stap_gdb_register_prefix",
-    predefault="0",
     invalid=False,
     printer="pstring (gdbarch->stap_gdb_register_prefix)",
 )
@@ -2128,7 +2112,6 @@ Suffix used to name a register using GDB's nomenclature.
 """,
     type="const char *",
     name="stap_gdb_register_suffix",
-    predefault="0",
     invalid=False,
     printer="pstring (gdbarch->stap_gdb_register_suffix)",
 )
@@ -2610,7 +2593,6 @@ Functions for allowing a target to modify its disassembler options.
 """,
     type="const char *",
     name="disassembler_options_implicit",
-    predefault="0",
     invalid=False,
     printer="pstring (gdbarch->disassembler_options_implicit)",
 )
@@ -2618,7 +2600,6 @@ Functions for allowing a target to modify its disassembler options.
 Value(
     type="char **",
     name="disassembler_options",
-    predefault="0",
     invalid=False,
     printer="pstring_ptr (gdbarch->disassembler_options)",
 )
@@ -2626,7 +2607,6 @@ Value(
 Value(
     type="const disasm_options_and_args_t *",
     name="valid_disassembler_options",
-    predefault="0",
     invalid=False,
     printer="host_address_to_string (gdbarch->valid_disassembler_options)",
 )

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-13 22:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-13 22:01 [binutils-gdb] gdbarch: remove some unneeded predefault="0" from gdbarch_components.py Andrew Burgess

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).