[v3] Update the core file architecture if a target description is present

Message ID 20210623024249.4182433-1-luis.machado@linaro.org
State New
Headers show
Series
  • [v3] Update the core file architecture if a target description is present
Related show

Commit Message

Eli Zaretskii via Gdb-patches June 23, 2021, 2:42 a.m.
Updates on v3:

- Fetch an initial gdbarch before attempting to fetch a target description.

Updates on v2:

- Update the constructor to read the target description from the core file.

--

At the moment, the core target has its own gdbarch (m_core_gdbarch), and that
gets set from the core_bfd on the core target's constructor.

That gdbarch doesn't contain a target description because it is constructed
before we get a chance to fetch the target description.

As a result, some hooks that depend on the target description being set are
not set, and that leads to problems. One of the examples is
gdbarch_report_signal_info, which is used to show AArch64 tag violation
information.

Fix this by reading the target description before fetching the core file's
gdbarch.

gdb/ChangeLog:

YYYY-MM-DD  Luis Machado  <luis.machado@linaro.org>

	* corelow.c (core_target::core_target) Update to read target
	description.
---
 gdb/corelow.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

-- 
2.25.1

Comments

Eli Zaretskii via Gdb-patches June 23, 2021, 4:37 p.m. | #1
On 2021-06-22 10:42 p.m., Luis Machado via Gdb-patches wrote:
> Updates on v3:

> 

> - Fetch an initial gdbarch before attempting to fetch a target description.

> 

> Updates on v2:

> 

> - Update the constructor to read the target description from the core file.

> 

> --

> 

> At the moment, the core target has its own gdbarch (m_core_gdbarch), and that

> gets set from the core_bfd on the core target's constructor.

> 

> That gdbarch doesn't contain a target description because it is constructed

> before we get a chance to fetch the target description.

> 

> As a result, some hooks that depend on the target description being set are

> not set, and that leads to problems. One of the examples is

> gdbarch_report_signal_info, which is used to show AArch64 tag violation

> information.

> 

> Fix this by reading the target description before fetching the core file's

> gdbarch.


LGTM, thanks.

I don't really have an idea of a test for this, do you?

Simon
Eli Zaretskii via Gdb-patches June 23, 2021, 5:22 p.m. | #2
On 6/23/21 1:37 PM, Simon Marchi wrote:
> On 2021-06-22 10:42 p.m., Luis Machado via Gdb-patches wrote:

>> Updates on v3:

>>

>> - Fetch an initial gdbarch before attempting to fetch a target description.

>>

>> Updates on v2:

>>

>> - Update the constructor to read the target description from the core file.

>>

>> --

>>

>> At the moment, the core target has its own gdbarch (m_core_gdbarch), and that

>> gets set from the core_bfd on the core target's constructor.

>>

>> That gdbarch doesn't contain a target description because it is constructed

>> before we get a chance to fetch the target description.

>>

>> As a result, some hooks that depend on the target description being set are

>> not set, and that leads to problems. One of the examples is

>> gdbarch_report_signal_info, which is used to show AArch64 tag violation

>> information.

>>

>> Fix this by reading the target description before fetching the core file's

>> gdbarch.

> 

> LGTM, thanks.

> 

> I don't really have an idea of a test for this, do you?


Off the top of my head the only test that exercises this is 
aarch64-specific (as described above) and is included with the MTE core 
file support patch.

A generic test would need to verify that the core gdbarch matches the 
inferior's gdbarch, but I'm not sure how that could be accomplished.

> 

> Simon

>

Patch

diff --git a/gdb/corelow.c b/gdb/corelow.c
index a1943ab2ea6..b762eaa0f2f 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -154,8 +154,23 @@  class core_target final : public process_stratum_target
 
 core_target::core_target ()
 {
+  /* Find a first arch based on the BFD.  We need the initial gdbarch so
+     we can setup the hooks to find a target description.  */
   m_core_gdbarch = gdbarch_from_bfd (core_bfd);
 
+  /* If the arch is able to read a target description from the core, it
+     could yield a more specific gdbarch.  */
+  const struct target_desc *tdesc = read_description ();
+
+  if (tdesc != nullptr)
+    {
+      struct gdbarch_info info;
+      gdbarch_info_init (&info);
+      info.abfd = core_bfd;
+      info.target_desc = tdesc;
+      m_core_gdbarch = gdbarch_find_by_info (info);
+    }
+
   if (!m_core_gdbarch
       || !gdbarch_iterate_over_regset_sections_p (m_core_gdbarch))
     error (_("\"%s\": Core file format not supported"),