From 78dd36b8f21a05337ebb1888cddd34dcabf261d0 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 6 Mar 2025 10:09:38 -0700 Subject: [PATCH] Use 'const' in some gdbarch methods This changes a couple of gdbarch methods to use 'const' for an "asymbol *" parameter. These methods shouldn't be modifying the underlying symbol in the BFD. Approved-By: Simon Marchi --- gdb/arm-tdep.c | 6 +++--- gdb/gdbarch-gen.c | 4 ++-- gdb/gdbarch-gen.h | 8 ++++---- gdb/gdbarch_components.py | 4 ++-- gdb/m68hc11-tdep.c | 5 +++-- gdb/mips-tdep.c | 5 +++-- gdb/ppc-linux-tdep.c | 5 +++-- gdb/ppc64-tdep.c | 5 +++-- gdb/ppc64-tdep.h | 2 +- 9 files changed, 24 insertions(+), 20 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index bdad0779ca7..879f5cf2447 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -9719,9 +9719,9 @@ coff_sym_is_thumb (int val) symbol to indicate that it does. */ static void -arm_elf_make_msymbol_special(asymbol *sym, struct minimal_symbol *msym) +arm_elf_make_msymbol_special (const asymbol *sym, struct minimal_symbol *msym) { - elf_symbol_type *elfsym = (elf_symbol_type *) sym; + const elf_symbol_type *elfsym = (const elf_symbol_type *) sym; if (ARM_GET_SYM_BRANCH_TYPE (elfsym->internal_elf_sym.st_target_internal) == ST_BRANCH_TO_THUMB) @@ -9737,7 +9737,7 @@ arm_coff_make_msymbol_special(int val, struct minimal_symbol *msym) static void arm_record_special_symbol (struct gdbarch *gdbarch, struct objfile *objfile, - asymbol *sym) + const asymbol *sym) { const char *name = bfd_asymbol_name (sym); struct arm_per_bfd *data; diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c index 8137ece78bc..97d7ed9b069 100644 --- a/gdb/gdbarch-gen.c +++ b/gdb/gdbarch-gen.c @@ -3562,7 +3562,7 @@ gdbarch_elf_make_msymbol_special_p (struct gdbarch *gdbarch) } void -gdbarch_elf_make_msymbol_special (struct gdbarch *gdbarch, asymbol *sym, struct minimal_symbol *msym) +gdbarch_elf_make_msymbol_special (struct gdbarch *gdbarch, const asymbol *sym, struct minimal_symbol *msym) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->elf_make_msymbol_special != NULL); @@ -4575,7 +4575,7 @@ gdbarch_record_special_symbol_p (struct gdbarch *gdbarch) } void -gdbarch_record_special_symbol (struct gdbarch *gdbarch, struct objfile *objfile, asymbol *sym) +gdbarch_record_special_symbol (struct gdbarch *gdbarch, struct objfile *objfile, const asymbol *sym) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->record_special_symbol != NULL); diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index abffcf99fac..7a52f79d762 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -867,8 +867,8 @@ extern void set_gdbarch_stack_frame_destroyed_p (struct gdbarch *gdbarch, gdbarc extern bool gdbarch_elf_make_msymbol_special_p (struct gdbarch *gdbarch); -typedef void (gdbarch_elf_make_msymbol_special_ftype) (asymbol *sym, struct minimal_symbol *msym); -extern void gdbarch_elf_make_msymbol_special (struct gdbarch *gdbarch, asymbol *sym, struct minimal_symbol *msym); +typedef void (gdbarch_elf_make_msymbol_special_ftype) (const asymbol *sym, struct minimal_symbol *msym); +extern void gdbarch_elf_make_msymbol_special (struct gdbarch *gdbarch, const asymbol *sym, struct minimal_symbol *msym); extern void set_gdbarch_elf_make_msymbol_special (struct gdbarch *gdbarch, gdbarch_elf_make_msymbol_special_ftype *elf_make_msymbol_special); typedef void (gdbarch_coff_make_msymbol_special_ftype) (int val, struct minimal_symbol *msym); @@ -1325,8 +1325,8 @@ extern void set_gdbarch_get_siginfo_type (struct gdbarch *gdbarch, gdbarch_get_s extern bool gdbarch_record_special_symbol_p (struct gdbarch *gdbarch); -typedef void (gdbarch_record_special_symbol_ftype) (struct gdbarch *gdbarch, struct objfile *objfile, asymbol *sym); -extern void gdbarch_record_special_symbol (struct gdbarch *gdbarch, struct objfile *objfile, asymbol *sym); +typedef void (gdbarch_record_special_symbol_ftype) (struct gdbarch *gdbarch, struct objfile *objfile, const asymbol *sym); +extern void gdbarch_record_special_symbol (struct gdbarch *gdbarch, struct objfile *objfile, const asymbol *sym); extern void set_gdbarch_record_special_symbol (struct gdbarch *gdbarch, gdbarch_record_special_symbol_ftype *record_special_symbol); /* Function for the 'catch syscall' feature. diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index e0fd74e80d1..cd0a8947948 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -1506,7 +1506,7 @@ the main symbol table and DWARF-2 records. """, type="void", name="elf_make_msymbol_special", - params=[("asymbol *", "sym"), ("struct minimal_symbol *", "msym")], + params=[("const asymbol *", "sym"), ("struct minimal_symbol *", "msym")], predicate=True, ) @@ -2126,7 +2126,7 @@ Record architecture-specific information from the symbol table. """, type="void", name="record_special_symbol", - params=[("struct objfile *", "objfile"), ("asymbol *", "sym")], + params=[("struct objfile *", "objfile"), ("const asymbol *", "sym")], predicate=True, ) diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c index 84a44f525c2..234edcf50bf 100644 --- a/gdb/m68hc11-tdep.c +++ b/gdb/m68hc11-tdep.c @@ -1326,11 +1326,12 @@ m68hc11_return_value (struct gdbarch *gdbarch, struct value *function, rti to return. */ static void -m68hc11_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym) +m68hc11_elf_make_msymbol_special (const asymbol *sym, + struct minimal_symbol *msym) { unsigned char flags; - flags = ((elf_symbol_type *)sym)->internal_elf_sym.st_other; + flags = ((const elf_symbol_type *) sym)->internal_elf_sym.st_other; if (flags & STO_M68HC12_FAR) MSYMBOL_SET_RTC (msym); if (flags & STO_M68HC12_INTERRUPT) diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c index 93f8cd0263a..3613f9bec8d 100644 --- a/gdb/mips-tdep.c +++ b/gdb/mips-tdep.c @@ -422,9 +422,10 @@ mips_unmake_compact_addr (CORE_ADDR addr) in a minimal symbol. */ static void -mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym) +mips_elf_make_msymbol_special (const asymbol * sym, + struct minimal_symbol *msym) { - elf_symbol_type *elfsym = (elf_symbol_type *) sym; + const elf_symbol_type *elfsym = (const elf_symbol_type *) sym; unsigned char st_other; if ((sym->flags & BSF_SYNTHETIC) == 0) diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c index 8a5eea765c2..a9f43c43861 100644 --- a/gdb/ppc-linux-tdep.c +++ b/gdb/ppc-linux-tdep.c @@ -1638,14 +1638,15 @@ ppc_linux_core_read_description (struct gdbarch *gdbarch, gdbarch.h. This implementation is used for the ELFv2 ABI only. */ static void -ppc_elfv2_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym) +ppc_elfv2_elf_make_msymbol_special (const asymbol *sym, + struct minimal_symbol *msym) { if ((sym->flags & BSF_SYNTHETIC) != 0) /* ELFv2 synthetic symbols (the PLT stubs and the __glink_PLTresolve trampoline) do not have a local entry point. */ return; - elf_symbol_type *elf_sym = (elf_symbol_type *)sym; + const elf_symbol_type *elf_sym = (const elf_symbol_type *)sym; /* If the symbol is marked as having a local entry point, set a target flag in the msymbol. We currently only support local entry point diff --git a/gdb/ppc64-tdep.c b/gdb/ppc64-tdep.c index 79bc4da71e2..5e758003db9 100644 --- a/gdb/ppc64-tdep.c +++ b/gdb/ppc64-tdep.c @@ -793,11 +793,12 @@ ppc64_convert_from_func_ptr_addr (struct gdbarch *gdbarch, from that symbol. */ void -ppc64_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym) +ppc64_elf_make_msymbol_special (const asymbol *sym, + struct minimal_symbol *msym) { if ((sym->flags & BSF_SYNTHETIC) != 0 && sym->udata.p != NULL) { - elf_symbol_type *elf_sym = (elf_symbol_type *) sym->udata.p; + const elf_symbol_type *elf_sym = (const elf_symbol_type *) sym->udata.p; msym->set_size (elf_sym->internal_elf_sym.st_size); } } diff --git a/gdb/ppc64-tdep.h b/gdb/ppc64-tdep.h index 7bea549dda0..5ad8841166d 100644 --- a/gdb/ppc64-tdep.h +++ b/gdb/ppc64-tdep.h @@ -31,6 +31,6 @@ extern CORE_ADDR ppc64_convert_from_func_ptr_addr (struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ); -extern void ppc64_elf_make_msymbol_special (asymbol *, +extern void ppc64_elf_make_msymbol_special (const asymbol *, struct minimal_symbol *); #endif /* GDB_PPC64_TDEP_H */ -- 2.39.5