From: Simon Marchi Date: Fri, 29 Sep 2023 18:24:35 +0000 (-0400) Subject: gdb: add inferior::{arch, set_arch} X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=27b1f19f8f5cc46faba4bb2142547df074a82a29;p=binutils-gdb.git gdb: add inferior::{arch, set_arch} Make the inferior's gdbarch field private, and add getters and setters. This helped me by allowing putting breakpoints on set_arch to know when the inferior's arch was set. A subsequent patch in this series also adds more things in set_arch. Change-Id: I0005bd1ef4cd6b612af501201cec44e457998eec Reviewed-By: John Baldwin Approved-By: Andrew Burgess --- diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index c1d59b5d77c..eb54db4bff4 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -1005,24 +1005,24 @@ aarch64_linux_nat_target::thread_architecture (ptid_t ptid) /* If this is a 32-bit architecture, then this is ARM, not AArch64. There's no SVE vectors here, so just return the inferior architecture. */ - if (gdbarch_bfd_arch_info (inf->gdbarch)->bits_per_word == 32) - return inf->gdbarch; + if (gdbarch_bfd_arch_info (inf->arch ())->bits_per_word == 32) + return inf->arch (); /* Only return the inferior's gdbarch if both vq and svq match the ones in the tdep. */ aarch64_gdbarch_tdep *tdep - = gdbarch_tdep (inf->gdbarch); + = gdbarch_tdep (inf->arch ()); uint64_t vq = aarch64_sve_get_vq (ptid.lwp ()); uint64_t svq = aarch64_za_get_svq (ptid.lwp ()); if (vq == tdep->vq && svq == tdep->sme_svq) - return inf->gdbarch; + return inf->arch (); /* We reach here if any vector length for the thread is different from its value at process start. Lookup gdbarch via info (potentially creating a new one) by using a target description that corresponds to the new vq/svq value and the current architecture features. */ - const struct target_desc *tdesc = gdbarch_target_desc (inf->gdbarch); + const struct target_desc *tdesc = gdbarch_target_desc (inf->arch ()); aarch64_features features = aarch64_features_from_target_desc (tdesc); features.vq = vq; features.svq = svq; diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c index e5783580a62..22c81262876 100644 --- a/gdb/amd-dbgapi-target.c +++ b/gdb/amd-dbgapi-target.c @@ -430,7 +430,7 @@ amd_dbgapi_target_breakpoint::check_status (struct bpstat *bs) if (it == info->breakpoint_map.end ()) error (_("Could not find breakpoint_id for breakpoint at %s"), - paddress (inf->gdbarch, bs->bp_location_at->address)); + paddress (inf->arch (), bs->bp_location_at->address)); amd_dbgapi_breakpoint_id_t breakpoint_id { it->first }; amd_dbgapi_breakpoint_action_t action; @@ -443,7 +443,7 @@ amd_dbgapi_target_breakpoint::check_status (struct bpstat *bs) if (status != AMD_DBGAPI_STATUS_SUCCESS) error (_("amd_dbgapi_report_breakpoint_hit failed for breakpoint %ld " "at %s (%s)"), - breakpoint_id.handle, paddress (inf->gdbarch, bs->bp_location_at->address), + breakpoint_id.handle, paddress (inf->arch (), bs->bp_location_at->address), get_status_string (status)); if (action == AMD_DBGAPI_BREAKPOINT_ACTION_RESUME) diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c index 6571be40bb5..f7f9a483def 100644 --- a/gdb/amd64-linux-nat.c +++ b/gdb/amd64-linux-nat.c @@ -337,7 +337,7 @@ ps_err_e ps_get_thread_area (struct ps_prochandle *ph, lwpid_t lwpid, int idx, void **base) { - if (gdbarch_bfd_arch_info (ph->thread->inf->gdbarch)->bits_per_word == 32) + if (gdbarch_bfd_arch_info (ph->thread->inf->arch ())->bits_per_word == 32) { unsigned int base_addr; ps_err_e result; diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index 2e597beb5d4..5331bd86443 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -1488,7 +1488,7 @@ set_target_gdbarch (struct gdbarch *new_gdbarch) { gdb_assert (new_gdbarch != NULL); gdb_assert (new_gdbarch->initialized_p); - current_inferior ()->gdbarch = new_gdbarch; + current_inferior ()->set_arch (new_gdbarch); gdb::observers::architecture_changed.notify (new_gdbarch); registers_changed (); } @@ -1498,7 +1498,7 @@ set_target_gdbarch (struct gdbarch *new_gdbarch) struct gdbarch * target_gdbarch (void) { - return current_inferior ()->gdbarch; + return current_inferior ()->arch (); } void _initialize_gdbarch_utils (); diff --git a/gdb/arm-fbsd-tdep.c b/gdb/arm-fbsd-tdep.c index b46fa91d0a0..b6aa42a4fd0 100644 --- a/gdb/arm-fbsd-tdep.c +++ b/gdb/arm-fbsd-tdep.c @@ -247,7 +247,7 @@ arm_fbsd_read_description_auxv (bool tls) const gdb::optional &auxv = target_read_auxv (); return arm_fbsd_read_description_auxv (auxv, current_inferior ()->top_target (), - current_inferior ()->gdbarch, + current_inferior ()->arch (), tls); } diff --git a/gdb/auxv.c b/gdb/auxv.c index 8cda0b687b4..45f3e920d80 100644 --- a/gdb/auxv.c +++ b/gdb/auxv.c @@ -418,7 +418,7 @@ target_auxv_search (CORE_ADDR match, CORE_ADDR *valp) return -1; return target_auxv_search (*auxv, current_inferior ()->top_target (), - current_inferior ()->gdbarch, match, valp); + current_inferior ()->arch (), match, valp); } /* Print the description of a single AUXV entry on the specified file. */ @@ -580,7 +580,7 @@ fprint_target_auxv (struct ui_file *file) size_t len = auxv->size (); while (parse_auxv (current_inferior ()->top_target (), - current_inferior ()->gdbarch, + current_inferior ()->arch (), &ptr, data + len, &type, &val) > 0) { gdbarch_print_auxv_entry (gdbarch, file, type, val); diff --git a/gdb/inferior.c b/gdb/inferior.c index 550bbd2827c..12419da2c3a 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -847,10 +847,10 @@ add_inferior_with_spaces (void) /* Setup the inferior's initial arch, based on information obtained from the global "set ..." options. */ gdbarch_info info; - inf->gdbarch = gdbarch_find_by_info (info); + inf->set_arch (gdbarch_find_by_info (info)); /* The "set ..." options reject invalid settings, so we should always have a valid arch by now. */ - gdb_assert (inf->gdbarch != NULL); + gdb_assert (inf->arch () != nullptr); return inf; } @@ -1014,7 +1014,7 @@ clone_inferior_command (const char *args, int from_tty) inf = add_inferior (0); inf->pspace = pspace; inf->aspace = pspace->aspace; - inf->gdbarch = orginf->gdbarch; + inf->set_arch (orginf->arch ()); switch_to_inferior_and_push_target (inf, no_connection, orginf); diff --git a/gdb/inferior.h b/gdb/inferior.h index 29c90d15efa..29e26a5846b 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -553,6 +553,14 @@ public: return m_cwd; } + /* Set this inferior's arch. */ + void set_arch (gdbarch *arch) + { m_gdbarch = arch; } + + /* Get this inferior's arch. */ + gdbarch *arch () + { return m_gdbarch; } + /* Convenient handle (GDB inferior id). Unique across all inferiors. */ int num = 0; @@ -648,19 +656,6 @@ public: user supplied description's filename, if any; etc.). */ target_desc_info tdesc_info; - /* The architecture associated with the inferior through the - connection to the target. - - The architecture vector provides some information that is really - a property of the inferior, accessed through a particular target: - ptrace operations; the layout of certain RSP packets; the - solib_ops vector; etc. To differentiate architecture accesses to - per-inferior/target properties from - per-thread/per-frame/per-objfile properties, accesses to - per-inferior/target properties should be made through - this gdbarch. */ - struct gdbarch *gdbarch = NULL; - /* Data related to displaced stepping. */ displaced_step_inferior_state displaced_step_state; @@ -687,6 +682,19 @@ private: /* The current working directory that will be used when starting this inferior. */ std::string m_cwd; + + /* The architecture associated with the inferior through the + connection to the target. + + The architecture vector provides some information that is really + a property of the inferior, accessed through a particular target: + ptrace operations; the layout of certain RSP packets; the + solib_ops vector; etc. To differentiate architecture accesses to + per-inferior/target properties from + per-thread/per-frame/per-objfile properties, accesses to + per-inferior/target properties should be made through + this gdbarch. */ + gdbarch *m_gdbarch = nullptr; }; /* Add an inferior to the inferior list, print a message that a new diff --git a/gdb/infrun.c b/gdb/infrun.c index 4730d290442..784f0b96ebf 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -505,7 +505,7 @@ holding the child stopped. Try \"set detach-on-fork\" or \ child_inf->attach_flag = parent_inf->attach_flag; copy_terminal_info (child_inf, parent_inf); - child_inf->gdbarch = parent_inf->gdbarch; + child_inf->set_arch (parent_inf->arch ()); child_inf->tdesc_info = parent_inf->tdesc_info; child_inf->symfile_flags = SYMFILE_NO_READ; @@ -580,7 +580,7 @@ holding the child stopped. Try \"set detach-on-fork\" or \ child_inf->attach_flag = parent_inf->attach_flag; copy_terminal_info (child_inf, parent_inf); - child_inf->gdbarch = parent_inf->gdbarch; + child_inf->set_arch (parent_inf->arch ()); child_inf->tdesc_info = parent_inf->tdesc_info; if (has_vforked) @@ -5821,7 +5821,7 @@ handle_inferior_event (struct execution_control_state *ecs) } else { - struct gdbarch *gdbarch = current_inferior ()->gdbarch; + struct gdbarch *gdbarch = current_inferior ()->arch (); if (gdbarch_gdb_signal_to_target_p (gdbarch)) { @@ -9847,7 +9847,7 @@ namespace selftests static void infrun_thread_ptid_changed () { - gdbarch *arch = current_inferior ()->gdbarch; + gdbarch *arch = current_inferior ()->arch (); /* The thread which inferior_ptid represents changes ptid. */ { diff --git a/gdb/jit.c b/gdb/jit.c index 804c832f47d..1997be77b83 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -1159,7 +1159,7 @@ jit_inferior_init (inferior *inf) struct jit_descriptor descriptor; struct jit_code_entry cur_entry; CORE_ADDR cur_entry_addr; - struct gdbarch *gdbarch = inf->gdbarch; + struct gdbarch *gdbarch = inf->arch (); program_space *pspace = inf->pspace; jit_debug_printf ("called"); diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index f03a5b95332..f7b8a594097 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -2615,7 +2615,7 @@ linux_displaced_step_prepare (gdbarch *arch, thread_info *thread, /* Figure out the location of the buffers. They are contiguous, starting at DISP_STEP_BUF_ADDR. They are all of size BUF_LEN. */ CORE_ADDR disp_step_buf_addr - = linux_displaced_step_location (thread->inf->gdbarch); + = linux_displaced_step_location (thread->inf->arch ()); int buf_len = gdbarch_displaced_step_buffer_length (arch); linux_gdbarch_data *gdbarch_data = get_linux_gdbarch_data (arch); @@ -2701,7 +2701,7 @@ linux_get_hwcap () { return linux_get_hwcap (target_read_auxv (), current_inferior ()->top_target (), - current_inferior ()->gdbarch); + current_inferior ()->arch ()); } /* See linux-tdep.h. */ @@ -2720,7 +2720,7 @@ linux_get_hwcap2 () { return linux_get_hwcap2 (target_read_auxv (), current_inferior ()->top_target (), - current_inferior ()->gdbarch); + current_inferior ()->arch ()); } /* Display whether the gcore command is using the diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c index 784dafa59db..7c75bb5693d 100644 --- a/gdb/ppc-linux-tdep.c +++ b/gdb/ppc-linux-tdep.c @@ -2080,7 +2080,7 @@ ppc_linux_displaced_step_prepare (gdbarch *arch, thread_info *thread, { /* Figure out where the displaced step buffer is. */ CORE_ADDR disp_step_buf_addr - = linux_displaced_step_location (thread->inf->gdbarch); + = linux_displaced_step_location (thread->inf->arch ()); per_inferior->disp_step_buf.emplace (disp_step_buf_addr); } diff --git a/gdb/proc-service.c b/gdb/proc-service.c index f735eb0ac81..e41278dbe6a 100644 --- a/gdb/proc-service.c +++ b/gdb/proc-service.c @@ -137,7 +137,7 @@ get_ps_regcache (struct ps_prochandle *ph, lwpid_t lwpid) inferior *inf = ph->thread->inf; return get_thread_arch_regcache (inf->process_target (), ptid_t (inf->pid, lwpid), - inf->gdbarch); + inf->arch ()); } /* Get the general registers of LWP LWPID within the target process PH diff --git a/gdb/process-stratum-target.c b/gdb/process-stratum-target.c index 5c031203e89..173c3ecad13 100644 --- a/gdb/process-stratum-target.c +++ b/gdb/process-stratum-target.c @@ -45,7 +45,7 @@ process_stratum_target::thread_architecture (ptid_t ptid) { inferior *inf = find_inferior_ptid (this, ptid); gdb_assert (inf != NULL); - return inf->gdbarch; + return inf->arch (); } bool diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c index 1f20b9acd11..50d20c33b9d 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -788,7 +788,7 @@ infpy_architecture (PyObject *self, PyObject *args) INFPY_REQUIRE_VALID (inf); - return gdbarch_to_arch_object (inf->inferior->gdbarch); + return gdbarch_to_arch_object (inf->inferior->arch ()); } /* Implement repr() for gdb.Inferior. */ diff --git a/gdb/python/python.c b/gdb/python/python.c index faa7e0c217d..e56d2463d59 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1375,7 +1375,7 @@ gdbpy_format_address (PyObject *self, PyObject *args, PyObject *kw) /* Grab both of these from the current inferior, and its associated default architecture. */ pspace = current_inferior ()->pspace; - gdbarch = current_inferior ()->gdbarch; + gdbarch = current_inferior ()->arch (); } else if (arch_obj == nullptr || pspace_obj == nullptr) { diff --git a/gdb/regcache.c b/gdb/regcache.c index 91b20b7a2a2..5acac2b8e47 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -1627,7 +1627,7 @@ get_thread_arch_aspace_regcache_and_check (inferior *inf_for_target_calls, /* We currently only test with a single gdbarch. Any gdbarch will do, so use the current inferior's gdbarch. Also use the current inferior's address space. */ - gdbarch *arch = inf_for_target_calls->gdbarch; + gdbarch *arch = inf_for_target_calls->arch (); address_space *aspace = inf_for_target_calls->aspace; regcache *regcache = get_thread_arch_aspace_regcache (inf_for_target_calls, ptid, arch, aspace); @@ -1645,8 +1645,8 @@ struct regcache_test_data { regcache_test_data () /* The specific arch doesn't matter. */ - : test_ctx_1 (current_inferior ()->gdbarch), - test_ctx_2 (current_inferior ()->gdbarch) + : test_ctx_1 (current_inferior ()->arch ()), + test_ctx_2 (current_inferior ()->arch ()) { /* Ensure the regcaches container is empty at the start. */ registers_changed (); @@ -2094,7 +2094,7 @@ regcache_thread_ptid_changed () registers_changed (); /* Any arch will do. */ - gdbarch *arch = current_inferior ()->gdbarch; + gdbarch *arch = current_inferior ()->arch (); /* Prepare two targets with one thread each, with the same ptid. */ scoped_mock_context target1 (arch); diff --git a/gdb/remote.c b/gdb/remote.c index ae08c980efc..ff3f55d591f 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -7161,7 +7161,7 @@ remote_target::remote_stop_ns (ptid_t ptid) sr->ptid = tp->ptid; sr->rs = rs; sr->ws.set_stopped (GDB_SIGNAL_0); - sr->arch = tp->inf->gdbarch; + sr->arch = tp->inf->arch (); sr->stop_reason = TARGET_STOPPED_BY_NO_REASON; sr->watch_data_address = 0; sr->core = 0; @@ -7899,7 +7899,7 @@ Packet: '%s'\n"), continue; } - event->arch = inf->gdbarch; + event->arch = inf->arch (); rsa = event->rs->get_remote_arch_state (event->arch); } diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c index 23397d037ae..bae6737852d 100644 --- a/gdb/rs6000-tdep.c +++ b/gdb/rs6000-tdep.c @@ -1087,7 +1087,7 @@ ppc_displaced_step_prepare (gdbarch *arch, thread_info *thread, { /* Figure out where the displaced step buffer is. */ CORE_ADDR disp_step_buf_addr - = displaced_step_at_entry_point (thread->inf->gdbarch); + = displaced_step_at_entry_point (thread->inf->arch ()); per_inferior->disp_step_buf.emplace (disp_step_buf_addr); } diff --git a/gdb/scoped-mock-context.h b/gdb/scoped-mock-context.h index 9ad7ebf5f0c..5b5f46df7ba 100644 --- a/gdb/scoped-mock-context.h +++ b/gdb/scoped-mock-context.h @@ -52,7 +52,7 @@ struct scoped_mock_context mock_inferior.thread_list.push_back (mock_thread); mock_inferior.ptid_thread_map[mock_ptid] = &mock_thread; - mock_inferior.gdbarch = gdbarch; + mock_inferior.set_arch (gdbarch); mock_inferior.aspace = mock_pspace.aspace; mock_inferior.pspace = &mock_pspace; diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c index 6b84f09e88b..b24d0e8fb23 100644 --- a/gdb/solib-rocm.c +++ b/gdb/solib-rocm.c @@ -773,7 +773,7 @@ rocm_update_solib_list () rocm_solib_ops.handle_event = rocm_solib_handle_event; /* Engage the ROCm so_ops. */ - set_gdbarch_so_ops (current_inferior ()->gdbarch, &rocm_solib_ops); + set_gdbarch_so_ops (current_inferior ()->arch (), &rocm_solib_ops); } } diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c index 7ac3ac709ec..956f10e387e 100644 --- a/gdb/symfile-mem.c +++ b/gdb/symfile-mem.c @@ -162,7 +162,7 @@ add_vsyscall_page (inferior *inf) { struct mem_range vsyscall_range; - if (gdbarch_vsyscall_range (inf->gdbarch, &vsyscall_range)) + if (gdbarch_vsyscall_range (inf->arch (), &vsyscall_range)) { struct bfd *bfd; diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index 03c78aa1291..c1ed491c558 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -539,7 +539,7 @@ run_tests () { if (current_inferior () != nullptr) { - struct gdbarch *gdbarch = current_inferior ()->gdbarch; + gdbarch *gdbarch = current_inferior ()->arch (); /* Check that tui_find_disassembly_address robustly handles the case of being passed a PC for which gdb_print_insn throws a MEMORY_ERROR. */ diff --git a/gdb/unittests/frame_info_ptr-selftests.c b/gdb/unittests/frame_info_ptr-selftests.c index 77052b3065f..668133aa11c 100644 --- a/gdb/unittests/frame_info_ptr-selftests.c +++ b/gdb/unittests/frame_info_ptr-selftests.c @@ -51,7 +51,7 @@ static void test_user_created_frame () { scoped_mock_context mock_context - (current_inferior ()->gdbarch); + (current_inferior ()->arch ()); frame_info_ptr frame = create_new_frame (0x1234, 0x5678); validate_user_created_frame (get_frame_id (frame)); diff --git a/gdb/value.c b/gdb/value.c index 1cc32625629..190887471c3 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -4222,7 +4222,7 @@ test_insert_into_bit_range_vector () static void test_value_copy () { - type *type = builtin_type (current_inferior ()->gdbarch)->builtin_int; + type *type = builtin_type (current_inferior ()->arch ())->builtin_int; /* Verify that we can copy an entirely optimized out value, that may not have its contents allocated. */