aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.reverse/step-reverse.c
diff options
context:
space:
mode:
authorBruno Larsen <blarsen@redhat.com>2022-05-25 15:02:47 -0300
committerBruno Larsen <blarsen@redhat.com>2022-10-21 12:49:26 +0200
commit1f3e37e057e876b37db49dbd8ed5ca22c33f6772 (patch)
tree722e065fd81c27111e6668e0bbe9fc17a9f801ed /gdb/testsuite/gdb.reverse/step-reverse.c
parent49d7cd733a7f1b87aa1d40318b3d7c2b65aca5ac (diff)
downloadbinutils-1f3e37e057e876b37db49dbd8ed5ca22c33f6772.zip
binutils-1f3e37e057e876b37db49dbd8ed5ca22c33f6772.tar.gz
binutils-1f3e37e057e876b37db49dbd8ed5ca22c33f6772.tar.bz2
gdb/reverse: Fix stepping over recursive functions
Currently, when using GDB to do reverse debugging, if we try to use the command "reverse next" to skip a recursive function, instead of skipping all of the recursive calls and stopping in the previous line, we stop at the second to last recursive call, and need to manually step backwards until we leave the first call. This is well documented in PR gdb/16678. This bug happens because when GDB notices that a reverse step has entered into a function, GDB will add a step_resume_breakpoint at the start of the function, then single step out of the prologue once that breakpoint is hit. The problem was happening because GDB wouldn't give that step_resume_breakpoint a frame-id, so the first time the breakpoint was hit, the inferior would be stopped. This is fixed by giving the current frame-id to the breakpoint. This commit also changes gdb.reverse/step-reverse.c to contain a recursive function and attempt to both, skip it altogether, and to skip the second call from inside the first call, as this setup broke a previous version of the patch.
Diffstat (limited to 'gdb/testsuite/gdb.reverse/step-reverse.c')
-rw-r--r--gdb/testsuite/gdb.reverse/step-reverse.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.reverse/step-reverse.c b/gdb/testsuite/gdb.reverse/step-reverse.c
index aea2a98..809c7d1 100644
--- a/gdb/testsuite/gdb.reverse/step-reverse.c
+++ b/gdb/testsuite/gdb.reverse/step-reverse.c
@@ -26,6 +26,20 @@ int callee() { /* ENTER CALLEE */
return myglob++; /* ARRIVED IN CALLEE */
} /* RETURN FROM CALLEE */
+/* We need to make this function take more than a single instruction
+ to run, otherwise it could hide PR gdb/16678, as reverse execution can
+ step over a single-instruction function. */
+int
+recursive_callee (int val)
+{
+ if (val == 0)
+ return 0;
+ val /= 2;
+ if (val > 1)
+ val++;
+ return recursive_callee (val); /* RECURSIVE CALL */
+} /* EXIT RECURSIVE FUNCTION */
+
/* A structure which, we hope, will need to be passed using memcpy. */
struct rhomboidal {
int rather_large[100];
@@ -51,6 +65,9 @@ int main () {
y = y + 4;
z = z + 5; /* STEP TEST 2 */
+ /* Test that next goes over recursive calls too */
+ recursive_callee (32); /* NEXT OVER THIS RECURSION */
+
/* Test that "next" goes over a call */
callee(); /* NEXT OVER THIS CALL */
@@ -60,7 +77,7 @@ int main () {
/* Test "stepi" */
a[5] = a[3] - a[4]; /* FINISH TEST */
callee(); /* STEPI TEST */
-
+
/* Test "nexti" */
callee(); /* NEXTI TEST */