aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2read.c
AgeCommit message (Collapse)AuthorFilesLines
2017-08-24DWARF-5 Fix DW_FORM_implicit_constJan Kratochvil1-1/+11
-gdwarf-4: ptype logical type = const char [2] (gdb) PASS: gdb.base/constvars.exp: ptype logical -gdwarf-5: ptype logical type = const char [] (gdb) FAIL: gdb.base/constvars.exp: ptype logical <2><2fc>: Abbrev Number: 1 (DW_TAG_variable) <2fd> DW_AT_name : (indirect string, offset: 0x2eb): logical <301> DW_AT_decl_file : 1 1 DW_TAG_variable [no children] DW_AT_name DW_FORM_strp DW_AT_decl_file DW_FORM_implicit_const: 1 During symbol reading, invalid attribute class or form for 'DW_FORM_implicit_const' in '(null)'. gdb/ChangeLog 2017-08-24 Jan Kratochvil <jan.kratochvil@redhat.com> PR symtab/22003 * dwarf2read.c (dwarf2_const_value_attr, dump_die_shallow) (dwarf2_get_attr_constant_value, dwarf2_fetch_constant_bytes) (skip_form_bytes, attr_form_is_constant): Handle DW_FORM_implicit_const.
2017-08-24DWARF-5: Fix -fdebug-types-sectionJan Kratochvil1-17/+40
GDB was now accessing as signatured_type memory allocated only by size of dwarf2_per_cu_data. gdb/ChangeLog 2017-08-24 Jan Kratochvil <jan.kratochvil@redhat.com> * dwarf2read.c (build_type_psymtabs_reader): New prototype. (process_psymtab_comp_unit): Accept IS_DEBUG_TYPES. (read_comp_units_from_section): New parameter abbrev_section, use read_and_check_comp_unit_head, allocate signatured_type if needed. (create_all_comp_units): Update read_comp_units_from_section caller.
2017-08-22Change gdb_realpath to return a unique_xmalloc_ptrTom Tromey1-8/+6
This changes gdb_realpath to return a unique_xmalloc_ptr and fixes up the callers. This allows removing some cleanups. This change by itself caused xfullpath.exp to fail; and attempting to fix that ran into various problems (like .get() being optimized out); so this patch also rewrites xfullpath.exp to be a C++ selftest instead. ChangeLog 2017-08-22 Tom Tromey <tom@tromey.com> * exec.c (exec_file_attach): Update. * linux-thread-db.c (try_thread_db_load): Update. * guile/scm-safe-call.c (gdbscm_safe_source_script): Update. * utils.c (gdb_realpath): Change return type. (gdb_realpath_keepfile): Update. (gdb_realpath_check_trailer, gdb_realpath_tests): New functions. (_initialize_utils): Register the new self test. * source.c (openp): Update. (find_and_open_source): Update. * nto-tdep.c (nto_find_and_open_solib): Update. * main.c (set_gdb_data_directory): Update. (captured_main_1): Update. * dwarf2read.c (dwarf2_get_dwz_file): Update (dw2_map_symbol_filenames): Update. * auto-load.c (auto_load_safe_path_vec_update): Update. (filename_is_in_auto_load_safe_path_vec): Change type of "filename_realp". (auto_load_objfile_script): Update. (file_is_auto_load_safe): Update. Use std::string. * utils.h (gdb_realpath): Return a gdb::unique_xmalloc_ptr. testsuite/ChangeLog 2017-08-22 Tom Tromey <tom@tromey.com> * gdb.gdb/xfullpath.exp: Remove.
2017-08-17Plug line_header leaksPedro Alves1-33/+56
This plugs a couple leaks introduced by commit fff8551cf549 ("dwarf2read.c: Some C++fycation, use std::vector, std::unique_ptr"). The first problem is that nothing owns the temporary line_header that handle_DW_AT_stmt_list creates in some cases. Before the commit mentioned above, the temporary line_header case used to have: make_cleanup (free_cu_line_header, cu); and that cleanup was assumed to be run by process_die, after handle_DW_AT_stmt_list returns and before child DIEs were processed. The second problem is found in setup_type_unit_groups: that also used to have a similar make_cleanup call, and ended up with a similar leak after the commit mentioned above. Fix both cases by recording in dwarf2_cu whether a line header is owned by the cu/die, and have process_die explicitly free the line_header if so, making use of a new RAII object that also replaces the reset_die_in_process cleanup, while at it. Thanks to Philippe Waroquiers for noticing the leak and pointing in the right direction. gdb/ChangeLog: 2017-08-17 Pedro Alves <palves@redhat.com> * dwarf2read.c (struct dwarf2_cu) <line_header_die_owner>: New field. (reset_die_in_process): Delete, replaced by ... (process_die_scope): ... this new class. Make it responsible for freeing cu->line_header too. (process_die): Use process_die_scope. (handle_DW_AT_stmt_list): Record the line header's owner CU/DIE in cu->line_header_die_owner. Don't release the line header if it's owned by the CU. (setup_type_unit_groups): Make the CU/DIE own the line header. Don't release the line header here.
2017-08-09gdb: Fix build failure with GCC 7H.J. Lu1-1/+2
Fix: /export/gnu/import/git/sources/binutils-gdb/gdb/dwarf2read.c: In function ‘const char* dwarf2_string_attr(die_info*, unsigned int, dwarf2_cu*)’: /export/gnu/import/git/sources/binutils-gdb/gdb/dwarf2read.c:17626:39: error: enum constant in boolean context [-Werror=int-in-bool-context] || attr->form == DW_FORM_string || DW_FORM_GNU_str_index * dwarf2read.c (dwarf2_string_attr): Fix a typo.
2017-08-07Fix dwarf2_string_attr for -gsplit-dwarfLeszek Swirski1-1/+2
The dwarf2_string_attr did not allow DW_FORM_GNU_str_index as a form for string types. This manifested as null strings in the namespace_name lookup (replaced with "(anonymous namespace)") when debugging Fission-compiled code. gdb/ChangeLog: * dwarf2read.c (dwarf2_string_attr): Allow DW_FORM_GNU_strp_alt.
2017-08-03Introduce and use gdb_file_upTom Tromey1-16/+2
This introduces gdb_file_up, a unique pointer holding a FILE*, and then changes some code in gdb to use it. In particular gdb_fopen_cloexec now returns a gdb_file_up. This allow removing some cleanups. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * xml-support.c (xml_fetch_content_from_file): Update. * ui-file.c (stdio_file::open): Update. * tracefile-tfile.c (tfile_start): Update. * remote.c (remote_file_put, remote_file_get): Update. * nat/linux-procfs.c (linux_proc_get_int) (linux_proc_pid_get_state, linux_proc_tid_get_name): Update. * nat/linux-osdata.c (linux_common_core_of_thread): Update. (command_from_pid, commandline_from_pid, linux_xfer_osdata_cpus) (print_sockets, linux_xfer_osdata_shm, linux_xfer_osdata_sem) (linux_xfer_osdata_msg, linux_xfer_osdata_modules): Update. * nat/linux-btrace.c (linux_determine_kernel_start): Update. * linux-nat.c (linux_proc_pending_signals): Update. * dwarf2read.c (write_psymtabs_to_index): Use gdb_file_up. (file_closer): Remove. * compile/compile.c (compile_to_object): Update. * common/filestuff.h (struct gdb_file_deleter): New. (gdb_file_up): New typedef. (gdb_fopen_cloexec): Change return type. * common/filestuff.c (gdb_fopen_cloexec): Return gdb_file_up. * cli/cli-dump.c (fopen_with_cleanup): Remove. (dump_binary_file, restore_binary_file): Update. * auto-load.c (auto_load_objfile_script_1): Update.
2017-07-20Use SYMBOL_MATCHES_SEARCH_NAME some morePedro Alves1-2/+2
gdb/ChangeLog: 2017-07-20 Pedro Alves <palves@redhat.com> * dwarf2read.c (dw2_lookup_symbol): Use SYMBOL_MATCHES_SEARCH_NAME. * psymtab.c (psym_lookup_symbol): Use SYMBOL_MATCHES_SEARCH_NAME.
2017-07-18Fix Fission (broken by my previous patch)David Blaikie1-0/+1
Turns out somewhere along the refactoring of the multiple-CU support for Fission I broke the patch before submitting it (& seems to have broken Fission support generally). Syncing back to the point at which the patch was committed, the previous test results on my machine are: expected passes: 36137 unexpected failures: 416 with the previous (broken) patch committed: expected passes: 36131 unexpected failures: 429 With this one line patch applied on top of the broken commit: expected passes: 36144 unexpected failures: 416 (& all other result counts remained the same in all 3 cases) gdb/ChangeLog: 2017-07-18 David Blaikie <dblaikie@gmail.com> * dwarf2read.c (create_cus_hash_table): Re-add lost initialization of dwo_cu's dwo_file.
2017-07-17Fix TAB-completion + .gdb_index slowness (generalize filename_seen_cache)Pedro Alves1-45/+60
Tab completion when debugging a program binary that uses GDB index is surprisingly much slower than when GDB uses psymtabs instead. Around 1.5x/3x slower. That's surprising, because the whole point of GDB index is to speed things up... For example, with: set pagination off set $count = 0 while $count < 400 complete b string_prin # matches gdb's string_printf printf "count = %d\n", $count set $count = $count + 1 end $ time ./gdb --batch -q ./gdb-with-index -ex "source script.cmd" real 0m11.042s user 0m10.920s sys 0m0.042s $ time ./gdb --batch -q ./gdb-without-index -ex "source script.cmd" real 0m4.635s user 0m4.590s sys 0m0.037s Same but with: - complete b string_prin + complete b zzzzzz to exercise the no-matches worst case, master currently gets you something like: with index without index real 0m11.971s 0m8.413s user 0m11.912s 0m8.355s sys 0m0.035s 0m0.035s Running gdb under perf shows 80% spent inside maybe_add_partial_symtab_filename, and 20% spent in the lbasename inside that. The problem that tab completion walks over all compunit symtabs, and for each, walks the contained file symtabs. And there a huge number of file symtabs (each included system header, etc.) that appear in each compunit symtab's file symtab list. As in, when debugging GDB, I have 367381 symtabs iterated, when of those only 5371 filenames are unique... This was a regression from the earlier (nice) split of symtabs in compunit symtabs + file symtabs. The fix here is to add a cache of unique filenames per objfile so that the walk / uniquing is only done once. There's already a abstraction for this in symtab.c; this patch moves that code out to a separate file and C++ifies it bit. This makes the worst-case scenario above consistently drop to ~2.5s (1.5s for the "string_prin" hit case), making it over 3.3x times faster than psymtabs in this use case (7x in the "string_prin" hit case). gdb/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * Makefile.in (COMMON_OBS): Add filename-seen-cache.o. * dwarf2read.c: Include "filename-seen-cache.h". * dwarf2read.c (dwarf2_per_objfile) <filenames_cache>: New field. (dw2_map_symbol_filenames): Build and use a filenames_seen_cache. * filename-seen-cache.c: New file. * filename-seen-cache.h: New file. * symtab.c: Include "filename-seen-cache.h". (struct filename_seen_cache, INITIAL_FILENAME_SEEN_CACHE_SIZE) (create_filename_seen_cache, clear_filename_seen_cache) (delete_filename_seen_cache, filename_seen): Delete, parts moved to filename-seen-cache.h/filename-seen-cache.c. (output_source_filename, sources_info) (maybe_add_partial_symtab_filename) (make_source_files_completion_list): Adjust to use filename_seen_cache.
2017-07-17C++ify dwarf2_per_objfilePedro Alves1-133/+164
This makes dwarf2_per_objfile a class with cdtors. A following patch will add a non-trivial field to struct dwarf2_per_objfile, making dwarf2_per_objfile itself non-trivial. Since dwarf2_per_objfile is allocated in an obstack, we need to run its cdtors manually. Tested on x86-64 GNU/Linux. gdb/ChangeLog: 2017-07-17 Pedro Alves <palves@redhat.com> * dwarf2read.c (dwarf2_per_objfile): In-class initialize all fields. (dwarf2_per_objfile::dwarf2_per_objfile(objfile*, const dwarf2_debug_sections*)): New. (dwarf2_per_objfile::dwarf2_per_objfile(const dwarf2_per_objfile&)): Declare as deleted. (dwarf2_per_objfile::operator=): Declare as deleted. (dwarf2_per_objfile::dwarf2_per_objfile) (dwarf2_per_objfile::~dwarf2_per_objfile) (dwarf2_per_objfile::free_cached_comp_units): New. (dwarf2_has_info): dwarf2_per_objfile initialization code moved to ctor. Call dwarf2_per_objfile's ctor manually. (dwarf2_locate_sections): Deleted/refactored as ... (dwarf2_per_objfile::locate_sections): ... this new method. (free_cached_comp_units): Defer to dwarf2_per_objfile::free_cached_comp_units. (dwarf2_free_objfile): Call dwarf2_per_objfile's dtor manually.
2017-07-06Fission support for multiple CUs per DWO fileDavid Blaikie1-47/+53
In some cases a compiler may produce a single object file (& thus single DWO file) representing multiple source files. The most common example of this is in whole program optimization (such as LLVM's LTO). Fission may still be a beneficial feature to use here - to avoid the need to read/link the debug info with system libraries and the like. This change adds basic support for multiple CUs in a single DWO file to support LLVM's output in this situation. There is still outstanding work to design and implement a solution for cross-CU references (usually using DW_FORM_ref_addr) in this scenario. For now LLVM works around this by duplicating DIEs rather than making cross-CU references in DWO files. This degrades debugger behavior/quality especially for file-local entities. 2017-07-06 David Blaikie <dblaikie@gmail.com> * dwarf2read.c (struct dwo_file): Use a htab of dwo_unit* (rather than a singular dwo_unit*) to support multiple CUs in the same way that multiple TUs are supported. (create_cus_hash_table): Replace create_dwo_cu with a function for parsing multiple CUs from a DWO file. (open_and_init_dwo_file): Use create_cus_hash_table rather than create_dwo_cu. (lookup_dwo_cutu): Lookup CU in the hash table in the dwo_file with htab_find, rather than comparing the signature to a singleton CU in the dwo_file. 2017-07-06 David Blaikie <dblaikie@gmail.com> * gdb.dwarf2/fission-multi-cu.S: Test containing multiple CUs in a DWO, built from fissiont-multi-cu{1,2}.c. * gdb.dwarf2/fission-multi-cu.exp: Test similar to fission-base.exp, except putting 'main' and 'func' in separate CUs in the same DWO file. * gdb.dwarf2/fission-multi-cu1.c: First CU for the multi-CU-single-DWO test. * gdb.dwarf2/fission-multi-cu2.c: Second CU in the multi-CU-single-DWO test.
2017-06-27Eliminate make_cleanup_obstack_free, introduce auto_obstackPedro Alves1-14/+4
This commit eliminates make_cleanup_obstack_free, replacing it with a new auto_obstack type that inherits obstack to add cdtors. These changes in the parsers may not be obvious: - obstack_init (&name_obstack); - make_cleanup_obstack_free (&name_obstack); + name_obstack.clear (); Here, the 'name_obstack' variable is a global. The change means that the obstack's contents from a previous parse will stay around until the next parsing starts. I.e., memory won't be reclaimed until then. I don't think that's a problem, these objects don't really grow much at all. The other option I tried was to add a separate type that is like auto_obstack but manages an external obstack, just for those cases. I like the current approach better as that other approach adds more boilerplate and yet another type to learn. gdb/ChangeLog: 2017-06-27 Pedro Alves <palves@redhat.com> * c-exp.y (name_obstack): Now an auto_obstack. (yylex): Use auto_obstack::clear. (c_parse): Use auto_obstack::clear instead of reinitializing and freeing the obstack. * c-lang.c (evaluate_subexp_c): Use auto_obstack. * d-exp.y (name_obstack): Now an auto_obstack. (yylex): Use auto_obstack::clear. (d_parse): Use auto_obstack::clear instead of reinitializing and freeing the obstack. * dwarf2loc.c (fetch_const_value_from_synthetic_pointer): Use auto_obstack. * dwarf2read.c (create_addrmap_from_index) (dwarf2_build_psymtabs_hard) (update_enumeration_type_from_children): Likewise. * gdb_obstack.h (auto_obstack): New type. * go-exp.y (name_obstack): Now an auto_obstack. (build_packaged_name): Use auto_obstack::clear. (go_parse): Use auto_obstack::clear instead of reinitializing and freeing the obstack. * linux-tdep.c (linux_make_mappings_corefile_notes): Use auto_obstack. * printcmd.c (printf_wide_c_string, ui_printf): Use auto_obstack. * rust-exp.y (work_obstack): Now an auto_obstack. (rust_parse, rust_lex_tests): Use auto_obstack::clear instead of reinitializing and freeing the obstack. * utils.c (do_obstack_free, make_cleanup_obstack_free): Delete. (host_char_to_target): Use auto_obstack. * utils.h (make_cleanup_obstack_free): Delete declaration. * valprint.c (generic_emit_char, generic_printstr): Use auto_obstack.
2017-06-19.gdb_index writer: close the file before unlinking itPedro Alves1-1/+5
We should close the file before unlinking because on MS-Windows one cannot delete a file that is still open. I considered making 'gdb::unlinker::unlinker(const char *)' 'noexcept(true)' and then adding static_assert (noexcept (gdb::unlinker (filename.c_str ())), ""); but that doesn't really work because gdb::unlinker has a gdb_assert, which can throw a QUIT if/when the assertion fails. 'noexcept(true)' would cause GDB to abruptly terminate if/when the assertion fails. gdb/ChangeLog: 2017-06-19 Pedro Alves <palves@redhat.com> * dwarf2read.c (write_psymtabs_to_index): Construct file_closer after gdb::unlinker.
2017-06-14Introduce gdb::byte_vector, add allocator that default-initializesPedro Alves1-1/+2
In some cases we've been replacing heap-allocated gdb_byte buffers managed with xmalloc/make_cleanup(xfree) with gdb::vector<gdb_byte>. That usually pessimizes the code a little bit because std::vector value-initializes elements (which for gdb_byte means zero-initialization), while if you're creating a temporary buffer, you're most certaintly going to fill it in with some data. An alternative is to use unique_ptr<gdb_byte[]> buf (new gdb_byte[size]); but it looks like that's not very popular. Recently, a use of obstacks in dwarf2read.c was replaced with std::vector<gdb_byte> and that as well introduced a pessimization for always memsetting the buffer when it's garanteed that the zeros will be overwritten immediately. (see dwarf2read.c change in this patch to find it.) So here's a different take at addressing this issue "by design": #1 - Introduce default_init_allocator<T> I.e., a custom allocator that does default construction using default initialization, meaning, no more zero initialization. That's the default_init_allocation<T> class added in this patch. See "Notes" at <http://en.cppreference.com/w/cpp/container/vector/resize>. #2 - Introduce def_vector<T> I.e., a convenience typedef, because typing the allocator is annoying: using def_vector<T> = std::vector<T, gdb::default_init_allocator<T>>; #3 - Introduce byte_vector Because gdb_byte vectors will be the common thing, add a convenience "byte_vector" typedef: using byte_vector = def_vector<gdb_byte>; which is really the same as: std::vector<gdb_byte, gdb::default_init_allocator<gdb_byte>>; The intent then is to make "gdb::byte_vector" be the go-to for dynamic byte buffers. So the less friction, the better. #4 - Adjust current code to use it. To set the example going forward. Replace std::vector uses and also unique_ptr<byte[]> uses. One nice thing is that with this allocator, for changes like these: -std::unique_ptr<byte[]> buf (new gdb_byte[some_size]); +gdb::byte_vector buf (some_size); fill_with_data (buf.data (), buf.size ()); the generated code is the same as before. I.e., the compiler de-structures the vector and gets rid of the unused "reserved vs size" related fields. The other nice thing is that it's easier to write gdb::byte_vector buf (size); than std::unique_ptr<gdb_byte[]> buf (new gdb_byte[size]); or even (C++14): auto buf = std::make_unique<gdb_byte[]> (size); // zero-initializes... #5 - Suggest s/std::vector<gdb_byte>/gdb::byte_vector/ going forward. Note that this commit actually fixes a couple of bugs where the current code is incorrectly using "std::vector::reserve(new_size)" and then accessing the vector's internal buffer beyond the vector's size: see dwarf2loc.c and charset.c. That's undefined behavior and may trigger debug mode assertion failures. With default_init_allocator, "resize()" behaves like "reserve()" performance wise, in that it leaves new elements with unspecified values, but, it does that safely without triggering undefined behavior when you access those values. gdb/ChangeLog: 2017-06-14 Pedro Alves <palves@redhat.com> * ada-lang.c: Include "common/byte-vector.h". (ada_value_primitive_packed_val): Use gdb::byte_vector. * charset.c (wchar_iterator::iterate): Resize the vector instead of reserving it. * common/byte-vector.h: Include "common/def-vector.h". (wchar_iterator::m_out): Now a gdb::def_vector<gdb_wchar_t>. * cli/cli-dump.c: Include "common/byte-vector.h". (dump_memory_to_file, restore_binary_file): Use gdb::byte_vector. * common/byte-vector.h: New file. * common/def-vector.h: New file. * common/default-init-alloc.h: New file. * dwarf2loc.c: Include "common/byte-vector.h". (rw_pieced_value): Use gdb::byte_vector, and resize the vector instead of reserving it. * dwarf2read.c: Include "common/byte-vector.h". (data_buf::m_vec): Now a gdb::byte_vector. * gdb_regex.c: Include "common/def-vector.h". (compiled_regex::compiled_regex): Use gdb::def_vector<char>. * mi/mi-main.c: Include "common/byte-vector.h". (mi_cmd_data_read_memory): Use gdb::byte_vector. * printcmd.c: Include "common/byte-vector.h". (print_scalar_formatted): Use gdb::byte_vector. * valprint.c: Include "common/byte-vector.h". (maybe_negate_by_bytes, print_decimal_chars): Use gdb::byte_vector.
2017-06-12.gdb_index prod perf regression: mapped_symtab now vector of valuesPedro Alves1-28/+28
... instead of vector of pointers There's no real reason for having mapped_symtab::data be a vector of heap-allocated symtab_index_entries. symtab_index_entries is not that large, it's movable, and it's cheap to move. Making the vector hold values instead improves cache locality and eliminates many roundtrips to the heap. Using the same test as in the previous patch, against the same gdb inferior, timing improves ~13% further: ~6.0s => ~5.2s (average of 5 runs). Note that before the .gdb_index C++ifycation patch, we were at ~5.7s. We're now consistenly better than before. gdb/ChangeLog 2017-06-12 Pedro Alves <palves@redhat.com> * dwarf2read.c (mapped_symtab::data): Now a vector of symtab_index_entry instead of vector of std::unique_ptr<symtab_index_entry>. All users adjusted to check whether an element's name is NULL instead of checking whether the element itself is NULL. (find_slot): Change return type. Adjust. (hash_expand, , add_index_entry, uniquify_cu_indices) (write_hash_table): Adjust.
2017-06-12.gdb_index prod perf regression: Estimate size of psyms_seenPedro Alves1-1/+35
Using the same test as the previous patch, perf shows GDB spending over 7% in "free". A substantial number of those calls comes from insertions in the psyms_seen unordered_set causing lots of rehashing and recreating buckets. Fix this by computing an estimate of the size of the set upfront. Using the same test as in the previous patch, against the same gdb inferior, timing improves ~8% further: ~6.5s => ~6.0s (average of 5 runs). gdb/ChangeLog: 2017-06-12 Pedro Alves <palves@redhat.com> * dwarf2read.c (recursively_count_psymbols): New function. (write_psymtabs_to_index): Call it to compute number of psyms and pass estimate size of psyms_seen to unordered_set's ctor.
2017-06-12.gdb_index prod perf regression: find before insert in unordered_mapPedro Alves1-5/+16
"perf" shows the unordered_map::emplace call in write_hash_table a bit high up on profiles. Fix this using the find + insert idiom instead of going straight to insert. I tried doing the same to the other unordered_maps::emplace calls in the file, but saw no performance improvement, so left them be. With a '-g3 -O2' build of gdb, and: $ cat save-index.cmd set $i = 0 while $i < 100 save gdb-index . set $i = $i + 1 end $ time ./gdb -data-directory=data-directory -nx --batch -q -x save-index.cmd ./gdb.pristine I get an improvement of ~7%: ~7.0s => ~6.5s (average of 5 runs). gdb/ChangeLog: 2017-06-12 Pedro Alves <palves@redhat.com> * dwarf2read.c (write_hash_table): Check if key already exists before emplacing.
2017-06-12Code cleanup: dwarf2read.c: Add data_buf::append_uintPedro Alves1-29/+29
This avoids having to specify the integer size twice in the same line. gdb/ChangeLog: 2017-06-12 Pedro Alves <palves@redhat.com> * dwarf2read.c (data_buf::append_space): Rename to... (data_buf::grow): ... this, and make private. Adjust all callers. (data_buf::append_uint): New method. (add_address_entry, write_one_signatured_type) (write_psymtabs_to_index): Use it.
2017-06-12Code cleanup: dwarf2read.c: Eliminate ::file_writePedro Alves1-20/+2
There's no real need for all this indirection. gdb/ChangeLog: 2017-06-12 Pedro Alves <palves@redhat.com> * dwarf2read.c (file_write(FILE *, const void *, size_t)): Delete. (file_write (FILE *, const std::vector<Elem>&)): Delete. (data_buf::file_write): Call ::fwrite directly.
2017-06-12Code cleanup: dwarf2read.c:uniquify_cu_indices: Use std::uniquePedro Alves1-17/+4
gdb/ChangeLog: 2017-06-12 Pedro Alves <palves@redhat.com> * dwarf2read.c (uniquify_cu_indices): Use std::unique and std::vector::erase.
2017-06-12Code cleanup: C++ify .gdb_index producerJan Kratochvil1-434/+275
gdb/ChangeLog 2017-06-12 Jan Kratochvil <jan.kratochvil@redhat.com> Code cleanup: C++ify .gdb_index producer. * dwarf2read.c: Include <unordered_set> and <unordered_map>. (MAYBE_SWAP) [WORDS_BIGENDIAN]: Cast to offset_type. (struct strtab_entry, hash_strtab_entry, eq_strtab_entry) (create_strtab, add_string): Remove. (file_write, data_buf): New. (struct symtab_index_entry): Use std::vector for cu_indices. (struct mapped_symtab): Use std::vector for data. (hash_symtab_entry, eq_symtab_entry, delete_symtab_entry) (create_symbol_hash_table, create_mapped_symtab, cleanup_mapped_symtab): Remove. (find_slot): Change return type. Update it to the new data structures. (hash_expand, add_index_entry): Update it to the new data structures. (offset_type_compare): Remove. (uniquify_cu_indices): Update it to the new data structures. (c_str_view, c_str_view_hasher, vector_hasher): New. (add_indices_to_cpool): Remove. (write_hash_table): Update it to the new data structures. (struct psymtab_cu_index_map, hash_psymtab_cu_index) (eq_psymtab_cu_index): Remove. (psym_index_map): New typedef. (struct addrmap_index_data): Change addr_obstack pointer to data_buf reference and std::unordered_map for cu_index_htab. (add_address_entry, add_address_entry_worker, write_address_map) (write_psymbols): Update it to the new data structures. (write_obstack): Remove. (struct signatured_type_index_data): Change types_list to a data_buf reference and psyms_seen to a std::unordered_set reference. (write_one_signatured_type, recursively_write_psymbols) (write_psymtabs_to_index): Update it to the new data structures.
2017-04-12Change increment_reading_symtab to return a scoped_restoreTom Tromey1-1/+1
This changes increment_reading_symtab to return a scoped_restore, then fixes up the users. gdb/ChangeLog 2017-04-12 Tom Tromey <tom@tromey.com> * symfile.h (increment_reading_symtab): Update type. * symfile.c (decrement_reading_symtab): Remove. (increment_reading_symtab): Return a scoped_restore_tmpl<int>. * psymtab.c (psymtab_to_symtab): Update. * dwarf2read.c (dw2_instantiate_symtab): Update.
2017-04-12Fix PR c++/21323: GDB thinks char16_t and char32_t are signed in C++Pedro Alves1-3/+16
While the C++ standard says that char16_t and char32_t are unsigned types: Types char16_t and char32_t denote distinct types with the same size, signedness, and alignment as uint_least16_t and uint_least32_t, respectively, in <cstdint>, called the underlying types. ... gdb treats them as signed currently: (gdb) p (char16_t)-1 $1 = -1 u'\xffff' There are actually two places in gdb that hardcode these types: - gdbtypes.c:gdbtypes_post_init, when creating the built-in types, seemingly used by the "x /s" command (judging from commit 9a22f0d0). - dwarf2read.c, when reading base types with DW_ATE_UTF encoding (which is what is used for these types, when compiling for C++11 and up). Despite the comment, the type created does end up used. 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. While writting the test, I noticed that the C++ language parser isn't actually aware of these built-in types, so if you try to use them without a program that uses them, you get: (gdb) set language c++ (gdb) ptype char16_t No symbol table is loaded. Use the "file" command. (gdb) ptype u"hello" No type named char16_t. (gdb) p u"hello" No type named char16_t. That's fixed by simply adding a couple entries to C++'s built-in types array in c-lang.c. With that, we get the expected: (gdb) ptype char16_t type = char16_t (gdb) ptype u"hello" type = char16_t [6] (gdb) p u"hello" $1 = u"hello" gdb/ChangeLog: 2017-04-12 Pedro Alves <palves@redhat.com> PR c++/21323 * c-lang.c (cplus_primitive_types) <cplus_primitive_type_char16_t, cplus_primitive_type_char32_t>: New enum values. (cplus_language_arch_info): Register cplus_primitive_type_char16_t and cplus_primitive_type_char32_t. * dwarf2read.c (read_base_type) <DW_ATE_UTF>: If bit size is 16 or 32, use the archtecture's built-in type for char16_t and char32_t, respectively. Otherwise, fallback to init_integer_type as before, but make the type unsigned, and issue a complaint. * gdbtypes.c (gdbtypes_post_init): Make char16_t and char32_t unsigned. gdb/testsuite/ChangeLog: 2017-04-12 Pedro Alves <palves@redhat.com> PR c++/21323 * gdb.cp/wide_char_types.c: New file. * gdb.cp/wide_char_types.exp: New file.
2017-04-05-Wwrite-strings: The RestPedro Alves1-4/+4
This is the remainder boring constification that all looks more of less borderline obvious IMO. gdb/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * ada-exp.y (yyerror): Constify. * ada-lang.c (bound_name, get_selections) (ada_variant_discrim_type) (ada_variant_discrim_name, ada_value_struct_elt) (ada_lookup_struct_elt_type, is_unchecked_variant) (ada_which_variant_applies, standard_exc, ada_get_next_arg) (catch_ada_exception_command_split) (catch_ada_assert_command_split, catch_assert_command) (ada_op_name): Constify. * ada-lang.h (ada_yyerror, get_selections) (ada_variant_discrim_name, ada_value_struct_elt): Constify. * arc-tdep.c (arc_print_frame_cache): Constify. * arm-tdep.c (arm_skip_stub): Constify. * ax-gdb.c (gen_binop, gen_struct_ref_recursive, gen_struct_ref) (gen_aggregate_elt_ref): Constify. * bcache.c (print_bcache_statistics): Constify. * bcache.h (print_bcache_statistics): Constify. * break-catch-throw.c (catch_exception_command_1): * breakpoint.c (struct ep_type_description::description): Constify. (add_solib_catchpoint): Constify. (catch_fork_command_1): Add cast. (add_catch_command): Constify. * breakpoint.h (add_catch_command, add_solib_catchpoint): Constify. * bsd-uthread.c (bsd_uthread_state): Constify. * buildsym.c (patch_subfile_names): Constify. * buildsym.h (next_symbol_text_func, patch_subfile_names): Constify. * c-exp.y (yyerror): Constify. (token::oper): Constify. * c-lang.h (c_yyerror, cp_print_class_member): Constify. * c-varobj.c (cplus_describe_child): Constify. * charset.c (find_charset_names): Add cast. (find_charset_names): Constify array and add const_cast. * cli/cli-cmds.c (complete_command, cd_command): Constify. (edit_command): Constify. * cli/cli-decode.c (lookup_cmd): Constify. * cli/cli-dump.c (dump_memory_command, dump_value_command): Constify. (struct dump_context): Constify. (add_dump_command, restore_command): Constify. * cli/cli-script.c (get_command_line): Constify. * cli/cli-script.h (get_command_line): Constify. * cli/cli-utils.c (check_for_argument): Constify. * cli/cli-utils.h (check_for_argument): Constify. * coff-pe-read.c (struct read_pe_section_data): Constify. * command.h (lookup_cmd): Constify. * common/print-utils.c (decimal2str): Constify. * completer.c (gdb_print_filename): Constify. * corefile.c (set_gnutarget): Constify. * cp-name-parser.y (yyerror): Constify. * cp-valprint.c (cp_print_class_member): Constify. * cris-tdep.c (cris_register_name, crisv32_register_name): Constify. * d-exp.y (yyerror): Constify. (struct token::oper): Constify. * d-lang.h (d_yyerror): Constify. * dbxread.c (struct header_file_location::name): Constify. (add_old_header_file, add_new_header_file, last_function_name) (dbx_next_symbol_text, add_bincl_to_list) (find_corresponding_bincl_psymtab, set_namestring) (find_stab_function_addr, read_dbx_symtab, start_psymtab) (dbx_end_psymtab, read_ofile_symtab, process_one_symbol): * defs.h (command_line_input, print_address_symbolic) (deprecated_readline_begin_hook): Constify. * dwarf2read.c (anonymous_struct_prefix, dwarf_bool_name): Constify. * event-top.c (handle_line_of_input): Constify and add cast. * exceptions.c (catch_errors): Constify. * exceptions.h (catch_errors): Constify. * expprint.c (print_subexp_standard, op_string, op_name) (op_name_standard, dump_raw_expression, dump_raw_expression): * expression.h (op_name, op_string, dump_raw_expression): Constify. * f-exp.y (yyerror): Constify. (struct token::oper): Constify. (struct f77_boolean_val::name): Constify. * f-lang.c (f_word_break_characters): Constify. * f-lang.h (f_yyerror): Constify. * fork-child.c (fork_inferior): Add cast. * frv-tdep.c (struct gdbarch_tdep::register_names): Constify. (new_variant): Constify. * gdbarch.sh (pstring_ptr, pstring_list): Constify. * gdbarch.c: Regenerate. * gdbcore.h (set_gnutarget): Constify. * go-exp.y (yyerror): Constify. (token::oper): Constify. * go-lang.h (go_yyerror): Constify. * go32-nat.c (go32_sysinfo): Constify. * guile/scm-breakpoint.c (gdbscm_breakpoint_expression): Constify. * guile/scm-cmd.c (cmdscm_function): Constify. * guile/scm-param.c (pascm_param_value): Constify. * h8300-tdep.c (h8300_register_name, h8300s_register_name) (h8300sx_register_name): Constify. * hppa-tdep.c (hppa32_register_name, hppa64_register_name): Constify. * ia64-tdep.c (ia64_register_names): Constify. * infcmd.c (construct_inferior_arguments): Constify. (path_command, attach_post_wait): Constify. * language.c (show_range_command, show_case_command) (unk_lang_error): Constify. * language.h (language_defn::la_error) (language_defn::la_name_of_this): Constify. * linespec.c (decode_line_2): Constify. * linux-thread-db.c (thread_db_err_str): Constify. * lm32-tdep.c (lm32_register_name): Constify. * m2-exp.y (yyerror): Constify. * m2-lang.h (m2_yyerror): Constify. * m32r-tdep.c (m32r_register_names): Constify and make static. * m68hc11-tdep.c (m68hc11_register_names): Constify. * m88k-tdep.c (m88k_register_name): Constify. * macroexp.c (appendmem): Constify. * mdebugread.c (fdr_name, add_data_symbol, parse_type) (upgrade_type, parse_external, parse_partial_symbols) (mdebug_next_symbol_text, cross_ref, mylookup_symbol, new_psymtab) (new_symbol): Constify. * memattr.c (mem_info_command): Constify. * mep-tdep.c (register_name_from_keyword): Constify. * mi/mi-cmd-env.c (mi_cmd_env_path, _initialize_mi_cmd_env): Constify. * mi/mi-cmd-stack.c (list_args_or_locals): Constify. * mi/mi-cmd-var.c (mi_cmd_var_show_attributes): Constify. * mi/mi-main.c (captured_mi_execute_command): Constify and add cast. (mi_execute_async_cli_command): Constify. * mips-tdep.c (mips_register_name): Constify. * mn10300-tdep.c (register_name, mn10300_generic_register_name) (am33_register_name, am33_2_register_name) * moxie-tdep.c (moxie_register_names): Constify. * nat/linux-osdata.c (osdata_type): Constify fields. * nto-tdep.c (nto_parse_redirection): Constify. * objc-lang.c (lookup_struct_typedef, lookup_objc_class) (lookup_child_selector): Constify. (objc_methcall::name): Constify. * objc-lang.h (lookup_objc_class, lookup_child_selector) (lookup_struct_typedef): Constify. * objfiles.c (pc_in_section): Constify. * objfiles.h (pc_in_section): Constify. * p-exp.y (struct token::oper): Constify. (yyerror): Constify. * p-lang.h (pascal_yyerror): Constify. * parser-defs.h (op_name_standard): Constify. (op_print::string): Constify. (exp_descriptor::op_name): Constify. * printcmd.c (print_address_symbolic): Constify. * psymtab.c (print_partial_symbols): Constify. * python/py-breakpoint.c (stop_func): Constify. (bppy_get_expression): Constify. * python/py-cmd.c (cmdpy_completer::name): Constify. (cmdpy_function): Constify. * python/py-event.c (evpy_add_attribute) (gdbpy_initialize_event_generic): Constify. * python/py-event.h (evpy_add_attribute) (gdbpy_initialize_event_generic): Constify. * python/py-evts.c (add_new_registry): Constify. * python/py-finishbreakpoint.c (outofscope_func): Constify. * python/py-framefilter.c (get_py_iter_from_func): Constify. * python/py-inferior.c (get_buffer): Add cast. * python/py-param.c (parm_constant::name): Constify. * python/py-unwind.c (fprint_frame_id): Constify. * python/python.c (gdbpy_parameter_value): Constify. * remote-fileio.c (remote_fio_func_map): Make 'name' const. * remote.c (memory_packet_config::name): Constify. (show_packet_config_cmd, remote_write_bytes) (remote_buffer_add_string): * reverse.c (exec_reverse_once): Constify. * rs6000-tdep.c (variant::name, variant::description): Constify. * rust-exp.y (rustyyerror): Constify. * rust-lang.c (rust_op_name): Constify. * rust-lang.h (rustyyerror): Constify. * serial.h (serial_ops::name): Constify. * sh-tdep.c (sh_sh_register_name, sh_sh3_register_name) (sh_sh3e_register_name, sh_sh2e_register_name) (sh_sh2a_register_name, sh_sh2a_nofpu_register_name) (sh_sh_dsp_register_name, sh_sh3_dsp_register_name) (sh_sh4_register_name, sh_sh4_nofpu_register_name) (sh_sh4al_dsp_register_name): Constify. * sh64-tdep.c (sh64_register_name): Constify. * solib-darwin.c (lookup_symbol_from_bfd): Constify. * spu-tdep.c (spu_register_name, info_spu_dma_cmdlist): Constify. * stabsread.c (patch_block_stabs, read_type_number) (ref_map::stabs, ref_add, process_reference) (symbol_reference_defined, define_symbol, define_symbol) (error_type, read_type, read_member_functions, read_cpp_abbrev) (read_one_struct_field, read_struct_fields, read_baseclasses) (read_tilde_fields, read_struct_type, read_array_type) (read_enum_type, read_sun_builtin_type, read_sun_floating_type) (read_huge_number, read_range_type, read_args, common_block_start) (find_name_end): Constify. * stabsread.h (common_block_start, define_symbol) (process_one_symbol, symbol_reference_defined, ref_add): * symfile.c (get_section_index, add_symbol_file_command): * symfile.h (get_section_index): Constify. * target-descriptions.c (tdesc_type::name): Constify. (tdesc_free_type): Add cast. * target.c (find_default_run_target): (add_deprecated_target_alias, find_default_run_target) (target_announce_detach): Constify. (do_option): Constify. * target.h (add_deprecated_target_alias): Constify. * thread.c (print_thread_info_1): Constify. * top.c (deprecated_readline_begin_hook, command_line_input): Constify. (init_main): Add casts. * top.h (handle_line_of_input): Constify. * tracefile-tfile.c (tfile_write_uploaded_tsv): Constify. * tracepoint.c (tvariables_info_1, trace_status_mi): Constify. (tfind_command): Rename to ... (tfind_command_1): ... this and constify. (tfind_command): New function. (tfind_end_command, tfind_start_command): Adjust. (encode_source_string): Constify. * tracepoint.h (encode_source_string): Constify. * tui/tui-data.c (tui_partial_win_by_name): Constify. * tui/tui-data.h (tui_partial_win_by_name): Constify. * tui/tui-source.c (tui_set_source_content_nil): Constify. * tui/tui-source.h (tui_set_source_content_nil): Constify. * tui/tui-win.c (parse_scrolling_args): Constify. * tui/tui-windata.c (tui_erase_data_content): Constify. * tui/tui-windata.h (tui_erase_data_content): Constify. * tui/tui-winsource.c (tui_erase_source_content): Constify. * tui/tui.c (tui_enable): Add cast. * utils.c (defaulted_query): Constify. (init_page_info): Add cast. (puts_debug, subset_compare): Constify. * utils.h (subset_compare): Constify. * varobj.c (varobj_format_string): Constify. * varobj.h (varobj_format_string): Constify. * vax-tdep.c (vax_register_name): Constify. * windows-nat.c (windows_detach): Constify. * xcoffread.c (process_linenos, xcoff_next_symbol_text): Constify. * xml-support.c (gdb_xml_end_element): Constify. * xml-tdesc.c (tdesc_start_reg): Constify. * xstormy16-tdep.c (xstormy16_register_name): Constify. * xtensa-tdep.c (xtensa_find_register_by_name): Constify. * xtensa-tdep.h (xtensa_register_t::name): Constify. gdb/gdbserver/ChangeLog: 2017-04-05 Pedro Alves <palves@redhat.com> * gdbreplay.c (sync_error): Constify. * linux-x86-low.c (push_opcode): Constify.
2017-04-04dwarf2read.c: C++fy lnp_state_machinePedro Alves1-198/+244
While I was looking at the file, I noticed that this struct could be nicely converted to a class. As I was progressing, I ended up moving all state machine actual internal state manipulation to methods of lnp_state_machine, essentially decoupling DWARF parsing from state tracking. I also noticed that the lnp_reader_state doesn't really serve any good use, so that's eliminated in the process. gdb/ChangeLog: 2017-04-04 Pedro Alves <palves@redhat.com> * dwarf2read.c (lnp_state_machine): Now a class. Initialize all data fields, make them private and add "m_" prefixes. (lnp_state_machine::lnp_state_machine): New ctor. (record_line, check_line_address, handle_set_discriminator) (handle_set_address, handle_advance_pc, handle_special_opcode) (handle_advance_line, handle_set_file, handle_negate_stmt) (handle_const_add_pc, handle_fixed_advance_pc, handle_copy) (end_sequence, advance_line): New methods. (m_gdbarch, m_record_lines_p): New fields. (lnp_reader_state): Delete. (dwarf_record_line): Rename to ... (lnp_state_machine::record_line): ... adjust. (init_lnp_state_machine): Delete. (lnp_state_machine::lnp_state_machine): New. (check_line_address): Rename to ... (lnp_state_machine::check_line_address): This. (dwarf_decode_lines_1): Remove reference to "reader_state". Adjust lnp_state_machine having a non-default ctor. Use bool. State machine internal state manipulation moved to lnp_state_machine methods.
2017-04-04Make sect_offset and cu_offset strong typedefs instead of structsPedro Alves1-320/+321
A while ago, back when GDB was a C program, the sect_offset and cu_offset types were made structs in order to prevent incorrect mixing of those offsets. Now that we require C++11, we can make them integers again, while keeping the safety, by exploiting "enum class". We can add a bit more safety, even, by defining operators that the types _should_ support, helping making the suspicious uses stand out more. Getting at the underlying type is done with the new to_underlying function added by the previous patch, which also helps better spot where do we need to step out of the safety net. Mostly, that's around parsing the DWARF, and when we print the offset for complaint/debug purposes. But there are other occasional uses. Since we have to define the sect_offset/cu_offset types in a header anyway, I went ahead and generalized/library-fied the idea of "offset" types, making it trivial to add more such types if we find a use. See common/offset-type.h and the DEFINE_OFFSET_TYPE macro. I needed a couple generaly-useful preprocessor bits (e.g., yet another CONCAT implementation), so I started a new common/preprocessor.h file. I included units tests covering the "offset" types API. These are mostly compile-time tests, using SFINAE to check that expressions that shouldn't compile (e.g., comparing unrelated offset types) really are invalid and would fail to compile. This same idea appeared in my pending enum-flags revamp from a few months ago (though this version is a bit further modernized compared to what I had posted), and I plan on reusing the "check valid expression" bits added here in that series, so I went ahead and defined the CHECK_VALID_EXPR macro in its own header -- common/valid-expr.h. I think that's nicer regardless. I was borderline between calling the new types "offset" types, or "index" types, BTW. I stuck with "offset" simply because that's what we're already calling them, mostly. gdb/ChangeLog: 2017-04-04 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/offset-type-selftests.c. (SUBDIR_UNITTESTS_OBS): Add offset-type-selftests.o. * common/offset-type.h: New file. * common/preprocessor.h: New file. * common/traits.h: New file. * common/valid-expr.h: New file. * dwarf2expr.c: Include "common/underlying.h". Adjust to use sect_offset and cu_offset strong typedefs throughout. * dwarf2expr.h: Adjust to use sect_offset and cu_offset strong typedefs throughout. * dwarf2loc.c: Include "common/underlying.h". Adjust to use sect_offset and cu_offset strong typedefs throughout. * dwarf2read.c: Adjust to use sect_offset and cu_offset strong typedefs throughout. * gdbtypes.h: Include "common/offset-type.h". (cu_offset): Now an offset type (strong typedef) instead of a struct. (sect_offset): Likewise. (union call_site_parameter_u): Rename "param_offset" field to "param_cu_off". * unittests/offset-type-selftests.c: New file.
2017-04-04dwarf2read.c: Make dir_index and file_name_index strong typedefsPedro Alves1-74/+99
This should help catch mistakes related to mixing the 1-based DWARF indexes with 0-based std::vector indexes, since the new types do not implicitly convert to anything. The change in read_formatted_entries relates to the fact that doing the seemingly simpler: - uintp = &fe.dir_index; + uintp = (unsigned int *) &fe.dir_index; would be undefined C/C++. So to address that, I made the function extract the form before assigning to the file_entry. It felt natural to use gdb::optional for "do I have this value", and this is what motivated the previous patch that added the missing observer methods to gdb::optional. gdb/ChangeLog: 2017-04-04 Pedro Alves <palves@redhat.com> * common/underlying.h: New file. * dwarf2read.c: Include "common/gdb_optional.h" and "common/underlying.h". (dir_index, file_name_index): New types. (file_entry): Use them. (file_entry::include): Use to_underlying. (line_header::add_file_name): Use dir_index. (read_formatted_entries): Use gdb::optional. Read form before writting to file_entry. (dwarf_decode_line_header): Use dir_index. (lnp_state_machine::current_file): Use to_underlying. (lnp_state_machine::file): Change type to file_name_index. (dwarf_record_line): Use to_underlying. (init_lnp_state_machine): Use file_name_index. (dwarf_decode_lines_1): Use dir_index and file_name_index.
2017-04-04dwarf2read.c: Some C++fycation, use std::vector, std::unique_ptrPedro Alves1-180/+128
This starts off as replacing a couple custom open coded vector implementations in the file with std::vector, and then the rest falls off of that. I.e., use new/delete instead of XCNEW/xfree, add ctors/dtors/initializers where appropriate. And then use std::unique_ptr instead of cleanups. Some functions became methods, and in a couple spots, some single-use callback functions that would have to be tweaked anyway are converted to lambdas instead. gdb/ChangeLog: 2017-04-04 Pedro Alves <palves@redhat.com> * dwarf2read.c (struct file_entry): Add ctors, and initialize all fields. (line_header): Initialize all data fields. Change type of standard_opcode_lengths to std::unique_ptr<unsigned char[]>. Change type of include_dirs to std::vector<const char *>. Remove num_include_dirs, include_dirs_size. Change type of file_names to std::vector<file_entry>. Remove num_file_names, file_names_size. (line_header::line_header): New. (line_header::add_include_dir, line_header::add_file_name): New methods. (line_header::include_dir_at): Remove NULL check. (line_header::file_name_at): Add const overload. (line_header_up): New unique_ptr typedef. (dw2_get_file_names_reader): Use line_header_up. Adjust to use std::vector. Remove free_line_header call. (dwarf2_build_include_psymtabs): Use line_header_up. Remove free_line_header call. (free_cu_line_header): Delete. (handle_DW_AT_stmt_list, handle_DW_AT_stmt_list) (setup_type_unit_groups): Use line_header_up instead of cleanups. Adjust to use std::vector. (free_line_header): Delete. (free_line_header_voidp): Use delete. (add_include_dir): Replace with ... (line_header::add_include_dir): ... this method. Use std::vector. (add_file_name): Replace with ... (line_header::add_file_name): ... this method. Use std::vector. (add_include_dir_stub): Delete. (read_formatted_entries): Remove memset. (dwarf_decode_line_header): Return a line_header_up instead of a raw pointer. Remove cleanup handling. Pass lambdas to read_formatted_entries. Adjust to use line_header methods. (dwarf_decode_lines_1): Adjust to use line_header methods. (dwarf_decode_lines, file_file_name, file_full_name): Adjust to use std::vector.
2017-03-27dwarf2read.c: Clean up out of bounds handlingPedro Alves1-70/+90
Multiple places in dwarf2read.c open code 1-based to 0-based index conversion and check for out of bounds accesses to lh->include_dirs and lh->file_names. This commit factors those out to a couple methods and uses them throughout. gdb/ChangeLog: 2017-03-27 Pedro Alves <palves@redhat.com> * dwarf2read.c (file_entry) <dir_index>: Add comment. (file_entry::include_dir): New method. (line_header::include_dir_at, line_header::file_name_at): New methods. (setup_type_unit_groups, setup_type_unit_groups) (psymtab_include_file_name): Simplify using the new methods. (lnp_state_machine) <the_line_header>: New field. <file>: Add comment. (lnp_state_machine::current_file): New method. (dwarf_record_line): Simplify using the new methods. (init_lnp_state_machine): Initialize the "the_line_header" field. (dwarf_decode_lines_1, dwarf_decode_lines, file_file_name): Simplify using the new methods.
2017-03-27gdb: Make ldirname return a std::stringPedro Alves1-56/+61
Eliminates several uses of cleanups. Tested on x86_64 Fedora 23 with Python 2 and 3. gdb/ChangeLog 2017-03-27 Pedro Alves <palves@redhat.com> * dwarf2read.c (struct file_and_directory): New. (dwarf2_get_dwz_file): Adjust to use std::string. (dw2_get_file_names_reader): Adjust to use file_and_directory. (find_file_and_directory): Adjust to return a file_and_directory object. (read_file_scope): Adjust to use file_and_directory. Remove make_cleanup/do_cleanups calls. (open_and_init_dwp_file): Adjust to use std::string. Remove make_cleanup/do_cleanups calls. * python/python.c (do_start_initialization): Adjust to ldirname returning a std::string. * utils.c (ldirname): Now returns a std::string. * utils.h (ldirname): Change return type to std::string. * xml-syscall.c (xml_init_syscalls_info): Adjust to ldirname returning a std::string. * xml-tdesc.c (file_read_description_xml): Likewise.
2017-03-24Avoid segfault on invalid directory tablePádraig Brady1-6/+12
gdb was segfaulting during backtrace on a binary here, where fe->dir_index parsed from the DWARF info was seen to access beyond the provided include_dirs array. This commit bounds the access to entries actually written to the array, and was verified to output the backtrace correctly. gdb/ChangeLog: * dwarf2read.c (setup_type_unit_groups): Ensure dir_index doesn't reference beyond the 'lh->include_dirs' array before accessing to it. (psymtab_include_file_name): Likewise. (dwarf_decode_lines_1): Likewise. (dwarf_decode_lines): Likewise. (file_file_name): Likewise.
2017-03-20Support DW_TAG_rvalue_reference typeArtemiy Volkov1-4/+11
Make gdb DWARF reader understand the DW_TAG_rvalue_reference type tag. Handling of this tag is done in the existing read_tag_reference_type() function, to which we add a new parameter representing the kind of reference type (lvalue vs rvalue). gdb/ChangeLog PR gdb/14441 * dwarf2read.c (process_die, read_type_die_1): Handle the DW_TAG_rvalue_reference_type DIE. (read_tag_reference_type): Add new parameter "refcode".
2017-03-20Change {lookup,make}_reference_type APIArtemiy Volkov1-1/+1
Parameterize lookup_reference_type() and make_reference_type() by the kind of reference type we want to look up. Create two wrapper functions lookup_{lvalue,rvalue}_reference_type() for lookup_reference_type() to simplify the API. Change all callers to use the new API. gdb/Changelog PR gdb/14441 * dwarf2read.c (read_tag_reference_type): Use lookup_lvalue_reference_type() instead of lookup_reference_type(). * eval.c (evaluate_subexp_standard): Likewise. * f-exp.y: Likewise. * gdbtypes.c (make_reference_type, lookup_reference_type): Generalize with rvalue reference types. (lookup_lvalue_reference_type, lookup_rvalue_reference_type): New convenience wrappers for lookup_reference_type(). * gdbtypes.h (make_reference_type, lookup_reference_type): Add a reference kind parameter. (lookup_lvalue_reference_type, lookup_rvalue_reference_type): Add wrappers for lookup_reference_type(). * guile/scm-type.c (gdbscm_type_reference): Use lookup_lvalue_reference_type() instead of lookup_reference_type(). * guile/scm-value.c (gdbscm_value_dynamic_type): Likewise. * parse.c (follow_types): Likewise. * python/py-type.c (typy_reference, typy_lookup_type): Likewise. * python/py-value.c (valpy_get_dynamic_type, valpy_getitem): Likewise. * python/py-xmethods.c (gdbpy_get_xmethod_result_type) (gdbpy_invoke_xmethod): Likewise. * stabsread.c: Provide extra argument to make_reference_type() call. * valops.c (value_ref, value_rtti_indirect_type): Use lookup_lvalue_reference_type() instead of lookup_reference_type().
2017-03-16Big-endian targets: Don't ignore offset into DW_OP_stack_valueAndreas Arnez1-0/+25
Recently I fixed a bug that caused a DW_OP_implicit_pointer with non-zero offset into a DW_OP_implicit_value to be handled incorrectly on big-endian targets. GDB ignored the offset and copied the wrong bytes: https://sourceware.org/ml/gdb-patches/2017-01/msg00251.html But there is still a similar issue when a DW_OP_implicit_pointer points into a DW_OP_stack_value instead; and again, the offset is ignored. There is an important difference, though: While implicit values are treated like blocks of data and anchored at the lowest-addressed byte, stack values traditionally contain integer numbers and are anchored at the *least significant* byte. Also, stack values do not come in varying sizes, but are cut down appropriately when used. Thus, on big-endian targets the scenario looks like this (higher addresses shown right): |<- - - - - Stack value - - - - - - ->| | | |<- original object ->| | | offset ->|####| ^^^^ de-referenced implicit pointer (Note how the original object's size influences the position of the de-referenced implicit pointer within the stack value. This is not the case for little-endian targets, where the original object starts at offset zero within the stack value.) This patch implements the logic indicated in the above diagram and adds an appropriate test case. A new function dwarf2_fetch_die_type_sect_off is added; it is used for retrieving the original object's type, so its size can be determined. That type is passed to dwarf2_evaluate_loc_desc_full via a new parameter. gdb/ChangeLog: * dwarf2loc.c (indirect_synthetic_pointer): Get data type of pointed-to DIE and pass it to dwarf2_evaluate_loc_desc_full. (dwarf2_evaluate_loc_desc_full): New parameter subobj_type; rename byte_offset to subobj_byte_offset. Fix the handling of DWARF_VALUE_STACK on big-endian targets when coming via an implicit pointer. (dwarf2_evaluate_loc_desc): Adjust call to dwarf2_evaluate_loc_desc_full. * dwarf2loc.h (dwarf2_fetch_die_type_sect_off): New declaration. * dwarf2read.c (dwarf2_fetch_die_type_sect_off): New function. gdb/testsuite/ChangeLog: * lib/dwarf.exp: Add support for DW_OP_implicit_pointer. * gdb.dwarf2/nonvar-access.exp: Add test for stack value location and implicit pointer into such a location.
2017-02-26DWARF-5: Initialization due to a false compiler warningJan Kratochvil1-0/+4
gcc-6.3.1-1.fc25.x86_64 dwarf2read.c: In function ‘void create_debug_type_hash_table(dwo_file*, dwarf2_section_info*, htab*&, rcuh_kind)’: dwarf2read.c:4776:32: error: ‘header.comp_unit_head::type_offset_in_tu.cu_offset::cu_off’ may be used uninitialized in this function [-Werror=maybe-uninitialized] dwarf2read.c:4816:21: error: ‘header.comp_unit_head::signature’ may be used uninitialized in this function [-Werror=maybe-uninitialized] cc1plus: all warnings being treated as errors gdb/ChangeLog 2017-02-26 Jan Kratochvil <jan.kratochvil@redhat.com> * dwarf2read.c (create_debug_type_hash_table): Initialize header.signature and header.type_offset_in_tu.
2017-02-23Use gdb::function_view in iterate_over_symtabs & coPedro Alves1-27/+24
I wanted to pass a lambda to iterate_over_symtabs (see following patch), so I converted it to function_view, and then the rest is cascaded from that. This gets rid of a bunch of single-use callback functions and corresponding manually managed callback capture types (add_partial_datum, search_symbols_data, etc.) in favor of letting the compiler generate them for us by using lambdas with a capture. In a couple cases, it was more natural to convert the existing function callbacks to function objects (i.e., operator(), e.g., decode_compound_collector). gdb/ChangeLog: 2017-02-23 Pedro Alves <palves@redhat.com> * ada-lang.c: Include "common/function-view.h". (ada_iterate_over_symbols): Adjust to use function_view as callback type. (struct add_partial_datum, ada_complete_symbol_matcher): Delete. (ada_make_symbol_completion_list): Use a lambda. (ada_exc_search_name_matches): Delete. (name_matches_regex): New. (ada_add_global_exceptions): Use a lambda and name_matches_regex. * compile/compile-c-support.c: Include "common/function-view.h". (print_one_macro): Change prototype to accept a ui_file pointer. (write_macro_definitions): Use a lambda. * dwarf2read.c: Include "common/function-view.h". (dw2_map_expand_apply, dw2_map_symtabs_matching_filename) (dw2_expand_symtabs_matching): Adjust to use function_view as callback type. * language.h: Include "common/function-view.h". (struct language_defn) <la_iterate_over_symbols>: Adjust to use function_view as callback type. (LA_ITERATE_OVER_SYMBOLS): Remove DATA parameter. * linespec.c: Include "common/function-view.h". (collect_info::add_symbol): New method. (struct symbol_and_data_callback, iterate_inline_only, struct symbol_matcher_data, iterate_name_matcher): Delete. (iterate_over_all_matching_symtabs): Adjust to use function_view as callback type and lambdas. (iterate_over_file_blocks): Adjust to use function_view as callback type. (decode_compound_collector): Now a class with private fields. (decode_compound_collector::release_symbols): New method. (collect_one_symbol): Rename to... (decode_compound_collector::operator()): ... this and adjust. (lookup_prefix_sym): decode_compound_collector construction bits move to decode_compound_collector ctor. Pass the decode_compound_collector object directly as callback. Remove cleanups and use decode_compound_collector::release_symbols instead. (symtab_collector): Now a class with private fields. (symtab_collector::release_symtabs): New method. (add_symtabs_to_list): Rename to... (symtab_collector::operator()): ... this and adjust. (collect_symtabs_from_filename): symtab_collector construction bits move to symtab_collector ctor. Pass the symtab_collector object directly as callback. Remove cleanups and use symtab_collector::release_symtabs instead. (collect_symbols): Delete. (add_matching_symbols_to_info): Use lambdas. * macrocmd.c (print_macro_callback): Delete. (info_macro_command): Use a lambda. (info_macros_command): Pass print_macro_definition as callable directly. (print_one_macro): Remove 'ignore' parameter. (macro_list_command): Adjust. * macrotab.c (macro_for_each_data::fn): Now a function_view. (macro_for_each_data::user_data): Delete field. (foreach_macro): Adjust to call the function_view. (macro_for_each): Adjust to use function_view as callback type. (foreach_macro_in_scope): Adjust to call the function_view. (macro_for_each_in_scope): Adjust to use function_view as callback type. * macrotab.h: Include "common/function-view.h". (macro_callback_fn): Declare a prototype instead of a pointer. Remove "user_data" parameter. (macro_for_each, macro_for_each_in_scope): Adjust to use function_view as callback type. * psymtab.c (partial_map_expand_apply) (psym_map_symtabs_matching_filename, recursively_search_psymtabs): Adjust to use function_view as callback type and to return bool. (psym_expand_symtabs_matching): Adjust to use function_view as callback types. * symfile-debug.c (debug_qf_map_symtabs_matching_filename): Adjust to use function_view as callback type and to return bool. (debug_qf_expand_symtabs_matching): Adjust to use function_view as callback types. * symfile.c (expand_symtabs_matching): Adjust to use function_view as callback types. * symfile.h: Include "common/function-view.h". (expand_symtabs_file_matcher_ftype) (expand_symtabs_symbol_matcher_ftype) (expand_symtabs_exp_notify_ftype): Remove "data" parameter and return bool. (quick_symbol_functions::map_symtabs_matching_filename) (quick_symbol_functions::expand_symtabs_matching): Adjust to use function_view as callback type and return bool. (expand_symtabs_matching): Adjust to use function_view as callback type. (maintenance_expand_name_matcher) (maintenance_expand_file_matcher): Delete. (maintenance_expand_symtabs): Use lambdas. * symtab.c (iterate_over_some_symtabs): Adjust to use function_view as callback types and return bool. (iterate_over_symtabs): Likewise. Use unique_xmalloc_ptr instead of a cleanup. (lookup_symtab_callback): Delete. (lookup_symtab): Use a lambda. (iterate_over_symbols): Adjust to use function_view as callback type. (struct search_symbols_data, search_symbols_file_matches) (search_symbols_name_matches): Delete. (search_symbols): Use a pair of lambdas. (struct add_name_data, add_macro_name, symbol_completion_matcher) (symtab_expansion_callback): Delete. (default_make_symbol_completion_list_break_on_1): Use lambdas. * symtab.h: Include "common/function-view.h". (iterate_over_some_symtabs): Adjust to use function_view as callback type and return bool. (iterate_over_symtabs): Adjust to use function_view as callback type. (symbol_found_callback_ftype): Remove 'data' parameter and return bool. (iterate_over_symbols): Adjust to use function_view as callback type.
2017-02-22Fix a regression by: Code cleanup: Split dwarf2_ranges_read to a callbackJan Kratochvil1-0/+2
On some Fedora 23 systems an internal error has been printed. gdb/ChangeLog 2017-02-21 Jan Kratochvil <jan.kratochvil@redhat.com> * dwarf2read.c (dwarf2_record_block_ranges): Add forgotten BASEADDR.
2017-02-21Fix recent compiler warnings.Jan Kratochvil1-1/+2
gcc-4.8.5-11.el7.x86_64 dwarf2read.c: In function ‘pc_bounds_kind dwarf2_get_pc_bounds(die_info*, CORE_ADDR*, CORE_ADDR*, dwarf2_cu*, partial_symtab*)’: dwarf2read.c:12134:7: error: ‘range_end’ may be used uninitialized in this function [-Werror=maybe-uninitialized] dwarf2read.c:12133:7: error: ‘range_beginning’ may be used uninitialized in this function [-Werror=maybe-uninitialized] gdb/ChangeLog 2017-02-21 Jan Kratochvil <jan.kratochvil@redhat.com> * dwarf2_rnglists_process: Initialize range_beginning and range_end.
2017-02-20DWARF-5: DW_FORM_data16Jan Kratochvil1-1/+24
DWARF-5 has new form DW_FORM_data16. The problem is that GDB cannot pass 16-byte constant as a constant value as that would require GDB to use GCC extension __int128. Formerly such data was coded as DW_FORM_block* so GDB still decodes DW_FORM_data16 like DW_FORM_block*. gdb/ChangeLog 2017-02-20 Jan Kratochvil <jan.kratochvil@redhat.com> * dwarf2read.c (skip_one_die, read_attribute_value) (dwarf2_const_value_attr, dump_die_shallow) (dwarf2_get_attr_constant_value, dwarf2_fetch_constant_bytes) (skip_form_bytes, attr_form_is_constant): Handle DW_FORM_data16. gdb/testsuite/ChangeLog 2017-02-20 Jan Kratochvil <jan.kratochvil@redhat.com> * gdb.dwarf2/formdata16.c: New file. * gdb.dwarf2/formdata16.exp: New file. * lib/dwarf.exp (Dwarf): Add DW_FORM_data16.
2017-02-20DWARF-5: MacrosJan Kratochvil1-38/+40
DWARF-5 renamed DW_MACRO_GNU_* to DW_MACRO_*. gdb/ChangeLog 2017-02-20 Jan Kratochvil <jan.kratochvil@redhat.com> * dwarf2read.c (read_file_scope): Rename DW_MACRO_GNU_*. (dwarf_parse_macro_header): Accept DWARF version 5. (dwarf_decode_macro_bytes, dwarf_decode_macros): Rename DW_MACRO_GNU_*.
2017-02-20DWARF-5: call sitesJan Kratochvil1-32/+61
this patch updates all call sites related DWARF-5 renames. gdb/ChangeLog 2017-02-20 Jan Kratochvil <jan.kratochvil@redhat.com> * block.c (call_site_for_pc): Rename DW_OP_GNU_*, DW_TAG_GNU_* and DW_AT_GNU_*. * common/common-exceptions.h (enum errors): Likewise. * dwarf2-frame.c (class dwarf_expr_executor): Likewise. * dwarf2expr.c (dwarf_block_to_dwarf_reg) (dwarf_expr_context::execute_stack_op): Likewise. * dwarf2expr.h (struct dwarf_expr_context, struct dwarf_expr_piece): Likewise. * dwarf2loc.c (dwarf_evaluate_loc_desc::get_base_type) (dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value) (show_entry_values_debug, call_site_to_target_addr) (func_addr_to_tail_call_list, func_verify_no_selftailcall) (dwarf_expr_reg_to_entry_parameter, dwarf_entry_parameter_to_value) (entry_data_value_free_closure, value_of_dwarf_reg_entry) (value_of_dwarf_block_entry, indirect_pieced_value) (symbol_needs_eval_context::push_dwarf_reg_entry_value): (disassemble_dwarf_expression): Likewise. * dwarf2read.c (process_die, inherit_abstract_dies) (read_call_site_scope): Likewise. * gdbtypes.h (struct func_type, struct call_site_parameter) (struct call_site): Likewise. * stack.c (read_frame_arg): Likewise. * std-operator.def (OP_VAR_ENTRY_VALUE): Likewise. gdb/doc/ChangeLog 2017-02-20 Jan Kratochvil <jan.kratochvil@redhat.com> * gdb.texinfo (Print Settings, Tail Call Frames): Rename DW_OP_GNU_*, DW_TAG_GNU_* and DW_AT_GNU_*. gdb/testsuite/ChangeLog 2017-02-20 Jan Kratochvil <jan.kratochvil@redhat.com> * gdb.arch/amd64-entry-value-param-dwarf5.S: New file. * gdb.arch/amd64-entry-value-param-dwarf5.c: New file. * gdb.arch/amd64-entry-value-param-dwarf5.exp: New file. * gdb.arch/amd64-entry-value.exp: Rename DW_OP_GNU_*, DW_TAG_GNU_* and DW_AT_GNU_*.
2017-02-20DWARF-5 basic functionalityJan Kratochvil1-132/+648
this is a kitchen-sink patch for everything that did not fit into its own patch. DWO is not yet implemented. gdb/ChangeLog 2017-02-20 Jan Kratochvil <jan.kratochvil@redhat.com> * defs.h (read_unsigned_leb128): New declaration. * dwarf2loc.c (decode_debug_loclists_addresses): New function. (decode_debug_loc_dwo_addresses): Update DEBUG_LOC_* to DW_LLE_*. (dwarf2_find_location_expression): Call also decode_debug_loclists_addresses. Handle DWARF-5 ULEB128 length. * dwarf2loc.h (dwarf2_version): New declaration. * dwarf2read.c (struct dwarf2_per_objfile): Add loclists, line_str, rnglists. (dwarf2_elf_names): Add .debug_loclists, .debug_line_str, .debug_rnglists. (struct dwop_section_names): Add loclists_dwo. (dwop_section_names): Add .debug_loclists.dwo. (struct comp_unit_head): Add unit_type, signature, type_offset_in_tu. (struct dwarf2_per_cu_data): Add dwarf_version. (struct dwo_sections): Add loclists. (struct attr_abbrev): Add implicit_const. (read_indirect_line_string): New declaration. (read_unsigned_leb128): Delete declaration. (rcuh_kind): New definition. (read_and_check_comp_unit_head): Change parameter is_debug_types_section to section_kind. (dwarf2_locate_sections): Handle loclists, line_str and rnglists. (read_comp_unit_head): Change parameter abfd to section, add parameter section_kind. Handle DWARF-5. (error_check_comp_unit_head): Accept also DWARF version 5. (read_and_check_comp_unit_head): Change parameter is_debug_types_section to section_kind. (read_and_check_type_unit_head): Delete function. (read_abbrev_offset): Handle DWARF-5. (create_debug_type_hash_table): Add parameter section_kind. Process only DW_UT_type. Use signature and type_offset_in_tu from struct comp_unit_head. (create_debug_types_hash_table): Update create_debug_type_hash_table caller. (create_all_type_units): Call create_debug_type_hash_table. (read_cutu_die_from_dwo, init_cutu_and_read_dies): Change read_and_check_type_unit_head caller to read_and_check_comp_unit_head caller. (skip_one_die): Handle DW_FORM_implicit_const. (dwarf2_rnglists_process): New function. (dwarf2_ranges_process): Call dwarf2_rnglists_process for DWARF-5. (abbrev_table_read_table): Handle DW_FORM_implicit_const. (read_attribute_value): Handle DW_FORM_implicit_const, DW_FORM_line_strp. (read_attribute): Handle DW_FORM_implicit_const. (read_indirect_string_at_offset_from): New function from read_indirect_string_at_offset. (read_indirect_string_at_offset): Call read_indirect_string_at_offset_from. (read_indirect_line_string_at_offset): New function. (read_indirect_string): New function comment. (read_indirect_line_string): New function. (read_unsigned_leb128): Make it global. (dwarf2_string_attr): Handle DWARF-5. (add_include_dir_stub, read_formatted_entries): New functions. (dwarf_decode_line_header, dump_die_shallow, cu_debug_loc_section): Handle DWARF-5. (per_cu_header_read_in): Update read_comp_unit_head caller. (dwarf2_version): New function. * symfile.h (struct dwarf2_debug_sections): Add loclists, line_str and rnglists. * xcoffread.c (dwarf2_xcoff_names): Update struct dwarf2_debug_sections fields. gdb/testsuite/ChangeLog 2017-02-20 Jan Kratochvil <jan.kratochvil@redhat.com> * gdb.dwarf2/dw2-error.exp (file $testfile): Update expected string.
2017-02-20Code cleanup: Refactor abbrev_table_read_table cycleJan Kratochvil1-10/+11
I find it as an improvement on its own, it prevents more code duplication in a future patch. gdb/ChangeLog 2017-02-20 Jan Kratochvil <jan.kratochvil@redhat.com> * dwarf2read.c (abbrev_table_read_table): Read the data only once.
2017-02-20Code cleanup: Split dwarf2_ranges_read to a callbackJan Kratochvil1-85/+42
DWARF-5 has .debug_rnglists which is somehow similar to .debug_ranges. This patch converts dwarf2_ranges_read to dwarf2_ranges_process which can work with both DWARF kinds of range lists through a callback. It also simplifies dwarf2_record_block_ranges which can benefit from it. gdb/ChangeLog 2017-02-20 Jan Kratochvil <jan.kratochvil@redhat.com> * dwarf2read.c (dwarf2_ranges_process): New function from dwarf2_ranges_read. (dwarf2_ranges_read, dwarf2_record_block_ranges): Use dwarf2_ranges_process.
2017-02-20Code cleanup: Split create_debug_types_hash_tableJan Kratochvil1-125/+131
DWARF-5 moved .debug_types into .debug_info and so the types reading code needs to be reused more (in a future patch). gdb/ChangeLog 2017-02-20 Jan Kratochvil <jan.kratochvil@redhat.com> * dwarf2read.c (create_debug_type_hash_table): New function from create_debug_types_hash_table. (create_debug_types_hash_table): Call create_debug_type_hash_table. (create_all_type_units, open_and_init_dwo_file): Update create_debug_types_hash_table callers.
2017-02-02Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchyPedro Alves1-31/+17
This patch starts from the desire to eliminate make_cleanup_ui_file_delete, but then goes beyond. It makes ui_file & friends a real C++ class hierarchy, and switches temporary ui_file-like objects to stack-based allocation. - mem_fileopen -> string_file mem_fileopen is replaced with a new string_file class that is treated as a value class created on the stack. This alone eliminates most make_cleanup_ui_file_delete calls, and, simplifies code a whole lot (diffstat shows around 1k loc dropped.) string_file's internal buffer is a std::string, thus the "string" in the name. This simplifies the implementation much, compared to mem_fileopen, which managed growing its internal buffer manually. - ui_file_as_string, ui_file_strdup, ui_file_obsavestring all gone The new string_file class has a string() method that provides direct writable access to the internal std::string buffer. This replaced ui_file_as_string, which forced a copy of the same data the stream had inside. With direct access via a writable reference, we can instead move the string out of the string_stream, avoiding deep string copying. Related, ui_file_xstrdup calls are replaced with xstrdup'ping the stream's string, and ui_file_obsavestring is replaced by obstack_copy0. With all those out of the way, getting rid of the weird ui_file_put mechanism was possible. - New ui_file::printf, ui_file::puts, etc. methods These simplify / clarify client code. I considered splitting client-code changes, like these, e.g.: - stb = mem_fileopen (); - fprintf_unfiltered (stb, "%s%s%s", - _("The valid values are:\n"), - regdesc, - _("The default is \"std\".")); + string_file stb; + stb.printf ("%s%s%s", + _("The valid values are:\n"), + regdesc, + _("The default is \"std\".")); In two steps, with the first step leaving fprintf_unfiltered (etc.) calls in place, and only afterwards do a pass to change all those to call stb.printf etc.. I didn't do that split, because (when I tried), it turned out to be pointless make-work: the first pass would have to touch the fprintf_unfiltered line anyway, to replace "stb" with "&stb". - gdb_fopen replaced with stack-based objects This avoids the need for cleanups or unique_ptr's. I.e., this: struct ui_file *file = gdb_fopen (filename, "w"); if (filename == NULL) perror_with_name (filename); cleanups = make_cleanup_ui_file_delete (file); // use file. do_cleanups (cleanups); is replaced with this: stdio_file file; if (!file.open (filename, "w")) perror_with_name (filename); // use file. - odd contorsions in null_file_write / null_file_fputs around when to call to_fputs / to_write eliminated. - Global null_stream object A few places that were allocating a ui_file in order to print to "nowhere" are adjusted to instead refer to a new 'null_stream' global stream. - TUI's tui_sfileopen eliminated. TUI's ui_file much simplified The TUI's ui_file was serving a dual purpose. It supported being used as string buffer, and supported being backed by a stdio FILE. The string buffer part is gone, replaced by using of string_file. The 'FILE *' support is now much simplified, by making the TUI's ui_file inherit from stdio_file. gdb/ChangeLog: 2017-02-02 Pedro Alves <palves@redhat.com> * ada-lang.c (type_as_string): Use string_file. * ada-valprint.c (ada_print_floating): Use string_file. * ada-varobj.c (ada_varobj_scalar_image) (ada_varobj_get_value_image): Use string_file. * aix-thread.c (aix_thread_extra_thread_info): Use string_file. * arm-tdep.c (_initialize_arm_tdep): Use string_printf. * breakpoint.c (update_inserted_breakpoint_locations) (insert_breakpoint_locations, reattach_breakpoints) (print_breakpoint_location, print_one_detail_ranged_breakpoint) (print_it_watchpoint): Use string_file. (save_breakpoints): Use stdio_file. * c-exp.y (oper): Use string_file. * cli/cli-logging.c (set_logging_redirect): Use ui_file_up and tee_file. (pop_output_files): Use delete. (handle_redirections): Use stdio_file and tee_file. * cli/cli-setshow.c (do_show_command): Use string_file. * compile/compile-c-support.c (c_compute_program): Use string_file. * compile/compile-c-symbols.c (generate_vla_size): Take a 'string_file &' instead of a 'ui_file *'. (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. Use string_file. (generate_c_for_variable_locations): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-internal.h (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-loc2c.c (push, pushf, unary, binary) (print_label, pushf_register_address, pushf_register) (do_compile_dwarf_expr_to_c): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * compile/compile.c (compile_to_object): Use string_file. * compile/compile.h (compile_dwarf_expr_to_c) (compile_dwarf_bounds_to_c): Take a 'string_file &' instead of a 'ui_file *'. * cp-support.c (inspect_type): Use string_file and obstack_copy0. (replace_typedefs_qualified_name): Use string_file and obstack_copy0. * disasm.c (gdb_pretty_print_insn): Use string_file. (gdb_disassembly): Adjust reference the null_stream global. (do_ui_file_delete): Delete. (gdb_insn_length): Use null_stream. * dummy-frame.c (maintenance_print_dummy_frames): Use stdio_file. * dwarf2loc.c (dwarf2_compile_property_to_c) (locexpr_generate_c_location, loclist_generate_c_location): Take a 'string_file &' instead of a 'ui_file *'. * dwarf2loc.h (dwarf2_compile_property_to_c): Likewise. * dwarf2read.c (do_ui_file_peek_last): Delete. (dwarf2_compute_name): Use string_file. * event-top.c (gdb_setup_readline): Use stdio_file. * gdbarch.sh (verify_gdbarch): Use string_file. * gdbtypes.c (safe_parse_type): Use null_stream. * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use string_file. * guile/scm-disasm.c (gdbscm_print_insn_from_port): Take a 'string_file *' instead of a 'ui_file *'. (gdbscm_arch_disassemble): Use string_file. * guile/scm-frame.c (frscm_print_frame_smob): Use string_file. * guile/scm-ports.c (class ioscm_file_port): Now a class that inherits from ui_file. (ioscm_file_port_delete, ioscm_file_port_rewind) (ioscm_file_port_put): Delete. (ioscm_file_port_write): Rename to ... (ioscm_file_port::write): ... this. Remove file_port_magic checks. (ioscm_file_port_new): Delete. (ioscm_with_output_to_port_worker): Use ioscm_file_port and ui_file_up. * guile/scm-type.c (tyscm_type_name): Use string_file. * guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print): Use string_file. * infcmd.c (print_return_value_1): Use string_file. * infrun.c (print_target_wait_results): Use string_file. * language.c (add_language): Use string_file. * location.c (explicit_to_string_internal): Use string_file. * main.c (captured_main_1): Use null_file. * maint.c (maintenance_print_architecture): Use stdio_file. * mi/mi-cmd-stack.c (list_arg_or_local): Use string_file. * mi/mi-common.h (struct mi_interp) <out, err, log, targ, event_channel>: Change type to mi_console_file pointer. * mi/mi-console.c (mi_console_file_fputs, mi_console_file_flush) (mi_console_file_delete): Delete. (struct mi_console_file): Delete. (mi_console_file_magic): Delete. (mi_console_file_new): Delete. (mi_console_file::mi_console_file): New. (mi_console_file_delete): Delete. (mi_console_file_fputs): Delete. (mi_console_file::write): New. (mi_console_raw_packet): Delete. (mi_console_file::flush): New. (mi_console_file_flush): Delete. (mi_console_set_raw): Rename to ... (mi_console_file::set_raw): ... this. * mi/mi-console.h (class mi_console_file): New class. (mi_console_file_new, mi_console_set_raw): Delete. * mi/mi-interp.c (mi_interpreter_init): Use mi_console_file. (mi_set_logging): Use delete and tee_file. Adjust. * mi/mi-main.c (output_register): Use string_file. (mi_cmd_data_evaluate_expression): Use string_file. (mi_cmd_data_read_memory): Use string_file. (mi_cmd_execute, print_variable_or_computed): Use string_file. * mi/mi-out.c (mi_ui_out::main_stream): New. (mi_ui_out::rewind): Use main_stream and string_file. (mi_ui_out::put): Use main_stream and string_file. (mi_ui_out::mi_ui_out): Remove 'stream' parameter. Allocate a 'string_file' instead. (mi_out_new): Don't allocate a mem_fileopen stream here. * mi/mi-out.h (mi_ui_out::mi_ui_out): Remove 'stream' parameter. (mi_ui_out::main_stream): Declare method. * printcmd.c (eval_command): Use string_file. * psymtab.c (maintenance_print_psymbols): Use stdio_file. * python/py-arch.c (archpy_disassemble): Use string_file. * python/py-breakpoint.c (bppy_get_commands): Use string_file. * python/py-frame.c (frapy_str): Use string_file. * python/py-framefilter.c (py_print_type, py_print_single_arg): Use string_file. * python/py-type.c (typy_str): Use string_file. * python/py-unwind.c (unwind_infopy_str): Use string_file. * python/py-value.c (valpy_str): Use string_file. * record-btrace.c (btrace_insn_history): Use string_file. * regcache.c (regcache_print): Use stdio_file. * reggroups.c (maintenance_print_reggroups): Use stdio_file. * remote.c (escape_buffer): Use string_file. * rust-lang.c (rust_get_disr_info): Use string_file. * serial.c (serial_open_ops_1): Use stdio_file. (do_serial_close): Use delete. * stack.c (print_frame_arg): Use string_file. (print_frame_args): Remove local mem_fileopen stream, not used. (print_frame): Use string_file. * symmisc.c (maintenance_print_symbols): Use stdio_file. * symtab.h (struct symbol_computed_ops) <generate_c_location>: Take a 'string_file *' instead of a 'ui_file *'. * top.c (new_ui): Use stdio_file and stderr_file. (free_ui): Use delete. (execute_command_to_string): Use string_file. (quit_confirm): Use string_file. * tracepoint.c (collection_list::append_exp): Use string_file. * tui/tui-disasm.c (tui_disassemble): Use string_file. * tui/tui-file.c: Don't include "ui-file.h". (enum streamtype, struct tui_stream): Delete. (tui_file_new, tui_file_delete, tui_fileopen, tui_sfileopen) (tui_file_isatty, tui_file_rewind, tui_file_put): Delete. (tui_file::tui_file): New method. (tui_file_fputs): Delete. (tui_file_get_strbuf): Delete. (tui_file::puts): New method. (tui_file_adjust_strbuf): Delete. (tui_file_flush): Delete. (tui_file::flush): New method. * tui/tui-file.h: Tweak intro comment. Include ui-file.h. (tui_fileopen, tui_sfileopen, tui_file_get_strbuf) (tui_file_adjust_strbuf): Delete declarations. (class tui_file): New class. * tui/tui-io.c (tui_initialize_io): Use tui_file. * tui/tui-regs.c (tui_restore_gdbout): Use delete. (tui_register_format): Use string_stream. * tui/tui-stack.c (tui_make_status_line): Use string_file. (tui_get_function_from_frame): Use string_file. * typeprint.c (type_to_string): Use string_file. * ui-file.c (struct ui_file, ui_file_magic, ui_file_new): Delete. (null_stream): New global. (ui_file_delete): Delete. (ui_file::ui_file): New. (null_file_isatty): Delete. (ui_file::~ui_file): New. (null_file_rewind): Delete. (ui_file::printf): New. (null_file_put): Delete. (null_file_flush): Delete. (ui_file::putstr): New. (null_file_write): Delete. (ui_file::putstrn): New. (null_file_read): Delete. (ui_file::putc): New. (null_file_fputs): Delete. (null_file_write_async_safe): Delete. (ui_file::vprintf): New. (null_file_delete): Delete. (null_file::write): New. (null_file_fseek): Delete. (null_file::puts): New. (ui_file_data): Delete. (null_file::write_async_safe): New. (gdb_flush, ui_file_isatty): Adjust. (ui_file_put, ui_file_rewind): Delete. (ui_file_write): Adjust. (ui_file_write_for_put): Delete. (ui_file_write_async_safe, ui_file_read): Adjust. (ui_file_fseek): Delete. (fputs_unfiltered): Adjust. (set_ui_file_flush, set_ui_file_isatty, set_ui_file_rewind) (set_ui_file_put, set_ui_file_write, set_ui_file_write_async_safe) (set_ui_file_read, set_ui_file_fputs, set_ui_file_fseek) (set_ui_file_data): Delete. (string_file::~string_file, string_file::write) (struct accumulated_ui_file, do_ui_file_xstrdup, ui_file_xstrdup) (do_ui_file_as_string, ui_file_as_string): Delete. (do_ui_file_obsavestring, ui_file_obsavestring): Delete. (struct mem_file): Delete. (mem_file_new): Delete. (stdio_file::stdio_file): New. (mem_file_delete): Delete. (stdio_file::stdio_file): New. (mem_fileopen): Delete. (stdio_file::~stdio_file): New. (mem_file_rewind): Delete. (stdio_file::set_stream): New. (mem_file_put): Delete. (stdio_file::open): New. (mem_file_write): Delete. (stdio_file_magic, struct stdio_file): Delete. (stdio_file_new, stdio_file_delete, stdio_file_flush): Delete. (stdio_file::flush): New. (stdio_file_read): Rename to ... (stdio_file::read): ... this. Adjust. (stdio_file_write): Rename to ... (stdio_file::write): ... this. Adjust. (stdio_file_write_async_safe): Rename to ... (stdio_file::write_async_safe) ... this. Adjust. (stdio_file_fputs): Rename to ... (stdio_file::puts) ... this. Adjust. (stdio_file_isatty): Delete. (stdio_file_fseek): Delete. (stdio_file::isatty): New. (stderr_file_write): Rename to ... (stderr_file::write) ... this. Adjust. (stderr_file_fputs): Rename to ... (stderr_file::puts) ... this. Adjust. (stderr_fileopen, stdio_fileopen, gdb_fopen): Delete. (stderr_file::stderr_file): New. (tee_file_magic): Delete. (struct tee_file): Delete. (tee_file::tee_file): New. (tee_file_new): Delete. (tee_file::~tee_file): New. (tee_file_delete): Delete. (tee_file_flush): Rename to ... (tee_file::flush): ... this. Adjust. (tee_file_write): Rename to ... (tee_file::write): ... this. Adjust. (tee_file::write_async_safe): New. (tee_file_fputs): Rename to ... (tee_file::puts): ... this. Adjust. (tee_file_isatty): Rename to ... (tee_file::isatty): ... this. Adjust. * ui-file.h (struct obstack, struct ui_file): Don't forward-declare. (ui_file_new, ui_file_flush_ftype, set_ui_file_flush) (ui_file_write_ftype) (set_ui_file_write, ui_file_fputs_ftype, set_ui_file_fputs) (ui_file_write_async_safe_ftype, set_ui_file_write_async_safe) (ui_file_read_ftype, set_ui_file_read, ui_file_isatty_ftype) (set_ui_file_isatty, ui_file_rewind_ftype, set_ui_file_rewind) (ui_file_put_method_ftype, ui_file_put_ftype, set_ui_file_put) (ui_file_delete_ftype, set_ui_file_data, ui_file_fseek_ftype) (set_ui_file_fseek): Delete. (ui_file_data, ui_file_delete, ui_file_rewind) (struct ui_file): New. (ui_file_up): New. (class null_file): New. (null_stream): Declare. (ui_file_write_for_put, ui_file_put): Delete. (ui_file_xstrdup, ui_file_as_string, ui_file_obsavestring): Delete. (ui_file_fseek, mem_fileopen, stdio_fileopen, stderr_fileopen) (gdb_fopen, tee_file_new): Delete. (struct string_file): New. (struct stdio_file): New. (stdio_file_up): New. (struct stderr_file): New. (class tee_file): New. * ui-out.c (ui_out::field_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * ui-out.h (class ui_out) <field_stream>: Likewise. * utils.c (do_ui_file_delete, make_cleanup_ui_file_delete) (null_stream): Delete. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * utils.h (struct ui_file): Delete forward declaration.. (make_cleanup_ui_file_delete, null_stream): Delete declarations. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. * varobj.c (varobj_value_get_print_value): Use string_file. * xtensa-tdep.c (xtensa_verify_config): Use string_file. * gdbarch.c: Regenerate.
2017-01-10Remove make_cleanup_discard_psymtabsTom Tromey1-3/+2
This removes make_cleanup_discard_psymtabs in favor of a new class. 2017-01-10 Tom Tromey <tom@tromey.com> * dwarf2read.c (dwarf2_build_psymtabs): Use psymtab_discarder. * psympriv.h (make_cleanup_discard_psymtabs): Don't declare. * psymtab.c (discard_psymtabs_upto): Remove. (make_cleanup_discard_psymtabs): Remove. (struct psymtab_state): Remove.
2017-01-10Introduce and use gdb::unlinkerTom Tromey1-16/+5
This introduces a new class, gdb::unlinker, that unlinks a file in the destructor. The user of this class has the option to preserve the file instead, by calling the "keep" method. This patch then changes the spots in gdb that use unlink in a cleanup to use this class instead. In one spot I went ahead and removed all the cleanups from the function. This fixes one latent bug -- do_bfd_delete_cleanup could refer to freed memory, by decref'ing the BFD before using its filename. 2017-01-10 Tom Tromey <tom@tromey.com> * record-full.c (record_full_save_cleanups): Remove. (record_full_save): Use gdb::unlinker. * gcore.c (do_bfd_delete_cleanup): Remove. (gcore_command): Use gdb::unlinker, unique_xmalloc_ptr. Remove cleanups. * dwarf2read.c (unlink_if_set): Remove. (write_psymtabs_to_index): Use gdb::unlinker. * common/gdb_unlinker.h: New file.
2017-01-10Use class to manage BFD reference countsTom Tromey1-39/+30
This introduces a new specialization of gdb::ref_ptr that can be used to manage BFD reference counts. Then it changes most places in gdb to use this new class, rather than explicit reference-counting or cleanups. This patch removes make_cleanup_bfd_unref. If you look you will see a couple of spots using "release" where a use of gdb_bfd_ref_ptr would be cleaner. These will be fixed in the next patch. I think this patch fixes some latent bugs. For example, it seems to me that previously objfpy_add_separate_debug_file leaked a BFD. I'm not 100% certain that the macho_symfile_read_all_oso change is correct. The existing code here is hard for me to follow. One goal of this sort of automated reference counting, though, is to make it more difficult to make logic errors; so hopefully the code is clear now. 2017-01-10 Tom Tromey <tom@tromey.com> * windows-tdep.c (windows_xfer_shared_library): Update. * windows-nat.c (windows_make_so): Update. * utils.h (make_cleanup_bfd_unref): Remove. * utils.c (do_bfd_close_cleanup, make_cleanup_bfd_unref): Remove. * symfile.h (symfile_bfd_open) (find_separate_debug_file_in_section): Return gdb_bfd_ref_ptr. * symfile.c (read_symbols, symbol_file_add) (separate_debug_file_exists): Update. (symfile_bfd_open): Return gdb_bfd_ref_ptr. (generic_load, reread_symbols): Update. * symfile-mem.c (symbol_file_add_from_memory): Update. * spu-linux-nat.c (spu_bfd_open): Return gdb_bfd_ref_ptr. (spu_symbol_file_add_from_memory): Update. * solist.h (struct target_so_ops) <bfd_open>: Return gdb_bfd_ref_ptr. (solib_bfd_fopen, solib_bfd_open): Return gdb_bfd_ref_ptr. * solib.c (solib_bfd_fopen, solib_bfd_open): Return gdb_bfd_ref_ptr. (solib_map_sections, reload_shared_libraries_1): Update. * solib-svr4.c (enable_break): Update. * solib-spu.c (spu_bfd_fopen): Return gdb_bfd_ref_ptr. * solib-frv.c (enable_break2): Update. * solib-dsbt.c (enable_break): Update. * solib-darwin.c (gdb_bfd_mach_o_fat_extract): Return gdb_bfd_ref_ptr. (darwin_solib_get_all_image_info_addr_at_init): Update. (darwin_bfd_open): Return gdb_bfd_ref_ptr. * solib-aix.c (solib_aix_bfd_open): Return gdb_bfd_ref_ptr. * record-full.c (record_full_save): Update. * python/py-objfile.c (objfpy_add_separate_debug_file): Update. * procfs.c (insert_dbx_link_bpt_in_file): Update. * minidebug.c (find_separate_debug_file_in_section): Return gdb_bfd_ref_ptr. * machoread.c (macho_add_oso_symfile): Change abfd to gdb_bfd_ref_ptr. (macho_symfile_read_all_oso): Update. (macho_check_dsym): Return gdb_bfd_ref_ptr. (macho_symfile_read): Update. * jit.c (bfd_open_from_target_memory): Return gdb_bfd_ref_ptr. (jit_bfd_try_read_symtab): Update. * gdb_bfd.h (gdb_bfd_open, gdb_bfd_fopen, gdb_bfd_openr) (gdb_bfd_openw, gdb_bfd_openr_iovec) (gdb_bfd_openr_next_archived_file, gdb_bfd_fdopenr): Return gdb_bfd_ref_ptr. (gdb_bfd_ref_policy): New struct. (gdb_bfd_ref_ptr): New typedef. * gdb_bfd.c (gdb_bfd_open, gdb_bfd_fopen, gdb_bfd_openr) (gdb_bfd_openw, gdb_bfd_openr_iovec) (gdb_bfd_openr_next_archived_file, gdb_bfd_fdopenr): Return gdb_bfd_ref_ptr. * gcore.h (create_gcore_bfd): Return gdb_bfd_ref_ptr. * gcore.c (create_gcore_bfd): Return gdb_bfd_ref_ptr. (gcore_command): Update. * exec.c (exec_file_attach): Update. * elfread.c (elf_symfile_read): Update. * dwarf2read.c (dwarf2_get_dwz_file): Update. (try_open_dwop_file, open_dwo_file): Return gdb_bfd_ref_ptr. (open_and_init_dwo_file): Update. (open_dwp_file): Return gdb_bfd_ref_ptr. (open_and_init_dwp_file): Update. * corelow.c (core_open): Update. * compile/compile-object-load.c (compile_object_load): Update. * common/gdb_ref_ptr.h (ref_ptr::operator->): New operator. * coffread.c (coff_symfile_read): Update. * cli/cli-dump.c (bfd_openr_or_error, bfd_openw_or_error): Return gdb_bfd_ref_ptr. Rename. (dump_bfd_file, restore_command): Update. * build-id.h (build_id_to_debug_bfd): Return gdb_bfd_ref_ptr. * build-id.c (build_id_to_debug_bfd): Return gdb_bfd_ref_ptr. (find_separate_debug_file_by_buildid): Update.