aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.rust
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-05-14 11:12:14 -0600
committerTom Tromey <tom@tromey.com>2017-05-19 21:23:16 -0600
commit43cc5389bc4662b31cad02a9f13358bd367d0ab3 (patch)
tree4b2f2c7522c88aeb6235cb82fe642d4e0079d265 /gdb/testsuite/gdb.rust
parenta9dba87af1aeabffb01769004ab893173f3ef472 (diff)
downloadgdb-43cc5389bc4662b31cad02a9f13358bd367d0ab3.zip
gdb-43cc5389bc4662b31cad02a9f13358bd367d0ab3.tar.gz
gdb-43cc5389bc4662b31cad02a9f13358bd367d0ab3.tar.bz2
Use watchpoint's language when re-parsing expression
PR rust/21484 notes that watch -location does not work with Rust: (gdb) watch -location a syntax error in expression, near `) 0x00007fffffffe0f4'. update_watchpoint tries to tell gdb that the new expression it creates has C syntax: /* The above expression is in C. */ b->language = language_c; However, update_watchpoint doesn't actually use this language when re-parsing the expression. Originally I was going to fix this by saving and restoring the language in update_watchpoint, but this regressed gdb.dlang/watch-loc.exp, because the constructed expression actually has D syntax (specifically the name is not parseable by C). Next I looked at directly constructing an expression, and not relying on the parser at all; but it seemed to me that upon a re-set, we'd want to reparse the type, and there is no existing API to do this correctly. So, in the end I made a hook to let each language choose what expression to use. I made all the languages other than Rust use the C expression, because that is the status quo ante. However, this is probably not truly correct. After this patch, at least, it is easy to correct by someone who knows the language(s) in question. Regtested by the buildbot. ChangeLog 2017-05-19 Tom Tromey <tom@tromey.com> PR rust/21484: * rust-lang.c (exp_descriptor_rust): New function. (rust_language_defn): Use it. * p-lang.c (pascal_language_defn): Update. * opencl-lang.c (opencl_language_defn): Update. * objc-lang.c (objc_language_defn): Update. * m2-lang.c (m2_language_defn): Update. * language.h (struct language_defn) <la_watch_location_expression>: New member. * language.c (unknown_language_defn, auto_language_defn) (local_language_defn): Update. * go-lang.c (go_language_defn): Update. * f-lang.c (f_language_defn): Update. * d-lang.c (d_language_defn): Update. * c-lang.h (c_watch_location_expression): Declare. * c-lang.c (c_watch_location_expression): New function. (c_language_defn, cplus_language_defn, asm_language_defn) (minimal_language_defn): Use it. * breakpoint.c (watch_command_1): Call la_watch_location_expression. * ada-lang.c (ada_language_defn): Update. testsuite/ChangeLog 2017-05-19 Tom Tromey <tom@tromey.com> PR rust/21484: * gdb.rust/watch.exp: New file. * gdb.rust/watch.rs: New file.
Diffstat (limited to 'gdb/testsuite/gdb.rust')
-rw-r--r--gdb/testsuite/gdb.rust/watch.exp35
-rw-r--r--gdb/testsuite/gdb.rust/watch.rs24
2 files changed, 59 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.rust/watch.exp b/gdb/testsuite/gdb.rust/watch.exp
new file mode 100644
index 0000000..0a3c055
--- /dev/null
+++ b/gdb/testsuite/gdb.rust/watch.exp
@@ -0,0 +1,35 @@
+# Copyright (C) 2017 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 watch -location with Rust.
+
+load_lib rust-support.exp
+if {[skip_rust_tests]} {
+ continue
+}
+
+standard_testfile .rs
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug rust}]} {
+ return -1
+}
+
+set line [gdb_get_line_number "set breakpoint here"]
+if {![runto ${srcfile}:$line]} {
+ untested "could not run to breakpoint"
+ return -1
+}
+
+# Just setting a watchpoint was enough to trigger the bug.
+gdb_test "watch -location y" ".*watchpoint .* -location .*"
diff --git a/gdb/testsuite/gdb.rust/watch.rs b/gdb/testsuite/gdb.rust/watch.rs
new file mode 100644
index 0000000..4146ecb
--- /dev/null
+++ b/gdb/testsuite/gdb.rust/watch.rs
@@ -0,0 +1,24 @@
+// Copyright (C) 2017 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/>.
+
+#![allow(dead_code)]
+#![allow(unused_variables)]
+#![allow(unused_assignments)]
+
+fn main() {
+ let mut y = 7;
+ y = y + 1; // set breakpoint here
+ y = y + 1;
+}