diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-09-13 21:53:26 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-10-06 11:18:37 +0100 |
commit | 31a8f60f2f31fccc1be955a692f1bd5330f8650d (patch) | |
tree | 848371858a7543cb860705bbe05b171c31e1cc4e /gdb | |
parent | ed3bdac42ce8e545e04bd15a153a85aee4a7a9af (diff) | |
download | gdb-31a8f60f2f31fccc1be955a692f1bd5330f8650d.zip gdb-31a8f60f2f31fccc1be955a692f1bd5330f8650d.tar.gz gdb-31a8f60f2f31fccc1be955a692f1bd5330f8650d.tar.bz2 |
gdb: handle unmapped overlays in find_pc_line
I configured and built 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 some_global_variable;
/* 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 function's 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.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/symtab.c | 15 |
2 files changed, 17 insertions, 3 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 14e754b..2744ad8 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2020-10-06 Andrew Burgess <andrew.burgess@embecosm.com> + + * symtab.c (find_pc_line): Return unmapped addresses when the + requested address is also unmapped. + 2020-10-05 Simon Marchi <simon.marchi@efficios.com> * Makefile.in (HFILES_NO_SRCDIR): Remove tui/tui-windata.h, add diff --git a/gdb/symtab.c b/gdb/symtab.c index 04891c4..a4f8239 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. */ |