summaryrefslogtreecommitdiff
path: root/gdb/progspace.c
Commit message (Collapse)AuthorAgeFilesLines
* Update copyright year range in header of all files managed by GDBJoel Brobecker2023-01-011-1/+1
| | | | | | | This commit is the result of running the gdb/copyright.py script, which automated the update of the copyright year range for all source files managed by the GDB project to be updated to include year 2023.
* gdb/maint: add core file name to 'maint info program-spaces' outputAndrew Burgess2022-12-141-2/+16
| | | | | Each program space can have an associated core file. Include this information in the output of 'maint info program-spaces'.
* Rewrite registry.hTom Tromey2022-07-281-22/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | This rewrites registry.h, removing all the macros and replacing it with relatively ordinary template classes. The result is less code than the previous setup. It replaces large macros with a relatively straightforward C++ class, and now manages its own cleanup. The existing type-safe "key" class is replaced with the equivalent template class. This approach ended up requiring relatively few changes to the users of the registry code in gdb -- code using the key system just required a small change to the key's declaration. All existing users of the old C-like API are now converted to use the type-safe API. This mostly involved changing explicit deletion functions to be an operator() in a deleter class. The old "save/free" two-phase process is removed, and replaced with a single "free" phase. No existing code used both phases. The old "free" callbacks took a parameter for the enclosing container object. However, this wasn't truly needed and is removed here as well.
* Change address_space to use new and deleteTom Tromey2022-07-281-26/+12
| | | | | | | | | | | | This changes address_space to use new and delete, and makes some other small C++-ification changes as well, like changing address_space_num to be a method. This patch was needed for the subsequent patch to rewrite the registry system.
* Use unique_ptr for objfilesTom Tromey2022-05-311-3/+3
| | | | | | | | | | | | | | | | A while back, I changed objfiles to be held via a shared_ptr. The idea at the time was that this was a step toward writing to the index cache in the background, and this would let gdb keep a reference alive to do so. However, since then we've rewritten the DWARF reader, and the new index can do this without requiring a shared pointer -- in fact there are patches pending to implement this. This patch switches objfile management to unique_ptr, which makes more sense now. Regression tested on x86-64 Fedora 34.
* Unify gdb printf functionsTom Tromey2022-03-291-6/+6
| | | | | | | | | Now that filtered and unfiltered output can be treated identically, we can unify the printf family of functions. This is done under the name "gdb_printf". Most of this patch was written by script.
* Add more filename stylingTom Tromey2022-02-281-1/+3
| | | | | | | I found a few spots where filename styling ought to be applied, but is not.
* Automatic Copyright Year update after running gdb/copyright.pyJoel Brobecker2022-01-011-1/+1
| | | | | | | | This commit brings all the changes made by running gdb/copyright.py as per GDB's Start of New Year Procedure. For the avoidance of doubt, all changes in this commits were performed by the script.
* gdb: make inferior_list use intrusive_listPedro Alves2021-07-121-2/+1
| | | | | | | | | | | | | | | | | | | | | | Change inferior_list, the global list of inferiors, to use intrusive_list. I think most other changes are somewhat obvious fallouts from this change. There is a small change in behavior in scoped_mock_context. Before this patch, constructing a scoped_mock_context would replace the whole inferior list with only the new mock inferior. Tests using two scoped_mock_contexts therefore needed to manually link the two inferiors together, as the second scoped_mock_context would bump the first mock inferior from the thread list. With this patch, a scoped_mock_context adds its mock inferior to the inferior list on construction, and removes it on destruction. This means that tests run with mock inferiors in the inferior list in addition to any pre-existing inferiors (there is always at least one). There is no possible pid clash problem, since each scoped mock inferior uses its own process target, and pids are per process target. Co-Authored-By: Simon Marchi <simon.marchi@efficios.com> Change-Id: I7eb6a8f867d4dcf8b8cd2dcffd118f7270756018
* gdb: introduce iterator_range, remove next_adapterSimon Marchi2021-07-061-8/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I was always a bit confused by next_adapter, because it kind of mixes the element type and the iterator type. In reality, it is not much more than a class that wraps two iterators (begin and end). However, it assumes that: - you can construct the begin iterator by passing a pointer to the first element of the iterable - you can default-construct iterator to make the end iterator I think that by generalizing it a little bit, we can re-use it at more places. Rename it to "iterator_range". I think it describes a bit better: it's a range made by wrapping a begin and end iterator. Move it to its own file, since it's not related to next_iterator anymore. iterator_range has two constructors. The variadic one, where arguments are forwarded to construct the underlying begin iterator. The end iterator is constructed through default construction. This is a generalization of what we have today. There is another constructor which receives already constructed begin and end iterators, useful if the end iterator can't be obtained by default-construction. Or, if you wanted to make a range that does not end at the end of the container, you could pass any iterator as the "end". This generalization allows removing some "range" classes, like all_inferiors_range. These classes existed only to pass some arguments when constructing the begin iterator. With iterator_range, those same arguments are passed to the iterator_range constructed and then forwarded to the constructed begin iterator. There is a small functional difference in how iterator_range works compared to next_adapter. next_adapter stored the pointer it received as argument and constructeur an iterator in the `begin` method. iterator_range constructs the begin iterator and stores it as a member. Its `begin` method returns a copy of that iterator. With just iterator_range, uses of next_adapter<foo> would be replaced with: using foo_iterator = next_iterator<foo>; using foo_range = iterator_range<foo_iterator>; However, I added a `next_range` wrapper as a direct replacement for next_adapter<foo>. IMO, next_range is a slightly better name than next_adapter. The rest of the changes are applications of this new class. gdbsupport/ChangeLog: * next-iterator.h (class next_adapter): Remove. * iterator-range.h: New. gdb/ChangeLog: * breakpoint.h (bp_locations_range): Remove. (bp_location_range): New. (struct breakpoint) <locations>: Adjust type. (breakpoint_range): Use iterator_range. (tracepoint_range): Use iterator_range. * breakpoint.c (breakpoint::locations): Adjust return type. * gdb_bfd.h (gdb_bfd_section_range): Use iterator_range. * gdbthread.h (all_threads_safe): Pass argument to all_threads_safe_range. * inferior-iter.h (all_inferiors_range): Use iterator_range. (all_inferiors_safe_range): Use iterator_range. (all_non_exited_inferiors_range): Use iterator_range. * inferior.h (all_inferiors, all_non_exited_inferiors): Pass inferior_list as argument. * objfiles.h (struct objfile) <compunits_range>: Remove. <compunits>: Return compunit_symtab_range. * progspace.h (unwrapping_objfile_iterator) <unwrapping_objfile_iterator>: Take parameter by value. (unwrapping_objfile_range): Use iterator_range. (struct program_space) <objfiles_range>: Define with "using". <objfiles>: Adjust. <objfiles_safe_range>: Define with "using". <objfiles_safe>: Adjust. <solibs>: Return so_list_range, define here. * progspace.c (program_space::solibs): Remove. * psymtab.h (class psymtab_storage) <partial_symtab_iterator>: New. <partial_symtab_range>: Use iterator_range. * solist.h (so_list_range): New. * symtab.h (compunit_symtab_range): New. (symtab_range): New. (compunit_filetabs): Change to a function. * thread-iter.h (inf_threads_range, inf_non_exited_threads_range, safe_inf_threads_range, all_threads_safe_range): Use iterator_range. * top.h (ui_range): New. (all_uis): Use ui_range. Change-Id: Ib7a9d2a3547f45f01aa1c6b24536ba159db9b854
* gdb: make some variables staticSimon Marchi2021-01-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm trying to enable clang's -Wmissing-variable-declarations warning. This patch fixes all the obvious spots where we can simply add "static" (at least, found when building on x86-64 Linux). gdb/ChangeLog: * aarch64-linux-tdep.c (aarch64_linux_record_tdep): Make static. * aarch64-tdep.c (tdesc_aarch64_list, aarch64_prologue_unwind, aarch64_stub_unwind, aarch64_normal_base, ): Make static. * arm-linux-tdep.c (arm_prologue_unwind): Make static. * arm-tdep.c (struct frame_unwind): Make static. * auto-load.c (auto_load_safe_path_vec): Make static. * csky-tdep.c (csky_stub_unwind): Make static. * gdbarch.c (gdbarch_data_registry): Make static. * gnu-v2-abi.c (gnu_v2_abi_ops): Make static. * i386-netbsd-tdep.c (i386nbsd_mc_reg_offset): Make static. * i386-tdep.c (i386_frame_setup_skip_insns, i386_tramp_chain_in_reg_insns, i386_tramp_chain_on_stack_insns): Make static. * infrun.c (observer_mode): Make static. * linux-nat.c (sigchld_action): Make static. * linux-thread-db.c (thread_db_list): Make static. * maint-test-options.c (maintenance_test_options_list): * mep-tdep.c (mep_csr_registers): Make static. * mi/mi-cmds.c (struct mi_cmd_stats): Remove struct type name. (stats): Make static. * nat/linux-osdata.c (struct osdata_type): Make static. * ppc-netbsd-tdep.c (ppcnbsd_reg_offsets): Make static. * progspace.c (last_program_space_num): Make static. * python/py-param.c (struct parm_constant): Remove struct type name. (parm_constants): Make static. * python/py-record-btrace.c (btpy_list_methods): Make static. * python/py-record.c (recpy_gap_type): Make static. * record.c (record_goto_cmdlist): Make static. * regcache.c (regcache_descr_handle): Make static. * registry.h (DEFINE_REGISTRY): Make definition static. * symmisc.c (std_in, std_out, std_err): Make static. * top.c (previous_saved_command_line): Make static. * tracepoint.c (trace_user, trace_notes, trace_stop_notes): Make static. * unittests/command-def-selftests.c (nr_duplicates, nr_invalid_prefixcmd, lists): Make static. * unittests/observable-selftests.c (test_notification): Make static. * unittests/optional/assignment/1.cc (counter): Make static. * unittests/optional/assignment/2.cc (counter): Make static. * unittests/optional/assignment/3.cc (counter): Make static. * unittests/optional/assignment/4.cc (counter): Make static. * unittests/optional/assignment/5.cc (counter): Make static. * unittests/optional/assignment/6.cc (counter): Make static. gdbserver/ChangeLog: * ax.cc (bytecode_address_table): Make static. * debug.cc (debug_file): Make static. * linux-low.cc (stopping_threads): Make static. (step_over_bkpt): Make static. * linux-x86-low.cc (amd64_emit_ops, i386_emit_ops): Make static. * tracepoint.cc (stop_tracing_bkpt, flush_trace_buffer_bkpt, alloced_trace_state_variables, trace_buffer_ctrl, tracing_start_time, tracing_stop_time, tracing_user_name, tracing_notes, tracing_stop_note): Make static. Change-Id: Ic1d8034723b7802502bda23770893be2338ab020
* Update copyright year range in all GDB filesJoel Brobecker2021-01-011-1/+1
| | | | | | | | | This commits the result of running gdb/copyright.py as per our Start of New Year procedure... gdb/ChangeLog Update copyright year range in copyright header of all GDB files.
* Remove call to exec_closeTom Tromey2020-10-291-1/+0
| | | | | | | | | | | | There's no need to call exec_close from ~progspace, because that method just does some cleanup that's already going to be done during destruction. This patch removes the call. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * progspace.c (program_space::~program_space): Don't call exec_close.
* Change program_space_empty_p to method on program_spaceTom Tromey2020-10-291-6/+3
| | | | | | | | | | | | | | | This changes program_space_empty_p to be a method on program_space. It also changes it to return bool. I removed the "_p" suffix because "empty" is a "well-known" C++ method name. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * inferior.c (delete_inferior): Update. * progspace.c (program_space::empty): Rename from program_space_empty_p. Return bool. * progspace.h (struct program_space) <empty>: New method. (program_space_empty_p): Don't declare.
* Change clear_program_space_solib_cache to method on program_spaceTom Tromey2020-10-291-4/+3
| | | | | | | | | | | | | | | | | | This changes clear_program_space_solib_cache to be a method on program_space. Also, it removes a call to this function from the program_space destructor, as that is not necessary. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * progspace.c (program_space::~program_space): Don't call clear_program_space_solib_cache. (program_space::clear_solib_cache): Rename from clear_solib_cache. * solib.c (handle_solib_event): Update. * progspace.h (struct program_space) <clear_solib_cache>: New method. (clear_program_space_solib_cache): Don't declare.
* Change program_space::ebfd to a gdb_bfd_ref_ptrTom Tromey2020-10-291-4/+2
| | | | | | | | | | | | | | | This changes program_space::ebfd to a gdb_bfd_ref_ptr, removing some manual management. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * exec.c (exec_file_attach): Update. * progspace.c (program_space::exec_close): Update. * progspace.h (struct program_space) <ebfd>: Now a gdb_bfd_ref_ptr. <set_exec_bfd>: Change argument type. <exec_bfd>: Update.
* Remove the exec_bfd macroTom Tromey2020-10-291-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This removes the exec_bfd macro, in favor of new accessors on program_space. In one spot the accessor can't be used; but this is still a big improvement over the macro, IMO. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * windows-tdep.c (windows_solib_create_inferior_hook): Update. * symfile.c (reread_symbols): Update. * symfile-mem.c (add_symbol_file_from_memory_command) (add_vsyscall_page): Update. * source-cache.c (source_cache::get_plain_source_lines): Update. * solib-svr4.c (find_program_interpreter, elf_locate_base) (svr4_current_sos_direct, svr4_exec_displacement) (svr4_relocate_main_executable): Update. (svr4_iterate_over_objfiles_in_search_order): Update. * solib-frv.c (enable_break2, enable_break): Update. * solib-dsbt.c (lm_base, enable_break): Update. * solib-darwin.c (find_program_interpreter) (darwin_solib_create_inferior_hook): Update. * sol-thread.c (rw_common, ps_pdmodel): Update. * rs6000-nat.c (rs6000_nat_target::create_inferior): Update. * remote.c (compare_sections_command) (remote_target::trace_set_readonly_regions): Update. * remote-sim.c (get_sim_inferior_data) (gdbsim_target::create_inferior, gdbsim_target::create_inferior): Update. (gdbsim_target_open, gdbsim_target::files_info): Update. * exec.h (exec_bfd): Remove macro. * progspace.c (initialize_progspace): Update. * proc-service.c (ps_addr_to_core_addr, core_addr_to_ps_addr): Update. * nto-procfs.c (nto_procfs_target::post_attach) (nto_procfs_target::create_inferior): Update. * maint.c (maintenance_info_sections): Update. * linux-thread-db.c (thread_db_target::get_thread_local_address): Update. * infcmd.c (post_create_inferior): Update. * gcore.c (default_gcore_arch, default_gcore_target): Update. (objfile_find_memory_regions): Update. * exec.c (validate_exec_file, exec_file_attach) (exec_read_partial_read_only, print_section_info): Update. * corelow.c (core_target_open): Update. * corefile.c (reopen_exec_file, validate_files): Update. * arm-tdep.c (gdb_print_insn_arm): Update. * arch-utils.c (gdbarch_update_p, default_print_insn): Update. * progspace.h (struct program_space) <exec_bfd, set_exec_bfd>: New methods.
* Change exec_close to be a method on program_spaceTom Tromey2020-10-291-0/+20
| | | | | | | | | | | | | | | | exec_close uses the current program space, so it seemed cleaner to change it to be a method on program_space. This patch makes this change. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * progspace.c (program_space::exec_close): New method, from exec_close in exec.c. * exec.c (exec_close): Move to progspace.c. (exec_target::close, exec_file_attach): Update. * progspace.h (struct program_space) <exec_close>: Declare method.
* Remove exec_filename macroTom Tromey2020-10-291-4/+4
| | | | | | | | | | | | | | | | | | | | | This removes the exec_filename macro, replacing it with uses of the member of current_program_space. This also renames that member, and changes it to be a unique pointer. gdb/ChangeLog 2020-10-29 Tom Tromey <tom@tromey.com> * progspace.h (struct program_space) <exec_filename>: Rename from pspace_exec_filename. Now a unique_xmalloc_ptr. * inferior.c (print_selected_inferior): Update. (print_inferior): Update. * mi/mi-main.c (print_one_inferior): Update. * exec.h (exec_filename): Remove macro. * corefile.c (get_exec_file): Update. * exec.c (exec_close): Update. (exec_file_attach): Update. * progspace.c (clone_program_space): Update. (print_program_space): Update.
* Remove clear_section_tableTom Tromey2020-10-121-1/+0
| | | | | | | | | | | | | | | | The call to clear_section_table in ~program_space is now clearly not needed -- the section table will clear itself. This patch removes this call and then inlines the one remaining call to clear_section_table. gdb/ChangeLog 2020-10-12 Tom Tromey <tom@tromey.com> * progspace.c (program_space::~program_space): Don't call clear_section_table. * exec.h (clear_section_table): Don't declare. * exec.c (exec_target::close): Update. (clear_section_table): Remove.
* Adjust "maint info program-spaces" to per-inferior target stackPedro Alves2020-08-291-2/+8
| | | | | | | | | | By inspection, I noticed that print_program_space is calling target_pid_to_str on the wrong target stack. Most targets print a process pid the same way, so it isn't actually visible. gdb/ChangeLog: * progspace.c (print_program_space): Use all_inferiors. Switch to the inferior before calling target_pid_to_str.
* gdb.base/corefile.exp regression for unix/-m32 on x86_64 (PR 26336)Pedro Alves2020-08-121-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | gdb.base/corefile.exp is showing an unexpected failure and an unresolved testcase when testing against unix/-m32: (gdb) PASS: gdb.base/corefile.exp: attach: sanity check we see the core file attach 15741 gdb/dwarf2-frame.c:1009: internal-error: dwarf2_frame_cache* dwarf2_frame_cache(frame_info*, void**): Assertion `fde != NULL' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) FAIL: gdb.base/corefile.exp: attach: with core (GDB internal error) Resyncing due to internal error. This regressed with: From 5b6d1e4fa4fc6827c7b3f0e99ff120dfa14d65d2 Mon Sep 17 00:00:00 2001 From: Pedro Alves <palves@redhat.com> Date: Fri, 10 Jan 2020 20:06:08 +0000 Subject: [PATCH] Multi-target support The assertion is here: #0 internal_error (file=0xbffffccb0 <error: Cannot access memory at address 0xbffffccb0>, line=0, fmt=0x555556327320 "en_US.UTF-8") at sr c/gdbsupport/errors.cc:51 #1 0x00005555557d4e45 in dwarf2_frame_cache (this_frame=0x55555672f950, this_cache=0x55555672f968) at src/gdb/dwarf2/frame.c:1013 #2 0x00005555557d5886 in dwarf2_frame_this_id (this_frame=0x55555672f950, this_cache=0x55555672f968, this_id=0x55555672f9b0) at src/gdb/d warf2/frame.c:1226 #3 0x00005555558b184e in compute_frame_id (fi=0x55555672f950) at src/gdb/frame.c:558 #4 0x00005555558b19b2 in get_frame_id (fi=0x55555672f950) at src/gdb/frame.c:588 #5 0x0000555555bda338 in scoped_restore_current_thread::scoped_restore_current_thread (this=0x7fffffffd0d8) at src/gdb/thread.c:1458 #6 0x00005555556ce41f in scoped_restore_current_pspace_and_thread::scoped_restore_current_pspace_and_thread (During symbol reading: .debug_line address at offset 0x1db2d3 is 0 [in module /home/pedro/gdb/cascais-builds/binutils-gdb/gdb/gdb] this=0x7fffffffd0d0) at src/gdb/progspace-and-thread.h:29 #7 0x0000555555898ea6 in remove_target_sections (owner=0x555556935550) at src/gdb/exec.c:798 #8 0x0000555555b700b6 in symfile_free_objfile (objfile=0x555556935550) at src/gdb/symfile.c:3742 #9 0x000055555565050e in std::_Function_handler<void (objfile*), void (*)(objfile*)>::_M_invoke(std::_Any_data const&, objfile*&&) (__functor=..., __args#0=@0x7fffffffd190 : 0x555556935550) at /usr/include/c++/9/bits/std_function.h:300 #10 0x0000555555a3053d in std::function<void (objfile*)>::operator()(objfile*) const (this=0x555556752a20, __args#0=0x555556935550) at /usr/include/c++/9/bits/std_function. h:688 #11 0x0000555555a2ff01 in gdb::observers::observable<objfile*>::notify (this=0x5555562eaa80 <gdb::observers::free_objfile>, args#0=0x555556935550) at /net/cascais.nfs/gdb/b inutils-gdb/src/gdb/../gdbsupport/observable.h:106 #12 0x0000555555a2c56a in objfile::~objfile (this=0x555556935550, __in_chrg=<optimized out>) at src/gdb/objfiles.c:521 #13 0x0000555555a31d46 in std::_Sp_counted_ptr<objfile*, (__gnu_cxx::_Lock_policy)2>::_M_dispose (this=0x555556c1f6f0) at /usr/include/c++/9/bits/shared_ptr_base.h:377 #14 0x00005555556d3444 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x555556c1f6f0) at /usr/include/c++/9/bits/shared_ptr_base.h:155 #15 0x00005555556cec77 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (this=0x555556b99ee8, __in_chrg=<optimized out>) at /usr/include/c++/9/bits/shared_ptr_base.h:730 #16 0x0000555555a2f8da in std::__shared_ptr<objfile, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=0x555556b99ee0, __in_chrg=<optimized out>) at /usr/include/c++/9/bits/shared_ptr_base.h:1169 #17 0x0000555555a2f8fa in std::shared_ptr<objfile>::~shared_ptr (this=0x555556b99ee0, __in_chrg=<optimized out>) at /usr/include/c++/9/bits/shared_ptr.h:103 #18 0x0000555555a63fba in __gnu_cxx::new_allocator<std::_List_node<std::shared_ptr<objfile> > >::destroy<std::shared_ptr<objfile> > (this=0x55555679f0c0, __p=0x555556b99ee0) at /usr/include/c++/9/ext/new_allocator.h:153 #19 0x0000555555a638fb in std::allocator_traits<std::allocator<std::_List_node<std::shared_ptr<objfile> > > >::destroy<std::shared_ptr<objfile> > (__a=..., __p=0x555556b99ee0) at /usr/include/c++/9/bits/alloc_traits.h:497 #20 0x0000555555a6351c in std::__cxx11::list<std::shared_ptr<objfile>, std::allocator<std::shared_ptr<objfile> > >::_M_erase (this=0x55555679f0c0, __position=std::shared_ptr<objfile> (expired, weak count 1) = {get() = 0x555556935550}) at /usr/include/c++/9/bits/stl_list.h:1921 #21 0x0000555555a62dab in std::__cxx11::list<std::shared_ptr<objfile>, std::allocator<std::shared_ptr<objfile> > >::erase (this=0x55555679f0c0, __position=std::shared_ptr<objfile> (expired, weak count 1) = {get() = 0x555556935550}) at /usr/include/c++/9/bits/list.tcc:158 #22 0x0000555555a614dd in program_space::remove_objfile (this=0x55555679f080, objfile=0x555556935550) at src/gdb/progspace.c:207 #23 0x0000555555a2c4dc in objfile::unlink (this=0x555556935550) at src/gdb/objfiles.c:497 #24 0x0000555555a2da65 in objfile_purge_solibs () at src/gdb/objfiles.c:904 #25 0x0000555555b3af74 in no_shared_libraries (ignored=0x0, from_tty=1) at src/gdb/solib.c:1236 #26 0x0000555555bbafc7 in target_pre_inferior (from_tty=1) at src/gdb/target.c:1900 #27 0x0000555555940afb in attach_command (args=0x5555563277c7 "15741", from_tty=1) at src/gdb/infcmd.c:2582 ... The problem is that the multi-target commit added a scoped_restore_current_thread to remove_target_sections (frame #7 above). scoped_restore_current_thread's ctor fetches the selected frame's frame id. If the frame had not had its frame id computed yet, it is computed then (frame #4 above). Because it has been determined earlier that the frame's unwinder is the DWARF unwinder, we end up here: static struct dwarf2_frame_cache * dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache) { ... /* Find the correct FDE. */ fde = dwarf2_frame_find_fde (&pc1, &cache->per_objfile); gdb_assert (fde != NULL); And, that assertion fails. The assertion is reasonable, because the DWARF unwinder only claims the frame if it managed to find the FDE earlier (in dwarf2_frame_sniffer). (unix/-m32 is thus really a red herring here -- it's just that on x86_64 -m64, the frame is not claimed by the DWARF unwinder.) The reason the assertion is failing, is because the objfile that contains the FDE has been removed from the objfiles list already when we get here (frame #22 above). This suggests that the fix should be to invalidate DWARF frames when their objfile is removed. Or to keep it simple and safe, invalidate the frame cache when an objfile is removed. That is what this commit does. OOC, I checked why is it that when you unload a file with plain "(gdb) file", we don't hit the assertion. It must be because we're already flushing the frame cache somewhere else in that case. And indeed, we flush the frame cache here: (gdb) bt #0 reinit_frame_cache () at src/gdb/frame.c:1857 #1 0x0000555555ad1ad6 in registers_changed_ptid (target=0x0, ptid=...) at src/gdb/regcache.c:470 #2 0x0000555555ad1b58 in registers_changed () at src/gdb/regcache.c:485 #3 0x00005555558d095e in set_target_gdbarch (new_gdbarch=0x555556d5f5b0) at src/gdb/gdbarch.c:5528 #4 0x0000555555677175 in set_gdbarch_from_file (abfd=0x0) at src/gdb/arch-utils.c:601 #5 0x0000555555897c6b in exec_file_attach (filename=0x0, from_tty=1) at src/gdb/exec.c:409 #6 0x000055555589852d in exec_file_command (args=0x0, from_tty=1) at src/gdb/exec.c:571 #7 0x00005555558985a1 in file_command (arg=0x0, from_tty=1) at src/gdb/exec.c:583 #8 0x000055555572b55f in do_const_cfunc (c=0x55555672e200, args=0x0, from_tty=1) at src/gdb/cli/cli-decode.c:95 #9 0x000055555572f3d3 in cmd_func (cmd=0x55555672e200, args=0x0, from_tty=1) at src/gdb/cli/cli-decode.c:2181 #10 0x0000555555be1ecc in execute_command (p=0x555556327804 "", from_tty=1) at src/gdb/top.c:668 #11 0x0000555555895427 in command_handler (command=0x555556327800 "file") at src/gdb/event-top.c:588 #12 0x00005555558958af in command_line_handler (rl=...) at src/gdb/event-top.c:773 #13 0x0000555555894b3e in gdb_rl_callback_handler (rl=0x55555a09e240 "file") at src/gdb/event-top.c:219 #14 0x0000555555ccfeec in rl_callback_read_char () at src/readline/readline/callback.c:281 #15 0x000055555589495a in gdb_rl_callback_read_char_wrapper_noexcept () at src/gdb/event-top.c:177 #16 0x0000555555894a08 in gdb_rl_callback_read_char_wrapper (client_data=0x555556327520) at src/gdb/event-top.c:194 #17 0x00005555558952a5 in stdin_event_handler (error=0, client_data=0x555556327520) at src/gdb/event-top.c:516 #18 0x0000555555e027d6 in handle_file_event (file_ptr=0x555558d20840, ready_mask=1) at src/gdbsupport/event-loop.cc:548 #19 0x0000555555e02d88 in gdb_wait_for_event (block=1) at src/gdbsupport/event-loop.cc:673 #20 0x0000555555e01c42 in gdb_do_one_event () at src/gdbsupport/event-loop.cc:215 #21 0x00005555559c47c2 in start_event_loop () at src/gdb/main.c:356 #22 0x00005555559c490d in captured_command_loop () at src/gdb/main.c:416 #23 0x00005555559c6217 in captured_main (data=0x7fffffffdc00) at src/gdb/main.c:1253 #24 0x00005555559c6289 in gdb_main (args=0x7fffffffdc00) at src/gdb/main.c:1268 #25 0x0000555555621756 in main (argc=3, argv=0x7fffffffdd18) at src/gdb/gdb.c:32 gdb/ChangeLog: PR gdb/26336 * progspace.c (program_space::remove_objfile): Invalidate the frame cache.
* Remove ALL_PSPACESTom Tromey2020-05-081-57/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This removes the ALL_PSPACES macro. In this case it seemed cleanest to change how program spaces are stored -- instead of using a linked list, they are now stored in a std::vector. gdb/ChangeLog 2020-05-08 Tom Tromey <tom@tromey.com> * symtab.c (set_symbol_cache_size) (maintenance_print_symbol_cache, maintenance_flush_symbol_cache) (maintenance_print_symbol_cache_statistics): Update. * symmisc.c (print_symbol_bcache_statistics) (print_objfile_statistics, maintenance_print_objfiles) (maintenance_info_symtabs, maintenance_check_symtabs) (maintenance_expand_symtabs, maintenance_info_line_tables): Update. * symfile-debug.c (set_debug_symfile): Update. * source.c (forget_cached_source_info): Update. * python/python.c (gdbpy_progspaces): Update. * psymtab.c (maintenance_info_psymtabs): Update. * probe.c (parse_probes): Update. * linespec.c (iterate_over_all_matching_symtabs) (collect_symtabs_from_filename, search_minsyms_for_name): Update. * guile/scm-progspace.c (gdbscm_progspaces): Update. * exec.c (exec_target::close): Update. * ada-tasks.c (ada_tasks_new_objfile_observer): Update. * breakpoint.c (print_one_breakpoint_location) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint): Update. * progspace.c (program_spaces): Now a std::vector. (maybe_new_address_space): Update. (add_program_space): Remove. (program_space::program_space): Update. (remove_program_space): Update. (number_of_program_spaces): Remove. (print_program_space, update_address_spaces): Update. * progspace.h (program_spaces): Change type. (ALL_PSPACES): Remove. (number_of_program_spaces): Don't declare. (struct program_space) <next>: Remove.
* Remove ALL_SO_LIBS and so_list_headTom Tromey2020-05-081-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | This patch started as an attempt to replace ALL_SO_LIBS with an ordinary C++ iterator. However, then I tripped over the so_list_head define again, and decided to remove it as well. gdb/ChangeLog 2020-05-08 Tom Tromey <tom@tromey.com> * mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries): Update. * solib-svr4.c (svr4_fetch_objfile_link_map): Update. (enable_break): Update. * solib-frv.c (frv_fdpic_find_global_pointer): Update. (frv_fdpic_find_canonical_descriptor): Update. (frv_fetch_objfile_link_map): Update. * progspace.c (program_space::free_all_objfiles): Update. (program_space::solibs): New method. * progspace.h (struct program_space) <solibs>: New method. * solist.h (master_so_list): Don't declare. (ALL_SO_LIBS): Remove. * solib.h (so_list_head): Remove. (update_solib_list): Update comment. * solib.c (master_so_list): Remove. (solib_used, update_solib_list, solib_add) (info_sharedlibrary_command, clear_solib) (reload_shared_libraries_1, remove_user_added_objfile): Update.
* Refactor delete_program_space as a destructorPedro Alves2020-04-161-41/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, while the program_space's ctor adds the new pspace to the pspaces list, the destructor doesn't remove the pspace from the pspace list. Instead, you're supposed to use delete_program_space, to both remove the pspace from the list, and deleting the pspace. This patch eliminates delete_program_space, and makes the pspace dtor remove the deleted pspace from the pspace list itself, i.e., makes the dtor do the mirror opposite of the ctor. I found this helps with a following patch that will allocate a mock program_space on the stack. It's easier to just let the regular dtor remove the mock pspace from the pspace list than arrange to call delete_program_space instead of the pspace dtor in that situation. While at it, move the ctor/dtor intro comments to the header file, and make the ctor explicit. gdb/ChangeLog: 2020-04-16 Pedro Alves <palves@redhat.com> * inferior.c (delete_inferior): Use delete operator directly instead of delete_program_space. * progspace.c (add_program_space): New, factored out from program_space::program_space. (remove_program_space): New, factored out from delete_program_space. (program_space::program_space): Remove intro comment. Rewrite. (program_space::~program_space): Remove intro comment. Call remove_program_space. (delete_program_space): Delete. * progspace.h (program_space::program_space): Make explicit. Move intro comment here, adjusted. (program_space::~program_space): Move intro comment here, adjusted. (delete_program_space): Remove.
* Switch the inferior too in switch_to_program_space_and_threadPedro Alves2020-01-101-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With multi-target, each inferior now has its own target connection. The problem in switch_to_program_space_and_thread is that in the current state GDB switches to "no thread" and also sets the program space but because the inferior is not switched, potentially an incorrect target remains selected. Here is a sample scenario that exploits this flow: On terminal 1, start a gdbserver on a program named foo: $ gdbserver :1234 ./foo On terminal 2, start gdb on a program named bar. Suppose foo and bar are compiled from foo.c and bar.c. They are completely separate. So, bar.c:2 has no meaning for foo. $ gdb -q ./bar Reading symbols from ./bar... (gdb) add-inferior [New inferior 2] Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) target remote :1234 ... (gdb) set debug remote 2 (gdb) break bar.c:2 Sending packet: $Hgp0.0#ad...Packet received: OK Sending packet: $m5fa,12#f8...Packet received: E01 Sending packet: $m5fa,1#c6...Packet received: E01 Sending packet: $m5fb,3#c9...Packet received: E01 Sending packet: $m5fe,1#ca...Packet received: E01 Breakpoint 1 at 0x5fe: file bar.c, line 2. (gdb) Here we have an unnecessary sending of the packets to the gdbserver. With this fix in progspace-and-thread.c, we'll get this: (gdb) break bar.c:2 Breakpoint 1 at 0x5fe: file bar.c, line 2. (gdb) Now there is no sending of the packets to gdbserver. The changes around clear_symtab_users calls are necessary because otherwise we regress gdb.base/step-over-exit.exp, hitting the new assertion in switch_to_program_space_and_thread. The problem is, a forked child terminates, and when GDB decides to auto-purge that inferior, GDB tries to switch to the pspace of that no-longer-existing inferior. The root of the problem is within the program_space destructor: program_space::~program_space () { ... set_current_program_space (this); # (1) ... breakpoint_program_space_exit (this); # (2) ... free_all_objfiles (); # (3) ... } We get here from delete_inferior -> delete_program_space. So we're deleting an inferior, and the inferior to be deleted is no longer in the inferior list. At (2), we've deleted all the breakpoints and locations for the program space being deleted. The crash happens while doing a breakpoint re-set, called by clear_symtab_users at the tail end of (3). That is, while recreating breakpoints for the current program space, which is the program space we're tearing down. During breakpoint re-set, we try to switch to the new location's pspace (the current pspace set in (1), so the pspace we're tearing down) with switch_to_program_space_and_thread, and that hits the failed assertion. It's the fact that we recreate breakpoints in the program_space destructor that is the latent bug here. Just don't do that, and we don't end up in the crash situation. My first approach to fix this added a symfile_add_flags parameter to program_space::free_all_objfiles, and then passed that down to clear_symtab_users. The program_space dtor would then pass down SYMFILE_DEFER_BP_RESET to free_all_objfiles. I couldn't help feeling that adding that parameter to free_all_objfiles looked a little awkward, so I settled on something a little different -- hoist the clear_symtab_users call to the callers. There are only two callers. I felt that that didn't look as odd, particularly since remove_symbol_file_command also does: objf->unlink (); clear_symtab_users (0); I.e., objfile deletion is already separate from calling clear_symtab_users in some places. gdb/ChangeLog: 2020-01-10 Aleksandar Paunovic <aleksandar.paunovic@intel.com> Pedro Alves <palves@redhat.com> * progspace-and-thread.c (switch_to_program_space_and_thread): Assert there's an inferior for PSPACE. Use switch_to_inferior_no_thread to switch the inferior too. * progspace.c (program_space::~program_space): Call clear_symtab_users here, with SYMFILE_DEFER_BP_RESET. (program_space::free_all_objfiles): Don't call clear_symtab_users here. * symfile.c (symbol_file_clear): Call clear_symtab_users here. gdb/testsuite/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> * gdb.server/bkpt-other-inferior.exp: New file.
* Update copyright year range in all GDB files.Joel Brobecker2020-01-011-1/+1
| | | | | | gdb/ChangeLog: Update copyright year range in all GDB files.
* Manage objfiles with shared_ptrTom Tromey2019-12-121-7/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes objfiles to be managed using a shared_ptr. shared_ptr is chosen because it enables the use of objfiles in background threads. The simplest way to do this was to introduce a new iterator that will return the underlying objfile, rather than a shared_ptr. (I also tried changing the rest of gdb to use shared_ptr, but this was quite large; and to using intrusive reference counting, but this also was tricky.) gdb/ChangeLog 2019-12-12 Tom Tromey <tom@tromey.com> * progspace.h (objfile_list): New typedef. (class unwrapping_objfile_iterator) (struct unwrapping_objfile_range): Newl (struct program_space) <objfiles_range>: Change type. <objfiles>: Change return type. <add_objfile>: Change type of "objfile" parameter. <objfiles_list>: Now a list of shared_ptr. * progspace.c (program_space::add_objfile): Change type of "objfile". Update. (program_space::remove_objfile): Update. * objfiles.h (struct objfile) <~objfile>: Make public. * objfiles.c (objfile::make): Update. (objfile::unlink): Don't call delete. Change-Id: I6fb7fbf06efb7cb7474c525908365863eae27eb3
* Move free_all_objfiles to program_spaceTom Tromey2019-12-121-0/+18
| | | | | | | | | | | | | | | | | | This changes free_all_objfiles to be a method on program_space, in line with the other changes to treat program_space as a container for objfiles. gdb/ChangeLog 2019-12-12 Tom Tromey <tom@tromey.com> * symfile.c (symbol_file_clear): Update. * progspace.h (struct program_space) <free_all_objfiles>: Declare method. * progspace.c (program_space::free_all_objfiles): New method. * objfiles.h (free_all_objfiles): Don't declare. * objfiles.c (free_all_objfiles): Move to program_space. Change-Id: I908b549d2981b6005f7ca181fc0e6d24fc8b7b6f
* Store objfiles on a std::listTom Tromey2019-12-121-38/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | This removes objfile::next and changes objfiles to be stored in a std::list. gdb/ChangeLog 2019-12-12 Tom Tromey <tom@tromey.com> * progspace.c (program_space::add_objfile) (program_space::remove_objfile): Update. (program_space::multi_objfile_p): Remove. * objfiles.h (struct objfile) <next>: Remove. * objfiles.c (objfile::objfile): Update. (put_objfile_before): Update. (unlink_objfile): Update. * progspace.h (object_files): Remove. (struct program_space) <objfiles_head>: Remove. <objfiles_list>: New member. <objfiles_range, objfiles_safe_range>: Change type. (objfiles): Change return type. (objfiles_safe): Update. (multi_objfile_p): Rewrite and inline. (object_files): Remove macro. Change-Id: Ib4430e3db6f9a390399924379a5c10426c514853
* Remove MULTI_OBJFILE_PTom Tromey2019-12-121-0/+8
| | | | | | | | | | | | | | | | | This removes the MULTI_OBJFILE_P macro in favor of a method on the program space. gdb/ChangeLog 2019-12-12 Tom Tromey <tom@tromey.com> * progspace.c (program_space::multi_objfile_p): New method. * printcmd.c (info_symbol_command): Update. * maint.c (maintenance_translate_address): Update. * objfiles.h (MULTI_OBJFILE_P): Remove. * progspace.h (struct program_space) <multi_objfile_p>: New method. Change-Id: I2779e26ea8909078d63fea8f13bce94cab73948c
* Introduce program_space::remove_objfileTom Tromey2019-12-121-0/+25
| | | | | | | | | | | | | | | | | | | | | | | This introduces a new method, program_space::remove_objfile, and changes the objfile destructor not to unlink an objfile from the program space's list. This is cleaner because, like the previous patch, it treats the program space more like a container for objfiles. Also, this makes it possible to keep an objfile alive even though it has been unlinked from the program space's list, which is important for processing in a worker thread. gdb/ChangeLog 2019-12-12 Tom Tromey <tom@tromey.com> * progspace.h (struct program_space) <remove_objfile>: Declare. * progspace.c (program_space::remove_objfile): New method. * objfiles.c (unlink_objfile): Remove. (objfile::unlink): Call remove_objfile. (objfile): Don't call unlink_objfile. Change-Id: I22f768827723dce21886fae9b3664532c8349e68
* Introduce program_space::add_objfileTom Tromey2019-12-121-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This introduces a new method, program_space::add_objfile, that adds an objfile to the program space's list of objfiles. It also changes the obfile's constructor so that linking an objfile into this list is not done here. The former is an improvement because it makes more sense to treat the program space as a container holding objfiles -- so manipulation of the list belongs there. The latter is not strictly needed, but seemed better both because it is removing a global side effect from a constructor, and for symmetry reasons, as a subsequent patch will remove unlinking from the destructor. gdb/ChangeLog 2019-12-12 Tom Tromey <tom@tromey.com> * progspace.h (struct program_space) <add_objfile>: Declare method. * progspace.c (program_space::add_objfile): New method. * objfiles.c (~objfile): Don't unlink objfile. (put_objfile_before): Remove. (add_separate_debug_objfile): Don't call put_objfile_before. (objfile::make): Call add_objfile. Set new_objfiles_available on the per-program-space data. Change-Id: I93e8525dda631cb89dcc2046a5c51c7c9f34ccfd
* Rename field_int to field_signedTom Tromey2019-07-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This renames ui_out::field_int to field_signed, and field_fmt_int to field_fmt_signed; and changes the type of the "value" parameter from int to LONGEST. Tested by the buildbot. gdb/ChangeLog 2019-07-17 Tom Tromey <tromey@adacore.com> * ui-out.h (class ui_out) <field_signed, field_fmt_signed, do_field_signed>: Rename. Change type of "value". * ui-out.c (ui_out::field_signed): Rename from field_int. Change type of "value". (ui_out::field_fmt_signed): Rename from field_fmt_int. Change type of "value". * tui/tui-out.h (class tui_ui_out) <do_field_signed>: Rename from do_field_int. Change type of "value". * tui/tui-out.c (tui_ui_out::do_field_signed): Rename from do_field_int. Change type of "value". * tracepoint.c (trace_status_mi, tfind_1) (print_one_static_tracepoint_marker): Update. * thread.c (print_thread_info_1, print_selected_thread_frame): Update. * stack.c (print_frame, print_frame_info): Update. * spu-tdep.c (info_spu_signal_command, info_spu_dma_cmdlist): Update. * source.c (print_source_lines_base): Update. * skip.c (info_skip_command): Update. * record-btrace.c (btrace_ui_out_decode_error) (btrace_call_history_src_line): Update. * python/py-framefilter.c (py_print_single_arg, py_print_frame): Update. * progspace.c (print_program_space): Update. * mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Update. * mi/mi-out.h (class mi_ui_out) <do_field_signed>: Rename from do_field_int. Change type of "value". * mi/mi-out.c (mi_ui_out::do_table_begin) (mi_ui_out::do_table_header): Update. (mi_ui_out::do_field_signed): Rename from do_field_int. Change type of "value". * mi/mi-main.c (mi_cmd_thread_list_ids, print_one_inferior) (mi_cmd_data_list_changed_registers, output_register) (mi_cmd_data_read_memory, mi_load_progress) (mi_cmd_trace_frame_collected): Update. * mi/mi-interp.c (mi_on_normal_stop_1, mi_output_solib_attribs): Update. * mi/mi-cmd-var.c (print_varobj, mi_cmd_var_create) (mi_cmd_var_delete, mi_cmd_var_info_num_children) (mi_cmd_var_list_children, varobj_update_one): Update. * mi/mi-cmd-stack.c (mi_cmd_stack_info_depth) (mi_cmd_stack_list_args, list_arg_or_local): Update. * mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_file): Update. * inferior.c (print_inferior): Update. * gdb_bfd.c (print_one_bfd): Update. * disasm.c (gdb_pretty_print_disassembler::pretty_print_insn): Update. * darwin-nat-info.c (darwin_debug_regions_recurse): Update. * cli-out.h (class cli_ui_out) <do_field_signed>: Rename from do_field_int. Change type of "value". * cli-out.c (cli_ui_out::do_field_signed): Rename from do_field_int. Change type of "value". * breakpoint.c (watchpoint_check, print_breakpoint_location) (print_one_breakpoint_location, print_it_catch_fork) (print_one_catch_fork, print_it_catch_vfork) (print_one_catch_vfork, print_it_catch_solib) (print_it_catch_exec, print_it_ranged_breakpoint) (print_mention_watchpoint, print_mention_masked_watchpoint) (bkpt_print_it, update_static_tracepoint): Update. * break-catch-throw.c (print_it_exception_catchpoint): Update. * break-catch-syscall.c (print_it_catch_syscall): Update. * ada-tasks.c (print_ada_task_info): Update. * ada-lang.c (print_it_exception, print_mention_exception): Update.
* Change pid_to_str to return std::stringTom Tromey2019-03-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently the target pid_to_str method returns a const char *, so many implementations have a static buffer that they update. This patch changes these methods to return a std::string instead. I think this is cleaner and avoids possible gotchas when calling pid_to_str on different ptids in a single statement. (Though no such calls exist currently.) This also updates various helper functions, and the gdbarch pid_to_str methods. I also made a best effort to fix all the callers, but I can't build some of the *-nat.c files. Tested by the buildbot. gdb/ChangeLog 2019-03-13 Tom Tromey <tromey@adacore.com> * i386-gnu-nat.c (i386_gnu_nat_target::fetch_registers) (i386_gnu_nat_target::store_registers): Update. * target-debug.h (target_debug_print_std_string): New macro. * x86-linux-nat.c (x86_linux_nat_target::enable_btrace): Update. * windows-tdep.c (display_one_tib): Update. * tui/tui-stack.c (tui_make_status_line): Update. * top.c (print_inferior_quit_action): Update. * thread.c (thr_try_catch_cmd): Update. (add_thread_with_info): Update. (thread_target_id_str): Update. (thr_try_catch_cmd): Update. (thread_command): Update. (thread_find_command): Update. * record-btrace.c (record_btrace_target::info_record) (record_btrace_resume_thread, record_btrace_target::resume) (record_btrace_cancel_resume, record_btrace_step_thread) (record_btrace_target::wait, record_btrace_target::wait) (record_btrace_target::wait, record_btrace_target::stop): Update. * progspace.c (print_program_space): Update. * process-stratum-target.c (process_stratum_target::thread_address_space): Update. * linux-fork.c (linux_fork_mourn_inferior) (detach_checkpoint_command, info_checkpoints_command) (linux_fork_context): Update. (linux_fork_detach): Update. (class scoped_switch_fork_info): Update. (delete_checkpoint_command): Update. * infrun.c (follow_fork_inferior): Update. (follow_fork_inferior): Update. (proceed_after_vfork_done): Update. (handle_vfork_child_exec_or_exit): Update. (follow_exec): Update. (displaced_step_prepare_throw): Update. (displaced_step_restore): Update. (start_step_over): Update. (resume_1): Update. (clear_proceed_status_thread): Update. (proceed): Update. (print_target_wait_results): Update. (do_target_wait): Update. (context_switch): Update. (stop_all_threads): Update. (restart_threads): Update. (finish_step_over): Update. (handle_signal_stop): Update. (switch_back_to_stepped_thread): Update. (keep_going_pass_signal): Update. (print_exited_reason): Update. (normal_stop): Update. * inferior.c (inferior_pid_to_str): Change return type. (print_selected_inferior): Update. (add_inferior): Update. (detach_inferior): Update. * dummy-frame.c (fprint_dummy_frames): Update. * dcache.c (dcache_info_1): Update. * btrace.c (btrace_enable, btrace_disable, btrace_teardown) (btrace_fetch, btrace_clear): Update. * linux-tdep.c (linux_core_pid_to_str): Change return type. * i386-cygwin-tdep.c (i386_windows_core_pid_to_str): Change return type. * fbsd-tdep.c (fbsd_core_pid_to_str): Change return type. * sol2-tdep.h (sol2_core_pid_to_str): Change return type. * sol2-tdep.c (sol2_core_pid_to_str): Change return type. * gdbarch.c, gdbarch.h: Rebuild. * gdbarch.sh (core_pid_to_str): Change return type. * windows-nat.c (struct windows_nat_target) <pid_to_str>: Change return type. (windows_nat_target::pid_to_str): Change return type. (windows_delete_thread): Update. (windows_nat_target::attach): Update. (windows_nat_target::files_info): Update. * target-delegates.c: Rebuild. * sol-thread.c (class sol_thread_target) <pid_to_str>: Change return type. (sol_thread_target::pid_to_str): Change return type. * remote.c (class remote_target) <pid_to_str>: Change return type. (remote_target::pid_to_str): Change return type. (extended_remote_target::attach, remote_target::remote_stop_ns) (remote_target::remote_notif_remove_queued_reply) (remote_target::push_stop_reply, remote_target::disable_btrace): Update. (extended_remote_target::attach): Update. * remote-sim.c (struct gdbsim_target) <pid_to_str>: Change return type. (gdbsim_target::pid_to_str): Change return type. * ravenscar-thread.c (struct ravenscar_thread_target) <pid_to_str>: Change return type. (ravenscar_thread_target::pid_to_str): Change return type. * procfs.c (class procfs_target) <pid_to_str>: Change return type. (procfs_target::pid_to_str): Change return type. (procfs_target::attach): Update. (procfs_target::detach): Update. (procfs_target::fetch_registers): Update. (procfs_target::store_registers): Update. (procfs_target::wait): Update. (procfs_target::files_info): Update. * obsd-nat.c (obsd_nat_target::pid_to_str): Change return type. * nto-procfs.c (struct nto_procfs_target) <pid_to_str>: Change return type. (nto_procfs_target::pid_to_str): Change return type. (nto_procfs_target::files_info, nto_procfs_target::attach): Update. * linux-thread-db.c (class thread_db_target) <pid_to_str>: Change return type. * linux-nat.c (linux_nat_target::pid_to_str): Change return type. (exit_lwp): Update. (attach_proc_task_lwp_callback, get_detach_signal) (detach_one_lwp, resume_lwp, linux_nat_target::resume) (linux_nat_target::resume, wait_lwp, stop_callback) (maybe_clear_ignore_sigint, stop_wait_callback, status_callback) (save_stop_reason, select_event_lwp, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps) (linux_nat_target::wait, linux_nat_stop_lwp): Update. * inf-ptrace.c (inf_ptrace_target::pid_to_str): Change return type. (inf_ptrace_target::attach): Update. (inf_ptrace_target::files_info): Update. * go32-nat.c (struct go32_nat_target) <pid_to_str>: Change return type. (go32_nat_target::pid_to_str): Change return type. * gnu-nat.c (gnu_nat_target::pid_to_str): Change return type. (gnu_nat_target::wait): Update. (gnu_nat_target::wait): Update. (gnu_nat_target::resume): Update. * fbsd-nat.c (fbsd_nat_target::pid_to_str): Change return type. (fbsd_nat_target::wait): Update. * darwin-nat.c (darwin_nat_target::pid_to_str): Change return type. (darwin_nat_target::attach): Update. * corelow.c (class core_target) <pid_to_str>: Change return type. (core_target::pid_to_str): Change return type. * target.c (normal_pid_to_str): Change return type. (default_pid_to_str): Likewise. (target_pid_to_str): Change return type. (target_translate_tls_address): Update. (target_announce_detach): Update. * bsd-uthread.c (struct bsd_uthread_target) <pid_to_str>: Change return type. (bsd_uthread_target::pid_to_str): Change return type. * bsd-kvm.c (class bsd_kvm_target) <pid_to_str>: Change return type. (bsd_kvm_target::pid_to_str): Change return type. * aix-thread.c (class aix_thread_target) <pid_to_str>: Change return type. (aix_thread_target::pid_to_str): Change return type. * target.h (struct target_ops) <pid_to_str>: Change return type. (target_pid_to_str, normal_pid_to_str): Likewise. * obsd-nat.h (class obsd_nat_target) <pid_to_str>: Change return type. * linux-nat.h (class linux_nat_target) <pid_to_str>: Change return type. * inf-ptrace.h (struct inf_ptrace_target) <pid_to_str>: Change return type. * gnu-nat.h (struct gnu_nat_target) <pid_to_str>: Change return type. * fbsd-nat.h (class fbsd_nat_target) <pid_to_str>: Change return type. * darwin-nat.h (class darwin_nat_target) <pid_to_str>: Change return type.
* Update copyright year range in all GDB files.Joel Brobecker2019-01-011-1/+1
| | | | | | | | | | | | | | | | This commit applies all changes made after running the gdb/copyright.py script. Note that one file was flagged by the script, due to an invalid copyright header (gdb/unittests/basic_string_view/element_access/char/empty.cc). As the file was copied from GCC's libstdc++-v3 testsuite, this commit leaves this file untouched for the time being; a patch to fix the header was sent to gcc-patches first. gdb/ChangeLog: Update copyright year range in all GDB files.
* Remove pid_to_ptidTom Tromey2018-07-031-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This removes pid_to_ptid in favor of calling the ptid_t constructor directly. gdb/ChangeLog 2018-07-03 Tom Tromey <tom@tromey.com> * common/ptid.c (pid_to_ptid): Remove. * common/ptid.h (pid_to_ptid): Don't declare. * aix-thread.c: Update. * arm-linux-nat.c: Update. * common/ptid.c: Update. * common/ptid.h: Update. * corelow.c: Update. * ctf.c: Update. * darwin-nat.c: Update. * fbsd-nat.c: Update. * fork-child.c: Update. * gnu-nat.c: Update. * go32-nat.c: Update. * inf-ptrace.c: Update. * infcmd.c: Update. * inferior.c: Update. * infrun.c: Update. * linux-fork.c: Update. * linux-nat.c: Update. * nat/aarch64-linux-hw-point.c: Update. * nat/fork-inferior.c: Update. * nat/x86-linux-dregs.c: Update. * nto-procfs.c: Update. * obsd-nat.c: Update. * procfs.c: Update. * progspace.c: Update. * remote.c: Update. * rs6000-nat.c: Update. * s390-linux-nat.c: Update. * sol-thread.c: Update. * spu-linux-nat.c: Update. * target.c: Update. * top.c: Update. * tracefile-tfile.c: Update. * windows-nat.c: Update. gdb/gdbserver/ChangeLog 2018-07-03 Tom Tromey <tom@tromey.com> * linux-low.c: Update. * linux-ppc-low.c: Update. * linux-x86-low.c: Update. * proc-service.c: Update. * server.c: Update. * spu-low.c: Update. * thread-db.c: Update. * win32-low.c: Update.
* Use thread_info and inferior pointers more throughoutPedro Alves2018-06-211-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is more preparation bits for multi-target support. In a multi-target scenario, we need to address the case of different processes/threads running on different targets that happen to have the same PID/PTID. E.g., we can have both process 123 in target 1, and process 123 in target 2, while they're in reality different processes running on different machines. Or maybe we've loaded multiple instances of the same core file. Etc. To address this, in my WIP multi-target branch, threads and processes are uniquely identified by the (process_stratum target_ops *, ptid_t) and (process_stratum target_ops *, pid) tuples respectively. I.e., each process_stratum instance has its own thread/process number space. As you can imagine, that requires passing around target_ops * pointers in a number of functions where we're currently passing only a ptid_t or an int. E.g., when we look up a thread_info object by ptid_t in find_thread_ptid, the ptid_t alone isn't sufficient. In many cases though, we already have the thread_info or inferior pointer handy, but we "lose" it somewhere along the call stack, only to look it up again by ptid_t/pid. Since thread_info or inferior objects know their parent target, if we pass around thread_info or inferior pointers when possible, we avoid having to add extra target_ops parameters to many functions, and also, we eliminate a number of by ptid_t/int lookups. So that's what this patch does. In a bit more detail: - Changes a number of functions and methods to take a thread_info or inferior pointer instead of a ptid_t or int parameter. - Changes a number of structure fields from ptid_t/int to inferior or thread_info pointers. - Uses the inferior_thread() function whenever possible instead of inferior_ptid. - Uses thread_info pointers directly when possible instead of the is_running/is_stopped etc. routines that require a lookup. - A number of functions are eliminated along the way, such as: int valid_gdb_inferior_id (int num); int pid_to_gdb_inferior_id (int pid); int gdb_inferior_id_to_pid (int num); int in_inferior_list (int pid); - A few structures and places hold a thread_info pointer across inferior execution, so now they take a strong reference to the (refcounted) thread_info object to avoid the thread_info pointer getting stale. This is done in enable_thread_stack_temporaries and in the infcall.c code. - Related, there's a spot in infcall.c where using a RAII object to handle the refcount would be handy, so a gdb::ref_ptr specialization for thread_info is added (thread_info_ref, in gdbthread.h), along with a gdb_ref_ptr policy that works for all refcounted_object types (in common/refcounted-object.h). gdb/ChangeLog: 2018-06-21 Pedro Alves <palves@redhat.com> * ada-lang.h (ada_get_task_number): Take a thread_info pointer instead of a ptid_t. All callers adjusted. * ada-tasks.c (ada_get_task_number): Likewise. All callers adjusted. (print_ada_task_info, display_current_task_id, task_command_1): Adjust. * breakpoint.c (watchpoint_in_thread_scope): Adjust to use inferior_thread. (breakpoint_kind): Adjust. (remove_breakpoints_pid): Rename to ... (remove_breakpoints_inf): ... this. Adjust to take an inferior pointer. All callers adjusted. (bpstat_clear_actions): Use inferior_thread. (get_bpstat_thread): New. (bpstat_do_actions): Use it. (bpstat_check_breakpoint_conditions, bpstat_stop_status): Adjust to take a thread_info pointer. All callers adjusted. (set_longjmp_breakpoint_for_call_dummy, set_momentary_breakpoint) (breakpoint_re_set_thread): Use inferior_thread. * breakpoint.h (struct inferior): Forward declare. (bpstat_stop_status): Update. (remove_breakpoints_pid): Delete. (remove_breakpoints_inf): New. * bsd-uthread.c (bsd_uthread_target::wait) (bsd_uthread_target::update_thread_list): Use find_thread_ptid. * btrace.c (btrace_add_pc, btrace_enable, btrace_fetch) (maint_btrace_packet_history_cmd) (maint_btrace_clear_packet_history_cmd): Adjust. (maint_btrace_clear_cmd, maint_info_btrace_cmd): Adjust to use inferior_thread. * cli/cli-interp.c: Include "inferior.h". * common/refcounted-object.h (struct refcounted_object_ref_policy): New. * compile/compile-object-load.c: Include gdbthread.h. (store_regs): Use inferior_thread. * corelow.c (core_target::close): Use current_inferior. (core_target_open): Adjust to use first_thread_of_inferior and use the current inferior. * ctf.c (ctf_target::close): Adjust to use current_inferior. * dummy-frame.c (dummy_frame_id) <ptid>: Delete, replaced by ... <thread>: ... this new field. All references adjusted. (dummy_frame_pop, dummy_frame_discard, register_dummy_frame_dtor): Take a thread_info pointer instead of a ptid_t. * dummy-frame.h (dummy_frame_push, dummy_frame_pop) (dummy_frame_discard, register_dummy_frame_dtor): Take a thread_info pointer instead of a ptid_t. * elfread.c: Include "inferior.h". (elf_gnu_ifunc_resolver_stop, elf_gnu_ifunc_resolver_return_stop): Use inferior_thread. * eval.c (evaluate_subexp): Likewise. * frame.c (frame_pop, has_stack_frames, find_frame_sal): Use inferior_thread. * gdb_proc_service.h (struct thread_info): Forward declare. (struct ps_prochandle) <ptid>: Delete, replaced by ... <thread>: ... this new field. All references adjusted. * gdbarch.h, gdbarch.c: Regenerate. * gdbarch.sh (get_syscall_number): Replace 'ptid' parameter with a 'thread' parameter. All implementations and callers adjusted. * gdbthread.h (thread_info) <set_running>: New method. (delete_thread, delete_thread_silent): Take a thread_info pointer instead of a ptid. (global_thread_id_to_ptid, ptid_to_global_thread_id): Delete. (first_thread_of_process): Delete, replaced by ... (first_thread_of_inferior): ... this new function. All callers adjusted. (any_live_thread_of_process): Delete, replaced by ... (any_live_thread_of_inferior): ... this new function. All callers adjusted. (switch_to_thread, switch_to_no_thread): Declare. (is_executing): Delete. (enable_thread_stack_temporaries): Update comment. <enable_thread_stack_temporaries>: Take a thread_info pointer instead of a ptid_t. Incref the thread. <~enable_thread_stack_temporaries>: Decref the thread. <m_ptid>: Delete <m_thr>: New. (thread_stack_temporaries_enabled_p, push_thread_stack_temporary) (get_last_thread_stack_temporary) (value_in_thread_stack_temporaries, can_access_registers_thread): Take a thread_info pointer instead of a ptid_t. All callers adjusted. * infcall.c (get_call_return_value): Use inferior_thread. (run_inferior_call): Work with thread pointers instead of ptid_t. (call_function_by_hand_dummy): Work with thread pointers instead of ptid_t. Use thread_info_ref. * infcmd.c (proceed_thread_callback): Access thread's state directly. (ensure_valid_thread, ensure_not_running): Use inferior_thread, access thread's state directly. (continue_command): Use inferior_thread. (info_program_command): Use find_thread_ptid and access thread state directly. (proceed_after_attach_callback): Use thread state directly. (notice_new_inferior): Take a thread_info pointer instead of a ptid_t. All callers adjusted. (exit_inferior): Take an inferior pointer instead of a pid. All callers adjusted. (exit_inferior_silent): New. (detach_inferior): Delete. (valid_gdb_inferior_id, pid_to_gdb_inferior_id) (gdb_inferior_id_to_pid, in_inferior_list): Delete. (detach_inferior_command, kill_inferior_command): Use find_inferior_id instead of valid_gdb_inferior_id and gdb_inferior_id_to_pid. (inferior_command): Use inferior and thread pointers. * inferior.h (struct thread_info): Forward declare. (notice_new_inferior): Take a thread_info pointer instead of a ptid_t. All callers adjusted. (detach_inferior): Delete declaration. (exit_inferior, exit_inferior_silent): Take an inferior pointer instead of a pid. All callers adjusted. (gdb_inferior_id_to_pid, pid_to_gdb_inferior_id, in_inferior_list) (valid_gdb_inferior_id): Delete. * infrun.c (follow_fork_inferior, proceed_after_vfork_done) (handle_vfork_child_exec_or_exit, follow_exec): Adjust. (struct displaced_step_inferior_state) <pid>: Delete, replaced by ... <inf>: ... this new field. <step_ptid>: Delete, replaced by ... <step_thread>: ... this new field. (get_displaced_stepping_state): Take an inferior pointer instead of a pid. All callers adjusted. (displaced_step_in_progress_any_inferior): Adjust. (displaced_step_in_progress_thread): Take a thread pointer instead of a ptid_t. All callers adjusted. (displaced_step_in_progress, add_displaced_stepping_state): Take an inferior pointer instead of a pid. All callers adjusted. (get_displaced_step_closure_by_addr): Adjust. (remove_displaced_stepping_state): Take an inferior pointer instead of a pid. All callers adjusted. (displaced_step_prepare_throw, displaced_step_prepare) (displaced_step_fixup): Take a thread pointer instead of a ptid_t. All callers adjusted. (start_step_over): Adjust. (infrun_thread_ptid_changed): Remove bit updating ptids in the displaced step queue. (do_target_resume): Adjust. (fetch_inferior_event): Use inferior_thread. (context_switch, get_inferior_stop_soon): Take an execution_control_state pointer instead of a ptid_t. All callers adjusted. (switch_to_thread_cleanup): Delete. (stop_all_threads): Use scoped_restore_current_thread. * inline-frame.c: Include "gdbthread.h". (inline_state) <inline_state>: Take a thread pointer instead of a ptid_t. All callers adjusted. <ptid>: Delete, replaced by ... <thread>: ... this new field. (find_inline_frame_state): Take a thread pointer instead of a ptid_t. All callers adjusted. (skip_inline_frames, step_into_inline_frame) (inline_skipped_frames, inline_skipped_symbol): Take a thread pointer instead of a ptid_t. All callers adjusted. * inline-frame.h (skip_inline_frames, step_into_inline_frame) (inline_skipped_frames, inline_skipped_symbol): Likewise. * linux-fork.c (delete_checkpoint_command): Adjust to use thread pointers directly. * linux-nat.c (get_detach_signal): Likewise. * linux-thread-db.c (thread_from_lwp): New 'stopped' parameter. (thread_db_notice_clone): Adjust. (thread_db_find_new_threads_silently) (thread_db_find_new_threads_2, thread_db_find_new_threads_1): Take a thread pointer instead of a ptid_t. All callers adjusted. * mi/mi-cmd-var.c: Include "inferior.h". (mi_cmd_var_update_iter): Update to use thread pointers. * mi/mi-interp.c (mi_new_thread): Update to use the thread's inferior directly. (mi_output_running_pid, mi_inferior_count): Delete, bits factored out to ... (mi_output_running): ... this new function. (mi_on_resume_1): Adjust to use it. (mi_user_selected_context_changed): Adjust to use inferior_thread. * mi/mi-main.c (proceed_thread): Adjust to use thread pointers directly. (interrupt_thread_callback): : Adjust to use thread and inferior pointers. * proc-service.c: Include "gdbthread.h". (ps_pglobal_lookup): Adjust to use the thread's inferior directly. * progspace-and-thread.c: Include "inferior.h". * progspace.c: Include "inferior.h". * python/py-exitedevent.c (create_exited_event_object): Adjust to hold a reference to an inferior_object. * python/py-finishbreakpoint.c (bpfinishpy_init): Adjust to use inferior_thread. * python/py-inferior.c (struct inferior_object): Give the type a tag name instead of a typedef. (python_on_normal_stop): No need to check if the current thread is listed. (inferior_to_inferior_object): Change return type to inferior_object. All callers adjusted. (find_thread_object): Delete, bits factored out to ... (thread_to_thread_object): ... this new function. * python/py-infthread.c (create_thread_object): Use inferior_to_inferior_object. (thpy_is_stopped): Use thread pointer directly. (gdbpy_selected_thread): Use inferior_thread. * python/py-record-btrace.c (btpy_list_object) <ptid>: Delete field, replaced with ... <thread>: ... this new field. All users adjusted. (btpy_insn_or_gap_new): Drop const. (btpy_list_new): Take a thread pointer instead of a ptid_t. All callers adjusted. * python/py-record.c: Include "gdbthread.h". (recpy_insn_new, recpy_func_new): Take a thread pointer instead of a ptid_t. All callers adjusted. (gdbpy_current_recording): Use inferior_thread. * python/py-record.h (recpy_record_object) <ptid>: Delete field, replaced with ... <thread>: ... this new field. All users adjusted. (recpy_element_object) <ptid>: Delete field, replaced with ... <thread>: ... this new field. All users adjusted. (recpy_insn_new, recpy_func_new): Take a thread pointer instead of a ptid_t. All callers adjusted. * python/py-threadevent.c: Include "gdbthread.h". (get_event_thread): Use thread_to_thread_object. * python/python-internal.h (struct inferior_object): Forward declare. (find_thread_object, find_inferior_object): Delete declarations. (thread_to_thread_object, inferior_to_inferior_object): New declarations. * record-btrace.c: Include "inferior.h". (require_btrace_thread): Use inferior_thread. (record_btrace_frame_sniffer) (record_btrace_tailcall_frame_sniffer): Use inferior_thread. (get_thread_current_frame): Use scoped_restore_current_thread and switch_to_thread. (get_thread_current_frame): Use thread pointer directly. (record_btrace_replay_at_breakpoint): Use thread's inferior pointer directly. * record-full.c: Include "inferior.h". * regcache.c: Include "gdbthread.h". (get_thread_arch_regcache): Use the inferior's address space directly. (get_thread_regcache, registers_changed_thread): New. * regcache.h (get_thread_regcache(thread_info *thread)): New overload. (registers_changed_thread): New. (remote_target) <remote_detach_1>: Swap order of parameters. (remote_add_thread): <remote_add_thread>: Return the new thread. (get_remote_thread_info(ptid_t)): New overload. (remote_target::remote_notice_new_inferior): Use thread pointers directly. (remote_target::process_initial_stop_replies): Use thread_info::set_running. (remote_target::remote_detach_1, remote_target::detach) (extended_remote_target::detach): Adjust. * stack.c (frame_show_address): Use inferior_thread. * target-debug.h (target_debug_print_thread_info_pp): New. * target-delegates.c: Regenerate. * target.c (default_thread_address_space): Delete. (memory_xfer_partial_1): Use current_inferior. (target_detach): Use current_inferior. (target_thread_address_space): Delete. (generic_mourn_inferior): Use current_inferior. * target.h (struct target_ops) <thread_address_space>: Delete. (target_thread_address_space): Delete. * thread.c (init_thread_list): Use ALL_THREADS_SAFE. Use thread pointers directly. (delete_thread_1, delete_thread, delete_thread_silent): Take a thread pointer instead of a ptid_t. Adjust all callers. (ptid_to_global_thread_id, global_thread_id_to_ptid): Delete. (first_thread_of_process): Delete, replaced by ... (first_thread_of_inferior): ... this new function. All callers adjusted. (any_thread_of_process): Rename to ... (any_thread_of_inferior): ... this, and take an inferior pointer. (any_live_thread_of_process): Rename to ... (any_live_thread_of_inferior): ... this, and take an inferior pointer. (thread_stack_temporaries_enabled_p, push_thread_stack_temporary) (value_in_thread_stack_temporaries) (get_last_thread_stack_temporary): Take a thread pointer instead of a ptid_t. Adjust all callers. (thread_info::set_running): New. (validate_registers_access): Use inferior_thread. (can_access_registers_ptid): Rename to ... (can_access_registers_thread): ... this, and take a thread pointer. (print_thread_info_1): Adjust to compare thread pointers instead of ptids. (switch_to_no_thread, switch_to_thread): Make extern. (scoped_restore_current_thread::~scoped_restore_current_thread): Use m_thread pointer directly. (scoped_restore_current_thread::scoped_restore_current_thread): Use inferior_thread. (thread_command): Use thread pointer directly. (thread_num_make_value_helper): Use inferior_thread. * top.c (execute_command): Use inferior_thread. * tui/tui-interp.c: Include "inferior.h". * varobj.c (varobj_create): Use inferior_thread. (value_of_root_1): Use find_thread_global_id instead of global_thread_id_to_ptid.
* Change program_space::added_solibs to a std::vectorTom Tromey2018-05-291-2/+1
| | | | | | | | | | | | | | | | | This changes program_space::added_solibs to a std::vector, removing a VEC. Tested by the buildbot. gdb/ChangeLog 2018-05-29 Tom Tromey <tom@tromey.com> * progspace.h (so_list_ptr): Remove typedef. Don't declare VEC. (struct program_space) <added_solibs>: Now a std::vector. * breakpoint.c (print_solib_event): Update. (check_status_catch_solib): Update. * progspace.c (clear_program_space_solib_cache): Update. * solib.c (update_solib_list): Update.
* Defer breakpoint reset when cloning progspace for fork childSimon Marchi2018-04-071-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using this simple test: static void break_here () { } int main (int argc, char *argv[]) { fork (); break_here(); return 0; } compiled as a PIE: $ gcc test.c -g3 -O0 -o test -pie and running this: $ ./gdb -nx -q --data-directory=data-directory ./test -ex "b break_here" -ex "set detach-on-fork off" -ex r gives: Warning: Cannot insert breakpoint 1. Cannot access memory at address 0x64a Note that GDB might get stopped by SIGTTOU because of this issue: https://sourceware.org/bugzilla/show_bug.cgi?id=23020 In that case, just use "fg" to continue. This issue happens only with position-independent executables. Adding the main objfile for the new inferior (the fork child) causes GDB to try to reset the breakpoints. However, that new objfile has not been relocated yet. So the breakpoint on "break_here" resolves to an unrelocated address, from which we are trying to read/write to set a breakpoint. Passing SYMFILE_DEFER_BP_RESET avoids that problem. The executable is relocated just after, in the follow_fork_inferior function. The buildbot seems happy with this patch. I don't think it's necessary to add a new test. Just changing this made many tests go from FAIL to PASS on my machine, where gcc produces PIE executables by default. If anything, I think we would need to add a board file that produces position-independent executables, so that we can run all the tests with PIE, even on machines where that is not the default. gdb/ChangeLog: * progspace.c (clone_program_space): Pass SYMFILE_DEFER_BP_RESET to symbol_file_add_main.
* Make program_space::deleted_solibs a vector of std::stringSimon Marchi2018-03-021-2/+1
| | | | | | | | | | | | | | | This allows removing a usage of free_char_ptr_vec. gdb/ChangeLog: * progspace.h (struct program_space) <deleted_solibs>: Change type to std::vector<std::string>. * progspace.c (clear_program_space_solib_cache): Adjust. * breakpoint.c (print_solib_event): Adjust. (check_status_catch_solib): Adjust. * solib.c (update_solib_list): Adjust. * ui-out.h (class ui_out) <field_string>: New overload. * ui-out.c (ui_out::field_string): New overload.
* C++ify program_spaceSimon Marchi2018-03-021-26/+15
| | | | | | | | | | | | | | | | | | | | | | This patch makes program_space a C++ object by adding a constructor/destructor, giving default values to fields, and using new/delete. gdb/ChangeLog: * progspace.h (struct program_space): Add constructor and destructor, initialize fields. (add_program_space): Remove. * progspace.c (add_program_space): Rename to... (program_space::program_space): ... this. (release_program_space): Rename to... (program_space::~program_space): ... this. (delete_program_space): Use delete to delete program_space. (initialize_progspace): Use new to allocate program_space. * inferior.c (add_inferior_with_spaces): Likewise. (clone_inferior_command): Likewise. * infrun.c (follow_fork_inferior): Likewise. (handle_vfork_child_exec_or_exit): Likewise.
* Update copyright year range in all GDB filesJoel Brobecker2018-01-021-1/+1
| | | | | | gdb/ChangeLog: Update copyright year range in all GDB files
* Redesign mock environment for gdbarch selftestsPedro Alves2017-10-041-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A following patch will remove this hack from within regcache's implementation: struct regcache * get_thread_arch_regcache (ptid_t ptid, struct gdbarch *gdbarch) { struct address_space *aspace; /* For the benefit of "maint print registers" & co when debugging an executable, allow dumping the regcache even when there is no thread selected (target_thread_address_space internal-errors if no address space is found). Note that normal user commands will fail higher up on the call stack due to no target_has_registers. */ aspace = (ptid_equal (null_ptid, ptid) ? NULL : target_thread_address_space (ptid)); i.e., it'll no longer be possible to try to build a regcache for null_ptid. That change alone would regress the gdbarch self tests though, causing this: (gdb) maintenance selftest [...] Running selftest register_to_value. src/gdb/inferior.c:309: internal-error: inferior* find_inferior_pid(int): Assertion `pid != 0' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) FAIL: gdb.gdb/unittest.exp: maintenance selftest (GDB internal error) The problem is that the way the mocking environment for those unit tests is written is a bit fragile: it creates a special purpose regcache (and sentinel's frame), using whatever is the current inferior_ptid (usually null_ptid), and assumes get_current_regcache will find that in the regcache::current_regcache list. This commit changes the way the mock environment is created. It eliminates the special regcache and frame and instead creates a fuller mock environment, with a custom mock target_ops, and then a mock inferior and thread "running" on that target. If there's already a running target when you type "maint selftest", then we error out, instead of pushing a new target on top of the existing one (and thus killing the debug session). This results in: (gdb) maint selftest (...) Self test failed: arch i386: target already pushed Self test failed: arch i386:x86-64: target already pushed Self test failed: arch i386:x64-32: target already pushed Self test failed: arch i8086: target already pushed Self test failed: arch i386:intel: target already pushed Self test failed: arch i386:x86-64:intel: target already pushed Self test failed: arch i386:x64-32:intel: target already pushed Self test failed: arch i386:nacl: target already pushed Self test failed: arch i386:x86-64:nacl: target already pushed Self test failed: arch i386:x64-32:nacl: target already pushed Self test failed: self-test failed at /home/pedro/gdb/mygit/src/gdb/selftest-arch.c:86 (...) Ran 19 unit tests, 1 failed I think that's OK, because self tests are really meant to be run from a clean state right after GDB is started. I'm adding that erroring out just as safe measure just in case someone types "maint selftest" on the command line while already debugging something (as I've done it). (In my multi-target branch, where this patch originated from, we don't actually need to error out, because there each inferior has its own target stack). Also, note that the current code was doing: current_inferior()->gdbarch = gdbarch; without taking care to restore the previous gdbarch. This means that GDB's state was being left inconsistent after running the self tests, further supporting the point that there's probably not much expectation that mixing "maint selftests" and regular debugging in the same GDB invocation really works. This patch fixes that, regardless. gdb/ChangeLog: 2017-10-04 Pedro Alves <palves@redhat.com> * frame.c (create_test_frame): Delete. * frame.h (create_test_frame): Delete. * gdbarch-selftests.c: Include gdbthread.h and target.h. (class regcache_test): Delete. (test_target_has_registers, test_target_has_stack) (test_target_has_memory, test_target_prepare_to_store) (test_target_store_registers): New functions. (test_target_ops): New class. (register_to_value_test): Error out if there's already a process_stratum (or higher) target pushed. Create a fuller mock environment, with mock target_ops, inferior, address space, thread and inferior_ptid. * progspace.c (struct address_space): Move to ... * progspace.h (struct address_space): ... here. * regcache.h (regcache::~regcache, regcache::raw_write) [GDB_SELF_TEST]: No longer virtual.
* Constify maintenance_info_program_spaces_commandTom Tromey2017-09-271-1/+1
| | | | | | | | gdb/ChangeLog 2017-09-27 Tom Tromey <tom@tromey.com> * progspace.c (maintenance_info_program_spaces_command): Constify.
* Introduce and use ui_out_emit_tableTom Tromey2017-08-031-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | This introduces ui_out_emit_table, similar to the other existing ui_out RAII classes, and then uses it in a number of places. This replaces some cleanups. ChangeLog 2017-08-03 Tom Tromey <tom@tromey.com> * tracepoint.c (tvariables_info_1): Use ui_out_emit_table. (info_static_tracepoint_markers_command): Likewise. * solib.c (info_sharedlibrary_command): Use ui_out_emit_table. * skip.c (skip_info): Use ui_out_emit_table. * progspace.c (print_program_space): Use ui_out_emit_table. * osdata.c (info_osdata): Use ui_out_emit_table. * mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions): Use ui_out_emit_table. * linux-thread-db.c (info_auto_load_libthread_db): Use ui_out_emit_table. * inferior.c (print_inferior): Use ui_out_emit_table. * gdb_bfd.c (maintenance_info_bfds): Use ui_out_emit_table. * breakpoint.c (breakpoint_1): Use ui_out_emit_table. * auto-load.c (auto_load_info_scripts): Use ui_out_emit_table. * ada-tasks.c (print_ada_task_info): Use ui_out_emit_table. * ui-out.h (class ui_out_emit_table): New.
* RAII-fy make_cleanup_restore_current_thread & friendsPedro Alves2017-05-041-77/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After all the make_cleanup_restore_current_thread fixing, I thought I'd convert that and its relatives (which are all cleanups) to RAII classes. scoped_restore_current_pspace_and_thread was put in a separate file to avoid a circular dependency. Tested on x86-64 Fedora 23, native and gdbserver. gdb/ChangeLog: 2017-05-04 Pedro Alves <palves@redhat.com> * Makefile.in (SFILES): Add progspace-and-thread.c. (HFILES_NO_SRCDIR): Add progspace-and-thread.h. (COMMON_OBS): Add progspace-and-thread.o. * breakpoint.c: Include "progspace-and-thread.h". (update_inserted_breakpoint_locations) (insert_breakpoint_locations, create_longjmp_master_breakpoint): Use scoped_restore_current_pspace_and_thread. (create_std_terminate_master_breakpoint): Use scoped_restore_current_program_space. (remove_breakpoint): Use scoped_restore_current_pspace_and_thread. (print_breakpoint_location): Use scoped_restore_current_program_space. (bp_loc_is_permanent): Use scoped_restore_current_pspace_and_thread. (resolve_sal_pc): Use scoped_restore_current_pspace_and_thread. (download_tracepoint_locations): Use scoped_restore_current_pspace_and_thread. (breakpoint_re_set): Use scoped_restore_current_pspace_and_thread. * exec.c (exec_close_1): Use scoped_restore_current_program_space. (enum step_over_calls_kind): Moved from inferior.h. (class scoped_restore_current_thread): New class. * gdbthread.h (make_cleanup_restore_current_thread): Delete declaration. (scoped_restore_current_thread): New class. * infcmd.c: Include "common/gdb_optional.h". (continue_1, proceed_after_attach): Use scoped_restore_current_thread. (notice_new_inferior): Use scoped_restore_current_thread. * inferior.c: Include "progspace-and-thread.h". (restore_inferior, save_current_inferior): Delete. (add_inferior_command, clone_inferior_command): Use scoped_restore_current_pspace_and_thread. * inferior.h (scoped_restore_current_inferior): New class. * infrun.c: Include "progspace-and-thread.h" and "common/gdb_optional.h". (follow_fork_inferior): Use scoped_restore_current_pspace_and_thread. (scoped_restore_exited_inferior): New class. (handle_vfork_child_exec_or_exit): Use scoped_restore_exited_inferior, scoped_restore_current_pspace_and_thread, scoped_restore_current_thread and scoped_restore. (fetch_inferior_event): Use scoped_restore_current_thread. * linespec.c (decode_line_full, decode_line_1): Use scoped_restore_current_program_space. * mi/mi-main.c: Include "progspace-and-thread.h". (exec_continue): Use scoped_restore_current_thread. (mi_cmd_exec_run): Use scoped_restore_current_pspace_and_thread. (mi_cmd_trace_frame_collected): Use scoped_restore_current_thread. * proc-service.c (ps_pglobal_lookup): Use scoped_restore_current_program_space. * progspace-and-thread.c: New file. * progspace-and-thread.h: New file. * progspace.c (release_program_space, clone_program_space): Use scoped_restore_current_program_space. (restore_program_space, save_current_program_space) (save_current_space_and_thread): Delete. (switch_to_program_space_and_thread): Moved to progspace-and-thread.c. * progspace.h (save_current_program_space) (save_current_space_and_thread): Delete declarations. (scoped_restore_current_program_space): New class. * remote.c (remote_btrace_maybe_reopen): Use scoped_restore_current_thread. * symtab.c: Include "progspace-and-thread.h". (skip_prologue_sal): Use scoped_restore_current_pspace_and_thread. * thread.c (print_thread_info_1): Use scoped_restore_current_thread. (struct current_thread_cleanup): Delete. (do_restore_current_thread_cleanup) (restore_current_thread_cleanup_dtor): Rename/convert both to ... (scoped_restore_current_thread::~scoped_restore_current_thread): ... this new dtor. (make_cleanup_restore_current_thread): Rename/convert to ... (scoped_restore_current_thread::scoped_restore_current_thread): ... this new ctor. (thread_apply_all_command): Use scoped_restore_current_thread. (thread_apply_command): Use scoped_restore_current_thread. * tracepoint.c (tdump_command): Use scoped_restore_current_thread. * varobj.c (value_of_root_1): Use scoped_restore_current_thread.
* Use ui_out_emit_tupleTom Tromey2017-04-221-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch changes various places to use ui_out_emit_tuple, eliminating a number of cleanups. This patch only tackles "easy" cases, which are ones where the cleanups in question were block-structured and did not involve any changes other than the obvious replacement. ChangeLog 2017-04-22 Tom Tromey <tom@tromey.com> * record-btrace.c (record_btrace_insn_history) (record_btrace_insn_history_range, record_btrace_call_history) (record_btrace_call_history_range): Use ui_out_emit_tuple. * thread.c (do_captured_list_thread_ids, print_thread_info_1): Use ui_out_emit_tuple. * stack.c (print_frame_info): Use ui_out_emit_tuple. * solib.c (info_sharedlibrary_command): Use ui_out_emit_tuple. * skip.c (skip_info): Use ui_out_emit_tuple. * remote.c (show_remote_cmd): Use ui_out_emit_tuple. * progspace.c (print_program_space): Use ui_out_emit_tuple. * probe.c (info_probes_for_ops): Use ui_out_emit_tuple. * osdata.c (info_osdata): Use ui_out_emit_tuple. * mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Use ui_out_emit_tuple. * mi/mi-main.c (print_one_inferior, list_available_thread_groups) (output_register, mi_cmd_data_read_memory) (mi_cmd_data_read_memory_bytes, mi_load_progress) (mi_cmd_trace_frame_collected): Use ui_out_emit_tuple. * mi/mi-cmd-var.c (mi_cmd_var_list_children, varobj_update_one): Use ui_out_emit_tuple. * mi/mi-cmd-stack.c (mi_cmd_stack_list_args): Use ui_out_emit_tuple. * mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions) (mi_cmd_info_gdb_mi_command): Use ui_out_emit_tuple. * linux-thread-db.c (info_auto_load_libthread_db): Use ui_out_emit_tuple. * inferior.c (print_inferior): Use ui_out_emit_tuple. * gdb_bfd.c (print_one_bfd): Use ui_out_emit_tuple. * disasm.c (do_mixed_source_and_assembly_deprecated) (do_mixed_source_and_assembly): Use ui_out_emit_tuple. * cp-abi.c (list_cp_abis): Use ui_out_emit_tuple. * cli/cli-setshow.c (cmd_show_list): Use ui_out_emit_tuple. * breakpoint.c (print_one_breakpoint_location) (print_one_breakpoint): Use ui_out_emit_tuple. * auto-load.c (print_script, info_auto_load_cmd): Use ui_out_emit_tuple. * ada-tasks.c (print_ada_task_info): Use ui_out_emit_tuple.
* update copyright year range in GDB filesJoel Brobecker2017-01-011-1/+1
| | | | | | | | | This applies the second part of GDB's End of Year Procedure, which updates the copyright year range in all of GDB's files. gdb/ChangeLog: Update copyright year range in all GDB files.
* Class-ify ui_outSimon Marchi2016-12-221-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch finalizes the C++ conversion of the ui-out subsystem, by turning the ui_out and ui_out_impl structures into a single class hierarchy. ui_out functions are turned into virtual methods of that new class, so as a result there are a lot of call sites to update. In the previous version of the patchset, there were separate ui_out and ui_out_impl classes, but it wasn't really useful and added boilerplate. In this version there is simply an ui_out base class that is extended for CLI, TUI and MI. It's a bit hard to maintain a ChangeLog for such a big patch, I did my best but I'm sure there are some missing or outdated info in there... gdb/ChangeLog: * ui-out.h (ui_out_begin, ui_out_end, ui_out_table_header, ui_out_table_body, ui_out_field_int, ui_out_field_fmt_int, ui_out_field_core_addr, ui_out_field_string, ui_out_field_stream, ui_out_field_fmt, ui_out_field_skip, ui_out_spaces, ui_out_text, ui_out_message, ui_out_wrap_hint, ui_out_flush, ui_out_test_flags, ui_out_query_field, ui_out_is_mi_like_p, ui_out_redirect): Remove, replace with a method in class ui_out. (table_begin_ftype): Remove, replace with pure virtual method in class ui_out. (table_body_ftype): Likewise. (table_end_ftype): Likewise. (table_header_ftype): Likewise. (ui_out_begin_ftype): Likewise. (ui_out_end_ftype): Likewise. (field_int_ftype): Likewise. (field_skip_ftype): Likewise. (field_string_ftype): Likewise. (field_fmt_ftype): Likewise. (spaces_ftype): Likewise. (text_ftype): Likewise. (message_ftype): Likewise. (wrap_hint_ftype): Likewise. (flush_ftype): Likewise. (redirect_ftype): Likewise. (data_destroy_ftype): Likewise. (struct ui_out_impl): Remove, replace with class ui_out. (ui_out_new): Remove. (class ui_out): New class. * ui-out.c (struct ui_out): Remove, replaced with class ui_out. (current_level): Remove, replace with ui_out method. (push_level): Likewise. (pop_level): Likewise. (uo_table_begin, uo_table_body, uo_table_end, uo_table_header, uo_begin, uo_end, uo_field_int, uo_field_skip, uo_field_fmt, uo_spaces, uo_text, uo_message, uo_wrap_hint, uo_flush, uo_redirect, uo_field_string): Remove. (ui_out_table_begin): Replace with ... (ui_out::table_begin): ... this. (ui_out_table_body): Replace with ... (ui_out::table_body): ... this. (ui_out_table_end): Replace with ... (ui_out::table_end): ... this. (ui_out_table_header): Replace with ... (ui_out::table_header): ... this. (ui_out_begin): Replace with ... (ui_out::begin): ... this. (ui_out_end): Replace with ... (ui_out::end): ... this. (ui_out_field_int): Replace with ... (ui_out::field_int): ... this. (ui_out_field_fmt_int): Replace with ... (ui_out::field_fmt_int): ... this. (ui_out_field_core_addr): Replace with ... (ui_out::field_core_addr): ... this. (ui_out_field_stream): Replace with ... (ui_out::field_stream): ... this. (ui_out_field_skip): Replace with ... (ui_out::field_skip): ... this. (ui_out_field_string): Replace with ... (ui_out::field_string): ... this. (ui_out_field_fmt): Replace with ... (ui_out::field_fmt): ... this. (ui_out_spaces): Replace with ... (ui_out::spaces): ... this. (ui_out_text): Replace with ... (ui_out::text): ... this. (ui_out_message): Replace with ... (ui_out::message): ... this. (ui_out_wrap_hint): Replace with ... (ui_out::wrap_hint): ... this. (ui_out_flush): Replace with ... (ui_out::flush): ... this. (ui_out_redirect): Replace with ... (ui_out::redirect): ... this. (ui_out_test_flags): Replace with ... (ui_out::test_flags): ... this. (ui_out_is_mi_like_p): Replace with ... (ui_out::is_mi_like_p): ... this. (verify_field): Replace with ... (ui_out::verify_field): ... this. (ui_out_query_field): Replace with ... (ui_out::query_table_field): ... this. (ui_out_data): Remove. (ui_out_new): Remove, replace with ... (ui_out::ui_out): ... this constructor. (do_cleanup_table_end, make_cleanup_ui_out_tuple_begin_end, do_cleanup_end, make_cleanup_ui_out_tuple_begin_end, make_cleanup_ui_out_list_begin_end): Update fallouts of struct ui_out -> class ui_out change. * cli-out.c (cli_out_data): Remove. (cli_uiout_dtor): Remove. (cli_table_begin): Replace with ... (cli_ui_out::do_table_begin): ... this new method. (cli_table_body): Replace with ... (cli_ui_out::do_table_body): ... this new method. (cli_table_end): Replace with ... (cli_ui_out::do_table_end): ... this new method. (cli_table_header): Replace with ... (cli_ui_out::do_table_header): ... this new method. (cli_begin): Replace with ... (cli_ui_out::do_begin): ... this new method. (cli_end): Replace with ... (cli_ui_out::do_end): ... this new method. (cli_field_int): Replace with ... (cli_ui_out::do_field_int): ... this new method. (cli_field_skip): Replace with ... (cli_ui_out::do_field_skip): ... this new method. (cli_field_string): Replace with ... (cli_ui_out::do_field_string): ... this new method. (cli_field_fmt): Replace with ... (cli_ui_out::do_field_fmt): ... this new method. (cli_spaces): Replace with ... (cli_ui_out::do_spaces): ... this new method. (cli_text): Replace with ... (cli_ui_out::do_text): ... this new method. (cli_message): Replace with ... (cli_ui_out::do_message): ... this new method. (cli_wrap_hint): Replace with ... (cli_ui_out::do_wrap_hint): ... this new method. (cli_flush): Replace with ... (cli_ui_out::do_flush): ... this new method. (cli_redirect): Replace with ... (cli_ui_out::do_redirect): ... this new method. (out_field_fmt): Replace with ... (cli_ui_out::out_field_fmt): ... this new method. (field_separator): Replace with ... (cli_ui_out::field_separator): ... this new method. (cli_out_set_stream): Replace with ... (cli_ui_out::set_stream): ... this new method. (cli_ui_out_impl): Remove. (cli_out_data_ctor): Remove. (cli_ui_out_impl::cli_ui_out_impl): New constructor. (cli_ui_out_impl::~cli_ui_out_impl): New destructor. (cli_out_new): Change return type to cli_ui_out *, instantiate a cli_ui_out. * cli-out.h (cli_ui_out_data): Remove, replace with class cli_ui_out. (class cli_ui_out): New class. (cli_ui_out_impl): Remove. (cli_out_data_ctor): Remove. (cli_out_new): Change return type to cli_ui_out*. (cli_out_set_stream): Remove. * cli/cli-interp.c (struct cli_interp) <cli_uiout>: Change type to cli_ui_out*. (cli_interpreter_resume): Adapt. (cli_interpreter_exec): Adapt. * mi/mi-out.c (mi_ui_out_data, mi_out_data): Remove. (mi_ui_out_impl): Remove. (mi_table_begin): Replace with ... (mi_ui_out::do_table_begin): ... this. (mi_table_body): Replace with ... (mi_ui_out::do_table_body): ... this. (mi_table_end): Replace with ... (mi_ui_out::do_table_end): ... this. (mi_table_header): Replace with ... (mi_ui_out::do_table_header): ... this. (mi_begin): Replace with ... (mi_ui_out::do_begin): ... this. (mi_end): Replace with ... (mi_ui_out::do_end): ... this. (mi_field_int): Replace with ... (mi_ui_out::do_field_int): ... this. (mi_field_skip): Replace with ... (mi_ui_out::do_field_skip): ... this. (mi_field_string): Replace with ... (mi_ui_out::do_field_string): ... this. (mi_field_fmt): Replace with ... (mi_ui_out::do_field_fmt): ... this. (mi_spaces): Replace with ... (mi_ui_out::do_spaces): ... this. (mi_text): Replace with ... (mi_ui_out::do_text): ... this. (mi_message): Replace with ... (mi_ui_out::do_message): ... this. (mi_wrap_hint): Replace with ... (mi_ui_out::do_wrap_hint): ... this. (mi_flush): Replace with ... (mi_ui_out::do_flush): ... this. (mi_redirect): Replace with ... (mi_ui_out::do_redirect): (field_separator): Replace with ... (mi_ui_out::field_separator): (mi_open): Replace with ... (mi_ui_out::open): ... this. (mi_close): Replace with ... (mi_ui_out::close): ... this. (mi_out_rewind): Replace with ... (mi_ui_out::rewind): ... this. (mi_out_put): Replace with ... (mi_ui_out::put): ... this. (mi_version): Replace with ... (mi_ui_out::version): ... this. (mi_out_data_ctor): Replace with ... (mi_ui_out::mi_ui_out): ... this. (mi_out_data_dtor): Replace with ... (mi_ui_out::~mi_ui_out): ... this. (mi_out_new): Change return type to mi_ui_out*, instantiate an mi_ui_out object. (as_mi_ui_out): New function. (mi_version): Update fallouts of struct ui_out to class ui_out transition. (mi_out_put): Likewise. (mi_out_rewind): Likewise. * mi/mi-out.h (mi_out_new): Change return type to mi_ui_out*. * tui/tui-out.c (tui_ui_out_data, tui_out_data, tui_ui_out_impl): Remove. (tui_field_int): Replace with ... (tui_ui_out::do_field_int): ... this. (tui_field_string): Replace with ... (tui_ui_out::do_field_string): ... this. (tui_field_fmt): Replace with ... (tui_ui_out::do_field_fmt): ... this. (tui_text): Replace with ... (tui_ui_out::do_text): ... this. (tui_out_new): Change return type to tui_ui_out*, instantiate tui_ui_out object. (tui_ui_out::tui_ui_out): New. * tui/tui-out.h: New file. * tui/tui.h (tui_out_new): Move declaration to tui/tui-out.h. * tui/tui-io.c: Include tui/tui-out.h. (tui_old_uiout): Change type to cli_ui_out*. (tui_setup_io): Use dynamic_cast. * tui/tui-io.h (tui_old_uiout): Change type to cli_ui_out*. * tui/tui-interp.c (tui_resume): Adapt. * ada-lang.c (print_it_exception): Update fallouts of struct ui_out to class ui_out transition. (print_one_exception): Likewise. (print_mention_exception): Likewise. * ada-tasks.c (print_ada_task_info): Likewise. (info_task): Likewise. (task_command): Likewise. * auto-load.c (print_script): Likewise. (auto_load_info_scripts): Likewise. (info_auto_load_cmd): Likewise. * break-catch-sig.c (signal_catchpoint_print_one): Likewise. * break-catch-syscall.c (print_it_catch_syscall): Likewise. (print_one_catch_syscall): Likewise. * break-catch-throw.c (print_it_exception_catchpoint): Likewise. (print_one_exception_catchpoint): Likewise. (print_one_detail_exception_catchpoint): Likewise. (print_mention_exception_catchpoint): Likewise. * breakpoint.c (maybe_print_thread_hit_breakpoint): Likewise. (print_solib_event): Likewise. (watchpoint_check): Likewise. (wrap_indent_at_field): Likewise. (print_breakpoint_location): Likewise. (output_thread_groups): Likewise. (print_one_breakpoint_location): Likewise. (breakpoint_1): Likewise. (default_collect_info): Likewise. (watchpoints_info): Likewise. (print_it_catch_fork): Likewise. (print_one_catch_fork): Likewise. (print_it_catch_vfork): Likewise. (print_one_catch_vfork): Likewise. (print_it_catch_solib): Likewise. (print_one_catch_solib): Likewise. (print_it_catch_exec): Likewise. (print_one_catch_exec): Likewise. (mention): Likewise. (print_it_ranged_breakpoint): Likewise. (print_one_ranged_breakpoint): Likewise. (print_one_detail_ranged_breakpoint): Likewise. (print_mention_ranged_breakpoint): Likewise. (print_it_watchpoint): Likewise. (print_mention_watchpoint): Likewise. (print_it_masked_watchpoint): Likewise. (print_one_detail_masked_watchpoint): Likewise. (print_mention_masked_watchpoint): Likewise. (bkpt_print_it): Likewise. (tracepoint_print_one_detail): Likewise. (tracepoint_print_mention): Likewise. (update_static_tracepoint): Likewise. (tracepoints_info): Likewise. (save_breakpoints): Likewise. * cli/cli-cmds.c (complete_command): Likewise. * cli/cli-logging.c (set_logging_redirect): Likewise. (pop_output_files): Likewise. (handle_redirections): Likewise. * cli/cli-script.c (print_command_lines): Likewise. * cli/cli-setshow.c (do_show_command): Likewise. (cmd_show_list): Likewise. * cp-abi.c (list_cp_abis): Likewise. (show_cp_abi_cmd): Likewise. * darwin-nat-info.c (darwin_debug_regions_recurse): Likewise. * disasm.c (gdb_pretty_print_insn): Likewise. (do_mixed_source_and_assembly_deprecated): Likewise. (do_mixed_source_and_assembly): Likewise. * gdb_bfd.c (print_one_bfd): Likewise. (maintenance_info_bfds): Likewise. * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Likewise. * guile/scm-ports.c (ioscm_with_output_to_port_worker): Likewise. * i386-linux-tdep.c (i386_linux_handle_segmentation_fault): Likewise. * i386-tdep.c (i386_mpx_print_bounds): Likewise. * infcmd.c (run_command_1): Likewise. (print_return_value_1): Likewise. * inferior.c (print_selected_inferior): Likewise. (print_inferior): Likewise. * infrun.c (print_end_stepping_range_reason): Likewise. (print_signal_exited_reason): Likewise. (print_exited_reason): Likewise. (print_signal_received_reason): Likewise. (print_no_history_reason): Likewise. * interps.c (interp_set): Likewise. * linespec.c (decode_line_full): Likewise. * linux-thread-db.c (info_auto_load_libthread_db): Likewise. * mi/mi-cmd-env.c (mi_cmd_env_pwd): Likewise. (mi_cmd_env_path): Likewise. (mi_cmd_env_dir): Likewise. (mi_cmd_inferior_tty_show): Likewise. * mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_file): Likewise. (print_partial_file_name): Likewise. (mi_cmd_file_list_exec_source_files): Likewise. * mi/mi-cmd-info.c (mi_cmd_info_ada_exceptions): Likewise. (mi_cmd_info_gdb_mi_command): Likewise. * mi/mi-cmd-stack.c (mi_cmd_stack_info_depth): Likewise. (mi_cmd_stack_list_args): Likewise. (list_arg_or_local): Likewise. * mi/mi-cmd-var.c (print_varobj): Likewise. (mi_cmd_var_create): Likewise. (mi_cmd_var_delete): Likewise. (mi_cmd_var_set_format): Likewise. (mi_cmd_var_show_format): Likewise. (mi_cmd_var_info_num_children): Likewise. (mi_cmd_var_list_children): Likewise. (mi_cmd_var_info_type): Likewise. (mi_cmd_var_info_path_expression): Likewise. (mi_cmd_var_info_expression): Likewise. (mi_cmd_var_show_attributes): Likewise. (mi_cmd_var_evaluate_expression): Likewise. (mi_cmd_var_assign): Likewise. (varobj_update_one): Likewise. * mi/mi-interp.c (as_mi_interp): Likewise. (mi_on_normal_stop_1): Likewise. (mi_tsv_modified): Likewise. (mi_breakpoint_created): Likewise. (mi_breakpoint_modified): Likewise. (mi_solib_loaded): Likewise. (mi_solib_unloaded): Likewise. (mi_command_param_changed): Likewise. (mi_memory_changed): Likewise. (mi_user_selected_context_changed): Likewise. * mi/mi-main.c (print_one_inferior): Likewise. (output_cores): Likewise. (list_available_thread_groups): Likewise. (mi_cmd_data_list_register_names): Likewise. (mi_cmd_data_list_changed_registers): Likewise. (output_register): Likewise. (mi_cmd_data_evaluate_expression): Likewise. (mi_cmd_data_read_memory): Likewise. (mi_cmd_data_read_memory_bytes): Likewise. (mi_cmd_list_features): Likewise. (mi_cmd_list_target_features): Likewise. (mi_cmd_add_inferior): Likewise. (mi_execute_command): Likewise. (mi_load_progress): Likewise. (print_variable_or_computed): Likewise. (mi_cmd_trace_frame_collected): Likewise. * mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Likewise. * osdata.c (info_osdata_command): Likewise. * probe.c (gen_ui_out_table_header_info): Likewise. (print_ui_out_not_applicables): Likewise. (print_ui_out_info): Likewise. (info_probes_for_ops): Likewise. (enable_probes_command): Likewise. (disable_probes_command): Likewise. * progspace.c (print_program_space): Likewise. * python/py-breakpoint.c (bppy_get_commands): Likewise. * python/py-framefilter.c (py_print_type): Likewise. (py_print_value): Likewise. (py_print_single_arg): Likewise. (enumerate_args): Likewise. (enumerate_locals): Likewise. (py_print_args): Likewise. (py_print_frame): Likewise. * record-btrace.c (btrace_ui_out_decode_error): Likewise. (btrace_call_history_insn_range): Likewise. (btrace_call_history_src_line): Likewise. (btrace_call_history): Likewise. * remote.c (show_remote_cmd): Likewise. * skip.c (skip_info): Likewise. * solib.c (info_sharedlibrary_command): Likewise. * source.c (print_source_lines_base): Likewise. * spu-tdep.c (info_spu_event_command): Likewise. (info_spu_signal_command): Likewise. (info_spu_mailbox_list): Likewise. (info_spu_dma_cmdlist): Likewise. (info_spu_dma_command): Likewise. (info_spu_proxydma_command): Likewise. * stack.c (print_stack_frame): Likewise. (print_frame_arg): Likewise. (read_frame_arg): Likewise. (print_frame_args): Likewise. (print_frame_info): Likewise. (print_frame): Likewise. * symfile.c (load_progress): Likewise. (generic_load): Likewise. (print_transfer_performance): Likewise. * thread.c (do_captured_list_thread_ids): Likewise. (print_thread_info_1): Likewise. (restore_selected_frame): Likewise. (do_captured_thread_select): Likewise. (print_selected_thread_frame): Likewise. * top.c (execute_command_to_string): Likewise. * tracepoint.c (tvariables_info_1): Likewise. (trace_status_mi): Likewise. (tfind_1): Likewise. (print_one_static_tracepoint_marker): Likewise. (info_static_tracepoint_markers_command): Likewise. * utils.c (do_ui_out_redirect_pop): Likewise. (fputs_maybe_filtered): Likewise.