]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: test to check one aspect of the linespec parsing code
authorAndrew Burgess <aburgess@redhat.com>
Thu, 27 Jan 2022 15:12:25 +0000 (15:12 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Wed, 2 Feb 2022 16:27:36 +0000 (16:27 +0000)
While working on the fix for PR cli/28665 (see previous couple of
commits), I was playing with making a change in the linespec parsing
code.  Specifically, I was thinking about whether the spec_string for
LINESPEC_LOCATION locations should ever be nullptr.

I made a change to prevent the spec_string from ever being nullptr,
tested gdb, and saw no regressions.

However, as part of this work I was reviewing how the breakpoint code
handles this case (spec_string being nullptr), and spotted that in
parse_breakpoint_sals the nullptr case is specifically handled, so
changing this should have caused a regression.  But I didn't see one.

So, this commit adds a comment in location.c mentioning that the
nullptr case is (a) not an oversight, and (b) is required.  Then I add
a new test to gdb.base/break.exp that ensures a change in this area
will cause a regression.

This test passes on current gdb, but with my modified (and broken)
gdb, the test would fail.

gdb/location.c
gdb/testsuite/gdb.base/break.exp

index 299ef7ecaddb0064f8004d75f01e0887eeef821b..0459980ab8c072de4716e6fed358eae4341b6cce 100644 (file)
@@ -134,6 +134,11 @@ struct event_location_linespec : public event_location
 
        linespec_lex_to_end (linespec);
        p = remove_trailing_whitespace (orig, *linespec);
+
+       /* If there is no valid linespec then this will leave the
+          spec_string as nullptr.  This behaviour is relied on in the
+          breakpoint setting code, where spec_string being nullptr means
+          to use the default breakpoint location.  */
        if ((p - orig) > 0)
          linespec_location.spec_string = savestring (orig, p - orig);
       }
index 39a8f32e88836897a5431e95d53e38f37031c35d..2c939ada14ac1edf48a22537fe29a01b4f4d4697 100644 (file)
@@ -520,6 +520,11 @@ gdb_test "break" \
     "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
     "break on default location, 4th time"
 
+# Check setting a breakpoint at the default location with a condition attached.
+gdb_test "break if (1)" \
+    "Note: breakpoints \[0-9\]*, \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*" \
+    "break on the default location, 5th time, but with a condition"
+
 # Verify that a "silent" breakpoint can be set, and that GDB is indeed
 # "silent" about its triggering.
 #