diff options
author | Tom Tromey <tom@tromey.com> | 2017-05-14 11:12:14 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-05-19 21:23:16 -0600 |
commit | 43cc5389bc4662b31cad02a9f13358bd367d0ab3 (patch) | |
tree | 4b2f2c7522c88aeb6235cb82fe642d4e0079d265 /gdb/c-lang.c | |
parent | a9dba87af1aeabffb01769004ab893173f3ef472 (diff) | |
download | gdb-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/c-lang.c')
-rw-r--r-- | gdb/c-lang.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 19a8608..a6d533d 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -712,7 +712,17 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp, } return evaluate_subexp_standard (expect_type, exp, pos, noside); } + +/* la_watch_location_expression for C. */ +gdb::unique_xmalloc_ptr<char> +c_watch_location_expression (struct type *type, CORE_ADDR addr) +{ + type = check_typedef (TYPE_TARGET_TYPE (check_typedef (type))); + std::string name = type_to_string (type); + return gdb::unique_xmalloc_ptr<char> + (xstrprintf ("* (%s *) %s", name.c_str (), core_addr_to_string (addr))); +} /* Table mapping opcodes into strings for printing operators @@ -865,6 +875,7 @@ const struct language_defn c_language_defn = default_print_array_index, default_pass_by_reference, c_get_string, + c_watch_location_expression, NULL, /* la_get_symbol_name_cmp */ iterate_over_symbols, &c_varobj_ops, @@ -1008,6 +1019,7 @@ const struct language_defn cplus_language_defn = default_print_array_index, cp_pass_by_reference, c_get_string, + c_watch_location_expression, NULL, /* la_get_symbol_name_cmp */ iterate_over_symbols, &cplus_varobj_ops, @@ -1060,6 +1072,7 @@ const struct language_defn asm_language_defn = default_print_array_index, default_pass_by_reference, c_get_string, + c_watch_location_expression, NULL, /* la_get_symbol_name_cmp */ iterate_over_symbols, &default_varobj_ops, @@ -1112,6 +1125,7 @@ const struct language_defn minimal_language_defn = default_print_array_index, default_pass_by_reference, c_get_string, + c_watch_location_expression, NULL, /* la_get_symbol_name_cmp */ iterate_over_symbols, &default_varobj_ops, |