gdb: remove most global core file accesses from record-full.c

This commit continues my ongoing work to reduce the number of global
accesses to the current core file BFD in GDB.  The global accesses I'm
working on removing look like 'current_program_space->core_bfd ()'.

This commit targets record-full.c.  All global accesses are removed
except for two in record_full_open, which is used to implements the
two commands 'target record-full' and 'record full restore'.

All other global accesses to the core file are removed by passing the
core file through as an argument from this one top level function.

As I followed the code through I noticed that record_full_restore,
which currently includes this check:

  if (current_program_space->core_bfd () == nullptr)
    return;

could never actually be called without a core file being set.  As the
argument is now 'struct bfd &', then there is no longer an option for
the incoming argument to be NULL, and the above check is removed.

There should be no user visible changes after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
Andrew Burgess
2025-08-27 11:30:47 +01:00
parent 9cede382cb
commit a839a42bcd

View File

@@ -908,7 +908,7 @@ record_full_exec_insn (struct regcache *regcache,
} }
} }
static void record_full_restore (void); static void record_full_restore (struct bfd &cbfd);
/* Asynchronous signal handle registered as event loop source for when /* Asynchronous signal handle registered as event loop source for when
we have pending events ready to be passed to the core. */ we have pending events ready to be passed to the core. */
@@ -921,10 +921,11 @@ record_full_async_inferior_event_handler (gdb_client_data data)
inferior_event_handler (INF_REG_EVENT); inferior_event_handler (INF_REG_EVENT);
} }
/* Open the process record target for 'core' files. */ /* Open the process record target for 'core' files. CBFD is the core file
containing the record information. */
static void static void
record_full_core_open_1 () record_full_core_open_1 (struct bfd &cbfd)
{ {
regcache *regcache = get_thread_regcache (inferior_thread ()); regcache *regcache = get_thread_regcache (inferior_thread ());
int regnum = gdbarch_num_regs (regcache->arch ()); int regnum = gdbarch_num_regs (regcache->arch ());
@@ -937,11 +938,10 @@ record_full_core_open_1 ()
for (i = 0; i < regnum; i ++) for (i = 0; i < regnum; i ++)
record_full_core_regbuf->raw_supply (i, *regcache); record_full_core_regbuf->raw_supply (i, *regcache);
record_full_core_sections record_full_core_sections = build_section_table (&cbfd);
= build_section_table (current_program_space->core_bfd ());
current_inferior ()->push_target (&record_full_core_ops); current_inferior ()->push_target (&record_full_core_ops);
record_full_restore (); record_full_restore (cbfd);
} }
/* Open the process record target for 'live' processes. */ /* Open the process record target for 'live' processes. */
@@ -987,8 +987,8 @@ record_full_open (const char *args, int from_tty)
record_full_list = &record_full_first; record_full_list = &record_full_first;
record_full_list->next = NULL; record_full_list->next = NULL;
if (current_program_space->core_bfd ()) if (current_program_space->core_bfd () != nullptr)
record_full_core_open_1 (); record_full_core_open_1 (*current_program_space->core_bfd ());
else else
record_full_open_1 (); record_full_open_1 ();
@@ -2332,9 +2332,10 @@ netorder32 (uint32_t input)
return ret; return ret;
} }
/* Restore the execution log from a core_bfd file. */ /* Restore the execution log from core file CBFD. */
static void static void
record_full_restore (void) record_full_restore (struct bfd &cbfd)
{ {
uint32_t magic; uint32_t magic;
struct record_full_entry *rec; struct record_full_entry *rec;
@@ -2342,11 +2343,6 @@ record_full_restore (void)
uint32_t osec_size; uint32_t osec_size;
int bfd_offset = 0; int bfd_offset = 0;
/* We restore the execution log from the open core bfd,
if there is one. */
if (current_program_space->core_bfd () == nullptr)
return;
/* "record_full_restore" can only be called when record list is empty. */ /* "record_full_restore" can only be called when record list is empty. */
gdb_assert (record_full_first.next == NULL); gdb_assert (record_full_first.next == NULL);
@@ -2354,7 +2350,7 @@ record_full_restore (void)
gdb_printf (gdb_stdlog, "Restoring recording from core file.\n"); gdb_printf (gdb_stdlog, "Restoring recording from core file.\n");
/* Now need to find our special note section. */ /* Now need to find our special note section. */
osec = bfd_get_section_by_name (current_program_space->core_bfd (), "null0"); osec = bfd_get_section_by_name (&cbfd, "null0");
if (record_debug) if (record_debug)
gdb_printf (gdb_stdlog, "Find precord section %s.\n", gdb_printf (gdb_stdlog, "Find precord section %s.\n",
osec ? "succeeded" : "failed"); osec ? "succeeded" : "failed");
@@ -2365,11 +2361,10 @@ record_full_restore (void)
gdb_printf (gdb_stdlog, "%s", bfd_section_name (osec)); gdb_printf (gdb_stdlog, "%s", bfd_section_name (osec));
/* Check the magic code. */ /* Check the magic code. */
bfdcore_read (current_program_space->core_bfd (), osec, &magic, bfdcore_read (&cbfd, osec, &magic, sizeof (magic), &bfd_offset);
sizeof (magic), &bfd_offset);
if (magic != RECORD_FULL_FILE_MAGIC) if (magic != RECORD_FULL_FILE_MAGIC)
error (_("Version mismatch or file format error in core file %s."), error (_("Version mismatch or file format error in core file %s."),
bfd_get_filename (current_program_space->core_bfd ())); bfd_get_filename (&cbfd));
if (record_debug) if (record_debug)
gdb_printf (gdb_stdlog, gdb_printf (gdb_stdlog,
" Reading 4-byte magic cookie " " Reading 4-byte magic cookie "
@@ -2395,23 +2390,21 @@ record_full_restore (void)
/* We are finished when offset reaches osec_size. */ /* We are finished when offset reaches osec_size. */
if (bfd_offset >= osec_size) if (bfd_offset >= osec_size)
break; break;
bfdcore_read (current_program_space->core_bfd (), osec, &rectype, bfdcore_read (&cbfd, osec, &rectype, sizeof (rectype), &bfd_offset);
sizeof (rectype), &bfd_offset);
switch (rectype) switch (rectype)
{ {
case record_full_reg: /* reg */ case record_full_reg: /* reg */
/* Get register number to regnum. */ /* Get register number to regnum. */
bfdcore_read (current_program_space->core_bfd (), osec, &regnum, bfdcore_read (&cbfd, osec, &regnum, sizeof (regnum),
sizeof (regnum), &bfd_offset); &bfd_offset);
regnum = netorder32 (regnum); regnum = netorder32 (regnum);
rec = record_full_reg_alloc (regcache, regnum); rec = record_full_reg_alloc (regcache, regnum);
/* Get val. */ /* Get val. */
bfdcore_read (current_program_space->core_bfd (), osec, bfdcore_read (&cbfd, osec, record_full_get_loc (rec),
record_full_get_loc (rec), rec->u.reg.len, rec->u.reg.len, &bfd_offset);
&bfd_offset);
if (record_debug) if (record_debug)
gdb_printf (gdb_stdlog, gdb_printf (gdb_stdlog,
@@ -2424,21 +2417,18 @@ record_full_restore (void)
case record_full_mem: /* mem */ case record_full_mem: /* mem */
/* Get len. */ /* Get len. */
bfdcore_read (current_program_space->core_bfd (), osec, &len, bfdcore_read (&cbfd, osec, &len, sizeof (len), &bfd_offset);
sizeof (len), &bfd_offset);
len = netorder32 (len); len = netorder32 (len);
/* Get addr. */ /* Get addr. */
bfdcore_read (current_program_space->core_bfd (), osec, &addr, bfdcore_read (&cbfd, osec, &addr, sizeof (addr), &bfd_offset);
sizeof (addr), &bfd_offset);
addr = netorder64 (addr); addr = netorder64 (addr);
rec = record_full_mem_alloc (addr, len); rec = record_full_mem_alloc (addr, len);
/* Get val. */ /* Get val. */
bfdcore_read (current_program_space->core_bfd (), osec, bfdcore_read (&cbfd, osec, record_full_get_loc (rec),
record_full_get_loc (rec), rec->u.mem.len, rec->u.mem.len, &bfd_offset);
&bfd_offset);
if (record_debug) if (record_debug)
gdb_printf (gdb_stdlog, gdb_printf (gdb_stdlog,
@@ -2456,14 +2446,13 @@ record_full_restore (void)
record_full_insn_num ++; record_full_insn_num ++;
/* Get signal value. */ /* Get signal value. */
bfdcore_read (current_program_space->core_bfd (), osec, &signal, bfdcore_read (&cbfd, osec, &signal, sizeof (signal),
sizeof (signal), &bfd_offset); &bfd_offset);
signal = netorder32 (signal); signal = netorder32 (signal);
rec->u.end.sigval = (enum gdb_signal) signal; rec->u.end.sigval = (enum gdb_signal) signal;
/* Get insn count. */ /* Get insn count. */
bfdcore_read (current_program_space->core_bfd (), osec, &count, bfdcore_read (&cbfd, osec, &count, sizeof (count), &bfd_offset);
sizeof (count), &bfd_offset);
count = netorder32 (count); count = netorder32 (count);
rec->u.end.insn_num = count; rec->u.end.insn_num = count;
record_full_insn_count = count + 1; record_full_insn_count = count + 1;
@@ -2479,7 +2468,7 @@ record_full_restore (void)
default: default:
error (_("Bad entry type in core file %s."), error (_("Bad entry type in core file %s."),
bfd_get_filename (current_program_space->core_bfd ())); bfd_get_filename (&cbfd));
break; break;
} }
@@ -2509,7 +2498,7 @@ record_full_restore (void)
/* Succeeded. */ /* Succeeded. */
gdb_printf (_("Restored records from core file %s.\n"), gdb_printf (_("Restored records from core file %s.\n"),
bfd_get_filename (current_program_space->core_bfd ())); bfd_get_filename (&cbfd));
print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1); print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
} }