: fix until behavior with trailing !is_stmt lines

Message ID 20220104203414.70308-1-blarsen@redhat.com
State New
Headers show
Series
  • : fix until behavior with trailing !is_stmt lines
Related show

Commit Message

Simon Marchi via Gdb-patches Jan. 4, 2022, 8:34 p.m.
When using the command "until", it is expected that GDB will exit a
loop, if the current line is the last statement. However, if there were
trailing non-statement linetable entries, "until" would just behave as
"next". This was most noticeable in clang-compiled code, but could
apparently happen with gcc-compiled as well.

The current patch fixes this by adding an extra step to the
until_next_command function, going through all the following linetable
entries for the same line that are not statements, to use the final one
as the final end pc.

This fixed PR/17315

---
 gdb/infcmd.c | 8 ++++++++
 1 file changed, 8 insertions(+)

-- 
2.31.1

Patch

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index e0e317d0757..d1646656d49 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1346,6 +1346,14 @@  until_next_command (int from_tty)
 
       tp->control.step_range_start = BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (func));
       tp->control.step_range_end = sal.end;
+      struct symtab_and_line final_sal;
+      final_sal = find_pc_line (tp->control.step_range_end, 0);
+      while (final_sal.line == sal.line){
+	  /* if there is another stmt for the same line, we dont need this */
+	  if (final_sal.is_stmt) break;
+	  tp->control.step_range_end = final_sal.end;
+	  final_sal = find_pc_line (final_sal.end, 0);
+      }
     }
   tp->control.may_range_step = 1;