[PATCH] [gdb]: fix until behavior with trailing !is_stmt lines

Bruno Larsen blarsen@redhat.com
Tue Jan 4 20:34:14 GMT 2022


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(+)

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;
 
-- 
2.31.1



More information about the Gdb-patches mailing list