aboutsummaryrefslogtreecommitdiff
path: root/gdb/compile/compile-object-load.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/compile/compile-object-load.c')
-rw-r--r--gdb/compile/compile-object-load.c71
1 files changed, 27 insertions, 44 deletions
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index ef77ee3..fe48979 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -1,6 +1,6 @@
/* Load module for 'compile' command.
- Copyright (C) 2014-2024 Free Software Foundation, Inc.
+ Copyright (C) 2014-2026 Free Software Foundation, Inc.
This file is part of GDB.
@@ -22,7 +22,6 @@
#include "command.h"
#include "objfiles.h"
#include "gdbcore.h"
-#include "readline/tilde.h"
#include "bfdlink.h"
#include "cli/cli-cmds.h"
#include "regcache.h"
@@ -221,7 +220,7 @@ link_callbacks_warning (struct bfd_link_info *link_info, const char *xwarning,
static void
link_callbacks_undefined_symbol (struct bfd_link_info *link_info,
const char *name, bfd *abfd, asection *section,
- bfd_vma address, bfd_boolean is_fatal)
+ bfd_vma address, bool is_fatal)
{
warning (_("Cannot resolve relocation to \"%s\" "
"from compiled module \"%s\" section \"%s\"."),
@@ -329,12 +328,12 @@ private:
bfd *link_next;
};
-/* Relocate and store into inferior memory each section SECT of ABFD. */
+/* Relocate and store into inferior memory section SECT. */
static void
-copy_sections (bfd *abfd, asection *sect, void *data)
+copy_section (bfd *abfd, asection *sect,
+ gdb::array_view<asymbol *> symbol_table)
{
- asymbol **symbol_table = (asymbol **) data;
bfd_byte *sect_data_got;
struct bfd_link_info link_info;
struct bfd_link_order link_order;
@@ -373,8 +372,8 @@ copy_sections (bfd *abfd, asection *sect, void *data)
sect_data_got = bfd_get_relocated_section_contents (abfd, &link_info,
&link_order,
- sect_data.get (),
- FALSE, symbol_table);
+ sect_data.get (), false,
+ symbol_table.data ());
if (sect_data_got == NULL)
error (_("Cannot map compiled module \"%s\" section \"%s\": %s"),
@@ -484,7 +483,7 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
"in compiled module \"%s\"."),
gdb_type_from_ptr->code (), COMPILE_I_EXPR_VAL,
objfile_name (objfile));
-
+
retval = gdb_type_from_ptr;
switch (gdb_type_from_ptr->code ())
{
@@ -562,7 +561,7 @@ store_regs (struct type *regs_type, CORE_ADDR regs_base)
struct value *regval;
CORE_ADDR inferior_addr;
- if (strcmp (reg_name, COMPILE_I_SIMPLE_REGISTER_DUMMY) == 0)
+ if (streq (reg_name, COMPILE_I_SIMPLE_REGISTER_DUMMY))
continue;
if ((reg_bitpos % 8) != 0 || reg_bitsize != 0)
@@ -605,9 +604,7 @@ compile_object_load (const compile_file_names &file_names,
CORE_ADDR regs_addr, out_value_addr = 0;
struct symbol *func_sym;
struct type *func_type;
- long storage_needed;
- asymbol **symbol_table, **symp;
- long number_of_symbols, missing_symbols;
+ long missing_symbols;
struct type *regs_type, *out_value_type = NULL;
char **matching;
struct objfile *objfile;
@@ -615,7 +612,7 @@ compile_object_load (const compile_file_names &file_names,
struct type *expect_return_type;
gdb::unique_xmalloc_ptr<char> filename
- (tilde_expand (file_names.object_file ()));
+ = gdb_rl_tilde_expand (file_names.object_file ());
gdb_bfd_ref_ptr abfd (gdb_bfd_open (filename.get (), gnutarget));
if (abfd == NULL)
@@ -631,15 +628,10 @@ compile_object_load (const compile_file_names &file_names,
error (_("\"%s\": not in object format."), filename.get ());
struct setup_sections_data setup_sections_data (abfd.get ());
- for (asection *sect = abfd->sections; sect != nullptr; sect = sect->next)
+ for (asection *sect : gdb_bfd_sections (abfd))
setup_sections_data.setup_one_section (sect);
setup_sections_data.setup_one_section (nullptr);
- storage_needed = bfd_get_symtab_upper_bound (abfd.get ());
- if (storage_needed < 0)
- error (_("Cannot read symbols of compiled module \"%s\": %s"),
- filename.get (), bfd_errmsg (bfd_get_error ()));
-
/* SYMFILE_VERBOSE is not passed even if FROM_TTY, user is not interested in
"Reading symbols from ..." message for automatically generated file. */
scoped_objfile_unlinker objfile_holder (symbol_file_add_from_bfd
@@ -692,26 +684,17 @@ compile_object_load (const compile_file_names &file_names,
"module \"%s\"."),
GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile));
- /* The memory may be later needed
- by bfd_generic_get_relocated_section_contents
- called from default_symfile_relocate. */
- symbol_table = (asymbol **) obstack_alloc (&objfile->objfile_obstack,
- storage_needed);
- number_of_symbols = bfd_canonicalize_symtab (abfd.get (), symbol_table);
- if (number_of_symbols < 0)
- error (_("Cannot parse symbols of compiled module \"%s\": %s"),
- filename.get (), bfd_errmsg (bfd_get_error ()));
+ gdb::array_view<asymbol *> symbol_table
+ = gdb_bfd_canonicalize_symtab (abfd.get ());
missing_symbols = 0;
- for (symp = symbol_table; symp < symbol_table + number_of_symbols; symp++)
+ for (asymbol *sym : symbol_table)
{
- asymbol *sym = *symp;
-
if (sym->flags != 0)
continue;
sym->flags = BSF_GLOBAL;
sym->section = bfd_abs_section_ptr;
- if (strcmp (sym->name, "_GLOBAL_OFFSET_TABLE_") == 0)
+ if (streq (sym->name, "_GLOBAL_OFFSET_TABLE_"))
{
if (compile_debug)
gdb_printf (gdb_stdlog,
@@ -724,7 +707,7 @@ compile_object_load (const compile_file_names &file_names,
sym->value = 0;
continue;
}
- if (strcmp (sym->name, ".TOC.") == 0)
+ if (streq (sym->name, ".TOC."))
{
/* Handle the .TOC. symbol as the linker would do. Set the .TOC.
sections value to 0x8000 (see bfd/elf64-ppc.c TOC_BASE_OFF);
@@ -737,15 +720,14 @@ compile_object_load (const compile_file_names &file_names,
asection *toc_fallback = bfd_get_section_by_name(abfd.get(), ".toc");
if (toc_fallback == NULL)
{
- for (asection *tsect = abfd->sections; tsect != nullptr;
- tsect = tsect->next)
- {
- if (bfd_section_flags (tsect) & SEC_ALLOC)
- {
- toc_fallback = tsect;
- break;
- }
- }
+ for (asection *tsect : gdb_bfd_sections (abfd))
+ {
+ if (bfd_section_flags (tsect) & SEC_ALLOC)
+ {
+ toc_fallback = tsect;
+ break;
+ }
+ }
}
if (toc_fallback == NULL)
@@ -800,7 +782,8 @@ compile_object_load (const compile_file_names &file_names,
if (missing_symbols)
error (_("%ld symbols were missing, cannot continue."), missing_symbols);
- bfd_map_over_sections (abfd.get (), copy_sections, symbol_table);
+ for (asection *sect : gdb_bfd_sections (abfd.get ()))
+ copy_section (abfd.get (), sect, symbol_table);
regs_type = get_regs_type (func_sym, objfile);
if (regs_type == NULL)