aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2025-08-27 11:30:47 +0100
committerAndrew Burgess <aburgess@redhat.com>2025-09-04 16:16:01 +0100
commita839a42bcd865707b25a3b787858d019a41b8b8e (patch)
treee369c9839b228fd76e7e118c38d82ebfd60b3ef7
parent9cede382cb96b08bff9dcdb18aa959ec6f18f04f (diff)
downloadbinutils-a839a42bcd865707b25a3b787858d019a41b8b8e.zip
binutils-a839a42bcd865707b25a3b787858d019a41b8b8e.tar.gz
binutils-a839a42bcd865707b25a3b787858d019a41b8b8e.tar.bz2
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>
-rw-r--r--gdb/record-full.c67
1 files changed, 28 insertions, 39 deletions
diff --git a/gdb/record-full.c b/gdb/record-full.c
index c55e3b9..2fbdf3b 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -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
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);
}
-/* 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
-record_full_core_open_1 ()
+record_full_core_open_1 (struct bfd &cbfd)
{
regcache *regcache = get_thread_regcache (inferior_thread ());
int regnum = gdbarch_num_regs (regcache->arch ());
@@ -937,11 +938,10 @@ record_full_core_open_1 ()
for (i = 0; i < regnum; i ++)
record_full_core_regbuf->raw_supply (i, *regcache);
- record_full_core_sections
- = build_section_table (current_program_space->core_bfd ());
+ record_full_core_sections = build_section_table (&cbfd);
current_inferior ()->push_target (&record_full_core_ops);
- record_full_restore ();
+ record_full_restore (cbfd);
}
/* 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->next = NULL;
- if (current_program_space->core_bfd ())
- record_full_core_open_1 ();
+ if (current_program_space->core_bfd () != nullptr)
+ record_full_core_open_1 (*current_program_space->core_bfd ());
else
record_full_open_1 ();
@@ -2332,9 +2332,10 @@ netorder32 (uint32_t input)
return ret;
}
-/* Restore the execution log from a core_bfd file. */
+/* Restore the execution log from core file CBFD. */
+
static void
-record_full_restore (void)
+record_full_restore (struct bfd &cbfd)
{
uint32_t magic;
struct record_full_entry *rec;
@@ -2342,11 +2343,6 @@ record_full_restore (void)
uint32_t osec_size;
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. */
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");
/* 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)
gdb_printf (gdb_stdlog, "Find precord section %s.\n",
osec ? "succeeded" : "failed");
@@ -2365,11 +2361,10 @@ record_full_restore (void)
gdb_printf (gdb_stdlog, "%s", bfd_section_name (osec));
/* Check the magic code. */
- bfdcore_read (current_program_space->core_bfd (), osec, &magic,
- sizeof (magic), &bfd_offset);
+ bfdcore_read (&cbfd, osec, &magic, sizeof (magic), &bfd_offset);
if (magic != RECORD_FULL_FILE_MAGIC)
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)
gdb_printf (gdb_stdlog,
" Reading 4-byte magic cookie "
@@ -2395,23 +2390,21 @@ record_full_restore (void)
/* We are finished when offset reaches osec_size. */
if (bfd_offset >= osec_size)
break;
- bfdcore_read (current_program_space->core_bfd (), osec, &rectype,
- sizeof (rectype), &bfd_offset);
+ bfdcore_read (&cbfd, osec, &rectype, sizeof (rectype), &bfd_offset);
switch (rectype)
{
case record_full_reg: /* reg */
/* Get register number to regnum. */
- bfdcore_read (current_program_space->core_bfd (), osec, &regnum,
- sizeof (regnum), &bfd_offset);
+ bfdcore_read (&cbfd, osec, &regnum, sizeof (regnum),
+ &bfd_offset);
regnum = netorder32 (regnum);
rec = record_full_reg_alloc (regcache, regnum);
/* Get val. */
- bfdcore_read (current_program_space->core_bfd (), osec,
- record_full_get_loc (rec), rec->u.reg.len,
- &bfd_offset);
+ bfdcore_read (&cbfd, osec, record_full_get_loc (rec),
+ rec->u.reg.len, &bfd_offset);
if (record_debug)
gdb_printf (gdb_stdlog,
@@ -2424,21 +2417,18 @@ record_full_restore (void)
case record_full_mem: /* mem */
/* Get len. */
- bfdcore_read (current_program_space->core_bfd (), osec, &len,
- sizeof (len), &bfd_offset);
+ bfdcore_read (&cbfd, osec, &len, sizeof (len), &bfd_offset);
len = netorder32 (len);
/* Get addr. */
- bfdcore_read (current_program_space->core_bfd (), osec, &addr,
- sizeof (addr), &bfd_offset);
+ bfdcore_read (&cbfd, osec, &addr, sizeof (addr), &bfd_offset);
addr = netorder64 (addr);
rec = record_full_mem_alloc (addr, len);
/* Get val. */
- bfdcore_read (current_program_space->core_bfd (), osec,
- record_full_get_loc (rec), rec->u.mem.len,
- &bfd_offset);
+ bfdcore_read (&cbfd, osec, record_full_get_loc (rec),
+ rec->u.mem.len, &bfd_offset);
if (record_debug)
gdb_printf (gdb_stdlog,
@@ -2456,14 +2446,13 @@ record_full_restore (void)
record_full_insn_num ++;
/* Get signal value. */
- bfdcore_read (current_program_space->core_bfd (), osec, &signal,
- sizeof (signal), &bfd_offset);
+ bfdcore_read (&cbfd, osec, &signal, sizeof (signal),
+ &bfd_offset);
signal = netorder32 (signal);
rec->u.end.sigval = (enum gdb_signal) signal;
/* Get insn count. */
- bfdcore_read (current_program_space->core_bfd (), osec, &count,
- sizeof (count), &bfd_offset);
+ bfdcore_read (&cbfd, osec, &count, sizeof (count), &bfd_offset);
count = netorder32 (count);
rec->u.end.insn_num = count;
record_full_insn_count = count + 1;
@@ -2479,7 +2468,7 @@ record_full_restore (void)
default:
error (_("Bad entry type in core file %s."),
- bfd_get_filename (current_program_space->core_bfd ()));
+ bfd_get_filename (&cbfd));
break;
}
@@ -2509,7 +2498,7 @@ record_full_restore (void)
/* Succeeded. */
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);
}