From: Andrew Burgess Date: Sun, 13 Sep 2020 20:53:26 +0000 (+0100) Subject: gdb: handle unmapped overlays in find_pc_line X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=31a8f60f2f31fccc1be955a692f1bd5330f8650d;p=binutils-gdb.git 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 14e754b7aa9..2744ad8e097 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2020-10-06 Andrew Burgess + + * symtab.c (find_pc_line): Return unmapped addresses when the + requested address is also unmapped. + 2020-10-05 Simon Marchi * Makefile.in (HFILES_NO_SRCDIR): Remove tui/tui-windata.h, add 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. */