summaryrefslogtreecommitdiff
path: root/gdb/c-lang.c
Commit message (Collapse)AuthorAgeFilesLines
* Pass const frame_info_ptr reference for skip_[language_]trampolineMark Wielaard2023-05-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | g++ 13.1.1 produces a -Werror=dangling-pointer= In file included from ../../binutils-gdb/gdb/frame.h:75, from ../../binutils-gdb/gdb/symtab.h:40, from ../../binutils-gdb/gdb/language.c:33: In member function ‘void intrusive_list<T, AsNode>::push_empty(T&) [with T = frame_info_ptr; AsNode = intrusive_base_node<frame_info_ptr>]’, inlined from ‘void intrusive_list<T, AsNode>::push_back(reference) [with T = frame_info_ptr; AsNode = intrusive_base_node<frame_info_ptr>]’ at gdbsupport/intrusive_list.h:332:24, inlined from ‘frame_info_ptr::frame_info_ptr(const frame_info_ptr&)’ at gdb/frame.h:241:26, inlined from ‘CORE_ADDR skip_language_trampoline(frame_info_ptr, CORE_ADDR)’ at gdb/language.c:530:49: gdbsupport/intrusive_list.h:415:12: error: storing the address of local variable ‘<anonymous>’ in ‘frame_info_ptr::frame_list.intrusive_list<frame_info_ptr>::m_back’ [-Werror=dangling-pointer=] 415 | m_back = &elem; | ~~~~~~~^~~~~~~ gdb/language.c: In function ‘CORE_ADDR skip_language_trampoline(frame_info_ptr, CORE_ADDR)’: gdb/language.c:530:49: note: ‘<anonymous>’ declared here 530 | CORE_ADDR real_pc = lang->skip_trampoline (frame, pc); | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~ gdb/frame.h:359:41: note: ‘frame_info_ptr::frame_list’ declared here 359 | static intrusive_list<frame_info_ptr> frame_list; | ^~~~~~~~~~ Each new frame_info_ptr is being pushed on a static frame list and g++ cannot see why that is safe in case the frame_info_ptr is created and destroyed immediately when passed as value. It isn't clear why only in this one place g++ sees the issue (probably because it can inline enough code in this specific case). Since passing the frame_info_ptr as const reference is cheaper, use that as workaround for this warning. PR build/30413 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30413 Tested-by: Kevin Buettner <kevinb@redhat.com> Reviewed-by: Kevin Buettner <kevinb@redhat.com> Reviewed-by: Tom Tromey <tom@tromey.com>
* Remove deprecated_lval_hackTom Tromey2023-02-131-3/+3
| | | | | | | | | | This removes deprecated_lval_hack and the VALUE_LVAL macro, replacing all uses with a call to value::lval. Approved-By: Simon Marchi <simon.marchi@efficios.com>
* Turn remaining value_contents functions into methodsTom Tromey2023-02-131-1/+1
| | | | | | | | | | | | | This turns the remaining value_contents functions -- value_contents, value_contents_all, value_contents_for_printing, and value_contents_for_printing_const -- into methods of value. It also converts the static functions require_not_optimized_out and require_available to be private methods. Approved-By: Simon Marchi <simon.marchi@efficios.com>
* Turn some value_contents functions into methodsTom Tromey2023-02-131-1/+1
| | | | | | | | | | | | This turns value_contents_raw, value_contents_writeable, and value_contents_all_raw into methods on value. The remaining functions will be changed later in the series; they were a bit trickier and so I didn't include them in this patch. Approved-By: Simon Marchi <simon.marchi@efficios.com>
* Turn allocate_value into a static "constructor"Tom Tromey2023-02-131-1/+1
| | | | | | | | | This changes allocate_value to be a static "constructor" of value. Approved-By: Simon Marchi <simon.marchi@efficios.com>
* Turn value_address and set_value_address functions into methodsTom Tromey2023-02-131-1/+1
| | | | | | | | | | This changes the value_address and set_value_address functions to be methods of value. Approved-By: Simon Marchi <simon.marchi@efficios.com>
* Turn value_type into methodTom Tromey2023-02-131-1/+1
| | | | | | | | | | This changes value_type to be a method of value. Much of this patch was written by script. Approved-By: Simon Marchi <simon.marchi@efficios.com>
* gdb: move compile_instance to compile/compile.hSimon Marchi2023-01-201-1/+0
| | | | | | | | | | struct compile_instance needs to be visible to users, since we use std::unique<compile_instance>. language.c and c-lang.c currently includes compile-internal.h for this reason, which kind of defeats the purpose of having an "internal" header file. Change-Id: Iedffe5f1173b3de7bdc1be533ee2a68e6f6c549f Reviewed-By: Bruno Larsen <blarsen@redhat.com>
* GDB: Add a character string limiting optionAndrew Burgess2023-01-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit splits the `set/show print elements' option into two. We retain `set/show print elements' for controlling how many elements of an array we print, but a new `set/show print characters' setting is added which is used for controlling how many characters of a string are printed. The motivation behind this change is to allow users a finer level of control over how data is printed, reflecting that, although strings can be thought of as arrays of characters, users often want to treat these two things differently. For compatibility reasons by default the `set/show print characters' option is set to `elements', which makes the limit for character strings follow the setting of the `set/show print elements' option, as it used to. Using `set print characters' with any other value makes the limit independent from the `set/show print elements' setting, however it can be restored to the default with the `set print characters elements' command at any time. A corresponding `-characters' option for the `print' command is added, with the same semantics, i.e. one can use `elements' to make a given `print' invocation follow the limit of elements, be it set with the `-elements' option also given with the same invocation or taken from the `set/show print elements' setting, for characters as well regardless of the current setting of the `set/show print characters' option. The GDB changes are all pretty straightforward, just changing references to the old 'print_max' to use a new `get_print_max_chars' helper which figures out which of the two of `print_max' and `print_max_chars' values to use. Likewise, the documentation is just updated to reference the new setting where appropriate. To make people's life easier the message shown by `show print elements' now indicates if the setting also applies to character strings: (gdb) set print characters elements (gdb) show print elements Limit on string chars or array elements to print is 200. (gdb) set print characters unlimited (gdb) show print elements Limit on array elements to print is 200. (gdb) and the help text shows the dependency as well: (gdb) help set print elements Set limit on array elements to print. "unlimited" causes there to be no limit. This setting also applies to string chars when "print characters" is set to "elements". (gdb) In the testsuite there are two minor updates, one to add `-characters' to the list of completions now shown for the `print' command, and a bare minimum pair of checks for the right handling of `set print characters' and `show print characters', copied from the corresponding checks for `set print elements' and `show print elements' respectively. Co-Authored-By: Maciej W. Rozycki <macro@embecosm.com> Approved-By: Simon Marchi <simon.marchi@efficios.com>
* Update copyright year range in header of all files managed by GDBJoel Brobecker2023-01-011-1/+1
| | | | | | | This commit is the result of running the gdb/copyright.py script, which automated the update of the copyright year range for all source files managed by the GDB project to be updated to include year 2023.
* Add name canonicalization for CTom Tromey2022-12-011-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PR symtab/29105 shows a number of situations where symbol lookup can result in the expansion of too many CUs. What happens is that lookup_signed_typename will try to look up a type like "signed int". In cooked_index_functions::expand_symtabs_matching, when looping over languages, the C++ case will canonicalize this type name to be "int" instead. Then this method will proceed to expand every CU that has an entry for "int" -- i.e., nearly all of them. A crucial component of this is that the caller, objfile::lookup_symbol, does not do this canonicalization, so when it tries to find the symbol for "signed int", it fails -- causing the loop to continue. This patch fixes the problem by introducing name canonicalization for C. The idea here is that, by making C and C++ agree on the canonical name when a symbol name can have multiple spellings, we avoid the bad behavior in objfile::lookup_symbol (and any other such code -- I don't know if there is any). Unlike C++, C only has a few situations where canonicalization is needed. And, in particular, due to the lack of overloading (thus avoiding any issues in linespec) and due to the way c-exp.y works, I think that no canonicalization is needed during symbol lookup -- only during symtab construction. This explains why lookup_name_info is not touched. The stabs reader is modified on a "best effort" basis. The DWARF reader needed one small tweak in dwarf2_name to avoid a regression in dw2-unusual-field-names.exp. I think this is adequately explained by the comment, but basically this is a scenario that should not occur in real code, only the gdb test suite. lookup_signed_typename is simplified. It used to search for two different type names, but now gdb can search just for the canonical form. gdb.dwarf2/enum-type.exp needed a small tweak, because the canonicalizer turns "unsigned integer" into "unsigned int integer". It seems better here to use the correct C type name. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29105 Tested-by: Simon Marchi <simark@simark.ca> Reviewed-by: Andrew Burgess <aburgess@redhat.com>
* Allow 'ptype/o' for assemblyTom Tromey2022-11-091-0/+28
| | | | | | | | | | | | | | | | | | | | | PR exp/28359 points out that 'ptype/o' does not work when the current language is "asm". I tracked this down to a hard-coded list of languages in typeprint.c. This patch replaces this list with a method on 'language_defn' instead. If all languages are ever updated to have this feature, the method could be removed; but in the meantime this lets each language control what happens. I looked at having each print_type method simply modify the flags itself, but this doesn't work very well with the feature that disables method-printing by default (but allows it via a flag). Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28359 Approved-By: Andrew Burgess <aburgess@redhat.com> Approved-By: Keith Seitz <keiths@redhat.com>
* internal_error: remove need to pass __FILE__/__LINE__Pedro Alves2022-10-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, every internal_error call must be passed __FILE__/__LINE__ explicitly, like: internal_error (__FILE__, __LINE__, "foo %d", var); The need to pass in explicit __FILE__/__LINE__ is there probably because the function predates widespread and portable variadic macros availability. We can use variadic macros nowadays, and in fact, we already use them in several places, including the related gdb_assert_not_reached. So this patch renames the internal_error function to something else, and then reimplements internal_error as a variadic macro that expands __FILE__/__LINE__ itself. The result is that we now should call internal_error like so: internal_error ("foo %d", var); Likewise for internal_warning. The patch adjusts all calls sites. 99% of the adjustments were done with a perl/sed script. The non-mechanical changes are in gdbsupport/errors.h, gdbsupport/gdb_assert.h, and gdb/gdbarch.py. Approved-By: Simon Marchi <simon.marchi@efficios.com> Change-Id: Ia6f372c11550ca876829e8fd85048f4502bdcf06
* Remove c_printstrTom Tromey2022-10-101-4/+4
| | | | | | | This renames c_printstr, removing a layer of indirection.
* Remove c_emit_charTom Tromey2022-10-101-2/+2
| | | | | | | This renames c_emit_char, removing a layer of indirection.
* Change GDB to use frame_info_ptrTom Tromey2022-10-101-1/+1
| | | | | | | | | | | | | | | | | | | This changes GDB to use frame_info_ptr instead of frame_info * The substitution was done with multiple sequential `sed` commands: sed 's/^struct frame_info;/class frame_info_ptr;/' sed 's/struct frame_info \*/frame_info_ptr /g' - which left some issues in a few files, that were manually fixed. sed 's/\<frame_info \*/frame_info_ptr /g' sed 's/frame_info_ptr $/frame_info_ptr/g' - used to remove whitespace problems. The changed files were then manually checked and some 'sed' changes undone, some constructors and some gets were added, according to what made sense, and what Tromey originally did Co-Authored-By: Bruno Larsen <blarsen@redhat.com> Approved-by: Tom Tomey <tom@tromey.com>
* gdb: remove TYPE_LENGTHSimon Marchi2022-09-211-9/+9
| | | | | | Remove the macro, replace all uses with calls to type::length. Change-Id: Ib9bdc954576860b21190886534c99103d6a47afb
* gdb: remove TYPE_TARGET_TYPESimon Marchi2022-09-211-7/+7
| | | | | | Remove the macro, replace all uses by calls to type::target_type. Change-Id: Ie51d3e1e22f94130176d6abd723255282bb6d1ed
* gdb: Add new 'print nibbles' featureEnze Li2022-06-181-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make an introduction of a new print setting that can be set by 'set print nibbles [on|off]'. The default value if OFF, which can be changed by user manually. Of course, 'show print nibbles' is also included in the patch. The new feature displays binary values by group, with four bits per group. The motivation for this work is to enhance the readability of binary values. Here's a GDB session before this patch is applied. (gdb) print var_a $1 = 1230 (gdb) print/t var_a $2 = 10011001110 With this patch applied, we can use the new print setting to display the new form of the binary values. (gdb) print var_a $1 = 1230 (gdb) print/t var_a $2 = 10011001110 (gdb) set print nibbles on (gdb) print/t var_a $3 = 0100 1100 1110 Tested on x86_64 openSUSE Tumbleweed.
* Always pass an explicit language down to c_type_printPedro Alves2022-05-101-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | The next patch will want to do language->print_type(type, ...), to print a type in a given language, avoiding a dependency on the current language. That doesn't work correctly currently, however, because most language implementations of language_defn::print_type call c_print_type without passing down the language. There are two overloads of c_print_type, one that takes a language, and one that does not. The one that does not uses the current language, defeating the point of calling language->print_type()... This commit removes the c_print_type overload that does not take a language, and adjusts the codebase throughout to always pass down a language. In most places, there's already an enum language handy. language_defn::print_type implementations naturally pass down this->la_language. In a couple spots, like in ada-typeprint.c and rust-lang.c there's no enum language handy, but the code is written for a specific language, so we just hardcode the language. In gnuv3_print_method_ptr, I wasn't sure whether we could hardcode C++ here, and we don't have an enum language handy, so I made it use the current language, just like today. Can always be improved later. Change-Id: Ib54fab4cf0fd307bfd55bf1dd5056830096a653b
* Remove the byte order parameter to target_read_stringTom Tromey2022-04-141-1/+1
| | | | | | | | | target_read_string takes a byte order parameter, but only uses this to check whether a given character is zero. This is readily done without requiring the parameter, so remove it.
* Rename read_stringTom Tromey2022-04-141-2/+2
| | | | | | | | This renames read_string to be an overload of target_read_string. This makes it more consistent for the eventual merger with gdbserver.
* Unify gdb putc functionsTom Tromey2022-03-291-5/+5
| | | | | | | | | Now that filtered and unfiltered output can be treated identically, we can unify the putc family of functions. This is done under the name "gdb_putc". Most of this patch was written by script.
* Unify gdb puts functionsTom Tromey2022-03-291-3/+3
| | | | | | | | | Now that filtered and unfiltered output can be treated identically, we can unify the puts family of functions. This is done under the name "gdb_puts". Most of this patch was written by script.
* Remove host_hex_valueTom Tromey2022-02-041-3/+3
| | | | | | | | | I noticed that host_hex_value is redundant, because gdbsupport already has fromhex. This patch removes the former in favor of the latter. Regression tested on x86-64 Fedora 34.
* Move gdb obstack code to gdbsupportTom Tromey2022-01-181-1/+1
| | | | | | | | This moves the gdb-specific obstack code -- both extensions like obconcat and obstack_strdup, and things like auto_obstack -- to gdbsupport.
* Automatic Copyright Year update after running gdb/copyright.pyJoel Brobecker2022-01-011-1/+1
| | | | | | | | This commit brings all the changes made by running gdb/copyright.py as per GDB's Start of New Year Procedure. For the avoidance of doubt, all changes in this commits were performed by the script.
* Allow DW_ATE_UTF for Rust charactersTom Tromey2021-11-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Rust compiler plans to change the encoding of a Rust 'char' type to use DW_ATE_UTF. You can see the discussion here: https://github.com/rust-lang/rust/pull/89887 However, this fails in gdb. I looked into this, and it turns out that the handling of DW_ATE_UTF is currently fairly specific to C++. In particular, the code here assumes the C++ type names, and it creates an integer type. This comes from commit 53e710acd ("GDB thinks char16_t and char32_t are signed in C++"). The message says: Both places need fixing. But since I couldn't tell why dwarf2read.c needs to create a new type, I've made it use the per-arch built-in types instead, so that the types are only created once per arch instead of once per objfile. That seems to work fine. ... which is fine, but it seems to me that it's also correct to make a new character type; and this approach is better because it preserves the type name as well. This does use more memory, but first we shouldn't be too concerned about the memory use of types coming from debuginfo; and second, if we are, we should implement type interning anyway. Changing this code to use a character type revealed a couple of oddities in the C/C++ handling of TYPE_CODE_CHAR. This patch fixes these as well. I filed PR rust/28637 for this issue, so that this patch can be backported to the gdb 11 branch.
* gdb: change functions returning value contents to use gdb::array_viewSimon Marchi2021-10-251-2/+2
| | | | | | | | | | | | | | | | | | | | | The bug fixed by this [1] patch was caused by an out-of-bounds access to a value's content. The code gets the value's content (just a pointer) and then indexes it with a non-sensical index. This made me think of changing functions that return value contents to return array_views instead of a plain pointer. This has the advantage that when GDB is built with _GLIBCXX_DEBUG, accesses to the array_view are checked, making bugs more apparent / easier to find. This patch changes the return types of these functions, and updates callers to call .data() on the result, meaning it's not changing anything in practice. Additional work will be needed (which can be done little by little) to make callers propagate the use of array_view and reap the benefits. [1] https://sourceware.org/pipermail/gdb-patches/2021-September/182306.html Change-Id: I5151f888f169e1c36abe2cbc57620110673816f3
* Use unique_xmalloc_ptr<char> when demanglingTom Tromey2021-10-041-3/+5
| | | | | | | | | | | | | I noticed that some methods in language_defn could use unique_xmalloc_ptr<char> rather than a plain 'char *'. This patch implements this change, fixing up the fallout and changing gdb_demangle to also return this type. In one spot, std::string is used to simplify some related code, and in another, an auto_obstack is used to avoid manual management. Regression tested on x86-64 Fedora 34.
* Remove EVAL_SKIPTom Tromey2021-03-081-18/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | EVAL_SKIP was needed in the old expression implementation due to its linearized tree structure. This is not needed in the new implementation, because it is trivial to not evaluate a subexpression. This patch removes the last vestiges of EVAL_SKIP. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * value.h (eval_skip_value): Don't declare. * opencl-lang.c (eval_opencl_assign): Update. * m2-lang.c (eval_op_m2_high, eval_op_m2_subscript): Update. * f-lang.c (eval_op_f_abs, eval_op_f_mod, eval_op_f_ceil) (eval_op_f_floor, eval_op_f_modulo, eval_op_f_cmplx): Remove. * expression.h (enum noside) <EVAL_SKIP>: Remove. * expop.h (typeof_operation::evaluate) (decltype_operation::evaluate, unop_addr_operation::evaluate) (unop_sizeof_operation::evaluate, assign_operation::evaluate) (cxx_cast_operation::evaluate): Update. * eval.c (eval_skip_value): Remove. (eval_op_scope, eval_op_var_entry_value) (eval_op_func_static_var, eval_op_string, eval_op_objc_selector) (eval_op_concat, eval_op_ternop, eval_op_structop_struct) (eval_op_structop_ptr, eval_op_member, eval_op_add, eval_op_sub) (eval_op_binary, eval_op_subscript, eval_op_equal) (eval_op_notequal, eval_op_less, eval_op_gtr, eval_op_geq) (eval_op_leq, eval_op_repeat, eval_op_plus, eval_op_neg) (eval_op_complement, eval_op_lognot, eval_op_ind) (eval_op_memval, eval_op_preinc, eval_op_predec) (eval_op_postinc, eval_op_postdec, eval_op_type) (eval_binop_assign_modify, eval_op_objc_msgcall) (eval_multi_subscript, logical_and_operation::evaluate) (logical_or_operation::evaluate, array_operation::evaluate) (operation::evaluate_for_cast) (var_msym_value_operation::evaluate_for_cast) (var_value_operation::evaluate_for_cast): Update. * c-lang.c (c_string_operation::evaluate): Update. * c-exp.h (objc_nsstring_operation::evaluate) (objc_selector_operation::evaluate): Update. * ada-lang.c (ada_assign_operation::evaluate) (eval_ternop_in_range, ada_unop_neg, ada_unop_in_range) (ada_atr_size): Update.
* Remove union exp_elementTom Tromey2021-03-081-59/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This removes union exp_element functions that either create such elements or walk them. struct expression no longer holds exp_elements. A couple of language_defn methods are also removed, as they are obsolete. Note that this patch also removes the print_expression code. The only in-tree caller of this was from dump_prefix_expression, which is only called when expression debugging is enabled. Implementing this would involve a fair amount of code, and it seems to me that prefix dumping is preferable anyway, as it is unambiguous. So, I have not reimplemented this feature. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * value.h (evaluate_subexp_with_coercion): Don't declare. * parse.c (exp_descriptor_standard): Remove. (expr_builder::expr_builder, expr_builder::release): Update. (expression::expression): Remove size_t parameter. (expression::~expression): Simplify. (expression::resize): Remove. (write_exp_elt, write_exp_elt_opcode, write_exp_elt_sym) (write_exp_elt_msym, write_exp_elt_block, write_exp_elt_objfile) (write_exp_elt_longcst, write_exp_elt_floatcst) (write_exp_elt_type, write_exp_elt_intern, write_exp_string) (write_exp_string_vector, write_exp_bitstring): Remove. * p-lang.h (class pascal_language) <opcode_print_table, op_print_tab>: Remove. * p-lang.c (pascal_language::op_print_tab): Remove. * opencl-lang.c (class opencl_language) <opcode_print_table>: Remove. * objc-lang.c (objc_op_print_tab): Remove. (class objc_language) <opcode_print_table>: Remove. * m2-lang.h (class m2_language) <opcode_print_table, op_print_tab>: Remove. * m2-lang.c (m2_language::op_print_tab): Remove. * language.h (struct language_defn) <post_parser, expression_ops, opcode_print_table>: Remove. * language.c (language_defn::expression_ops) (auto_or_unknown_language::opcode_print_table): Remove. * go-lang.h (class go_language) <opcode_print_table, op_print_tab>: Remove. * go-lang.c (go_language::op_print_tab): Remove. * f-lang.h (class f_language) <opcode_print_table>: Remove <op_print_tab>: Remove. * f-lang.c (f_language::op_print_tab): Remove. * expression.h (union exp_element): Remove. (struct expression): Remove size_t parameter from constructor. <resize>: Remove. <first_opcode>: Update. <nelts, elts>: Remove. (EXP_ELEM_TO_BYTES, BYTES_TO_EXP_ELEM): Remove. (evaluate_subexp_standard, print_expression, op_string) (dump_raw_expression): Don't declare. * expprint.c (print_expression, print_subexp) (print_subexp_funcall, print_subexp_standard, op_string) (dump_raw_expression, dump_subexp, dump_subexp_body) (dump_subexp_body_funcall, dump_subexp_body_standard): Remove. (dump_prefix_expression): Update. * eval.c (evaluate_subexp): Remove. (evaluate_expression, evaluate_type): Update. (evaluate_subexpression_type): Remove. (fetch_subexp_value): Remove "pc" parameter. Update. (extract_field_op, evaluate_struct_tuple, evaluate_funcall) (evaluate_subexp_standard, evaluate_subexp_for_address) (evaluate_subexp_with_coercion, evaluate_subexp_for_sizeof) (evaluate_subexp_for_cast): Remove. (parse_and_eval_type): Update. * dtrace-probe.c (dtrace_probe::compile_to_ax): Update. * d-lang.c (d_op_print_tab): Remove. (class d_language) <opcode_print_table>: Remove. * c-lang.h (c_op_print_tab): Don't declare. * c-lang.c (c_op_print_tab): Remove. (class c_language, class cplus_language, class asm_language, class minimal_language) <opcode_print_table>: Remove. * breakpoint.c (update_watchpoint, watchpoint_check) (watchpoint_exp_is_const, watch_command_1): Update. * ax-gdb.h (union exp_element): Don't declare. * ax-gdb.c (const_var_ref, const_expr, maybe_const_expr) (gen_repeat, gen_sizeof, gen_expr_for_cast, gen_expr) (gen_expr_binop_rest): Remove. (gen_trace_for_expr, gen_eval_for_expr, gen_printf): Update. * ada-lang.c (ada_op_print_tab): Remove. (class ada_language) <post_parser, opcode_print_table>: Remove.
* Remove now-unused C evaluator codeTom Tromey2021-03-081-180/+0
| | | | | | | | | | | | | | | | | | | | Now that the C parser has switched to the new style, there is no need for the old C evaluation code. This affects some other languages that were relying on the C code. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * go-lang.c (go_language::expression_ops): Don't declare. * go-lang.h (class go_language) <expression_ops>: Remove. * opencl-lang.c (evaluate_subexp_opencl, exp_descriptor_opencl): Remove. (class opencl_language) <expression_ops>: Remove. * d-lang.c (class d_language) <expression_ops>: Remove. * c-lang.h (evaluate_subexp_c, exp_descriptor_c): Don't declare. * c-lang.c (evaluate_subexp_c, exp_descriptor_c): Remove. (class c_language, class cplus_language, class asm_language) (class minimal_language) <expression_ops>: Remove.
* Add c-exp.h and c_string_operationTom Tromey2021-03-081-0/+126
| | | | | | | | | | | | This adds the new file c-exp.h, where C operation classes will be declared. The first such class, c_string_operation, is also added here. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * c-lang.c (c_string_operation::evaluate): New method. * c-exp.h: New file.
* Return unique_ptr from language_defn::get_compile_contextTom Tromey2021-02-051-4/+3
| | | | | | | | | | | | | | | | | | | | This changes language_defn::get_compile_context to return a unique_ptr. This makes the ownership transfer clear. gdb/ChangeLog 2021-02-05 Tom Tromey <tom@tromey.com> * compile/compile-c-support.c (get_compile_context) (c_get_compile_context, cplus_get_compile_context): Change return type. * language.c (language_defn::get_compile_instance): New method. * language.h (language_defn::get_compile_instance): Change return type. No longer inline. * c-lang.c (c_language::get_compile_instance): Change return type. (cplus_language::get_compile_instance): Change return type. * c-lang.h (c_get_compile_context, cplus_get_compile_context): Change return type. * compile/compile.c (compile_to_object): Update.
* gdb: rename get_type_arch to type::archSimon Marchi2021-01-281-4/+4
| | | | | | | | | | | ... and update all users. gdb/ChangeLog: * gdbtypes.h (get_type_arch): Rename to... (struct type) <arch>: ... this, update all users. Change-Id: I0e3ef938a0afe798ac0da74a9976bbd1d082fc6f
* Update copyright year range in all GDB filesJoel Brobecker2021-01-011-1/+1
| | | | | | | | | This commits the result of running gdb/copyright.py as per our Start of New Year procedure... gdb/ChangeLog Update copyright year range in copyright header of all GDB files.
* gdb: remove LA_EMIT_CHAR macroAndrew Burgess2020-12-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | Now that every use of the LA_EMIT_CHAR macro is within a language_defn member function we can simply call the emitchar member function directly instead of using the LA_EMIT_CHAR macro. If we are ever inside a language object, for example, cplus_language, while current_language points at something other than cplus_language then this commit will result in a change in behaviour. However, I believe if we did have such a difference then this would be a bug in GDB. AS such I'm going to claim there _should_ be no user visible changes from this commit. gdb/ChangeLog: * c-lang.c (language_defn::printchar): Call emitchar, not LA_EMIT_CHAR. * f-lang.h (f_language::printchar): Likewise. * language.h (LA_EMIT_CHAR): Delete macro. * rust-lang.c (rust_language::printchar): Call emitchar, not LA_EMIT_CHAR.
* gdb: rename c_printchar as language_defn::printcharAndrew Burgess2020-12-231-1/+4
| | | | | | | | | | | | | | | This commit removes the global function c_printchar and moves the implementation into language_defn::printchar. There should be no user visible changes after this commit. gdb/ChangeLog: * c-lang.c (c_printchar): Rename to... (language_defn::printchar): ...this. * c-lang.h (c_printchar): Delete declaration. * language.c (language_defn::printchar): Delete this implementation. Is now implemented in c-lang.c.
* gdb: make get_discrete_bounds return boolSimon Marchi2020-12-091-2/+2
| | | | | | | | | | | | | | | | | get_discrete_bounds currently has three possible return values (see its current doc for details). It appears that for all callers, it would be sufficient to have a boolean "worked" / "didn't work" return value. Change the return type of get_discrete_bounds to bool and adjust all callers. Doing so simplifies the following patch. gdb/ChangeLog: * gdbtypes.h (get_discrete_bounds): Return bool, adjust all callers. * gdbtypes.c (get_discrete_bounds): Return bool. Change-Id: Ie51feee23c75f0cd7939742604282d745db59172
* Remove per-language op_name functionsTom Tromey2020-11-301-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | enum exp_opcode is created from all the .def files, but then each language is required to implement its own op_name function to turn an enum value to a string. This seemed over-complicated to me, and this patch removes the per-language functions in favor of simply using the .def names for all languages. Note that op_name is only used for dumping expressions, which is a maintainer/debug feature. Furthermore, I don't think there was any case where the .def name and the string name differed. gdb/ChangeLog 2020-11-30 Tom Tromey <tom@tromey.com> * rust-lang.c (rust_op_name): Remove. (exp_descriptor_rust): Update. * parser-defs.h (op_name_standard): Don't declare. (struct exp_descriptor) <op_name>: Remove. * parse.c (exp_descriptor_standard): Update. * opencl-lang.c (exp_descriptor_opencl): Update. * m2-lang.c (m2_language::exp_descriptor_modula2): Update. * f-lang.c (op_name_f): Remove. (f_language::exp_descriptor_tab): Update. * expression.h (op_name): Update. * expprint.c (op_name): Rewrite. (op_name_standard): Remove. (dump_raw_expression, dump_subexp): Update. * c-lang.c (exp_descriptor_c): Update. * ax-gdb.c (gen_expr): Update. * ada-lang.c (ada_op_name): Remove. (ada_exp_descriptor): Update.
* Use const more in c-lang.cTom Tromey2020-11-131-14/+14
| | | | | | | | | | | This changes a few functions in c-lang.c to add "const" to parameters and return types. Tested by rebuilding. gdb/ChangeLog 2020-11-13 Tom Tromey <tom@tromey.com> * c-lang.c (convert_ucn, convert_octal, convert_hex) (convert_escape, parse_one_string): Constify.
* gdb: rewrite how per language primitive types are managedAndrew Burgess2020-11-121-132/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider the following GDB session: $ gdb (gdb) set language c (gdb) ptype void type = void (gdb) set language fortran (gdb) ptype void No symbol table is loaded. Use the "file" command. (gdb) With no symbol file loaded GDB and the language set to C GDB knows about the type void, while when the language is set to Fortran GDB doesn't know about the void, why is that? In f-lang.c, f_language::language_arch_info, we do have this line: lai->primitive_type_vector [f_primitive_type_void] = builtin->builtin_void; where we add the void type to the list of primitive types that GDB should always know about, so what's going wrong? It turns out that the primitive types are stored in a C style array, indexed by an enum, so Fortran uses `enum f_primitive_types'. The array is allocated and populated in each languages language_arch_info member function. The array is allocated with an extra entry at the end which is left as a NULL value, and this indicates the end of the array of types. Unfortunately for Fortran, a type is not assigned for each element in the enum. As a result the final populated array has gaps in it, gaps which are initialised to NULL, and so every time we iterate over the list (for Fortran) we stop early, and never reach the void type. This has been the case since 2007 when this functionality was added to GDB in commit cad351d11d6c3f6487cd. Obviously I could just fix Fortran by ensuring that either the enum is trimmed, or we create types for the missing types. However, I think a better approach would be to move to C++ data structures and removed the fixed enum indexing into the array approach. After this commit the primitive types are pushed into a vector, and GDB just iterates over the vector in the obvious way when it needs to hunt for a type. After this commit all the currently defined primitive types can be found when the language is set to Fortran, for example: $ gdb (gdb) set language fortran (gdb) ptype void type = void (gdb) A new test checks this functionality. I didn't see any other languages with similar issues, but I could have missed something. gdb/ChangeLog: * ada-exp.y (find_primitive_type): Make parameter const. * ada-lang.c (enum ada_primitive_types): Delete. (ada_language::language_arch_info): Update. * c-lang.c (enum c_primitive_types): Delete. (c_language_arch_info): Update. (enum cplus_primitive_types): Delete. (cplus_language::language_arch_info): Update. * d-lang.c (enum d_primitive_types): Delete. (d_language::language_arch_info): Update. * f-lang.c (enum f_primitive_types): Delete. (f_language::language_arch_info): Update. * go-lang.c (enum go_primitive_types): Delete. (go_language::language_arch_info): Update. * language.c (auto_or_unknown_language::language_arch_info): Update. (language_gdbarch_post_init): Use obstack_new, use array indexing. (language_string_char_type): Add header comment, call function in language_arch_info. (language_bool_type): Likewise (language_arch_info::bool_type): Define. (language_lookup_primitive_type_1): Delete. (language_lookup_primitive_type): Rewrite as a templated function to call function in language_arch_info, then instantiate twice. (language_arch_info::type_and_symbol::alloc_type_symbol): Define. (language_arch_info::lookup_primitive_type_and_symbol): Define. (language_arch_info::lookup_primitive_type): Define twice with different signatures. (language_arch_info::lookup_primitive_type_as_symbol): Define. (language_lookup_primitive_type_as_symbol): Rewrite to call a member function in language_arch_info. * language.h (language_arch_info): Complete rewrite. (language_lookup_primitive_type): Make templated. * m2-lang.c (enum m2_primitive_types): Delete. (m2_language::language_arch_info): Update. * opencl-lang.c (OCL_P_TYPE): Delete. (enum opencl_primitive_types): Delete. (opencl_type_data): Delete. (builtin_opencl_type): Delete. (lookup_opencl_vector_type): Update. (opencl_language::language_arch_info): Update, lots of content moved from... (build_opencl_types): ...here. This function is now deleted. (_initialize_opencl_language): Delete. * p-lang.c (enum pascal_primitive_types): Delete. (pascal_language::language_arch_info): Update. * rust-lang.c (enum rust_primitive_types): Delete. (rust_language::language_arch_info): Update. gdb/testsuite/ChangeLog: * gdb.fortran/types.exp: Add more tests.
* gdb: Rename language_defn::demangleAndrew Burgess2020-10-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GDB already has a global symbol `demangle` (a boolean), having a language method called `demangle` is not a good idea as we often want to reference `demangle` the control variable inside `demangle` the member function. This commit renames `demangle` the member function to `demangle_symbol`. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language::demangle): Rename to... (ada_language::demangle_symbol): ...this. * c-lang.c (cplus_language::demangle): Rename to... (cplus_language::demangle_symbol): ...this. * d-lang.c (d_language::demangle): Rename to... (d_language::demangle_symbol): ...this. * f-lang.c (f_language::demangle): Rename to... (f_language::demangle_symbol): ...this. * go-lang.c (go_language::demangle): Rename to... (go_language::demangle_symbol): ...this. * language.c (language_demangle): Update call to demangle_symbol. (auto_or_unknown_language::demangle): Rename to... (auto_or_unknown_language::demangle_symbol): ...this. * language.h (language_defn::demangle): Rename to... (language_defn::demangle_symbol): ...this. * objc-lang.c (objc_language::demangle): Rename to... (objc_language::demangle_symbol): ...this. * rust-lang.c (rust_language::demangle): Rename to... (rust_language::demangle_symbol): ...this.
* gdb: Remove language_data structAndrew Burgess2020-09-161-31/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The language_data type, from which language_defn inherits, is now empty, and this commit removes it. Each language is updated to no longer create and use a language_data struct. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_data): Delete. (ada_language): Remove references to ada_language_data. * c-lang.c (c_language_data): Delete. (c_language): Remove references to c_language_data. (cplus_language_data): Delete. (cplus_language): Remove references to cplus_language_data. (asm_language_data): Delete. (asm_language): Remove references to asm_language_data. (minimal_language_data): Delete. (minimal_language): Remove references to minimal_language_data. * d-lang.c (d_language_data): Delete. (d_language): Remove references to d_language_data. * f-lang.c (f_language_data): Delete. (f_language): Remove references to f_language_data. * go-lang.c (go_language_data): Delete. (go_language): Remove references to go_language_data. * language.c (unknown_language_data): Delete. (unknown_language): Remove references to unknown_language_data. (auto_language_data): Delete. (auto_language): Remove references to auto_language_data. * language.h (language_data): Delete struct. (language_defn): No longer inherit from language_data. * m2-lang.c (m2_language_data): Delete. (m2_language): Remove references to m2_language_data. * objc-lang.c (objc_language_data): Delete. (objc_language): Remove references to objc_language_data. * opencl-lang.c (opencl_language_data): Delete. (opencl_language): Remove references to opencl_language_data. * p-lang.c (pascal_language_data): Delete. (pascal_language): Remove references to pascal_language_data. * rust-lang.c (rust_language_data): Delete. (rust_language): Remove references to rust_language_data.
* gdb: Convert language_data::la_op_print_tab to a methodAndrew Burgess2020-09-161-4/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Convert language_data::la_op_print_tab member variable to a virtual method language_defn::opcode_print_table. I changed the name in order to make it clearer (I hope) what the method does. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_data): Remove la_op_print_tab initializer. (ada_language::opcode_print_table): New member function. * c-lang.c (c_language_data): Remove la_op_print_tab initializer. (c_language::opcode_print_table): New member function. (cplus_language_data): Remove la_op_print_tab initializer. (cplus_language::opcode_print_table): New member function. (asm_language_data): Remove la_op_print_tab initializer. (asm_language::opcode_print_table): New member function. (minimal_language_data): Remove la_op_print_tab initializer. (minimal_language::opcode_print_table): New member function. * d-lang.c (d_language_data): Remove la_op_print_tab initializer. (d_language::opcode_print_table): New member function. * expprint.c (print_subexp_standard): Update call to opcode_print_table. (op_string): Likewise. * f-lang.c (f_language_data): Remove la_op_print_tab initializer. (f_language::opcode_print_table): New member function. * go-lang.c (go_language_data): Remove la_op_print_tab initializer. (go_language::opcode_print_table): New member function. * language.c (unknown_language_data): Remove la_op_print_tab initializer. (unknown_language::opcode_print_table): New member function. (auto_language_data): Remove la_op_print_tab initializer. (auto_language::opcode_print_table): New member function. * language.h (language_data): Remove la_op_print_tab field. (language_defn::opcode_print_table): Declare new member function. * m2-lang.c (m2_language_data): Remove la_op_print_tab initializer. (m2_language::opcode_print_table): New member function. * objc-lang.c (objc_language_data): Remove la_op_print_tab initializer. (objc_language::opcode_print_table): New member function. * opencl-lang.c (opencl_language_data): Remove la_op_print_tab initializer. (opencl_language::opcode_print_table): New member function. * p-lang.c (pascal_language_data): Remove la_op_print_tab initializer. (pascal_language::opcode_print_table): New member function. * rust-lang.c (rust_language_data): Remove la_op_print_tab initializer. (rust_language::opcode_print_table): New member function.
* gdb: Convert language_data::la_exp_desc to a methodAndrew Burgess2020-09-161-4/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Convert language_data::la_exp_desc member variable to a virtual method language_defn::expression_ops. The change of names brings this method more into line with the existing varobj_ops method, that also returns a table of function pointers. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_data): Remove la_exp_desc initializer. (ada_language::expression_ops): New member function. * c-lang.c (c_language_data): Remove la_exp_desc initializer. (c_language::expression_ops): New member function. (cplus_language_data): Remove la_exp_desc initializer. (cplus_language::expression_ops): New member function. (asm_language_data): Remove la_exp_desc initializer. (asm_language::expression_ops): New member function. (minimal_language_data): Remove la_exp_desc initializer. (minimal_language::expression_ops): New member function. * d-lang.c (d_language_data): Remove la_exp_desc initializer. (d_language::expression_ops): New member function. * eval.c (evaluate_subexp): Update call to expression_ops. * expprint.c (print_subexp): Likewise. (op_name): Likewise. (dump_subexp_body): Likewise. * f-lang.c (f_language_data): Remove la_exp_desc initializer. (f_language::expression_ops): New member function. * go-lang.c (go_language_data): Remove la_exp_desc initializer. (go_language::expression_ops): New member function. * language.c (language_defn::expression_ops): New function. (unknown_language_data): Remove la_exp_desc initializer. (auto_language_data): Likewise. * language.h (language_data): Remove la_exp_desc field. (language_defn::expression_ops): Declare new member function. * m2-lang.c (m2_language_data): Remove la_exp_desc initializer. (m2_language::expression_ops): New member function. * objc-lang.c (objc_language_data): Remove la_exp_desc initializer. * opencl-lang.c (opencl_language_data): Remove la_exp_desc initializer. (opencl_language::expression_ops): New member function. * p-lang.c (pascal_language_data): Remove la_exp_desc initializer. * parse.c (operator_length): Update call to expression_ops. (exp_iterate): Likewise. * rust-lang.c (rust_language_data): Remove la_exp_desc initializer. (ruse_language::expression_ops): New member function.
* gdb: Convert language_data::la_varobj_ops to a methodAndrew Burgess2020-09-161-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Convert language_data::la_varobj_ops member variable to a virtual method language_defn::varobj_ops. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_data): Remove la_varobj_ops initializer. (ada_language::varobj_ops): New member function. * c-lang.c (c_language_data): Remove la_varobj_ops initializer. (cplus_language_data): Likewise. (cplus_language::varobj_ops): New member function. (asm_language_data): Remove la_varobj_ops initializer. (minimal_language_data): Likewise. * d-lang.c (d_language_data): Likewise. * f-lang.c (f_language_data): Likewise. * go-lang.c (go_language_data): Likewise. * language.c (language_defn::varobj_ops): New function. (unknown_language_data): Remove la_varobj_ops initializer. (auto_language_data): Likewise. * language.h (language_data): Remove la_varobj_ops field. (language_defn::varobj_ops): Declare new member function. * m2-lang.c (m2_language_data): Remove la_varobj_ops initializer. * objc-lang.c (objc_language_data): Likewise. * opencl-lang.c (opencl_language_data): Likewise. * p-lang.c (pascal_language_data): Likewise. * rust-lang.c (rust_language_data): Likewise. * varobj.c (varobj_create): Update call to varobj_ops. * varobj.h (default_varobj_ops): Delete define.
* gdb: Convert language_data::la_macro_expansion to a methodAndrew Burgess2020-09-161-4/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Convert language_data::la_macro_expansion member variable to a virtual method language_defn::macro_expansion. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_data): Remove la_macro_expansion initializer. * c-lang.c (c_language_data): Likewise. (c_language::macro_expansion): New member function. (cplus_language_data): Likewise. (cplus_language::macro_expansion): New member function. (asm_language_data): Likewise. (asm_language::macro_expansion): New member function. (minimal_language_data): Likewise. (minimal_language::macro_expansion): New member function. * d-lang.c (d_language_data): Remove la_macro_expansion initializer. * f-lang.c (f_language_data): Likewise. * go-lang.c (go_language_data): Likewise. * language.c (unknown_language_data): Likewise. (auto_language_data): Likewise. * language.h (language_data): Remove la_macro_expansion field. (language_defn::macro_expansion): New member function. * m2-lang.c (m2_language_data): Remove la_macro_expansion initializer. * objc-lang.c (objc_language_data): Likewise. (objc_language::macro_expansion): New member function. * opencl-lang.c (opencl_language_data): Likewise. (opencl_language::macro_expansion): New member function. * p-lang.c (pascal_language_data): Remove la_macro_expansion initializer. * rust-lang.c (rust_language_data): Likewise. * symtab.c (default_collect_symbol_completion_matches_break_on): Update call to macro_expansion.
* gdb: Convert language_data::la_array_ordering to a methodAndrew Burgess2020-09-161-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Convert language_data::la_array_ordering member variable to a virtual method language_defn::array_ordering. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_data): Remove la_array_ordering initializer. * c-lang.c (c_language_data): Likewise. (cplus_language_data): Likewise. (asm_language_data): Likewise. (minimal_language_data): Likewise. * d-lang.c (d_language_data): Likewise. * dwarf2/read.c (read_array_order): Update for call to array_ordering. * f-lang.c (f_language_data): Remove la_array_ordering initializer. (f_language::array_ordering): New member function. * go-lang.c (go_language_data): Remove la_array_ordering initializer. * language.c (unknown_language_data): Likewise. (auto_language_data): Likewise. * language.h (language_data): Delete la_array_ordering field. (language_defn::array_ordering): New member function. * m2-lang.c (m2_language_data): Remove la_array_ordering initializer. * objc-lang.c (objc_language_data): Likewise. * opencl-lang.c (opencl_language_data): Likewise. * p-lang.c (pascal_language_data): Likewise. * rust-lang.c (rust_language_data): Likewise.