Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Subject: [PATCH] gdb: fix logic of find_comp_unit and set_comp_unit
Date: Thu,  3 Dec 2020 13:00:11 -0500	[thread overview]
Message-ID: <20201203180011.1909405-1-simon.marchi@polymtl.ca> (raw)

The logic in find_comp_unit and set_comp_unit is reversed.  When the BFD
requires relocation, we want to put the comp_unit structure in the
map where the comp_unit objects are not shared, that is the one indexed
by objfile.  If the BFD does not require relocation, then, we can share
a single comp_unit structure for all users of that BFD, so we want to
put it in the BFD-indexed map.  The comments on top of
dwarf2_frame_bfd_data and dwarf2_frame_objfile_data make that clear.

Fix it by swapping the two in find_comp_unit and set_comp_unit.

I don't have a test for this, because I don't see how to write one in a
reasonable amount of time.

gdb/ChangeLog:

	PR gdb/26876
	* dwarf2/frame.c (find_comp_unit, set_comp_unit): Reverse use of
	dwarf2_frame_bfd_data and dwarf2_frame_objfile_data.

Change-Id: I80c1ee7ad8425fa4947de65b170973d05f5a52ec
---
 gdb/dwarf2/frame.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c
index a577a671f242..7df3ccfe46a7 100644
--- a/gdb/dwarf2/frame.c
+++ b/gdb/dwarf2/frame.c
@@ -1640,8 +1640,9 @@ find_comp_unit (struct objfile *objfile)
 {
   bfd *abfd = objfile->obfd;
   if (gdb_bfd_requires_relocations (abfd))
-    return dwarf2_frame_bfd_data.get (abfd);
-  return dwarf2_frame_objfile_data.get (objfile);
+    return dwarf2_frame_objfile_data.get (objfile);
+
+  return dwarf2_frame_bfd_data.get (abfd);
 }
 
 /* Store the comp_unit on OBJFILE, or the corresponding BFD, as
@@ -1652,8 +1653,9 @@ set_comp_unit (struct objfile *objfile, struct comp_unit *unit)
 {
   bfd *abfd = objfile->obfd;
   if (gdb_bfd_requires_relocations (abfd))
-    return dwarf2_frame_bfd_data.set (abfd, unit);
-  return dwarf2_frame_objfile_data.set (objfile, unit);
+    return dwarf2_frame_objfile_data.set (objfile, unit);
+
+  return dwarf2_frame_bfd_data.set (abfd, unit);
 }
 
 /* Find the FDE for *PC.  Return a pointer to the FDE, and store the
-- 
2.29.2


             reply	other threads:[~2020-12-03 18:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03 18:00 Simon Marchi via Gdb-patches [this message]
2020-12-03 20:42 ` Tom Tromey
2020-12-03 20:48   ` Simon Marchi via Gdb-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201203180011.1909405-1-simon.marchi@polymtl.ca \
    --to=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox