From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 635793858C50 for ; Fri, 29 Sep 2023 18:25:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 635793858C50 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com Received: from localhost.localdomain (unknown [207.253.217.242]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id DF3011E0C2; Fri, 29 Sep 2023 14:25:43 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 1/5] gdb: add inferior::{arch, set_arch} Date: Fri, 29 Sep 2023 14:24:35 -0400 Message-ID: <20230929182541.138320-2-simon.marchi@efficios.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230929182541.138320-1-simon.marchi@efficios.com> References: <20230929182541.138320-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1173.3 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_SOFTFAIL,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 --- gdb/aarch64-linux-nat.c | 10 +++---- gdb/amd-dbgapi-target.c | 4 +-- gdb/amd64-linux-nat.c | 2 +- gdb/arch-utils.c | 4 +-- gdb/arm-fbsd-tdep.c | 2 +- gdb/auxv.c | 4 +-- gdb/inferior.c | 6 ++--- gdb/inferior.h | 34 +++++++++++++++--------- gdb/infrun.c | 8 +++--- gdb/jit.c | 2 +- gdb/linux-tdep.c | 6 ++--- gdb/ppc-linux-tdep.c | 2 +- gdb/proc-service.c | 2 +- gdb/process-stratum-target.c | 2 +- gdb/python/py-inferior.c | 2 +- gdb/python/python.c | 2 +- gdb/regcache.c | 8 +++--- gdb/remote.c | 4 +-- gdb/rs6000-tdep.c | 2 +- gdb/scoped-mock-context.h | 2 +- gdb/solib-rocm.c | 2 +- gdb/symfile-mem.c | 2 +- gdb/tui/tui-disasm.c | 2 +- gdb/unittests/frame_info_ptr-selftests.c | 2 +- gdb/value.c | 2 +- 25 files changed, 63 insertions(+), 55 deletions(-) diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index eeb9761bfe57..17976592df9c 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -904,22 +904,22 @@ 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 it if the current vector length matches the one in the tdep. */ aarch64_gdbarch_tdep *tdep - = gdbarch_tdep (inf->gdbarch); + = gdbarch_tdep (inf->arch ()); uint64_t vq = aarch64_sve_get_vq (ptid.lwp ()); if (vq == tdep->vq) - return inf->gdbarch; + return inf->arch (); /* We reach here if the 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 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; diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c index e5783580a62e..22c812628762 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 6571be40bb5e..f7f9a483def8 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 56c7fd2f5e73..748ca3535c2e 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -1478,7 +1478,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 (); } @@ -1488,7 +1488,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 b46fa91d0a0b..b6aa42a4fd05 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 9f599b04a4fe..7371fe687078 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. */ @@ -576,7 +576,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 550bbd2827c0..12419da2c3a9 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 29c90d15efae..29e26a5846b4 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -553,6 +553,14 @@ class inferior : public refcounted_object, 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 @@ class inferior : public refcounted_object, 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 @@ class inferior : public refcounted_object, /* 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 4730d2904423..784f0b96ebf5 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 804c832f47d3..1997be77b835 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 22bb9686e8da..a382a32ec623 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 784dafa59dbf..7c75bb5693d8 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 f735eb0ac812..e41278dbe6a8 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 5c031203e89e..173c3ecad134 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 906d402827ce..4f652004462e 100644 --- a/gdb/python/py-inferior.c +++ b/gdb/python/py-inferior.c @@ -786,7 +786,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 6a978d632e9a..29a9989a9d6b 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 91b20b7a2a2f..5acac2b8e472 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 9bb4f1de5982..54df818dcc4a 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 23397d037ae8..bae6737852d8 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 9ad7ebf5f0c4..5b5f46df7ba1 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 6b84f09e88ba..b24d0e8fb235 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 7ac3ac709ecb..956f10e387e6 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 03c78aa12911..c1ed491c5580 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 77052b3065f9..668133aa11c5 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 1cc326256293..190887471c35 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. */ -- 2.42.0