aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.linespec
diff options
context:
space:
mode:
authorKeith Seitz <keiths@redhat.com>2015-03-23 12:59:18 -0700
committerKeith Seitz <keiths@redhat.com>2015-03-23 13:16:39 -0700
commit0578b14e990e76f3c2dd9010c4cb9201bc9fa4b4 (patch)
treef1d3015cb60449da8288124ca8634ac7aa13a584 /gdb/testsuite/gdb.linespec
parent7e993ebf2343a5b39d6d1df29fdebc2818064ae5 (diff)
downloadgdb-0578b14e990e76f3c2dd9010c4cb9201bc9fa4b4.zip
gdb-0578b14e990e76f3c2dd9010c4cb9201bc9fa4b4.tar.gz
gdb-0578b14e990e76f3c2dd9010c4cb9201bc9fa4b4.tar.bz2
Expand keyword lexing intelligence in the linespec parser.
This patch changes the heuristic the linespec lexer uses to detect a keyword in the input stream. Currently, the heuristic is: a word is a keyword if it 1) points to a string that is a keyword 2) is followed by a non-identifier character This is strictly more correct than using whitespace. For example, it allows constructs such as "break foo if(i == 1)". However, find_condition_and_thread in breakpoint.c does not support this expanded usage. It requires whitespace to follow the keyword. The proposed new heuristic is: a word is a keyword if it 1) points to a string that is a keyword 2) is followed by whitespace 3) is not followed by another keyword string followed by whitespace This additional complexity allows constructs such as "break thread thread 3" and "break thread 3". In the former case, the actual location is a symbol named "thread" to be set on thread #3. In the later case, the location is NULL, i.e., the default location, to be set on thread #3. In order to pass all the new tests added here, I've also had to add a new feature to parse_breakpoint_sals, which expands recognition of the default location to keywords other than "if", which is the only keyword currently permitted with the default (NULL) location, but there is no reason to exclude other keywords. Consequently, it will be possible to use "break thread 1" or "break task 1". In addition to all of this, it is now possible to remove the keyword_ok state from the linespec parser. gdb/ChangeLog * breakpoint.c (parse_breakpoint_sals): Use linespec_lexer_lex_keyword to ascertain if the user specified a NULL location. * linespec.c [IF_KEYWORD_INDEX]: Define. (linespec_lexer_lex_keyword): Export. (struct ls_parser) <keyword_ok>: Remove. A keyword is only a keyword if not followed by another keyword. (linespec_lexer_lex_one): Remove keyword_ok handling. Add comment explaining why the parsing stream is not advanced when a keyword is seen. (parse_linespec): Remove parser->keyword_ok. * linespec.h (linespec_lexer_lex_keyword): Add declaration. gdb/testsuite/ChangeLog * gdb.linespec/keywords.c: New file. * gdb.linespec/keywords.exp: New file.
Diffstat (limited to 'gdb/testsuite/gdb.linespec')
-rw-r--r--gdb/testsuite/gdb.linespec/keywords.c36
-rw-r--r--gdb/testsuite/gdb.linespec/keywords.exp77
2 files changed, 113 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.linespec/keywords.c b/gdb/testsuite/gdb.linespec/keywords.c
new file mode 100644
index 0000000..de2db63
--- /dev/null
+++ b/gdb/testsuite/gdb.linespec/keywords.c
@@ -0,0 +1,36 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+static int
+task (int task)
+{
+ return task - 1;
+}
+
+static int
+thread (int thread)
+{
+ return task (thread) + 1;
+}
+
+int
+main (void)
+{
+ int x = 0;
+ x += thread (0);
+ return x;
+}
diff --git a/gdb/testsuite/gdb.linespec/keywords.exp b/gdb/testsuite/gdb.linespec/keywords.exp
new file mode 100644
index 0000000..fcb745f
--- /dev/null
+++ b/gdb/testsuite/gdb.linespec/keywords.exp
@@ -0,0 +1,77 @@
+# Copyright 2015 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test keyword parsing in the linespec parser.
+
+standard_testfile
+set exefile $testfile
+
+if {[prepare_for_testing $testfile $exefile $srcfile {debug}]} {
+ return -1
+}
+
+if ![runto_main] {
+ fail "Can't run to main"
+ return 0
+}
+
+# Turn off pending breakpoints to facilitate testing errors.
+gdb_test_no_output "set breakpoint pending off"
+
+# The linespec lexer ignores the language setting when lexing
+# keywords.
+gdb_test "break if" "Function \"if\" not defined."
+gdb_breakpoint "thread" "message"
+gdb_breakpoint "task" "message"
+
+# The lexer should prune any trailing whitesapce, so the expected
+# outcome of the following tests should be the same as the previous
+# tests.
+with_test_prefix "trailing whitespace" {
+ gdb_test "break if " "Function \"if\" not defined."
+ gdb_breakpoint "thread " "message"
+ gdb_breakpoint "task " "message"
+}
+
+# With a single keyword specified first in the location,
+# we assume we have a NULL location, i.e., the actual location
+# of the event is the current default location.
+#
+# break if XX --> okay if XX is a valid expression
+# (the lexer cannot know whether the expression is valid or not)
+# break {thread,task} NUMBER --> invalid thread/task
+# break {thread,task} STUFF --> "junk" after keyword (STUFF is not numeric)
+gdb_test "break thread 123" "Unknown thread 123\\."
+gdb_test "break thread foo" "Junk after thread keyword\\."
+gdb_test "break task 123" "Unknown task 123\\."
+gdb_test "break task foo" "Junk after task keyword\\."
+gdb_breakpoint "thread if 0" "message"
+
+# These are also NULL locations, but using a subsequent keyword
+# as the "junk".
+gdb_test "break thread thread" "Junk after thread keyword\\."
+gdb_test "break thread task" "Junk after thread keyword\\."
+gdb_test "break thread if" "Junk after thread keyword\\."
+gdb_test "break task task" "Junk after task keyword\\."
+gdb_test "break task thread" "Junk after task keyword\\."
+gdb_test "break task if" "Junk after task keyword\\."
+
+# Test locations containing keyword followed by keyword.
+gdb_test "break thread thread 123" "Unknown thread 123\\."
+gdb_test "break task task 123" "Unknown task 123\\."
+
+# Test NULL location with valid conditional containing a keyword.
+gdb_breakpoint "thread if thread == 0"
+gdb_breakpoint "task if task == 0"