public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/2] gdb: handle unmapped overlays in find_pc_line
Date: Fri, 18 Sep 2020 19:17:35 +0100	[thread overview]
Message-ID: <c595891e77b4103fcef748601bebffe8f5b76549.1600452947.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1600452947.git.andrew.burgess@embecosm.com>

I configured and build an m32r-elf toolchain, and ran the
gdb.base/overlays.exp test.  I saw a couple of errors where GDB would
place a breakpoint in the wrong place when placing a breakpoint using
a function name, for example in this function:

/* 1 */  int foo (int x)
/* 2 */  {
/* 3 */    if (x)
/* 4 */      return foox;
/* 5 */    else
/* 6 */      return 0;
/* 7 */  }

GDB would place the breakpoint on line 2 instead of line 3.  The issue
is that GDB was failing to skip the prologue correctly.

The reason for this is that in m32r-tdep.c:m32r_skip_prologue, we
first use find_pc_partial_function to find the functions start and end
addresses, then we use find_pc_line to find the start and end of the
first line of the function.

Currently, if the pc value passed to find_pc_partial_function is in an
unmapped overlay then the function start and end addresses that are
returned are also the unmapped addresses.

However, this is not the case for find_pc_line, here, if the address
passed in is in an unmapped overlay then we still get back a
symtab_and_line describing the mapped location.

What this means is that if a functions mapped location is 0x100 ->
0x120, and its unmapped locations is 0x400 -> 0x420 then we think that
the start/end is 0x400 and 0x420 respectively, but the first line
might run from 0x100 to 0x108.

GDB will then try to scan the prologue starting from 0x400 and ending
at 0x108, this immediately gives up as it thinks we have gone past the
end of the prologue and the breakpoint is placed at 0x400.

In this commit I propose that we change find_pc_line to return
addresses in the unmapped range if the address passed in is already in
the unmapped range.  Now the first line will appear to run from 0x400
to 0x408 and the prologue scanner will correctly find the end of the
prologue.

With this commit gdb.base/overlays.exp now completely passes with an
m32r-elf toolchain.

gdb/ChangeLog:

	* symtab.c (find_pc_line): Return unmapped addresses when the
	requested address is also unmapped.
---
 gdb/ChangeLog |  5 +++++
 gdb/symtab.c  | 15 ++++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 04891c4a89b..a4f8239a8a1 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -3323,9 +3323,18 @@ find_pc_line (CORE_ADDR pc, int notcurrent)
   struct obj_section *section;
 
   section = find_pc_overlay (pc);
-  if (pc_in_unmapped_range (pc, section))
-    pc = overlay_mapped_address (pc, section);
-  return find_pc_sect_line (pc, section, notcurrent);
+  if (!pc_in_unmapped_range (pc, section))
+    return find_pc_sect_line (pc, section, notcurrent);
+
+  /* If the original PC was an unmapped address then we translate this to a
+     mapped address in order to lookup the sal.  However, as the user
+     passed us an unmapped address it makes more sense to return a result
+     that has the pc and end fields translated to unmapped addresses.  */
+  pc = overlay_mapped_address (pc, section);
+  symtab_and_line sal = find_pc_sect_line (pc, section, notcurrent);
+  sal.pc = overlay_unmapped_address (sal.pc, section);
+  sal.end = overlay_unmapped_address (sal.end, section);
+  return sal;
 }
 
 /* See symtab.h.  */
-- 
2.25.4


  parent reply	other threads:[~2020-09-18 18:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-18 18:17 [PATCH 0/2] Get gdb.base/overlays.exp passing on m32r Andrew Burgess
2020-09-18 18:17 ` [PATCH 1/2] gdb/testsuite: allow gdb.base/overlays.exp to compile for m32r Andrew Burgess
2020-09-18 18:17 ` Andrew Burgess [this message]
2020-09-20 21:08   ` [PATCH 2/2] gdb: handle unmapped overlays in find_pc_line Simon Marchi
2020-09-21  8:47     ` Andrew Burgess
2020-10-06 10:25 ` [PATCH 0/2] Get gdb.base/overlays.exp passing on m32r Andrew Burgess

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=c595891e77b4103fcef748601bebffe8f5b76549.1600452947.git.andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).