aboutsummaryrefslogtreecommitdiff
path: root/gdb/symtab.c
diff options
context:
space:
mode:
authorCarl Love <cel@linux.ibm.com>2024-01-02 17:46:02 -0500
committerCarl Love <cel@linux.ibm.com>2024-01-02 17:46:02 -0500
commitfe6356def678a93121a68147bdf93b6980bbf75d (patch)
treecb2ff763d9af621b425751841cd6255ee59baa94 /gdb/symtab.c
parent29deb4221d07d2c497183853e6023acb51d49be9 (diff)
downloadbinutils-fe6356def678a93121a68147bdf93b6980bbf75d.zip
binutils-fe6356def678a93121a68147bdf93b6980bbf75d.tar.gz
binutils-fe6356def678a93121a68147bdf93b6980bbf75d.tar.bz2
PowerPC and aarch64: Fix reverse stepping failure
When running GDB's testsuite on aarch64-linux/Ubuntu 20.04 (also spotted on the ppc backend), there are failures in gdb.reverse/solib-precsave.exp and gdb.reverse/solib-reverse.exp. The failure happens around the following code: 38 b[1] = shr2(17); /* middle part two */ 40 b[0] = 6; b[1] = 9; /* generic statement, end part two */ 42 shr1 ("message 1\n"); /* shr1 one */ Normal execution: - step from line 38 will land on line 40. - step from line 40 will land on line 42. Reverse execution: - step from line 42 will land on line 40. - step from line 40 will land on line 40. - step from line 40 will land on line 38. The problem here is that line 40 contains two contiguous but distinct PC ranges in the line table, like so: Line 40 - [0x7ec ~ 0x7f4] Line 40 - [0x7f4 ~ 0x7fc] The two distinct ranges are generated because GCC started outputting source column information, which GDB doesn't take into account at the moment. When stepping forward from line 40, we skip both of these ranges and land on line 42. When stepping backward from line 42, we stop at the start PC of the second (or first, going backwards) range of line 40. Since we've reached ecs->event_thread->control.step_range_start, we stop stepping backwards. The above issues were fixed by introducing a new function that looks for adjacent PC ranges for the same line, until we notice a line change. Then we take that as the start PC of the range. The new start PC for the range is used for the control.step_range_start when setting up a step range. The test case gdb.reverse/map-to-same-line.exp is added to test the fix for the above reverse step issues. Patch has been tested on PowerPC, X86 and AArch64 with no regressions.
Diffstat (limited to 'gdb/symtab.c')
-rw-r--r--gdb/symtab.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 7b05594..ffb095a 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -73,6 +73,7 @@
#include <string_view>
#include "gdbsupport/pathstuff.h"
#include "gdbsupport/common-utils.h"
+#include <optional>
/* Forward declarations for local functions. */
@@ -3317,6 +3318,55 @@ find_pc_line (CORE_ADDR pc, int notcurrent)
return sal;
}
+/* Compare two symtab_and_line entries. Return true if both have
+ the same line number and the same symtab pointer. That means we
+ are dealing with two entries from the same line and from the same
+ source file.
+
+ Return false otherwise. */
+
+static bool
+sal_line_symtab_matches_p (const symtab_and_line &sal1,
+ const symtab_and_line &sal2)
+{
+ return sal1.line == sal2.line && sal1.symtab == sal2.symtab;
+}
+
+/* See symtah.h. */
+
+std::optional<CORE_ADDR>
+find_line_range_start (CORE_ADDR pc)
+{
+ struct symtab_and_line current_sal = find_pc_line (pc, 0);
+
+ if (current_sal.line == 0)
+ return {};
+
+ struct symtab_and_line prev_sal = find_pc_line (current_sal.pc - 1, 0);
+
+ /* If the previous entry is for a different line, that means we are already
+ at the entry with the start PC for this line. */
+ if (!sal_line_symtab_matches_p (prev_sal, current_sal))
+ return current_sal.pc;
+
+ /* Otherwise, keep looking for entries for the same line but with
+ smaller PC's. */
+ bool done = false;
+ CORE_ADDR prev_pc;
+ while (!done)
+ {
+ prev_pc = prev_sal.pc;
+
+ prev_sal = find_pc_line (prev_pc - 1, 0);
+
+ /* Did we notice a line change? If so, we are done searching. */
+ if (!sal_line_symtab_matches_p (prev_sal, current_sal))
+ done = true;
+ }
+
+ return prev_pc;
+}
+
/* See symtab.h. */
struct symtab *