This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] Fix regression in "commands"


Pedro pointed out a regression in "commands", where trying to clear a
breakpoint's command list would fail:

    (top-gdb) commands
    Type commands for breakpoint(s) 3, one per line.
    End with a line saying just "end".
    >end
    No breakpoints specified.
    (top-gdb)

I believe the bug was introduced by my patch that changes
counted_command_line to be a shared_ptr.  This causes the problem
because now the counted_command_line in commands_command_1 can be NULL,
whereas previously it never could be.

The fix here is to track whether commands have been read using a
separate flag.

2017-11-03  Tom Tromey  <tom@tromey.com>

	* breakpoint.c (commands_command_1): Use a flag to track whether
	commands have been read.

2017-11-03  Tom Tromey  <tom@tromey.com>

	* gdb.base/break.exp: Add test for empty "commands".
---
 gdb/ChangeLog                    | 5 +++++
 gdb/breakpoint.c                 | 7 +++++--
 gdb/testsuite/ChangeLog          | 4 ++++
 gdb/testsuite/gdb.base/break.exp | 5 +++++
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1f823ca..0dc20bf 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2017-11-03  Tom Tromey  <tom@tromey.com>
+
+	* breakpoint.c (commands_command_1): Use a flag to track whether
+	commands have been read.
+
 2017-11-03  Ulrich Weigand  <uweigand@de.ibm.com>
 
 	* doublest.c (convert_doublest_to_floatformat): Fix uninitialized
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 0bf47d5..609f1ed 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1255,6 +1255,7 @@ commands_command_1 (const char *arg, int from_tty,
 		    struct command_line *control)
 {
   counted_command_line cmd;
+  bool read_commands = false;
 
   std::string new_arg;
 
@@ -1271,7 +1272,7 @@ commands_command_1 (const char *arg, int from_tty,
   map_breakpoint_numbers
     (arg, [&] (breakpoint *b)
      {
-       if (cmd == NULL)
+       if (!read_commands)
 	 {
 	   if (control != NULL)
 	     cmd = copy_command_lines (control->body_list[0]);
@@ -1288,6 +1289,8 @@ commands_command_1 (const char *arg, int from_tty,
 					  ? check_tracepoint_command : 0),
 					 b);
 	     }
+
+	   read_commands = true;
 	 }
 
        /* If a breakpoint was on the list more than once, we don't need to
@@ -1300,7 +1303,7 @@ commands_command_1 (const char *arg, int from_tty,
 	 }
      });
 
-  if (cmd == NULL)
+  if (!read_commands)
     error (_("No breakpoints specified."));
 }
 
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 158fea4..e82d2b9 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2017-11-03  Tom Tromey  <tom@tromey.com>
+
+	* gdb.base/break.exp: Add test for empty "commands".
+
 2017-11-03  Yao Qi  <yao.qi@linaro.org>
 
 	* gdb.mi/list-thread-groups-available.exp: Skip it if XML parsing
diff --git a/gdb/testsuite/gdb.base/break.exp b/gdb/testsuite/gdb.base/break.exp
index 96e2f35..604d957 100644
--- a/gdb/testsuite/gdb.base/break.exp
+++ b/gdb/testsuite/gdb.base/break.exp
@@ -854,3 +854,8 @@ gdb_test_no_output "set \$foo=81.5" \
 gdb_test "break $srcfile:\$foo" \
     "Convenience variables used in line specs must have integer values.*" \
     "set breakpoint via non-integer convenience variable disallowed"
+
+
+# Test that commands can be cleared without error.
+gdb_test "commands\nend" ">end" "clear breakpoint commands"
+
-- 
2.9.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]