aboutsummaryrefslogtreecommitdiff
path: root/gdb
AgeCommit message (Collapse)AuthorFilesLines
2020-05-27Add dwarf2_per_bfd field to dwarf2_per_cu_dataSimon Marchi3-6/+32
Some code using dwarf2_per_cu_data objects accesses the corresponding dwarf2_per_bfd using the following pattern: per_cu->dwarf2_per_objfile->per_bfd Since dwarf2_per_cu_data objects are going to become objfile-independent, the dwarf2_per_objfile link must go. To replace it, add a dwarf2_per_cu_data->per_bfd link. It makes sense to have it there because the dwarf2_per_cu_data objects belong to the dwarf2_per_bfd, so this is essentially just a backlink to their owner. gdb/ChangeLog: * dwarf2/read.h (struct dwarf2_per_cu_data) <per_bfd>: New member. * dwarf2/read.c (dwarf2_per_bfd::allocate_per_cu): Initialize dwarf2_per_cu_data::per_bfd. (dwarf2_per_bfd::allocate_signatured_type): Likewise. (create_type_unit_group): Likewise. (queue_comp_unit): Remove reference to per_cu->dwarf2_per_objfile. (maybe_queue_comp_unit): Likewise. (fill_in_sig_entry_from_dwo_entry): Assign new field. (create_cus_hash_table): Assign new field. Change-Id: I4ba0a393e64a14489ef061261a3dede1509d055b
2020-05-27Remove dwarf2_cu->per_cu->dwarf2_per_objfile referencesSimon Marchi2-165/+133
Change spots that access the dwarf2_per_objfile object through this pattern: dwarf2_cu->per_cu->dwarf2_per_objfile to dwarf2_cu->per_objfile This allows removing many references to dwarf2_per_cu_data::dwarf2_per_objfile. Again, I hope the following ChangeLog entry will be fine. I'd rather not list all the affected functions, as it would be time-consuming and a bit pointless. gdb/ChangeLog: * dwarf2/read.c: Replace dwarf2_cu->per_cu->dwarf2_per_objfile references with dwarf2_cu->per_objfile throughout. Change-Id: I00f44e88295f70ae805a4b18e8144ca92154612e
2020-05-27Remove reference to dwarf2_per_cu_data::dwarf2_per_objfile in ↵Simon Marchi2-38/+66
dw2_do_instantiate_symtab This patch begins by removing the per_cu->dwarf2_per_objfile reference in dw2_do_instantiate_symtab, instead accepting a dwarf2_per_objfile object as a parameter. It then fixes the fallouts. In this context, the dwarf2_per_objfile is generally derived from an objfile passed to a quick_symbol_functions callback. gdb/ChangeLog: * dwarf2/read.c (dw2_do_instantiate_symtab): Add per_objfile parameter, don't use per_cu->dwarf2_per_objfile. (dw2_instantiate_symtab): Likewise. (dw2_find_last_source_symtab): Update. (dw2_map_expand_apply): Update. (dw2_lookup_symbol): Update. (dw2_expand_symtabs_for_function): Update. (dw2_expand_all_symtabs): Update. (dw2_expand_symtabs_with_fullname): Update. (dw2_expand_symtabs_matching_one): Add per_objfile parameter, don't use per_cu->dwarf2_per_objfile. (dw2_expand_marked_cus): Update. (dw2_find_pc_sect_compunit_symtab): Update. (dw2_debug_names_lookup_symbol): Update. (dw2_debug_names_expand_symtabs_for_function): Update. (dw2_debug_names_map_matching_symbols): Update. (dwarf2_psymtab::expand_psymtab): Update. Change-Id: I248300822a09bae8470b65a7122d04fb9cb2b5bc
2020-05-27Add dwarf2_per_objfile field to dwarf2_cuSimon Marchi2-10/+28
Subsequent patches will make dwarf2_per_cu_data objfile-independent. This means that the dwarf2_per_cu_data::dwarf2_per_objfile field must go. The code using a dwarf2_cu structure currently accesses the current dwarf2_per_objfile object through dwarf2_cu->per_cu->dwarf2_per_objfile. Since it's ok for the dwarf2_cu to know about the current objfile (a dwarf2_cu is always used in the context of a particular objfile), add a dwarf2_per_objfile field to dwarf2_cu. Upcoming patches will gradually remove uses of dwarf2_per_cu_data::dwarf2_per_objfile in favor of dwarf2_cu::dwarf2_per_objfile, until the former can be removed. gdb/ChangeLog: * dwarf2/read.c (struct dwarf2_cu) <dwarf2_cu>: Add parameter. <per_objfile>: New member. (class cutu_reader) <init_tu_and_read_dwo_dies>: Add parameter. (cutu_reader::init_tu_and_read_dwo_dies): Add parameter, update call to dwarf2_cu. (cutu_reader::cutu_reader): Update. (dwarf2_cu::dwarf2_cu): Add parameter, initialize per_objfile. Change-Id: I8fd0da7371f65baea1ea7787aad08e10453bc565
2020-05-27Move die_type_hash to dwarf2_per_objfileSimon Marchi3-10/+19
The die_type_hash field can't be shared between multiple obfiles, as it holds `struct type` objects, which are objfile-specific. Move it from dwarf2_per_bfd to dwarf2_per_objfile and update all references. gdb/ChangeLog: * dwarf2/read.h (struct dwarf2_per_bfd) <die_type_hash>: Move to struct dwarf2_per_objfile. (struct dwarf2_per_objfile) <die_type_hash>: Move from struct dwarf2_per_bfd. * dwarf2/read.c (set_die_type): Update. (get_die_type_at_offset): Update. Change-Id: I3589777ed3579bcabafd2ba859d27babe4502bfb
2020-05-27Remove symtab links from dwarf2_psymtab and dwarf2_per_cu_quick_dataSimon Marchi3-70/+160
The dwarf2_psymtab and dwarf2_per_cu_quick_data types contain a pointer to a compunit_symtab, which is a pointer to the corresponding full symtab. The dwarf2_psymtab and dwarf2_per_cu_quick_data objects are going to become objfile-independent, and possibly shared by multiple objfiles, whereas compunit_symtab will stay objfile-dependent. This backlink to the compunit_symtab must therefore be removed. This patch replaces them with a vector in the dwarf2_per_objfile type, that serves as a mapping from dwarf2_per_cu_data objects to compunit_symtab objects, for this particular objfile. The vector is indexed using the index assigned to the dwarf2_per_cu_data at its creation. I removed the get_compunit_symtab, as it appears to bring not much value over calling dwarf2_per_objfile::get_symtab directly. gdb/ChangeLog: YYYY-MM-DD Tom Tromey <tom@tromey.com> YYYY-MM-DD Simon Marchi <simon.marchi@efficios.com> * dwarf2/read.h (struct dwarf2_per_bfd) <num_psymtabs>: New method. (struct dwarf2_per_objfile) <resize_symtabs, symtab_set_p, get_symtab, set_symtab>: New methods. <m_symtabs>: New field. (struct dwarf2_psymtab): Derive from partial_symtab. <readin_p, get_compunit_symtab>: Declare methods. * dwarf2/read.c (dwarf2_per_objfile::symtab_set_p, dwarf2_per_objfile::get_symtab, dwarf2_per_objfile::set_symtab): New methods. (struct dwarf2_per_cu_quick_data) <compunit_symtab>: Remove. (dw2_do_instantiate_symtab, dw2_instantiate_symtab) (dw2_map_expand_apply, dw2_map_symtabs_matching_filename) (dw2_symtab_iter_next, dw2_print_stats) (dw2_expand_symtabs_with_fullname) (dw2_expand_symtabs_matching_one) (dw_expand_symtabs_matching_file_matcher) (dw2_find_pc_sect_compunit_symtab, dw2_map_symbol_filenames) (dw2_debug_names_iterator::next) (dw2_debug_names_map_matching_symbols) (fill_in_sig_entry_from_dwo_entry, dwarf2_psymtab::read_symtab) (process_queue, dwarf2_psymtab::expand_psymtab): Update. (dwarf2_psymtab::readin_p, dwarf2_psymtab::get_compunit_symtab): New methods. (get_compunit_symtab, process_full_comp_unit) (process_full_type_unit): Update. (dwarf2_build_psymtabs, dwarf2_initialize_objfile, add_type_unit): Call Change-Id: Iec53d96e0b70a57d8b68408febdac3c6c3d4854b
2020-05-27Split dwarf2_per_objfile into dwarf2_per_objfile and dwarf2_per_bfdSimon Marchi5-362/+412
This is the first step of splitting dwarf2_per_objfile in two, one structure for objfile-independent data (dwarf2_per_bfd) and one for objfile-dependent data (dwarf2_per_objfile). The existing dwarf2_per_objfile is renamed dwarf2_per_bfd, and a new dwarf2_per_objfile type is introduced, which sits "in between" the objfile and dwarf2_per_bfd. So where we had this before: objfile -> dwarf2_per_objfile (*) we now have this: objfile -> dwarf2_per_objfile -> dwarf2_per_bfd (*) (*) Note that the dwarf2_per_objfile in the former corresponds to the dwarf2_per_bfd in the latter. I've done the minimal amount of changes in this patch: following patches will incrementally move things that are not actually shareable between objfiles from dwarf2_per_bfd to dwarf2_per_objfile. Most references to dwarf2_per_objfile objects are changed to dwarf2_per_objfile->per_bfd. To avoid many of these replacements, which would have to be reverted later anyway, I've moved right away the objfile backlink to the new dwarf2_per_objfile structure in this patch. I've also moved the read_line_string method, since it references the objfile backlink, and it's actually not difficult to move. Once the moves are completed, multiple dwarf2_per_objfile sharing the same BFD will point to the same single instance of dwarf2_per_bfd (as long as they don't require relocation). dwarf2_has_info, where we create these objects, is updated to the new architecture. I've had to change the get_gdb_index_contents_ftype typedef and related functions. The parameter type was changed from dwarf2_per_objfile to dwarf2_per_bfd, otherwise the template wouldn't work. Please excuse the terse ChangeLog entry, I have not listed all the functions where dwarf2_per_objfile has been changed to dwarf2_per_objfile->per_bfd. It would take a considerable amount of time and would not really be useful in the end. gdb/ChangeLog: * dwarf2/read.h (dwarf2_per_objfile): Rename to dwarf2_per_bfd, then introduce a new dwarf2_per_objfile type. <read_line_string>: Move to the new dwarf2_per_objfile type. <objfile>: Likewise. (dwarf2_per_bfd): Rename dwarf2_per_objfile to this. * dwarf2/read.c: Replace references to dwarf2_per_objfile with dwarf2_per_objfile->per_bfd. (dwarf2_per_objfile::dwarf2_per_objfile): Rename to... (dwarf2_per_bfd::dwarf2_per_bfd): ... this. (dwarf2_per_objfile::free_cached_comp_units): Rename to... (dwarf2_per_bfd::free_cached_comp_units): ... this. (dwarf2_has_info): Allocate dwarf2_per_bfd. (dwarf2_per_objfile::locate_sections): Rename to... (dwarf2_per_bfd::locate_sections): ... this. (dwarf2_per_objfile::get_cutu): Rename to... (dwarf2_per_bfd::get_cutu): ... this. (dwarf2_per_objfile::get_cu): Rename to... (dwarf2_per_bfd::get_cu): ... this. (dwarf2_per_objfile::get_tu): Rename to... (dwarf2_per_bfd::get_tu): ... this. (dwarf2_per_objfile::allocate_per_cu): Rename to... (dwarf2_per_bfd::allocate_per_cu): ... this. (dwarf2_per_objfile::allocate_signatured_type): Rename to... (dwarf2_per_bfd::allocate_signatured_type): ... this. (get_gdb_index_contents_ftype): Change parameter from dwarf2_per_objfile to dwarf2_per_bfd. * dwarf2/macro.c, dwarf2/index-write.c: Replace references to dwarf2_per_objfile with dwarf2_per_objfile->per_bfd. Change-Id: I7de7b5d1ce7494aa73bfcf15f719d3c5c46e138c
2020-05-27Add dwarf2_per_objfile member to DWARF batonsTom Tromey4-12/+54
Various DWARF callbacks expect to be able to fetch the objfile and / or dwarf2_per_objfile from the DWARF CU object. However, this won't be possible once sharing is implemented. Because these objects are related to full symbols (e.g., they are used to implement location expressions), they can simply store the dwarf2_per_objfile they need. This patch adds a per_objfile member to the various "baton" structures and arranges to set this value when constructing the baton. gdb/ChangeLog: YYYY-MM-DD Tom Tromey <tom@tromey.com> YYYY-MM-DD Simon Marchi <simon.marchi@efficios.com> * dwarf2/loc.c (struct piece_closure) <per_objfile>: New member. (allocate_piece_closure): Set "per_objfile" member. (dwarf2_find_location_expression, dwarf2_locexpr_baton_eval) (locexpr_describe_location, loclist_describe_location): Use new member. * dwarf2/read.c (read_call_site_scope) (mark_common_block_symbol_computed, attr_to_dynamic_prop) (dwarf2_const_value_attr, dwarf2_fetch_die_loc_sect_off) (fill_in_loclist_baton, dwarf2_symbol_mark_computed, handle_data_member_location): Set per_objfile member. * dwarf2/loc.h (struct dwarf2_locexpr_baton) <per_objfile>: New member. (struct dwarf2_loclist_baton) <per_objfile>: New member. Change-Id: If3aaa6a0f544be86710157c3adb68fde24d80037
2020-05-27Add dwarf2_per_cu_data::indexTom Tromey3-19/+60
Currently, a dwarf2_per_cu_data can hold a link to the corresponding expanded compunit_symtab. However, the dwarf2_per_cu_data objects are shared across objfiles, a simple pointer won't work: each objfile sharing the dwarf2_per_cu_data instance will have a corresponding compunit_symtab. Instead, this link will be stored in the dwarf2_per_objfile object (which will contain the objfile-specific data). To enable this, we add an index to each dwarf2_per_cu_data and signatured_type. The data structure in the dwarf2_per_objfile will use this new index to map a dwarf2_per_cu_data to its corresponding compunit_symtab, for this objfile. gdb/ChangeLog: * dwarf2/read.h (struct dwarf2_per_objfile) <allocate_per_cu, allocate_signatured_type>: Declare new methods. <m_num_psymtabs>: New member. (struct dwarf2_per_cu_data) <index>: New member. * dwarf2/read.c (dwarf2_per_objfile::allocate_per_cu) (dwarf2_per_objfile::allocate_signatured_type): New methods. (create_cu_from_index_list): Use allocate_per_cu. (create_signatured_type_table_from_index) (create_signatured_type_table_from_debug_names) (create_debug_type_hash_table, add_type_unit) (read_comp_units_from_section): Use allocate_signatured_type. Change-Id: I7733479a38ce82a5015cb184c8acce5f8bbf2e69
2020-05-27Add "objfile" parameter to two partial_symtab methodsTom Tromey4-35/+55
This series will cause partial symtabs to be shared across objfiles. However, full symtabs and symbols will still be objfile-dependent, so will be expanded separately for each objfile. So, a debug info reader will need to know which objfile to consult when expanding a partial symtab. This patch adds an objfile parameter to the two relevant methods of partial_symtab. Current implementations simply ignore them. gdb/ChangeLog: * psymtab.c (partial_map_expand_apply) (psym_find_pc_sect_compunit_symtab, psym_lookup_symbol) (psym_lookup_global_symbol_language) (psymtab_to_symtab, psym_find_last_source_symtab, dump_psymtab) (psym_print_stats, psym_expand_symtabs_for_function) (psym_map_symbol_filenames, psym_map_matching_symbols) (psym_expand_symtabs_matching) (partial_symtab::read_dependencies, maintenance_info_psymtabs) (maintenance_check_psymtabs): Update. * psympriv.h (struct partial_symtab) <readin_p, get_compunit_symtab>: Add objfile parameter. (struct standard_psymtab) <readin_p, get_compunit_symtab>: Likewise. * dwarf2/read.c (struct dwarf2_include_psymtab) <readin_p, get_compunit_symtab>: Likewise. (dwarf2_psymtab::expand_psymtab): Pass objfile argument. Change-Id: I3f0b26787c3e78f7fb78b9fc011d91fb8690f3a0
2020-05-27Introduce dwarf2_per_objfile::obstackTom Tromey3-52/+66
Currently much of the DWARF-related data is stored on the objfile obstack. This prevents sharing this data across objfiles, so this patch adds a new obstack to dwarf2_per_objfile. Note that the dwarf2_per_objfile type is going to become "dwarf2_per_bfd" in a subsequent patch, which is indeed going to be shared between objfiles. One way to check whether this is correct is to look at the remaining uses of objfile_obstack in the DWARF code and note that they all appear in the "full CU" code paths. The converse -- storing per-objfile data on the shared obstack -- is not good, but it is just a memory leak, not a potential use-after-free. Double-checking this would also be useful, though. gdb/ChangeLog: * dwarf2/read.h (struct dwarf2_per_objfile) <obstack>: New member. * dwarf2/read.c (delete_file_name_entry): Fix comment. (create_cu_from_index_list) (create_signatured_type_table_from_index) (create_signatured_type_table_from_debug_names) (dw2_get_file_names_reader, dwarf2_initialize_objfile) (dwarf2_create_include_psymtab) (create_debug_type_hash_table, add_type_unit) (create_type_unit_group, read_comp_units_from_section) (dwarf2_compute_name, create_cus_hash_table) (create_dwp_hash_table, create_dwo_unit_in_dwp_v1) (create_dwo_unit_in_dwp_v2, open_and_init_dwp_file): Use new obstack. (dw2_get_real_path): Likewise. Change argument to dwarf2_per_objfile. Change-Id: Icdec7be7c4d9f33d1dce4f807284f3077f7d3f03
2020-05-27Fix PR 26000, logical bitwise error / prologue analyzerLuis Machado2-1/+7
This fixes an instruction mask typo. We should be matching only ldrd (immediate) and not any other of its variants. As is, it never matches anything. With the patch, the instruction mask also allows matching of ldrd (literal), but the check for SP discards this particular instruction pattern, as it has a hardcoded PC register. gdb/ChangeLog: 2020-05-27 Luis Machado <luis.machado@linaro.org> PR tdep/26000 * arm-tdep.c (thumb_analyze_prologue): Fix instruction matching for ldrd (immediate).
2020-05-27Fix some duplicate test namesLuis Machado23-306/+475
While doing a testsuite run on aarch64-linux, I noticed a bunch of duplicated test name results. It annoyed me a little, so I decided to go ahead and fix the worst offenders. The following patch brings the duplicate test names down from 461 to 137. The remaining ones are mostly scattered across the testsuite, with 1 to 3 duplicates per testcase. We can fix those as we go. gdb/testsuite/ChangeLog: 2020-05-27 Luis Machado <luis.machado@linaro.org> * gdb.arch/aarch64-sighandler-regs.exp: Fix duplicated test names. * gdb.arch/aarch64-tagged-pointer.exp: Likewise. * gdb.arch/arm-disassembler-options.exp: Likewise. * gdb.arch/arm-disp-step.exp: Likewise. * gdb.arch/thumb-prologue.exp: Likewise. * gdb.base/async.exp: Likewise. * gdb.base/auxv.exp: Likewise. * gdb.base/complex-parts.exp: Likewise. * gdb.base/ena-dis-br.exp: Likewise. * gdb.base/foll-exec.exp: Likewise. * gdb.base/permissions.exp: Likewise. * gdb.base/relocate.exp: Likewise. * gdb.base/return2.exp: Likewise. * gdb.base/sigbpt.exp: Likewise. * gdb.base/siginfo-obj.exp: Likewise. * gdb.cp/converts.exp: Likewise. * gdb.cp/exceptprint.exp: Likewise. * gdb.cp/inherit.exp: Likewise. * gdb.cp/nsnoimports.exp: Likewise. * gdb.cp/virtbase2.exp: Likewise. * gdb.mi/mi-var-cmd.exp: Likewise. * gdb.mi/var-cmd.c: Likewise.
2020-05-26Ensure class_tui is listed in the output of "help" giving the list of classes.Philippe Waroquiers3-1/+13
Before this change, "help" was not showing the TUI class. With this change: (gdb) help ... support -- Support facilities. text-user-interface -- TUI is the GDB text based interface. tracepoints -- Tracing of program execution without stopping the program. ... (gdb) help text-user-interface TUI is the GDB text based interface. In TUI mode, GDB can display several text windows showing the source file, the processor registers, the program disassembly, ... List of commands: + -- Scroll window forward. ... Note that we cannot use "tui" for the fake class command name, as "tui" is a command. gdb/ChangeLog 2020-05-26 Philippe Waroquiers <philippe.waroquiers@skynet.be> * command.h: Add comment giving the name of class_tui. * cli/cli-cmds.c (_initialize_cli_cmds): If TUI defined, create the fake command for the help for class_tui.
2020-05-26Handle indexing Ada arrays with enum indicesTom Tromey9-85/+86
In Ada, like C, an enum can assign values to the constants. However, unlike C (or any other language supported by gdb), the enum type can also be used as the range of an array. In this case, the user's code references the enum constants, but the compiler translates these to the position of the constant in the enum. So for example one might write: type Enum_With_Gaps is ( LIT0, LIT1, LIT2, LIT3, LIT4 ); for Enum_With_Gaps use ( LIT0 => 3, LIT1 => 5, LIT2 => 8, LIT3 => 13, LIT4 => 21 ); Then index an array like "array(LIT3)" -- but this will be the 4th element in an array of 5 elements, not the 13th element in an array of 19 (assuming I did the math right) elements. gdb supports this to some degree, with the only missing piece being indexing into such an array. This patch implements this missing feature, and also fixes an existing bug, which is that in some situations I believe gdb would mis-compute the resulting array's length. The approach taken here is to try to integrate this feature into the core of gdb. My view is that much of the Ada support should be better integrated with gdb, rather than being "on the side". This, I think, would help avoid code duplication at least. So, I try to take steps toward this goal when possible. Because other languages generally don't allow the user to specify the index type of an array, I simply made the core of gdb unconditionally apply discrete_position when computing the range of such an array. This is a no-op for ordinary types, but applies the enum value-to-position transformation for TYPE_CODE_ENUM. gdb/ChangeLog 2020-05-26 Tom Tromey <tromey@adacore.com> * ada-lang.c (ada_print_array_index): Change type. Call val_atr. (ada_value_ptr_subscript): Don't call pos_atr on the lower bound. (val_atr): New function. (value_val_atr): Use it. * ada-valprint.c (print_optional_low_bound): Change low bound handling for enums. (val_print_packed_array_elements): Don't call discrete_position. * gdbtypes.c (get_discrete_bounds) <TYPE_CODE_RANGE>: Call discrete_position for enum types. * language.c (default_print_array_index): Change type. * language.h (struct language_defn) <la_print_array_index>: Add index_type parameter, change type of index_value. (LA_PRINT_ARRAY_INDEX): Add index_type parameter. (default_print_array_index): Update. * valprint.c (maybe_print_array_index): Don't call value_from_longest. Update. (value_print_array_elements): Don't call discrete_position. gdb/testsuite/ChangeLog 2020-05-26 Tom Tromey <tromey@adacore.com> * gdb.ada/arr_acc_idx_w_gap.exp: Add tests.
2020-05-26Fix bugs in 'val and 'pos with range typesTom Tromey7-2/+28
In Ada, the 'val and 'pos attributes can be used to map from an enumeration constant to its position in the enum and vice versa. These operators did not work properly when the type in question was a subrange of an enum type with "holes". gdb/ChangeLog 2020-05-26 Tom Tromey <tromey@adacore.com> * ada-lang.c (value_val_atr): Handle TYPE_CODE_RANGE. * gdbtypes.c (discrete_position): Handle TYPE_CODE_RANGE. gdb/testsuite/ChangeLog 2020-05-26 Tom Tromey <tromey@adacore.com> * gdb.ada/arr_acc_idx_w_gap.exp: Add enum subrange tests. * gdb.ada/arr_acc_idx_w_gap/enum_with_gap.ads (Enum_Subrange): New type. * gdb.ada/arr_acc_idx_w_gap/enum_with_gap_main.adb (V): New variable.
2020-05-26Use = instead of == for better portabilityChristian Biesinger via Gdb-patches2-2/+7
Reported by sobukus on IRC. gdb/testsuite/ChangeLog: 2020-05-26 Christian Biesinger <cbiesinger@google.com> * Makefile.in: Use = instead of == for the test command for portability. Change-Id: I431ccfa5e5ba15f9af082ffd6aa8cd7046456cd2
2020-05-26[gdb/testsuite] Add test-case gold-gdb-index.expTom de Vries5-0/+132
There's a PR binutils/15646 - "gold-generated .gdb_index has duplicated symbols that gdb-generated index doesn't", and gdb contains a workaround, added in commit 8943b87476 "Work around gold/15646". Add a test-case testing this workaround. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2020-05-26 Tom de Vries <tdevries@suse.de> * gdb.base/gold-gdb-index-2.c: New test. * gdb.base/gold-gdb-index.c: New test. * gdb.base/gold-gdb-index.exp: New file. * gdb.base/gold-gdb-index.h: New test.
2020-05-25[gdb/testsuite] Add target board gold-gdb-indexTom de Vries2-0/+49
Add new target board that uses gold to add a .gdb_index section, enabled by -ggnu-pubnames. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2020-05-25 Tom de Vries <tdevries@suse.de> * boards/gold-gdb-index.exp: New file.
2020-05-25gdb: make avr_integer_to_address generate code or data address based on typeCristiano De Alti2-1/+11
The AVR architecture is a Harvard one, meaning it has different memory spaces for code and data. In GDB, this is dealt with by having the data (SRAM) addresses start at 0x00800000. When interpreting an integer as an address (converting to a CORE_ADDR), we currently always generate a data address. This doesn't work for some cases described below, where the integer is meant to represent a code address. This patch changes avr_integer_to_address so that it generates the correct type of address (code or data) based on the passed type. Using the simavr.exp board, I didn't see any regressions when running the gdb.base/*.exp tests. A few tests go from fail to pass, but none from pass to fail. There are a few new fails and unresolved, but it's just because some tests manage to make more progress before failing in a different way. In practice, it fixes disassembling by address, as described in the PR: - (gdb) disassemble 0x12a,0x12b - Dump of assembler code from 0x12a to 0x12b: - 0x0000012a <main+0>: push r28 - End of assembler dump. + (gdb) disassemble 0x12a,0x12b + Dump of assembler code from 0x80012a to 0x80012b: + 0x0080012a: nop + End of assembler dump. And also, setting a breakpoint by address: - (gdb) p &main - $1 = (int (*)(void)) 0x12a <main> - (gdb) b *0x12a - Breakpoint 1 at 0x80012a + (gdb) p &main + $1 = (int (*)(void)) 0x12a <main> + (gdb) b *0x12a + Breakpoint 1 at 0x12a: file test-avr.c, line 3. + Note: automatically using hardware breakpoints for read-only addresses. gdb/ChangeLog: PR gdb/13519 * avr-tdep.c (avr_integer_to_address): Return data or code address accordingly to the second 'type' argument of the function. Change-Id: Iaea1587d053e86f4ab8aebdcabec8d31a6d262cd
2020-05-25gdb/testsuite: add simavr.exp boardSimon Marchi2-0/+99
This patch adds a board file for against a simavr target (so, for the AVR architecture). simavr, when started with option -g, runs a GDB stub on port 1234. In the current latest release (1.6), the port is hardcoded to 1234. But in master, there is the option to choose another port. So while the board file hardcodes the port today, in the future it should be possible to let the user choose a port, or automatically select a free port. It is easy enough to run, make sure you have avr-gcc/avr-g++ and simavr installed, and as usual just run: make check RUNTESTFLAGS="--target_board=simavr" The following environment variables influence the behavior of the board file: - SIMAVR_MCU: type of chip to simulate - SIMAVR_PATH: path to simavr binary (useful if you build your own simavr or for some reason it is not simply called `simavr`. As expected, there are a lot of failures. Many tests use some features not supported by such a target, and I suppose there are real GDB bugs too. But a lot also passes (including tests that actually run stuff), so this board file should still help to validate changes to the AVR architecture support. These are the results I got of running tests gdb.base/*.exp: # of expected passes 20926 # of unexpected failures 2257 # of expected failures 14 # of unknown successes 1 # of known failures 13 # of unresolved testcases 592 # of untested testcases 156 # of unsupported tests 30 # of paths in test names 3 # of duplicate test names 56 gdb/testsuite/ChangeLog: * boards/simavr.exp: New file. Change-Id: Ib7fa8c4e2e90b08b104bb9b552df37779de3bc21
2020-05-25gdb/testsuite: add inferior arguments testSimon Marchi4-8/+169
Add a test for verifying different methods of passing arguments to the inferior: the start, starti and run commands, as well as `set args`. All these methods work naturally when using the unix or native-extended-gdbserver target boards. Since those are non-stub boards, GDB runs new inferiors and therefore pass arguments to them. With target boards where GDB connects to a stub, for example with native-gdbserver, they don't really make sense. The inferior process is already started when GDB connects. However, the "run" method is still tested with stub targets, because the gdb_run_cmd procedure is adapted for stub targets. Instead of issuing the `run` command, it spawns whatever program is supposed to bring up the stub (gdbserver, for example) using gdb_reload and makes GDB connect to it. So this allows us to exercise argument passing through the gdbserver command line, when testing with the native-gdbserver board. Note that there is already a gdb.base/args.exp, but this tests specifically the --args switch of GDB. Perhaps it could be integrated in this new test, as a new "method". gdb/testsuite/ChangeLog: * lib/gdb.exp (gdb_run_cmd): Return success or failure. * gdb.base/inferior-args.exp: New file. * gdb.base/inferior-args.c: New file. Change-Id: Ib61ea6220a47f9f67aed2960dcacd240cb57af70
2020-05-25gdb/testsuite: support passing inferior arguments with native-gdbserver boardSimon Marchi8-24/+62
This patch makes it possible to run tests requiring passing arguments to the inferior with the native-gdbserver board. The end goal is to write a test that verifies passing arguments to the inferior works, and to have that test exercise inferior arguments passed on the gdbserver command line, when using the native-gdbserver target board (in addition to the other boards). This is done in the next patch. With the native-gdbserver target board, gdbserver is started in gdb_reload (implemented in config/gdbserver.exp), called in gdb_run_cmd. gdb_run_cmd already supposedly accepts inferior arguments (although that feature does not seem to be used anywhere), which it passes to the `run` command, for non-stub target boards. I've changed gdb_run_cmd so that it forwards these arguments to gdb_reload as well. gdb_reload passes them to gdbserver_run, and they eventually make their way to the gdbserver command line. gdb_run_cmd currently accepts `args` (the varargs of tcl), which means it receives inferior arguments as a list. This won't work with arguments with spaces, because they will end up being formatted with curly braces like this: % set args [list hello "with spaces" world] hello {with spaces} world % puts "run $args" run hello {with spaces} world I've changed it to accept a single string that is passed to `run` and gdb_reload. I've done the same change in gdb_start_cmd and gdb_starti_cmd, although these two are not used with native-gdbserver. I've changed all gdb_reload implementations in the tree to accept a new inferior_args argument, although most of them don't do anything with it (and don't need to). People maintaining target boards out of tree will need to do the same. I found two tests to adjust to avoid adding new failures or errors. These tests needed new [use_gdb_stub] checks, because they rely on having GDB run new processes. These are guarded by a [target_info exists noargs], which made them get skipped on native-gdbserver. But now that the native-gdbserver board supports args, this is no longer enough. Note that with this change, noargs and use_gdb_stub are orthogonal. It took me a moment to grasp this, so I thought I would spell out the different possible situations: - !noargs and !use_gdb_stub: inferior process started by gdb, can pass args - noargs and !use_gdb_stub: inferior process started by gdb (perhaps through extended-remote protocol, the simulator, some other target), but that target doesn't support inferior arguments - noargs and use_gdb_stub: inferior process started by some other program to which GDB connects using the remote protocol, that program does not support passing args to the inferior process - !noargs and use_gdb_stub: inferior process started by some other program to which GDB connects u sing the remote protocol, that program supports passing args to the inferior process gdb/testsuite/ChangeLog: * lib/gdb.exp (gdb_run_cmd): Change argument from args to inferior_args. Pass it to gdb_reload. (gdb_start_cmd, gdb_starti_cmd): Change argument from args to inferior_args. (gdb_reload): Add inferior_args argument. * config/gdbserver.exp (gdb_reload): Add inferior_args argument, pass it to gdbserver_run. * boards/native-gdbserver.exp: Do not set noargs. * boards/native-extended-gdbserver.exp (gdb_reload): Add inferior_args argument. * boards/stdio-gdbserver-base.exp (gdb_reload): Likewise. * gdb.base/a2-run.exp: Check for use_gdb_stub. * gdb.base/args.exp: Likewise. Change-Id: Ibda027c71867157852f34700342ab31edf39e4d8
2020-05-25gdbsupport: Let construct_inferior_arguments take gdb::array_view paramMichael Weghorn1-2/+3
Adapt the construct_inferior_arguments function to take a gdb::array_view<char * const> parameter instead of a char * array and an int indicating the length and adapt the only call site. This will allow calling it more simply in a follow-up patch introducing more uses of the function. gdbsupport/ChangeLog: * common-inferior.cc, common-inferior.h (construct_inferior_arguments): Adapt to take a gdb::array_view<char * const> parameter. Adapt call site. Change-Id: I1c6496c8c0b0eb3ef3fda96e9e3bd64c5e6cac3c
2020-05-25gdbsupport: Adapt construct_inferior_argumentsMichael Weghorn1-6/+3
Allow construct_inferior_arguments to handle zero args and have it return a std::string, similar to how stringify_argv in gdbsupport/common-utils does. Also, add a const qualifier for the second parameter, since it is only read, not written to. The intention is to replace existing uses of stringify_argv by construct_inferior_arguments in a subsequent step, since construct_inferior_arguments properly handles special characters, while stringify_argv doesn't. gdbsupport/ChangeLog: * common-inferior.cc, common-inferior.h (construct_inferior_arguments): Adapt to handle zero args and return a std::string. Adapt call site. Change-Id: I126c4390a1018c7527b0b8fd545252ab8a5a7adc
2020-05-25gdb: Move construct_inferior_arguments to gdbsupportMichael Weghorn3-126/+5
This moves the function construct_inferior_arguments from gdb/inferior.h and gdb/infcmd.c to gdbsupport/common-inferior.{h,cc}. While at it, also move the function's comment to the header file to align with current standards. The intention is to use it from gdbserver in a follow-up commit. gdb/ChangeLog: * infcmd.c, inferior.h: (construct_inferior_arguments): Moved function from here to gdbsupport/common-inferior.{h,cc} gdbsupport/ChangeLog: * common-inferior.h, common-inferior.cc: (construct_inferior_arguments): Move function here from gdb/infcmd.c, gdb/inferior.h Change-Id: Ib9290464ce8c0872f605d8829f88352d064c30d6
2020-05-25[gdb/testsuite] Add comment in exec_is_pieTom de Vries2-0/+7
Add comment to exec_is_pie explaining why readelf -d output is not used. gdb/testsuite/ChangeLog: 2020-05-25 Tom de Vries <tdevries@suse.de> * lib/gdb.exp (exec_is_pie): Add comment.
2020-05-25[gdb/testsuite] Fix var use in compile_and_download_n_jit_soTom de Vries2-1/+6
In commit 1b59ca1cf1 "[gdb/testsuite] Fix tcl error in jit-elf-helpers.exp", I introduced a variable f in compile_and_download_n_jit_so, to be used in the untested message, but actually variable binfile was used instead: ... + set f [file tail $binfile] + untested "failed to compile shared library $binfile" ... Fix this by using $f in the untested message. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2020-05-25 Tom de Vries <tdevries@suse.de> * lib/jit-elf-helpers.exp (compile_and_download_n_jit_so): Use $f instead of $binfile in the untested message.
2020-05-25[gdb/testsuite] Fix exec_is_pie with gold linkerTom de Vries2-2/+8
When running test-case gdb.base/break-interp.exp with target board gold, we run into: ... gdb compile failed, pie failed to generate PIE executable ... The problem is that the proc exec_is_pie uses the PIE flag in the readelf -d output, which doesn't seem to be set by the gold linker. Instead, use the "Type" field in the readelf -h output. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2020-05-25 Tom de Vries <tdevries@suse.de> PR testsuite/26031 * lib/gdb.exp (exec_is_pie): Test readelf -h output.
2020-05-25[gdb/testsuite] Add target board goldTom de Vries2-0/+36
Add a target board that uses the gold linker. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2020-05-25 Tom de Vries <tdevries@suse.de> * boards/gold.exp: New file.
2020-05-24Revert "Add completion styling"Tom Tromey10-148/+32
This reverts commit eca1f90cf47a2edc1a1cd22e12c6c0f3b900654e. Several changes were requested, and it seemed simplest to revert it. gdb/ChangeLog 2020-05-23 Tom Tromey <tom@tromey.com> Revert commit eca1f90c: * NEWS: Remove entry for completion styling. * completer.c (_rl_completion_prefix_display_length): Move declaration later. (gdb_fnprint): Revert. (gdb_display_match_list_1): Likewise. * cli/cli-style.c (completion_prefix_style) (completion_difference_style, completion_suffix_style): Remove. (_initialize_cli_style): Revert. * cli/cli-style.h (completion_prefix_style) (completion_difference_style, completion_suffix_style): Don't declare. gdb/doc/ChangeLog 2020-05-23 Tom Tromey <tom@tromey.com> * gdb.texinfo (Output Styling): Don't mention completion styling. (Editing): Don't mention readline completion styling. gdb/testsuite/ChangeLog 2020-05-23 Tom Tromey <tom@tromey.com> * gdb.base/style.exp: Remove completion styling test. * lib/gdb-utils.exp (style): Remove completion styles.
2020-05-24gdb: make gdbarch.sh write gdbarch.{c,h} directlySimon Marchi3-55/+8
It was suggested in this thread [1] that gdbarch.sh should write to gdbarch.h and gdbarch.c directly. This patch implements that. When running gdbarch.sh, we currently need to move new-gdbarch.c over gdbarch.c and new-gdbarch.h over gdbarch.h. It might have been useful at some point to not have gdbarch.sh overwrite gdbarch.h and gdbarch.c, but with git it's really unnecessary. Any changes to gdbarch.sh can be inspected using `git diff`. A next step would be to have the Makefile automatically run gdbarch.sh if it sees that gdbarch.c and gdbarch.h are out of date. Or maybe even remove gdbarch.c and gdbarch.h from the tree and generate them in the build directory when building. But that requires more thinking and discussions, and I think that this change is already useful in itself. [1] https://sourceware.org/pipermail/gdb-patches/2020-May/168265.html gdb/ChangeLog; * gdbarch.sh: Write to gdbarch.c/gdbarch.h directly. Don't compare old and new versions. (compare_new): Remove. Change-Id: I7970a9e8af0afc0145cb5a28e73d94fbaa1e25b9
2020-05-24Don't remove C++ aliases from completions if symbol doesn't matchPedro Alves3-7/+19
completion_list_add_symbol currently tries to remove C++ function aliases from the completions match list even if the symbol passed down wasn't successfully added to the completion list because it didn't match. I.e., we call cp_canonicalize_string_no_typedefs for each and every C++ function in the program, which is useful work. This patch skips that useless work. gdb/ChangeLog: 2020-05-24 Pedro Alves <palves@redhat.com> * symtab.c (completion_list_add_name): Return boolean indication of whether the symbol matched. (completion_list_add_symbol): Don't try to remove C++ aliases if the symbol didn't match in the first place. * symtab.h (completion_list_add_name): Return bool.
2020-05-23gdb: remove TYPE_FIELD macroSimon Marchi31-81/+84
Replace all uses of it by type::field. Note that since type::field returns a reference to the field, some spots are used to assign the whole field structure. See ctfread.c, function attach_fields_to_type, for example. This is the same as was happening with the macro, so I don't think it's a problem, but if anybody sees a really nicer way to do this, now could be a good time to implement it. gdb/ChangeLog: * gdbtypes.h (TYPE_FIELD): Remove. Replace all uses with type::field.
2020-05-23Document the GDB 9.2 release in gdb/ChangeLogJoel Brobecker1-0/+4
gdb/ChangeLog: GDB 9.2 released.
2020-05-23Add completion stylingTom Tromey10-7/+172
Readline has a styling feature for completion -- if it is enabled, the common prefix of completions will be displayed in a different style. This doesn't work in gdb, because gdb implements its own completer. This patch implements the feature. However, it doesn't directly use the Readline feature, because gdb can do a bit better: it can let the user control the styling using the existing mechanisms. This version incorporates an Emacs idea, via Eli: style the prefix, the "difference character", and the suffix differently. gdb/ChangeLog 2020-05-23 Tom Tromey <tom@tromey.com> * NEWS: Add entry for completion styling. * completer.c (_rl_completion_prefix_display_length): Move declaration earlier. (gdb_fnprint): Use completion_style. (gdb_display_match_list_1): Likewise. * cli/cli-style.c (completion_prefix_style) (completion_difference_style, completion_suffix_style): New globals. (_initialize_cli_style): Register new globals. * cli/cli-style.h (completion_prefix_style) (completion_difference_style, completion_suffix_style): Declare. gdb/doc/ChangeLog 2020-05-23 Tom Tromey <tom@tromey.com> * gdb.texinfo (Output Styling): Mention completion styling. (Editing): Mention readline completion styling. gdb/testsuite/ChangeLog 2020-05-23 Tom Tromey <tom@tromey.com> * gdb.base/style.exp: Add completion styling test. * lib/gdb-utils.exp (style): Add completion styles.
2020-05-23Use safe-ctype.h (ISSPACE etc.) in symbol parsing & comparisonPedro Alves2-23/+38
This patch avoids depending on the current locale when parsing & comparing symbol names, by using libiberty's safe-ctype.h uppercase TOLOWER, ISXDIGIT, etc. macros instead of the standard ctype.h tolower, isxdigit, etc. macros/functions. This commit: commit b1b60145aedb8adcb0b9dcf43a5ae735c2f03b51 Author: Pedro Alves <palves@redhat.com> AuthorDate: Tue May 22 17:35:38 2018 +0100 Support UTF-8 identifiers in C/C++ expressions (PR gdb/22973) did something similar, except in the expression parser. This can improve GDB's symbol loading performance significantly. Currently strcmp_iw_ordered can show up high on profiles (called from sort_pst_symbols -> std::sort) because of the isspace and tolower functions. Hannes mentions seeing it as high as in ~24% of the profiling samples on Windows (https://sourceware.org/pipermail/gdb-patches/2020-May/168858.html). I tested GDB's performance (built with "-g -O2") loading a "-g -O0" build of gdb. I ran GDB 10 times like: /bin/time -f %e \ ./gdb/gdb --data-directory ./gdb/data-directory -nx \ -batch /tmp/gdb-g-O0 Then I computed the mean time. The baseline mean time was gdb 2.515 This patch brings the number down to gdb 2.096 Which is an around 16% improvement. gdb/ChangeLog: 2020-05-23 Pedro Alves <palves@redhat.com> * utils.c: Include "gdbsupport/gdb-safe-ctype.h". (parse_escape): Use ISDIGIT instead of isdigit. (puts_debug): Use gdb_isprint instead of isprint. (fprintf_symbol_filtered): Use ISALNUM instead of isalnum. (cp_skip_operator_token, skip_ws, strncmp_iw_with_mode): Use ISSPACE instead of isspace. (strncmp_iw_with_mode): Use TOLOWER instead of tolower and ISSPACE instead of isspace. (strcmp_iw_ordered): Use ISSPACE instead of isspace. (string_to_core_addr): Use TOLOWER instead of tolower, ISXDIGIT instead of isxdigit and ISDIGIT instead of isdigit. gdbsupport/ChangeLog: 2020-05-23 Pedro Alves <palves@redhat.com> * gdb-safe-ctype.h: New.
2020-05-22gdb: remove TYPE_FIELDS macroSimon Marchi12-32/+42
Remove all uses of the `TYPE_FIELDS` macro. Replace them with either: 1) type::fields, to obtain a pointer to the fields array (same as TYPE_FIELDS yields) 2) type::field, a new convenience method that obtains a reference to one of the type's field by index. It is meant to replace TYPE_FIELDS (type)[idx] with type->field (idx) gdb/ChangeLog: * gdbtypes.h (struct type) <field>: New method. (TYPE_FIELDS): Remove, replace all uses with either type::fields or type::field. Change-Id: I49fba10114417deb502060c6156aa5f7fc62462f
2020-05-22gdb: add type::fields / type::set_fieldsSimon Marchi14-86/+114
Add the `fields` and `set_fields` methods on `struct type`, in order to remove the `TYPE_FIELDS` macro. In this patch, the `TYPE_FIELDS` macro is changed to the `type::fields`, so all the call sites that use it to set the fields array are changed to use `type::set_fields`. The next patch will remove `TYPE_FIELDS` entirely. gdb/ChangeLog: * gdbtypes.h (struct type) <fields, set_fields>: New methods. (TYPE_FIELDS): Use type::fields. Change all call sites that modify the propery to use type::set_fields instead. Change-Id: I05174ce68f2ce3fccdf5d8b469ff141f14886b33
2020-05-22gdb: remove TYPE_NFIELDS macroSimon Marchi68-318/+322
Remove `TYPE_NFIELDS`, changing all the call sites to use `type::num_fields` directly. This is quite a big diff, but this was mostly done using sed and coccinelle. A few call sites were done by hand. gdb/ChangeLog: * gdbtypes.h (TYPE_NFIELDS): Remove. Change all cal sites to use type::num_fields instead. Change-Id: Ib73be4c36f9e770e0f729bac3b5257d7cb2f9591
2020-05-22gdb: add type::num_fields / type::set_num_fieldsSimon Marchi14-43/+62
Add the `num_fields` and `set_num_fields` methods on `struct type`, in order to remove the `TYPE_NFIELDS` macro. In this patch, the `TYPE_NFIELDS` macro is changed to use `type::num_fields`, so all the call sites that are used to set the number of fields are changed to use `type::set_num_fields`. The next patch will remove `TYPE_NFIELDS` completely. I think that in the future, we should consider making the interface of `struct type` better. For example, right now it's possible for the number of fields property and the actual number of fields set to be out of sync. However, I want to keep the existing behavior in this patch, just translate from macros to methods. gdb/ChangeLog: * gdbtypes.h (struct type) <num_fields, set_num_fields>: New methods. (TYPE_NFIELDS): Use type::num_fields. Change all call sites that modify the number of fields to use type::set_num_fields instead. Change-Id: I5ad9de5be4097feaf942d111077434bf91d13dc5
2020-05-22Remove obsolete declarationTom Tromey2-1/+5
Commit c9e0a7e3331 ("Remove munmap_listp_free_cleanup") removed munmap_listp_free, but missed a declaration. This patch removes that as well. gdb/ChangeLog 2020-05-22 Tom Tromey <tromey@adacore.com> * compile/compile-object-load.h (munmap_list_free): Don't declare.
2020-05-22gdb: Restore old annotations behaviour when printing frame infoAndrew Burgess9-20/+73
This undoes most of the changes from these commits: commit ec8e2b6d3051f0b4b2a8eee9917898e95046c62f Date: Fri Jun 14 23:43:00 2019 +0100 gdb: Don't allow annotations to influence what else GDB prints commit 0d3abd8cc936360f8c46502135edd2e646473438 Date: Wed Jun 12 22:34:26 2019 +0100 gdb: Remove an update of current_source_line and current_source_symtab as a result of the discussion here: https://sourceware.org/pipermail/gdb/2020-April/048468.html Having taken time to reflect on the discussion, and reading the documentation again I believe we should revert GDB's behaviour back to how it used to be. The original concern that triggered the initial patch was that when annotations were on the current source and line were updated (inside the annotation code), while when annotations are off this update would not occur. This was incorrect, as printing the source with the call to print_source_lines does also update the current source and line. Further, the documentation here: https://sourceware.org/gdb/current/onlinedocs/gdb/Source-Annotations.html#Source-Annotations Clearly states: "The following annotation is used instead of displaying source code: ^Z^Zsource filename:line:character:middle:addr ..." So it is documented that the 'source' annotation is a replacement for, and not in addition to, actually printing the source lie. There are still a few issues that I can see, these are: 1. In source.c:info_line_command, when annotations are on we call annotate_source_line, however, if annotations are off then there is no corresponding call to print the source line. This means that a if a user uses 'info line ...' with annotations on, and then does a 'list', they will get different results than if they had done this with annotations off. 2. It bothers me that the call to annotate_source_line returns a boolean, and that this controls a call to print_source_line (in stack.c:print_frame_info). The reason for this is that the source line annotation will only print something if the file is found, and the line number is in range for the file. It seems to me like an annotation should always be printed, either one that identifies the file and line, or one that identifies the file and line GDB would like to access, but couldn't. I considered changing this, but in the end decided not too, if I extend the existing 'source' annotation to print something in all cases then I risk breaking existing UIs that rely on the file and line always being valid. If I add a new annotation then this might also break existing UIs that rely on GDB itself printing the error from within print_source_line. Given that annotations is deprecated (as I understand it) mechanism for UIs to interact with GDB (in favour of MI) I figure we should just restore the old behaviour, and leave the mini-bugs in until someone actually complains. This isn't a straight revert of the two commits mentioned above. I've left annotate_source_line instead of going back to the original identify_source_line, which lived in source.c, but was really annotation related. The API for setting the current source and line has changed since the original patches, so I updated for that change too. Finally I wrote the code in stack.c so that we avoided an extra level of indentation, which I felt made things easier to read. gdb/ChangeLog: * annotate.c (annotate_source_line): Update return type, add call to update current symtab and line. * annotate.h (annotate_source_line): Update return type, and extend header comment. * source.c (info_line_command): Check annotation_level before calling annotate_source_line. * stack.c (print_frame_info): If calling annotate_source_line returns true, then don't print any other source line information. gdb/testsuite/ChangeLog: * gdb.base/annota1.exp: Update expected results. * gdb.cp/annota2.exp: Update expected results, remove duplicate test name. * gdb.cp/annota3.exp: Update expected results.
2020-05-21gdb: fix -Wtautological-overlap-compare error in lm32-tdep.cSimon Marchi2-1/+5
Building with clang 11, we get: /home/smarchi/src/binutils-gdb/gdb/lm32-tdep.c:84:44: error: overlapping comparisons always evaluate to false [-Werror,-Wtautological-overlap-compare] return ((regnum >= SIM_LM32_EA_REGNUM) && (regnum <= SIM_LM32_BA_REGNUM)) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Indeed, this doesn't make sense, as EA_REGNUM is greater than BA_REGNUM. I'll assume that it was just a mistake and that these two should be swapped. The regnums for BA and EA are contiguous, so ultimately this particular part of the condition is only true if regnum is == EA or == BA. These registers are Exception Address and Breakpoint Address, so I guess it makes sense for them to be in the system register group. The relevant reference is here: https://www.latticesemi.com/-/media/LatticeSemi/Documents/UserManuals/JL/LatticeMico32ProcessorReferenceManual39.ashx?document_id=52077 gdb/ChangeLog: * lm32-tdep.c (lm32_register_reggroup_p): Fix condition.
2020-05-21gdb: remove unnecessary NULL checks before xfreeSimon Marchi11-22/+24
I was inspired by a series of patches merged by Alan Modra in the other projects, so I did the same in GDB with a bit of Coccinelle and grep. This patch removes the unnecessary NULL checks before calls to xfree. They are unnecessary because xfree already does a NULL check. Since free is supposed to handle NULL values correctly, the NULL check in xfree itself is also questionable, but I've left it there for now. gdb/ChangeLog: * coffread.c (patch_type): Remove NULL check before xfree. * corefile.c (set_gnutarget): Likewise. * cp-abi.c (set_cp_abi_as_auto_default): Likewise. * exec.c (build_section_table): Likewise. * remote.c (remote_target::pass_signals): Likewise. * utils.c (n_spaces): Likewise. * cli/cli-script.c (document_command): Likewise. * i386-windows-tdep.c (core_process_module_section): Likewise. * linux-fork.c (struct fork_info) <~fork_info>: Likewise.
2020-05-20gdb: reset/recompute objfile section offsets in reread_symbolsSimon Marchi2-0/+14
This patch started as an investigation of this bug, where the program is re-compiled between two "start" runs: $ ./gdb -nx --data-directory=data-directory -q a.out Reading symbols from a.out... (gdb) start Temporary breakpoint 1 at 0x1131: file test.c, line 1. Starting program: /home/smarchi/build/wt/test/gdb/a.out Temporary breakpoint 1, main () at test.c:1 1 int main() { return 0; } *** re-compile a.out *** (gdb) start The program being debugged has been started already. Start it from the beginning? (y or n) y `/home/smarchi/build/wt/test/gdb/a.out' has changed; re-reading symbols. Temporary breakpoint 2 at 0x555555555129: file test.c, line 1. Starting program: /home/smarchi/build/wt/test/gdb/a.out warning: Probes-based dynamic linker interface failed. Reverting to original interface. Temporary breakpoint 2, main () at test.c:1 1 int main() { return 0; } (gdb) To reproduce the bug, a.out needs to be a position-independent executable (PIE). Here's what happens: 1) We first read the symbols of a.out. The section offsets in the objfile are all 0, so the symbols are created unrelocated. 2) The breakpoint on main is created, as you can see the breakpoint address (derived from the `main` symbol with value 0x1129) is still unrelocated (0x1131). Since the program is not yet started, we don't know at which base address the executable is going to end at. Everything good so far. 3) The execution starts, GDB finds out the executable's base address, fills the objfile's section_offsets vector with a bunch of offsets, and relocates the symbols with those offsets. The latter modifies the symbol values (the `main` symbol is changed from 0x1129 to 0x555555555129). 4) We `start` again, we detect that `a.out` has changed, the `reread_symbols` function kicks in. It tries to reset everything in the `struct objfile` corresponding to `a.out`, except that it leaves the `section_offsets` vector there. 5) `reread_symbols` reads the debug info (calls `read_symbols`). As the DWARF info is read, symbols are created using the old offsets still in `section_offsets`. For example, the `main` symbol is created with the value 0x555555555129. Even though at this point there is no process, so that address is bogus. There's probably more that depends on section_offsets that is not done correctly. 6) Something in the SVR4 solib handling goes wrong, probably because of something that went wrong in (5). I can't quite explain it (if somebody would like to provide a more complete analysis, please go ahead). But this is where it takes a wrong turn: #0 elf_locate_base () at /home/smarchi/src/wt/test/gdb/solib-svr4.c:799 #1 0x000055f0a5bee6d5 in locate_base (info=<optimized out>) at /home/smarchi/src/wt/test/gdb/solib-svr4.c:848 #2 0x000055f0a5bf1771 in svr4_handle_solib_event () at /home/smarchi/src/wt/test/gdb/solib-svr4.c:1955 #3 0x000055f0a5c0ff92 in handle_solib_event () at /home/smarchi/src/wt/test/gdb/solib.c:1258 In the non-working case (without this patch), elf_locate_base returns 0, whereas in the working case (with this patch) it returns a valid address, as we should expect. This patch fixes this by making reread_symbols clear the `section_offsets` vector, and re-create it by calling `sym_offsets`. This is analogous to what syms_from_objfile_1 does. I didn't seem absolutely necessary, but I also made it clear the various `sect_index_*` fields, since their values no longer make sense (they describe the old executable, and are indices in the now cleared sections/section_offsets arrays). I don't really like the approach taken by reread_symbols, trying to reset everything manually on the objfile object, instead of, for example, creating a new one from scratch. But I don't know enough yet to propose a better solution. One more reason I think this patch is needed is that the number of sections of the new executable could be different from the number of sections of the old executable. So if we don't re-create the section_offsets array, not only we'll have wrong offsets, but we could make accesses past the array. Something else that silently fails (but doesn't seem to have consequences) is the prologue analysis when we try to create the breakpoint on `main`. Since the `main` symbol has the wrong value 0x555555555129, we try to access memory in that area, which fails. This can be observed by debugging gdb and using `catch throw`. Before the process is started, we need to access the memory at its unrelocated address, 0x1129, which will read memory from the ELF file. This is now what happens, with this patch applied. It silently fails, probably because commit 46a62268b, "Catch exceptions thrown from gdbarch_skip_prologue", papered over the problem and added an empty catch clause. I'm quite sure that the root cause then was the one fixed by this patch. This fixes tests gdb.ada/exec_changed.exp and gdb.base/reread.exp for me. gdb/ChangeLog: * symfile.c (reread_symbols): Clear objfile's section_offsets vector and section indices, re-compute them by calling sym_offsets.
2020-05-20[PATCH v2 0/9] RISC-V: Support version controling for ISA standard ↵Nelson Chu2-4/+4
extensions and CSR 1. Remove the -mriscv-isa-version and --with-riscv-isa-version options. We can still use -march to choose the version for each extensions, so there is no need to add these. 2. Change the arguments of options from [1p9|1p9p1|...] to [1.9|1.9.1|...]. Unlike the architecture string has specified by spec, ther is no need to do the same thing for options. 3. Spilt the patches to reduce the burdens of review. [PATCH 3/7] RISC-V: Support new GAS options and configure options to set ISA versions to [PATCH v2 3/9] RISC-V: Support GAS option -misa-spec to set ISA versions [PATCH v2 4/9] RISC-V: Support configure options to set ISA versions by default. [PATCH 4/7] RISC-V: Support version checking for CSR according to privilege version. to [PATCH v2 5/9] RISC-V: Support version checking for CSR according to privilege spec version. [PATCH v2 6/9] RISC-V: Support configure option to choose the privilege spec version. 4. Use enum class rather than string to compare the choosen ISA spec in opcodes/riscv-opc.c. The behavior is same as comparing the choosen privilege spec. include * opcode/riscv.h: Include "bfd.h" to support bfd_boolean. (enum riscv_isa_spec_class): New enum class. All supported ISA spec belong to one of the class (struct riscv_ext_version): New structure holds version information for the specific ISA. * opcode/riscv-opc.h (DECLARE_CSR): There are two version information, define_version and abort_version. The define_version means which privilege spec is started to define the CSR, and the abort_version means which privilege spec is started to abort the CSR. If the CSR is valid for the newest spec, then the abort_version should be PRIV_SPEC_CLASS_DRAFT. (DECLARE_CSR_ALIAS): Same as DECLARE_CSR, but only for the obselete CSR. * opcode/riscv.h (enum riscv_priv_spec_class): New enum class. Define the current supported privilege spec versions. (struct riscv_csr_extra): Add new fields to store more information about the CSR. We use these information to find the suitable CSR address when user choosing a specific privilege spec. binutils * dwarf.c: Updated since DECLARE_CSR is changed. opcodes * riscv-opc.c (riscv_ext_version_table): The table used to store all information about the supported spec and the corresponding ISA versions. Currently, only Zicsr is supported to verify the correctness of Z sub extension settings. Others will be supported in the future patches. (struct isa_spec_t, isa_specs): List for all supported ISA spec classes and the corresponding strings. (riscv_get_isa_spec_class): New function. Get the corresponding ISA spec class by giving a ISA spec string. * riscv-opc.c (struct priv_spec_t): New structure. (struct priv_spec_t priv_specs): List for all supported privilege spec classes and the corresponding strings. (riscv_get_priv_spec_class): New function. Get the corresponding privilege spec class by giving a spec string. (riscv_get_priv_spec_name): New function. Get the corresponding privilege spec string by giving a CSR version class. * riscv-dis.c: Updated since DECLARE_CSR is changed. * riscv-dis.c: Add new disassembler option -Mpriv-spec to dump the CSR according to the chosen version. Build a hash table riscv_csr_hash to store the valid CSR for the chosen pirv verison. Dump the direct CSR address rather than it's name if it is invalid. (parse_riscv_dis_option_without_args): New function. Parse the options without arguments. (parse_riscv_dis_option): Call parse_riscv_dis_option_without_args to parse the options without arguments first, and then handle the options with arguments. Add the new option -Mpriv-spec, which has argument. * riscv-dis.c (print_riscv_disassembler_options): Add description about the new OBJDUMP option. ld * testsuite/ld-riscv-elf/attr-merge-arch-01.d: Updated priv attributes according to the -mpriv-spec option. * testsuite/ld-riscv-elf/attr-merge-arch-02.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-arch-03.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-priv-spec-a.s: Likewise. * testsuite/ld-riscv-elf/attr-merge-priv-spec-b.s: Likewise. * testsuite/ld-riscv-elf/attr-merge-priv-spec.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-stack-align.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-strict-align-01.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-strict-align-02.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-strict-align-03.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-strict-align-04.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-strict-align-05.d: Likewise. bfd * elfxx-riscv.h (riscv_parse_subset_t): Add new callback function get_default_version. It is used to find the default version for the specific extension. * elfxx-riscv.c (riscv_parsing_subset_version): Remove the parameters default_major_version and default_minor_version. Add new bfd_boolean parameter *use_default_version. Set it to TRUE if we need to call the callback rps->get_default_version to find the default version. (riscv_parse_std_ext): Call rps->get_default_version if we fail to find the default version in riscv_parsing_subset_version, and then call riscv_add_subset to add the subset into subset list. (riscv_parse_prefixed_ext): Likewise. (riscv_std_z_ext_strtab): Support Zicsr extensions. * elfnn-riscv.c (riscv_merge_std_ext): Use strcasecmp to compare the strings rather than characters. riscv_merge_arch_attr_info): The callback function get_default_version is only needed for assembler, so set it to NULL int the linker. * elfxx-riscv.c (riscv_estimate_digit): Remove the static. * elfxx-riscv.h: Updated. gas * testsuite/gas/riscv/priv-reg-fail-read-only-01.s: Updated. * config/tc-riscv.c (default_arch_with_ext, default_isa_spec): Static variables which are used to set the ISA extensions. You can use -march (or ELF build attributes) and -misa-spec to set them, respectively. (ext_version_hash): The hash table used to handle the extensions with versions. (init_ext_version_hash): Initialize the ext_version_hash according to riscv_ext_version_table. (riscv_get_default_ext_version): The callback function of riscv_parse_subset_t. According to the choosed ISA spec, get the default version for the specific extension. (riscv_set_arch): Set the callback function. (enum options, struct option md_longopts): Add new option -misa-spec. (md_parse_option): Do not call riscv_set_arch for -march. We will call it later in riscv_after_parse_args. Call riscv_get_isa_spec_class to set default_isa_spec class. (riscv_after_parse_args): Call init_ext_version_hash to initialize the ext_version_hash, and then call riscv_set_arch to set the architecture with versions according to default_arch_with_ext. * testsuite/gas/riscv/attribute-02.d: Set 0p0 as default version for x extensions. * testsuite/gas/riscv/attribute-03.d: Likewise. * testsuite/gas/riscv/attribute-09.d: New testcase. For i-ext, we already set it's version to 2p1 by march, so no need to use the default 2p2 version. For m-ext, we do not set the version by -march and ELF arch attribute, so set the default 2p0 to it. For zicsr, it is not defined in ISA spec 2p2, so set 0p0 to it. * testsuite/gas/riscv/attribute-10.d: New testcase. The version of zicsr is 2p0 according to ISA spec 20191213. * config/tc-riscv.c (DEFAULT_RISCV_ARCH_WITH_EXT) (DEFAULT_RISCV_ISA_SPEC): Default configure option settings. You can set them by configure options --with-arch and --with-isa-spec, respectively. (riscv_set_default_isa_spec): New function used to set the default ISA spec. (md_parse_option): Call riscv_set_default_isa_spec rather than call riscv_get_isa_spec_class directly. (riscv_after_parse_args): If the -isa-spec is not set, then we set the default ISA spec according to DEFAULT_RISCV_ISA_SPEC by calling riscv_set_default_isa_spec. * testsuite/gas/riscv/attribute-01.d: Add -misa-spec=2.2, since the --with-isa-spec may be set to different ISA spec. * testsuite/gas/riscv/attribute-02.d: Likewise. * testsuite/gas/riscv/attribute-03.d: Likewise. * testsuite/gas/riscv/attribute-04.d: Likewise. * testsuite/gas/riscv/attribute-05.d: Likewise. * testsuite/gas/riscv/attribute-06.d: Likewise. * testsuite/gas/riscv/attribute-07.d: Likewise. * configure.ac: Add configure options, --with-arch and --with-isa-spec. * configure: Regenerated. * config.in: Regenerated. * config/tc-riscv.c (default_priv_spec): Static variable which is used to check if the CSR is valid for the chosen privilege spec. You can use -mpriv-spec to set it. (enum reg_class): We now get the CSR address from csr_extra_hash rather than reg_names_hash. Therefore, move RCLASS_CSR behind RCLASS_MAX. (riscv_init_csr_hashes): Only need to initialize one hash table csr_extra_hash. (riscv_csr_class_check): Change the return type to void. Don't check the ISA dependency if -mcsr-check isn't set. (riscv_csr_version_check): New function. Check and find the CSR address from csr_extra_hash, according to default_priv_spec. Report warning for the invalid CSR if -mcsr-check is set. (reg_csr_lookup_internal): Updated. (reg_lookup_internal): Likewise. (md_begin): Updated since DECLARE_CSR and DECLARE_CSR_ALIAS are changed. (enum options, struct option md_longopts): Add new GAS option -mpriv-spec. (md_parse_option): Call riscv_set_default_priv_version to set default_priv_spec. (riscv_after_parse_args): If -mpriv-spec isn't set, then set the default privilege spec to the newest one. (enum riscv_csr_class, struct riscv_csr_extra): Move them to include/opcode/riscv.h. * testsuite/gas/riscv/priv-reg-fail-fext.d: This test case just want to check the ISA dependency for CSR, so fix the spec version by adding -mpriv-spec=1.11. * testsuite/gas/riscv/priv-reg-fail-fext.l: Likewise. There are some version warnings for the test case. * gas/testsuite/gas/riscv/priv-reg-fail-read-only-01.d: Likewise. * gas/testsuite/gas/riscv/priv-reg-fail-read-only-01.l: Likewise. * gas/testsuite/gas/riscv/priv-reg-fail-read-only-02.d: Likewise. * gas/testsuite/gas/riscv/priv-reg-fail-rv32-only.d: Likewise. * gas/testsuite/gas/riscv/priv-reg-fail-rv32-only.l: Likewise. * gas/testsuite/gas/riscv/priv-reg-fail-version-1p9.d: New test case. Check whether the CSR is valid when privilege version 1.9 is choosed. * gas/testsuite/gas/riscv/priv-reg-fail-version-1p9.l: Likewise. * gas/testsuite/gas/riscv/priv-reg-fail-version-1p9p1.d: New test case. Check whether the CSR is valid when privilege version 1.9.1 is choosed. * gas/testsuite/gas/riscv/priv-reg-fail-version-1p9p1.l: Likewise. * gas/testsuite/gas/riscv/priv-reg-fail-version-1p10.d: New test case. Check whether the CSR is valid when privilege version 1.10 is choosed. * gas/testsuite/gas/riscv/priv-reg-fail-version-1p10.l: Likewise. * gas/testsuite/gas/riscv/priv-reg-fail-version-1p11.d: New test case. Check whether the CSR is valid when privilege version 1.11 is choosed. * gas/testsuite/gas/riscv/priv-reg-fail-version-1p11.l: Likewise. * config/tc-riscv.c (DEFAULT_RISCV_ISA_SPEC): Default configure option setting. You can set it by configure option --with-priv-spec. (riscv_set_default_priv_spec): New function used to set the default privilege spec. (md_parse_option): Call riscv_set_default_priv_spec rather than call riscv_get_priv_spec_class directly. (riscv_after_parse_args): If -mpriv-spec isn't set, then we set the default privilege spec according to DEFAULT_RISCV_PRIV_SPEC by calling riscv_set_default_priv_spec. * testsuite/gas/riscv/csr-dw-regnums.d: Add -mpriv-spec=1.11, since the --with-priv-spec may be set to different privilege spec. * testsuite/gas/riscv/priv-reg.d: Likewise. * configure.ac: Add configure option --with-priv-spec. * configure: Regenerated. * config.in: Regenerated. * config/tc-riscv.c (explicit_attr): Rename explicit_arch_attr to explicit_attr. Set it to TRUE if any ELF attribute is found. (riscv_set_default_priv_spec): Try to set the default_priv_spec if the priv attributes are set. (md_assemble): Set the default_priv_spec according to the priv attributes when we start to assemble instruction. (riscv_write_out_attrs): Rename riscv_write_out_arch_attr to riscv_write_out_attrs. Update the arch and priv attributes. If we don't set the corresponding ELF attributes, then try to output the default ones. (riscv_set_public_attributes): If any ELF attribute or -march-attr options is set (explicit_attr is TRUE), then call riscv_write_out_attrs to update the arch and priv attributes. (s_riscv_attribute): Make sure all arch and priv attributes are set before any instruction. * testsuite/gas/riscv/attribute-01.d: Update the priv attributes if any ELF attribute or -march-attr is set. If the priv attributes are not set, then try to update them by the default setting (-mpriv-spec or --with-priv-spec). * testsuite/gas/riscv/attribute-02.d: Likewise. * testsuite/gas/riscv/attribute-03.d: Likewise. * testsuite/gas/riscv/attribute-04.d: Likewise. * testsuite/gas/riscv/attribute-06.d: Likewise. * testsuite/gas/riscv/attribute-07.d: Likewise. * testsuite/gas/riscv/attribute-08.d: Likewise. * testsuite/gas/riscv/attribute-09.d: Likewise. * testsuite/gas/riscv/attribute-10.d: Likewise. * testsuite/gas/riscv/attribute-unknown.d: Likewise. * testsuite/gas/riscv/attribute-05.d: Likewise. Also, the priv spec set by priv attributes must be supported. * testsuite/gas/riscv/attribute-05.s: Likewise. * testsuite/gas/riscv/priv-reg-fail-version-1p9.d: Likewise. Updated priv attributes according to the -mpriv-spec option. * testsuite/gas/riscv/priv-reg-fail-version-1p9p1.d: Likewise. * testsuite/gas/riscv/priv-reg-fail-version-1p10.d: Likewise. * testsuite/gas/riscv/priv-reg-fail-version-1p11.d: Likewise. * testsuite/gas/riscv/priv-reg.d: Removed. * testsuite/gas/riscv/priv-reg-version-1p9.d: New test case. Dump the CSR according to the priv spec 1.9. * testsuite/gas/riscv/priv-reg-version-1p9p1.d: New test case. Dump the CSR according to the priv spec 1.9.1. * testsuite/gas/riscv/priv-reg-version-1p10.d: New test case. Dump the CSR according to the priv spec 1.10. * testsuite/gas/riscv/priv-reg-version-1p11.d: New test case. Dump the CSR according to the priv spec 1.11. * config/tc-riscv.c (md_show_usage): Add descriptions about the new GAS options. * doc/c-riscv.texi: Likewise.
2020-05-20gdb/testsuite: check mmap ret val against MAP_FAILEDSimon Marchi5-3/+19
Fixup a few spots in the testsuite that use mmap to consistently check the return value against MAP_FAILED. One spot in gdb.base/coredump-filter.c checked against NULL, that is wrong. The other spots either didn't check, or checked against -1. MAP_FAILED has the value -1, at least on Linux, but it's better to check against the documented define. gdb/testsuite/ChangeLog: PR gdb/26016 * gdb.base/coredump-filter.c (do_mmap): Check mmap ret val against MAP_FAILED. * gdb.base/coremaker.c (mmapdata): Likewise. * gdb.base/jit-reader-host.c (main): Likewise. * gdb.base/sym-file-loader.c (load): Likewise. (load_shlib): Likewise.
2020-05-20Fix array_char_idx.expTom Tromey2-1/+7
Newer versions of GCC can statically initialize an array in the array_char_idx.exp test case. This leads to a spurious failure. This patch fixes the problem by having the test case recognize both possible results. I'm checking this in. gdb/testsuite/ChangeLog 2020-05-20 Tom Tromey <tromey@adacore.com> * gdb.ada/array_char_idx.exp: Recognize initialized array.
2020-05-20Remove bound_name static from ada-lang.cTom Tromey2-14/+14
ada-lang.c has a "bound_name" static that is used when finding fields in a structure in some cases. This patch removes it in favor of computing the desired field name at runtime; this avoids an artificial limit. I'm checking this in. Tested on x86-64 Fedora 30, and also on the internal AdaCore test suite. gdb/ChangeLog 2020-05-20 Tom Tromey <tromey@adacore.com> * ada-lang.c (bound_name, MAX_ADA_DIMENS): Remove. (desc_one_bound, desc_index_type): Compute field name.