From 31a8f60f2f31fccc1be955a692f1bd5330f8650d Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Sun, 13 Sep 2020 21:53:26 +0100 Subject: 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. --- gdb/symtab.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'gdb/symtab.c') 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. */ -- cgit v1.1