binutils-gdb/gdb/inferior.h

682 lines
22 KiB
C
Raw Permalink Normal View History

/* Variables that describe the inferior process running under GDB:
Where it is, why it stopped, and how to step it.
Copyright (C) 1986-2020 Free Software Foundation, Inc.
1999-07-07 22:19:36 +02:00
This file is part of GDB.
1999-07-07 22:19:36 +02:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
1999-07-07 22:19:36 +02:00
(at your option) any later version.
1999-07-07 22:19:36 +02:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
1999-07-07 22:19:36 +02:00
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#if !defined (INFERIOR_H)
#define INFERIOR_H 1
struct target_waitstatus;
struct frame_info;
struct ui_file;
struct type;
struct gdbarch;
struct regcache;
struct ui_out;
* inflow.h (our_process_group): Remove declaration. (inferior_process_group): Delete global variable declaration. (inferior_process_group): New function declaration. * inflow.c: Include observer.h. (inferior_ttystate, our_ttystate, tflags_inferior, tflags_ours): Delete. (struct terminal_info): New struct. (our_terminal_info): New global. (inferior_process_group): New function. (inferior_thisrun_terminal): Extend description comment. (gdb_has_a_terminal): Adjust to write to our_terminal_info fields instead of globals. (terminal_init_inferior_with_pgrp): Adjust to per-inferior terminal settings. (terminal_inferior): Ditto. (terminal_ours_1): Ditto. (inflow_new_inferior, inflow_inferior_exit): New functions. (child_terminal_info): Adjust to per-inferior terminal settings. (osig_set): New global. (set_sigint_trap): Adjust to per-inferior terminal settings. Set or clear `osig_set' accordingly. (clear_sigint_trap): Check `osig_set' to decide wheater to restore SIGINT handler, instead of checking the current inferior (which may be none). (_initialize_inflow): Attach inflow_new_inferior and inflow_inferior_exit to the "new_inferior" and "inferior_exit" notifications, respectively. * inferior.h (struct terminal_info): Forward declare. (struct inferior): Add `terminal_info' field. * inferior.c (delete_inferior_1): Notify the inferior_exit observers before removing the inferior from the lists and deleting it. * inf-ptrace.c (inf_ptrace_stop): `inferior_process_group' is now a function instead of a variable. Adjust. * procfs.c (procfs_stop): Ditto.
2009-05-18 02:58:38 +02:00
struct terminal_info;
gdb/ 2012-11-09 Pedro Alves <palves@redhat.com> * gdbarch.sh (target_gdbarch) <gdbarch.h>: Reimplement as macro. (get_target_gdbarch) <gdbarch.h>: New function. (startup_gdbarch) <gdbarch.h>: Declare. <gdbarch.c> (target_gdbarch): Delete. <gdbarch.c> (deprecated_target_gdbarch_select_hack): Set the current inferior's gdbarch. <gdbarch.c> (get_target_gdbarch): New function. * inferior.c: Include target-descriptions.h. (free_inferior): Free target description info. (add_inferior_with_spaces): Set the inferior's initial architecture. (clone_inferior_command): Copy the original inferior's target description if it was user specified. (initialize_inferiors): Add comment. * inferior.h (struct target_desc_info): Forward declare. (struct inferior) <gdbarch>: New field. * linux-nat.c: Include target-descriptions.h. (linux_child_follow_fork): Copy the parent's architecture and target description to the child. * target-descriptions.c: Include inferior.h. (struct target_desc_info): New structure, holding the equivalents of ... (target_desc_fetched, current_target_desc) (target_description_filename): ... these removed globals. (get_tdesc_info, target_desc_info_from_user_p) (copy_inferior_target_desc_info, target_desc_info_free): New. (target_desc_fetched, current_target_desc) (target_description_filename): Reimplemented as convenience macros. (tdesc_filename_cmd_string): New global. (set_tdesc_filename_cmd): Copy the string manipulated by the "set tdescs filename ..." commands to the per-inferior equivalent. (show_tdesc_filename_cmd): Get the value to show from the per-inferior description filename. (_initilize_target_descriptions): Change the "set/show tdesc filename" commands' variable. * target-descriptions.h (struct target_desc, struct target_desc_info) (struct inferior): Forward declare. (target_find_description, target_clear_description) (target_current_description): Adjust comments. (copy_inferior_target_desc_info, target_desc_info_free) (target_desc_info_from_user_p). Declare. gdb/testsuite/ 2012-11-09 Pedro Alves <palves@redhat.com> * gdb.multi/multi-arch.exp: New.
2012-11-09 02:47:20 +01:00
struct target_desc_info;
struct continuation;
Fix removing inferiors from within "thread apply" commands This patch fixes an internal error exposed by a test that does something like: define kill-and-remove kill inferiors 2 remove-inferiors 2 end # Start one inferior. start # Start another inferior. add-inferior 2 inferior 2 start # Kill and remove inferior 1 while inferior 2 is selected. thread apply 1.1 kill-and-remove The internal error looks like this: Thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677)): [Switching to inferior 1 [process 20677] (gdb/testsuite/outputs/gdb.threads/threadapply/threadapply)] [Switching to thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677))] #0 main () at src/gdb/testsuite/gdb.threads/threadapply.c:38 38 for (i = 0; i < NUM; i++) src/gdb/inferior.c:66: internal-error: void set_current_inferior(inferior*): Assertion `inf != NULL' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) FAIL: gdb.threads/threadapply.exp: kill_and_remove_inferior: try kill-and-remove: thread apply 1.1 kill-and-remove (GDB internal error) There are several problems around this area of the code. One is that in do_restore_current_thread_cleanup, we do a look up of inferior by ptid, which can find the wrong inferior if the previously selected inferior exited and some other inferior was started with a reused pid (rare, but still...). The other problem is that the "remove-inferiors" command rejects attempts to remove the current inferior, but when we get to "remove-inferiors" in a "thread apply THR remove-inferiors 2" command, the current inferior is the inferior of thread THR, not the previously selected inferior, so if the previously selected inferior was inferior 2, that command still manages to wipe it, and then gdb restores the old selected inferior, which is now a dangling pointer... So the fix here is: - Make make_cleanup_restore_current_thread store a pointer to the previously selected inferior directly, and use it directly instead of doing ptid look ups. - Add a refcount to inferiors, very similar to thread_info's refcount, that is incremented/decremented by make_cleanup_restore_current_thread, and checked before deleting an inferior. To avoid duplication, a new refcounted_object type is added, that both thread_info and inferior inherit from. gdb/ChangeLog: 2017-04-19 Pedro Alves <palves@redhat.com> * common/refcounted-object.h: New file. * gdbthread.h: Include "common/refcounted-object.h". (thread_info): Inherit from refcounted_object and add comments. (thread_info::incref, thread_info::decref) (thread_info::m_refcount): Delete. (thread_info::deletable): Use the refcounted_object::refcount() method. * inferior.c (current_inferior_): Add comment. (set_current_inferior): Increment/decrement refcounts. (prune_inferiors, remove_inferior_command): Skip inferiors marked not-deletable instead of comparing with the current inferior. (initialize_inferiors): Increment the initial inferior's refcount. * inferior.h (struct inferior): Forward declare. Include "common/refcounted-object.h". (current_inferior, set_current_inferior): Move declaration to before struct inferior's definition, and fix comment. (inferior): Inherit from refcounted_object. Add comments. * thread.c (switch_to_thread_no_regs): Reference the thread's inferior pointer directly instead of doing a ptid lookup. (switch_to_no_thread): New function. (switch_to_thread(thread_info *)): New function, factored out from ... (switch_to_thread(ptid_t)): ... this. (restore_current_thread): Delete. (current_thread_cleanup): Remove 'inf_id' and 'was_removable' fields, and add 'inf' field. (do_restore_current_thread_cleanup): Check whether old->inf is alive instead of looking up an inferior by ptid. Use switch_to_thread and switch_to_no_thread. (restore_current_thread_cleanup_dtor): Use old->inf directly instead of lookup up an inferior by id. Decref the inferior. Don't restore 'removable'. (make_cleanup_restore_current_thread): Same the inferior pointer in old, instead of the inferior number. Incref the inferior. Don't save/clear 'removable'. gdb/testsuite/ChangeLog: 2017-04-19 Pedro Alves <palves@redhat.com> * gdb.threads/threadapply.exp (kill_and_remove_inferior): New procedure. (top level): Call it. * lib/gdb.exp (gdb_define_cmd): New procedure.
2017-04-19 14:12:23 +02:00
struct inferior;
Use thread_info and inferior pointers more throughout 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.
2018-06-21 18:09:31 +02:00
struct thread_info;
/* For bpstat. */
#include "breakpoint.h"
/* For enum gdb_signal. */
#include "target.h"
/* For struct frame_id. */
#include "frame.h"
C++ify gdb/common/environ.c As part of the preparation necessary for my upcoming task, I'd like to propose that we turn gdb_environ into a class. The approach taken here is simple: the class gdb_environ contains everything that is needed to manipulate the environment variables. These variables are stored in an std::vector<char *>, which can be converted to a 'char **' and passed as argument to functions that need it. The usage has not changed much. As per Pedro's suggestion, this class uses a static factory method initialization. This means that when an instance is created, it is initially empty. When needed, it has to be initialized using the static method 'from_host_environ'. As mentioned before, this is a preparation for an upcoming work that I will be posting in the next few weeks or so. For that work, I'll probably create another data structure that will contain all the environment variables that were set by the user using the 'set environment' command, because I'll need access to them. This will be much easier with the class-ification of gdb_environ. As noted, this has been regression-tested with the new version of environ.exp and no regressions were found. gdb/ChangeLog: 2017-06-20 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add 'unittests/environ-selftests.c'. (SUBDIR_UNITTESTS_OBS): Add 'environ-selftests.o'. * charset.c (find_charset_names): Declare object 'iconv_env'. Update code to use 'iconv_env' object. Remove call to 'free_environ'. * common/environ.c: Include <utility>. (make_environ): Delete function. (free_environ): Delete function. (gdb_environ::clear): New function. (gdb_environ::operator=): New function. (gdb_environ::get): Likewise. (environ_vector): Delete function. (set_in_environ): Delete function. (gdb_environ::set): New function. (unset_in_environ): Delete function. (gdb_environ::unset): New function. (gdb_environ::envp): Likewise. * common/environ.h: Include <vector>. (struct gdb_environ): Delete; transform into... (class gdb_environ): ... this class. (free_environ): Delete prototype. (init_environ, get_in_environ, set_in_environ, unset_in_environ, environ_vector): Likewise. * infcmd.c (run_command_1): Update code to call 'envp' from 'gdb_environ' class. (environment_info): Update code to call methods from 'gdb_environ' class. (unset_environment_command): Likewise. (path_info): Likewise. (path_command): Likewise. * inferior.c (inferior::~inferior): Delete call to 'free_environ'. (inferior::inferior): Initialize 'environment' using the host's information. * inferior.h: Remove forward declaration of 'struct gdb_environ'. Include "environ.h". (class inferior) <environment>: Change type from 'struct gdb_environ' to 'gdb_environ'. * mi/mi-cmd-env.c (mi_cmd_env_path): Update code to call methods from 'gdb_environ' class. * solib.c (solib_find_1): Likewise * unittests/environ-selftests.c: New file. gdb/gdbserver/ChangeLog: 2017-06-20 Sergio Durigan Junior <sergiodj@redhat.com> * linux-low.c (linux_create_inferior): Adjust code to access the environment information via 'gdb_environ' class. * lynx-low.c (lynx_create_inferior): Likewise. * server.c (our_environ): Make it an instance of 'gdb_environ'. (get_environ): Return a pointer to 'our_environ'. (captured_main): Initialize 'our_environ'. * server.h (get_environ): Adjust prototype. * spu-low.c (spu_create_inferior): Adjust code to access the environment information via 'gdb_environ' class.
2017-02-11 03:19:44 +01:00
/* For gdb_environ. */
Rename common to gdbsupport This is the next patch in the ongoing series to move gdbsever to the top level. This patch just renames the "common" directory. The idea is to do this move in two parts: first rename the directory (this patch), then move the directory to the top. This approach makes the patches a bit more tractable. I chose the name "gdbsupport" for the directory. However, as this patch was largely written by sed, we could pick a new name without too much difficulty. Tested by the buildbot. gdb/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * contrib/ari/gdb_ari.sh: Change common to gdbsupport. * configure: Rebuild. * configure.ac: Change common to gdbsupport. * gdbsupport: Rename from common. * acinclude.m4: Change common to gdbsupport. * Makefile.in (CONFIG_SRC_SUBDIR, COMMON_SFILES) (HFILES_NO_SRCDIR, stamp-version, ALLDEPFILES): Change common to gdbsupport. * aarch64-tdep.c, ada-lang.c, ada-lang.h, agent.c, alloc.c, amd64-darwin-tdep.c, amd64-dicos-tdep.c, amd64-fbsd-nat.c, amd64-fbsd-tdep.c, amd64-linux-nat.c, amd64-linux-tdep.c, amd64-nbsd-tdep.c, amd64-obsd-tdep.c, amd64-sol2-tdep.c, amd64-tdep.c, amd64-windows-tdep.c, arch-utils.c, arch/aarch64-insn.c, arch/aarch64.c, arch/aarch64.h, arch/amd64.c, arch/amd64.h, arch/arm-get-next-pcs.c, arch/arm-linux.c, arch/arm.c, arch/i386.c, arch/i386.h, arch/ppc-linux-common.c, arch/riscv.c, arch/riscv.h, arch/tic6x.c, arm-tdep.c, auto-load.c, auxv.c, ax-gdb.c, ax-general.c, ax.h, breakpoint.c, breakpoint.h, btrace.c, btrace.h, build-id.c, build-id.h, c-lang.h, charset.c, charset.h, cli/cli-cmds.c, cli/cli-cmds.h, cli/cli-decode.c, cli/cli-dump.c, cli/cli-option.h, cli/cli-script.c, coff-pe-read.c, command.h, compile/compile-c-support.c, compile/compile-c.h, compile/compile-cplus-symbols.c, compile/compile-cplus-types.c, compile/compile-cplus.h, compile/compile-loc2c.c, compile/compile.c, completer.c, completer.h, contrib/ari/gdb_ari.sh, corefile.c, corelow.c, cp-support.c, cp-support.h, cp-valprint.c, csky-tdep.c, ctf.c, darwin-nat.c, debug.c, defs.h, disasm-selftests.c, disasm.c, disasm.h, dtrace-probe.c, dwarf-index-cache.c, dwarf-index-cache.h, dwarf-index-write.c, dwarf2-frame.c, dwarf2expr.c, dwarf2loc.c, dwarf2read.c, event-loop.c, event-top.c, exceptions.c, exec.c, extension.h, fbsd-nat.c, features/aarch64-core.c, features/aarch64-fpu.c, features/aarch64-pauth.c, features/aarch64-sve.c, features/i386/32bit-avx.c, features/i386/32bit-avx512.c, features/i386/32bit-core.c, features/i386/32bit-linux.c, features/i386/32bit-mpx.c, features/i386/32bit-pkeys.c, features/i386/32bit-segments.c, features/i386/32bit-sse.c, features/i386/64bit-avx.c, features/i386/64bit-avx512.c, features/i386/64bit-core.c, features/i386/64bit-linux.c, features/i386/64bit-mpx.c, features/i386/64bit-pkeys.c, features/i386/64bit-segments.c, features/i386/64bit-sse.c, features/i386/x32-core.c, features/riscv/32bit-cpu.c, features/riscv/32bit-csr.c, features/riscv/32bit-fpu.c, features/riscv/64bit-cpu.c, features/riscv/64bit-csr.c, features/riscv/64bit-fpu.c, features/tic6x-c6xp.c, features/tic6x-core.c, features/tic6x-gp.c, filename-seen-cache.h, findcmd.c, findvar.c, fork-child.c, gcore.c, gdb_bfd.c, gdb_bfd.h, gdb_proc_service.h, gdb_regex.c, gdb_select.h, gdb_usleep.c, gdbarch-selftests.c, gdbthread.h, gdbtypes.h, gnu-nat.c, go32-nat.c, guile/guile.c, guile/scm-ports.c, guile/scm-safe-call.c, guile/scm-type.c, i386-fbsd-nat.c, i386-fbsd-tdep.c, i386-go32-tdep.c, i386-linux-nat.c, i386-linux-tdep.c, i386-tdep.c, i387-tdep.c, ia64-libunwind-tdep.c, ia64-linux-nat.c, inf-child.c, inf-ptrace.c, infcall.c, infcall.h, infcmd.c, inferior-iter.h, inferior.c, inferior.h, inflow.c, inflow.h, infrun.c, infrun.h, inline-frame.c, language.h, linespec.c, linux-fork.c, linux-nat.c, linux-tdep.c, linux-thread-db.c, location.c, machoread.c, macrotab.h, main.c, maint.c, maint.h, memattr.c, memrange.h, mi/mi-cmd-break.h, mi/mi-cmd-env.c, mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-interp.c, mi/mi-main.c, mi/mi-parse.h, minsyms.c, mips-linux-tdep.c, namespace.h, nat/aarch64-linux-hw-point.c, nat/aarch64-linux-hw-point.h, nat/aarch64-linux.c, nat/aarch64-sve-linux-ptrace.c, nat/amd64-linux-siginfo.c, nat/fork-inferior.c, nat/linux-btrace.c, nat/linux-btrace.h, nat/linux-namespaces.c, nat/linux-nat.h, nat/linux-osdata.c, nat/linux-personality.c, nat/linux-procfs.c, nat/linux-ptrace.c, nat/linux-ptrace.h, nat/linux-waitpid.c, nat/mips-linux-watch.c, nat/mips-linux-watch.h, nat/ppc-linux.c, nat/x86-dregs.c, nat/x86-dregs.h, nat/x86-linux-dregs.c, nat/x86-linux.c, nto-procfs.c, nto-tdep.c, objfile-flags.h, objfiles.c, objfiles.h, obsd-nat.c, observable.h, osdata.c, p-valprint.c, parse.c, parser-defs.h, ppc-linux-nat.c, printcmd.c, probe.c, proc-api.c, procfs.c, producer.c, progspace.h, psymtab.h, python/py-framefilter.c, python/py-inferior.c, python/py-ref.h, python/py-type.c, python/python.c, record-btrace.c, record-full.c, record.c, record.h, regcache-dump.c, regcache.c, regcache.h, remote-fileio.c, remote-fileio.h, remote-sim.c, remote.c, riscv-tdep.c, rs6000-aix-tdep.c, rust-exp.y, s12z-tdep.c, selftest-arch.c, ser-base.c, ser-event.c, ser-pipe.c, ser-tcp.c, ser-unix.c, skip.c, solib-aix.c, solib-target.c, solib.c, source-cache.c, source.c, source.h, sparc-nat.c, spu-linux-nat.c, stack.c, stap-probe.c, symfile-add-flags.h, symfile.c, symfile.h, symtab.c, symtab.h, target-descriptions.c, target-descriptions.h, target-memory.c, target.c, target.h, target/waitstatus.c, target/waitstatus.h, thread-iter.h, thread.c, tilegx-tdep.c, top.c, top.h, tracefile-tfile.c, tracefile.c, tracepoint.c, tracepoint.h, tui/tui-io.c, ui-file.c, ui-out.h, unittests/array-view-selftests.c, unittests/child-path-selftests.c, unittests/cli-utils-selftests.c, unittests/common-utils-selftests.c, unittests/copy_bitwise-selftests.c, unittests/environ-selftests.c, unittests/format_pieces-selftests.c, unittests/function-view-selftests.c, unittests/lookup_name_info-selftests.c, unittests/memory-map-selftests.c, unittests/memrange-selftests.c, unittests/mkdir-recursive-selftests.c, unittests/observable-selftests.c, unittests/offset-type-selftests.c, unittests/optional-selftests.c, unittests/parse-connection-spec-selftests.c, unittests/ptid-selftests.c, unittests/rsp-low-selftests.c, unittests/scoped_fd-selftests.c, unittests/scoped_mmap-selftests.c, unittests/scoped_restore-selftests.c, unittests/string_view-selftests.c, unittests/style-selftests.c, unittests/tracepoint-selftests.c, unittests/unpack-selftests.c, unittests/utils-selftests.c, unittests/xml-utils-selftests.c, utils.c, utils.h, valarith.c, valops.c, valprint.c, value.c, value.h, varobj.c, varobj.h, windows-nat.c, x86-linux-nat.c, xml-support.c, xml-support.h, xml-tdesc.h, xstormy16-tdep.c, xtensa-linux-nat.c, dwarf2read.h: Change common to gdbsupport. gdb/gdbserver/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * configure: Rebuild. * configure.ac: Change common to gdbsupport. * acinclude.m4: Change common to gdbsupport. * Makefile.in (SFILES, OBS, GDBREPLAY_OBS, IPA_OBJS) (version-generated.c, gdbsupport/%-ipa.o, gdbsupport/%.o): Change common to gdbsupport. * ax.c, event-loop.c, fork-child.c, gdb_proc_service.h, gdbreplay.c, gdbthread.h, hostio-errno.c, hostio.c, i387-fp.c, inferiors.c, inferiors.h, linux-aarch64-tdesc-selftest.c, linux-amd64-ipa.c, linux-i386-ipa.c, linux-low.c, linux-tic6x-low.c, linux-x86-low.c, linux-x86-tdesc-selftest.c, linux-x86-tdesc.c, lynx-i386-low.c, lynx-low.c, mem-break.h, nto-x86-low.c, regcache.c, regcache.h, remote-utils.c, server.c, server.h, spu-low.c, symbol.c, target.h, tdesc.c, tdesc.h, thread-db.c, tracepoint.c, win32-i386-low.c, win32-low.c: Change common to gdbsupport.
2019-05-06 04:29:24 +02:00
#include "gdbsupport/environ.h"
C++ify gdb/common/environ.c As part of the preparation necessary for my upcoming task, I'd like to propose that we turn gdb_environ into a class. The approach taken here is simple: the class gdb_environ contains everything that is needed to manipulate the environment variables. These variables are stored in an std::vector<char *>, which can be converted to a 'char **' and passed as argument to functions that need it. The usage has not changed much. As per Pedro's suggestion, this class uses a static factory method initialization. This means that when an instance is created, it is initially empty. When needed, it has to be initialized using the static method 'from_host_environ'. As mentioned before, this is a preparation for an upcoming work that I will be posting in the next few weeks or so. For that work, I'll probably create another data structure that will contain all the environment variables that were set by the user using the 'set environment' command, because I'll need access to them. This will be much easier with the class-ification of gdb_environ. As noted, this has been regression-tested with the new version of environ.exp and no regressions were found. gdb/ChangeLog: 2017-06-20 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add 'unittests/environ-selftests.c'. (SUBDIR_UNITTESTS_OBS): Add 'environ-selftests.o'. * charset.c (find_charset_names): Declare object 'iconv_env'. Update code to use 'iconv_env' object. Remove call to 'free_environ'. * common/environ.c: Include <utility>. (make_environ): Delete function. (free_environ): Delete function. (gdb_environ::clear): New function. (gdb_environ::operator=): New function. (gdb_environ::get): Likewise. (environ_vector): Delete function. (set_in_environ): Delete function. (gdb_environ::set): New function. (unset_in_environ): Delete function. (gdb_environ::unset): New function. (gdb_environ::envp): Likewise. * common/environ.h: Include <vector>. (struct gdb_environ): Delete; transform into... (class gdb_environ): ... this class. (free_environ): Delete prototype. (init_environ, get_in_environ, set_in_environ, unset_in_environ, environ_vector): Likewise. * infcmd.c (run_command_1): Update code to call 'envp' from 'gdb_environ' class. (environment_info): Update code to call methods from 'gdb_environ' class. (unset_environment_command): Likewise. (path_info): Likewise. (path_command): Likewise. * inferior.c (inferior::~inferior): Delete call to 'free_environ'. (inferior::inferior): Initialize 'environment' using the host's information. * inferior.h: Remove forward declaration of 'struct gdb_environ'. Include "environ.h". (class inferior) <environment>: Change type from 'struct gdb_environ' to 'gdb_environ'. * mi/mi-cmd-env.c (mi_cmd_env_path): Update code to call methods from 'gdb_environ' class. * solib.c (solib_find_1): Likewise * unittests/environ-selftests.c: New file. gdb/gdbserver/ChangeLog: 2017-06-20 Sergio Durigan Junior <sergiodj@redhat.com> * linux-low.c (linux_create_inferior): Adjust code to access the environment information via 'gdb_environ' class. * lynx-low.c (lynx_create_inferior): Likewise. * server.c (our_environ): Make it an instance of 'gdb_environ'. (get_environ): Return a pointer to 'our_environ'. (captured_main): Initialize 'our_environ'. * server.h (get_environ): Adjust prototype. * spu-low.c (spu_create_inferior): Adjust code to access the environment information via 'gdb_environ' class.
2017-02-11 03:19:44 +01:00
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
#include "progspace.h"
* auto-load.c (_initialize_auto_load): Update. * solib-svr4.c (_initialize_svr4_solib): Update * solib-dsbt.c (_initialize_dsbt_solib): Update. * solib-darwin.c (_initialize_darwin_solib): Update. * registry.h: New file. * python/py-progspace.c (gdbpy_initialize_pspace): Update. * python/py-inferior.c (gdbpy_initialize_inferior): Update. * progspace.h: Include registry.h. Use DECLARE_REGISTRY. (register_program_space_data_with_cleanup) (register_program_space_data, program_space_alloc_data) (clear_program_space_data, set_program_space_data) (program_space_data): Don't declare. * progspace.c: Use DEFINE_REGISTRY. (struct program_space_data, struct program_space_data_registration, struct program_space_data_registry, program_space_data_registry) (register_program_space_data_with_cleanup) (register_program_space_data, program_space_alloc_data) (program_space_free_data, clear_program_space_data) (set_program_space_data, program_space_data): Remove. * objfiles.h: Include registry.h. Use DECLARE_REGISTRY. (struct objfile) <data, num_data>: Replace with REGISTRY_FIELDS. (register_objfile_data_with_cleanup, register_objfile_data) (clear_objfile_data, set_objfile_data, objfile_data): Don't declare. * objfiles.c: Use DEFINE_REGISTRY. (struct objfile_data, struct objfile_data_registration, struct objfile_data_registry, objfile_data_registry) (register_objfile_data_with_cleanup, register_objfile_data) (objfile_alloc_data, objfile_free_data, clear_objfile_data) (set_objfile_data, objfile_data): Remove. (_initialize_objfiles): Update. * jit.c (_initialize_jit): Update. * inflow.c (_initialize_inflow): Update. * inferior.h: Include registry.h. Use DECLARE_REGISTRY. (struct inferior) <data, num_data>: Replace with REGISTRY_FIELDS. (register_inferior_data_with_cleanup, register_inferior_data) (clear_inferior_data, set_inferior_data, inferior_data): Don't declare. * inferior.c: Use DEFINE_REGISTRY. (struct inferior_data, struct inferior_data_registration, struct inferior_data_registry, inferior_data_registry) (register_inferior_data_with_cleanup, register_inferior_data) (inferior_alloc_data, inferior_free_data clear_inferior_data) (set_inferior_data, inferior_data): Remove. * auxv.c (_initialize_auxv): Update. * ada-lang.c (_initialize_ada_language): Update. * breakpoint.c (_initialize_breakpoint): Update. * i386-nat.c (i386_use_watchpoints): Update.
2012-08-22 17:17:21 +02:00
#include "registry.h"
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
Make symfile_add_flags and objfile->flags strongly typed This makes these flag types be "enum flag" types. The benefit is making use of C++'s stronger typing -- mixing the flags types by mistake errors at compile time. This caught one old bug in symbol_file_add_main_1 already, fixed by this patch as well: @@ -1318,7 +1326,7 @@ symbol_file_add_main_1 (const char *args, int from_tty, int flags) what is frameless. */ reinit_frame_cache (); - if ((flags & SYMFILE_NO_READ) == 0) + if ((add_flags & SYMFILE_NO_READ) == 0) set_initial_language (); } Above, "flags" are objfile flags, not symfile_add_flags. So that was actually checking for "flag & OBJF_PSYMTABS_READ", which has the same value as SYMFILE_NO_READ... I moved the flags definitions to separate files to break circular dependencies. Built with --enable-targets=all and tested on x86-64 Fedora 23. gdb/ChangeLog: 2016-10-26 Pedro Alves <palves@redhat.com> * coffread.c (coff_symfile_read): Use symfile_add_flags. * dbxread.c (dbx_symfile_read): Ditto. * elfread.c (elf_symfile_read): Ditto. * inferior.h: Include symfile-add-flags.h. (struct inferior) <symfile_flags>: Now symfile_add_flags. * machoread.c (macho_add_oso_symfile, macho_symfile_read_all_oso) (macho_symfile_read, mipscoff_symfile_read): Use symfile_add_flags. * objfile-flags.h: New file. * objfiles.c (allocate_objfile): Use objfile_flags. * objfiles.h: Include objfile-flags.h. (struct objfile) <flags>: Now an objfile_flags. (OBJF_REORDERED, OBJF_SHARED, OBJF_READNOW, OBJF_USERLOADED) (OBJF_PSYMTABS_READ, OBJF_MAINLINE, OBJF_NOT_FILENAME): Delete. Converted to an enum-flags in objfile-flags.h. (allocate_objfile): Use objfile_flags. * python/py-objfile.c (objfpy_add_separate_debug_file): Remove unnecessary local. * solib.c (solib_read_symbols, solib_add) (reload_shared_libraries_1): Use symfile_add_flags. * solib.h: Include "symfile-add-flags.h". (solib_read_symbols): Use symfile_add_flags. * symfile-add-flags.h: New file. * symfile-debug.c (debug_sym_read): Use symfile_add_flags. * symfile-mem.c (symbol_file_add_from_memory): Use symfile_add_flags. * symfile.c (read_symbols, syms_from_objfile_1) (syms_from_objfile, finish_new_objfile): Use symfile_add_flags. (symbol_file_add_with_addrs): Use symfile_add_flags and objfile_flags. (symbol_file_add_separate): Use symfile_add_flags. (symbol_file_add_from_bfd, symbol_file_add): Use symfile_add_flags and objfile_flags. (symbol_file_add_main_1): : Use objfile_flags. Fix add_flags vs flags confusion. (symbol_file_command): Use objfile_flags. (add_symbol_file_command): Use symfile_add_flags and objfile_flags. (clear_symtab_users): Use symfile_add_flags. * symfile.h: Include "symfile-add-flags.h" and "objfile-flags.h". (struct sym_fns) <sym_read>: Use symfile_add_flags. (clear_symtab_users): Use symfile_add_flags. (enum symfile_add_flags): Delete, moved to symfile-add-flags.h and converted to enum-flags. (symbol_file_add, symbol_file_add_from_bfd) (symbol_file_add_separate): Use symfile_add_flags. * xcoffread.c (xcoff_initial_scan): Use symfile_add_flags.
2016-10-26 17:47:10 +02:00
#include "symfile-add-flags.h"
Rename common to gdbsupport This is the next patch in the ongoing series to move gdbsever to the top level. This patch just renames the "common" directory. The idea is to do this move in two parts: first rename the directory (this patch), then move the directory to the top. This approach makes the patches a bit more tractable. I chose the name "gdbsupport" for the directory. However, as this patch was largely written by sed, we could pick a new name without too much difficulty. Tested by the buildbot. gdb/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * contrib/ari/gdb_ari.sh: Change common to gdbsupport. * configure: Rebuild. * configure.ac: Change common to gdbsupport. * gdbsupport: Rename from common. * acinclude.m4: Change common to gdbsupport. * Makefile.in (CONFIG_SRC_SUBDIR, COMMON_SFILES) (HFILES_NO_SRCDIR, stamp-version, ALLDEPFILES): Change common to gdbsupport. * aarch64-tdep.c, ada-lang.c, ada-lang.h, agent.c, alloc.c, amd64-darwin-tdep.c, amd64-dicos-tdep.c, amd64-fbsd-nat.c, amd64-fbsd-tdep.c, amd64-linux-nat.c, amd64-linux-tdep.c, amd64-nbsd-tdep.c, amd64-obsd-tdep.c, amd64-sol2-tdep.c, amd64-tdep.c, amd64-windows-tdep.c, arch-utils.c, arch/aarch64-insn.c, arch/aarch64.c, arch/aarch64.h, arch/amd64.c, arch/amd64.h, arch/arm-get-next-pcs.c, arch/arm-linux.c, arch/arm.c, arch/i386.c, arch/i386.h, arch/ppc-linux-common.c, arch/riscv.c, arch/riscv.h, arch/tic6x.c, arm-tdep.c, auto-load.c, auxv.c, ax-gdb.c, ax-general.c, ax.h, breakpoint.c, breakpoint.h, btrace.c, btrace.h, build-id.c, build-id.h, c-lang.h, charset.c, charset.h, cli/cli-cmds.c, cli/cli-cmds.h, cli/cli-decode.c, cli/cli-dump.c, cli/cli-option.h, cli/cli-script.c, coff-pe-read.c, command.h, compile/compile-c-support.c, compile/compile-c.h, compile/compile-cplus-symbols.c, compile/compile-cplus-types.c, compile/compile-cplus.h, compile/compile-loc2c.c, compile/compile.c, completer.c, completer.h, contrib/ari/gdb_ari.sh, corefile.c, corelow.c, cp-support.c, cp-support.h, cp-valprint.c, csky-tdep.c, ctf.c, darwin-nat.c, debug.c, defs.h, disasm-selftests.c, disasm.c, disasm.h, dtrace-probe.c, dwarf-index-cache.c, dwarf-index-cache.h, dwarf-index-write.c, dwarf2-frame.c, dwarf2expr.c, dwarf2loc.c, dwarf2read.c, event-loop.c, event-top.c, exceptions.c, exec.c, extension.h, fbsd-nat.c, features/aarch64-core.c, features/aarch64-fpu.c, features/aarch64-pauth.c, features/aarch64-sve.c, features/i386/32bit-avx.c, features/i386/32bit-avx512.c, features/i386/32bit-core.c, features/i386/32bit-linux.c, features/i386/32bit-mpx.c, features/i386/32bit-pkeys.c, features/i386/32bit-segments.c, features/i386/32bit-sse.c, features/i386/64bit-avx.c, features/i386/64bit-avx512.c, features/i386/64bit-core.c, features/i386/64bit-linux.c, features/i386/64bit-mpx.c, features/i386/64bit-pkeys.c, features/i386/64bit-segments.c, features/i386/64bit-sse.c, features/i386/x32-core.c, features/riscv/32bit-cpu.c, features/riscv/32bit-csr.c, features/riscv/32bit-fpu.c, features/riscv/64bit-cpu.c, features/riscv/64bit-csr.c, features/riscv/64bit-fpu.c, features/tic6x-c6xp.c, features/tic6x-core.c, features/tic6x-gp.c, filename-seen-cache.h, findcmd.c, findvar.c, fork-child.c, gcore.c, gdb_bfd.c, gdb_bfd.h, gdb_proc_service.h, gdb_regex.c, gdb_select.h, gdb_usleep.c, gdbarch-selftests.c, gdbthread.h, gdbtypes.h, gnu-nat.c, go32-nat.c, guile/guile.c, guile/scm-ports.c, guile/scm-safe-call.c, guile/scm-type.c, i386-fbsd-nat.c, i386-fbsd-tdep.c, i386-go32-tdep.c, i386-linux-nat.c, i386-linux-tdep.c, i386-tdep.c, i387-tdep.c, ia64-libunwind-tdep.c, ia64-linux-nat.c, inf-child.c, inf-ptrace.c, infcall.c, infcall.h, infcmd.c, inferior-iter.h, inferior.c, inferior.h, inflow.c, inflow.h, infrun.c, infrun.h, inline-frame.c, language.h, linespec.c, linux-fork.c, linux-nat.c, linux-tdep.c, linux-thread-db.c, location.c, machoread.c, macrotab.h, main.c, maint.c, maint.h, memattr.c, memrange.h, mi/mi-cmd-break.h, mi/mi-cmd-env.c, mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-interp.c, mi/mi-main.c, mi/mi-parse.h, minsyms.c, mips-linux-tdep.c, namespace.h, nat/aarch64-linux-hw-point.c, nat/aarch64-linux-hw-point.h, nat/aarch64-linux.c, nat/aarch64-sve-linux-ptrace.c, nat/amd64-linux-siginfo.c, nat/fork-inferior.c, nat/linux-btrace.c, nat/linux-btrace.h, nat/linux-namespaces.c, nat/linux-nat.h, nat/linux-osdata.c, nat/linux-personality.c, nat/linux-procfs.c, nat/linux-ptrace.c, nat/linux-ptrace.h, nat/linux-waitpid.c, nat/mips-linux-watch.c, nat/mips-linux-watch.h, nat/ppc-linux.c, nat/x86-dregs.c, nat/x86-dregs.h, nat/x86-linux-dregs.c, nat/x86-linux.c, nto-procfs.c, nto-tdep.c, objfile-flags.h, objfiles.c, objfiles.h, obsd-nat.c, observable.h, osdata.c, p-valprint.c, parse.c, parser-defs.h, ppc-linux-nat.c, printcmd.c, probe.c, proc-api.c, procfs.c, producer.c, progspace.h, psymtab.h, python/py-framefilter.c, python/py-inferior.c, python/py-ref.h, python/py-type.c, python/python.c, record-btrace.c, record-full.c, record.c, record.h, regcache-dump.c, regcache.c, regcache.h, remote-fileio.c, remote-fileio.h, remote-sim.c, remote.c, riscv-tdep.c, rs6000-aix-tdep.c, rust-exp.y, s12z-tdep.c, selftest-arch.c, ser-base.c, ser-event.c, ser-pipe.c, ser-tcp.c, ser-unix.c, skip.c, solib-aix.c, solib-target.c, solib.c, source-cache.c, source.c, source.h, sparc-nat.c, spu-linux-nat.c, stack.c, stap-probe.c, symfile-add-flags.h, symfile.c, symfile.h, symtab.c, symtab.h, target-descriptions.c, target-descriptions.h, target-memory.c, target.c, target.h, target/waitstatus.c, target/waitstatus.h, thread-iter.h, thread.c, tilegx-tdep.c, top.c, top.h, tracefile-tfile.c, tracefile.c, tracepoint.c, tracepoint.h, tui/tui-io.c, ui-file.c, ui-out.h, unittests/array-view-selftests.c, unittests/child-path-selftests.c, unittests/cli-utils-selftests.c, unittests/common-utils-selftests.c, unittests/copy_bitwise-selftests.c, unittests/environ-selftests.c, unittests/format_pieces-selftests.c, unittests/function-view-selftests.c, unittests/lookup_name_info-selftests.c, unittests/memory-map-selftests.c, unittests/memrange-selftests.c, unittests/mkdir-recursive-selftests.c, unittests/observable-selftests.c, unittests/offset-type-selftests.c, unittests/optional-selftests.c, unittests/parse-connection-spec-selftests.c, unittests/ptid-selftests.c, unittests/rsp-low-selftests.c, unittests/scoped_fd-selftests.c, unittests/scoped_mmap-selftests.c, unittests/scoped_restore-selftests.c, unittests/string_view-selftests.c, unittests/style-selftests.c, unittests/tracepoint-selftests.c, unittests/unpack-selftests.c, unittests/utils-selftests.c, unittests/xml-utils-selftests.c, utils.c, utils.h, valarith.c, valops.c, valprint.c, value.c, value.h, varobj.c, varobj.h, windows-nat.c, x86-linux-nat.c, xml-support.c, xml-support.h, xml-tdesc.h, xstormy16-tdep.c, xtensa-linux-nat.c, dwarf2read.h: Change common to gdbsupport. gdb/gdbserver/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * configure: Rebuild. * configure.ac: Change common to gdbsupport. * acinclude.m4: Change common to gdbsupport. * Makefile.in (SFILES, OBS, GDBREPLAY_OBS, IPA_OBJS) (version-generated.c, gdbsupport/%-ipa.o, gdbsupport/%.o): Change common to gdbsupport. * ax.c, event-loop.c, fork-child.c, gdb_proc_service.h, gdbreplay.c, gdbthread.h, hostio-errno.c, hostio.c, i387-fp.c, inferiors.c, inferiors.h, linux-aarch64-tdesc-selftest.c, linux-amd64-ipa.c, linux-i386-ipa.c, linux-low.c, linux-tic6x-low.c, linux-x86-low.c, linux-x86-tdesc-selftest.c, linux-x86-tdesc.c, lynx-i386-low.c, lynx-low.c, mem-break.h, nto-x86-low.c, regcache.c, regcache.h, remote-utils.c, server.c, server.h, spu-low.c, symbol.c, target.h, tdesc.c, tdesc.h, thread-db.c, tracepoint.c, win32-i386-low.c, win32-low.c: Change common to gdbsupport.
2019-05-06 04:29:24 +02:00
#include "gdbsupport/refcounted-object.h"
#include "gdbsupport/forward-scope-exit.h"
#include "gdbsupport/gdb_unique_ptr.h"
Make symfile_add_flags and objfile->flags strongly typed This makes these flag types be "enum flag" types. The benefit is making use of C++'s stronger typing -- mixing the flags types by mistake errors at compile time. This caught one old bug in symbol_file_add_main_1 already, fixed by this patch as well: @@ -1318,7 +1326,7 @@ symbol_file_add_main_1 (const char *args, int from_tty, int flags) what is frameless. */ reinit_frame_cache (); - if ((flags & SYMFILE_NO_READ) == 0) + if ((add_flags & SYMFILE_NO_READ) == 0) set_initial_language (); } Above, "flags" are objfile flags, not symfile_add_flags. So that was actually checking for "flag & OBJF_PSYMTABS_READ", which has the same value as SYMFILE_NO_READ... I moved the flags definitions to separate files to break circular dependencies. Built with --enable-targets=all and tested on x86-64 Fedora 23. gdb/ChangeLog: 2016-10-26 Pedro Alves <palves@redhat.com> * coffread.c (coff_symfile_read): Use symfile_add_flags. * dbxread.c (dbx_symfile_read): Ditto. * elfread.c (elf_symfile_read): Ditto. * inferior.h: Include symfile-add-flags.h. (struct inferior) <symfile_flags>: Now symfile_add_flags. * machoread.c (macho_add_oso_symfile, macho_symfile_read_all_oso) (macho_symfile_read, mipscoff_symfile_read): Use symfile_add_flags. * objfile-flags.h: New file. * objfiles.c (allocate_objfile): Use objfile_flags. * objfiles.h: Include objfile-flags.h. (struct objfile) <flags>: Now an objfile_flags. (OBJF_REORDERED, OBJF_SHARED, OBJF_READNOW, OBJF_USERLOADED) (OBJF_PSYMTABS_READ, OBJF_MAINLINE, OBJF_NOT_FILENAME): Delete. Converted to an enum-flags in objfile-flags.h. (allocate_objfile): Use objfile_flags. * python/py-objfile.c (objfpy_add_separate_debug_file): Remove unnecessary local. * solib.c (solib_read_symbols, solib_add) (reload_shared_libraries_1): Use symfile_add_flags. * solib.h: Include "symfile-add-flags.h". (solib_read_symbols): Use symfile_add_flags. * symfile-add-flags.h: New file. * symfile-debug.c (debug_sym_read): Use symfile_add_flags. * symfile-mem.c (symbol_file_add_from_memory): Use symfile_add_flags. * symfile.c (read_symbols, syms_from_objfile_1) (syms_from_objfile, finish_new_objfile): Use symfile_add_flags. (symbol_file_add_with_addrs): Use symfile_add_flags and objfile_flags. (symbol_file_add_separate): Use symfile_add_flags. (symbol_file_add_from_bfd, symbol_file_add): Use symfile_add_flags and objfile_flags. (symbol_file_add_main_1): : Use objfile_flags. Fix add_flags vs flags confusion. (symbol_file_command): Use objfile_flags. (add_symbol_file_command): Use symfile_add_flags and objfile_flags. (clear_symtab_users): Use symfile_add_flags. * symfile.h: Include "symfile-add-flags.h" and "objfile-flags.h". (struct sym_fns) <sym_read>: Use symfile_add_flags. (clear_symtab_users): Use symfile_add_flags. (enum symfile_add_flags): Delete, moved to symfile-add-flags.h and converted to enum-flags. (symbol_file_add, symbol_file_add_from_bfd) (symbol_file_add_separate): Use symfile_add_flags. * xcoffread.c (xcoff_initial_scan): Use symfile_add_flags.
2016-10-26 17:47:10 +02:00
Rename common to gdbsupport This is the next patch in the ongoing series to move gdbsever to the top level. This patch just renames the "common" directory. The idea is to do this move in two parts: first rename the directory (this patch), then move the directory to the top. This approach makes the patches a bit more tractable. I chose the name "gdbsupport" for the directory. However, as this patch was largely written by sed, we could pick a new name without too much difficulty. Tested by the buildbot. gdb/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * contrib/ari/gdb_ari.sh: Change common to gdbsupport. * configure: Rebuild. * configure.ac: Change common to gdbsupport. * gdbsupport: Rename from common. * acinclude.m4: Change common to gdbsupport. * Makefile.in (CONFIG_SRC_SUBDIR, COMMON_SFILES) (HFILES_NO_SRCDIR, stamp-version, ALLDEPFILES): Change common to gdbsupport. * aarch64-tdep.c, ada-lang.c, ada-lang.h, agent.c, alloc.c, amd64-darwin-tdep.c, amd64-dicos-tdep.c, amd64-fbsd-nat.c, amd64-fbsd-tdep.c, amd64-linux-nat.c, amd64-linux-tdep.c, amd64-nbsd-tdep.c, amd64-obsd-tdep.c, amd64-sol2-tdep.c, amd64-tdep.c, amd64-windows-tdep.c, arch-utils.c, arch/aarch64-insn.c, arch/aarch64.c, arch/aarch64.h, arch/amd64.c, arch/amd64.h, arch/arm-get-next-pcs.c, arch/arm-linux.c, arch/arm.c, arch/i386.c, arch/i386.h, arch/ppc-linux-common.c, arch/riscv.c, arch/riscv.h, arch/tic6x.c, arm-tdep.c, auto-load.c, auxv.c, ax-gdb.c, ax-general.c, ax.h, breakpoint.c, breakpoint.h, btrace.c, btrace.h, build-id.c, build-id.h, c-lang.h, charset.c, charset.h, cli/cli-cmds.c, cli/cli-cmds.h, cli/cli-decode.c, cli/cli-dump.c, cli/cli-option.h, cli/cli-script.c, coff-pe-read.c, command.h, compile/compile-c-support.c, compile/compile-c.h, compile/compile-cplus-symbols.c, compile/compile-cplus-types.c, compile/compile-cplus.h, compile/compile-loc2c.c, compile/compile.c, completer.c, completer.h, contrib/ari/gdb_ari.sh, corefile.c, corelow.c, cp-support.c, cp-support.h, cp-valprint.c, csky-tdep.c, ctf.c, darwin-nat.c, debug.c, defs.h, disasm-selftests.c, disasm.c, disasm.h, dtrace-probe.c, dwarf-index-cache.c, dwarf-index-cache.h, dwarf-index-write.c, dwarf2-frame.c, dwarf2expr.c, dwarf2loc.c, dwarf2read.c, event-loop.c, event-top.c, exceptions.c, exec.c, extension.h, fbsd-nat.c, features/aarch64-core.c, features/aarch64-fpu.c, features/aarch64-pauth.c, features/aarch64-sve.c, features/i386/32bit-avx.c, features/i386/32bit-avx512.c, features/i386/32bit-core.c, features/i386/32bit-linux.c, features/i386/32bit-mpx.c, features/i386/32bit-pkeys.c, features/i386/32bit-segments.c, features/i386/32bit-sse.c, features/i386/64bit-avx.c, features/i386/64bit-avx512.c, features/i386/64bit-core.c, features/i386/64bit-linux.c, features/i386/64bit-mpx.c, features/i386/64bit-pkeys.c, features/i386/64bit-segments.c, features/i386/64bit-sse.c, features/i386/x32-core.c, features/riscv/32bit-cpu.c, features/riscv/32bit-csr.c, features/riscv/32bit-fpu.c, features/riscv/64bit-cpu.c, features/riscv/64bit-csr.c, features/riscv/64bit-fpu.c, features/tic6x-c6xp.c, features/tic6x-core.c, features/tic6x-gp.c, filename-seen-cache.h, findcmd.c, findvar.c, fork-child.c, gcore.c, gdb_bfd.c, gdb_bfd.h, gdb_proc_service.h, gdb_regex.c, gdb_select.h, gdb_usleep.c, gdbarch-selftests.c, gdbthread.h, gdbtypes.h, gnu-nat.c, go32-nat.c, guile/guile.c, guile/scm-ports.c, guile/scm-safe-call.c, guile/scm-type.c, i386-fbsd-nat.c, i386-fbsd-tdep.c, i386-go32-tdep.c, i386-linux-nat.c, i386-linux-tdep.c, i386-tdep.c, i387-tdep.c, ia64-libunwind-tdep.c, ia64-linux-nat.c, inf-child.c, inf-ptrace.c, infcall.c, infcall.h, infcmd.c, inferior-iter.h, inferior.c, inferior.h, inflow.c, inflow.h, infrun.c, infrun.h, inline-frame.c, language.h, linespec.c, linux-fork.c, linux-nat.c, linux-tdep.c, linux-thread-db.c, location.c, machoread.c, macrotab.h, main.c, maint.c, maint.h, memattr.c, memrange.h, mi/mi-cmd-break.h, mi/mi-cmd-env.c, mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-interp.c, mi/mi-main.c, mi/mi-parse.h, minsyms.c, mips-linux-tdep.c, namespace.h, nat/aarch64-linux-hw-point.c, nat/aarch64-linux-hw-point.h, nat/aarch64-linux.c, nat/aarch64-sve-linux-ptrace.c, nat/amd64-linux-siginfo.c, nat/fork-inferior.c, nat/linux-btrace.c, nat/linux-btrace.h, nat/linux-namespaces.c, nat/linux-nat.h, nat/linux-osdata.c, nat/linux-personality.c, nat/linux-procfs.c, nat/linux-ptrace.c, nat/linux-ptrace.h, nat/linux-waitpid.c, nat/mips-linux-watch.c, nat/mips-linux-watch.h, nat/ppc-linux.c, nat/x86-dregs.c, nat/x86-dregs.h, nat/x86-linux-dregs.c, nat/x86-linux.c, nto-procfs.c, nto-tdep.c, objfile-flags.h, objfiles.c, objfiles.h, obsd-nat.c, observable.h, osdata.c, p-valprint.c, parse.c, parser-defs.h, ppc-linux-nat.c, printcmd.c, probe.c, proc-api.c, procfs.c, producer.c, progspace.h, psymtab.h, python/py-framefilter.c, python/py-inferior.c, python/py-ref.h, python/py-type.c, python/python.c, record-btrace.c, record-full.c, record.c, record.h, regcache-dump.c, regcache.c, regcache.h, remote-fileio.c, remote-fileio.h, remote-sim.c, remote.c, riscv-tdep.c, rs6000-aix-tdep.c, rust-exp.y, s12z-tdep.c, selftest-arch.c, ser-base.c, ser-event.c, ser-pipe.c, ser-tcp.c, ser-unix.c, skip.c, solib-aix.c, solib-target.c, solib.c, source-cache.c, source.c, source.h, sparc-nat.c, spu-linux-nat.c, stack.c, stap-probe.c, symfile-add-flags.h, symfile.c, symfile.h, symtab.c, symtab.h, target-descriptions.c, target-descriptions.h, target-memory.c, target.c, target.h, target/waitstatus.c, target/waitstatus.h, thread-iter.h, thread.c, tilegx-tdep.c, top.c, top.h, tracefile-tfile.c, tracefile.c, tracepoint.c, tracepoint.h, tui/tui-io.c, ui-file.c, ui-out.h, unittests/array-view-selftests.c, unittests/child-path-selftests.c, unittests/cli-utils-selftests.c, unittests/common-utils-selftests.c, unittests/copy_bitwise-selftests.c, unittests/environ-selftests.c, unittests/format_pieces-selftests.c, unittests/function-view-selftests.c, unittests/lookup_name_info-selftests.c, unittests/memory-map-selftests.c, unittests/memrange-selftests.c, unittests/mkdir-recursive-selftests.c, unittests/observable-selftests.c, unittests/offset-type-selftests.c, unittests/optional-selftests.c, unittests/parse-connection-spec-selftests.c, unittests/ptid-selftests.c, unittests/rsp-low-selftests.c, unittests/scoped_fd-selftests.c, unittests/scoped_mmap-selftests.c, unittests/scoped_restore-selftests.c, unittests/string_view-selftests.c, unittests/style-selftests.c, unittests/tracepoint-selftests.c, unittests/unpack-selftests.c, unittests/utils-selftests.c, unittests/xml-utils-selftests.c, utils.c, utils.h, valarith.c, valops.c, valprint.c, value.c, value.h, varobj.c, varobj.h, windows-nat.c, x86-linux-nat.c, xml-support.c, xml-support.h, xml-tdesc.h, xstormy16-tdep.c, xtensa-linux-nat.c, dwarf2read.h: Change common to gdbsupport. gdb/gdbserver/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * configure: Rebuild. * configure.ac: Change common to gdbsupport. * acinclude.m4: Change common to gdbsupport. * Makefile.in (SFILES, OBS, GDBREPLAY_OBS, IPA_OBJS) (version-generated.c, gdbsupport/%-ipa.o, gdbsupport/%.o): Change common to gdbsupport. * ax.c, event-loop.c, fork-child.c, gdb_proc_service.h, gdbreplay.c, gdbthread.h, hostio-errno.c, hostio.c, i387-fp.c, inferiors.c, inferiors.h, linux-aarch64-tdesc-selftest.c, linux-amd64-ipa.c, linux-i386-ipa.c, linux-low.c, linux-tic6x-low.c, linux-x86-low.c, linux-x86-tdesc-selftest.c, linux-x86-tdesc.c, lynx-i386-low.c, lynx-low.c, mem-break.h, nto-x86-low.c, regcache.c, regcache.h, remote-utils.c, server.c, server.h, spu-low.c, symbol.c, target.h, tdesc.c, tdesc.h, thread-db.c, tracepoint.c, win32-i386-low.c, win32-low.c: Change common to gdbsupport.
2019-05-06 04:29:24 +02:00
#include "gdbsupport/common-inferior.h"
Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc. As preparation for multi-target, this patch makes each inferior have its own thread list. This isn't absolutely necessary for multi-target, but simplifies things. It originally stemmed from the desire to eliminate the init_thread_list calls sprinkled around, plus it makes it more efficient to iterate over threads of a given inferior (no need to always iterate over threads of all inferiors). We still need to iterate over threads of all inferiors in a number of places, which means we'd need adjust the ALL_THREADS / ALL_NON_EXITED_THREADS macros. However, naively tweaking those macros to have an extra for loop, like: #define ALL_THREADS (thr, inf) \ for (inf = inferior_list; inf; inf = inf->next) \ for (thr = inf->thread_list; thr; thr = thr->next) causes problems with code that does "break" or "continue" within the ALL_THREADS loop body. Plus, we need to declare the extra "inf" local variable in order to pass it as temporary variable to ALL_THREADS (etc.) It gets even trickier when we consider extending the macros to filter out threads matching a ptid_t and a target. The macros become tricker to read/write. Been there. An alternative (which was my next attempt), is to replace the ALL_THREADS etc. iteration style with for_each_all_threads, for_each_non_exited_threads, etc. functions which would take a callback as parameter, which would usually be passed a lambda. However, I did not find that satisfactory at all, because the resulting code ends up a little less natural / more noisy to read, write and debug/step-through (due to use of lambdas), and in many places where we use "continue;" to skip to the next thread now need to use "return;". (I ran into hard to debug bugs caused by a continue/return confusion.) I.e., before: ALL_NON_EXITED_THREADS (tp) { if (tp->not_what_I_want) continue; // do something } would turn into: for_each_non_exited_thread ([&] (thread_info *tp) { if (tp->not_what_I_want) return; // do something }); Lastly, the solution I settled with was to replace the ALL_THREADS / ALL_NON_EXITED_THREADS / ALL_INFERIORS macros with (C++20-like) ranges and iterators, such that you can instead naturaly iterate over threads/inferiors using range-for, like e.g,.: // all threads, including THREAD_EXITED threads. for (thread_info *tp : all_threads ()) { .... } // all non-exited threads. for (thread_info *tp : all_non_exited_threads ()) { .... } // all non-exited threads of INF inferior. for (thread_info *tp : inf->non_exited_threads ()) { .... } The all_non_exited_threads() function takes an optional filter ptid_t as parameter, which is quite convenient when we need to iterate over threads matching that filter. See e.g., how the set_executing/set_stop_requested/finish_thread_state etc. functions in thread.c end up being simplified. Most of the patch thus is about adding the infrustructure for allowing the above. Later on when we get to actual multi-target, these functions/ranges/iterators will gain a "target_ops *" parameter so that e.g., we can iterate over all threads of a given target that match a given filter ptid_t. The only entry points users needs to be aware of are the all_threads/all_non_exited_threads etc. functions seen above. Thus, those functions are declared in gdbthread.h/inferior.h. The actual iterators/ranges are mainly "internals" and thus are put out of view in the new thread-iter.h/thread-iter.c/inferior-iter.h files. That keeps the gdbthread.h/inferior.h headers quite a bit more readable. A common/safe-iterator.h header is added which adds a template that can be used to build "safe" iterators, which are forward iterators that can be used to replace the ALL_THREADS_SAFE macro and other instances of the same idiom in future. There's a little bit of shuffling of code between gdbthread.h/thread.c/inferior.h in the patch. That is necessary in order to avoid circular dependencies between the gdbthread.h/inferior.h headers. As for the init_thread_list calls sprinkled around, they're all eliminated by this patch, and a new, central call is added to inferior_appeared. Note how also related to that, there's a call to init_wait_for_inferior in remote.c that is eliminated. init_wait_for_inferior is currently responsible for discarding skipped inline frames, which had to be moved elsewhere. Given that nowadays we always have a thread even for single-threaded processes, the natural place is to delete a frame's inline frame info when we delete the thread. I.e., from clear_thread_inferior_resources. gdb/ChangeLog: 2018-11-22 Pedro Alves <palves@redhat.com> * Makefile.in (COMMON_SFILES): Add thread-iter.c. * breakpoint.c (breakpoints_should_be_inserted_now): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (print_one_breakpoint_location): Replace ALL_INFERIORS with all_inferiors. * bsd-kvm.c: Include inferior.h. * btrace.c (btrace_free_objfile): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * common/filtered-iterator.h: New. * common/safe-iterator.h: New. * corelow.c (core_target_open): Don't call init_thread_list here. * darwin-nat.c (thread_info_from_private_thread_info): Replace ALL_THREADS with all_threads. * fbsd-nat.c (fbsd_nat_target::resume): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fbsd-tdep.c (fbsd_make_corefile_notes): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fork-child.c (postfork_hook): Don't call init_thread_list here. * gdbarch-selftests.c (register_to_value_test): Adjust. * gdbthread.h: Don't include "inferior.h" here. (struct inferior): Forward declare. (enum step_over_calls_kind): Moved here from inferior.h. (thread_info::deletable): Definition moved to thread.c. (find_thread_ptid (inferior *, ptid_t)): Declare. (ALL_THREADS, ALL_THREADS_BY_INFERIOR, ALL_THREADS_SAFE): Delete. Include "thread-iter.h". (all_threads, all_non_exited_threads, all_threads_safe): New. (any_thread_p): Declare. (thread_list): Delete. * infcmd.c (signal_command): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (proceed_after_attach_callback): Delete. (proceed_after_attach): Take an inferior pointer instead of an integer PID. Adjust to use range-for. (attach_post_wait): Pass down inferior pointer instead of pid. Use range-for instead of ALL_NON_EXITED_THREADS. (detach_command): Remove init_thread_list call. * inferior-iter.h: New. * inferior.c (struct delete_thread_of_inferior_arg): Delete. (delete_thread_of_inferior): Delete. (delete_inferior, exit_inferior_1): Use range-for with inf->threads_safe() instead of iterate_over_threads. (inferior_appeared): Call init_thread_list here. (discard_all_inferiors): Use all_non_exited_inferiors. (find_inferior_id, find_inferior_pid): Use all_inferiors. (iterate_over_inferiors): Use all_inferiors_safe. (have_inferiors, number_of_live_inferiors): Use all_non_exited_inferiors. (number_of_inferiors): Use all_inferiors and std::distance. (print_inferior): Use all_inferiors. * inferior.h: Include gdbthread.h. (enum step_over_calls_kind): Moved to gdbthread.h. (struct inferior) <thread_list>: New field. <threads, non_exited_threads, threads_safe>: New methods. (ALL_INFERIORS): Delete. Include "inferior-iter.h". (ALL_NON_EXITED_INFERIORS): Delete. (all_inferiors_safe, all_inferiors, all_non_exited_inferiors): New functions. * inflow.c (child_interrupt, child_pass_ctrlc): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * infrun.c (follow_exec): Use all_threads_safe. (clear_proceed_status, proceed): Use all_non_exited_threads. (init_wait_for_inferior): Don't clear inline frame state here. (infrun_thread_stop_requested, for_each_just_stopped_thread): Use all_threads instead of ALL_NON_EXITED_THREADS. (random_pending_event_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use a lambda for repeated code. (clean_up_just_stopped_threads_fsms): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (handle_no_resumed): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use all_inferiors instead of ALL_INFERIORS. (restart_threads, switch_back_to_stepped_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-nat.c (check_zombie_leaders): Replace ALL_INFERIORS with all_inferiors. (kill_unfollowed_fork_children): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-tdep.c (linux_make_corefile_notes): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-thread-db.c (thread_db_target::update_thread_list): Replace ALL_INFERIORS with all_inferiors. (thread_db_target::thread_handle_to_thread_info): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * mi/mi-interp.c (multiple_inferiors_p): New. (mi_on_resume_1): Simplify using all_non_exited_threads and multiple_inferiors_p. * mi/mi-main.c (mi_cmd_thread_list_ids): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * nto-procfs.c (nto_procfs_target::open): Don't call init_thread_list here. * record-btrace.c (record_btrace_target_open) (record_btrace_target::stop_recording) (record_btrace_target::close) (record_btrace_target::record_is_replaying) (record_btrace_target::resume, record_btrace_target::wait) (record_btrace_target::record_stop_replaying): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * record-full.c (record_full_wait_1): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * regcache.c (cooked_read_test): Remove reference to global thread_list. * remote-sim.c (gdbsim_target::create_inferior): Don't call init_thread_list here. * remote.c (remote_target::update_thread_list): Use all_threads_safe instead of ALL_NON_EXITED_THREADS. (remote_target::process_initial_stop_replies): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::open_1): Don't call init_thread_list here. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::commit_resume) (remote_target::remove_new_fork_children): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::kill_new_fork_children): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Remove init_thread_list and init_wait_for_inferior calls. (remote_target::remote_btrace_maybe_reopen) (remote_target::thread_handle_to_thread_info): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * target.c (target_terminal::restore_inferior) (target_terminal_is_ours_kind): Replace ALL_INFERIORS with all_non_exited_inferiors. * thread-iter.c: New file. * thread-iter.h: New file. * thread.c: Include "inline-frame.h". (thread_list): Delete. (clear_thread_inferior_resources): Call clear_inline_frame_state. (init_thread_list): Use all_threads_safe instead of ALL_THREADS_SAFE. Adjust to per-inferior thread lists. (new_thread): Adjust to per-inferior thread lists. (add_thread_silent): Pass inferior to find_thread_ptid. (thread_info::deletable): New, moved from the header. (delete_thread_1): Adjust to per-inferior thread lists. (find_thread_global_id): Use inf->threads(). (find_thread_ptid): Use find_inferior_ptid and pass inferior to find_thread_ptid. (find_thread_ptid(inferior*, ptid_t)): New overload. (iterate_over_threads): Use all_threads_safe. (any_thread_p): New. (thread_count): Use all_threads and std::distance. (live_threads_count): Use all_non_exited_threads and std::distance. (valid_global_thread_id): Use all_threads. (in_thread_list): Use find_thread_ptid. (first_thread_of_inferior): Adjust to per-inferior thread lists. (any_thread_of_inferior, any_live_thread_of_inferior): Use inf->non_exited_threads(). (prune_threads, delete_exited_threads): Use all_threads_safe. (thread_change_ptid): Pass inferior pointer to find_thread_ptid. (set_resumed, set_running): Use all_non_exited_threads. (is_thread_state, is_stopped, is_exited, is_running) (is_executing): Delete. (set_executing, set_stop_requested, finish_thread_state): Use all_non_exited_threads. (print_thread_info_1): Use all_inferiors and all_threads. (thread_apply_all_command): Use all_non_exited_threads. (thread_find_command): Use all_threads. (update_threads_executing): Use all_non_exited_threads. * tid-parse.c (parse_thread_id): Use inf->threads. * x86-bsd-nat.c (x86bsd_dr_set): Use inf->non_exited_threads ().
2018-11-22 17:09:14 +01:00
#include "gdbthread.h"
Share fork_inferior et al with gdbserver This is the most important (and the biggest, sorry) patch of the series. It moves fork_inferior from gdb/fork-child.c to nat/fork-inferior.c and makes all the necessary adjustments to both GDB and gdbserver to make sure everything works OK. There is no "most important change" with this patch; all changes are made in a progressive way, making sure that gdbserver had the necessary features while not breaking GDB at the same time. I decided to go ahead and implement a partial support for starting the inferior with a shell on gdbserver, although the full feature comes in the next patch. The user won't have the option to disable the startup-with-shell, and also won't be able to change which shell gdbserver will use (other than setting the $SHELL environment variable, that is). Everything is working as expected, and no regressions were present during the tests. gdb/ChangeLog: 2017-06-07 Sergio Durigan Junior <sergiodj@redhat.com> Pedro Alves <palves@redhat.com> * Makefile.in (HFILES_NO_SRCDIR): Add "common/common-inferior.h" and "nat/fork-inferior.h". * common/common-inferior.h: New file, with contents from "gdb/inferior.h". * commom/common-utils.c: Include "common-utils.h". (stringify_argv): New function. * common/common-utils.h (stringify_argv): New prototype. * configure.nat: Add "fork-inferior.o" as a dependency for "*linux*", "fbsd*" and "nbsd*" hosts. * corefile.c (get_exec_file): Update comment. * darwin-nat.c (darwin_ptrace_him): Call "gdb_startup_inferior" instead of "startup_inferior". (darwin_create_inferior): Call "add_thread_silent" after "fork_inferior". * fork-child.c: Cleanup unnecessary includes. (SHELL_FILE): Move to "common/common-fork-child.c". (environ): Likewise. (exec_wrapper): Initialize. (get_exec_wrapper): New function. (breakup_args): Move to "common/common-fork-child.c"; rename to "breakup_args_for_exec". (escape_bang_in_quoted_argument): Move to "common/common-fork-child.c". (saved_ui): New variable. (prefork_hook): New function. (postfork_hook): Likewise. (postfork_child_hook): Likewise. (gdb_startup_inferior): Likewise. (fork_inferior): Move to "common/common-fork-child.c". Update function to support gdbserver. (startup_inferior): Likewise. * gdbcore.h (get_exec_file): Remove declaration. * gnu-nat.c (gnu_create_inferior): Call "gdb_startup_inferior" instead of "startup_inferior". Call "add_thread_silent" after "fork_inferior". * inf-ptrace.c: Include "nat/fork-inferior.h" and "utils.h". (inf_ptrace_create_inferior): Call "gdb_startup_inferior" instead of "startup_inferior". Call "add_thread_silent" after "fork_inferior". * inferior.h: Include "common-inferior.h". (trace_start_error): Move to "common/common-utils.h". (trace_start_error_with_name): Likewise. (fork_inferior): Move prototype to "nat/fork-inferior.h". (startup_inferior): Likewise. (gdb_startup_inferior): New prototype. * nat/fork-inferior.c: New file, with contents from "fork-child.c". * nat/fork-inferior.h: New file. * procfs.c (procfs_init_inferior): Call "gdb_startup_inferior" instead of "startup_inferior". Call "add_thread_silent" after "fork_inferior". * target.h (target_terminal_init): Move prototype to "target/target.h". (target_terminal_inferior): Likewise. (target_terminal_ours): Likewise. * target/target.h (target_terminal_init): New prototype, moved from "target.h". (target_terminal_inferior): Likewise. (target_terminal_ours): Likewise. * utils.c (gdb_flush_out_err): New function. gdb/gdbserver/ChangeLog: 2017-06-07 Sergio Durigan Junior <sergiodj@redhat.com> Pedro Alves <palves@redhat.com> * Makefile.in (SFILES): Add "nat/fork-inferior.o". * configure: Regenerate. * configure.srv (srv_linux_obj): Add "fork-child.o" and "fork-inferior.o". (i[34567]86-*-lynxos*): Likewise. (spu*-*-*): Likewise. * fork-child.c: New file. * linux-low.c: Include "common-inferior.h", "nat/fork-inferior.h" and "environ.h". (linux_ptrace_fun): New function. (linux_create_inferior): Adjust function prototype to reflect change on "target.h". Adjust function code to use "fork_inferior". (linux_request_interrupt): Delete "signal_pid". * lynx-low.c: Include "common-inferior.h" and "nat/fork-inferior.h". (lynx_ptrace_fun): New function. (lynx_create_inferior): Adjust function prototype to reflect change on "target.h". Adjust function code to use "fork_inferior". * nto-low.c (nto_create_inferior): Adjust function prototype and code to reflect change on "target.h". Update comments. * server.c: Include "common-inferior.h", "nat/fork-inferior.h", "common-terminal.h" and "environ.h". (terminal_fd): Moved to fork-child.c. (old_foreground_pgrp): Likewise. (restore_old_foreground_pgrp): Likewise. (last_status): Make it global. (last_ptid): Likewise. (our_environ): New variable. (startup_with_shell): Likewise. (program_name): Likewise. (program_argv): Rename to... (program_args): ...this. (wrapper_argv): New variable. (start_inferior): Delete function. (get_exec_wrapper): New function. (get_exec_file): Likewise. (get_environ): Likewise. (prefork_hook): Likewise. (post_fork_inferior): Likewise. (postfork_hook): Likewise. (postfork_child_hook): Likewise. (handle_v_run): Update code to deal with arguments coming from the remote host. Update calls from "start_inferior" to "create_inferior". (captured_main): Likewise. Initialize environment variable. Call "have_job_control". * server.h (post_fork_inferior): New prototype. (get_environ): Likewise. (last_status): Declare. (last_ptid): Likewise. (signal_pid): Likewise. * spu-low.c: Include "common-inferior.h" and "nat/fork-inferior.h". (spu_ptrace_fun): New function. (spu_create_inferior): Adjust function prototype to reflect change on "target.h". Adjust function code to use "fork_inferior". * target.c (target_terminal_init): New function. (target_terminal_inferior): Likewise. (target_terminal_ours): Likewise. * target.h: Include <vector>. (struct target_ops) <create_inferior>: Update prototype. (create_inferior): Update macro. * utils.c (gdb_flush_out_err): New function. * win32-low.c (win32_create_inferior): Adjust function prototype and code to reflect change on "target.h". gdb/testsuite/ChangeLog: 2017-06-07 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.server/non-existing-program.exp: Update regex in order to reflect the fact that gdbserver is now using fork_inferior (with a shell) to startup the inferior.
2016-12-23 03:11:11 +01:00
Multi-target support This commit adds multi-target support to GDB. What this means is that with this commit, GDB can now be connected to different targets at the same time. E.g., you can debug a live native process and a core dump at the same time, connect to multiple gdbservers, etc. Actually, the word "target" is overloaded in gdb. We already have a target stack, with pushes several target_ops instances on top of one another. We also have "info target" already, which means something completely different to what this patch does. So from here on, I'll be using the "target connections" term, to mean an open process_stratum target, pushed on a target stack. This patch makes gdb have multiple target stacks, and multiple process_stratum targets open simultaneously. The user-visible changes / commands will also use this terminology, but of course it's all open to debate. User-interface-wise, not that much changes. The main difference is that each inferior may have its own target connection. A target connection (e.g., a target extended-remote connection) may support debugging multiple processes, just as before. Say you're debugging against gdbserver in extended-remote mode, and you do "add-inferior" to prepare to spawn a new process, like: (gdb) target extended-remote :9999 ... (gdb) start ... (gdb) add-inferior Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) file a.out ... (gdb) start ... At this point, you have two inferiors connected to the same gdbserver. With this commit, GDB will maintain a target stack per inferior, instead of a global target stack. To preserve the behavior above, by default, "add-inferior" makes the new inferior inherit a copy of the target stack of the current inferior. Same across a fork - the child inherits a copy of the target stack of the parent. While the target stacks are copied, the targets themselves are not. Instead, target_ops is made a refcounted_object, which means that target_ops instances are refcounted, which each inferior counting for a reference. What if you want to create an inferior and connect it to some _other_ target? For that, this commit introduces a new "add-inferior -no-connection" option that makes the new inferior not share the current inferior's target. So you could do: (gdb) target extended-remote :9999 Remote debugging using :9999 ... (gdb) add-inferior -no-connection [New inferior 2] Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 <null> (gdb) tar extended-remote :10000 Remote debugging using :10000 ... (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 process 18450 target:/home/pedro/tmp/main (gdb) A following patch will extended "info inferiors" to include a column indicating which connection an inferior is bound to, along with a couple other UI tweaks. Other than that, debugging is the same as before. Users interact with inferiors and threads as before. The only difference is that inferiors may be bound to processes running in different machines. That's pretty much all there is to it in terms of noticeable UI changes. On to implementation. Since we can be connected to different systems at the same time, a ptid_t is no longer a unique identifier. Instead a thread can be identified by a pair of ptid_t and 'process_stratum_target *', the later being the instance of the process_stratum target that owns the process/thread. Note that process_stratum_target inherits from target_ops, and all process_stratum targets inherit from process_stratum_target. In earlier patches, many places in gdb were converted to refer to threads by thread_info pointer instead of ptid_t, but there are still places in gdb where we start with a pid/tid and need to find the corresponding inferior or thread_info objects. So you'll see in the patch many places adding a process_stratum_target parameter to functions that used to take only a ptid_t. Since each inferior has its own target stack now, we can always find the process_stratum target for an inferior. That is done via a inf->process_target() convenience method. Since each inferior has its own target stack, we need to handle the "beneath" calls when servicing target calls. The solution I settled with is just to make sure to switch the current inferior to the inferior you want before making a target call. Not relying on global context is just not feasible in current GDB. Fortunately, there aren't that many places that need to do that, because generally most code that calls target methods already has the current context pointing to the right inferior/thread. Note, to emphasize -- there's no method to "switch to this target stack". Instead, you switch the current inferior, and that implicitly switches the target stack. In some spots, we need to iterate over all inferiors so that we reach all target stacks. Native targets are still singletons. There's always only a single instance of such targets. Remote targets however, we'll have one instance per remote connection. The exec target is still a singleton. There's only one instance. I did not see the point of instanciating more than one exec_target object. After vfork, we need to make sure to push the exec target on the new inferior. See exec_on_vfork. For type safety, functions that need a {target, ptid} pair to identify a thread, take a process_stratum_target pointer for target parameter instead of target_ops *. Some shared code in gdb/nat/ also need to gain a target pointer parameter. This poses an issue, since gdbserver doesn't have process_stratum_target, only target_ops. To fix this, this commit renames gdbserver's target_ops to process_stratum_target. I think this makes sense. There's no concept of target stack in gdbserver, and gdbserver's target_ops really implements a process_stratum-like target. The thread and inferior iterator functions also gain process_stratum_target parameters. These are used to be able to iterate over threads and inferiors of a given target. Following usual conventions, if the target pointer is null, then we iterate over threads and inferiors of all targets. I tried converting "add-inferior" to the gdb::option framework, as a preparatory patch, but that stumbled on the fact that gdb::option does not support file options yet, for "add-inferior -exec". I have a WIP patchset that adds that, but it's not a trivial patch, mainly due to need to integrate readline's filename completion, so I deferred that to some other time. In infrun.c/infcmd.c, the main change is that we need to poll events out of all targets. See do_target_wait. Right after collecting an event, we switch the current inferior to an inferior bound to the target that reported the event, so that target methods can be used while handling the event. This makes most of the code transparent to multi-targets. See fetch_inferior_event. infrun.c:stop_all_threads is interesting -- in this function we need to stop all threads of all targets. What the function does is send an asynchronous stop request to all threads, and then synchronously waits for events, with target_wait, rinse repeat, until all it finds are stopped threads. Now that we have multiple targets, it's not efficient to synchronously block in target_wait waiting for events out of one target. Instead, we implement a mini event loop, with interruptible_select, select'ing on one file descriptor per target. For this to work, we need to be able to ask the target for a waitable file descriptor. Such file descriptors already exist, they are the descriptors registered in the main event loop with add_file_handler, inside the target_async implementations. This commit adds a new target_async_wait_fd target method that just returns the file descriptor in question. See wait_one / stop_all_threads in infrun.c. The 'threads_executing' global is made a per-target variable. Since it is only relevant to process_stratum_target targets, this is where it is put, instead of in target_ops. You'll notice that remote.c includes some FIXME notes. These refer to the fact that the global arrays that hold data for the remote packets supported are still globals. For example, if we connect to two different servers/stubs, then each might support different remote protocol features. They might even be different architectures, like e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a host/controller scenario as a single program. That isn't going to work correctly today, because of said globals. I'm leaving fixing that for another pass, since it does not appear to be trivial, and I'd rather land the base work first. It's already useful to be able to debug multiple instances of the same server (e.g., a distributed cluster, where you have full control over the servers installed), so I think as is it's already reasonable incremental progress. Current limitations: - You can only resume more that one target at the same time if all targets support asynchronous debugging, and support non-stop mode. It should be possible to support mixed all-stop + non-stop backends, but that is left for another time. This means that currently in order to do multi-target with gdbserver you need to issue "maint set target-non-stop on". I would like to make that mode be the default, but we're not there yet. Note that I'm talking about how the target backend works, only. User-visible all-stop mode works just fine. - As explained above, connecting to different remote servers at the same time is likely to produce bad results if they don't support the exact set of RSP features. FreeBSD updates courtesy of John Baldwin. gdb/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> John Baldwin <jhb@FreeBSD.org> * aarch64-linux-nat.c (aarch64_linux_nat_target::thread_architecture): Adjust. * ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call. (task_command_1): Likewise. * aix-thread.c (sync_threadlists, aix_thread_target::resume) (aix_thread_target::wait, aix_thread_target::fetch_registers) (aix_thread_target::store_registers) (aix_thread_target::thread_alive): Adjust. * amd64-fbsd-tdep.c: Include "inferior.h". (amd64fbsd_get_thread_local_address): Pass down target. * amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle thread's gdbarch instead of target_gdbarch. * break-catch-sig.c (signal_catchpoint_print_it): Adjust call to get_last_target_status. * break-catch-syscall.c (print_it_catch_syscall): Likewise. * breakpoint.c (breakpoints_should_be_inserted_now): Consider all inferiors. (update_inserted_breakpoint_locations): Skip if inferiors with no execution. (update_global_location_list): When handling moribund locations, find representative inferior for location's pspace, and use thread count of its process_stratum target. * bsd-kvm.c (bsd_kvm_target_open): Pass target down. * bsd-uthread.c (bsd_uthread_target::wait): Use as_process_stratum_target and adjust thread_change_ptid and add_thread calls. (bsd_uthread_target::update_thread_list): Use as_process_stratum_target and adjust find_thread_ptid, thread_change_ptid and add_thread calls. * btrace.c (maint_btrace_packet_history_cmd): Adjust find_thread_ptid call. * corelow.c (add_to_thread_list): Adjust add_thread call. (core_target_open): Adjust add_thread_silent and thread_count calls. (core_target::pid_to_str): Adjust find_inferior_ptid call. * ctf.c (ctf_target_open): Adjust add_thread_silent call. * event-top.c (async_disconnect): Pop targets from all inferiors. * exec.c (add_target_sections): Push exec target on all inferiors sharing the program space. (remove_target_sections): Remove the exec target from all inferiors sharing the program space. (exec_on_vfork): New. * exec.h (exec_on_vfork): Declare. * fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::update_thread_list): Adjust. (fbsd_nat_target::resume): Adjust. (fbsd_handle_debug_trap): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust. * fbsd-tdep.c (fbsd_corefile_thread): Adjust get_thread_arch_regcache call. * fork-child.c (gdb_startup_inferior): Pass target down to startup_inferior and set_executing. * gdbthread.h (struct process_stratum_target): Forward declare. (add_thread, add_thread_silent, add_thread_with_info) (in_thread_list): Add process_stratum_target parameter. (find_thread_ptid(inferior*, ptid_t)): New overload. (find_thread_ptid, thread_change_ptid): Add process_stratum_target parameter. (all_threads()): Delete overload. (all_threads, all_non_exited_threads): Add process_stratum_target parameter. (all_threads_safe): Use brace initialization. (thread_count): Add process_stratum_target parameter. (set_resumed, set_running, set_stop_requested, set_executing) (threads_are_executing, finish_thread_state): Add process_stratum_target parameter. (switch_to_thread): Use is_current_thread. * i386-fbsd-tdep.c: Include "inferior.h". (i386fbsd_get_thread_local_address): Pass down target. * i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust. * inf-child.c (inf_child_target::maybe_unpush_target): Remove have_inferiors check. * inf-ptrace.c (inf_ptrace_target::create_inferior) (inf_ptrace_target::attach): Adjust. * infcall.c (run_inferior_call): Adjust. * infcmd.c (run_command_1): Pass target to scoped_finish_thread_state. (proceed_thread_callback): Skip inferiors with no execution. (continue_command): Rename 'all_threads' local to avoid hiding 'all_threads' function. Adjust get_last_target_status call. (prepare_one_step): Adjust set_running call. (signal_command): Use user_visible_resume_target. Compare thread pointers instead of inferior_ptid. (info_program_command): Adjust to pass down target. (attach_command): Mark target's 'thread_executing' flag. (stop_current_target_threads_ns): New, factored out from ... (interrupt_target_1): ... this. Switch inferior before making target calls. * inferior-iter.h (struct all_inferiors_iterator, struct all_inferiors_range) (struct all_inferiors_safe_range) (struct all_non_exited_inferiors_range): Filter on process_stratum_target too. Remove explicit. * inferior.c (inferior::inferior): Push dummy target on target stack. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors): Add process_stratum_target parameter, and pass it down. (have_live_inferiors): Adjust. (switch_to_inferior_and_push_target): New. (add_inferior_command, clone_inferior_command): Handle "-no-connection" parameter. Use switch_to_inferior_and_push_target. (_initialize_inferior): Mention "-no-connection" option in the help of "add-inferior" and "clone-inferior" commands. * inferior.h: Include "process-stratum-target.h". (interrupt_target_1): Use bool. (struct inferior) <push_target, unpush_target, target_is_pushed, find_target_beneath, top_target, process_target, target_at, m_stack>: New. (discard_all_inferiors): Delete. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors) (all_inferiors, all_non_exited_inferiors): Add process_stratum_target parameter. * infrun.c: Include "gdb_select.h" and <unordered_map>. (target_last_proc_target): New global. (follow_fork_inferior): Push target on new inferior. Pass target to add_thread_silent. Call exec_on_vfork. Handle target's reference count. (follow_fork): Adjust get_last_target_status call. Also consider target. (follow_exec): Push target on new inferior. (struct execution_control_state) <target>: New field. (user_visible_resume_target): New. (do_target_resume): Call target_async. (resume_1): Set target's threads_executing flag. Consider resume target. (commit_resume_all_targets): New. (proceed): Also consider resume target. Skip threads of inferiors with no execution. Commit resumtion in all targets. (start_remote): Pass current inferior to wait_for_inferior. (infrun_thread_stop_requested): Consider target as well. Pass thread_info pointer to clear_inline_frame_state instead of ptid. (infrun_thread_thread_exit): Consider target as well. (random_pending_event_thread): New inferior parameter. Use it. (do_target_wait): Rename to ... (do_target_wait_1): ... this. Add inferior parameter, and pass it down. (threads_are_resumed_pending_p, do_target_wait): New. (prepare_for_detach): Adjust calls. (wait_for_inferior): New inferior parameter. Handle it. Use do_target_wait_1 instead of do_target_wait. (fetch_inferior_event): Adjust. Switch to representative inferior. Pass target down. (set_last_target_status): Add process_stratum_target parameter. Save target in global. (get_last_target_status): Add process_stratum_target parameter and handle it. (nullify_last_target_wait_ptid): Clear 'target_last_proc_target'. (context_switch): Check inferior_ptid == null_ptid before calling inferior_thread(). (get_inferior_stop_soon): Pass down target. (wait_one): Rename to ... (poll_one_curr_target): ... this. (struct wait_one_event): New. (wait_one): New. (stop_all_threads): Adjust. (handle_no_resumed, handle_inferior_event): Adjust to consider the event's target. (switch_back_to_stepped_thread): Also consider target. (print_stop_event): Update. (normal_stop): Update. Also consider the resume target. * infrun.h (wait_for_inferior): Remove declaration. (user_visible_resume_target): New declaration. (get_last_target_status, set_last_target_status): New process_stratum_target parameter. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter, and use it. (clear_inline_frame_state (thread_info*)): New. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter. (clear_inline_frame_state (thread_info*)): Declare. * linux-fork.c (delete_checkpoint_command): Pass target down to find_thread_ptid. (checkpoint_command): Adjust. * linux-nat.c (linux_nat_target::follow_fork): Switch to thread instead of just tweaking inferior_ptid. (linux_nat_switch_fork): Pass target down to thread_change_ptid. (exit_lwp): Pass target down to find_thread_ptid. (attach_proc_task_lwp_callback): Pass target down to add_thread/set_running/set_executing. (linux_nat_target::attach): Pass target down to thread_change_ptid. (get_detach_signal): Pass target down to find_thread_ptid. Consider last target status's target. (linux_resume_one_lwp_throw, resume_lwp) (linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp) (stop_wait_callback, save_stop_reason, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down. (linux_nat_target::async_wait_fd): New. (linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass target down. * linux-nat.h (linux_nat_target::async_wait_fd): Declare. * linux-tdep.c (get_thread_arch_regcache): Pass target down. * linux-thread-db.c (struct thread_db_info::process_target): New field. (add_thread_db_info): Save target. (get_thread_db_info): New process_stratum_target parameter. Also match target. (delete_thread_db_info): New process_stratum_target parameter. Also match target. (thread_from_lwp): Adjust to pass down target. (thread_db_notice_clone): Pass down target. (check_thread_db_callback): Pass down target. (try_thread_db_load_1): Always push the thread_db target. (try_thread_db_load, record_thread): Pass target down. (thread_db_target::detach): Pass target down. Always unpush the thread_db target. (thread_db_target::wait, thread_db_target::mourn_inferior): Pass target down. Always unpush the thread_db target. (find_new_threads_callback, thread_db_find_new_threads_2) (thread_db_target::update_thread_list): Pass target down. (thread_db_target::pid_to_str): Pass current inferior down. (thread_db_target::get_thread_local_address): Pass target down. (thread_db_target::resume, maintenance_check_libthread_db): Pass target down. * nto-procfs.c (nto_procfs_target::update_thread_list): Adjust. * procfs.c (procfs_target::procfs_init_inferior): Declare. (proc_set_current_signal, do_attach, procfs_target::wait): Adjust. (procfs_init_inferior): Rename to ... (procfs_target::procfs_init_inferior): ... this and adjust. (procfs_target::create_inferior, procfs_notice_thread) (procfs_do_thread_registers): Adjust. * ppc-fbsd-tdep.c: Include "inferior.h". (ppcfbsd_get_thread_local_address): Pass down target. * proc-service.c (ps_xfer_memory): Switch current inferior and program space as well. (get_ps_regcache): Pass target down. * process-stratum-target.c (process_stratum_target::thread_address_space) (process_stratum_target::thread_architecture): Pass target down. * process-stratum-target.h (process_stratum_target::threads_executing): New field. (as_process_stratum_target): New. * ravenscar-thread.c (ravenscar_thread_target::update_inferior_ptid): Pass target down. (ravenscar_thread_target::wait, ravenscar_add_thread): Pass target down. * record-btrace.c (record_btrace_target::info_record): Adjust. (record_btrace_target::record_method) (record_btrace_target::record_is_replaying) (record_btrace_target::fetch_registers) (get_thread_current_frame_id, record_btrace_target::resume) (record_btrace_target::wait, record_btrace_target::stop): Pass target down. * record-full.c (record_full_wait_1): Switch to event thread. Pass target down. * regcache.c (regcache::regcache) (get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add process_stratum_target parameter and handle it. (current_thread_target): New global. (get_thread_regcache): Add process_stratum_target parameter and handle it. Switch inferior before calling target method. (get_thread_regcache): Pass target down. (get_thread_regcache_for_ptid): Pass target down. (registers_changed_ptid): Add process_stratum_target parameter and handle it. (registers_changed_thread, registers_changed): Pass target down. (test_get_thread_arch_aspace_regcache): New. (current_regcache_test): Define a couple local test_target_ops instances and use them for testing. (readwrite_regcache): Pass process_stratum_target parameter. (cooked_read_test, cooked_write_test): Pass mock_target down. * regcache.h (get_thread_regcache, get_thread_arch_regcache) (get_thread_arch_aspace_regcache): Add process_stratum_target parameter. (regcache::target): New method. (regcache::regcache, regcache::get_thread_arch_aspace_regcache) (regcache::registers_changed_ptid): Add process_stratum_target parameter. (regcache::m_target): New field. (registers_changed_ptid): Add process_stratum_target parameter. * remote.c (remote_state::supports_vCont_probed): New field. (remote_target::async_wait_fd): New method. (remote_unpush_and_throw): Add remote_target parameter. (get_current_remote_target): Adjust. (remote_target::remote_add_inferior): Push target. (remote_target::remote_add_thread) (remote_target::remote_notice_new_inferior) (get_remote_thread_info): Pass target down. (remote_target::update_thread_list): Skip threads of inferiors bound to other targets. (remote_target::close): Don't discard inferiors. (remote_target::add_current_inferior_and_thread) (remote_target::process_initial_stop_replies) (remote_target::start_remote) (remote_target::remote_serial_quit_handler): Pass down target. (remote_target::remote_unpush_target): New remote_target parameter. Unpush the target from all inferiors. (remote_target::remote_unpush_and_throw): New remote_target parameter. Pass it down. (remote_target::open_1): Check whether the current inferior has execution instead of checking whether any inferior is live. Pass target down. (remote_target::remote_detach_1): Pass down target. Use remote_unpush_target. (extended_remote_target::attach): Pass down target. (remote_target::remote_vcont_probe): Set supports_vCont_probed. (remote_target::append_resumption): Pass down target. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc, remote_target::resume) (remote_target::commit_resume): Pass down target. (remote_target::remote_stop_ns): Check supports_vCont_probed. (remote_target::interrupt_query) (remote_target::remove_new_fork_children) (remote_target::check_pending_events_prevent_wildcard_vcont) (remote_target::remote_parse_stop_reply) (remote_target::process_stop_reply): Pass down target. (first_remote_resumed_thread): New remote_target parameter. Pass it down. (remote_target::wait_as): Pass down target. (unpush_and_perror): New remote_target parameter. Pass it down. (remote_target::readchar, remote_target::remote_serial_write) (remote_target::getpkt_or_notif_sane_1) (remote_target::kill_new_fork_children, remote_target::kill): Pass down target. (remote_target::mourn_inferior): Pass down target. Use remote_unpush_target. (remote_target::core_of_thread) (remote_target::remote_btrace_maybe_reopen): Pass down target. (remote_target::pid_to_exec_file) (remote_target::thread_handle_to_thread_info): Pass down target. (remote_target::async_wait_fd): New. * riscv-fbsd-tdep.c: Include "inferior.h". (riscv_fbsd_get_thread_local_address): Pass down target. * sol2-tdep.c (sol2_core_pid_to_str): Pass down target. * sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs) (ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback): Adjust. * solib-spu.c (spu_skip_standalone_loader): Pass down target. * solib-svr4.c (enable_break): Pass down target. * spu-multiarch.c (parse_spufs_run): Pass down target. * spu-tdep.c (spu2ppu_sniffer): Pass down target. * target-delegates.c: Regenerate. * target.c (g_target_stack): Delete. (current_top_target): Return the current inferior's top target. (target_has_execution_1): Refer to the passed-in inferior's top target. (target_supports_terminal_ours): Check whether the initial inferior was already created. (decref_target): New. (target_stack::push): Incref/decref the target. (push_target, push_target, unpush_target): Adjust. (target_stack::unpush): Defref target. (target_is_pushed): Return bool. Adjust to refer to the current inferior's target stack. (dispose_inferior): Delete, and inline parts ... (target_preopen): ... here. Only dispose of the current inferior. (target_detach): Hold strong target reference while detaching. Pass target down. (target_thread_name): Add assertion. (target_resume): Pass down target. (target_ops::beneath, find_target_at): Adjust to refer to the current inferior's target stack. (get_dummy_target): New. (target_pass_ctrlc): Pass the Ctrl-C to the first inferior that has a thread running. (initialize_targets): Rename to ... (_initialize_target): ... this. * target.h: Include "gdbsupport/refcounted-object.h". (struct target_ops): Inherit refcounted_object. (target_ops::shortname, target_ops::longname): Make const. (target_ops::async_wait_fd): New method. (decref_target): Declare. (struct target_ops_ref_policy): New. (target_ops_ref): New typedef. (get_dummy_target): Declare function. (target_is_pushed): Return bool. * thread-iter.c (all_matching_threads_iterator::m_inf_matches) (all_matching_threads_iterator::all_matching_threads_iterator): Handle filter target. * thread-iter.h (struct all_matching_threads_iterator, struct all_matching_threads_range, class all_non_exited_threads_range): Filter by target too. Remove explicit. * thread.c (threads_executing): Delete. (inferior_thread): Pass down current inferior. (clear_thread_inferior_resources): Pass down thread pointer instead of ptid_t. (add_thread_silent, add_thread_with_info, add_thread): Add process_stratum_target parameter. Use it for thread and inferior searches. (is_current_thread): New. (thread_info::deletable): Use it. (find_thread_ptid, thread_count, in_thread_list) (thread_change_ptid, set_resumed, set_running): New process_stratum_target parameter. Pass it down. (set_executing): New process_stratum_target parameter. Pass it down. Adjust reference to 'threads_executing'. (threads_are_executing): New process_stratum_target parameter. Adjust reference to 'threads_executing'. (set_stop_requested, finish_thread_state): New process_stratum_target parameter. Pass it down. (switch_to_thread): Also match inferior. (switch_to_thread): New process_stratum_target parameter. Pass it down. (update_threads_executing): Reimplement. * top.c (quit_force): Pop targets from all inferior. (gdb_init): Don't call initialize_targets. * windows-nat.c (windows_nat_target) <get_windows_debug_event>: Declare. (windows_add_thread, windows_delete_thread): Adjust. (get_windows_debug_event): Rename to ... (windows_nat_target::get_windows_debug_event): ... this. Adjust. * tracefile-tfile.c (tfile_target_open): Pass down target. * gdbsupport/common-gdbthread.h (struct process_stratum_target): Forward declare. (switch_to_thread): Add process_stratum_target parameter. * mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target parameter. Use it. (mi_on_resume): Pass target down. * nat/fork-inferior.c (startup_inferior): Add process_stratum_target parameter. Pass it down. * nat/fork-inferior.h (startup_inferior): Add process_stratum_target parameter. * python/py-threadevent.c (py_get_event_thread): Pass target down. gdb/gdbserver/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> * fork-child.c (post_fork_inferior): Pass target down to startup_inferior. * inferiors.c (switch_to_thread): Add process_stratum_target parameter. * lynx-low.c (lynx_target_ops): Now a process_stratum_target. * nto-low.c (nto_target_ops): Now a process_stratum_target. * linux-low.c (linux_target_ops): Now a process_stratum_target. * remote-utils.c (prepare_resume_reply): Pass the target to switch_to_thread. * target.c (the_target): Now a process_stratum_target. (done_accessing_memory): Pass the target to switch_to_thread. (set_target_ops): Ajust to use process_stratum_target. * target.h (struct target_ops): Rename to ... (struct process_stratum_target): ... this. (the_target, set_target_ops): Adjust. (prepare_to_access_memory): Adjust comment. * win32-low.c (child_xfer_memory): Adjust to use process_stratum_target. (win32_target_ops): Now a process_stratum_target.
2020-01-10 21:06:08 +01:00
#include "process-stratum-target.h"
gdb/ Rename and move inferior_thread_state and inferior_status. * gdbthread.h (struct thread_control_state): New struct, move fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step and stop_bpstat here from struct thread_info. (struct thread_suspend_state): New struct, move field stop_signal here from struct thread_info. (struct thread_info): Move the fields above from this struct. * inferior.h: Move the inferior_thread_state and inferior_status declarations comment to their definitions at infrun.c. (struct inferior_control_state): New struct, move field stop_soon from struct inferior here. (struct inferior_suspend_state): New empty struct. (struct inferior): New fields control and suspend. Move out field stop_soon. * infrun.c (struct inferior_thread_state): Rename to ... (infcall_suspend_state): ... here. Replace field stop_signal by fields thread_suspend and inferior_suspend. (save_inferior_thread_state): Rename to ... (save_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (restore_inferior_thread_state): Rename to ... (restore_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (do_restore_inferior_thread_state_cleanup): Rename to ... (do_restore_infcall_suspend_state_cleanup): ... here. (make_cleanup_restore_inferior_thread_state): Rename to ... (make_cleanup_restore_infcall_suspend_state): ... here. (discard_inferior_thread_state): Rename to ... (discard_infcall_suspend_state): ... here. (get_inferior_thread_state_regcache): Rename to ... (get_infcall_suspend_state_regcache): ... here. (struct inferior_status): Rename to ... (struct infcall_control_state): ... here. Replace fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step, stop_bpstat and stop_soon by fields thread_control and inferior_control. (save_inferior_status): Rename to ... (save_infcall_control_state): ... here. Update the code for new fields. (restore_inferior_status): Rename to ... (restore_infcall_control_state): ... here. Update the code for new fields. (do_restore_inferior_status_cleanup): Rename to ... (do_restore_infcall_control_state_cleanup): ... here. (make_cleanup_restore_inferior_status): Rename to ... (make_cleanup_restore_infcall_control_state): ... here. (discard_inferior_status): Rename to ... (discard_infcall_control_state): ... here. * alpha-tdep.c, breakpoint.c, dummy-frame.c, dummy-frame.h, exceptions.c, fbsd-nat.c, gdbthread.h, infcall.c, infcmd.c, inferior.c, inferior.h, infrun.c, linux-nat.c, mi/mi-interp.c, mips-tdep.c, procfs.c, solib-irix.c, solib-osf.c, solib-spu.c, solib-sunos.c, solib-svr4.c, thread.c, windows-nat.c: Update all the references to the moved fields and renamed functions.
2010-11-28 05:31:25 +01:00
struct infcall_suspend_state;
struct infcall_control_state;
1999-04-26 20:34:20 +02:00
gdb/ Rename and move inferior_thread_state and inferior_status. * gdbthread.h (struct thread_control_state): New struct, move fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step and stop_bpstat here from struct thread_info. (struct thread_suspend_state): New struct, move field stop_signal here from struct thread_info. (struct thread_info): Move the fields above from this struct. * inferior.h: Move the inferior_thread_state and inferior_status declarations comment to their definitions at infrun.c. (struct inferior_control_state): New struct, move field stop_soon from struct inferior here. (struct inferior_suspend_state): New empty struct. (struct inferior): New fields control and suspend. Move out field stop_soon. * infrun.c (struct inferior_thread_state): Rename to ... (infcall_suspend_state): ... here. Replace field stop_signal by fields thread_suspend and inferior_suspend. (save_inferior_thread_state): Rename to ... (save_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (restore_inferior_thread_state): Rename to ... (restore_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (do_restore_inferior_thread_state_cleanup): Rename to ... (do_restore_infcall_suspend_state_cleanup): ... here. (make_cleanup_restore_inferior_thread_state): Rename to ... (make_cleanup_restore_infcall_suspend_state): ... here. (discard_inferior_thread_state): Rename to ... (discard_infcall_suspend_state): ... here. (get_inferior_thread_state_regcache): Rename to ... (get_infcall_suspend_state_regcache): ... here. (struct inferior_status): Rename to ... (struct infcall_control_state): ... here. Replace fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step, stop_bpstat and stop_soon by fields thread_control and inferior_control. (save_inferior_status): Rename to ... (save_infcall_control_state): ... here. Update the code for new fields. (restore_inferior_status): Rename to ... (restore_infcall_control_state): ... here. Update the code for new fields. (do_restore_inferior_status_cleanup): Rename to ... (do_restore_infcall_control_state_cleanup): ... here. (make_cleanup_restore_inferior_status): Rename to ... (make_cleanup_restore_infcall_control_state): ... here. (discard_inferior_status): Rename to ... (discard_infcall_control_state): ... here. * alpha-tdep.c, breakpoint.c, dummy-frame.c, dummy-frame.h, exceptions.c, fbsd-nat.c, gdbthread.h, infcall.c, infcmd.c, inferior.c, inferior.h, infrun.c, linux-nat.c, mi/mi-interp.c, mips-tdep.c, procfs.c, solib-irix.c, solib-osf.c, solib-spu.c, solib-sunos.c, solib-svr4.c, thread.c, windows-nat.c: Update all the references to the moved fields and renamed functions.
2010-11-28 05:31:25 +01:00
extern void restore_infcall_suspend_state (struct infcall_suspend_state *);
extern void restore_infcall_control_state (struct infcall_control_state *);
* dummy-frame.c (dummy_frame): Replace regcache member with caller_state. (dummy_frame_push): Replace caller_regcache arg with caller_state. All callers updated. (remove_dummy_frame,pop_dummy_frame,lookup_dummy_frame): New fns. (dummy_frame_pop): Rewrite. Verify requested frame is in the dummy frame stack. Restore program state. (cleanup_dummy_frames): Rewrite. (dummy_frame_sniffer): Update. Make static. * dummy-frame.h (regcache,frame_info): Delete forward decls. (inferior_thread_state): New forward decl. (dummy_frame_push): Update prototype. * frame.c (frame_pop): dummy_frame_pop now does all the work for DUMMY_FRAMEs. * infcall.c (breakpoint_auto_delete_contents): Delete. (get_function_name,run_inferior_call): New fns. (call_function_by_hand): Simplify by moving some code to get_function_name, run_inferior_call. Inferior function call wrapped in TRY_CATCH so there's less need for cleanups and all exits from proceed are handled similarily. Detect program exit. Detect program stopping in a different thread. Make error messages more consistent. * inferior.h (inferior_thread_state): Declare (opaque type). (save_inferior_thread_state,restore_inferior_thread_state, make_cleanup_restore_inferior_thread_state, discard_inferior_thread_state, get_inferior_thread_state_regcache): Declare. (save_inferior_status): Update prototype. * infrun.c: (normal_stop): When stopped for the completion of an inferior function call, verify the expected stack frame kind. (inferior_thread_state): New struct. (save_inferior_thread_state,restore_inferior_thread_state, do_restore_inferior_thread_state_cleanup, make_cleanup_restore_inferior_thread_state, discard_inferior_thread_state, get_inferior_thread_state_regcache): New functions. (inferior_status): Move stop_signal, stop_pc, registers to inferior_thread_state. Remove restore_stack_info. (save_inferior_status): Remove arg restore_stack_info. All callers updated. Remove saving of state now saved by save_inferior_thread_state. (restore_inferior_status): Remove restoration of state now done by restore_inferior_thread_state. (discard_inferior_status): Remove freeing of registers, now done by discard_inferior_thread_state. * gdb.base/break.exp: Update expected gdb output. * gdb.base/sepdebug.exp: Ditto. * gdb.mi/mi-syn-frame.exp: Ditto. * gdb.mi/mi2-syn-frame.exp: Ditto. * gdb.base/call-signal-resume.exp: New file. * gdb.base/call-signals.c: New file. * gdb.base/unwindonsignal.exp: New file. * gdb.base/unwindonsignal.c: New file. * gdb.threads/interrupted-hand-call.exp: New file. * gdb.threads/interrupted-hand-call.c: New file. * gdb.threads/thread-unwindonsignal.exp: New file.
2009-01-19 20:05:01 +01:00
/* A deleter for infcall_suspend_state that calls
restore_infcall_suspend_state. */
struct infcall_suspend_state_deleter
{
void operator() (struct infcall_suspend_state *state) const
{
try
{
restore_infcall_suspend_state (state);
}
catch (const gdb_exception_error &e)
{
/* If we are restoring the inferior state due to an exception,
some error message will be printed. So, only warn the user
when we cannot restore during normal execution. */
if (!std::uncaught_exception ())
warning (_("Failed to restore inferior state: %s"), e.what ());
}
}
};
/* A unique_ptr specialization for infcall_suspend_state. */
typedef std::unique_ptr<infcall_suspend_state, infcall_suspend_state_deleter>
infcall_suspend_state_up;
extern infcall_suspend_state_up save_infcall_suspend_state ();
/* A deleter for infcall_control_state that calls
restore_infcall_control_state. */
struct infcall_control_state_deleter
{
void operator() (struct infcall_control_state *state) const
{
restore_infcall_control_state (state);
}
};
/* A unique_ptr specialization for infcall_control_state. */
typedef std::unique_ptr<infcall_control_state, infcall_control_state_deleter>
infcall_control_state_up;
* dummy-frame.c (dummy_frame): Replace regcache member with caller_state. (dummy_frame_push): Replace caller_regcache arg with caller_state. All callers updated. (remove_dummy_frame,pop_dummy_frame,lookup_dummy_frame): New fns. (dummy_frame_pop): Rewrite. Verify requested frame is in the dummy frame stack. Restore program state. (cleanup_dummy_frames): Rewrite. (dummy_frame_sniffer): Update. Make static. * dummy-frame.h (regcache,frame_info): Delete forward decls. (inferior_thread_state): New forward decl. (dummy_frame_push): Update prototype. * frame.c (frame_pop): dummy_frame_pop now does all the work for DUMMY_FRAMEs. * infcall.c (breakpoint_auto_delete_contents): Delete. (get_function_name,run_inferior_call): New fns. (call_function_by_hand): Simplify by moving some code to get_function_name, run_inferior_call. Inferior function call wrapped in TRY_CATCH so there's less need for cleanups and all exits from proceed are handled similarily. Detect program exit. Detect program stopping in a different thread. Make error messages more consistent. * inferior.h (inferior_thread_state): Declare (opaque type). (save_inferior_thread_state,restore_inferior_thread_state, make_cleanup_restore_inferior_thread_state, discard_inferior_thread_state, get_inferior_thread_state_regcache): Declare. (save_inferior_status): Update prototype. * infrun.c: (normal_stop): When stopped for the completion of an inferior function call, verify the expected stack frame kind. (inferior_thread_state): New struct. (save_inferior_thread_state,restore_inferior_thread_state, do_restore_inferior_thread_state_cleanup, make_cleanup_restore_inferior_thread_state, discard_inferior_thread_state, get_inferior_thread_state_regcache): New functions. (inferior_status): Move stop_signal, stop_pc, registers to inferior_thread_state. Remove restore_stack_info. (save_inferior_status): Remove arg restore_stack_info. All callers updated. Remove saving of state now saved by save_inferior_thread_state. (restore_inferior_status): Remove restoration of state now done by restore_inferior_thread_state. (discard_inferior_status): Remove freeing of registers, now done by discard_inferior_thread_state. * gdb.base/break.exp: Update expected gdb output. * gdb.base/sepdebug.exp: Ditto. * gdb.mi/mi-syn-frame.exp: Ditto. * gdb.mi/mi2-syn-frame.exp: Ditto. * gdb.base/call-signal-resume.exp: New file. * gdb.base/call-signals.c: New file. * gdb.base/unwindonsignal.exp: New file. * gdb.base/unwindonsignal.c: New file. * gdb.threads/interrupted-hand-call.exp: New file. * gdb.threads/interrupted-hand-call.c: New file. * gdb.threads/thread-unwindonsignal.exp: New file.
2009-01-19 20:05:01 +01:00
extern infcall_control_state_up save_infcall_control_state ();
gdb/ Rename and move inferior_thread_state and inferior_status. * gdbthread.h (struct thread_control_state): New struct, move fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step and stop_bpstat here from struct thread_info. (struct thread_suspend_state): New struct, move field stop_signal here from struct thread_info. (struct thread_info): Move the fields above from this struct. * inferior.h: Move the inferior_thread_state and inferior_status declarations comment to their definitions at infrun.c. (struct inferior_control_state): New struct, move field stop_soon from struct inferior here. (struct inferior_suspend_state): New empty struct. (struct inferior): New fields control and suspend. Move out field stop_soon. * infrun.c (struct inferior_thread_state): Rename to ... (infcall_suspend_state): ... here. Replace field stop_signal by fields thread_suspend and inferior_suspend. (save_inferior_thread_state): Rename to ... (save_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (restore_inferior_thread_state): Rename to ... (restore_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (do_restore_inferior_thread_state_cleanup): Rename to ... (do_restore_infcall_suspend_state_cleanup): ... here. (make_cleanup_restore_inferior_thread_state): Rename to ... (make_cleanup_restore_infcall_suspend_state): ... here. (discard_inferior_thread_state): Rename to ... (discard_infcall_suspend_state): ... here. (get_inferior_thread_state_regcache): Rename to ... (get_infcall_suspend_state_regcache): ... here. (struct inferior_status): Rename to ... (struct infcall_control_state): ... here. Replace fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step, stop_bpstat and stop_soon by fields thread_control and inferior_control. (save_inferior_status): Rename to ... (save_infcall_control_state): ... here. Update the code for new fields. (restore_inferior_status): Rename to ... (restore_infcall_control_state): ... here. Update the code for new fields. (do_restore_inferior_status_cleanup): Rename to ... (do_restore_infcall_control_state_cleanup): ... here. (make_cleanup_restore_inferior_status): Rename to ... (make_cleanup_restore_infcall_control_state): ... here. (discard_inferior_status): Rename to ... (discard_infcall_control_state): ... here. * alpha-tdep.c, breakpoint.c, dummy-frame.c, dummy-frame.h, exceptions.c, fbsd-nat.c, gdbthread.h, infcall.c, infcmd.c, inferior.c, inferior.h, infrun.c, linux-nat.c, mi/mi-interp.c, mips-tdep.c, procfs.c, solib-irix.c, solib-osf.c, solib-spu.c, solib-sunos.c, solib-svr4.c, thread.c, windows-nat.c: Update all the references to the moved fields and renamed functions.
2010-11-28 05:31:25 +01:00
extern void discard_infcall_suspend_state (struct infcall_suspend_state *);
extern void discard_infcall_control_state (struct infcall_control_state *);
1999-04-26 20:34:20 +02:00
Class readonly_detached_regcache This patch adds a new class (type) for readonly regcache, which is created via regcache::save. readonly_detached_regcache inherits readable_regcache. gdb: 2018-02-21 Yao Qi <yao.qi@linaro.org> * dummy-frame.c (dummy_frame_cache) <prev_regcache>: Use readonly_detached_regcache. (dummy_frame_prev_register): Use regcache->cooked_read. * frame.c (frame_save_as_regcache): Change return type. (frame_pop): Update. * frame.h (frame_save_as_regcache): Update declaration. * inferior.h (get_infcall_suspend_state_regcache): Update declaration. * infrun.c (infcall_suspend_state) <registers>: use readonly_detached_regcache. (save_infcall_suspend_state): Don't use regcache_dup. (get_infcall_suspend_state_regcache): Change return type. * linux-fork.c (struct fork_info) <savedregs>: Change to readonly_detached_regcache. <pc>: New field. (fork_save_infrun_state): Don't use regcache_dup. (info_checkpoints_command): Adjust. * mi/mi-main.c (register_changed_p): Update declaration. (mi_cmd_data_list_changed_registers): Use readonly_detached_regcache. (register_changed_p): Change parameter type to readonly_detached_regcache. * ppc-linux-tdep.c (ppu2spu_cache) <regcache>: Use readonly_detached_regcache. (ppu2spu_sniffer): Construct a new readonly_detached_regcache. * regcache.c (readonly_detached_regcache::readonly_detached_regcache): New. (regcache::save): Move it to reg_buffer. (regcache::restore): Change parameter type. (regcache_dup): Remove. * regcache.h (reg_buffer) <save>: New method. (readonly_detached_regcache): New class. * spu-tdep.c (spu2ppu_cache) <regcache>: Use readonly_detached_regcache. (spu2ppu_sniffer): Construct a new readonly_detached_regcache.
2018-02-21 12:20:03 +01:00
extern readonly_detached_regcache *
gdb/ Rename and move inferior_thread_state and inferior_status. * gdbthread.h (struct thread_control_state): New struct, move fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step and stop_bpstat here from struct thread_info. (struct thread_suspend_state): New struct, move field stop_signal here from struct thread_info. (struct thread_info): Move the fields above from this struct. * inferior.h: Move the inferior_thread_state and inferior_status declarations comment to their definitions at infrun.c. (struct inferior_control_state): New struct, move field stop_soon from struct inferior here. (struct inferior_suspend_state): New empty struct. (struct inferior): New fields control and suspend. Move out field stop_soon. * infrun.c (struct inferior_thread_state): Rename to ... (infcall_suspend_state): ... here. Replace field stop_signal by fields thread_suspend and inferior_suspend. (save_inferior_thread_state): Rename to ... (save_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (restore_inferior_thread_state): Rename to ... (restore_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (do_restore_inferior_thread_state_cleanup): Rename to ... (do_restore_infcall_suspend_state_cleanup): ... here. (make_cleanup_restore_inferior_thread_state): Rename to ... (make_cleanup_restore_infcall_suspend_state): ... here. (discard_inferior_thread_state): Rename to ... (discard_infcall_suspend_state): ... here. (get_inferior_thread_state_regcache): Rename to ... (get_infcall_suspend_state_regcache): ... here. (struct inferior_status): Rename to ... (struct infcall_control_state): ... here. Replace fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step, stop_bpstat and stop_soon by fields thread_control and inferior_control. (save_inferior_status): Rename to ... (save_infcall_control_state): ... here. Update the code for new fields. (restore_inferior_status): Rename to ... (restore_infcall_control_state): ... here. Update the code for new fields. (do_restore_inferior_status_cleanup): Rename to ... (do_restore_infcall_control_state_cleanup): ... here. (make_cleanup_restore_inferior_status): Rename to ... (make_cleanup_restore_infcall_control_state): ... here. (discard_inferior_status): Rename to ... (discard_infcall_control_state): ... here. * alpha-tdep.c, breakpoint.c, dummy-frame.c, dummy-frame.h, exceptions.c, fbsd-nat.c, gdbthread.h, infcall.c, infcmd.c, inferior.c, inferior.h, infrun.c, linux-nat.c, mi/mi-interp.c, mips-tdep.c, procfs.c, solib-irix.c, solib-osf.c, solib-spu.c, solib-sunos.c, solib-svr4.c, thread.c, windows-nat.c: Update all the references to the moved fields and renamed functions.
2010-11-28 05:31:25 +01:00
get_infcall_suspend_state_regcache (struct infcall_suspend_state *);
* dummy-frame.c (dummy_frame): Replace regcache member with caller_state. (dummy_frame_push): Replace caller_regcache arg with caller_state. All callers updated. (remove_dummy_frame,pop_dummy_frame,lookup_dummy_frame): New fns. (dummy_frame_pop): Rewrite. Verify requested frame is in the dummy frame stack. Restore program state. (cleanup_dummy_frames): Rewrite. (dummy_frame_sniffer): Update. Make static. * dummy-frame.h (regcache,frame_info): Delete forward decls. (inferior_thread_state): New forward decl. (dummy_frame_push): Update prototype. * frame.c (frame_pop): dummy_frame_pop now does all the work for DUMMY_FRAMEs. * infcall.c (breakpoint_auto_delete_contents): Delete. (get_function_name,run_inferior_call): New fns. (call_function_by_hand): Simplify by moving some code to get_function_name, run_inferior_call. Inferior function call wrapped in TRY_CATCH so there's less need for cleanups and all exits from proceed are handled similarily. Detect program exit. Detect program stopping in a different thread. Make error messages more consistent. * inferior.h (inferior_thread_state): Declare (opaque type). (save_inferior_thread_state,restore_inferior_thread_state, make_cleanup_restore_inferior_thread_state, discard_inferior_thread_state, get_inferior_thread_state_regcache): Declare. (save_inferior_status): Update prototype. * infrun.c: (normal_stop): When stopped for the completion of an inferior function call, verify the expected stack frame kind. (inferior_thread_state): New struct. (save_inferior_thread_state,restore_inferior_thread_state, do_restore_inferior_thread_state_cleanup, make_cleanup_restore_inferior_thread_state, discard_inferior_thread_state, get_inferior_thread_state_regcache): New functions. (inferior_status): Move stop_signal, stop_pc, registers to inferior_thread_state. Remove restore_stack_info. (save_inferior_status): Remove arg restore_stack_info. All callers updated. Remove saving of state now saved by save_inferior_thread_state. (restore_inferior_status): Remove restoration of state now done by restore_inferior_thread_state. (discard_inferior_status): Remove freeing of registers, now done by discard_inferior_thread_state. * gdb.base/break.exp: Update expected gdb output. * gdb.base/sepdebug.exp: Ditto. * gdb.mi/mi-syn-frame.exp: Ditto. * gdb.mi/mi2-syn-frame.exp: Ditto. * gdb.base/call-signal-resume.exp: New file. * gdb.base/call-signals.c: New file. * gdb.base/unwindonsignal.exp: New file. * gdb.base/unwindonsignal.c: New file. * gdb.threads/interrupted-hand-call.exp: New file. * gdb.threads/interrupted-hand-call.c: New file. * gdb.threads/thread-unwindonsignal.exp: New file.
2009-01-19 20:05:01 +01:00
2000-05-28 03:12:42 +02:00
extern void set_sigint_trap (void);
2000-05-28 03:12:42 +02:00
extern void clear_sigint_trap (void);
2001-05-04 06:15:33 +02:00
/* Collected pid, tid, etc. of the debugged inferior. When there's
Remove ptid_get_pid This removes ptid_get_pid in favor of calling the ptid_t::pid method. gdb/ChangeLog 2018-07-03 Tom Tromey <tom@tromey.com> * common/ptid.c (ptid_get_pid): Remove. * common/ptid.h (ptid_get_pid): Don't declare. * aarch64-linux-nat.c: Update. * ada-lang.c: Update. * aix-thread.c: Update. * alpha-bsd-nat.c: Update. * amd64-fbsd-nat.c: Update. * amd64-linux-nat.c: Update. * arm-linux-nat.c: Update. * arm-nbsd-nat.c: Update. * auxv.c: Update. * break-catch-syscall.c: Update. * breakpoint.c: Update. * bsd-uthread.c: Update. * corelow.c: Update. * ctf.c: Update. * darwin-nat.c: Update. * fbsd-nat.c: Update. * fbsd-tdep.c: Update. * gcore.c: Update. * gnu-nat.c: Update. * hppa-nbsd-nat.c: Update. * hppa-obsd-nat.c: Update. * i386-fbsd-nat.c: Update. * ia64-linux-nat.c: Update. * inf-ptrace.c: Update. * infcmd.c: Update. * inferior.c: Update. * inferior.h: Update. * inflow.c: Update. * infrun.c: Update. * linux-fork.c: Update. * linux-nat.c: Update. * linux-tdep.c: Update. * linux-thread-db.c: Update. * m68k-bsd-nat.c: Update. * mi/mi-interp.c: Update. * mi/mi-main.c: Update. * mips-linux-nat.c: Update. * mips-nbsd-nat.c: Update. * mips64-obsd-nat.c: Update. * nat/aarch64-linux-hw-point.c: Update. * nat/aarch64-linux.c: Update. * nat/linux-btrace.c: Update. * nat/linux-osdata.c: Update. * nat/linux-procfs.c: Update. * nat/x86-linux-dregs.c: Update. * nto-procfs.c: Update. * obsd-nat.c: Update. * ppc-linux-nat.c: Update. * ppc-nbsd-nat.c: Update. * ppc-obsd-nat.c: Update. * proc-service.c: Update. * procfs.c: Update. * python/py-inferior.c: Update. * python/py-infthread.c: Update. * ravenscar-thread.c: Update. * record.c: Update. * remote-sim.c: Update. * remote.c: Update. * rs6000-nat.c: Update. * s390-linux-nat.c: Update. * sh-nbsd-nat.c: Update. * sol-thread.c: Update. * sparc-nat.c: Update. * sparc64-tdep.c: Update. * spu-linux-nat.c: Update. * spu-tdep.c: Update. * target-debug.h: Update. * target.c: Update. * thread.c: Update. * tid-parse.c: Update. * tracefile-tfile.c: Update. * vax-bsd-nat.c: Update. * windows-nat.c: Update. * x86-linux-nat.c: Update. * x86-nat.c: Update. gdb/gdbserver/ChangeLog 2018-07-03 Tom Tromey <tom@tromey.com> * linux-low.c: Update. * linux-mips-low.c: Update. * lynx-low.c: Update. * mem-break.c: Update. * nto-low.c: Update. * remote-utils.c: Update. * server.c: Update. * spu-low.c: Update. * target.c: Update. * tracepoint.c: Update.
2018-06-11 20:05:27 +02:00
no inferior, inferior_ptid.pid () will be 0. */
2001-05-04 06:15:33 +02:00
extern ptid_t inferior_ptid;
2000-05-28 03:12:42 +02:00
extern void generic_mourn_inferior (void);
extern CORE_ADDR unsigned_pointer_to_address (struct gdbarch *gdbarch,
struct type *type,
const gdb_byte *buf);
extern void unsigned_address_to_pointer (struct gdbarch *gdbarch,
struct type *type, gdb_byte *buf,
CORE_ADDR addr);
extern CORE_ADDR signed_pointer_to_address (struct gdbarch *gdbarch,
struct type *type,
const gdb_byte *buf);
extern void address_to_signed_pointer (struct gdbarch *gdbarch,
struct type *type, gdb_byte *buf,
CORE_ADDR addr);
* gdbarch.sh (POINTER_TO_ADDRESS, ADDRESS_TO_POINTER): Two new functions which architectures can redefine, defaulting to generic_pointer_to_address and generic_address_to_pointer. * findvar.c (extract_typed_address, store_typed_address, generic_pointer_to_address, generic_address_to_pointer): New functions. (POINTER_TO_ADDRESS, ADDRESS_TO_POINTER): Provide default definitions. (extract_address, store_address): Doc fixes. * values.c (value_as_pointer): Doc fix. (value_from_pointer): New function. * defs.h (extract_typed_address, store_typed_address): New declarations. * inferior.h (generic_address_to_pointer, generic_pointer_to_address): New declarations. * value.h (value_from_pointer): New declaration. * ax-gdb.c (const_var_ref): Use value_from_pointer, not value_from_longest. * blockframe.c (generic_push_dummy_frame): Use read_pc and read_sp, not read_register. * c-valprint.c (c_val_print): Use extract_typed_address instead of extract_address to extract vtable entries and references. * cp-valprint.c (cp_print_value_fields): Use value_from_pointer instead of value_from_longest to extract the vtable's address. * eval.c (evaluate_subexp_standard): Use value_from_pointer instead of value_from_longest to compute `this', and for doing pointer-to-member dereferencing. * findvar.c (read_register): Use extract_unsigned_integer, not extract_address. (read_var_value): Use store_typed_address instead of store_address for building label values. (locate_var_value): Use value_from_pointer instead of value_from_longest. * hppa-tdep.c (find_stub_with_shl_get): Use value_from_pointer, instead of value_from_longest, to build arguments to __d_shl_get. * printcmd.c (set_next_address): Use value_from_pointer, not value_from_longest. (x_command): Use value_from_pointer, not value_from_longest. * tracepoint.c (set_traceframe_context): Use value_from_pointer, not value_from_longest. * valarith.c (value_add, value_sub): Use value_from_pointer, not value_from_longest. * valops.c (find_function_in_inferior, value_coerce_array, value_coerce_function, value_addr, hand_function_call): Same. * value.h (COERCE_REF): Use unpack_pointer, not unpack_long. * values.c (unpack_long): Use extract_typed_address to produce addresses from pointers and references, not extract_address. (value_from_longest): Use store_typed_address instead of store_address to produce pointer and reference values.
2000-04-14 20:43:41 +02:00
2000-05-28 03:12:42 +02:00
extern void reopen_exec_file (void);
/* From misc files */
extern void default_print_registers_info (struct gdbarch *gdbarch,
struct ui_file *file,
struct frame_info *frame,
int regnum, int all);
/* Default implementation of gdbarch_print_float_info. Print
the values of all floating point registers. */
extern void default_print_float_info (struct gdbarch *gdbarch,
struct ui_file *file,
struct frame_info *frame,
const char *args);
extern void child_terminal_info (struct target_ops *self, const char *, int);
Rename native-only terminal related functions. Looking at target_terminal_inferior etc. in async mode, I realized that the naming of the terminal_inferior, terminal_ours, etc. functions doesn't really give a clue that they're meant for the native target only. This patch renames them. There's already child_terminal_info using the child_ prefix, and, they're most prominently installed by inf-child.c, so I went with the child_ prefix. I dropped "inferior" from a couple to make the name match the corresponding target method. Tested on x86_64 Fedora 17, and cross built for mingw. I didn't test gnu-nat.c, but I think the change is as obvious as it gets. I grepped the tree looking for other potential spots that would need adjustment but this is all I found. If something breaks, it should be trivial to fix. gdb/ 2014-03-14 Pedro Alves <palves@redhat.com> * inferior.h (terminal_ours_for_output): Rename to ... (child_terminal_ours_for_output): ... this. (terminal_save_ours): Rename to ... (child_terminal_save_ours): ... this. (terminal_ours): Rename to ... (child_terminal_ours): ... this. (terminal_inferior): Rename to ... (child_terminal_inferior): ... this. (terminal_init_inferior): Rename to ... (child_terminal_init_inferior): ... this. (terminal_init_inferior_with_pgrp): Rename to ... (child_terminal_init_inferior_with_pgrp): ... this. * inflow.c (terminal_init_inferior_with_pgrp): Rename to ... (child_terminal_init_with_pgrp): ... this. (terminal_save_ours): Rename to ... (child_terminal_save_ours): ... this. (terminal_init_inferior): Rename to ... (child_terminal_init): ... this. Adjust. (terminal_inferior): Rename to ... (child_terminal_inferior): ... this. (terminal_ours_for_output): Rename to ... (child_terminal_ours_for_output): ... this. Adjust. (terminal_ours): Rename to ... (child_terminal_ours): ... this. (terminal_ours_1): Rename to ... (child_terminal_ours_1): ... this. Adjust. * linux-nat.c (linux_nat_terminal_inferior): Adjust. * windows-nat.c (do_initial_windows_stuff): Adjust. * gnu-nat.c (gnu_terminal_init_inferior): Rename to ... (gnu_terminal_init): ... this. Adjust. (gnu_target): Adjust. * inf-child.c (inf_child_target): Adjust.
2014-03-14 01:06:45 +01:00
extern void child_terminal_ours (struct target_ops *self);
extern void child_terminal_ours_for_output (struct target_ops *self);
Rename native-only terminal related functions. Looking at target_terminal_inferior etc. in async mode, I realized that the naming of the terminal_inferior, terminal_ours, etc. functions doesn't really give a clue that they're meant for the native target only. This patch renames them. There's already child_terminal_info using the child_ prefix, and, they're most prominently installed by inf-child.c, so I went with the child_ prefix. I dropped "inferior" from a couple to make the name match the corresponding target method. Tested on x86_64 Fedora 17, and cross built for mingw. I didn't test gnu-nat.c, but I think the change is as obvious as it gets. I grepped the tree looking for other potential spots that would need adjustment but this is all I found. If something breaks, it should be trivial to fix. gdb/ 2014-03-14 Pedro Alves <palves@redhat.com> * inferior.h (terminal_ours_for_output): Rename to ... (child_terminal_ours_for_output): ... this. (terminal_save_ours): Rename to ... (child_terminal_save_ours): ... this. (terminal_ours): Rename to ... (child_terminal_ours): ... this. (terminal_inferior): Rename to ... (child_terminal_inferior): ... this. (terminal_init_inferior): Rename to ... (child_terminal_init_inferior): ... this. (terminal_init_inferior_with_pgrp): Rename to ... (child_terminal_init_inferior_with_pgrp): ... this. * inflow.c (terminal_init_inferior_with_pgrp): Rename to ... (child_terminal_init_with_pgrp): ... this. (terminal_save_ours): Rename to ... (child_terminal_save_ours): ... this. (terminal_init_inferior): Rename to ... (child_terminal_init): ... this. Adjust. (terminal_inferior): Rename to ... (child_terminal_inferior): ... this. (terminal_ours_for_output): Rename to ... (child_terminal_ours_for_output): ... this. Adjust. (terminal_ours): Rename to ... (child_terminal_ours): ... this. (terminal_ours_1): Rename to ... (child_terminal_ours_1): ... this. Adjust. * linux-nat.c (linux_nat_terminal_inferior): Adjust. * windows-nat.c (do_initial_windows_stuff): Adjust. * gnu-nat.c (gnu_terminal_init_inferior): Rename to ... (gnu_terminal_init): ... this. Adjust. (gnu_target): Adjust. * inf-child.c (inf_child_target): Adjust.
2014-03-14 01:06:45 +01:00
extern void child_terminal_inferior (struct target_ops *self);
Per-inferior target_terminal state, fix PR gdb/13211, more In my multi-target branch I ran into problems with GDB's terminal handling that exist in master as well, with multi-inferior debugging. This patch adds a testcase for said problems (gdb.multi/multi-term-settings.exp), fixes the problems, fixes PR gdb/13211 as well (and adds a testcase for that too, gdb.base/interrupt-daemon.exp). The basis of the problem I ran into is the following. Consider a scenario where you have: - inferior 1 - started with "attach", process is running on some other terminal. - inferior 2 - started with "run", process is sharing gdb's terminal. In this scenario, when you stop/resume both inferiors, you want GDB to save/restore the terminal settings of inferior 2, the one that is sharing GDB's terminal. I.e., you want inferior 2 to "own" the terminal (in target_terminal::is_ours/target_terminal::is_inferior sense). Unfortunately, that's not what you get currently. Because GDB doesn't know whether an attached inferior is actually sharing GDB's terminal, it tries to save/restore its settings anyway, ignoring errors. In this case, this is pointless, because inferior 1 is running on a different terminal, but GDB doesn't know better. And then, because it is only possible to have the terminal settings of a single inferior be in effect at a time, or make one inferior/pgrp be the terminal's foreground pgrp (aka, only one inferior can "own" the terminal, ignoring fork children here), if GDB happens to try to restore the terminal settings of inferior 1 first, then GDB never restores the terminal settings of inferior 2. This patch fixes that and a few things more along the way: - Moves enum target_terminal::terminal_state out of the target_terminal class (it's currently private) and makes it a scoped enum so that it can be easily used elsewhere. - Replaces the inflow.c:terminal_is_ours boolean with a target_terminal_state variable. This allows distinguishing is_ours and is_ours_for_output states. This allows finally making child_terminal_ours_1 do something with its "output_only" parameter. - Makes each inferior have its own copy of the is_ours/is_ours_for_output/is_inferior state. - Adds a way for GDB to tell whether the inferior is sharing GDB's terminal. Works best on Linux and Solaris; the fallback works just as well as currently. - With that, we can remove the inf->attach_flag tests from child_terminal_inferior/child_terminal_ours. - Currently target_ops.to_ours is responsible for both saving the current inferior's terminal state, and restoring gdb's state. Because each inferior has its own terminal state (possibly handled by different targets in a multi-target world, even), we need to split the inferior-saving part from the gdb-restoring part. The patch adds a new target_ops.to_save_inferior target method for that. - Adds a new target_terminal::save_inferior() function, so that sequences like: scoped_restore_terminal_state save_state; target_terminal::ours_for_output (); ... restore back inferiors that were target_terminal_state::is_inferior before back to is_inferior, and leaves inferiors that were is_ours alone. - Along the way, this adds a default implementation of target_pass_ctrlc to inflow.c (for inf-child.c), that handles passing the Ctrl-C to a process running on GDB's terminal or to some other process otherwise. - Similarly, adds a new target default implementation of target_interrupt, for the "interrupt" command. The current implementation of this hook in inf-ptrace.c kills the whole process group, but that's incorrect/undesirable because we may not be attached to all processes in the process group. And also, it's incorrect because inferior_process_group() doesn't really return the inferior's real process group id if the inferior is not a process group leader... This is the cause of PR gdb/13211 [1], which this patch fixes. While at it, that target method's "ptid" parameter is eliminated, because it's not really used. - A new test is included that exercises and fixes PR gdb/13211, and also fixes a GDB issue reported on stackoverflow that I ran into while working on this [2]. The problem is similar to PR gdb/13211, except that it also triggers with Ctrl-C. When debugging a daemon (i.e., a process that disconnects from the controlling terminal and is not a process group leader, then Ctrl-C doesn't work, you just can't interrupt the inferior at all, resulting in a hung debug session. The problem is that since the inferior is no longer associated with gdb's session / controlling terminal, then trying to put the inferior in the foreground fails. And so Ctrl-C never reaches the inferior directly. pass_signal is only used when the inferior is attached, but that is not the case here. This is fixed by the new child_pass_ctrlc. Without the fix, the new interrupt-daemon.exp testcase fails with timeout waiting for a SIGINT that never arrives. [1] PR gdb/13211 - Async / Process group and interrupt not working https://sourceware.org/bugzilla/show_bug.cgi?id=13211 [2] GDB not reacting Ctrl-C when after fork() and setsid() https://stackoverflow.com/questions/46101292/gdb-not-reacting-ctrl-c-when-after-fork-and-setsid Note this patch does _not_ fix: - PR gdb/14559 - The 'interrupt' command does not work if sigwait is in use https://sourceware.org/bugzilla/show_bug.cgi?id=14559 - PR gdb/9425 - When using "sigwait" GDB doesn't trap SIGINT. Ctrl+C terminates program when should break gdb. https://sourceware.org/bugzilla/show_bug.cgi?id=9425 The only way to fix that that I know of (without changing the kernel) is to make GDB put inferiors in a separate session (create a pseudo-tty master/slave pair, make the inferior run with the slave as its terminal, and have gdb pump output/input on the master end). gdb/ChangeLog: 2018-01-30 Pedro Alves <palves@redhat.com> PR gdb/13211 * config.in, configure: Regenerate. * configure.ac: Check for getpgid. * go32-nat.c (go32_pass_ctrlc): New. (go32_target): Install it. * inf-child.c (inf_child_target): Install child_terminal_save_inferior, child_pass_ctrlc and child_interrupt. * inf-ptrace.c (inf_ptrace_interrupt): Delete. (inf_ptrace_target): No longer install it. * infcmd.c (interrupt_target_1): Adjust. * inferior.h (child_terminal_save_inferior, child_pass_ctrlc) (child_interrupt): Declare. (inferior::terminal_state): New. * inflow.c (struct terminal_info): Update comments. (inferior_process_group): Delete. (terminal_is_ours): Delete. (gdb_tty_state): New. (child_terminal_init): Adjust. (is_gdb_terminal, sharing_input_terminal_1) (sharing_input_terminal): New functions. (child_terminal_inferior): Adjust. Use sharing_input_terminal. Set the process's actual process group in the foreground if possible. Handle is_ours_for_output/is_ours distinction. Don't mark terminal as the inferior's if not sharing GDB's terminal. Don't check attach_flag. (child_terminal_ours_for_output, child_terminal_ours): Adjust to pass down a target_terminal_state. (child_terminal_save_inferior): New, factored out from ... (child_terminal_ours_1): ... this. Handle target_terminal_state::is_ours_for_output. (child_interrupt, child_pass_ctrlc): New. (inflow_inferior_exit): Clear the inferior's terminal_state. (copy_terminal_info): Copy the inferior's terminal state. (_initialize_inflow): Remove reference to terminal_is_ours. * inflow.h (inferior_process_group): Delete. * nto-procfs.c (nto_handle_sigint, procfs_interrupt): Adjust. * procfs.c (procfs_target): Don't install procfs_interrupt. (procfs_interrupt): Delete. * remote.c (remote_serial_quit_handler): Adjust. (remote_interrupt): Remove ptid parameter. Adjust. * target-delegates.c: Regenerate. * target.c: Include "terminal.h". (target_terminal::terminal_state): Rename to ... (target_terminal::m_terminal_state): ... this. (target_terminal::init): Adjust. (target_terminal::inferior): Adjust to per-inferior terminal_state. (target_terminal::restore_inferior, target_terminal_is_ours_kind): New. (target_terminal::ours, target_terminal::ours_for_output): Use target_terminal_is_ours_kind. (target_interrupt): Remove ptid parameter. Adjust. (default_target_pass_ctrlc): Adjust. * target.h (target_ops::to_terminal_save_inferior): New field. (target_ops::to_interrupt): Remove ptid_t parameter. (target_interrupt): Remove ptid_t parameter. Update comment. (target_pass_ctrlc): Update comment. * target/target.h (target_terminal_state): New scoped enum, factored out of ... (target_terminal::terminal_state): ... here. (target_terminal::inferior): Update comments. (target_terminal::restore_inferior): New. (target_terminal::is_inferior, target_terminal::is_ours) (target_terminal::is_ours_for_output): Adjust. (target_terminal::scoped_restore_terminal_state): Adjust to rename, and call restore_inferior() instead of inferior(). (target_terminal::scoped_restore_terminal_state::m_state): Change type. (target_terminal::terminal_state): Rename to ... (target_terminal::m_terminal_state): ... this and change type. gdb/gdbserver/ChangeLog: 2018-01-30 Pedro Alves <palves@redhat.com> PR gdb/13211 * target.c (target_terminal::terminal_state): Rename to ... (target_terminal::m_terminal_state): ... this. gdb/testsuite/ChangeLog: 2018-01-30 Pedro Alves <palves@redhat.com> PR gdb/13211 * gdb.base/interrupt-daemon.c: New. * gdb.base/interrupt-daemon.exp: New. * gdb.multi/multi-term-settings.c: New. * gdb.multi/multi-term-settings.exp: New.
2018-01-30 15:23:51 +01:00
extern void child_terminal_save_inferior (struct target_ops *self);
Rename native-only terminal related functions. Looking at target_terminal_inferior etc. in async mode, I realized that the naming of the terminal_inferior, terminal_ours, etc. functions doesn't really give a clue that they're meant for the native target only. This patch renames them. There's already child_terminal_info using the child_ prefix, and, they're most prominently installed by inf-child.c, so I went with the child_ prefix. I dropped "inferior" from a couple to make the name match the corresponding target method. Tested on x86_64 Fedora 17, and cross built for mingw. I didn't test gnu-nat.c, but I think the change is as obvious as it gets. I grepped the tree looking for other potential spots that would need adjustment but this is all I found. If something breaks, it should be trivial to fix. gdb/ 2014-03-14 Pedro Alves <palves@redhat.com> * inferior.h (terminal_ours_for_output): Rename to ... (child_terminal_ours_for_output): ... this. (terminal_save_ours): Rename to ... (child_terminal_save_ours): ... this. (terminal_ours): Rename to ... (child_terminal_ours): ... this. (terminal_inferior): Rename to ... (child_terminal_inferior): ... this. (terminal_init_inferior): Rename to ... (child_terminal_init_inferior): ... this. (terminal_init_inferior_with_pgrp): Rename to ... (child_terminal_init_inferior_with_pgrp): ... this. * inflow.c (terminal_init_inferior_with_pgrp): Rename to ... (child_terminal_init_with_pgrp): ... this. (terminal_save_ours): Rename to ... (child_terminal_save_ours): ... this. (terminal_init_inferior): Rename to ... (child_terminal_init): ... this. Adjust. (terminal_inferior): Rename to ... (child_terminal_inferior): ... this. (terminal_ours_for_output): Rename to ... (child_terminal_ours_for_output): ... this. Adjust. (terminal_ours): Rename to ... (child_terminal_ours): ... this. (terminal_ours_1): Rename to ... (child_terminal_ours_1): ... this. Adjust. * linux-nat.c (linux_nat_terminal_inferior): Adjust. * windows-nat.c (do_initial_windows_stuff): Adjust. * gnu-nat.c (gnu_terminal_init_inferior): Rename to ... (gnu_terminal_init): ... this. Adjust. (gnu_target): Adjust. * inf-child.c (inf_child_target): Adjust.
2014-03-14 01:06:45 +01:00
extern void child_terminal_init (struct target_ops *self);
Rename native-only terminal related functions. Looking at target_terminal_inferior etc. in async mode, I realized that the naming of the terminal_inferior, terminal_ours, etc. functions doesn't really give a clue that they're meant for the native target only. This patch renames them. There's already child_terminal_info using the child_ prefix, and, they're most prominently installed by inf-child.c, so I went with the child_ prefix. I dropped "inferior" from a couple to make the name match the corresponding target method. Tested on x86_64 Fedora 17, and cross built for mingw. I didn't test gnu-nat.c, but I think the change is as obvious as it gets. I grepped the tree looking for other potential spots that would need adjustment but this is all I found. If something breaks, it should be trivial to fix. gdb/ 2014-03-14 Pedro Alves <palves@redhat.com> * inferior.h (terminal_ours_for_output): Rename to ... (child_terminal_ours_for_output): ... this. (terminal_save_ours): Rename to ... (child_terminal_save_ours): ... this. (terminal_ours): Rename to ... (child_terminal_ours): ... this. (terminal_inferior): Rename to ... (child_terminal_inferior): ... this. (terminal_init_inferior): Rename to ... (child_terminal_init_inferior): ... this. (terminal_init_inferior_with_pgrp): Rename to ... (child_terminal_init_inferior_with_pgrp): ... this. * inflow.c (terminal_init_inferior_with_pgrp): Rename to ... (child_terminal_init_with_pgrp): ... this. (terminal_save_ours): Rename to ... (child_terminal_save_ours): ... this. (terminal_init_inferior): Rename to ... (child_terminal_init): ... this. Adjust. (terminal_inferior): Rename to ... (child_terminal_inferior): ... this. (terminal_ours_for_output): Rename to ... (child_terminal_ours_for_output): ... this. Adjust. (terminal_ours): Rename to ... (child_terminal_ours): ... this. (terminal_ours_1): Rename to ... (child_terminal_ours_1): ... this. Adjust. * linux-nat.c (linux_nat_terminal_inferior): Adjust. * windows-nat.c (do_initial_windows_stuff): Adjust. * gnu-nat.c (gnu_terminal_init_inferior): Rename to ... (gnu_terminal_init): ... this. Adjust. (gnu_target): Adjust. * inf-child.c (inf_child_target): Adjust.
2014-03-14 01:06:45 +01:00
extern void child_terminal_init_with_pgrp (int pgrp);
Per-inferior target_terminal state, fix PR gdb/13211, more In my multi-target branch I ran into problems with GDB's terminal handling that exist in master as well, with multi-inferior debugging. This patch adds a testcase for said problems (gdb.multi/multi-term-settings.exp), fixes the problems, fixes PR gdb/13211 as well (and adds a testcase for that too, gdb.base/interrupt-daemon.exp). The basis of the problem I ran into is the following. Consider a scenario where you have: - inferior 1 - started with "attach", process is running on some other terminal. - inferior 2 - started with "run", process is sharing gdb's terminal. In this scenario, when you stop/resume both inferiors, you want GDB to save/restore the terminal settings of inferior 2, the one that is sharing GDB's terminal. I.e., you want inferior 2 to "own" the terminal (in target_terminal::is_ours/target_terminal::is_inferior sense). Unfortunately, that's not what you get currently. Because GDB doesn't know whether an attached inferior is actually sharing GDB's terminal, it tries to save/restore its settings anyway, ignoring errors. In this case, this is pointless, because inferior 1 is running on a different terminal, but GDB doesn't know better. And then, because it is only possible to have the terminal settings of a single inferior be in effect at a time, or make one inferior/pgrp be the terminal's foreground pgrp (aka, only one inferior can "own" the terminal, ignoring fork children here), if GDB happens to try to restore the terminal settings of inferior 1 first, then GDB never restores the terminal settings of inferior 2. This patch fixes that and a few things more along the way: - Moves enum target_terminal::terminal_state out of the target_terminal class (it's currently private) and makes it a scoped enum so that it can be easily used elsewhere. - Replaces the inflow.c:terminal_is_ours boolean with a target_terminal_state variable. This allows distinguishing is_ours and is_ours_for_output states. This allows finally making child_terminal_ours_1 do something with its "output_only" parameter. - Makes each inferior have its own copy of the is_ours/is_ours_for_output/is_inferior state. - Adds a way for GDB to tell whether the inferior is sharing GDB's terminal. Works best on Linux and Solaris; the fallback works just as well as currently. - With that, we can remove the inf->attach_flag tests from child_terminal_inferior/child_terminal_ours. - Currently target_ops.to_ours is responsible for both saving the current inferior's terminal state, and restoring gdb's state. Because each inferior has its own terminal state (possibly handled by different targets in a multi-target world, even), we need to split the inferior-saving part from the gdb-restoring part. The patch adds a new target_ops.to_save_inferior target method for that. - Adds a new target_terminal::save_inferior() function, so that sequences like: scoped_restore_terminal_state save_state; target_terminal::ours_for_output (); ... restore back inferiors that were target_terminal_state::is_inferior before back to is_inferior, and leaves inferiors that were is_ours alone. - Along the way, this adds a default implementation of target_pass_ctrlc to inflow.c (for inf-child.c), that handles passing the Ctrl-C to a process running on GDB's terminal or to some other process otherwise. - Similarly, adds a new target default implementation of target_interrupt, for the "interrupt" command. The current implementation of this hook in inf-ptrace.c kills the whole process group, but that's incorrect/undesirable because we may not be attached to all processes in the process group. And also, it's incorrect because inferior_process_group() doesn't really return the inferior's real process group id if the inferior is not a process group leader... This is the cause of PR gdb/13211 [1], which this patch fixes. While at it, that target method's "ptid" parameter is eliminated, because it's not really used. - A new test is included that exercises and fixes PR gdb/13211, and also fixes a GDB issue reported on stackoverflow that I ran into while working on this [2]. The problem is similar to PR gdb/13211, except that it also triggers with Ctrl-C. When debugging a daemon (i.e., a process that disconnects from the controlling terminal and is not a process group leader, then Ctrl-C doesn't work, you just can't interrupt the inferior at all, resulting in a hung debug session. The problem is that since the inferior is no longer associated with gdb's session / controlling terminal, then trying to put the inferior in the foreground fails. And so Ctrl-C never reaches the inferior directly. pass_signal is only used when the inferior is attached, but that is not the case here. This is fixed by the new child_pass_ctrlc. Without the fix, the new interrupt-daemon.exp testcase fails with timeout waiting for a SIGINT that never arrives. [1] PR gdb/13211 - Async / Process group and interrupt not working https://sourceware.org/bugzilla/show_bug.cgi?id=13211 [2] GDB not reacting Ctrl-C when after fork() and setsid() https://stackoverflow.com/questions/46101292/gdb-not-reacting-ctrl-c-when-after-fork-and-setsid Note this patch does _not_ fix: - PR gdb/14559 - The 'interrupt' command does not work if sigwait is in use https://sourceware.org/bugzilla/show_bug.cgi?id=14559 - PR gdb/9425 - When using "sigwait" GDB doesn't trap SIGINT. Ctrl+C terminates program when should break gdb. https://sourceware.org/bugzilla/show_bug.cgi?id=9425 The only way to fix that that I know of (without changing the kernel) is to make GDB put inferiors in a separate session (create a pseudo-tty master/slave pair, make the inferior run with the slave as its terminal, and have gdb pump output/input on the master end). gdb/ChangeLog: 2018-01-30 Pedro Alves <palves@redhat.com> PR gdb/13211 * config.in, configure: Regenerate. * configure.ac: Check for getpgid. * go32-nat.c (go32_pass_ctrlc): New. (go32_target): Install it. * inf-child.c (inf_child_target): Install child_terminal_save_inferior, child_pass_ctrlc and child_interrupt. * inf-ptrace.c (inf_ptrace_interrupt): Delete. (inf_ptrace_target): No longer install it. * infcmd.c (interrupt_target_1): Adjust. * inferior.h (child_terminal_save_inferior, child_pass_ctrlc) (child_interrupt): Declare. (inferior::terminal_state): New. * inflow.c (struct terminal_info): Update comments. (inferior_process_group): Delete. (terminal_is_ours): Delete. (gdb_tty_state): New. (child_terminal_init): Adjust. (is_gdb_terminal, sharing_input_terminal_1) (sharing_input_terminal): New functions. (child_terminal_inferior): Adjust. Use sharing_input_terminal. Set the process's actual process group in the foreground if possible. Handle is_ours_for_output/is_ours distinction. Don't mark terminal as the inferior's if not sharing GDB's terminal. Don't check attach_flag. (child_terminal_ours_for_output, child_terminal_ours): Adjust to pass down a target_terminal_state. (child_terminal_save_inferior): New, factored out from ... (child_terminal_ours_1): ... this. Handle target_terminal_state::is_ours_for_output. (child_interrupt, child_pass_ctrlc): New. (inflow_inferior_exit): Clear the inferior's terminal_state. (copy_terminal_info): Copy the inferior's terminal state. (_initialize_inflow): Remove reference to terminal_is_ours. * inflow.h (inferior_process_group): Delete. * nto-procfs.c (nto_handle_sigint, procfs_interrupt): Adjust. * procfs.c (procfs_target): Don't install procfs_interrupt. (procfs_interrupt): Delete. * remote.c (remote_serial_quit_handler): Adjust. (remote_interrupt): Remove ptid parameter. Adjust. * target-delegates.c: Regenerate. * target.c: Include "terminal.h". (target_terminal::terminal_state): Rename to ... (target_terminal::m_terminal_state): ... this. (target_terminal::init): Adjust. (target_terminal::inferior): Adjust to per-inferior terminal_state. (target_terminal::restore_inferior, target_terminal_is_ours_kind): New. (target_terminal::ours, target_terminal::ours_for_output): Use target_terminal_is_ours_kind. (target_interrupt): Remove ptid parameter. Adjust. (default_target_pass_ctrlc): Adjust. * target.h (target_ops::to_terminal_save_inferior): New field. (target_ops::to_interrupt): Remove ptid_t parameter. (target_interrupt): Remove ptid_t parameter. Update comment. (target_pass_ctrlc): Update comment. * target/target.h (target_terminal_state): New scoped enum, factored out of ... (target_terminal::terminal_state): ... here. (target_terminal::inferior): Update comments. (target_terminal::restore_inferior): New. (target_terminal::is_inferior, target_terminal::is_ours) (target_terminal::is_ours_for_output): Adjust. (target_terminal::scoped_restore_terminal_state): Adjust to rename, and call restore_inferior() instead of inferior(). (target_terminal::scoped_restore_terminal_state::m_state): Change type. (target_terminal::terminal_state): Rename to ... (target_terminal::m_terminal_state): ... this and change type. gdb/gdbserver/ChangeLog: 2018-01-30 Pedro Alves <palves@redhat.com> PR gdb/13211 * target.c (target_terminal::terminal_state): Rename to ... (target_terminal::m_terminal_state): ... this. gdb/testsuite/ChangeLog: 2018-01-30 Pedro Alves <palves@redhat.com> PR gdb/13211 * gdb.base/interrupt-daemon.c: New. * gdb.base/interrupt-daemon.exp: New. * gdb.multi/multi-term-settings.c: New. * gdb.multi/multi-term-settings.exp: New.
2018-01-30 15:23:51 +01:00
extern void child_pass_ctrlc (struct target_ops *self);
extern void child_interrupt (struct target_ops *self);
/* From fork-child.c */
Share fork_inferior et al with gdbserver This is the most important (and the biggest, sorry) patch of the series. It moves fork_inferior from gdb/fork-child.c to nat/fork-inferior.c and makes all the necessary adjustments to both GDB and gdbserver to make sure everything works OK. There is no "most important change" with this patch; all changes are made in a progressive way, making sure that gdbserver had the necessary features while not breaking GDB at the same time. I decided to go ahead and implement a partial support for starting the inferior with a shell on gdbserver, although the full feature comes in the next patch. The user won't have the option to disable the startup-with-shell, and also won't be able to change which shell gdbserver will use (other than setting the $SHELL environment variable, that is). Everything is working as expected, and no regressions were present during the tests. gdb/ChangeLog: 2017-06-07 Sergio Durigan Junior <sergiodj@redhat.com> Pedro Alves <palves@redhat.com> * Makefile.in (HFILES_NO_SRCDIR): Add "common/common-inferior.h" and "nat/fork-inferior.h". * common/common-inferior.h: New file, with contents from "gdb/inferior.h". * commom/common-utils.c: Include "common-utils.h". (stringify_argv): New function. * common/common-utils.h (stringify_argv): New prototype. * configure.nat: Add "fork-inferior.o" as a dependency for "*linux*", "fbsd*" and "nbsd*" hosts. * corefile.c (get_exec_file): Update comment. * darwin-nat.c (darwin_ptrace_him): Call "gdb_startup_inferior" instead of "startup_inferior". (darwin_create_inferior): Call "add_thread_silent" after "fork_inferior". * fork-child.c: Cleanup unnecessary includes. (SHELL_FILE): Move to "common/common-fork-child.c". (environ): Likewise. (exec_wrapper): Initialize. (get_exec_wrapper): New function. (breakup_args): Move to "common/common-fork-child.c"; rename to "breakup_args_for_exec". (escape_bang_in_quoted_argument): Move to "common/common-fork-child.c". (saved_ui): New variable. (prefork_hook): New function. (postfork_hook): Likewise. (postfork_child_hook): Likewise. (gdb_startup_inferior): Likewise. (fork_inferior): Move to "common/common-fork-child.c". Update function to support gdbserver. (startup_inferior): Likewise. * gdbcore.h (get_exec_file): Remove declaration. * gnu-nat.c (gnu_create_inferior): Call "gdb_startup_inferior" instead of "startup_inferior". Call "add_thread_silent" after "fork_inferior". * inf-ptrace.c: Include "nat/fork-inferior.h" and "utils.h". (inf_ptrace_create_inferior): Call "gdb_startup_inferior" instead of "startup_inferior". Call "add_thread_silent" after "fork_inferior". * inferior.h: Include "common-inferior.h". (trace_start_error): Move to "common/common-utils.h". (trace_start_error_with_name): Likewise. (fork_inferior): Move prototype to "nat/fork-inferior.h". (startup_inferior): Likewise. (gdb_startup_inferior): New prototype. * nat/fork-inferior.c: New file, with contents from "fork-child.c". * nat/fork-inferior.h: New file. * procfs.c (procfs_init_inferior): Call "gdb_startup_inferior" instead of "startup_inferior". Call "add_thread_silent" after "fork_inferior". * target.h (target_terminal_init): Move prototype to "target/target.h". (target_terminal_inferior): Likewise. (target_terminal_ours): Likewise. * target/target.h (target_terminal_init): New prototype, moved from "target.h". (target_terminal_inferior): Likewise. (target_terminal_ours): Likewise. * utils.c (gdb_flush_out_err): New function. gdb/gdbserver/ChangeLog: 2017-06-07 Sergio Durigan Junior <sergiodj@redhat.com> Pedro Alves <palves@redhat.com> * Makefile.in (SFILES): Add "nat/fork-inferior.o". * configure: Regenerate. * configure.srv (srv_linux_obj): Add "fork-child.o" and "fork-inferior.o". (i[34567]86-*-lynxos*): Likewise. (spu*-*-*): Likewise. * fork-child.c: New file. * linux-low.c: Include "common-inferior.h", "nat/fork-inferior.h" and "environ.h". (linux_ptrace_fun): New function. (linux_create_inferior): Adjust function prototype to reflect change on "target.h". Adjust function code to use "fork_inferior". (linux_request_interrupt): Delete "signal_pid". * lynx-low.c: Include "common-inferior.h" and "nat/fork-inferior.h". (lynx_ptrace_fun): New function. (lynx_create_inferior): Adjust function prototype to reflect change on "target.h". Adjust function code to use "fork_inferior". * nto-low.c (nto_create_inferior): Adjust function prototype and code to reflect change on "target.h". Update comments. * server.c: Include "common-inferior.h", "nat/fork-inferior.h", "common-terminal.h" and "environ.h". (terminal_fd): Moved to fork-child.c. (old_foreground_pgrp): Likewise. (restore_old_foreground_pgrp): Likewise. (last_status): Make it global. (last_ptid): Likewise. (our_environ): New variable. (startup_with_shell): Likewise. (program_name): Likewise. (program_argv): Rename to... (program_args): ...this. (wrapper_argv): New variable. (start_inferior): Delete function. (get_exec_wrapper): New function. (get_exec_file): Likewise. (get_environ): Likewise. (prefork_hook): Likewise. (post_fork_inferior): Likewise. (postfork_hook): Likewise. (postfork_child_hook): Likewise. (handle_v_run): Update code to deal with arguments coming from the remote host. Update calls from "start_inferior" to "create_inferior". (captured_main): Likewise. Initialize environment variable. Call "have_job_control". * server.h (post_fork_inferior): New prototype. (get_environ): Likewise. (last_status): Declare. (last_ptid): Likewise. (signal_pid): Likewise. * spu-low.c: Include "common-inferior.h" and "nat/fork-inferior.h". (spu_ptrace_fun): New function. (spu_create_inferior): Adjust function prototype to reflect change on "target.h". Adjust function code to use "fork_inferior". * target.c (target_terminal_init): New function. (target_terminal_inferior): Likewise. (target_terminal_ours): Likewise. * target.h: Include <vector>. (struct target_ops) <create_inferior>: Update prototype. (create_inferior): Update macro. * utils.c (gdb_flush_out_err): New function. * win32-low.c (win32_create_inferior): Adjust function prototype and code to reflect change on "target.h". gdb/testsuite/ChangeLog: 2017-06-07 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.server/non-existing-program.exp: Update regex in order to reflect the fact that gdbserver is now using fork_inferior (with a shell) to startup the inferior.
2016-12-23 03:11:11 +01:00
/* Helper function to call STARTUP_INFERIOR with PID and NUM_TRAPS.
This function already calls set_executing. Return the ptid_t from
STARTUP_INFERIOR. */
extern ptid_t gdb_startup_inferior (pid_t pid, int num_traps);
/* From infcmd.c */
Remote all-stop-on-top-of-non-stop This is the first pass at implementing support for all-stop mode running against the remote target using the non-stop variant of the protocol. The trickiest part here is the initial connection setup/synching. We need to fetch all inferiors' target descriptions etc. before stopping threads, because stop_all_threads needs to read the threads' registers (to record each thread's stop_pc). But OTOH, the initial inferior setup (target_post_attach, post_create_inferior, etc.), only works correctly if the inferior is stopped... So I've split that initial setup part from attach_command_post_wait to a separate function, and added a "still needs setup" flag to the inferior structure. This is similar to gdbserver/linux-low.c's handling of discovering the process's target description). Then if on connection all threads of the remote inferior are running, when we go about stopping them, as soon as they stop we call setup_inferior, from within stop_all_threads. Also, in all-stop, we need to process all the initial stop replies to learn about all the pending signal the threads may already be stopped for, and pick the one to report as current. This is exposed by gdb.threads/reconnect-signal.exp. gdb/ 2015-11-30 Pedro Alves <palves@redhat.com> * gdbthread.h (switch_to_thread_no_regs): Declare. * infcmd.c (setup_inferior): New function, factored out from ... (attach_command_post_wait): ... this. Rename to ... (attach_post_wait): ... this. Replace parameter async_exec with attach_post_wait_mode parameter. Adjust. (enum attach_post_wait_mode): New enum. (struct attach_command_continuation_args): Replace 'async_exec' field with 'mode' field. (attach_command_continuation): Adjust. (attach_command): Add comment. Mark the inferior as needing setup. Adjust to use enum attach_post_wait_mode. (notice_new_inferior): Use switch_to_thread_no_regs. Adjust to use enum attach_post_wait_mode. * inferior.h (setup_inferior): Declare. (struct inferior) <needs_setup>: New field. * infrun.c (set_last_target_status): Make extern. (stop_all_threads): Make extern. Setup inferior, if necessary. * infrun.h (set_last_target_status, stop_all_threads): Declare. * remote-notif.c (remote_async_get_pending_events_handler) (handle_notification): Replace non_stop checks with target_is_non_stop_p() checks. * remote.c (remote_notice_new_inferior): Remove non_stop check. (remote_update_thread_list): Replace non_stop check with target_is_non_stop_p() check. (print_one_stopped_thread): New function. (process_initial_stop_replies): New 'from_tty' parameter. "Notice" all new live inferiors after storing initial stops as pending status in each corresponding thread. If all-stop, stop all threads, try picking a signalled thread as current, and print the status of that one thread. Record the last target status. (remote_start_remote): Replace non_stop checks with target_is_non_stop_p() checks. Don't query for the remote current thread of use qOffsets here. Pass from_tty to process_initial_stop_replies. (extended_remote_attach): Replace non_stop checks with target_is_non_stop_p() checks. (extended_remote_post_attach): Send qOffsets here. (remote_vcont_resume, remote_resume, remote_stop) (remote_interrupt, remote_parse_stop_reply, remote_wait): Replace non_stop checks with target_is_non_stop_p() checks. (remote_async): If target is non-stop, mark/clear the pending events token. * thread.c (switch_to_thread_no_regs): New function.
2015-11-30 17:05:13 +01:00
/* Initial inferior setup. Determines the exec file is not yet known,
takes any necessary post-attaching actions, fetches the target
description and syncs the shared library list. */
extern void setup_inferior (int from_tty);
extern void post_create_inferior (struct target_ops *, int);
Constify add_com This changes add_com to take a cmd_const_cfunc_ftype, and then fixes up all the command implementations. In most cases this is trivial. In a couple of places I had to again introduce a temporary non-const overload. These overloads will be removed when add_info is constified. gdb/ChangeLog 2017-11-07 Tom Tromey <tom@tromey.com> * solib.h (no_shared_libraries): Constify. * frame.h (return_command): Constify. * cli/cli-cmds.h (quit_command): Constify. * top.h (quit_command, execute_command): Constify. * target.h (flash_erase_command): Constify. * inferior.h (set_inferior_args, attach_command): Constify. * tracepoint.h (start_tracing, stop_tracing): Constify. * breakpoint.h (break_command, tbreak_command) (hbreak_command_wrapper, thbreak_command_wrapper) (rbreak_command_wrapper, watch_command_wrapper) (awatch_command_wrapper, rwatch_command_wrapper) (get_tracepoint_by_number): Constify. * symtab.c (info_variables_command, rbreak_command) (symtab_symbol_info): Constify. (info_variables_command): Add non-const overload. * top.c (dont_repeat_command): Constify. * breakpoint.c (ignore_command, commands_command) (condition_command, tbreak_command, hbreak_command) (thbreak_command, clear_command, break_command) (info_breakpoints_command, watch_command, rwatch_command) (awatch_command, trace_command, ftrace_command, strace_command) (trace_pass_command, break_range_command, dprintf_command) (agent_printf_command, get_tracepoint_by_number) (watch_maybe_just_location, trace_pass_command): Constify. (info_breakpoints_command): Add non-const overload. * tracefile.c (tsave_command): Constify. * infcmd.c (attach_command, disconnect_command, signal_command) (queue_signal_command, stepi_command, nexti_command) (finish_command, next_command, step_command, until_command) (advance_command, jump_command, continue_command, run_command) (start_command, starti_command, interrupt_command) (run_command_1, set_inferior_args, step_1): Constify. * inferior.c (add_inferior_command, remove_inferior_command) (clone_inferior_command): Constify. * linux-fork.c (checkpoint_command, restart_command): Constify. * windows-nat.c (signal_event_command): Constify. * guile/guile.c (guile_repl_command, guile_command): Constify. * printcmd.c (x_command, display_command, printf_command) (output_command, set_command, call_command, print_command) (eval_command): Constify. (non_const_set_command): Remove. (_initialize_printcmd): Update. * source.c (forward_search_command, reverse_search_command): Constify. * jit.c (jit_reader_load_command, jit_reader_unload_command): Constify. * infrun.c (handle_command): Constify. * memattr.c (mem_command): Constify. * stack.c (return_command, up_command, up_silently_command) (down_command, down_silently_command, frame_command) (backtrace_command, func_command, backtrace_command_1): Constify. (backtrace_command): Add non-const overload. * remote-sim.c (simulator_command): Constify. * exec.c (set_section_command): Constify. * tracepoint.c (tdump_command, trace_variable_command) (tstatus_command, tstop_command, tstart_command) (end_actions_pseudocommand, while_stepping_pseudocommand) (collect_pseudocommand, teval_pseudocommand, actions_command) (start_tracing, stop_tracing): Constify. * value.c (init_if_undefined_command): Constify. * tui/tui-stack.c (tui_update_command): Constify. * tui/tui-win.c (tui_refresh_all_command) (tui_set_tab_width_command, tui_set_win_height_command) (tui_set_focus_command, tui_scroll_forward_command) (tui_scroll_backward_command, tui_scroll_left_command) (tui_scroll_right_command, parse_scrolling_args, tui_set_focus) (tui_set_win_height): Constify. * tui/tui-layout.c (tui_layout_command): Constify. * procfs.c (proc_trace_syscalls, proc_trace_sysentry_cmd) (proc_trace_sysexit_cmd, proc_untrace_sysentry_cmd) (proc_untrace_sysexit_cmd): Constify. * remote.c (threadlist_test_cmd, threadinfo_test_cmd) (threadset_test_cmd, threadlist_update_test_cmd) (threadalive_test): Constify. * objc-lang.c (print_object_command): Constify. * command.h (add_com): Constify. * cli/cli-dump.c (restore_command): Constify. * cli/cli-cmds.c (pwd_command, echo_command, quit_command) (help_command, complete_command, shell_command, edit_command) (list_command, disassemble_command, make_command) (apropos_command, alias_command): Constify. * cli/cli-script.c (document_command, define_command) (while_command, if_command, validate_comname): Constify. * cli/cli-decode.c (struct cmd_list_element): Change type of "fun". * target.c (do_monitor_command, flash_erase_command): Constify. * regcache.c (reg_flush_command): Constify. * reverse.c (reverse_step, reverse_next, reverse_stepi) (reverse_nexti, reverse_continue, reverse_finish) (save_bookmark_command, goto_bookmark_command) (exec_reverse_once): Constify. * python/python.c (python_interactive_command, python_command): Constify. * typeprint.c (ptype_command, whatis_command, whatis_exp): Constify. * solib.c (sharedlibrary_command, no_shared_libraries): Constify. * gcore.c (gcore_command): Constify.
2017-10-11 23:43:01 +02:00
extern void attach_command (const char *, int);
extern const char *get_inferior_args (void);
Constify add_com This changes add_com to take a cmd_const_cfunc_ftype, and then fixes up all the command implementations. In most cases this is trivial. In a couple of places I had to again introduce a temporary non-const overload. These overloads will be removed when add_info is constified. gdb/ChangeLog 2017-11-07 Tom Tromey <tom@tromey.com> * solib.h (no_shared_libraries): Constify. * frame.h (return_command): Constify. * cli/cli-cmds.h (quit_command): Constify. * top.h (quit_command, execute_command): Constify. * target.h (flash_erase_command): Constify. * inferior.h (set_inferior_args, attach_command): Constify. * tracepoint.h (start_tracing, stop_tracing): Constify. * breakpoint.h (break_command, tbreak_command) (hbreak_command_wrapper, thbreak_command_wrapper) (rbreak_command_wrapper, watch_command_wrapper) (awatch_command_wrapper, rwatch_command_wrapper) (get_tracepoint_by_number): Constify. * symtab.c (info_variables_command, rbreak_command) (symtab_symbol_info): Constify. (info_variables_command): Add non-const overload. * top.c (dont_repeat_command): Constify. * breakpoint.c (ignore_command, commands_command) (condition_command, tbreak_command, hbreak_command) (thbreak_command, clear_command, break_command) (info_breakpoints_command, watch_command, rwatch_command) (awatch_command, trace_command, ftrace_command, strace_command) (trace_pass_command, break_range_command, dprintf_command) (agent_printf_command, get_tracepoint_by_number) (watch_maybe_just_location, trace_pass_command): Constify. (info_breakpoints_command): Add non-const overload. * tracefile.c (tsave_command): Constify. * infcmd.c (attach_command, disconnect_command, signal_command) (queue_signal_command, stepi_command, nexti_command) (finish_command, next_command, step_command, until_command) (advance_command, jump_command, continue_command, run_command) (start_command, starti_command, interrupt_command) (run_command_1, set_inferior_args, step_1): Constify. * inferior.c (add_inferior_command, remove_inferior_command) (clone_inferior_command): Constify. * linux-fork.c (checkpoint_command, restart_command): Constify. * windows-nat.c (signal_event_command): Constify. * guile/guile.c (guile_repl_command, guile_command): Constify. * printcmd.c (x_command, display_command, printf_command) (output_command, set_command, call_command, print_command) (eval_command): Constify. (non_const_set_command): Remove. (_initialize_printcmd): Update. * source.c (forward_search_command, reverse_search_command): Constify. * jit.c (jit_reader_load_command, jit_reader_unload_command): Constify. * infrun.c (handle_command): Constify. * memattr.c (mem_command): Constify. * stack.c (return_command, up_command, up_silently_command) (down_command, down_silently_command, frame_command) (backtrace_command, func_command, backtrace_command_1): Constify. (backtrace_command): Add non-const overload. * remote-sim.c (simulator_command): Constify. * exec.c (set_section_command): Constify. * tracepoint.c (tdump_command, trace_variable_command) (tstatus_command, tstop_command, tstart_command) (end_actions_pseudocommand, while_stepping_pseudocommand) (collect_pseudocommand, teval_pseudocommand, actions_command) (start_tracing, stop_tracing): Constify. * value.c (init_if_undefined_command): Constify. * tui/tui-stack.c (tui_update_command): Constify. * tui/tui-win.c (tui_refresh_all_command) (tui_set_tab_width_command, tui_set_win_height_command) (tui_set_focus_command, tui_scroll_forward_command) (tui_scroll_backward_command, tui_scroll_left_command) (tui_scroll_right_command, parse_scrolling_args, tui_set_focus) (tui_set_win_height): Constify. * tui/tui-layout.c (tui_layout_command): Constify. * procfs.c (proc_trace_syscalls, proc_trace_sysentry_cmd) (proc_trace_sysexit_cmd, proc_untrace_sysentry_cmd) (proc_untrace_sysexit_cmd): Constify. * remote.c (threadlist_test_cmd, threadinfo_test_cmd) (threadset_test_cmd, threadlist_update_test_cmd) (threadalive_test): Constify. * objc-lang.c (print_object_command): Constify. * command.h (add_com): Constify. * cli/cli-dump.c (restore_command): Constify. * cli/cli-cmds.c (pwd_command, echo_command, quit_command) (help_command, complete_command, shell_command, edit_command) (list_command, disassemble_command, make_command) (apropos_command, alias_command): Constify. * cli/cli-script.c (document_command, define_command) (while_command, if_command, validate_comname): Constify. * cli/cli-decode.c (struct cmd_list_element): Change type of "fun". * target.c (do_monitor_command, flash_erase_command): Constify. * regcache.c (reg_flush_command): Constify. * reverse.c (reverse_step, reverse_next, reverse_stepi) (reverse_nexti, reverse_continue, reverse_finish) (save_bookmark_command, goto_bookmark_command) (exec_reverse_once): Constify. * python/python.c (python_interactive_command, python_command): Constify. * typeprint.c (ptype_command, whatis_command, whatis_exp): Constify. * solib.c (sharedlibrary_command, no_shared_libraries): Constify. * gcore.c (gcore_command): Constify.
2017-10-11 23:43:01 +02:00
extern void set_inferior_args (const char *);
extern void set_inferior_args_vector (int, char **);
Constify add_info This patch constifies add_info and updates all the info commands. The bulk of this patch was written using a script; and then I did a manual pass to fix up the remaining compilation errors. I could not compile every changed file; in particular nto-procfs.c, gnu-nat.c, and darwin-nat-info.c; but I at least tried to check the correctness by inspection. gdb/ChangeLog 2017-11-07 Tom Tromey <tom@tromey.com> * frame.h (info_locals_command, info_args_command): Constify. * auto-load.h (auto_load_info_scripts): Constify. * inferior.h (registers_info): Constify. * copying.c: Rebuild. * copying.awk: Constify generated commands. * auto-load.c (auto_load_info_scripts) (info_auto_load_gdb_scripts): Constify. * cli/cli-decode.c (struct cmd_list_element): Take a cmd_const_cfunc_ftype. * command.h (add_info): Take a cmd_const_cfunc_ftype. * tui/tui-win.c (tui_all_windows_info): Constify. * python/py-auto-load.c (info_auto_load_python_scripts): Constify. * cli/cli-cmds.c (show_command): Remove non-const overload. * tracepoint.c (info_tvariables_command, info_scope_command): Constify. (info_static_tracepoint_markers_command): Constify. * thread.c (info_threads_command): Constify. (print_thread_info_1): Constify. * target.c (info_target_command): Constify. * symtab.c (info_sources_command, info_functions_command) (info_types_command): Constify. (info_variables_command): Remove non-const overload. * symfile.c (info_ext_lang_command): Constify. * stack.c (info_frame_command, info_locals_command) (info_args_command): Constify. (backtrace_command): Remove non-const overload. * source.c (info_source_command, info_line_command): Constify. * solib.c (info_sharedlibrary_command): Constify. * skip.c (info_skip_command): Constify. * ser-go32.c (info_serial_command): Constify. * reverse.c (info_bookmarks_command): Constify. * printcmd.c (info_symbol_command, info_address_command) (info_display_command): Constify. * osdata.c (info_osdata_command): Constify. * objc-lang.c (info_selectors_command, info_classes_command): Constify. * nto-procfs.c (procfs_pidlist, procfs_meminfo): Constify. * memattr.c (info_mem_command): Constify. * macrocmd.c (info_macro_command, info_macros_command): Constify. * linux-fork.c (info_checkpoints_command): Constify. * infrun.c (info_signals_command): Constify. * inflow.c (info_terminal_command): Constify. * inferior.c (info_inferiors_command): Constify. (print_inferior): Constify. * infcmd.c (info_program_command, info_all_registers_command) (info_registers_command, info_vector_command) (info_float_command): Constify. (registers_info): Constify. * gnu-nat.c (info_send_rights_cmd, info_recv_rights_cmd) (info_port_sets_cmd, info_dead_names_cmd, info_port_rights_cmd): Constify. * f-valprint.c (info_common_command): Constify. * dcache.c (info_dcache_command): Constify. (dcache_info_1): Constify. * darwin-nat-info.c (info_mach_tasks_command) (info_mach_task_command, info_mach_ports_command) (info_mach_port_command, info_mach_threads_command) (info_mach_thread_command, info_mach_regions_command) (info_mach_regions_recurse_command, info_mach_region_command) (info_mach_exceptions_command): Constify. (get_task_from_args): Constify. * cp-support.c (info_vtbl_command): Constify. * breakpoint.c (info_watchpoints_command) (info_tracepoints_command): Constify. (info_breakpoints_command): Remove non-const overload. * avr-tdep.c (avr_io_reg_read_command): Constify. * auxv.c (info_auxv_command): Constify. * ada-tasks.c (info_tasks_command): Constify. (info_task): Constify. * ada-lang.c (info_exceptions_command): Constify.
2017-10-14 06:07:26 +02:00
extern void registers_info (const char *, int);
extern void continue_1 (int all_threads);
Multi-target support This commit adds multi-target support to GDB. What this means is that with this commit, GDB can now be connected to different targets at the same time. E.g., you can debug a live native process and a core dump at the same time, connect to multiple gdbservers, etc. Actually, the word "target" is overloaded in gdb. We already have a target stack, with pushes several target_ops instances on top of one another. We also have "info target" already, which means something completely different to what this patch does. So from here on, I'll be using the "target connections" term, to mean an open process_stratum target, pushed on a target stack. This patch makes gdb have multiple target stacks, and multiple process_stratum targets open simultaneously. The user-visible changes / commands will also use this terminology, but of course it's all open to debate. User-interface-wise, not that much changes. The main difference is that each inferior may have its own target connection. A target connection (e.g., a target extended-remote connection) may support debugging multiple processes, just as before. Say you're debugging against gdbserver in extended-remote mode, and you do "add-inferior" to prepare to spawn a new process, like: (gdb) target extended-remote :9999 ... (gdb) start ... (gdb) add-inferior Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) file a.out ... (gdb) start ... At this point, you have two inferiors connected to the same gdbserver. With this commit, GDB will maintain a target stack per inferior, instead of a global target stack. To preserve the behavior above, by default, "add-inferior" makes the new inferior inherit a copy of the target stack of the current inferior. Same across a fork - the child inherits a copy of the target stack of the parent. While the target stacks are copied, the targets themselves are not. Instead, target_ops is made a refcounted_object, which means that target_ops instances are refcounted, which each inferior counting for a reference. What if you want to create an inferior and connect it to some _other_ target? For that, this commit introduces a new "add-inferior -no-connection" option that makes the new inferior not share the current inferior's target. So you could do: (gdb) target extended-remote :9999 Remote debugging using :9999 ... (gdb) add-inferior -no-connection [New inferior 2] Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 <null> (gdb) tar extended-remote :10000 Remote debugging using :10000 ... (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 process 18450 target:/home/pedro/tmp/main (gdb) A following patch will extended "info inferiors" to include a column indicating which connection an inferior is bound to, along with a couple other UI tweaks. Other than that, debugging is the same as before. Users interact with inferiors and threads as before. The only difference is that inferiors may be bound to processes running in different machines. That's pretty much all there is to it in terms of noticeable UI changes. On to implementation. Since we can be connected to different systems at the same time, a ptid_t is no longer a unique identifier. Instead a thread can be identified by a pair of ptid_t and 'process_stratum_target *', the later being the instance of the process_stratum target that owns the process/thread. Note that process_stratum_target inherits from target_ops, and all process_stratum targets inherit from process_stratum_target. In earlier patches, many places in gdb were converted to refer to threads by thread_info pointer instead of ptid_t, but there are still places in gdb where we start with a pid/tid and need to find the corresponding inferior or thread_info objects. So you'll see in the patch many places adding a process_stratum_target parameter to functions that used to take only a ptid_t. Since each inferior has its own target stack now, we can always find the process_stratum target for an inferior. That is done via a inf->process_target() convenience method. Since each inferior has its own target stack, we need to handle the "beneath" calls when servicing target calls. The solution I settled with is just to make sure to switch the current inferior to the inferior you want before making a target call. Not relying on global context is just not feasible in current GDB. Fortunately, there aren't that many places that need to do that, because generally most code that calls target methods already has the current context pointing to the right inferior/thread. Note, to emphasize -- there's no method to "switch to this target stack". Instead, you switch the current inferior, and that implicitly switches the target stack. In some spots, we need to iterate over all inferiors so that we reach all target stacks. Native targets are still singletons. There's always only a single instance of such targets. Remote targets however, we'll have one instance per remote connection. The exec target is still a singleton. There's only one instance. I did not see the point of instanciating more than one exec_target object. After vfork, we need to make sure to push the exec target on the new inferior. See exec_on_vfork. For type safety, functions that need a {target, ptid} pair to identify a thread, take a process_stratum_target pointer for target parameter instead of target_ops *. Some shared code in gdb/nat/ also need to gain a target pointer parameter. This poses an issue, since gdbserver doesn't have process_stratum_target, only target_ops. To fix this, this commit renames gdbserver's target_ops to process_stratum_target. I think this makes sense. There's no concept of target stack in gdbserver, and gdbserver's target_ops really implements a process_stratum-like target. The thread and inferior iterator functions also gain process_stratum_target parameters. These are used to be able to iterate over threads and inferiors of a given target. Following usual conventions, if the target pointer is null, then we iterate over threads and inferiors of all targets. I tried converting "add-inferior" to the gdb::option framework, as a preparatory patch, but that stumbled on the fact that gdb::option does not support file options yet, for "add-inferior -exec". I have a WIP patchset that adds that, but it's not a trivial patch, mainly due to need to integrate readline's filename completion, so I deferred that to some other time. In infrun.c/infcmd.c, the main change is that we need to poll events out of all targets. See do_target_wait. Right after collecting an event, we switch the current inferior to an inferior bound to the target that reported the event, so that target methods can be used while handling the event. This makes most of the code transparent to multi-targets. See fetch_inferior_event. infrun.c:stop_all_threads is interesting -- in this function we need to stop all threads of all targets. What the function does is send an asynchronous stop request to all threads, and then synchronously waits for events, with target_wait, rinse repeat, until all it finds are stopped threads. Now that we have multiple targets, it's not efficient to synchronously block in target_wait waiting for events out of one target. Instead, we implement a mini event loop, with interruptible_select, select'ing on one file descriptor per target. For this to work, we need to be able to ask the target for a waitable file descriptor. Such file descriptors already exist, they are the descriptors registered in the main event loop with add_file_handler, inside the target_async implementations. This commit adds a new target_async_wait_fd target method that just returns the file descriptor in question. See wait_one / stop_all_threads in infrun.c. The 'threads_executing' global is made a per-target variable. Since it is only relevant to process_stratum_target targets, this is where it is put, instead of in target_ops. You'll notice that remote.c includes some FIXME notes. These refer to the fact that the global arrays that hold data for the remote packets supported are still globals. For example, if we connect to two different servers/stubs, then each might support different remote protocol features. They might even be different architectures, like e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a host/controller scenario as a single program. That isn't going to work correctly today, because of said globals. I'm leaving fixing that for another pass, since it does not appear to be trivial, and I'd rather land the base work first. It's already useful to be able to debug multiple instances of the same server (e.g., a distributed cluster, where you have full control over the servers installed), so I think as is it's already reasonable incremental progress. Current limitations: - You can only resume more that one target at the same time if all targets support asynchronous debugging, and support non-stop mode. It should be possible to support mixed all-stop + non-stop backends, but that is left for another time. This means that currently in order to do multi-target with gdbserver you need to issue "maint set target-non-stop on". I would like to make that mode be the default, but we're not there yet. Note that I'm talking about how the target backend works, only. User-visible all-stop mode works just fine. - As explained above, connecting to different remote servers at the same time is likely to produce bad results if they don't support the exact set of RSP features. FreeBSD updates courtesy of John Baldwin. gdb/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> John Baldwin <jhb@FreeBSD.org> * aarch64-linux-nat.c (aarch64_linux_nat_target::thread_architecture): Adjust. * ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call. (task_command_1): Likewise. * aix-thread.c (sync_threadlists, aix_thread_target::resume) (aix_thread_target::wait, aix_thread_target::fetch_registers) (aix_thread_target::store_registers) (aix_thread_target::thread_alive): Adjust. * amd64-fbsd-tdep.c: Include "inferior.h". (amd64fbsd_get_thread_local_address): Pass down target. * amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle thread's gdbarch instead of target_gdbarch. * break-catch-sig.c (signal_catchpoint_print_it): Adjust call to get_last_target_status. * break-catch-syscall.c (print_it_catch_syscall): Likewise. * breakpoint.c (breakpoints_should_be_inserted_now): Consider all inferiors. (update_inserted_breakpoint_locations): Skip if inferiors with no execution. (update_global_location_list): When handling moribund locations, find representative inferior for location's pspace, and use thread count of its process_stratum target. * bsd-kvm.c (bsd_kvm_target_open): Pass target down. * bsd-uthread.c (bsd_uthread_target::wait): Use as_process_stratum_target and adjust thread_change_ptid and add_thread calls. (bsd_uthread_target::update_thread_list): Use as_process_stratum_target and adjust find_thread_ptid, thread_change_ptid and add_thread calls. * btrace.c (maint_btrace_packet_history_cmd): Adjust find_thread_ptid call. * corelow.c (add_to_thread_list): Adjust add_thread call. (core_target_open): Adjust add_thread_silent and thread_count calls. (core_target::pid_to_str): Adjust find_inferior_ptid call. * ctf.c (ctf_target_open): Adjust add_thread_silent call. * event-top.c (async_disconnect): Pop targets from all inferiors. * exec.c (add_target_sections): Push exec target on all inferiors sharing the program space. (remove_target_sections): Remove the exec target from all inferiors sharing the program space. (exec_on_vfork): New. * exec.h (exec_on_vfork): Declare. * fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::update_thread_list): Adjust. (fbsd_nat_target::resume): Adjust. (fbsd_handle_debug_trap): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust. * fbsd-tdep.c (fbsd_corefile_thread): Adjust get_thread_arch_regcache call. * fork-child.c (gdb_startup_inferior): Pass target down to startup_inferior and set_executing. * gdbthread.h (struct process_stratum_target): Forward declare. (add_thread, add_thread_silent, add_thread_with_info) (in_thread_list): Add process_stratum_target parameter. (find_thread_ptid(inferior*, ptid_t)): New overload. (find_thread_ptid, thread_change_ptid): Add process_stratum_target parameter. (all_threads()): Delete overload. (all_threads, all_non_exited_threads): Add process_stratum_target parameter. (all_threads_safe): Use brace initialization. (thread_count): Add process_stratum_target parameter. (set_resumed, set_running, set_stop_requested, set_executing) (threads_are_executing, finish_thread_state): Add process_stratum_target parameter. (switch_to_thread): Use is_current_thread. * i386-fbsd-tdep.c: Include "inferior.h". (i386fbsd_get_thread_local_address): Pass down target. * i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust. * inf-child.c (inf_child_target::maybe_unpush_target): Remove have_inferiors check. * inf-ptrace.c (inf_ptrace_target::create_inferior) (inf_ptrace_target::attach): Adjust. * infcall.c (run_inferior_call): Adjust. * infcmd.c (run_command_1): Pass target to scoped_finish_thread_state. (proceed_thread_callback): Skip inferiors with no execution. (continue_command): Rename 'all_threads' local to avoid hiding 'all_threads' function. Adjust get_last_target_status call. (prepare_one_step): Adjust set_running call. (signal_command): Use user_visible_resume_target. Compare thread pointers instead of inferior_ptid. (info_program_command): Adjust to pass down target. (attach_command): Mark target's 'thread_executing' flag. (stop_current_target_threads_ns): New, factored out from ... (interrupt_target_1): ... this. Switch inferior before making target calls. * inferior-iter.h (struct all_inferiors_iterator, struct all_inferiors_range) (struct all_inferiors_safe_range) (struct all_non_exited_inferiors_range): Filter on process_stratum_target too. Remove explicit. * inferior.c (inferior::inferior): Push dummy target on target stack. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors): Add process_stratum_target parameter, and pass it down. (have_live_inferiors): Adjust. (switch_to_inferior_and_push_target): New. (add_inferior_command, clone_inferior_command): Handle "-no-connection" parameter. Use switch_to_inferior_and_push_target. (_initialize_inferior): Mention "-no-connection" option in the help of "add-inferior" and "clone-inferior" commands. * inferior.h: Include "process-stratum-target.h". (interrupt_target_1): Use bool. (struct inferior) <push_target, unpush_target, target_is_pushed, find_target_beneath, top_target, process_target, target_at, m_stack>: New. (discard_all_inferiors): Delete. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors) (all_inferiors, all_non_exited_inferiors): Add process_stratum_target parameter. * infrun.c: Include "gdb_select.h" and <unordered_map>. (target_last_proc_target): New global. (follow_fork_inferior): Push target on new inferior. Pass target to add_thread_silent. Call exec_on_vfork. Handle target's reference count. (follow_fork): Adjust get_last_target_status call. Also consider target. (follow_exec): Push target on new inferior. (struct execution_control_state) <target>: New field. (user_visible_resume_target): New. (do_target_resume): Call target_async. (resume_1): Set target's threads_executing flag. Consider resume target. (commit_resume_all_targets): New. (proceed): Also consider resume target. Skip threads of inferiors with no execution. Commit resumtion in all targets. (start_remote): Pass current inferior to wait_for_inferior. (infrun_thread_stop_requested): Consider target as well. Pass thread_info pointer to clear_inline_frame_state instead of ptid. (infrun_thread_thread_exit): Consider target as well. (random_pending_event_thread): New inferior parameter. Use it. (do_target_wait): Rename to ... (do_target_wait_1): ... this. Add inferior parameter, and pass it down. (threads_are_resumed_pending_p, do_target_wait): New. (prepare_for_detach): Adjust calls. (wait_for_inferior): New inferior parameter. Handle it. Use do_target_wait_1 instead of do_target_wait. (fetch_inferior_event): Adjust. Switch to representative inferior. Pass target down. (set_last_target_status): Add process_stratum_target parameter. Save target in global. (get_last_target_status): Add process_stratum_target parameter and handle it. (nullify_last_target_wait_ptid): Clear 'target_last_proc_target'. (context_switch): Check inferior_ptid == null_ptid before calling inferior_thread(). (get_inferior_stop_soon): Pass down target. (wait_one): Rename to ... (poll_one_curr_target): ... this. (struct wait_one_event): New. (wait_one): New. (stop_all_threads): Adjust. (handle_no_resumed, handle_inferior_event): Adjust to consider the event's target. (switch_back_to_stepped_thread): Also consider target. (print_stop_event): Update. (normal_stop): Update. Also consider the resume target. * infrun.h (wait_for_inferior): Remove declaration. (user_visible_resume_target): New declaration. (get_last_target_status, set_last_target_status): New process_stratum_target parameter. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter, and use it. (clear_inline_frame_state (thread_info*)): New. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter. (clear_inline_frame_state (thread_info*)): Declare. * linux-fork.c (delete_checkpoint_command): Pass target down to find_thread_ptid. (checkpoint_command): Adjust. * linux-nat.c (linux_nat_target::follow_fork): Switch to thread instead of just tweaking inferior_ptid. (linux_nat_switch_fork): Pass target down to thread_change_ptid. (exit_lwp): Pass target down to find_thread_ptid. (attach_proc_task_lwp_callback): Pass target down to add_thread/set_running/set_executing. (linux_nat_target::attach): Pass target down to thread_change_ptid. (get_detach_signal): Pass target down to find_thread_ptid. Consider last target status's target. (linux_resume_one_lwp_throw, resume_lwp) (linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp) (stop_wait_callback, save_stop_reason, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down. (linux_nat_target::async_wait_fd): New. (linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass target down. * linux-nat.h (linux_nat_target::async_wait_fd): Declare. * linux-tdep.c (get_thread_arch_regcache): Pass target down. * linux-thread-db.c (struct thread_db_info::process_target): New field. (add_thread_db_info): Save target. (get_thread_db_info): New process_stratum_target parameter. Also match target. (delete_thread_db_info): New process_stratum_target parameter. Also match target. (thread_from_lwp): Adjust to pass down target. (thread_db_notice_clone): Pass down target. (check_thread_db_callback): Pass down target. (try_thread_db_load_1): Always push the thread_db target. (try_thread_db_load, record_thread): Pass target down. (thread_db_target::detach): Pass target down. Always unpush the thread_db target. (thread_db_target::wait, thread_db_target::mourn_inferior): Pass target down. Always unpush the thread_db target. (find_new_threads_callback, thread_db_find_new_threads_2) (thread_db_target::update_thread_list): Pass target down. (thread_db_target::pid_to_str): Pass current inferior down. (thread_db_target::get_thread_local_address): Pass target down. (thread_db_target::resume, maintenance_check_libthread_db): Pass target down. * nto-procfs.c (nto_procfs_target::update_thread_list): Adjust. * procfs.c (procfs_target::procfs_init_inferior): Declare. (proc_set_current_signal, do_attach, procfs_target::wait): Adjust. (procfs_init_inferior): Rename to ... (procfs_target::procfs_init_inferior): ... this and adjust. (procfs_target::create_inferior, procfs_notice_thread) (procfs_do_thread_registers): Adjust. * ppc-fbsd-tdep.c: Include "inferior.h". (ppcfbsd_get_thread_local_address): Pass down target. * proc-service.c (ps_xfer_memory): Switch current inferior and program space as well. (get_ps_regcache): Pass target down. * process-stratum-target.c (process_stratum_target::thread_address_space) (process_stratum_target::thread_architecture): Pass target down. * process-stratum-target.h (process_stratum_target::threads_executing): New field. (as_process_stratum_target): New. * ravenscar-thread.c (ravenscar_thread_target::update_inferior_ptid): Pass target down. (ravenscar_thread_target::wait, ravenscar_add_thread): Pass target down. * record-btrace.c (record_btrace_target::info_record): Adjust. (record_btrace_target::record_method) (record_btrace_target::record_is_replaying) (record_btrace_target::fetch_registers) (get_thread_current_frame_id, record_btrace_target::resume) (record_btrace_target::wait, record_btrace_target::stop): Pass target down. * record-full.c (record_full_wait_1): Switch to event thread. Pass target down. * regcache.c (regcache::regcache) (get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add process_stratum_target parameter and handle it. (current_thread_target): New global. (get_thread_regcache): Add process_stratum_target parameter and handle it. Switch inferior before calling target method. (get_thread_regcache): Pass target down. (get_thread_regcache_for_ptid): Pass target down. (registers_changed_ptid): Add process_stratum_target parameter and handle it. (registers_changed_thread, registers_changed): Pass target down. (test_get_thread_arch_aspace_regcache): New. (current_regcache_test): Define a couple local test_target_ops instances and use them for testing. (readwrite_regcache): Pass process_stratum_target parameter. (cooked_read_test, cooked_write_test): Pass mock_target down. * regcache.h (get_thread_regcache, get_thread_arch_regcache) (get_thread_arch_aspace_regcache): Add process_stratum_target parameter. (regcache::target): New method. (regcache::regcache, regcache::get_thread_arch_aspace_regcache) (regcache::registers_changed_ptid): Add process_stratum_target parameter. (regcache::m_target): New field. (registers_changed_ptid): Add process_stratum_target parameter. * remote.c (remote_state::supports_vCont_probed): New field. (remote_target::async_wait_fd): New method. (remote_unpush_and_throw): Add remote_target parameter. (get_current_remote_target): Adjust. (remote_target::remote_add_inferior): Push target. (remote_target::remote_add_thread) (remote_target::remote_notice_new_inferior) (get_remote_thread_info): Pass target down. (remote_target::update_thread_list): Skip threads of inferiors bound to other targets. (remote_target::close): Don't discard inferiors. (remote_target::add_current_inferior_and_thread) (remote_target::process_initial_stop_replies) (remote_target::start_remote) (remote_target::remote_serial_quit_handler): Pass down target. (remote_target::remote_unpush_target): New remote_target parameter. Unpush the target from all inferiors. (remote_target::remote_unpush_and_throw): New remote_target parameter. Pass it down. (remote_target::open_1): Check whether the current inferior has execution instead of checking whether any inferior is live. Pass target down. (remote_target::remote_detach_1): Pass down target. Use remote_unpush_target. (extended_remote_target::attach): Pass down target. (remote_target::remote_vcont_probe): Set supports_vCont_probed. (remote_target::append_resumption): Pass down target. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc, remote_target::resume) (remote_target::commit_resume): Pass down target. (remote_target::remote_stop_ns): Check supports_vCont_probed. (remote_target::interrupt_query) (remote_target::remove_new_fork_children) (remote_target::check_pending_events_prevent_wildcard_vcont) (remote_target::remote_parse_stop_reply) (remote_target::process_stop_reply): Pass down target. (first_remote_resumed_thread): New remote_target parameter. Pass it down. (remote_target::wait_as): Pass down target. (unpush_and_perror): New remote_target parameter. Pass it down. (remote_target::readchar, remote_target::remote_serial_write) (remote_target::getpkt_or_notif_sane_1) (remote_target::kill_new_fork_children, remote_target::kill): Pass down target. (remote_target::mourn_inferior): Pass down target. Use remote_unpush_target. (remote_target::core_of_thread) (remote_target::remote_btrace_maybe_reopen): Pass down target. (remote_target::pid_to_exec_file) (remote_target::thread_handle_to_thread_info): Pass down target. (remote_target::async_wait_fd): New. * riscv-fbsd-tdep.c: Include "inferior.h". (riscv_fbsd_get_thread_local_address): Pass down target. * sol2-tdep.c (sol2_core_pid_to_str): Pass down target. * sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs) (ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback): Adjust. * solib-spu.c (spu_skip_standalone_loader): Pass down target. * solib-svr4.c (enable_break): Pass down target. * spu-multiarch.c (parse_spufs_run): Pass down target. * spu-tdep.c (spu2ppu_sniffer): Pass down target. * target-delegates.c: Regenerate. * target.c (g_target_stack): Delete. (current_top_target): Return the current inferior's top target. (target_has_execution_1): Refer to the passed-in inferior's top target. (target_supports_terminal_ours): Check whether the initial inferior was already created. (decref_target): New. (target_stack::push): Incref/decref the target. (push_target, push_target, unpush_target): Adjust. (target_stack::unpush): Defref target. (target_is_pushed): Return bool. Adjust to refer to the current inferior's target stack. (dispose_inferior): Delete, and inline parts ... (target_preopen): ... here. Only dispose of the current inferior. (target_detach): Hold strong target reference while detaching. Pass target down. (target_thread_name): Add assertion. (target_resume): Pass down target. (target_ops::beneath, find_target_at): Adjust to refer to the current inferior's target stack. (get_dummy_target): New. (target_pass_ctrlc): Pass the Ctrl-C to the first inferior that has a thread running. (initialize_targets): Rename to ... (_initialize_target): ... this. * target.h: Include "gdbsupport/refcounted-object.h". (struct target_ops): Inherit refcounted_object. (target_ops::shortname, target_ops::longname): Make const. (target_ops::async_wait_fd): New method. (decref_target): Declare. (struct target_ops_ref_policy): New. (target_ops_ref): New typedef. (get_dummy_target): Declare function. (target_is_pushed): Return bool. * thread-iter.c (all_matching_threads_iterator::m_inf_matches) (all_matching_threads_iterator::all_matching_threads_iterator): Handle filter target. * thread-iter.h (struct all_matching_threads_iterator, struct all_matching_threads_range, class all_non_exited_threads_range): Filter by target too. Remove explicit. * thread.c (threads_executing): Delete. (inferior_thread): Pass down current inferior. (clear_thread_inferior_resources): Pass down thread pointer instead of ptid_t. (add_thread_silent, add_thread_with_info, add_thread): Add process_stratum_target parameter. Use it for thread and inferior searches. (is_current_thread): New. (thread_info::deletable): Use it. (find_thread_ptid, thread_count, in_thread_list) (thread_change_ptid, set_resumed, set_running): New process_stratum_target parameter. Pass it down. (set_executing): New process_stratum_target parameter. Pass it down. Adjust reference to 'threads_executing'. (threads_are_executing): New process_stratum_target parameter. Adjust reference to 'threads_executing'. (set_stop_requested, finish_thread_state): New process_stratum_target parameter. Pass it down. (switch_to_thread): Also match inferior. (switch_to_thread): New process_stratum_target parameter. Pass it down. (update_threads_executing): Reimplement. * top.c (quit_force): Pop targets from all inferior. (gdb_init): Don't call initialize_targets. * windows-nat.c (windows_nat_target) <get_windows_debug_event>: Declare. (windows_add_thread, windows_delete_thread): Adjust. (get_windows_debug_event): Rename to ... (windows_nat_target::get_windows_debug_event): ... this. Adjust. * tracefile-tfile.c (tfile_target_open): Pass down target. * gdbsupport/common-gdbthread.h (struct process_stratum_target): Forward declare. (switch_to_thread): Add process_stratum_target parameter. * mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target parameter. Use it. (mi_on_resume): Pass target down. * nat/fork-inferior.c (startup_inferior): Add process_stratum_target parameter. Pass it down. * nat/fork-inferior.h (startup_inferior): Add process_stratum_target parameter. * python/py-threadevent.c (py_get_event_thread): Pass target down. gdb/gdbserver/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> * fork-child.c (post_fork_inferior): Pass target down to startup_inferior. * inferiors.c (switch_to_thread): Add process_stratum_target parameter. * lynx-low.c (lynx_target_ops): Now a process_stratum_target. * nto-low.c (nto_target_ops): Now a process_stratum_target. * linux-low.c (linux_target_ops): Now a process_stratum_target. * remote-utils.c (prepare_resume_reply): Pass the target to switch_to_thread. * target.c (the_target): Now a process_stratum_target. (done_accessing_memory): Pass the target to switch_to_thread. (set_target_ops): Ajust to use process_stratum_target. * target.h (struct target_ops): Rename to ... (struct process_stratum_target): ... this. (the_target, set_target_ops): Adjust. (prepare_to_access_memory): Adjust comment. * win32-low.c (child_xfer_memory): Adjust to use process_stratum_target. (win32_target_ops): Now a process_stratum_target.
2020-01-10 21:06:08 +01:00
extern void interrupt_target_1 (bool all_threads);
using delete_longjmp_breakpoint_cleanup
= FORWARD_SCOPE_EXIT (delete_longjmp_breakpoint);
gdb PR c++/9593: * thread.c (clear_thread_inferior_resources): Call delete_longjmp_breakpoint. * infrun.c (handle_inferior_event): Handle exception breakpoints. (handle_inferior_event): Likewise. (insert_exception_resume_breakpoint): New function. (check_exception_resume): Likewise. * inferior.h (delete_longjmp_breakpoint_cleanup): Declare. * infcmd.c (delete_longjmp_breakpoint_cleanup): No longer static. (step_1): Set thread's initiating frame. (until_next_continuation): New function. (until_next_command): Support exception breakpoints. (finish_command_continuation): Delete longjmp breakpoint. (finish_forward): Support exception breakpoints. * gdbthread.h (struct thread_info) <initiating_frame>: New field. * breakpoint.h (enum bptype) <bp_exception, bp_exception_resume, bp_exception_master>: New constants. (struct bpstat_what) <is_longjmp>: New field. (set_longjmp_breakpoint): Update. * breakpoint.c (create_exception_master_breakpoint): New function. (update_breakpoints_after_exec): Handle bp_exception_master. Call create_exception_master_breakpoint. (print_it_typical): Handle bp_exception_master, bp_exception. (bpstat_stop_status): Handle bp_exception_master. (bpstat_what): Handle bp_exception_master, bp_exception, bp_exception_resume. (bptype_string): Likewise. (print_one_breakpoint_location): Likewise. (allocate_bp_location): Likewise. (set_longjmp_breakpoint): Handle exception breakpoints. Change interface. (delete_longjmp_breakpoint): Handle exception breakpoints. (mention): Likewise. (struct until_break_command_continuation_args) <thread_num>: New field. (until_break_command_continuation): Call delete_longjmp_breakpoint. (until_break_command): Support exception breakpoints. (delete_command): Likewise. (breakpoint_re_set_one): Likewise. (breakpoint_re_set): Likewise. gdb/testuite * gdb.java/jnpe.java: New file. * gdb.java/jnpe.exp: New file. * gdb.cp/nextoverthrow.exp: New file. * gdb.cp/nextoverthrow.cc: New file.
2010-12-09 17:09:54 +01:00
Constify add_prefix_cmd This changes add_prefix_cmd to accept a const-taking function as an argument; then fixes up all the callers. In a couple of spots I had to add a non-const overload of a function, because the function is passed to two different command-adding "constructors". These overloads are temporary; once constification is complete they can be removed. This patch also fixes a typo I happened to notice while constifying. Note that this touches a couple of files (gnu-nat.c and go32-nat.c) that I can't build. So, while I made a best-effort there, I am not certain they will still compile. Tested by rebuilding. gdb/ChangeLog 2017-10-11 Tom Tromey <tom@tromey.com> * gdbthread.h (thread_command): Constify. * inferior.h (detach_command): Constify. * top.h (set_history, show_history): Constify. * arm-tdep.c (set_arm_command, show_arm_command): Constify. * serial.c (serial_set_cmd, serial_show_cmd): Constify. * bsd-kvm.c (bsd_kvm_cmd): Constify. * printcmd.c (set_command): Constify. (non_const_set_command): New function. * dcache.c (set_dcache_command, show_dcache_command): Constify. * breakpoint.c (enable_command, disable_command, delete_command) (catch_command, tcatch_command, set_breakpoint_cmd) (show_breakpoint_cmd): Constify. * macrocmd.c (macro_command): Constify. * infcmd.c (unset_command, kill_command, detach_command) (info_proc_cmd): Constify. * i386-tdep.c (set_mpx_cmd, show_mpx_cmd): Constify. * auto-load.c (show_auto_load_cmd, set_auto_load_cmd) (info_auto_load_cmd): Constify. * target-descriptions.c (set_tdesc_cmd, show_tdesc_cmd) (unset_tdesc_cmd): Constify. * ada-lang.c (set_ada_command, show_ada_command) (maint_set_ada_cmd, maint_show_ada_cmd): Constify. * guile/guile.c (set_guile_command, show_guile_command) (info_guile_command): Constify. * tui/tui-win.c (tui_command, set_tui_cmd, show_tui_cmd): Constify. * skip.c (skip_command): Constify. * compile/compile.c (_initialize_compile): Constify. * dwarf2read.c (set_dwarf_cmd, show_dwarf_cmd): Constify. * btrace.c (maint_btrace_cmd, maint_btrace_set_cmd) (maint_btrace_show_cmd, maint_btrace_pt_set_cmd) (maint_btrace_pt_show_cmd): Constify. * remote.c (set_remote_cmd, show_remote_cmd, remote_command): Constify. * python/python.c (user_show_python, user_set_python): Constify. * mips-tdep.c (set_mips_command, show_mips_command) (set_mipsfpu_command): Constify. * record-btrace.c (cmd_record_btrace_start) (cmd_set_record_btrace, cmd_show_record_btrace) (cmd_set_record_btrace_bts, cmd_show_record_btrace_bts) (cmd_set_record_btrace_pt, cmd_show_record_btrace_pt): Constify. * rs6000-tdep.c (set_powerpc_command, show_powerpc_command): Constify. * symfile.c (overlay_command): Constify. * spu-tdep.c (set_spu_command, show_spu_command): Constify. * cli/cli-logging.c (set_logging_command, show_logging_command): Constify. * cli/cli-dump.c (dump_command, append_command) (srec_dump_command, ihex_dump_command, verilog_dump_command) (tekhex_dump_command, binary_dump_command) (binary_append_command): Constify. * cli/cli-decode.c (struct cmd_list_element): Change type of "fun". * cli/cli-cmds.c (info_command, show_command, set_debug) (show_debug): Constify. (show_command): Add non-const overload. * top.c (set_history, show_history): Constify. * sh-tdep.c (set_sh_command, show_sh_command): Constify. * command.h (add_prefix_cmd): Accept a cmd_const_cfunc_ftype. * target.c (target_command): Constify. * sparc64-tdep.c (info_adi_command): Constify. * record-full.c (cmd_record_full_start): Constify. (set_record_full_command): Constify. Fix typo. (show_record_full_command): Constify. * thread.c (thread_command, thread_apply_command): Constify. * memattr.c (dummy_cmd): Constify. * value.c (function_command): Constify. * frame.c (set_backtrace_cmd, show_backtrace_cmd): Constify. * probe.c (info_probes_command): Constify. * ser-tcp.c (set_tcp_cmd, show_tcp_cmd): Constify. * gnu-nat.c (set_task_cmd, show_task_cmd, set_thread_cmd) (show_thread_cmd, set_thread_default_cmd) (show_thread_default_cmd): Constify. (check_empty): Constify. * tracepoint.c (tfind_command): Constify. * cp-support.c (maint_cplus_command): Constify. * windows-tdep.c (info_w32_command): Constify. * record.c (cmd_record_start, set_record_command) (show_record_command, info_record_command, cmd_record_goto): Constify. * ravenscar-thread.c (set_ravenscar_command) (show_ravenscar_command): Constify. * utils.c (set_internal_problem_cmd, show_internal_problem_cmd): Constify. (add_internal_problem_command): Remove casts. * arc-tdep.c (maintenance_print_arc_command): Constify. * valprint.c (set_print, show_print, set_print_raw) (show_print_raw): Constify. * maint.c (maintenance_command, maintenance_info_command) (maintenance_print_command, maintenance_set_cmd) (maintenance_show_cmd, set_per_command_cmd) (show_per_command_cmd, maintenance_check_command): Constify. * language.c (set_check, show_check): Constify. * typeprint.c (show_print_type, set_print_type): Constify. * go32-nat.c (go32_info_dos_command): Constify.
2017-09-26 06:28:30 +02:00
extern void detach_command (const char *, int);
extern void notice_new_inferior (struct thread_info *, int, int);
extern struct value *get_return_value (struct value *function,
struct type *value_type);
Introduce gdb.FinishBreakpoint in Python * Makefile.in (SUBDIR_PYTHON_OBS): Add py-finishbreakpoint.o. (SUBDIR_PYTHON_SRCS): Add python/py-finishbreakpoint.c. Add build rule for this file. * infcmd.c (print_return_value): Split to create get_return_value. (get_return_value): New function based on print_return_value. Handle case where stop_registers are not set. * inferior.h (get_return_value): New prototype. * python/py-breakpoint.c (bppy_pending_object): Make non-static. (gdbpy_breakpoint_created): Set is_py_finish_bp is necessary. (struct breakpoint_object): Move to python-internal.h (BPPY_REQUIRE_VALID): Likewise. (BPPY_SET_REQUIRE_VALID): Likewise. (gdbpy_breakpoint_created): Initialize is_finish_bp. (gdbpy_should_stop): Add pre/post hooks before/after calling stop method. * python/python-internal.h (breakpoint_object_type): Add as extern. (bppy_pending_object): Likewise. (typedef struct breakpoint_object) Removed. (struct breakpoint_object): Moved from py-breakpoint.c. Add field is_finish_bp. (BPPY_REQUIRE_VALID): Moved from py-breakpoint.c. (BPPY_SET_REQUIRE_VALID): Likewise. (frame_object_to_frame_info): New prototype. (gdbpy_initialize_finishbreakpoints): New prototype. (bpfinishpy_is_finish_bp): Likewise. (bpfinishpy_pre_stop_hook): Likewise. (bpfinishpy_post_stop_hook): Likewise. * python/py-finishbreakpoint.c: New file. * python/py-frame.c(frame_object_to_frame_info): Make non-static and accept PyObject instead of frame_object. (frapy_is_valid): Don't cast to frame_object. (frapy_name): Likewise. (frapy_type): Likewise. (frapy_unwind_stop_reason): Likewise. (frapy_pc): Likewise. (frapy_block): Likewise. (frapy_function): Likewise. (frapy_older): Likewise. (frapy_newer): Likewise. (frapy_find_sal): Likewise. (frapy_read_var): Likewise. (frapy_select): Likewise. * python/python.c (gdbpy_is_stopped_at_finish_bp): New noop function. (_initialize_python): Add gdbpy_initialize_finishbreakpoints. * python/python.h: Include breakpoint.h (gdbpy_is_stopped_at_finish_bp): New prototype. doc/ * gdb.texinfo (Finish Breakpoints in Python): New subsection. (Python API): Add menu entry for Finish Breakpoints. testsuite/ * Makefile.in (EXECUTABLES): Add py-finish-breakpoint and py-finish-breakpoint2 (MISCALLANEOUS): Add py-events-shlib.so and py-events-shlib-nodebug.so * gdb.python/py-breakpoint.exp (mult_line): Define and use variable instead of line number. * gdb.python/py-finish-breakpoint.c: New file. * gdb.python/py-finish-breakpoint.exp: New file. * gdb.python/py-finish-breakpoint.py: New file. * gdb.python/py-finish-breakpoint2.cc: New file. * gdb.python/py-finish-breakpoint2.exp: New file. * gdb.python/py-finish-breakpoint2.py: New file.
2011-12-23 18:06:16 +01:00
enable target async by default; separate MI and target notions of async This finally makes background execution commands possible by default. However, in order to do that, there's one last thing we need to do -- we need to separate the MI and target notions of "async". Unlike the CLI, where the user explicitly requests foreground vs background execution in the execution command itself (c vs c&), MI chose to treat "set target-async" specially -- setting it changes the default behavior of execution commands. So, we can't simply "set target-async" default to on, as that would affect MI frontends. Instead we have to make the setting MI-specific, and teach MI about sync commands on top of an async target. Because the "target" word in "set target-async" ends up as a potential source of confusion, the patch adds a "set mi-async" option, and makes "set target-async" a deprecated alias. Rather than make the targets always async, this patch introduces a new "maint set target-async" option so that the GDB developer can control whether the target is async. This makes it simpler to debug issues arising only in the synchronous mode; important because sync mode seems unlikely to go away. Unlike in previous revisions, "set target-async" does not affect this new maint parameter. The rationale for this is that then one can easily run the test suite in the "maint set target-async off" mode and have tests that enable mi-async fail just like they fail on non-async-capable targets. This emulation is exactly the point of the maint option. I had asked Tom in a previous iteration to split the actual change of the target async default to a separate patch, but it turns out that that is quite awkward in this version of the patch, because with MI async and target async decoupled (unlike in previous versions), if we don't flip the default at the same time, then just "set target-async on" alone never actually manages to do anything. It's best to not have that transitory state in the tree. Given "set target-async on" now only has effect for MI, the patch goes through the testsuite removing it from non-MI tests. MI tests are adjusted to use the new and less confusing "mi-async" spelling. 2014-05-29 Pedro Alves <palves@redhat.com> Tom Tromey <tromey@redhat.com> * NEWS: Mention "maint set target-async", "set mi-async", and that background execution commands are now always available. * target.h (target_async_permitted): Update comment. * target.c (target_async_permitted, target_async_permitted_1): Default to 1. (set_target_async_command): Rename to ... (maint_set_target_async_command): ... this. (show_target_async_command): Rename to ... (maint_show_target_async_command): ... this. (_initialize_target): Adjust. * infcmd.c (prepare_execution_command): Make extern. * inferior.h (prepare_execution_command): Declare. * infrun.c (set_observer_mode): Leave target async alone. * mi/mi-interp.c (mi_interpreter_init): Install mi_on_sync_execution_done as sync_execution_done observer. (mi_on_sync_execution_done): New function. (mi_execute_command_input_handler): Don't print the prompt if we just started a synchronous command with an async target. (mi_on_resume): Check sync_execution before printing prompt. * mi/mi-main.h (mi_async_p): Declare. * mi/mi-main.c: Include gdbcmd.h. (mi_async_p): New function. (mi_async, mi_async_1): New globals. (set_mi_async_command, show_mi_async_command, mi_async): New functions. (exec_continue): Call prepare_execution_command. (run_one_inferior, mi_cmd_exec_run, mi_cmd_list_target_features) (mi_execute_async_cli_command): Use mi_async_p. (_initialize_mi_main): Install "set mi-async". Make "target-async" a deprecated alias. 2014-05-29 Pedro Alves <palves@redhat.com> Tom Tromey <tromey@redhat.com> * gdb.texinfo (Non-Stop Mode): Remove "set target-async 1" from example. (Asynchronous and non-stop modes): Document '-gdb-set mi-async'. Mention that target-async is now deprecated. (Maintenance Commands): Document maint set/show target-async. 2014-05-29 Pedro Alves <palves@redhat.com> Tom Tromey <tromey@redhat.com> * gdb.base/async-shell.exp: Don't enable target-async. * gdb.base/async.exp * gdb.base/corefile.exp (corefile_test_attach): Remove 'async' parameter. Adjust. (top level): Don't test with "target-async". * gdb.base/dprintf-non-stop.exp: Don't enable target-async. * gdb.base/gdb-sigterm.exp: Don't test with "target-async". * gdb.base/inferior-died.exp: Don't enable target-async. * gdb.base/interrupt-noterm.exp: Likewise. * gdb.mi/mi-async.exp: Use "mi-async" instead of "target-async". * gdb.mi/mi-nonstop-exit.exp: Likewise. * gdb.mi/mi-nonstop.exp: Likewise. * gdb.mi/mi-ns-stale-regcache.exp: Likewise. * gdb.mi/mi-nsintrall.exp: Likewise. * gdb.mi/mi-nsmoribund.exp: Likewise. * gdb.mi/mi-nsthrexec.exp: Likewise. * gdb.mi/mi-watch-nonstop.exp: Likewise. * gdb.multi/watchpoint-multi.exp: Adjust comment. * gdb.python/py-evsignal.exp: Don't enable target-async. * gdb.python/py-evthreads.exp: Likewise. * gdb.python/py-prompt.exp: Likewise. * gdb.reverse/break-precsave.exp: Don't test with "target-async". * gdb.server/solib-list.exp: Don't enable target-async. * gdb.threads/thread-specific-bp.exp: Likewise. * lib/mi-support.exp: Adjust to use mi-async.
2014-05-29 20:58:57 +02:00
/* Prepare for execution command. TARGET is the target that will run
the command. BACKGROUND determines whether this is a foreground
(synchronous) or background (asynchronous) command. */
extern void prepare_execution_command (struct target_ops *target,
int background);
/* Nonzero if stopped due to completion of a stack dummy routine. */
2010-03-25 21:48:53 +01:00
extern enum stop_stack_kind stop_stack_dummy;
/* Nonzero if program stopped due to a random (unexpected) signal in
inferior process. */
extern int stopped_by_random_signal;
Enable 'set print inferior-events' and improve detach/fork/kill/exit messages This patch aims to turn 'set print inferior-events' always on, and do some cleanup on the messages printed by GDB when various inferior events happen (attach, detach, fork, kill, exit). To make sure that the patch is correct, I've tested it with a handful of combinations of 'set follow-fork-mode', 'set detach-on-fork' and 'set print inferior-events'. In the end, I decided to make my hand-made test into an official testcase. More on that below. Using the following program as an example: #include <unistd.h> int main () { fork (); return 0; } We see the following outputs from the patched GDB: - With 'set print inferior-events on': (gdb) r Starting program: a.out [Detaching after fork from child process 27749] [Inferior 1 (process 27745) exited normally] (gdb) - With 'set print inferior-events off': (gdb) r Starting program: a.out [Inferior 1 (process 27823) exited normally] (gdb) Comparing this against an unpatched GDB: - With 'set print inferior-events off' and 'set follow-fork-mode child': (gdb) r Starting program: a.out [Inferior 2 (process 5993) exited normally] (gdb) Compare this against an unpatched GDB: (unpatched-gdb) r Starting program: a.out [New process 5702] [Inferior 2 (process 5702) exited normally] (unpatched-gdb) It is possible to notice that, in this scenario, the patched GDB will lose the '[New process %d]' message. - With 'set print inferior-events on', 'set follow-fork-mode child' and 'set detach-on-fork on': (gdb) r Starting program: a.out [Attaching after process 27905 fork to child process 27909] [New inferior 2 (process 27909)] [Detaching after fork from parent process 27905] [Inferior 1 (process 27905) detached] [Inferior 2 (process 27909) exited normally] (gdb) Compare this output with an unpatched GDB, using the same settings: (unpatched-gdb) r Starting program: a.out [New inferior 28033] [Inferior 28029 detached] [New process 28033] [Inferior 2 (process 28033) exited normally] [Inferior 28033 exited] (unpatched-gdb) As can be seen above, I've also made a few modifications to messages that are printed when 'set print inferior-events' is on. For example, a few of the messages did not contain the '[' and ']' as prefix/suffix, which led to a few inconsistencies like: Attaching after process 22995 fork to child process 22999. [New inferior 22999] Detaching after fork from child process 22999. [Inferior 22995 detached] [Inferior 2 (process 22999) exited normally] So I took the opportunity and included the square brackets where applicable. I have also made the existing messages more uniform, by always printing "Inferior %d (process %d)..." where applicable. This makes it easier to identify the inferior number and the PID number from the messages. As suggested by Pedro, the "[Inferior %d exited]" message from 'exit_inferior' has been removed, because it got duplicated when 'inferior-events' is on. I'm also using the 'add_{thread,inferior}_silent' versions (instead of their verbose counterparts) on some locations, also to avoid duplicated messages. For example, a patched GDB with 'set print inferior-events on', 'set detach-on-fork on' and 'set follow-fork-mode child', but using 'add_thread', would print: (gdb) run Starting program: a.out [Attaching after process 25088 fork to child process 25092.] [New inferior 25092] <--- duplicated [Detaching after fork from child process 25092.] [Inferior 25088 detached] [New process 25092] <--- duplicated [Inferior 2 (process 25092) exited normally] But if we use 'add_thread_silent' (with the same configuration as before): (gdb) run Starting program: a.out [Attaching after process 31606 fork to child process 31610] [New inferior 2 (process 31610)] [Detaching after fork from parent process 31606] [Inferior 1 (process 31606) detached] [Inferior 2 (process 31610) exited normally] As for the tests, the configuration options being exercised are: - follow-fork-mode: child/parent - detach-on-fork: on/off - print inferior-events: on/off It was also necessary to perform adjustments on several testcases, because the expected messages changed considerably. Built and regtested on BuildBot, without regressions. gdb/ChangeLog: 2018-04-24 Jan Kratochvil <jan.kratochvil@redhat.com> Sergio Durigan Junior <sergiodj@redhat.com> Pedro Alves <palves@redhat.com> * infcmd.c (kill_command): Print message when inferior has been killed. * inferior.c (print_inferior_events): Remove 'static'. Set as '1'. (add_inferior): Improve message printed when 'print_inferior_events' is on. (exit_inferior): Remove message printed when 'print_inferior_events' is on. (detach_inferior): Improve message printed when 'print_inferior_events' is on. (initialize_inferiors): Use 'add_inferior_silent' to set 'current_inferior_'. * inferior.h (print_inferior_events): Declare here as 'extern'. * infrun.c (follow_fork_inferior): Print '[Attaching...]' or '[Detaching...]' messages when 'print_inferior_events' is on. Use 'add_thread_silent' instead of 'add_thread'. Add '[' and ']' as prefix/suffix for messages. Remove periods. Fix erroneous 'Detaching after fork from child...', replace it by '... from parent...'. (handle_vfork_child_exec_or_exit): Add '[' and ']' as prefix/suffix when printing 'Detaching...' messages. Print them when 'print_inferior_events' is on. * remote.c (remote_detach_1): Print message when detaching from inferior and '!is_fork_parent'. gdb/testsuite/ChangeLog: 2018-04-24 Jan Kratochvil <jan.kratochvil@redhat.com> Sergio Durigan Junior <sergiodj@redhat.com> Pedro Alves <palves@redhat.com> * gdb.base/attach-non-pgrp-leader.exp: Adjust 'Detaching...' regexps to expect for '[Inferior ... detached]' as well. * gdb.base/attach.exp: Likewise. * gdb.base/catch-syscall.exp (check_for_program_end): Adjust "gdb_continue_to_end". (test_catch_syscall_with_wrong_args): Likewise. * gdb.base/foll-fork.exp: Adjust regexps to match '[' and ']'. Don't set 'verbose' on. * gdb.base/foll-vfork.exp: Likewise. * gdb.base/fork-print-inferior-events.c: New file. * gdb.base/fork-print-inferior-events.exp: New file. * gdb.base/hook-stop.exp: Adjust regexps to expect for new '[Inferior ... has been killed]' message. * gdb.base/kill-after-signal.exp: Likewise. * gdb.base/solib-overlap.exp: Adjust regexps to expect for new detach message. * gdb.threads/kill.exp: Adjust regexps to expect for new kill message. * gdb.threads/clone-attach-detach.exp: Adjust 'Detaching...' regexps to expect for '[Inferior ... detached]' as well. * gdb.threads/process-dies-while-detaching.exp: Likewise.
2018-01-31 01:09:42 +01:00
/* Print notices on inferior events (attach, detach, etc.), set with
`set print inferior-events'. */
Change boolean options to bool instead of int This is for add_setshow_boolean_cmd as well as the gdb::option interface. gdb/ChangeLog: 2019-09-17 Christian Biesinger <cbiesinger@google.com> * ada-lang.c (ada_ignore_descriptive_types_p): Change to bool. (print_signatures): Likewise. (trust_pad_over_xvs): Likewise. * arch/aarch64-insn.c (aarch64_debug): Likewise. * arch/aarch64-insn.h (aarch64_debug): Likewise. * arm-linux-nat.c (arm_apcs_32): Likewise. * arm-linux-tdep.c (arm_apcs_32): Likewise. * arm-nbsd-nat.c (arm_apcs_32): Likewise. * arm-tdep.c (arm_debug): Likewise. (arm_apcs_32): Likewise. * auto-load.c (debug_auto_load): Likewise. (auto_load_gdb_scripts): Likewise. (global_auto_load): Likewise. (auto_load_local_gdbinit): Likewise. (auto_load_local_gdbinit_loaded): Likewise. * auto-load.h (global_auto_load): Likewise. (auto_load_local_gdbinit): Likewise. (auto_load_local_gdbinit_loaded): Likewise. * breakpoint.c (disconnected_dprintf): Likewise. (breakpoint_proceeded): Likewise. (automatic_hardware_breakpoints): Likewise. (always_inserted_mode): Likewise. (target_exact_watchpoints): Likewise. (_initialize_breakpoint): Update. * breakpoint.h (target_exact_watchpoints): Change to bool. * btrace.c (maint_btrace_pt_skip_pad): Likewise. * cli/cli-cmds.c (trace_commands): Likewise. * cli/cli-cmds.h (trace_commands): Likewise. * cli/cli-decode.c (add_setshow_boolean_cmd): Change int* argument to bool*. * cli/cli-logging.c (logging_overwrite): Change to bool. (logging_redirect): Likewise. (debug_redirect): Likewise. * cli/cli-option.h (option_def) <boolean>: Change return type to bool*. (struct boolean_option_def) <get_var_address_cb_>: Change return type to bool. <boolean_option_def>: Update. (struct flag_option_def): Change default type of Context to bool from int. <flag_option_def>: Change return type of var_address_cb_ to bool*. * cli/cli-setshow.c (do_set_command): Cast to bool* instead of int*. (get_setshow_command_value_string): Likewise. * cli/cli-style.c (cli_styling): Change to bool. (source_styling): Likewise. * cli/cli-style.h (source_styling): Likewise. (cli_styling): Likewise. * cli/cli-utils.h (struct qcs_flags) <quiet, cont, silent>: Change to bool. * command.h (var_types): Update comment. (add_setshow_boolean_cmd): Change int* var argument to bool*. * compile/compile-cplus-types.c (debug_compile_cplus_types): Change to bool. (debug_compile_cplus_scopes): Likewise. * compile/compile-internal.h (compile_debug): Likewise. * compile/compile.c (compile_debug): Likewise. (struct compile_options) <raw>: Likewise. * cp-support.c (catch_demangler_crashes): Likewise. * cris-tdep.c (usr_cmd_cris_version_valid): Likewise. (usr_cmd_cris_dwarf2_cfi): Likewise. * csky-tdep.c (csky_debug): Likewise. * darwin-nat.c (enable_mach_exceptions): Likewise. * dcache.c (dcache_enabled_p): Likewise. * defs.h (info_verbose): Likewise. * demangle.c (demangle): Likewise. (asm_demangle): Likewise. * dwarf-index-cache.c (debug_index_cache): Likewise. * dwarf2-frame.c (dwarf2_frame_unwinders_enabled_p): Likewise. * dwarf2-frame.h (dwarf2_frame_unwinders_enabled_p): Likewise. * dwarf2read.c (check_physname): Likewise. (use_deprecated_index_sections): Likewise. (dwarf_always_disassemble): Likewise. * eval.c (overload_resolution): Likewise. * event-top.c (set_editing_cmd_var): Likewise. (exec_done_display_p): Likewise. * event-top.h (set_editing_cmd_var): Likewise. (exec_done_display_p): Likewise. * exec.c (write_files): Likewise. * fbsd-nat.c (debug_fbsd_lwp): Likewise (debug_fbsd_nat): Likewise. * frame.h (struct frame_print_options) <print_raw_frame_arguments>: Likewise. (struct set_backtrace_options) <backtrace_past_main>: Likewise. <backtrace_past_entry> Likewise. * gdb-demangle.h (demangle): Likewise. (asm_demangle): Likewise. * gdb_bfd.c (bfd_sharing): Likewise. * gdbcore.h (write_files): Likewise. * gdbsupport/common-debug.c (show_debug_regs): Likewise. * gdbsupport/common-debug.h (show_debug_regs): Likewise. * gdbthread.h (print_thread_events): Likewise. * gdbtypes.c (opaque_type_resolution): Likewise. (strict_type_checking): Likewise. * gnu-nat.c (gnu_debug_flag): Likewise. * guile/scm-auto-load.c (auto_load_guile_scripts): Likewise. * guile/scm-param.c (pascm_variable): Add boolval. (add_setshow_generic): Update. (pascm_param_value): Update. (pascm_set_param_value_x): Update. * hppa-tdep.c (hppa_debug): Change to bool.. * infcall.c (may_call_functions_p): Likewise. (coerce_float_to_double_p): Likewise. (unwind_on_signal_p): Likewise. (unwind_on_terminating_exception_p): Likewise. * infcmd.c (startup_with_shell): Likewise. * inferior.c (print_inferior_events): Likewise. * inferior.h (startup_with_shell): Likewise. (print_inferior_events): Likewise. * infrun.c (step_stop_if_no_debug): Likewise. (detach_fork): Likewise. (debug_displaced): Likewise. (disable_randomization): Likewise. (non_stop): Likewise. (non_stop_1): Likewise. (observer_mode): Likewise. (observer_mode_1): Likewise. (set_observer_mode): Update. (sched_multi): Change to bool. * infrun.h (debug_displaced): Likewise. (sched_multi): Likewise. (step_stop_if_no_debug): Likewise. (non_stop): Likewise. (disable_randomization): Likewise. * linux-tdep.c (use_coredump_filter): Likewise. (dump_excluded_mappings): Likewise. * linux-thread-db.c (auto_load_thread_db): Likewise. (check_thread_db_on_load): Likewise. * main.c (captured_main_1): Update. * maint-test-options.c (struct test_options_opts) <flag_opt, xx1_opt, xx2_opt, boolean_opt>: Change to bool. * maint-test-settings.c (maintenance_test_settings_boolean): Likewise. * maint.c (maintenance_profile_p): Likewise. (per_command_time): Likewise. (per_command_space): Likewise. (per_command_symtab): Likewise. * memattr.c (inaccessible_by_default): Likewise. * mi/mi-main.c (mi_async): Likewise. (mi_async_1): Likewise. * mips-tdep.c (mips64_transfers_32bit_regs_p): Likewise. * nat/fork-inferior.h (startup_with_shell): Likewise. * nat/linux-namespaces.c (debug_linux_namespaces): Likewise. * nat/linux-namespaces.h (debug_linux_namespaces): Likewise. * nios2-tdep.c (nios2_debug): Likewise. * or1k-tdep.c (or1k_debug): Likewise. * parse.c (parser_debug): Likewise. * parser-defs.h (parser_debug): Likewise. * printcmd.c (print_symbol_filename): Likewise. * proc-api.c (procfs_trace): Likewise. * python/py-auto-load.c (auto_load_python_scripts): Likewise. * python/py-param.c (union parmpy_variable): Add "bool boolval" field. (set_parameter_value): Update. (add_setshow_generic): Update. * python/py-value.c (copy_py_bool_obj): Change argument from int* to bool*. * python/python.c (gdbpy_parameter_value): Cast to bool* instead of int*. * ravenscar-thread.c (ravenscar_task_support): Change to bool. * record-btrace.c (record_btrace_target::store_registers): Update. * record-full.c (record_full_memory_query): Change to bool. (record_full_stop_at_limit): Likewise. * record-full.h (record_full_memory_query): Likewise. * remote-notif.c (notif_debug): Likewise. * remote-notif.h (notif_debug): Likewise. * remote.c (use_range_stepping): Likewise. (interrupt_on_connect): Likewise. (remote_break): Likewise. * ser-tcp.c (tcp_auto_retry): Likewise. * ser-unix.c (serial_hwflow): Likewise. * skip.c (debug_skip): Likewise. * solib-aix.c (solib_aix_debug): Likewise. * spu-tdep.c (spu_stop_on_load_p): Likewise. (spu_auto_flush_cache_p): Likewise. * stack.c (struct backtrace_cmd_options) <full, no_filters, hide>: Likewise. (struct info_print_options) <quiet>: Likewise. * symfile-debug.c (debug_symfile): Likewise. * symfile.c (auto_solib_add): Likewise. (separate_debug_file_debug): Likewise. * symfile.h (auto_solib_add): Likewise. (separate_debug_file_debug): Likewise. * symtab.c (basenames_may_differ): Likewise. (struct filename_partial_match_opts) <dirname, basename>: Likewise. (struct info_print_options) <quiet, exclude_minsyms>: Likewise. (struct info_types_options) <quiet>: Likewise. * symtab.h (demangle): Likewise. (basenames_may_differ): Likewise. * target-dcache.c (stack_cache_enabled_1): Likewise. (code_cache_enabled_1): Likewise. * target.c (trust_readonly): Likewise. (may_write_registers): Likewise. (may_write_memory): Likewise. (may_insert_breakpoints): Likewise. (may_insert_tracepoints): Likewise. (may_insert_fast_tracepoints): Likewise. (may_stop): Likewise. (auto_connect_native_target): Likewise. (target_stop_and_wait): Update. (target_async_permitted): Change to bool. (target_async_permitted_1): Likewise. (may_write_registers_1): Likewise. (may_write_memory_1): Likewise. (may_insert_breakpoints_1): Likewise. (may_insert_tracepoints_1): Likewise. (may_insert_fast_tracepoints_1): Likewise. (may_stop_1): Likewise. * target.h (target_async_permitted): Likewise. (may_write_registers): Likewise. (may_write_memory): Likewise. (may_insert_breakpoints): Likewise. (may_insert_tracepoints): Likewise. (may_insert_fast_tracepoints): Likewise. (may_stop): Likewise. * thread.c (struct info_threads_opts) <show_global_ids>: Likewise. (make_thread_apply_all_options_def_group): Change argument from int* to bool*. (thread_apply_all_command): Update. (print_thread_events): Change to bool. * top.c (confirm): Likewise. (command_editing_p): Likewise. (history_expansion_p): Likewise. (write_history_p): Likewise. (info_verbose): Likewise. * top.h (confirm): Likewise. (history_expansion_p): Likewise. * tracepoint.c (disconnected_tracing): Likewise. (circular_trace_buffer): Likewise. * typeprint.c (print_methods): Likewise. (print_typedefs): Likewise. * utils.c (debug_timestamp): Likewise. (sevenbit_strings): Likewise. (pagination_enabled): Likewise. * utils.h (sevenbit_strings): Likewise. (pagination_enabled): Likewise. * valops.c (overload_resolution): Likewise. * valprint.h (struct value_print_options) <prettyformat_arrays, prettyformat_structs, vtblprint, unionprint, addressprint, objectprint, stop_print_at_null, print_array_indexes, deref_ref, static_field_print, pascal_static_field_print, raw, summary, symbol_print, finish_print>: Likewise. * windows-nat.c (new_console): Likewise. (cygwin_exceptions): Likewise. (new_group): Likewise. (debug_exec): Likewise. (debug_events): Likewise. (debug_memory): Likewise. (debug_exceptions): Likewise. (useshell): Likewise. * windows-tdep.c (maint_display_all_tib): Likewise. * xml-support.c (debug_xml): Likewise.
2019-09-14 21:36:58 +02:00
extern bool print_inferior_events;
Enable 'set print inferior-events' and improve detach/fork/kill/exit messages This patch aims to turn 'set print inferior-events' always on, and do some cleanup on the messages printed by GDB when various inferior events happen (attach, detach, fork, kill, exit). To make sure that the patch is correct, I've tested it with a handful of combinations of 'set follow-fork-mode', 'set detach-on-fork' and 'set print inferior-events'. In the end, I decided to make my hand-made test into an official testcase. More on that below. Using the following program as an example: #include <unistd.h> int main () { fork (); return 0; } We see the following outputs from the patched GDB: - With 'set print inferior-events on': (gdb) r Starting program: a.out [Detaching after fork from child process 27749] [Inferior 1 (process 27745) exited normally] (gdb) - With 'set print inferior-events off': (gdb) r Starting program: a.out [Inferior 1 (process 27823) exited normally] (gdb) Comparing this against an unpatched GDB: - With 'set print inferior-events off' and 'set follow-fork-mode child': (gdb) r Starting program: a.out [Inferior 2 (process 5993) exited normally] (gdb) Compare this against an unpatched GDB: (unpatched-gdb) r Starting program: a.out [New process 5702] [Inferior 2 (process 5702) exited normally] (unpatched-gdb) It is possible to notice that, in this scenario, the patched GDB will lose the '[New process %d]' message. - With 'set print inferior-events on', 'set follow-fork-mode child' and 'set detach-on-fork on': (gdb) r Starting program: a.out [Attaching after process 27905 fork to child process 27909] [New inferior 2 (process 27909)] [Detaching after fork from parent process 27905] [Inferior 1 (process 27905) detached] [Inferior 2 (process 27909) exited normally] (gdb) Compare this output with an unpatched GDB, using the same settings: (unpatched-gdb) r Starting program: a.out [New inferior 28033] [Inferior 28029 detached] [New process 28033] [Inferior 2 (process 28033) exited normally] [Inferior 28033 exited] (unpatched-gdb) As can be seen above, I've also made a few modifications to messages that are printed when 'set print inferior-events' is on. For example, a few of the messages did not contain the '[' and ']' as prefix/suffix, which led to a few inconsistencies like: Attaching after process 22995 fork to child process 22999. [New inferior 22999] Detaching after fork from child process 22999. [Inferior 22995 detached] [Inferior 2 (process 22999) exited normally] So I took the opportunity and included the square brackets where applicable. I have also made the existing messages more uniform, by always printing "Inferior %d (process %d)..." where applicable. This makes it easier to identify the inferior number and the PID number from the messages. As suggested by Pedro, the "[Inferior %d exited]" message from 'exit_inferior' has been removed, because it got duplicated when 'inferior-events' is on. I'm also using the 'add_{thread,inferior}_silent' versions (instead of their verbose counterparts) on some locations, also to avoid duplicated messages. For example, a patched GDB with 'set print inferior-events on', 'set detach-on-fork on' and 'set follow-fork-mode child', but using 'add_thread', would print: (gdb) run Starting program: a.out [Attaching after process 25088 fork to child process 25092.] [New inferior 25092] <--- duplicated [Detaching after fork from child process 25092.] [Inferior 25088 detached] [New process 25092] <--- duplicated [Inferior 2 (process 25092) exited normally] But if we use 'add_thread_silent' (with the same configuration as before): (gdb) run Starting program: a.out [Attaching after process 31606 fork to child process 31610] [New inferior 2 (process 31610)] [Detaching after fork from parent process 31606] [Inferior 1 (process 31606) detached] [Inferior 2 (process 31610) exited normally] As for the tests, the configuration options being exercised are: - follow-fork-mode: child/parent - detach-on-fork: on/off - print inferior-events: on/off It was also necessary to perform adjustments on several testcases, because the expected messages changed considerably. Built and regtested on BuildBot, without regressions. gdb/ChangeLog: 2018-04-24 Jan Kratochvil <jan.kratochvil@redhat.com> Sergio Durigan Junior <sergiodj@redhat.com> Pedro Alves <palves@redhat.com> * infcmd.c (kill_command): Print message when inferior has been killed. * inferior.c (print_inferior_events): Remove 'static'. Set as '1'. (add_inferior): Improve message printed when 'print_inferior_events' is on. (exit_inferior): Remove message printed when 'print_inferior_events' is on. (detach_inferior): Improve message printed when 'print_inferior_events' is on. (initialize_inferiors): Use 'add_inferior_silent' to set 'current_inferior_'. * inferior.h (print_inferior_events): Declare here as 'extern'. * infrun.c (follow_fork_inferior): Print '[Attaching...]' or '[Detaching...]' messages when 'print_inferior_events' is on. Use 'add_thread_silent' instead of 'add_thread'. Add '[' and ']' as prefix/suffix for messages. Remove periods. Fix erroneous 'Detaching after fork from child...', replace it by '... from parent...'. (handle_vfork_child_exec_or_exit): Add '[' and ']' as prefix/suffix when printing 'Detaching...' messages. Print them when 'print_inferior_events' is on. * remote.c (remote_detach_1): Print message when detaching from inferior and '!is_fork_parent'. gdb/testsuite/ChangeLog: 2018-04-24 Jan Kratochvil <jan.kratochvil@redhat.com> Sergio Durigan Junior <sergiodj@redhat.com> Pedro Alves <palves@redhat.com> * gdb.base/attach-non-pgrp-leader.exp: Adjust 'Detaching...' regexps to expect for '[Inferior ... detached]' as well. * gdb.base/attach.exp: Likewise. * gdb.base/catch-syscall.exp (check_for_program_end): Adjust "gdb_continue_to_end". (test_catch_syscall_with_wrong_args): Likewise. * gdb.base/foll-fork.exp: Adjust regexps to match '[' and ']'. Don't set 'verbose' on. * gdb.base/foll-vfork.exp: Likewise. * gdb.base/fork-print-inferior-events.c: New file. * gdb.base/fork-print-inferior-events.exp: New file. * gdb.base/hook-stop.exp: Adjust regexps to expect for new '[Inferior ... has been killed]' message. * gdb.base/kill-after-signal.exp: Likewise. * gdb.base/solib-overlap.exp: Adjust regexps to expect for new detach message. * gdb.threads/kill.exp: Adjust regexps to expect for new kill message. * gdb.threads/clone-attach-detach.exp: Adjust 'Detaching...' regexps to expect for '[Inferior ... detached]' as well. * gdb.threads/process-dies-while-detaching.exp: Likewise.
2018-01-31 01:09:42 +01:00
/* Anything but NO_STOP_QUIETLY means we expect a trap and the caller
will handle it themselves. STOP_QUIETLY is used when running in
the shell before the child program has been exec'd and when running
through shared library loading. STOP_QUIETLY_REMOTE is used when
setting up a remote connection; it is like STOP_QUIETLY_NO_SIGSTOP
except that there is no need to hide a signal. */
/* STOP_QUIETLY_NO_SIGSTOP is used to handle a tricky situation with attach.
When doing an attach, the kernel stops the debuggee with a SIGSTOP.
On newer GNU/Linux kernels (>= 2.5.61) the handling of SIGSTOP for
a ptraced process has changed. Earlier versions of the kernel
would ignore these SIGSTOPs, while now SIGSTOP is treated like any
other signal, i.e. it is not muffled.
If the gdb user does a 'continue' after the 'attach', gdb passes
the global variable stop_signal (which stores the signal from the
attach, SIGSTOP) to the ptrace(PTRACE_CONT,...) call. This is
problematic, because the kernel doesn't ignore such SIGSTOP
now. I.e. it is reported back to gdb, which in turn presents it
back to the user.
To avoid the problem, we use STOP_QUIETLY_NO_SIGSTOP, which allows
gdb to clear the value of stop_signal after the attach, so that it
is not passed back down to the kernel. */
enum stop_kind
{
NO_STOP_QUIETLY = 0,
STOP_QUIETLY,
STOP_QUIETLY_REMOTE,
STOP_QUIETLY_NO_SIGSTOP
};
/* Possible values for gdbarch_call_dummy_location. */
#define ON_STACK 1
#define AT_ENTRY_POINT 4
Create private_inferior class hierarchy There are currently multiple definitions of private_inferior, defined in remote.c and darwin-nat.h. The patch that poisons XNEW and friends for non-POD types trips on that, because private_inferior is freed in ~inferior(), where it is an opaque type. Since the compiler can't tell whether the type is POD, it gives an error. Also, we can't start using C++ features in these structures (make them non-POD) as long as there are multiple definitions with the same name. For these reasons, this patch makes a class hierarchy, with private_inferior being the abstract base class, and darwin_inferior & remote_inferior inheriting from it. Destruction is done through the virtual destructor. I stumbled on some suspicious code in the darwin implementation though. darwin_check_new_threads does an XCNEW(darwin_thread_t) when it finds a new thread, allocating a new structure for it (darwin_thread_t is a typedef for private_thread_info). It then VEC_safe_pushes it in a vector defined as DEF_VEC_O (a vector of objects). This means that the structure content gets copied in the vector. The thread_info object is created with the XCNEW'ed structure as the private thread info, while the rest of the code works with the instance in the vector. We have therefore two distinct instances of darwin_thread_t/private_thread_info for each thread. This is not really a problem in practice, because thread_info::priv is not used in the darwin code. I still find it weird and far from ideal, so I tried to fix it by changing the vector to be a vector of pointers. There should now be a single instance of the structure for each thread. The deallocation of the darwin_thread_t/private_thread_info structure is done by the thread_info destructor. I am able to build on macOS, but not really test, since the port seems a bit broken. I am not able to debug reliably on the machine I have access to, which runs macOS 10.12.6. gdb/ChangeLog: * inferior.h (private_inferior): Define structure type, add virtual pure destructor. (inferior) <priv>: Change type to unique_ptr. * inferior.c (private_inferior::~private_inferior): Provide default implementation. (inferior::~inferior): Don't free priv field. (exit_inferior_1): Likewise. * darwin-nat.h (struct darwin_exception_info): Initialize fields. (darwin_exception_info): Remove typedef. (DEF_VEC_O (darwin_thread_t)); Remove. (private_inferior): Rename to ... (darwin_private_inferior): ... this, extend private_inferior. (get_darwin_inferior): New. <threads>: Change type to std::vector of darwin_thread_t pointers. * darwin-nat.c (darwin_check_new_threads): Adjust. (find_inferior_task_it): Adjust. (darwin_find_thread); Adjust. (darwin_suspend_inferior): Adjust. (darwin_resume_inferior): Adjust. (darwin_find_new_inferior): Adjust. (darwin_decode_notify_message): Adjust. (darwin_send_reply): Adjust. (darwin_resume_inferior_threads): Adjust. (darwin_suspend_inferior_threads): Adjust. (darwin_decode_message): Adjust. (darwin_wait): Adjust. (darwin_interrupt): Adjust. (darwin_deallocate_threads): Adjust. (darwin_mourn_inferior): Adjust, don't free private data. (darwin_reply_to_all_pending_messages): Adjust. (darwin_stop_inferior): Adjust. (darwin_setup_exceptions): Adjust. (darwin_kill_inferior): Adjust. (darwin_setup_request_notification): Adjust. (darwin_attach_pid): Adjust. (darwin_init_thread_list): Adjust. (darwin_setup_fake_stop_event): Adjust. (darwin_attach): Adjust. (darwin_detach): Adjust. (darwin_xfer_partial): Adjust. (set_enable_mach_exceptions): Adjust. (darwin_pid_to_exec_file): Adjust. (darwin_get_ada_task_ptid): Adjust. * darwin-nat-info.c (get_task_from_args): Adjust. (info_mach_ports_command): Adjust. (info_mach_region_command): Adjust. (info_mach_exceptions_command): Adjust. * remote.c (private_inferior): Rename to ... (remote_private_inferior): ... this, initialize fields. (get_remote_inferior); New. (remote_commit_resume): Use get_remote_inferior. (check_pending_event_prevents_wildcard_vcont_callback): Likewise.
2017-11-24 16:39:30 +01:00
/* Base class for target-specific inferior data. */
struct private_inferior
{
virtual ~private_inferior () = 0;
};
gdb/ Rename and move inferior_thread_state and inferior_status. * gdbthread.h (struct thread_control_state): New struct, move fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step and stop_bpstat here from struct thread_info. (struct thread_suspend_state): New struct, move field stop_signal here from struct thread_info. (struct thread_info): Move the fields above from this struct. * inferior.h: Move the inferior_thread_state and inferior_status declarations comment to their definitions at infrun.c. (struct inferior_control_state): New struct, move field stop_soon from struct inferior here. (struct inferior_suspend_state): New empty struct. (struct inferior): New fields control and suspend. Move out field stop_soon. * infrun.c (struct inferior_thread_state): Rename to ... (infcall_suspend_state): ... here. Replace field stop_signal by fields thread_suspend and inferior_suspend. (save_inferior_thread_state): Rename to ... (save_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (restore_inferior_thread_state): Rename to ... (restore_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (do_restore_inferior_thread_state_cleanup): Rename to ... (do_restore_infcall_suspend_state_cleanup): ... here. (make_cleanup_restore_inferior_thread_state): Rename to ... (make_cleanup_restore_infcall_suspend_state): ... here. (discard_inferior_thread_state): Rename to ... (discard_infcall_suspend_state): ... here. (get_inferior_thread_state_regcache): Rename to ... (get_infcall_suspend_state_regcache): ... here. (struct inferior_status): Rename to ... (struct infcall_control_state): ... here. Replace fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step, stop_bpstat and stop_soon by fields thread_control and inferior_control. (save_inferior_status): Rename to ... (save_infcall_control_state): ... here. Update the code for new fields. (restore_inferior_status): Rename to ... (restore_infcall_control_state): ... here. Update the code for new fields. (do_restore_inferior_status_cleanup): Rename to ... (do_restore_infcall_control_state_cleanup): ... here. (make_cleanup_restore_inferior_status): Rename to ... (make_cleanup_restore_infcall_control_state): ... here. (discard_inferior_status): Rename to ... (discard_infcall_control_state): ... here. * alpha-tdep.c, breakpoint.c, dummy-frame.c, dummy-frame.h, exceptions.c, fbsd-nat.c, gdbthread.h, infcall.c, infcmd.c, inferior.c, inferior.h, infrun.c, linux-nat.c, mi/mi-interp.c, mips-tdep.c, procfs.c, solib-irix.c, solib-osf.c, solib-spu.c, solib-sunos.c, solib-svr4.c, thread.c, windows-nat.c: Update all the references to the moved fields and renamed functions.
2010-11-28 05:31:25 +01:00
/* Inferior process specific part of `struct infcall_control_state'.
Inferior thread counterpart is `struct thread_control_state'. */
struct inferior_control_state
{
inferior_control_state ()
: stop_soon (NO_STOP_QUIETLY)
{
}
explicit inferior_control_state (enum stop_kind when)
: stop_soon (when)
{
}
gdb/ Rename and move inferior_thread_state and inferior_status. * gdbthread.h (struct thread_control_state): New struct, move fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step and stop_bpstat here from struct thread_info. (struct thread_suspend_state): New struct, move field stop_signal here from struct thread_info. (struct thread_info): Move the fields above from this struct. * inferior.h: Move the inferior_thread_state and inferior_status declarations comment to their definitions at infrun.c. (struct inferior_control_state): New struct, move field stop_soon from struct inferior here. (struct inferior_suspend_state): New empty struct. (struct inferior): New fields control and suspend. Move out field stop_soon. * infrun.c (struct inferior_thread_state): Rename to ... (infcall_suspend_state): ... here. Replace field stop_signal by fields thread_suspend and inferior_suspend. (save_inferior_thread_state): Rename to ... (save_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (restore_inferior_thread_state): Rename to ... (restore_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (do_restore_inferior_thread_state_cleanup): Rename to ... (do_restore_infcall_suspend_state_cleanup): ... here. (make_cleanup_restore_inferior_thread_state): Rename to ... (make_cleanup_restore_infcall_suspend_state): ... here. (discard_inferior_thread_state): Rename to ... (discard_infcall_suspend_state): ... here. (get_inferior_thread_state_regcache): Rename to ... (get_infcall_suspend_state_regcache): ... here. (struct inferior_status): Rename to ... (struct infcall_control_state): ... here. Replace fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step, stop_bpstat and stop_soon by fields thread_control and inferior_control. (save_inferior_status): Rename to ... (save_infcall_control_state): ... here. Update the code for new fields. (restore_inferior_status): Rename to ... (restore_infcall_control_state): ... here. Update the code for new fields. (do_restore_inferior_status_cleanup): Rename to ... (do_restore_infcall_control_state_cleanup): ... here. (make_cleanup_restore_inferior_status): Rename to ... (make_cleanup_restore_infcall_control_state): ... here. (discard_inferior_status): Rename to ... (discard_infcall_control_state): ... here. * alpha-tdep.c, breakpoint.c, dummy-frame.c, dummy-frame.h, exceptions.c, fbsd-nat.c, gdbthread.h, infcall.c, infcmd.c, inferior.c, inferior.h, infrun.c, linux-nat.c, mi/mi-interp.c, mips-tdep.c, procfs.c, solib-irix.c, solib-osf.c, solib-spu.c, solib-sunos.c, solib-svr4.c, thread.c, windows-nat.c: Update all the references to the moved fields and renamed functions.
2010-11-28 05:31:25 +01:00
/* See the definition of stop_kind above. */
enum stop_kind stop_soon;
};
Fix removing inferiors from within "thread apply" commands This patch fixes an internal error exposed by a test that does something like: define kill-and-remove kill inferiors 2 remove-inferiors 2 end # Start one inferior. start # Start another inferior. add-inferior 2 inferior 2 start # Kill and remove inferior 1 while inferior 2 is selected. thread apply 1.1 kill-and-remove The internal error looks like this: Thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677)): [Switching to inferior 1 [process 20677] (gdb/testsuite/outputs/gdb.threads/threadapply/threadapply)] [Switching to thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677))] #0 main () at src/gdb/testsuite/gdb.threads/threadapply.c:38 38 for (i = 0; i < NUM; i++) src/gdb/inferior.c:66: internal-error: void set_current_inferior(inferior*): Assertion `inf != NULL' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) FAIL: gdb.threads/threadapply.exp: kill_and_remove_inferior: try kill-and-remove: thread apply 1.1 kill-and-remove (GDB internal error) There are several problems around this area of the code. One is that in do_restore_current_thread_cleanup, we do a look up of inferior by ptid, which can find the wrong inferior if the previously selected inferior exited and some other inferior was started with a reused pid (rare, but still...). The other problem is that the "remove-inferiors" command rejects attempts to remove the current inferior, but when we get to "remove-inferiors" in a "thread apply THR remove-inferiors 2" command, the current inferior is the inferior of thread THR, not the previously selected inferior, so if the previously selected inferior was inferior 2, that command still manages to wipe it, and then gdb restores the old selected inferior, which is now a dangling pointer... So the fix here is: - Make make_cleanup_restore_current_thread store a pointer to the previously selected inferior directly, and use it directly instead of doing ptid look ups. - Add a refcount to inferiors, very similar to thread_info's refcount, that is incremented/decremented by make_cleanup_restore_current_thread, and checked before deleting an inferior. To avoid duplication, a new refcounted_object type is added, that both thread_info and inferior inherit from. gdb/ChangeLog: 2017-04-19 Pedro Alves <palves@redhat.com> * common/refcounted-object.h: New file. * gdbthread.h: Include "common/refcounted-object.h". (thread_info): Inherit from refcounted_object and add comments. (thread_info::incref, thread_info::decref) (thread_info::m_refcount): Delete. (thread_info::deletable): Use the refcounted_object::refcount() method. * inferior.c (current_inferior_): Add comment. (set_current_inferior): Increment/decrement refcounts. (prune_inferiors, remove_inferior_command): Skip inferiors marked not-deletable instead of comparing with the current inferior. (initialize_inferiors): Increment the initial inferior's refcount. * inferior.h (struct inferior): Forward declare. Include "common/refcounted-object.h". (current_inferior, set_current_inferior): Move declaration to before struct inferior's definition, and fix comment. (inferior): Inherit from refcounted_object. Add comments. * thread.c (switch_to_thread_no_regs): Reference the thread's inferior pointer directly instead of doing a ptid lookup. (switch_to_no_thread): New function. (switch_to_thread(thread_info *)): New function, factored out from ... (switch_to_thread(ptid_t)): ... this. (restore_current_thread): Delete. (current_thread_cleanup): Remove 'inf_id' and 'was_removable' fields, and add 'inf' field. (do_restore_current_thread_cleanup): Check whether old->inf is alive instead of looking up an inferior by ptid. Use switch_to_thread and switch_to_no_thread. (restore_current_thread_cleanup_dtor): Use old->inf directly instead of lookup up an inferior by id. Decref the inferior. Don't restore 'removable'. (make_cleanup_restore_current_thread): Same the inferior pointer in old, instead of the inferior number. Incref the inferior. Don't save/clear 'removable'. gdb/testsuite/ChangeLog: 2017-04-19 Pedro Alves <palves@redhat.com> * gdb.threads/threadapply.exp (kill_and_remove_inferior): New procedure. (top level): Call it. * lib/gdb.exp (gdb_define_cmd): New procedure.
2017-04-19 14:12:23 +02:00
/* Return a pointer to the current inferior. */
extern inferior *current_inferior ();
extern void set_current_inferior (inferior *);
/* Switch inferior (and program space) to INF, and switch to no thread
selected. */
extern void switch_to_inferior_no_thread (inferior *inf);
/* GDB represents the state of each program execution with an object
called an inferior. An inferior typically corresponds to a process
but is more general and applies also to targets that do not have a
notion of processes. Each run of an executable creates a new
inferior, as does each attachment to an existing process.
Inferiors have unique internal identifiers that are different from
target process ids. Each inferior may in turn have multiple
Fix removing inferiors from within "thread apply" commands This patch fixes an internal error exposed by a test that does something like: define kill-and-remove kill inferiors 2 remove-inferiors 2 end # Start one inferior. start # Start another inferior. add-inferior 2 inferior 2 start # Kill and remove inferior 1 while inferior 2 is selected. thread apply 1.1 kill-and-remove The internal error looks like this: Thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677)): [Switching to inferior 1 [process 20677] (gdb/testsuite/outputs/gdb.threads/threadapply/threadapply)] [Switching to thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677))] #0 main () at src/gdb/testsuite/gdb.threads/threadapply.c:38 38 for (i = 0; i < NUM; i++) src/gdb/inferior.c:66: internal-error: void set_current_inferior(inferior*): Assertion `inf != NULL' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) FAIL: gdb.threads/threadapply.exp: kill_and_remove_inferior: try kill-and-remove: thread apply 1.1 kill-and-remove (GDB internal error) There are several problems around this area of the code. One is that in do_restore_current_thread_cleanup, we do a look up of inferior by ptid, which can find the wrong inferior if the previously selected inferior exited and some other inferior was started with a reused pid (rare, but still...). The other problem is that the "remove-inferiors" command rejects attempts to remove the current inferior, but when we get to "remove-inferiors" in a "thread apply THR remove-inferiors 2" command, the current inferior is the inferior of thread THR, not the previously selected inferior, so if the previously selected inferior was inferior 2, that command still manages to wipe it, and then gdb restores the old selected inferior, which is now a dangling pointer... So the fix here is: - Make make_cleanup_restore_current_thread store a pointer to the previously selected inferior directly, and use it directly instead of doing ptid look ups. - Add a refcount to inferiors, very similar to thread_info's refcount, that is incremented/decremented by make_cleanup_restore_current_thread, and checked before deleting an inferior. To avoid duplication, a new refcounted_object type is added, that both thread_info and inferior inherit from. gdb/ChangeLog: 2017-04-19 Pedro Alves <palves@redhat.com> * common/refcounted-object.h: New file. * gdbthread.h: Include "common/refcounted-object.h". (thread_info): Inherit from refcounted_object and add comments. (thread_info::incref, thread_info::decref) (thread_info::m_refcount): Delete. (thread_info::deletable): Use the refcounted_object::refcount() method. * inferior.c (current_inferior_): Add comment. (set_current_inferior): Increment/decrement refcounts. (prune_inferiors, remove_inferior_command): Skip inferiors marked not-deletable instead of comparing with the current inferior. (initialize_inferiors): Increment the initial inferior's refcount. * inferior.h (struct inferior): Forward declare. Include "common/refcounted-object.h". (current_inferior, set_current_inferior): Move declaration to before struct inferior's definition, and fix comment. (inferior): Inherit from refcounted_object. Add comments. * thread.c (switch_to_thread_no_regs): Reference the thread's inferior pointer directly instead of doing a ptid lookup. (switch_to_no_thread): New function. (switch_to_thread(thread_info *)): New function, factored out from ... (switch_to_thread(ptid_t)): ... this. (restore_current_thread): Delete. (current_thread_cleanup): Remove 'inf_id' and 'was_removable' fields, and add 'inf' field. (do_restore_current_thread_cleanup): Check whether old->inf is alive instead of looking up an inferior by ptid. Use switch_to_thread and switch_to_no_thread. (restore_current_thread_cleanup_dtor): Use old->inf directly instead of lookup up an inferior by id. Decref the inferior. Don't restore 'removable'. (make_cleanup_restore_current_thread): Same the inferior pointer in old, instead of the inferior number. Incref the inferior. Don't save/clear 'removable'. gdb/testsuite/ChangeLog: 2017-04-19 Pedro Alves <palves@redhat.com> * gdb.threads/threadapply.exp (kill_and_remove_inferior): New procedure. (top level): Call it. * lib/gdb.exp (gdb_define_cmd): New procedure.
2017-04-19 14:12:23 +02:00
threads running in it.
Inferiors are intrusively refcounted objects. Unlike thread
objects, being the user-selected inferior is considered a strong
reference and is thus accounted for in the inferior object's
refcount (see set_current_inferior). When GDB needs to remember
the selected inferior to later restore it, GDB temporarily bumps
the inferior object's refcount, to prevent something deleting the
inferior object before reverting back (e.g., due to a
"remove-inferiors" command (see
scoped_restore_current_inferior). All other inferior
Fix removing inferiors from within "thread apply" commands This patch fixes an internal error exposed by a test that does something like: define kill-and-remove kill inferiors 2 remove-inferiors 2 end # Start one inferior. start # Start another inferior. add-inferior 2 inferior 2 start # Kill and remove inferior 1 while inferior 2 is selected. thread apply 1.1 kill-and-remove The internal error looks like this: Thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677)): [Switching to inferior 1 [process 20677] (gdb/testsuite/outputs/gdb.threads/threadapply/threadapply)] [Switching to thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677))] #0 main () at src/gdb/testsuite/gdb.threads/threadapply.c:38 38 for (i = 0; i < NUM; i++) src/gdb/inferior.c:66: internal-error: void set_current_inferior(inferior*): Assertion `inf != NULL' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) FAIL: gdb.threads/threadapply.exp: kill_and_remove_inferior: try kill-and-remove: thread apply 1.1 kill-and-remove (GDB internal error) There are several problems around this area of the code. One is that in do_restore_current_thread_cleanup, we do a look up of inferior by ptid, which can find the wrong inferior if the previously selected inferior exited and some other inferior was started with a reused pid (rare, but still...). The other problem is that the "remove-inferiors" command rejects attempts to remove the current inferior, but when we get to "remove-inferiors" in a "thread apply THR remove-inferiors 2" command, the current inferior is the inferior of thread THR, not the previously selected inferior, so if the previously selected inferior was inferior 2, that command still manages to wipe it, and then gdb restores the old selected inferior, which is now a dangling pointer... So the fix here is: - Make make_cleanup_restore_current_thread store a pointer to the previously selected inferior directly, and use it directly instead of doing ptid look ups. - Add a refcount to inferiors, very similar to thread_info's refcount, that is incremented/decremented by make_cleanup_restore_current_thread, and checked before deleting an inferior. To avoid duplication, a new refcounted_object type is added, that both thread_info and inferior inherit from. gdb/ChangeLog: 2017-04-19 Pedro Alves <palves@redhat.com> * common/refcounted-object.h: New file. * gdbthread.h: Include "common/refcounted-object.h". (thread_info): Inherit from refcounted_object and add comments. (thread_info::incref, thread_info::decref) (thread_info::m_refcount): Delete. (thread_info::deletable): Use the refcounted_object::refcount() method. * inferior.c (current_inferior_): Add comment. (set_current_inferior): Increment/decrement refcounts. (prune_inferiors, remove_inferior_command): Skip inferiors marked not-deletable instead of comparing with the current inferior. (initialize_inferiors): Increment the initial inferior's refcount. * inferior.h (struct inferior): Forward declare. Include "common/refcounted-object.h". (current_inferior, set_current_inferior): Move declaration to before struct inferior's definition, and fix comment. (inferior): Inherit from refcounted_object. Add comments. * thread.c (switch_to_thread_no_regs): Reference the thread's inferior pointer directly instead of doing a ptid lookup. (switch_to_no_thread): New function. (switch_to_thread(thread_info *)): New function, factored out from ... (switch_to_thread(ptid_t)): ... this. (restore_current_thread): Delete. (current_thread_cleanup): Remove 'inf_id' and 'was_removable' fields, and add 'inf' field. (do_restore_current_thread_cleanup): Check whether old->inf is alive instead of looking up an inferior by ptid. Use switch_to_thread and switch_to_no_thread. (restore_current_thread_cleanup_dtor): Use old->inf directly instead of lookup up an inferior by id. Decref the inferior. Don't restore 'removable'. (make_cleanup_restore_current_thread): Same the inferior pointer in old, instead of the inferior number. Incref the inferior. Don't save/clear 'removable'. gdb/testsuite/ChangeLog: 2017-04-19 Pedro Alves <palves@redhat.com> * gdb.threads/threadapply.exp (kill_and_remove_inferior): New procedure. (top level): Call it. * lib/gdb.exp (gdb_define_cmd): New procedure.
2017-04-19 14:12:23 +02:00
references are considered weak references. Inferiors are always
listed exactly once in the inferior list, so placing an inferior in
the inferior list is an implicit, not counted strong reference. */
class inferior : public refcounted_object
{
public:
explicit inferior (int pid);
~inferior ();
Fix removing inferiors from within "thread apply" commands This patch fixes an internal error exposed by a test that does something like: define kill-and-remove kill inferiors 2 remove-inferiors 2 end # Start one inferior. start # Start another inferior. add-inferior 2 inferior 2 start # Kill and remove inferior 1 while inferior 2 is selected. thread apply 1.1 kill-and-remove The internal error looks like this: Thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677)): [Switching to inferior 1 [process 20677] (gdb/testsuite/outputs/gdb.threads/threadapply/threadapply)] [Switching to thread 1.1 (Thread 0x7ffff7fc2700 (LWP 20677))] #0 main () at src/gdb/testsuite/gdb.threads/threadapply.c:38 38 for (i = 0; i < NUM; i++) src/gdb/inferior.c:66: internal-error: void set_current_inferior(inferior*): Assertion `inf != NULL' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) FAIL: gdb.threads/threadapply.exp: kill_and_remove_inferior: try kill-and-remove: thread apply 1.1 kill-and-remove (GDB internal error) There are several problems around this area of the code. One is that in do_restore_current_thread_cleanup, we do a look up of inferior by ptid, which can find the wrong inferior if the previously selected inferior exited and some other inferior was started with a reused pid (rare, but still...). The other problem is that the "remove-inferiors" command rejects attempts to remove the current inferior, but when we get to "remove-inferiors" in a "thread apply THR remove-inferiors 2" command, the current inferior is the inferior of thread THR, not the previously selected inferior, so if the previously selected inferior was inferior 2, that command still manages to wipe it, and then gdb restores the old selected inferior, which is now a dangling pointer... So the fix here is: - Make make_cleanup_restore_current_thread store a pointer to the previously selected inferior directly, and use it directly instead of doing ptid look ups. - Add a refcount to inferiors, very similar to thread_info's refcount, that is incremented/decremented by make_cleanup_restore_current_thread, and checked before deleting an inferior. To avoid duplication, a new refcounted_object type is added, that both thread_info and inferior inherit from. gdb/ChangeLog: 2017-04-19 Pedro Alves <palves@redhat.com> * common/refcounted-object.h: New file. * gdbthread.h: Include "common/refcounted-object.h". (thread_info): Inherit from refcounted_object and add comments. (thread_info::incref, thread_info::decref) (thread_info::m_refcount): Delete. (thread_info::deletable): Use the refcounted_object::refcount() method. * inferior.c (current_inferior_): Add comment. (set_current_inferior): Increment/decrement refcounts. (prune_inferiors, remove_inferior_command): Skip inferiors marked not-deletable instead of comparing with the current inferior. (initialize_inferiors): Increment the initial inferior's refcount. * inferior.h (struct inferior): Forward declare. Include "common/refcounted-object.h". (current_inferior, set_current_inferior): Move declaration to before struct inferior's definition, and fix comment. (inferior): Inherit from refcounted_object. Add comments. * thread.c (switch_to_thread_no_regs): Reference the thread's inferior pointer directly instead of doing a ptid lookup. (switch_to_no_thread): New function. (switch_to_thread(thread_info *)): New function, factored out from ... (switch_to_thread(ptid_t)): ... this. (restore_current_thread): Delete. (current_thread_cleanup): Remove 'inf_id' and 'was_removable' fields, and add 'inf' field. (do_restore_current_thread_cleanup): Check whether old->inf is alive instead of looking up an inferior by ptid. Use switch_to_thread and switch_to_no_thread. (restore_current_thread_cleanup_dtor): Use old->inf directly instead of lookup up an inferior by id. Decref the inferior. Don't restore 'removable'. (make_cleanup_restore_current_thread): Same the inferior pointer in old, instead of the inferior number. Incref the inferior. Don't save/clear 'removable'. gdb/testsuite/ChangeLog: 2017-04-19 Pedro Alves <palves@redhat.com> * gdb.threads/threadapply.exp (kill_and_remove_inferior): New procedure. (top level): Call it. * lib/gdb.exp (gdb_define_cmd): New procedure.
2017-04-19 14:12:23 +02:00
/* Returns true if we can delete this inferior. */
bool deletable () const { return refcount () == 0; }
Multi-target support This commit adds multi-target support to GDB. What this means is that with this commit, GDB can now be connected to different targets at the same time. E.g., you can debug a live native process and a core dump at the same time, connect to multiple gdbservers, etc. Actually, the word "target" is overloaded in gdb. We already have a target stack, with pushes several target_ops instances on top of one another. We also have "info target" already, which means something completely different to what this patch does. So from here on, I'll be using the "target connections" term, to mean an open process_stratum target, pushed on a target stack. This patch makes gdb have multiple target stacks, and multiple process_stratum targets open simultaneously. The user-visible changes / commands will also use this terminology, but of course it's all open to debate. User-interface-wise, not that much changes. The main difference is that each inferior may have its own target connection. A target connection (e.g., a target extended-remote connection) may support debugging multiple processes, just as before. Say you're debugging against gdbserver in extended-remote mode, and you do "add-inferior" to prepare to spawn a new process, like: (gdb) target extended-remote :9999 ... (gdb) start ... (gdb) add-inferior Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) file a.out ... (gdb) start ... At this point, you have two inferiors connected to the same gdbserver. With this commit, GDB will maintain a target stack per inferior, instead of a global target stack. To preserve the behavior above, by default, "add-inferior" makes the new inferior inherit a copy of the target stack of the current inferior. Same across a fork - the child inherits a copy of the target stack of the parent. While the target stacks are copied, the targets themselves are not. Instead, target_ops is made a refcounted_object, which means that target_ops instances are refcounted, which each inferior counting for a reference. What if you want to create an inferior and connect it to some _other_ target? For that, this commit introduces a new "add-inferior -no-connection" option that makes the new inferior not share the current inferior's target. So you could do: (gdb) target extended-remote :9999 Remote debugging using :9999 ... (gdb) add-inferior -no-connection [New inferior 2] Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 <null> (gdb) tar extended-remote :10000 Remote debugging using :10000 ... (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 process 18450 target:/home/pedro/tmp/main (gdb) A following patch will extended "info inferiors" to include a column indicating which connection an inferior is bound to, along with a couple other UI tweaks. Other than that, debugging is the same as before. Users interact with inferiors and threads as before. The only difference is that inferiors may be bound to processes running in different machines. That's pretty much all there is to it in terms of noticeable UI changes. On to implementation. Since we can be connected to different systems at the same time, a ptid_t is no longer a unique identifier. Instead a thread can be identified by a pair of ptid_t and 'process_stratum_target *', the later being the instance of the process_stratum target that owns the process/thread. Note that process_stratum_target inherits from target_ops, and all process_stratum targets inherit from process_stratum_target. In earlier patches, many places in gdb were converted to refer to threads by thread_info pointer instead of ptid_t, but there are still places in gdb where we start with a pid/tid and need to find the corresponding inferior or thread_info objects. So you'll see in the patch many places adding a process_stratum_target parameter to functions that used to take only a ptid_t. Since each inferior has its own target stack now, we can always find the process_stratum target for an inferior. That is done via a inf->process_target() convenience method. Since each inferior has its own target stack, we need to handle the "beneath" calls when servicing target calls. The solution I settled with is just to make sure to switch the current inferior to the inferior you want before making a target call. Not relying on global context is just not feasible in current GDB. Fortunately, there aren't that many places that need to do that, because generally most code that calls target methods already has the current context pointing to the right inferior/thread. Note, to emphasize -- there's no method to "switch to this target stack". Instead, you switch the current inferior, and that implicitly switches the target stack. In some spots, we need to iterate over all inferiors so that we reach all target stacks. Native targets are still singletons. There's always only a single instance of such targets. Remote targets however, we'll have one instance per remote connection. The exec target is still a singleton. There's only one instance. I did not see the point of instanciating more than one exec_target object. After vfork, we need to make sure to push the exec target on the new inferior. See exec_on_vfork. For type safety, functions that need a {target, ptid} pair to identify a thread, take a process_stratum_target pointer for target parameter instead of target_ops *. Some shared code in gdb/nat/ also need to gain a target pointer parameter. This poses an issue, since gdbserver doesn't have process_stratum_target, only target_ops. To fix this, this commit renames gdbserver's target_ops to process_stratum_target. I think this makes sense. There's no concept of target stack in gdbserver, and gdbserver's target_ops really implements a process_stratum-like target. The thread and inferior iterator functions also gain process_stratum_target parameters. These are used to be able to iterate over threads and inferiors of a given target. Following usual conventions, if the target pointer is null, then we iterate over threads and inferiors of all targets. I tried converting "add-inferior" to the gdb::option framework, as a preparatory patch, but that stumbled on the fact that gdb::option does not support file options yet, for "add-inferior -exec". I have a WIP patchset that adds that, but it's not a trivial patch, mainly due to need to integrate readline's filename completion, so I deferred that to some other time. In infrun.c/infcmd.c, the main change is that we need to poll events out of all targets. See do_target_wait. Right after collecting an event, we switch the current inferior to an inferior bound to the target that reported the event, so that target methods can be used while handling the event. This makes most of the code transparent to multi-targets. See fetch_inferior_event. infrun.c:stop_all_threads is interesting -- in this function we need to stop all threads of all targets. What the function does is send an asynchronous stop request to all threads, and then synchronously waits for events, with target_wait, rinse repeat, until all it finds are stopped threads. Now that we have multiple targets, it's not efficient to synchronously block in target_wait waiting for events out of one target. Instead, we implement a mini event loop, with interruptible_select, select'ing on one file descriptor per target. For this to work, we need to be able to ask the target for a waitable file descriptor. Such file descriptors already exist, they are the descriptors registered in the main event loop with add_file_handler, inside the target_async implementations. This commit adds a new target_async_wait_fd target method that just returns the file descriptor in question. See wait_one / stop_all_threads in infrun.c. The 'threads_executing' global is made a per-target variable. Since it is only relevant to process_stratum_target targets, this is where it is put, instead of in target_ops. You'll notice that remote.c includes some FIXME notes. These refer to the fact that the global arrays that hold data for the remote packets supported are still globals. For example, if we connect to two different servers/stubs, then each might support different remote protocol features. They might even be different architectures, like e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a host/controller scenario as a single program. That isn't going to work correctly today, because of said globals. I'm leaving fixing that for another pass, since it does not appear to be trivial, and I'd rather land the base work first. It's already useful to be able to debug multiple instances of the same server (e.g., a distributed cluster, where you have full control over the servers installed), so I think as is it's already reasonable incremental progress. Current limitations: - You can only resume more that one target at the same time if all targets support asynchronous debugging, and support non-stop mode. It should be possible to support mixed all-stop + non-stop backends, but that is left for another time. This means that currently in order to do multi-target with gdbserver you need to issue "maint set target-non-stop on". I would like to make that mode be the default, but we're not there yet. Note that I'm talking about how the target backend works, only. User-visible all-stop mode works just fine. - As explained above, connecting to different remote servers at the same time is likely to produce bad results if they don't support the exact set of RSP features. FreeBSD updates courtesy of John Baldwin. gdb/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> John Baldwin <jhb@FreeBSD.org> * aarch64-linux-nat.c (aarch64_linux_nat_target::thread_architecture): Adjust. * ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call. (task_command_1): Likewise. * aix-thread.c (sync_threadlists, aix_thread_target::resume) (aix_thread_target::wait, aix_thread_target::fetch_registers) (aix_thread_target::store_registers) (aix_thread_target::thread_alive): Adjust. * amd64-fbsd-tdep.c: Include "inferior.h". (amd64fbsd_get_thread_local_address): Pass down target. * amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle thread's gdbarch instead of target_gdbarch. * break-catch-sig.c (signal_catchpoint_print_it): Adjust call to get_last_target_status. * break-catch-syscall.c (print_it_catch_syscall): Likewise. * breakpoint.c (breakpoints_should_be_inserted_now): Consider all inferiors. (update_inserted_breakpoint_locations): Skip if inferiors with no execution. (update_global_location_list): When handling moribund locations, find representative inferior for location's pspace, and use thread count of its process_stratum target. * bsd-kvm.c (bsd_kvm_target_open): Pass target down. * bsd-uthread.c (bsd_uthread_target::wait): Use as_process_stratum_target and adjust thread_change_ptid and add_thread calls. (bsd_uthread_target::update_thread_list): Use as_process_stratum_target and adjust find_thread_ptid, thread_change_ptid and add_thread calls. * btrace.c (maint_btrace_packet_history_cmd): Adjust find_thread_ptid call. * corelow.c (add_to_thread_list): Adjust add_thread call. (core_target_open): Adjust add_thread_silent and thread_count calls. (core_target::pid_to_str): Adjust find_inferior_ptid call. * ctf.c (ctf_target_open): Adjust add_thread_silent call. * event-top.c (async_disconnect): Pop targets from all inferiors. * exec.c (add_target_sections): Push exec target on all inferiors sharing the program space. (remove_target_sections): Remove the exec target from all inferiors sharing the program space. (exec_on_vfork): New. * exec.h (exec_on_vfork): Declare. * fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::update_thread_list): Adjust. (fbsd_nat_target::resume): Adjust. (fbsd_handle_debug_trap): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust. * fbsd-tdep.c (fbsd_corefile_thread): Adjust get_thread_arch_regcache call. * fork-child.c (gdb_startup_inferior): Pass target down to startup_inferior and set_executing. * gdbthread.h (struct process_stratum_target): Forward declare. (add_thread, add_thread_silent, add_thread_with_info) (in_thread_list): Add process_stratum_target parameter. (find_thread_ptid(inferior*, ptid_t)): New overload. (find_thread_ptid, thread_change_ptid): Add process_stratum_target parameter. (all_threads()): Delete overload. (all_threads, all_non_exited_threads): Add process_stratum_target parameter. (all_threads_safe): Use brace initialization. (thread_count): Add process_stratum_target parameter. (set_resumed, set_running, set_stop_requested, set_executing) (threads_are_executing, finish_thread_state): Add process_stratum_target parameter. (switch_to_thread): Use is_current_thread. * i386-fbsd-tdep.c: Include "inferior.h". (i386fbsd_get_thread_local_address): Pass down target. * i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust. * inf-child.c (inf_child_target::maybe_unpush_target): Remove have_inferiors check. * inf-ptrace.c (inf_ptrace_target::create_inferior) (inf_ptrace_target::attach): Adjust. * infcall.c (run_inferior_call): Adjust. * infcmd.c (run_command_1): Pass target to scoped_finish_thread_state. (proceed_thread_callback): Skip inferiors with no execution. (continue_command): Rename 'all_threads' local to avoid hiding 'all_threads' function. Adjust get_last_target_status call. (prepare_one_step): Adjust set_running call. (signal_command): Use user_visible_resume_target. Compare thread pointers instead of inferior_ptid. (info_program_command): Adjust to pass down target. (attach_command): Mark target's 'thread_executing' flag. (stop_current_target_threads_ns): New, factored out from ... (interrupt_target_1): ... this. Switch inferior before making target calls. * inferior-iter.h (struct all_inferiors_iterator, struct all_inferiors_range) (struct all_inferiors_safe_range) (struct all_non_exited_inferiors_range): Filter on process_stratum_target too. Remove explicit. * inferior.c (inferior::inferior): Push dummy target on target stack. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors): Add process_stratum_target parameter, and pass it down. (have_live_inferiors): Adjust. (switch_to_inferior_and_push_target): New. (add_inferior_command, clone_inferior_command): Handle "-no-connection" parameter. Use switch_to_inferior_and_push_target. (_initialize_inferior): Mention "-no-connection" option in the help of "add-inferior" and "clone-inferior" commands. * inferior.h: Include "process-stratum-target.h". (interrupt_target_1): Use bool. (struct inferior) <push_target, unpush_target, target_is_pushed, find_target_beneath, top_target, process_target, target_at, m_stack>: New. (discard_all_inferiors): Delete. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors) (all_inferiors, all_non_exited_inferiors): Add process_stratum_target parameter. * infrun.c: Include "gdb_select.h" and <unordered_map>. (target_last_proc_target): New global. (follow_fork_inferior): Push target on new inferior. Pass target to add_thread_silent. Call exec_on_vfork. Handle target's reference count. (follow_fork): Adjust get_last_target_status call. Also consider target. (follow_exec): Push target on new inferior. (struct execution_control_state) <target>: New field. (user_visible_resume_target): New. (do_target_resume): Call target_async. (resume_1): Set target's threads_executing flag. Consider resume target. (commit_resume_all_targets): New. (proceed): Also consider resume target. Skip threads of inferiors with no execution. Commit resumtion in all targets. (start_remote): Pass current inferior to wait_for_inferior. (infrun_thread_stop_requested): Consider target as well. Pass thread_info pointer to clear_inline_frame_state instead of ptid. (infrun_thread_thread_exit): Consider target as well. (random_pending_event_thread): New inferior parameter. Use it. (do_target_wait): Rename to ... (do_target_wait_1): ... this. Add inferior parameter, and pass it down. (threads_are_resumed_pending_p, do_target_wait): New. (prepare_for_detach): Adjust calls. (wait_for_inferior): New inferior parameter. Handle it. Use do_target_wait_1 instead of do_target_wait. (fetch_inferior_event): Adjust. Switch to representative inferior. Pass target down. (set_last_target_status): Add process_stratum_target parameter. Save target in global. (get_last_target_status): Add process_stratum_target parameter and handle it. (nullify_last_target_wait_ptid): Clear 'target_last_proc_target'. (context_switch): Check inferior_ptid == null_ptid before calling inferior_thread(). (get_inferior_stop_soon): Pass down target. (wait_one): Rename to ... (poll_one_curr_target): ... this. (struct wait_one_event): New. (wait_one): New. (stop_all_threads): Adjust. (handle_no_resumed, handle_inferior_event): Adjust to consider the event's target. (switch_back_to_stepped_thread): Also consider target. (print_stop_event): Update. (normal_stop): Update. Also consider the resume target. * infrun.h (wait_for_inferior): Remove declaration. (user_visible_resume_target): New declaration. (get_last_target_status, set_last_target_status): New process_stratum_target parameter. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter, and use it. (clear_inline_frame_state (thread_info*)): New. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter. (clear_inline_frame_state (thread_info*)): Declare. * linux-fork.c (delete_checkpoint_command): Pass target down to find_thread_ptid. (checkpoint_command): Adjust. * linux-nat.c (linux_nat_target::follow_fork): Switch to thread instead of just tweaking inferior_ptid. (linux_nat_switch_fork): Pass target down to thread_change_ptid. (exit_lwp): Pass target down to find_thread_ptid. (attach_proc_task_lwp_callback): Pass target down to add_thread/set_running/set_executing. (linux_nat_target::attach): Pass target down to thread_change_ptid. (get_detach_signal): Pass target down to find_thread_ptid. Consider last target status's target. (linux_resume_one_lwp_throw, resume_lwp) (linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp) (stop_wait_callback, save_stop_reason, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down. (linux_nat_target::async_wait_fd): New. (linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass target down. * linux-nat.h (linux_nat_target::async_wait_fd): Declare. * linux-tdep.c (get_thread_arch_regcache): Pass target down. * linux-thread-db.c (struct thread_db_info::process_target): New field. (add_thread_db_info): Save target. (get_thread_db_info): New process_stratum_target parameter. Also match target. (delete_thread_db_info): New process_stratum_target parameter. Also match target. (thread_from_lwp): Adjust to pass down target. (thread_db_notice_clone): Pass down target. (check_thread_db_callback): Pass down target. (try_thread_db_load_1): Always push the thread_db target. (try_thread_db_load, record_thread): Pass target down. (thread_db_target::detach): Pass target down. Always unpush the thread_db target. (thread_db_target::wait, thread_db_target::mourn_inferior): Pass target down. Always unpush the thread_db target. (find_new_threads_callback, thread_db_find_new_threads_2) (thread_db_target::update_thread_list): Pass target down. (thread_db_target::pid_to_str): Pass current inferior down. (thread_db_target::get_thread_local_address): Pass target down. (thread_db_target::resume, maintenance_check_libthread_db): Pass target down. * nto-procfs.c (nto_procfs_target::update_thread_list): Adjust. * procfs.c (procfs_target::procfs_init_inferior): Declare. (proc_set_current_signal, do_attach, procfs_target::wait): Adjust. (procfs_init_inferior): Rename to ... (procfs_target::procfs_init_inferior): ... this and adjust. (procfs_target::create_inferior, procfs_notice_thread) (procfs_do_thread_registers): Adjust. * ppc-fbsd-tdep.c: Include "inferior.h". (ppcfbsd_get_thread_local_address): Pass down target. * proc-service.c (ps_xfer_memory): Switch current inferior and program space as well. (get_ps_regcache): Pass target down. * process-stratum-target.c (process_stratum_target::thread_address_space) (process_stratum_target::thread_architecture): Pass target down. * process-stratum-target.h (process_stratum_target::threads_executing): New field. (as_process_stratum_target): New. * ravenscar-thread.c (ravenscar_thread_target::update_inferior_ptid): Pass target down. (ravenscar_thread_target::wait, ravenscar_add_thread): Pass target down. * record-btrace.c (record_btrace_target::info_record): Adjust. (record_btrace_target::record_method) (record_btrace_target::record_is_replaying) (record_btrace_target::fetch_registers) (get_thread_current_frame_id, record_btrace_target::resume) (record_btrace_target::wait, record_btrace_target::stop): Pass target down. * record-full.c (record_full_wait_1): Switch to event thread. Pass target down. * regcache.c (regcache::regcache) (get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add process_stratum_target parameter and handle it. (current_thread_target): New global. (get_thread_regcache): Add process_stratum_target parameter and handle it. Switch inferior before calling target method. (get_thread_regcache): Pass target down. (get_thread_regcache_for_ptid): Pass target down. (registers_changed_ptid): Add process_stratum_target parameter and handle it. (registers_changed_thread, registers_changed): Pass target down. (test_get_thread_arch_aspace_regcache): New. (current_regcache_test): Define a couple local test_target_ops instances and use them for testing. (readwrite_regcache): Pass process_stratum_target parameter. (cooked_read_test, cooked_write_test): Pass mock_target down. * regcache.h (get_thread_regcache, get_thread_arch_regcache) (get_thread_arch_aspace_regcache): Add process_stratum_target parameter. (regcache::target): New method. (regcache::regcache, regcache::get_thread_arch_aspace_regcache) (regcache::registers_changed_ptid): Add process_stratum_target parameter. (regcache::m_target): New field. (registers_changed_ptid): Add process_stratum_target parameter. * remote.c (remote_state::supports_vCont_probed): New field. (remote_target::async_wait_fd): New method. (remote_unpush_and_throw): Add remote_target parameter. (get_current_remote_target): Adjust. (remote_target::remote_add_inferior): Push target. (remote_target::remote_add_thread) (remote_target::remote_notice_new_inferior) (get_remote_thread_info): Pass target down. (remote_target::update_thread_list): Skip threads of inferiors bound to other targets. (remote_target::close): Don't discard inferiors. (remote_target::add_current_inferior_and_thread) (remote_target::process_initial_stop_replies) (remote_target::start_remote) (remote_target::remote_serial_quit_handler): Pass down target. (remote_target::remote_unpush_target): New remote_target parameter. Unpush the target from all inferiors. (remote_target::remote_unpush_and_throw): New remote_target parameter. Pass it down. (remote_target::open_1): Check whether the current inferior has execution instead of checking whether any inferior is live. Pass target down. (remote_target::remote_detach_1): Pass down target. Use remote_unpush_target. (extended_remote_target::attach): Pass down target. (remote_target::remote_vcont_probe): Set supports_vCont_probed. (remote_target::append_resumption): Pass down target. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc, remote_target::resume) (remote_target::commit_resume): Pass down target. (remote_target::remote_stop_ns): Check supports_vCont_probed. (remote_target::interrupt_query) (remote_target::remove_new_fork_children) (remote_target::check_pending_events_prevent_wildcard_vcont) (remote_target::remote_parse_stop_reply) (remote_target::process_stop_reply): Pass down target. (first_remote_resumed_thread): New remote_target parameter. Pass it down. (remote_target::wait_as): Pass down target. (unpush_and_perror): New remote_target parameter. Pass it down. (remote_target::readchar, remote_target::remote_serial_write) (remote_target::getpkt_or_notif_sane_1) (remote_target::kill_new_fork_children, remote_target::kill): Pass down target. (remote_target::mourn_inferior): Pass down target. Use remote_unpush_target. (remote_target::core_of_thread) (remote_target::remote_btrace_maybe_reopen): Pass down target. (remote_target::pid_to_exec_file) (remote_target::thread_handle_to_thread_info): Pass down target. (remote_target::async_wait_fd): New. * riscv-fbsd-tdep.c: Include "inferior.h". (riscv_fbsd_get_thread_local_address): Pass down target. * sol2-tdep.c (sol2_core_pid_to_str): Pass down target. * sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs) (ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback): Adjust. * solib-spu.c (spu_skip_standalone_loader): Pass down target. * solib-svr4.c (enable_break): Pass down target. * spu-multiarch.c (parse_spufs_run): Pass down target. * spu-tdep.c (spu2ppu_sniffer): Pass down target. * target-delegates.c: Regenerate. * target.c (g_target_stack): Delete. (current_top_target): Return the current inferior's top target. (target_has_execution_1): Refer to the passed-in inferior's top target. (target_supports_terminal_ours): Check whether the initial inferior was already created. (decref_target): New. (target_stack::push): Incref/decref the target. (push_target, push_target, unpush_target): Adjust. (target_stack::unpush): Defref target. (target_is_pushed): Return bool. Adjust to refer to the current inferior's target stack. (dispose_inferior): Delete, and inline parts ... (target_preopen): ... here. Only dispose of the current inferior. (target_detach): Hold strong target reference while detaching. Pass target down. (target_thread_name): Add assertion. (target_resume): Pass down target. (target_ops::beneath, find_target_at): Adjust to refer to the current inferior's target stack. (get_dummy_target): New. (target_pass_ctrlc): Pass the Ctrl-C to the first inferior that has a thread running. (initialize_targets): Rename to ... (_initialize_target): ... this. * target.h: Include "gdbsupport/refcounted-object.h". (struct target_ops): Inherit refcounted_object. (target_ops::shortname, target_ops::longname): Make const. (target_ops::async_wait_fd): New method. (decref_target): Declare. (struct target_ops_ref_policy): New. (target_ops_ref): New typedef. (get_dummy_target): Declare function. (target_is_pushed): Return bool. * thread-iter.c (all_matching_threads_iterator::m_inf_matches) (all_matching_threads_iterator::all_matching_threads_iterator): Handle filter target. * thread-iter.h (struct all_matching_threads_iterator, struct all_matching_threads_range, class all_non_exited_threads_range): Filter by target too. Remove explicit. * thread.c (threads_executing): Delete. (inferior_thread): Pass down current inferior. (clear_thread_inferior_resources): Pass down thread pointer instead of ptid_t. (add_thread_silent, add_thread_with_info, add_thread): Add process_stratum_target parameter. Use it for thread and inferior searches. (is_current_thread): New. (thread_info::deletable): Use it. (find_thread_ptid, thread_count, in_thread_list) (thread_change_ptid, set_resumed, set_running): New process_stratum_target parameter. Pass it down. (set_executing): New process_stratum_target parameter. Pass it down. Adjust reference to 'threads_executing'. (threads_are_executing): New process_stratum_target parameter. Adjust reference to 'threads_executing'. (set_stop_requested, finish_thread_state): New process_stratum_target parameter. Pass it down. (switch_to_thread): Also match inferior. (switch_to_thread): New process_stratum_target parameter. Pass it down. (update_threads_executing): Reimplement. * top.c (quit_force): Pop targets from all inferior. (gdb_init): Don't call initialize_targets. * windows-nat.c (windows_nat_target) <get_windows_debug_event>: Declare. (windows_add_thread, windows_delete_thread): Adjust. (get_windows_debug_event): Rename to ... (windows_nat_target::get_windows_debug_event): ... this. Adjust. * tracefile-tfile.c (tfile_target_open): Pass down target. * gdbsupport/common-gdbthread.h (struct process_stratum_target): Forward declare. (switch_to_thread): Add process_stratum_target parameter. * mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target parameter. Use it. (mi_on_resume): Pass target down. * nat/fork-inferior.c (startup_inferior): Add process_stratum_target parameter. Pass it down. * nat/fork-inferior.h (startup_inferior): Add process_stratum_target parameter. * python/py-threadevent.c (py_get_event_thread): Pass target down. gdb/gdbserver/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> * fork-child.c (post_fork_inferior): Pass target down to startup_inferior. * inferiors.c (switch_to_thread): Add process_stratum_target parameter. * lynx-low.c (lynx_target_ops): Now a process_stratum_target. * nto-low.c (nto_target_ops): Now a process_stratum_target. * linux-low.c (linux_target_ops): Now a process_stratum_target. * remote-utils.c (prepare_resume_reply): Pass the target to switch_to_thread. * target.c (the_target): Now a process_stratum_target. (done_accessing_memory): Pass the target to switch_to_thread. (set_target_ops): Ajust to use process_stratum_target. * target.h (struct target_ops): Rename to ... (struct process_stratum_target): ... this. (the_target, set_target_ops): Adjust. (prepare_to_access_memory): Adjust comment. * win32-low.c (child_xfer_memory): Adjust to use process_stratum_target. (win32_target_ops): Now a process_stratum_target.
2020-01-10 21:06:08 +01:00
/* Push T in this inferior's target stack. */
void push_target (struct target_ops *t)
{ m_target_stack.push (t); }
/* Unpush T from this inferior's target stack. */
int unpush_target (struct target_ops *t)
{ return m_target_stack.unpush (t); }
/* Returns true if T is pushed in this inferior's target stack. */
bool target_is_pushed (target_ops *t)
{ return m_target_stack.is_pushed (t); }
/* Find the target beneath T in this inferior's target stack. */
target_ops *find_target_beneath (const target_ops *t)
{ return m_target_stack.find_beneath (t); }
/* Return the target at the top of this inferior's target stack. */
target_ops *top_target ()
{ return m_target_stack.top (); }
/* Return the target at process_stratum level in this inferior's
target stack. */
struct process_stratum_target *process_target ()
{ return (process_stratum_target *) m_target_stack.at (process_stratum); }
/* Return the target at STRATUM in this inferior's target stack. */
target_ops *target_at (enum strata stratum)
{ return m_target_stack.at (stratum); }
Make target_ops::has_execution take an 'inferior *' instead of a ptid_t With the multi-target work, each inferior will have its own target stack, so to call a target method, we'll need to make sure that the inferior in question is the current one, otherwise target->beneath() calls will find the target beneath in the wrong inferior. In some places, it's much more convenient to be able to check whether an inferior has execution without having to switch to it in order to call target_has_execution on the right inferior/target stack, to avoid side effects with switching inferior/thread/program space. The current target_ops::has_execution method takes a ptid_t as parameter, which, in a multi-target world, isn't sufficient to identify the target. This patch prepares to address that, by changing the parameter to an inferior pointer instead. From the inferior, we'll be able to query its target stack to tell which target is beneath. Also adds a new inferior::has_execution() method to make callers a bit more natural to read. gdb/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> * corelow.c (core_target::has_execution): Change parameter type to inferior pointer. * inferior.c (number_of_live_inferiors): Use inferior::has_execution instead of target_has_execution_1. * inferior.h (inferior::has_execution): New. * linux-thread-db.c (thread_db_target::update_thread_list): Use inferior::has_execution instead of target_has_execution_1. * process-stratum-target.c (process_stratum_target::has_execution): Change parameter type to inferior pointer. Check the inferior's PID instead of inferior_ptid. * process-stratum-target.h (process_stratum_target::has_execution): Change parameter type to inferior pointer. * record-full.c (record_full_core_target::has_execution): Change parameter type to inferior pointer. * target.c (target_has_execution_1): Change parameter type to inferior pointer. (target_has_execution_current): Adjust. * target.h (target_ops::has_execution): Change parameter type to inferior pointer. (target_has_execution_1): Change parameter type to inferior pointer. Change return type to bool. * tracefile.h (tracefile_target::has_execution): Change parameter type to inferior pointer.
2020-01-10 21:05:44 +01:00
bool has_execution ()
{ return target_has_execution_1 (this); }
/* Pointer to next inferior in singly-linked list of inferiors. */
struct inferior *next = NULL;
Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc. As preparation for multi-target, this patch makes each inferior have its own thread list. This isn't absolutely necessary for multi-target, but simplifies things. It originally stemmed from the desire to eliminate the init_thread_list calls sprinkled around, plus it makes it more efficient to iterate over threads of a given inferior (no need to always iterate over threads of all inferiors). We still need to iterate over threads of all inferiors in a number of places, which means we'd need adjust the ALL_THREADS / ALL_NON_EXITED_THREADS macros. However, naively tweaking those macros to have an extra for loop, like: #define ALL_THREADS (thr, inf) \ for (inf = inferior_list; inf; inf = inf->next) \ for (thr = inf->thread_list; thr; thr = thr->next) causes problems with code that does "break" or "continue" within the ALL_THREADS loop body. Plus, we need to declare the extra "inf" local variable in order to pass it as temporary variable to ALL_THREADS (etc.) It gets even trickier when we consider extending the macros to filter out threads matching a ptid_t and a target. The macros become tricker to read/write. Been there. An alternative (which was my next attempt), is to replace the ALL_THREADS etc. iteration style with for_each_all_threads, for_each_non_exited_threads, etc. functions which would take a callback as parameter, which would usually be passed a lambda. However, I did not find that satisfactory at all, because the resulting code ends up a little less natural / more noisy to read, write and debug/step-through (due to use of lambdas), and in many places where we use "continue;" to skip to the next thread now need to use "return;". (I ran into hard to debug bugs caused by a continue/return confusion.) I.e., before: ALL_NON_EXITED_THREADS (tp) { if (tp->not_what_I_want) continue; // do something } would turn into: for_each_non_exited_thread ([&] (thread_info *tp) { if (tp->not_what_I_want) return; // do something }); Lastly, the solution I settled with was to replace the ALL_THREADS / ALL_NON_EXITED_THREADS / ALL_INFERIORS macros with (C++20-like) ranges and iterators, such that you can instead naturaly iterate over threads/inferiors using range-for, like e.g,.: // all threads, including THREAD_EXITED threads. for (thread_info *tp : all_threads ()) { .... } // all non-exited threads. for (thread_info *tp : all_non_exited_threads ()) { .... } // all non-exited threads of INF inferior. for (thread_info *tp : inf->non_exited_threads ()) { .... } The all_non_exited_threads() function takes an optional filter ptid_t as parameter, which is quite convenient when we need to iterate over threads matching that filter. See e.g., how the set_executing/set_stop_requested/finish_thread_state etc. functions in thread.c end up being simplified. Most of the patch thus is about adding the infrustructure for allowing the above. Later on when we get to actual multi-target, these functions/ranges/iterators will gain a "target_ops *" parameter so that e.g., we can iterate over all threads of a given target that match a given filter ptid_t. The only entry points users needs to be aware of are the all_threads/all_non_exited_threads etc. functions seen above. Thus, those functions are declared in gdbthread.h/inferior.h. The actual iterators/ranges are mainly "internals" and thus are put out of view in the new thread-iter.h/thread-iter.c/inferior-iter.h files. That keeps the gdbthread.h/inferior.h headers quite a bit more readable. A common/safe-iterator.h header is added which adds a template that can be used to build "safe" iterators, which are forward iterators that can be used to replace the ALL_THREADS_SAFE macro and other instances of the same idiom in future. There's a little bit of shuffling of code between gdbthread.h/thread.c/inferior.h in the patch. That is necessary in order to avoid circular dependencies between the gdbthread.h/inferior.h headers. As for the init_thread_list calls sprinkled around, they're all eliminated by this patch, and a new, central call is added to inferior_appeared. Note how also related to that, there's a call to init_wait_for_inferior in remote.c that is eliminated. init_wait_for_inferior is currently responsible for discarding skipped inline frames, which had to be moved elsewhere. Given that nowadays we always have a thread even for single-threaded processes, the natural place is to delete a frame's inline frame info when we delete the thread. I.e., from clear_thread_inferior_resources. gdb/ChangeLog: 2018-11-22 Pedro Alves <palves@redhat.com> * Makefile.in (COMMON_SFILES): Add thread-iter.c. * breakpoint.c (breakpoints_should_be_inserted_now): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (print_one_breakpoint_location): Replace ALL_INFERIORS with all_inferiors. * bsd-kvm.c: Include inferior.h. * btrace.c (btrace_free_objfile): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * common/filtered-iterator.h: New. * common/safe-iterator.h: New. * corelow.c (core_target_open): Don't call init_thread_list here. * darwin-nat.c (thread_info_from_private_thread_info): Replace ALL_THREADS with all_threads. * fbsd-nat.c (fbsd_nat_target::resume): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fbsd-tdep.c (fbsd_make_corefile_notes): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fork-child.c (postfork_hook): Don't call init_thread_list here. * gdbarch-selftests.c (register_to_value_test): Adjust. * gdbthread.h: Don't include "inferior.h" here. (struct inferior): Forward declare. (enum step_over_calls_kind): Moved here from inferior.h. (thread_info::deletable): Definition moved to thread.c. (find_thread_ptid (inferior *, ptid_t)): Declare. (ALL_THREADS, ALL_THREADS_BY_INFERIOR, ALL_THREADS_SAFE): Delete. Include "thread-iter.h". (all_threads, all_non_exited_threads, all_threads_safe): New. (any_thread_p): Declare. (thread_list): Delete. * infcmd.c (signal_command): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (proceed_after_attach_callback): Delete. (proceed_after_attach): Take an inferior pointer instead of an integer PID. Adjust to use range-for. (attach_post_wait): Pass down inferior pointer instead of pid. Use range-for instead of ALL_NON_EXITED_THREADS. (detach_command): Remove init_thread_list call. * inferior-iter.h: New. * inferior.c (struct delete_thread_of_inferior_arg): Delete. (delete_thread_of_inferior): Delete. (delete_inferior, exit_inferior_1): Use range-for with inf->threads_safe() instead of iterate_over_threads. (inferior_appeared): Call init_thread_list here. (discard_all_inferiors): Use all_non_exited_inferiors. (find_inferior_id, find_inferior_pid): Use all_inferiors. (iterate_over_inferiors): Use all_inferiors_safe. (have_inferiors, number_of_live_inferiors): Use all_non_exited_inferiors. (number_of_inferiors): Use all_inferiors and std::distance. (print_inferior): Use all_inferiors. * inferior.h: Include gdbthread.h. (enum step_over_calls_kind): Moved to gdbthread.h. (struct inferior) <thread_list>: New field. <threads, non_exited_threads, threads_safe>: New methods. (ALL_INFERIORS): Delete. Include "inferior-iter.h". (ALL_NON_EXITED_INFERIORS): Delete. (all_inferiors_safe, all_inferiors, all_non_exited_inferiors): New functions. * inflow.c (child_interrupt, child_pass_ctrlc): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * infrun.c (follow_exec): Use all_threads_safe. (clear_proceed_status, proceed): Use all_non_exited_threads. (init_wait_for_inferior): Don't clear inline frame state here. (infrun_thread_stop_requested, for_each_just_stopped_thread): Use all_threads instead of ALL_NON_EXITED_THREADS. (random_pending_event_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use a lambda for repeated code. (clean_up_just_stopped_threads_fsms): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (handle_no_resumed): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use all_inferiors instead of ALL_INFERIORS. (restart_threads, switch_back_to_stepped_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-nat.c (check_zombie_leaders): Replace ALL_INFERIORS with all_inferiors. (kill_unfollowed_fork_children): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-tdep.c (linux_make_corefile_notes): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-thread-db.c (thread_db_target::update_thread_list): Replace ALL_INFERIORS with all_inferiors. (thread_db_target::thread_handle_to_thread_info): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * mi/mi-interp.c (multiple_inferiors_p): New. (mi_on_resume_1): Simplify using all_non_exited_threads and multiple_inferiors_p. * mi/mi-main.c (mi_cmd_thread_list_ids): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * nto-procfs.c (nto_procfs_target::open): Don't call init_thread_list here. * record-btrace.c (record_btrace_target_open) (record_btrace_target::stop_recording) (record_btrace_target::close) (record_btrace_target::record_is_replaying) (record_btrace_target::resume, record_btrace_target::wait) (record_btrace_target::record_stop_replaying): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * record-full.c (record_full_wait_1): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * regcache.c (cooked_read_test): Remove reference to global thread_list. * remote-sim.c (gdbsim_target::create_inferior): Don't call init_thread_list here. * remote.c (remote_target::update_thread_list): Use all_threads_safe instead of ALL_NON_EXITED_THREADS. (remote_target::process_initial_stop_replies): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::open_1): Don't call init_thread_list here. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::commit_resume) (remote_target::remove_new_fork_children): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::kill_new_fork_children): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Remove init_thread_list and init_wait_for_inferior calls. (remote_target::remote_btrace_maybe_reopen) (remote_target::thread_handle_to_thread_info): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * target.c (target_terminal::restore_inferior) (target_terminal_is_ours_kind): Replace ALL_INFERIORS with all_non_exited_inferiors. * thread-iter.c: New file. * thread-iter.h: New file. * thread.c: Include "inline-frame.h". (thread_list): Delete. (clear_thread_inferior_resources): Call clear_inline_frame_state. (init_thread_list): Use all_threads_safe instead of ALL_THREADS_SAFE. Adjust to per-inferior thread lists. (new_thread): Adjust to per-inferior thread lists. (add_thread_silent): Pass inferior to find_thread_ptid. (thread_info::deletable): New, moved from the header. (delete_thread_1): Adjust to per-inferior thread lists. (find_thread_global_id): Use inf->threads(). (find_thread_ptid): Use find_inferior_ptid and pass inferior to find_thread_ptid. (find_thread_ptid(inferior*, ptid_t)): New overload. (iterate_over_threads): Use all_threads_safe. (any_thread_p): New. (thread_count): Use all_threads and std::distance. (live_threads_count): Use all_non_exited_threads and std::distance. (valid_global_thread_id): Use all_threads. (in_thread_list): Use find_thread_ptid. (first_thread_of_inferior): Adjust to per-inferior thread lists. (any_thread_of_inferior, any_live_thread_of_inferior): Use inf->non_exited_threads(). (prune_threads, delete_exited_threads): Use all_threads_safe. (thread_change_ptid): Pass inferior pointer to find_thread_ptid. (set_resumed, set_running): Use all_non_exited_threads. (is_thread_state, is_stopped, is_exited, is_running) (is_executing): Delete. (set_executing, set_stop_requested, finish_thread_state): Use all_non_exited_threads. (print_thread_info_1): Use all_inferiors and all_threads. (thread_apply_all_command): Use all_non_exited_threads. (thread_find_command): Use all_threads. (update_threads_executing): Use all_non_exited_threads. * tid-parse.c (parse_thread_id): Use inf->threads. * x86-bsd-nat.c (x86bsd_dr_set): Use inf->non_exited_threads ().
2018-11-22 17:09:14 +01:00
/* This inferior's thread list. */
thread_info *thread_list = nullptr;
/* Returns a range adapter covering the inferior's threads,
including exited threads. Used like this:
for (thread_info *thr : inf->threads ())
{ .... }
*/
inf_threads_range threads ()
{ return inf_threads_range (this->thread_list); }
/* Returns a range adapter covering the inferior's non-exited
threads. Used like this:
for (thread_info *thr : inf->non_exited_threads ())
{ .... }
*/
inf_non_exited_threads_range non_exited_threads ()
{ return inf_non_exited_threads_range (this->thread_list); }
/* Like inferior::threads(), but returns a range adapter that can be
used with range-for, safely. I.e., it is safe to delete the
currently-iterated thread, like this:
for (thread_info *t : inf->threads_safe ())
if (some_condition ())
delete f;
*/
inline safe_inf_threads_range threads_safe ()
{ return safe_inf_threads_range (this->thread_list); }
/* Set/get file name for default use for standard in/out in the
inferior. On Unix systems, we try to make TERMINAL_NAME the
inferior's controlling terminal. If TERMINAL_NAME is nullptr or
the empty string, then the inferior inherits GDB's terminal (or
GDBserver's if spawning a remote process). */
void set_tty (const char *terminal_name);
const char *tty ();
/* Convenient handle (GDB inferior id). Unique across all
inferiors. */
int num = 0;
/* Actual target inferior id, usually, a process id. This matches
the ptid_t.pid member of threads of this inferior. */
int pid = 0;
/* True if the PID was actually faked by GDB. */
bool fake_pid_p = false;
Per-inferior/Inferior-qualified thread IDs This commit changes GDB to track thread numbers per-inferior. Then, if you're debugging multiple inferiors, GDB displays "inferior-num.thread-num" instead of just "thread-num" whenever it needs to display a thread: (gdb) info inferiors Num Description Executable 1 process 6022 /home/pedro/gdb/tests/threads * 2 process 6037 /home/pedro/gdb/tests/threads (gdb) info threads Id Target Id Frame 1.1 Thread 0x7ffff7fc2740 (LWP 6022) "threads" (running) 1.2 Thread 0x7ffff77c0700 (LWP 6028) "threads" (running) 1.3 Thread 0x7ffff7fc2740 (LWP 6032) "threads" (running) 2.1 Thread 0x7ffff7fc1700 (LWP 6037) "threads" (running) 2.2 Thread 0x7ffff77c0700 (LWP 6038) "threads" (running) * 2.3 Thread 0x7ffff7fc2740 (LWP 6039) "threads" (running) (gdb) ... (gdb) thread 1.1 [Switching to thread 1.1 (Thread 0x7ffff7fc2740 (LWP 8155))] (gdb) ... etc. You can still use "thread NUM", in which case GDB infers you're referring to thread NUM of the current inferior. The $_thread convenience var and Python's InferiorThread.num attribute are remapped to the new per-inferior thread number. It's a backward compatibility break, but since it only matters when debugging multiple inferiors, I think it's worth doing. Because MI thread IDs need to be a single integer, we keep giving threads a global identifier, _in addition_ to the per-inferior number, and make MI always refer to the global thread IDs. IOW, nothing changes from a MI frontend's perspective. Similarly, since Python's Breakpoint.thread and Guile's breakpoint-thread/set-breakpoint-thread breakpoint methods need to work with integers, those are adjusted to work with global thread IDs too. Follow up patches will provide convenient means to access threads' global IDs. To avoid potencially confusing users (which also avoids updating much of the testsuite), if there's only one inferior and its ID is "1", IOW, the user hasn't done anything multi-process/inferior related, then the "INF." part of thread IDs is not shown. E.g,.: (gdb) info inferiors Num Description Executable * 1 process 15275 /home/pedro/gdb/tests/threads (gdb) info threads Id Target Id Frame * 1 Thread 0x7ffff7fc1740 (LWP 15275) "threads" main () at threads.c:40 (gdb) add-inferior Added inferior 2 (gdb) info threads Id Target Id Frame * 1.1 Thread 0x7ffff7fc1740 (LWP 15275) "threads" main () at threads.c:40 (gdb) No regressions on x86_64 Fedora 20. gdb/ChangeLog: 2016-01-13 Pedro Alves <palves@redhat.com> * NEWS: Mention that thread IDs are now per inferior and global thread IDs. * Makefile.in (SFILES): Add tid-parse.c. (COMMON_OBS): Add tid-parse.o. (HFILES_NO_SRCDIR): Add tid-parse.h. * ada-tasks.c: Adjust to use ptid_to_global_thread_id. * breakpoint.c (insert_breakpoint_locations) (remove_threaded_breakpoints, bpstat_check_breakpoint_conditions) (print_one_breakpoint_location, set_longjmp_breakpoint) (check_longjmp_breakpoint_for_call_dummy) (set_momentary_breakpoint): Adjust to use global IDs. (find_condition_and_thread, watch_command_1): Use parse_thread_id. (until_break_command, longjmp_bkpt_dtor) (breakpoint_re_set_thread, insert_single_step_breakpoint): Adjust to use global IDs. * dummy-frame.c (pop_dummy_frame_bpt): Adjust to use ptid_to_global_thread_id. * elfread.c (elf_gnu_ifunc_resolver_stop): Likewise. * gdbthread.h (struct thread_info): Rename field 'num' to 'global_num. Add new fields 'per_inf_num' and 'inf'. (thread_id_to_pid): Rename thread_id_to_pid to global_thread_id_to_ptid. (pid_to_thread_id): Rename to ... (ptid_to_global_thread_id): ... this. (valid_thread_id): Rename to ... (valid_global_thread_id): ... this. (find_thread_id): Rename to ... (find_thread_global_id): ... this. (ALL_THREADS, ALL_THREADS_BY_INFERIOR): Declare. (print_thread_info): Add comment. * tid-parse.h: New file. * tid-parse.c: New file. * infcmd.c (step_command_fsm_prepare) (step_command_fsm_should_stop): Adjust to use the global thread ID. (until_next_command, until_next_command) (finish_command_fsm_should_stop): Adjust to use the global thread ID. (attach_post_wait): Adjust to check the inferior number too. * inferior.h (struct inferior) <highest_thread_num>: New field. * infrun.c (handle_signal_stop) (insert_exception_resume_breakpoint) (insert_exception_resume_from_probe): Adjust to use the global thread ID. * record-btrace.c (record_btrace_open): Use global thread IDs. * remote.c (process_initial_stop_replies): Also consider the inferior number. * target.c (target_pre_inferior): Clear the inferior's highest thread num. * thread.c (clear_thread_inferior_resources): Adjust to use the global thread ID. (new_thread): New inferior parameter. Adjust to use it. Set both the thread's global ID and the thread's per-inferior ID. (add_thread_silent): Adjust. (find_thread_global_id): New. (find_thread_id): Make static. Adjust to rename. (valid_thread_id): Rename to ... (valid_global_thread_id): ... this. (pid_to_thread_id): Rename to ... (ptid_to_global_thread_id): ... this. (thread_id_to_pid): Rename to ... (global_thread_id_to_ptid): ... this. Adjust. (first_thread_of_process): Adjust. (do_captured_list_thread_ids): Adjust to use global thread IDs. (should_print_thread): New function. (print_thread_info): Rename to ... (print_thread_info_1): ... this, and add new show_global_ids parameter. Handle it. Iterate over inferiors. (print_thread_info): Reimplement as wrapper around print_thread_info_1. (show_inferior_qualified_tids): New function. (print_thread_id): Use it. (tp_array_compar): Compare inferior numbers too. (thread_apply_command): Use tid_range_parser. (do_captured_thread_select): Use parse_thread_id. (thread_id_make_value): Adjust. (_initialize_thread): Adjust "info threads" help string. * varobj.c (struct varobj_root): Update comment. (varobj_create): Adjust to use global thread IDs. (value_of_root_1): Adjust to use global_thread_id_to_ptid. * windows-tdep.c (display_tib): No longer accept an argument. * cli/cli-utils.c (get_number_trailer): Make extern. * cli/cli-utils.h (get_number_trailer): Declare. (get_number_const): Adjust documentation. * mi/mi-cmd-var.c (mi_cmd_var_update_iter): Adjust to use global thread IDs. * mi/mi-interp.c (mi_new_thread, mi_thread_exit) (mi_on_normal_stop, mi_output_running_pid, mi_on_resume): * mi/mi-main.c (mi_execute_command, mi_cmd_execute): Likewise. * guile/scm-breakpoint.c (gdbscm_set_breakpoint_thread_x): Likewise. * python/py-breakpoint.c (bppy_set_thread): Likewise. * python/py-finishbreakpoint.c (bpfinishpy_init): Likewise. * python/py-infthread.c (thpy_get_num): Add comment and return the per-inferior thread ID. (thread_object_getset): Update comment of "num". gdb/testsuite/ChangeLog: 2016-01-07 Pedro Alves <palves@redhat.com> * gdb.base/break.exp: Adjust to output changes. * gdb.base/hbreak2.exp: Likewise. * gdb.base/sepdebug.exp: Likewise. * gdb.base/watch_thread_num.exp: Likewise. * gdb.linespec/keywords.exp: Likewise. * gdb.multi/info-threads.exp: Likewise. * gdb.threads/thread-find.exp: Likewise. * gdb.multi/tids.c: New file. * gdb.multi/tids.exp: New file. gdb/doc/ChangeLog: 2016-01-07 Pedro Alves <palves@redhat.com> * gdb.texinfo (Threads): Document per-inferior thread IDs, qualified thread IDs, global thread IDs and thread ID lists. (Set Watchpoints, Thread-Specific Breakpoints): Adjust to refer to thread IDs. (Convenience Vars): Document the $_thread convenience variable. (Ada Tasks): Adjust to refer to thread IDs. (GDB/MI Async Records, GDB/MI Thread Commands, GDB/MI Ada Tasking Commands, GDB/MI Variable Objects): Update to mention global thread IDs. * guile.texi (Breakpoints In Guile) <breakpoint-thread/set-breakpoint-thread breakpoint>: Mention global thread IDs instead of thread IDs. * python.texi (Threads In Python): Adjust documentation of InferiorThread.num. (Breakpoint.thread): Mention global thread IDs instead of thread IDs.
2016-01-13 11:56:07 +01:00
/* The highest thread number this inferior ever had. */
int highest_thread_num = 0;
Per-inferior/Inferior-qualified thread IDs This commit changes GDB to track thread numbers per-inferior. Then, if you're debugging multiple inferiors, GDB displays "inferior-num.thread-num" instead of just "thread-num" whenever it needs to display a thread: (gdb) info inferiors Num Description Executable 1 process 6022 /home/pedro/gdb/tests/threads * 2 process 6037 /home/pedro/gdb/tests/threads (gdb) info threads Id Target Id Frame 1.1 Thread 0x7ffff7fc2740 (LWP 6022) "threads" (running) 1.2 Thread 0x7ffff77c0700 (LWP 6028) "threads" (running) 1.3 Thread 0x7ffff7fc2740 (LWP 6032) "threads" (running) 2.1 Thread 0x7ffff7fc1700 (LWP 6037) "threads" (running) 2.2 Thread 0x7ffff77c0700 (LWP 6038) "threads" (running) * 2.3 Thread 0x7ffff7fc2740 (LWP 6039) "threads" (running) (gdb) ... (gdb) thread 1.1 [Switching to thread 1.1 (Thread 0x7ffff7fc2740 (LWP 8155))] (gdb) ... etc. You can still use "thread NUM", in which case GDB infers you're referring to thread NUM of the current inferior. The $_thread convenience var and Python's InferiorThread.num attribute are remapped to the new per-inferior thread number. It's a backward compatibility break, but since it only matters when debugging multiple inferiors, I think it's worth doing. Because MI thread IDs need to be a single integer, we keep giving threads a global identifier, _in addition_ to the per-inferior number, and make MI always refer to the global thread IDs. IOW, nothing changes from a MI frontend's perspective. Similarly, since Python's Breakpoint.thread and Guile's breakpoint-thread/set-breakpoint-thread breakpoint methods need to work with integers, those are adjusted to work with global thread IDs too. Follow up patches will provide convenient means to access threads' global IDs. To avoid potencially confusing users (which also avoids updating much of the testsuite), if there's only one inferior and its ID is "1", IOW, the user hasn't done anything multi-process/inferior related, then the "INF." part of thread IDs is not shown. E.g,.: (gdb) info inferiors Num Description Executable * 1 process 15275 /home/pedro/gdb/tests/threads (gdb) info threads Id Target Id Frame * 1 Thread 0x7ffff7fc1740 (LWP 15275) "threads" main () at threads.c:40 (gdb) add-inferior Added inferior 2 (gdb) info threads Id Target Id Frame * 1.1 Thread 0x7ffff7fc1740 (LWP 15275) "threads" main () at threads.c:40 (gdb) No regressions on x86_64 Fedora 20. gdb/ChangeLog: 2016-01-13 Pedro Alves <palves@redhat.com> * NEWS: Mention that thread IDs are now per inferior and global thread IDs. * Makefile.in (SFILES): Add tid-parse.c. (COMMON_OBS): Add tid-parse.o. (HFILES_NO_SRCDIR): Add tid-parse.h. * ada-tasks.c: Adjust to use ptid_to_global_thread_id. * breakpoint.c (insert_breakpoint_locations) (remove_threaded_breakpoints, bpstat_check_breakpoint_conditions) (print_one_breakpoint_location, set_longjmp_breakpoint) (check_longjmp_breakpoint_for_call_dummy) (set_momentary_breakpoint): Adjust to use global IDs. (find_condition_and_thread, watch_command_1): Use parse_thread_id. (until_break_command, longjmp_bkpt_dtor) (breakpoint_re_set_thread, insert_single_step_breakpoint): Adjust to use global IDs. * dummy-frame.c (pop_dummy_frame_bpt): Adjust to use ptid_to_global_thread_id. * elfread.c (elf_gnu_ifunc_resolver_stop): Likewise. * gdbthread.h (struct thread_info): Rename field 'num' to 'global_num. Add new fields 'per_inf_num' and 'inf'. (thread_id_to_pid): Rename thread_id_to_pid to global_thread_id_to_ptid. (pid_to_thread_id): Rename to ... (ptid_to_global_thread_id): ... this. (valid_thread_id): Rename to ... (valid_global_thread_id): ... this. (find_thread_id): Rename to ... (find_thread_global_id): ... this. (ALL_THREADS, ALL_THREADS_BY_INFERIOR): Declare. (print_thread_info): Add comment. * tid-parse.h: New file. * tid-parse.c: New file. * infcmd.c (step_command_fsm_prepare) (step_command_fsm_should_stop): Adjust to use the global thread ID. (until_next_command, until_next_command) (finish_command_fsm_should_stop): Adjust to use the global thread ID. (attach_post_wait): Adjust to check the inferior number too. * inferior.h (struct inferior) <highest_thread_num>: New field. * infrun.c (handle_signal_stop) (insert_exception_resume_breakpoint) (insert_exception_resume_from_probe): Adjust to use the global thread ID. * record-btrace.c (record_btrace_open): Use global thread IDs. * remote.c (process_initial_stop_replies): Also consider the inferior number. * target.c (target_pre_inferior): Clear the inferior's highest thread num. * thread.c (clear_thread_inferior_resources): Adjust to use the global thread ID. (new_thread): New inferior parameter. Adjust to use it. Set both the thread's global ID and the thread's per-inferior ID. (add_thread_silent): Adjust. (find_thread_global_id): New. (find_thread_id): Make static. Adjust to rename. (valid_thread_id): Rename to ... (valid_global_thread_id): ... this. (pid_to_thread_id): Rename to ... (ptid_to_global_thread_id): ... this. (thread_id_to_pid): Rename to ... (global_thread_id_to_ptid): ... this. Adjust. (first_thread_of_process): Adjust. (do_captured_list_thread_ids): Adjust to use global thread IDs. (should_print_thread): New function. (print_thread_info): Rename to ... (print_thread_info_1): ... this, and add new show_global_ids parameter. Handle it. Iterate over inferiors. (print_thread_info): Reimplement as wrapper around print_thread_info_1. (show_inferior_qualified_tids): New function. (print_thread_id): Use it. (tp_array_compar): Compare inferior numbers too. (thread_apply_command): Use tid_range_parser. (do_captured_thread_select): Use parse_thread_id. (thread_id_make_value): Adjust. (_initialize_thread): Adjust "info threads" help string. * varobj.c (struct varobj_root): Update comment. (varobj_create): Adjust to use global thread IDs. (value_of_root_1): Adjust to use global_thread_id_to_ptid. * windows-tdep.c (display_tib): No longer accept an argument. * cli/cli-utils.c (get_number_trailer): Make extern. * cli/cli-utils.h (get_number_trailer): Declare. (get_number_const): Adjust documentation. * mi/mi-cmd-var.c (mi_cmd_var_update_iter): Adjust to use global thread IDs. * mi/mi-interp.c (mi_new_thread, mi_thread_exit) (mi_on_normal_stop, mi_output_running_pid, mi_on_resume): * mi/mi-main.c (mi_execute_command, mi_cmd_execute): Likewise. * guile/scm-breakpoint.c (gdbscm_set_breakpoint_thread_x): Likewise. * python/py-breakpoint.c (bppy_set_thread): Likewise. * python/py-finishbreakpoint.c (bpfinishpy_init): Likewise. * python/py-infthread.c (thpy_get_num): Add comment and return the per-inferior thread ID. (thread_object_getset): Update comment of "num". gdb/testsuite/ChangeLog: 2016-01-07 Pedro Alves <palves@redhat.com> * gdb.base/break.exp: Adjust to output changes. * gdb.base/hbreak2.exp: Likewise. * gdb.base/sepdebug.exp: Likewise. * gdb.base/watch_thread_num.exp: Likewise. * gdb.linespec/keywords.exp: Likewise. * gdb.multi/info-threads.exp: Likewise. * gdb.threads/thread-find.exp: Likewise. * gdb.multi/tids.c: New file. * gdb.multi/tids.exp: New file. gdb/doc/ChangeLog: 2016-01-07 Pedro Alves <palves@redhat.com> * gdb.texinfo (Threads): Document per-inferior thread IDs, qualified thread IDs, global thread IDs and thread ID lists. (Set Watchpoints, Thread-Specific Breakpoints): Adjust to refer to thread IDs. (Convenience Vars): Document the $_thread convenience variable. (Ada Tasks): Adjust to refer to thread IDs. (GDB/MI Async Records, GDB/MI Thread Commands, GDB/MI Ada Tasking Commands, GDB/MI Variable Objects): Update to mention global thread IDs. * guile.texi (Breakpoints In Guile) <breakpoint-thread/set-breakpoint-thread breakpoint>: Mention global thread IDs instead of thread IDs. * python.texi (Threads In Python): Adjust documentation of InferiorThread.num. (Breakpoint.thread): Mention global thread IDs instead of thread IDs.
2016-01-13 11:56:07 +01:00
gdb/ Rename and move inferior_thread_state and inferior_status. * gdbthread.h (struct thread_control_state): New struct, move fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step and stop_bpstat here from struct thread_info. (struct thread_suspend_state): New struct, move field stop_signal here from struct thread_info. (struct thread_info): Move the fields above from this struct. * inferior.h: Move the inferior_thread_state and inferior_status declarations comment to their definitions at infrun.c. (struct inferior_control_state): New struct, move field stop_soon from struct inferior here. (struct inferior_suspend_state): New empty struct. (struct inferior): New fields control and suspend. Move out field stop_soon. * infrun.c (struct inferior_thread_state): Rename to ... (infcall_suspend_state): ... here. Replace field stop_signal by fields thread_suspend and inferior_suspend. (save_inferior_thread_state): Rename to ... (save_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (restore_inferior_thread_state): Rename to ... (restore_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (do_restore_inferior_thread_state_cleanup): Rename to ... (do_restore_infcall_suspend_state_cleanup): ... here. (make_cleanup_restore_inferior_thread_state): Rename to ... (make_cleanup_restore_infcall_suspend_state): ... here. (discard_inferior_thread_state): Rename to ... (discard_infcall_suspend_state): ... here. (get_inferior_thread_state_regcache): Rename to ... (get_infcall_suspend_state_regcache): ... here. (struct inferior_status): Rename to ... (struct infcall_control_state): ... here. Replace fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step, stop_bpstat and stop_soon by fields thread_control and inferior_control. (save_inferior_status): Rename to ... (save_infcall_control_state): ... here. Update the code for new fields. (restore_inferior_status): Rename to ... (restore_infcall_control_state): ... here. Update the code for new fields. (do_restore_inferior_status_cleanup): Rename to ... (do_restore_infcall_control_state_cleanup): ... here. (make_cleanup_restore_inferior_status): Rename to ... (make_cleanup_restore_infcall_control_state): ... here. (discard_inferior_status): Rename to ... (discard_infcall_control_state): ... here. * alpha-tdep.c, breakpoint.c, dummy-frame.c, dummy-frame.h, exceptions.c, fbsd-nat.c, gdbthread.h, infcall.c, infcmd.c, inferior.c, inferior.h, infrun.c, linux-nat.c, mi/mi-interp.c, mips-tdep.c, procfs.c, solib-irix.c, solib-osf.c, solib-spu.c, solib-sunos.c, solib-svr4.c, thread.c, windows-nat.c: Update all the references to the moved fields and renamed functions.
2010-11-28 05:31:25 +01:00
/* State of GDB control of inferior process execution.
See `struct inferior_control_state'. */
inferior_control_state control;
gdb/ Rename and move inferior_thread_state and inferior_status. * gdbthread.h (struct thread_control_state): New struct, move fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step and stop_bpstat here from struct thread_info. (struct thread_suspend_state): New struct, move field stop_signal here from struct thread_info. (struct thread_info): Move the fields above from this struct. * inferior.h: Move the inferior_thread_state and inferior_status declarations comment to their definitions at infrun.c. (struct inferior_control_state): New struct, move field stop_soon from struct inferior here. (struct inferior_suspend_state): New empty struct. (struct inferior): New fields control and suspend. Move out field stop_soon. * infrun.c (struct inferior_thread_state): Rename to ... (infcall_suspend_state): ... here. Replace field stop_signal by fields thread_suspend and inferior_suspend. (save_inferior_thread_state): Rename to ... (save_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (restore_inferior_thread_state): Rename to ... (restore_infcall_suspend_state): ... here. New variable inf. Update the code for new fields. (do_restore_inferior_thread_state_cleanup): Rename to ... (do_restore_infcall_suspend_state_cleanup): ... here. (make_cleanup_restore_inferior_thread_state): Rename to ... (make_cleanup_restore_infcall_suspend_state): ... here. (discard_inferior_thread_state): Rename to ... (discard_infcall_suspend_state): ... here. (get_inferior_thread_state_regcache): Rename to ... (get_infcall_suspend_state_regcache): ... here. (struct inferior_status): Rename to ... (struct infcall_control_state): ... here. Replace fields step_range_start, step_range_end, step_frame_id, step_stack_frame_id, trap_expected, proceed_to_finish, in_infcall, step_over_calls, stop_step, stop_bpstat and stop_soon by fields thread_control and inferior_control. (save_inferior_status): Rename to ... (save_infcall_control_state): ... here. Update the code for new fields. (restore_inferior_status): Rename to ... (restore_infcall_control_state): ... here. Update the code for new fields. (do_restore_inferior_status_cleanup): Rename to ... (do_restore_infcall_control_state_cleanup): ... here. (make_cleanup_restore_inferior_status): Rename to ... (make_cleanup_restore_infcall_control_state): ... here. (discard_inferior_status): Rename to ... (discard_infcall_control_state): ... here. * alpha-tdep.c, breakpoint.c, dummy-frame.c, dummy-frame.h, exceptions.c, fbsd-nat.c, gdbthread.h, infcall.c, infcmd.c, inferior.c, inferior.h, infrun.c, linux-nat.c, mi/mi-interp.c, mips-tdep.c, procfs.c, solib-irix.c, solib-osf.c, solib-spu.c, solib-sunos.c, solib-svr4.c, thread.c, windows-nat.c: Update all the references to the moved fields and renamed functions.
2010-11-28 05:31:25 +01:00
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* True if this was an auto-created inferior, e.g. created from
following a fork; false, if this inferior was manually added by
the user, and we should not attempt to prune it
automatically. */
bool removable = false;
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* The address space bound to this inferior. */
struct address_space *aspace = NULL;
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* The program space bound to this inferior. */
struct program_space *pspace = NULL;
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
Per-inferior args and tty and environment. * infcmd.c (inferior_args): Rename to ... (inferior_args_scratch): ... this. (inferior_io_terminal): Rename to ... (inferior_io_terminal_scratch): ... this. (inferior_argc, inferior_argv): Remove. (set_inferior_io_terminal, get_inferior_io_terminal): Store inside current_inferior(). (set_inferior_tty_command, show_inferior_tty_command): New. (get_inferior_args, set_inferior_args): Store inside current_inferior(). (notice_args_set): Likewise and rename to... (set_args_command): ... this. (set_inferior_args_vector): Likewise. (notice_args_read): Rename to... (show_args_command): ...new. (tty_command): Remove. (run_command_1): Don't free old args, as they are freed by set_inferior_arg now. (run_no_args_command): Likewise. (inferior_environ): Remove. (run_command_1): Use environment of the current inferior. (environment_info, set_environment_command) (unset_environment_command, path_info, path_command): Likewise. (_initialize_infcmd): Adjust for function and variable renames. Do not init inferior_environ. * inferior.h (set_inferior_arg): Adjust prototype. (struct inferior): New fields args, argc, argv, terminal, environment. (inferior_environ): Remove declaration. * inferior.c (free_inferior): Free new fields. (add_inferior_silent): Initialize 'environment' field. * main.c (captured_main): Set arguments only after the initial inferior has been created. Set set_inferior_io_terminal, not tty_command. * mi/mi-main.c (mi_cmd_env_path): Use environment of the current inferior. (_initialize_mi_cmd_env): Adjust for disappearance of global inferior_environ. * solib.c (solib_find): Use environment of the current inferior.
2010-01-20 15:23:07 +01:00
/* The arguments string to use when running. */
char *args = NULL;
Per-inferior args and tty and environment. * infcmd.c (inferior_args): Rename to ... (inferior_args_scratch): ... this. (inferior_io_terminal): Rename to ... (inferior_io_terminal_scratch): ... this. (inferior_argc, inferior_argv): Remove. (set_inferior_io_terminal, get_inferior_io_terminal): Store inside current_inferior(). (set_inferior_tty_command, show_inferior_tty_command): New. (get_inferior_args, set_inferior_args): Store inside current_inferior(). (notice_args_set): Likewise and rename to... (set_args_command): ... this. (set_inferior_args_vector): Likewise. (notice_args_read): Rename to... (show_args_command): ...new. (tty_command): Remove. (run_command_1): Don't free old args, as they are freed by set_inferior_arg now. (run_no_args_command): Likewise. (inferior_environ): Remove. (run_command_1): Use environment of the current inferior. (environment_info, set_environment_command) (unset_environment_command, path_info, path_command): Likewise. (_initialize_infcmd): Adjust for function and variable renames. Do not init inferior_environ. * inferior.h (set_inferior_arg): Adjust prototype. (struct inferior): New fields args, argc, argv, terminal, environment. (inferior_environ): Remove declaration. * inferior.c (free_inferior): Free new fields. (add_inferior_silent): Initialize 'environment' field. * main.c (captured_main): Set arguments only after the initial inferior has been created. Set set_inferior_io_terminal, not tty_command. * mi/mi-main.c (mi_cmd_env_path): Use environment of the current inferior. (_initialize_mi_cmd_env): Adjust for disappearance of global inferior_environ. * solib.c (solib_find): Use environment of the current inferior.
2010-01-20 15:23:07 +01:00
/* The size of elements in argv. */
int argc = 0;
Per-inferior args and tty and environment. * infcmd.c (inferior_args): Rename to ... (inferior_args_scratch): ... this. (inferior_io_terminal): Rename to ... (inferior_io_terminal_scratch): ... this. (inferior_argc, inferior_argv): Remove. (set_inferior_io_terminal, get_inferior_io_terminal): Store inside current_inferior(). (set_inferior_tty_command, show_inferior_tty_command): New. (get_inferior_args, set_inferior_args): Store inside current_inferior(). (notice_args_set): Likewise and rename to... (set_args_command): ... this. (set_inferior_args_vector): Likewise. (notice_args_read): Rename to... (show_args_command): ...new. (tty_command): Remove. (run_command_1): Don't free old args, as they are freed by set_inferior_arg now. (run_no_args_command): Likewise. (inferior_environ): Remove. (run_command_1): Use environment of the current inferior. (environment_info, set_environment_command) (unset_environment_command, path_info, path_command): Likewise. (_initialize_infcmd): Adjust for function and variable renames. Do not init inferior_environ. * inferior.h (set_inferior_arg): Adjust prototype. (struct inferior): New fields args, argc, argv, terminal, environment. (inferior_environ): Remove declaration. * inferior.c (free_inferior): Free new fields. (add_inferior_silent): Initialize 'environment' field. * main.c (captured_main): Set arguments only after the initial inferior has been created. Set set_inferior_io_terminal, not tty_command. * mi/mi-main.c (mi_cmd_env_path): Use environment of the current inferior. (_initialize_mi_cmd_env): Adjust for disappearance of global inferior_environ. * solib.c (solib_find): Use environment of the current inferior.
2010-01-20 15:23:07 +01:00
/* The vector version of arguments. If ARGC is nonzero,
then we must compute ARGS from this (via the target).
This is always coming from main's argv and therefore
should never be freed. */
char **argv = NULL;
Per-inferior args and tty and environment. * infcmd.c (inferior_args): Rename to ... (inferior_args_scratch): ... this. (inferior_io_terminal): Rename to ... (inferior_io_terminal_scratch): ... this. (inferior_argc, inferior_argv): Remove. (set_inferior_io_terminal, get_inferior_io_terminal): Store inside current_inferior(). (set_inferior_tty_command, show_inferior_tty_command): New. (get_inferior_args, set_inferior_args): Store inside current_inferior(). (notice_args_set): Likewise and rename to... (set_args_command): ... this. (set_inferior_args_vector): Likewise. (notice_args_read): Rename to... (show_args_command): ...new. (tty_command): Remove. (run_command_1): Don't free old args, as they are freed by set_inferior_arg now. (run_no_args_command): Likewise. (inferior_environ): Remove. (run_command_1): Use environment of the current inferior. (environment_info, set_environment_command) (unset_environment_command, path_info, path_command): Likewise. (_initialize_infcmd): Adjust for function and variable renames. Do not init inferior_environ. * inferior.h (set_inferior_arg): Adjust prototype. (struct inferior): New fields args, argc, argv, terminal, environment. (inferior_environ): Remove declaration. * inferior.c (free_inferior): Free new fields. (add_inferior_silent): Initialize 'environment' field. * main.c (captured_main): Set arguments only after the initial inferior has been created. Set set_inferior_io_terminal, not tty_command. * mi/mi-main.c (mi_cmd_env_path): Use environment of the current inferior. (_initialize_mi_cmd_env): Adjust for disappearance of global inferior_environ. * solib.c (solib_find): Use environment of the current inferior.
2010-01-20 15:23:07 +01:00
Implement "set cwd" command on GDB This commit adds new "set/show cwd" commands, which are used to set/show the current working directory of the inferior that will be started. The idea here is that "set cwd" will become the de facto way of setting the inferior's cwd. Currently, the user can use "cd" for that, but there are side effects: with "cd", GDB also switches to another directory, and that can impact the loading of scripts and other files. With "set cwd", we separate the logic into a new command. To maintain backward compatibility, if the user issues a "cd" command but doesn't use "set cwd", then the inferior's cwd will still be changed according to what the user specified. However, "set cwd" has precedence over "cd", so it can always be used to override it. "set cwd" works in the following way: - If the user sets the inferior's cwd by using "set cwd", then this directory is saved into current_inferior ()->cwd and is used when the inferior is started (see below). - If the user doesn't set the inferior's cwd by using "set cwd", but rather use the "cd" command as before, then this directory is inherited by the inferior because GDB will have chdir'd into it. On Unix-like hosts, the way the directory is changed before the inferior execution is by expanding the user set directory before the fork, and then "chdir" after the call to fork/vfork on "fork_inferior", but before the actual execution. On Windows, the inferior cwd set by the user is passed directly to the CreateProcess call, which takes care of the actual chdir for us. This way, we'll make sure that GDB's cwd is not affected by the user set cwd. gdb/ChangeLog: 2017-10-04 Sergio Durigan Junior <sergiodj@redhat.com> * NEWS (New commands): Mention "set/show cwd". * cli/cli-cmds.c (_initialize_cli_cmds): Mention "set cwd" on "cd" command's help text. * common/common-inferior.h (get_inferior_cwd): New prototype. * infcmd.c (inferior_cwd_scratch): New global variable. (set_inferior_cwd): New function. (get_inferior_cwd): Likewise. (set_cwd_command): Likewise. (show_cwd_command): Likewise. (_initialize_infcmd): Add "set/show cwd" commands. * inferior.h (class inferior) <cwd>: New field. * nat/fork-inferior.c: Include "gdb_tilde_expand.h". (fork_inferior): Change inferior's cwd before its execution. * windows-nat.c (windows_create_inferior): Pass inferior's cwd to CreateProcess. gdb/gdbserver/ChangeLog: 2017-10-04 Sergio Durigan Junior <sergiodj@redhat.com> * inferiors.c (current_inferior_cwd): New global variable. (get_inferior_cwd): New function. * inferiors.h (struct process_info) <cwd>: New field. gdb/doc/ChangeLog: 2017-10-04 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.texinfo (Starting your Program) <The working directory.>: Mention new "set cwd" command. (Working Directory) <Your Program's Working Directory>: Rephrase to explain that "set cwd" exists and is the default way to change the inferior's cwd. gdb/testsuite/ChangeLog: 2017-10-04 Sergio Durigan Junior <sergiodj@redhat.com> * gdb.base/set-cwd.c: New file. * gdb.base/set-cwd.exp: Likewise.
2017-09-11 07:13:50 +02:00
/* The current working directory that will be used when starting
this inferior. */
gdb::unique_xmalloc_ptr<char> cwd;
Per-inferior target_terminal state, fix PR gdb/13211, more In my multi-target branch I ran into problems with GDB's terminal handling that exist in master as well, with multi-inferior debugging. This patch adds a testcase for said problems (gdb.multi/multi-term-settings.exp), fixes the problems, fixes PR gdb/13211 as well (and adds a testcase for that too, gdb.base/interrupt-daemon.exp). The basis of the problem I ran into is the following. Consider a scenario where you have: - inferior 1 - started with "attach", process is running on some other terminal. - inferior 2 - started with "run", process is sharing gdb's terminal. In this scenario, when you stop/resume both inferiors, you want GDB to save/restore the terminal settings of inferior 2, the one that is sharing GDB's terminal. I.e., you want inferior 2 to "own" the terminal (in target_terminal::is_ours/target_terminal::is_inferior sense). Unfortunately, that's not what you get currently. Because GDB doesn't know whether an attached inferior is actually sharing GDB's terminal, it tries to save/restore its settings anyway, ignoring errors. In this case, this is pointless, because inferior 1 is running on a different terminal, but GDB doesn't know better. And then, because it is only possible to have the terminal settings of a single inferior be in effect at a time, or make one inferior/pgrp be the terminal's foreground pgrp (aka, only one inferior can "own" the terminal, ignoring fork children here), if GDB happens to try to restore the terminal settings of inferior 1 first, then GDB never restores the terminal settings of inferior 2. This patch fixes that and a few things more along the way: - Moves enum target_terminal::terminal_state out of the target_terminal class (it's currently private) and makes it a scoped enum so that it can be easily used elsewhere. - Replaces the inflow.c:terminal_is_ours boolean with a target_terminal_state variable. This allows distinguishing is_ours and is_ours_for_output states. This allows finally making child_terminal_ours_1 do something with its "output_only" parameter. - Makes each inferior have its own copy of the is_ours/is_ours_for_output/is_inferior state. - Adds a way for GDB to tell whether the inferior is sharing GDB's terminal. Works best on Linux and Solaris; the fallback works just as well as currently. - With that, we can remove the inf->attach_flag tests from child_terminal_inferior/child_terminal_ours. - Currently target_ops.to_ours is responsible for both saving the current inferior's terminal state, and restoring gdb's state. Because each inferior has its own terminal state (possibly handled by different targets in a multi-target world, even), we need to split the inferior-saving part from the gdb-restoring part. The patch adds a new target_ops.to_save_inferior target method for that. - Adds a new target_terminal::save_inferior() function, so that sequences like: scoped_restore_terminal_state save_state; target_terminal::ours_for_output (); ... restore back inferiors that were target_terminal_state::is_inferior before back to is_inferior, and leaves inferiors that were is_ours alone. - Along the way, this adds a default implementation of target_pass_ctrlc to inflow.c (for inf-child.c), that handles passing the Ctrl-C to a process running on GDB's terminal or to some other process otherwise. - Similarly, adds a new target default implementation of target_interrupt, for the "interrupt" command. The current implementation of this hook in inf-ptrace.c kills the whole process group, but that's incorrect/undesirable because we may not be attached to all processes in the process group. And also, it's incorrect because inferior_process_group() doesn't really return the inferior's real process group id if the inferior is not a process group leader... This is the cause of PR gdb/13211 [1], which this patch fixes. While at it, that target method's "ptid" parameter is eliminated, because it's not really used. - A new test is included that exercises and fixes PR gdb/13211, and also fixes a GDB issue reported on stackoverflow that I ran into while working on this [2]. The problem is similar to PR gdb/13211, except that it also triggers with Ctrl-C. When debugging a daemon (i.e., a process that disconnects from the controlling terminal and is not a process group leader, then Ctrl-C doesn't work, you just can't interrupt the inferior at all, resulting in a hung debug session. The problem is that since the inferior is no longer associated with gdb's session / controlling terminal, then trying to put the inferior in the foreground fails. And so Ctrl-C never reaches the inferior directly. pass_signal is only used when the inferior is attached, but that is not the case here. This is fixed by the new child_pass_ctrlc. Without the fix, the new interrupt-daemon.exp testcase fails with timeout waiting for a SIGINT that never arrives. [1] PR gdb/13211 - Async / Process group and interrupt not working https://sourceware.org/bugzilla/show_bug.cgi?id=13211 [2] GDB not reacting Ctrl-C when after fork() and setsid() https://stackoverflow.com/questions/46101292/gdb-not-reacting-ctrl-c-when-after-fork-and-setsid Note this patch does _not_ fix: - PR gdb/14559 - The 'interrupt' command does not work if sigwait is in use https://sourceware.org/bugzilla/show_bug.cgi?id=14559 - PR gdb/9425 - When using "sigwait" GDB doesn't trap SIGINT. Ctrl+C terminates program when should break gdb. https://sourceware.org/bugzilla/show_bug.cgi?id=9425 The only way to fix that that I know of (without changing the kernel) is to make GDB put inferiors in a separate session (create a pseudo-tty master/slave pair, make the inferior run with the slave as its terminal, and have gdb pump output/input on the master end). gdb/ChangeLog: 2018-01-30 Pedro Alves <palves@redhat.com> PR gdb/13211 * config.in, configure: Regenerate. * configure.ac: Check for getpgid. * go32-nat.c (go32_pass_ctrlc): New. (go32_target): Install it. * inf-child.c (inf_child_target): Install child_terminal_save_inferior, child_pass_ctrlc and child_interrupt. * inf-ptrace.c (inf_ptrace_interrupt): Delete. (inf_ptrace_target): No longer install it. * infcmd.c (interrupt_target_1): Adjust. * inferior.h (child_terminal_save_inferior, child_pass_ctrlc) (child_interrupt): Declare. (inferior::terminal_state): New. * inflow.c (struct terminal_info): Update comments. (inferior_process_group): Delete. (terminal_is_ours): Delete. (gdb_tty_state): New. (child_terminal_init): Adjust. (is_gdb_terminal, sharing_input_terminal_1) (sharing_input_terminal): New functions. (child_terminal_inferior): Adjust. Use sharing_input_terminal. Set the process's actual process group in the foreground if possible. Handle is_ours_for_output/is_ours distinction. Don't mark terminal as the inferior's if not sharing GDB's terminal. Don't check attach_flag. (child_terminal_ours_for_output, child_terminal_ours): Adjust to pass down a target_terminal_state. (child_terminal_save_inferior): New, factored out from ... (child_terminal_ours_1): ... this. Handle target_terminal_state::is_ours_for_output. (child_interrupt, child_pass_ctrlc): New. (inflow_inferior_exit): Clear the inferior's terminal_state. (copy_terminal_info): Copy the inferior's terminal state. (_initialize_inflow): Remove reference to terminal_is_ours. * inflow.h (inferior_process_group): Delete. * nto-procfs.c (nto_handle_sigint, procfs_interrupt): Adjust. * procfs.c (procfs_target): Don't install procfs_interrupt. (procfs_interrupt): Delete. * remote.c (remote_serial_quit_handler): Adjust. (remote_interrupt): Remove ptid parameter. Adjust. * target-delegates.c: Regenerate. * target.c: Include "terminal.h". (target_terminal::terminal_state): Rename to ... (target_terminal::m_terminal_state): ... this. (target_terminal::init): Adjust. (target_terminal::inferior): Adjust to per-inferior terminal_state. (target_terminal::restore_inferior, target_terminal_is_ours_kind): New. (target_terminal::ours, target_terminal::ours_for_output): Use target_terminal_is_ours_kind. (target_interrupt): Remove ptid parameter. Adjust. (default_target_pass_ctrlc): Adjust. * target.h (target_ops::to_terminal_save_inferior): New field. (target_ops::to_interrupt): Remove ptid_t parameter. (target_interrupt): Remove ptid_t parameter. Update comment. (target_pass_ctrlc): Update comment. * target/target.h (target_terminal_state): New scoped enum, factored out of ... (target_terminal::terminal_state): ... here. (target_terminal::inferior): Update comments. (target_terminal::restore_inferior): New. (target_terminal::is_inferior, target_terminal::is_ours) (target_terminal::is_ours_for_output): Adjust. (target_terminal::scoped_restore_terminal_state): Adjust to rename, and call restore_inferior() instead of inferior(). (target_terminal::scoped_restore_terminal_state::m_state): Change type. (target_terminal::terminal_state): Rename to ... (target_terminal::m_terminal_state): ... this and change type. gdb/gdbserver/ChangeLog: 2018-01-30 Pedro Alves <palves@redhat.com> PR gdb/13211 * target.c (target_terminal::terminal_state): Rename to ... (target_terminal::m_terminal_state): ... this. gdb/testsuite/ChangeLog: 2018-01-30 Pedro Alves <palves@redhat.com> PR gdb/13211 * gdb.base/interrupt-daemon.c: New. * gdb.base/interrupt-daemon.exp: New. * gdb.multi/multi-term-settings.c: New. * gdb.multi/multi-term-settings.exp: New.
2018-01-30 15:23:51 +01:00
/* The terminal state as set by the last target_terminal::terminal_*
call. */
target_terminal_state terminal_state = target_terminal_state::is_ours;
Per-inferior args and tty and environment. * infcmd.c (inferior_args): Rename to ... (inferior_args_scratch): ... this. (inferior_io_terminal): Rename to ... (inferior_io_terminal_scratch): ... this. (inferior_argc, inferior_argv): Remove. (set_inferior_io_terminal, get_inferior_io_terminal): Store inside current_inferior(). (set_inferior_tty_command, show_inferior_tty_command): New. (get_inferior_args, set_inferior_args): Store inside current_inferior(). (notice_args_set): Likewise and rename to... (set_args_command): ... this. (set_inferior_args_vector): Likewise. (notice_args_read): Rename to... (show_args_command): ...new. (tty_command): Remove. (run_command_1): Don't free old args, as they are freed by set_inferior_arg now. (run_no_args_command): Likewise. (inferior_environ): Remove. (run_command_1): Use environment of the current inferior. (environment_info, set_environment_command) (unset_environment_command, path_info, path_command): Likewise. (_initialize_infcmd): Adjust for function and variable renames. Do not init inferior_environ. * inferior.h (set_inferior_arg): Adjust prototype. (struct inferior): New fields args, argc, argv, terminal, environment. (inferior_environ): Remove declaration. * inferior.c (free_inferior): Free new fields. (add_inferior_silent): Initialize 'environment' field. * main.c (captured_main): Set arguments only after the initial inferior has been created. Set set_inferior_io_terminal, not tty_command. * mi/mi-main.c (mi_cmd_env_path): Use environment of the current inferior. (_initialize_mi_cmd_env): Adjust for disappearance of global inferior_environ. * solib.c (solib_find): Use environment of the current inferior.
2010-01-20 15:23:07 +01:00
/* Environment to use for running inferior,
in format described in environ.h. */
C++ify gdb/common/environ.c As part of the preparation necessary for my upcoming task, I'd like to propose that we turn gdb_environ into a class. The approach taken here is simple: the class gdb_environ contains everything that is needed to manipulate the environment variables. These variables are stored in an std::vector<char *>, which can be converted to a 'char **' and passed as argument to functions that need it. The usage has not changed much. As per Pedro's suggestion, this class uses a static factory method initialization. This means that when an instance is created, it is initially empty. When needed, it has to be initialized using the static method 'from_host_environ'. As mentioned before, this is a preparation for an upcoming work that I will be posting in the next few weeks or so. For that work, I'll probably create another data structure that will contain all the environment variables that were set by the user using the 'set environment' command, because I'll need access to them. This will be much easier with the class-ification of gdb_environ. As noted, this has been regression-tested with the new version of environ.exp and no regressions were found. gdb/ChangeLog: 2017-06-20 Sergio Durigan Junior <sergiodj@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add 'unittests/environ-selftests.c'. (SUBDIR_UNITTESTS_OBS): Add 'environ-selftests.o'. * charset.c (find_charset_names): Declare object 'iconv_env'. Update code to use 'iconv_env' object. Remove call to 'free_environ'. * common/environ.c: Include <utility>. (make_environ): Delete function. (free_environ): Delete function. (gdb_environ::clear): New function. (gdb_environ::operator=): New function. (gdb_environ::get): Likewise. (environ_vector): Delete function. (set_in_environ): Delete function. (gdb_environ::set): New function. (unset_in_environ): Delete function. (gdb_environ::unset): New function. (gdb_environ::envp): Likewise. * common/environ.h: Include <vector>. (struct gdb_environ): Delete; transform into... (class gdb_environ): ... this class. (free_environ): Delete prototype. (init_environ, get_in_environ, set_in_environ, unset_in_environ, environ_vector): Likewise. * infcmd.c (run_command_1): Update code to call 'envp' from 'gdb_environ' class. (environment_info): Update code to call methods from 'gdb_environ' class. (unset_environment_command): Likewise. (path_info): Likewise. (path_command): Likewise. * inferior.c (inferior::~inferior): Delete call to 'free_environ'. (inferior::inferior): Initialize 'environment' using the host's information. * inferior.h: Remove forward declaration of 'struct gdb_environ'. Include "environ.h". (class inferior) <environment>: Change type from 'struct gdb_environ' to 'gdb_environ'. * mi/mi-cmd-env.c (mi_cmd_env_path): Update code to call methods from 'gdb_environ' class. * solib.c (solib_find_1): Likewise * unittests/environ-selftests.c: New file. gdb/gdbserver/ChangeLog: 2017-06-20 Sergio Durigan Junior <sergiodj@redhat.com> * linux-low.c (linux_create_inferior): Adjust code to access the environment information via 'gdb_environ' class. * lynx-low.c (lynx_create_inferior): Likewise. * server.c (our_environ): Make it an instance of 'gdb_environ'. (get_environ): Return a pointer to 'our_environ'. (captured_main): Initialize 'our_environ'. * server.h (get_environ): Adjust prototype. * spu-low.c (spu_create_inferior): Adjust code to access the environment information via 'gdb_environ' class.
2017-02-11 03:19:44 +01:00
gdb_environ environment;
Per-inferior args and tty and environment. * infcmd.c (inferior_args): Rename to ... (inferior_args_scratch): ... this. (inferior_io_terminal): Rename to ... (inferior_io_terminal_scratch): ... this. (inferior_argc, inferior_argv): Remove. (set_inferior_io_terminal, get_inferior_io_terminal): Store inside current_inferior(). (set_inferior_tty_command, show_inferior_tty_command): New. (get_inferior_args, set_inferior_args): Store inside current_inferior(). (notice_args_set): Likewise and rename to... (set_args_command): ... this. (set_inferior_args_vector): Likewise. (notice_args_read): Rename to... (show_args_command): ...new. (tty_command): Remove. (run_command_1): Don't free old args, as they are freed by set_inferior_arg now. (run_no_args_command): Likewise. (inferior_environ): Remove. (run_command_1): Use environment of the current inferior. (environment_info, set_environment_command) (unset_environment_command, path_info, path_command): Likewise. (_initialize_infcmd): Adjust for function and variable renames. Do not init inferior_environ. * inferior.h (set_inferior_arg): Adjust prototype. (struct inferior): New fields args, argc, argv, terminal, environment. (inferior_environ): Remove declaration. * inferior.c (free_inferior): Free new fields. (add_inferior_silent): Initialize 'environment' field. * main.c (captured_main): Set arguments only after the initial inferior has been created. Set set_inferior_io_terminal, not tty_command. * mi/mi-main.c (mi_cmd_env_path): Use environment of the current inferior. (_initialize_mi_cmd_env): Adjust for disappearance of global inferior_environ. * solib.c (solib_find): Use environment of the current inferior.
2010-01-20 15:23:07 +01:00
/* True if this child process was attached rather than forked. */
bool attach_flag = false;
Remove the attach_flag global, and make it per-inferior. * inferior.h (attach_flag): Delete. (inferior_process): Declare. * solib.c (update_solib_list): Adjust. * gnu-nat.c (gnu_create_inferior, gnu_attach): Adjust. * inf-ptrace.c (inf_ptrace_detach): Adjust. (inf_ptrace_files_info): Get it from the current inferior. * inf-ttrace.c (inf_ttrace_attach): Adjust. (inf_ttrace_files_info): Get it from the current inferior. * inflow.c (terminal_inferior, terminal_ours_1, set_sigint_trap) (clear_sigint_trap): Get it from the current process. * remote.c (extended_remote_attach_1) (extended_remote_create_inferior_1): Adjust. * top.c (quit_confirm, quit_target): Get it from the current inferior. * procfs.c (do_detach): Adjust. (procfs_wait): Get it from the event inferior. (procfs_files_info): Get it from the current inferior. * nto-procfs.c (procfs_files_info): Likewise. (procfs_attach): Adjust. Set the attach_flag here. (do_attach): Don't set it here. (procfs_detach): Don't clear it. (procfs_mourn_inferior): Don't clear it. * solib-osf.c (osf_solib_create_inferior_hook): Adjust. * target.c (attach_flag): Delete. (generic_mourn_inferior): Don't clear it. * win32-nat.c (get_win32_debug_event): Get it from the event process. (do_initial_win32_stuff): Add attaching argument. Set attach_flag in the inferior accordingly. (win32_attach): Don't set the attach_flag here. Pass 1 to do_intial_win32_stuff. (win32_files_info): Get it from the current inferior. (win32_create_inferior): Dont clear attach_flag here. Pass 0 to do_intial_win32_stuff.
2008-09-22 17:21:30 +02:00
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* If this inferior is a vfork child, then this is the pointer to
its vfork parent, if GDB is still attached to it. */
inferior *vfork_parent = NULL;
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* If this process is a vfork parent, this is the pointer to the
child. Since a vfork parent is left frozen by the kernel until
the child execs or exits, a process can only have one vfork child
at a given time. */
inferior *vfork_child = NULL;
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* True if this inferior should be detached when it's vfork sibling
exits or execs. */
bool pending_detach = false;
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* True if this inferior is a vfork parent waiting for a vfork child
not under our control to be done with the shared memory region,
either by exiting or execing. */
bool waiting_for_vfork_done = false;
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* True if we're in the process of detaching from this inferior. */
Make inferior::detaching a bool, and introduce scoped_restore::release() I left making inferior::detaching a bool to a separate patch, because doing that makes a make_cleanup_restore_integer call in infrun.c:prepare_for_detach no longer compile (passing a 'bool *' when an 'int *' is expected). Since we want to get rid of cleanups anyway, I looked at converting that to a scoped_restore. However, prepare_for_detach wants to discard the cleanup on success, and scoped_restore doesn't have an equivalent for that. So I added one -- I called it "release()" because it seems like a natural fit in the way standard components call similarly-spirited methods, and, it's also what the proposal for a generic scope guard calls it too, AFAICS: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189.pdf I've added some scoped_guard unit tests, while at it. gdb/ChangeLog: 2017-04-19 Pedro Alves <palves@redhat.com> * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/scoped_restore-selftests.c. (SUBDIR_UNITTESTS_OBS): Add scoped_restore-selftests.o. * common/scoped_restore.h (scoped_restore_base): Make "class". (scoped_restore_base::release): New public method. (scoped_restore_base::scoped_restore_base): New protected ctor. (scoped_restore_base::m_saved_var): New protected field. (scoped_restore_tmpl::scoped_restore_tmpl(T*)): Initialize the scoped_restore_base base class instead of m_saved_var directly. (scoped_restore_tmpl::scoped_restore_tmpl(T*, T2)): Likewise. (scoped_restore_tmpl::scoped_restore_tmpl(const scoped_restore_tmpl<T>&)): Likewise. (scoped_restore_tmpl::~scoped_restore_tmpl): Use the saved_var method. (scoped_restore_tmpl::saved_var): New method. (scoped_restore_tmpl::m_saved_var): Delete. * inferior.h (inferior::detaching): Now a bool. * infrun.c (prepare_for_detach): Use a scoped_restore instead of a cleanup. * unittests/scoped_restore-selftests.c: New file.
2017-04-19 14:12:23 +02:00
bool detaching = false;
/* What is left to do for an execution command after any thread of
this inferior stops. For continuations associated with a
specific thread, see `struct thread_info'. */
continuation *continuations = NULL;
Remote all-stop-on-top-of-non-stop This is the first pass at implementing support for all-stop mode running against the remote target using the non-stop variant of the protocol. The trickiest part here is the initial connection setup/synching. We need to fetch all inferiors' target descriptions etc. before stopping threads, because stop_all_threads needs to read the threads' registers (to record each thread's stop_pc). But OTOH, the initial inferior setup (target_post_attach, post_create_inferior, etc.), only works correctly if the inferior is stopped... So I've split that initial setup part from attach_command_post_wait to a separate function, and added a "still needs setup" flag to the inferior structure. This is similar to gdbserver/linux-low.c's handling of discovering the process's target description). Then if on connection all threads of the remote inferior are running, when we go about stopping them, as soon as they stop we call setup_inferior, from within stop_all_threads. Also, in all-stop, we need to process all the initial stop replies to learn about all the pending signal the threads may already be stopped for, and pick the one to report as current. This is exposed by gdb.threads/reconnect-signal.exp. gdb/ 2015-11-30 Pedro Alves <palves@redhat.com> * gdbthread.h (switch_to_thread_no_regs): Declare. * infcmd.c (setup_inferior): New function, factored out from ... (attach_command_post_wait): ... this. Rename to ... (attach_post_wait): ... this. Replace parameter async_exec with attach_post_wait_mode parameter. Adjust. (enum attach_post_wait_mode): New enum. (struct attach_command_continuation_args): Replace 'async_exec' field with 'mode' field. (attach_command_continuation): Adjust. (attach_command): Add comment. Mark the inferior as needing setup. Adjust to use enum attach_post_wait_mode. (notice_new_inferior): Use switch_to_thread_no_regs. Adjust to use enum attach_post_wait_mode. * inferior.h (setup_inferior): Declare. (struct inferior) <needs_setup>: New field. * infrun.c (set_last_target_status): Make extern. (stop_all_threads): Make extern. Setup inferior, if necessary. * infrun.h (set_last_target_status, stop_all_threads): Declare. * remote-notif.c (remote_async_get_pending_events_handler) (handle_notification): Replace non_stop checks with target_is_non_stop_p() checks. * remote.c (remote_notice_new_inferior): Remove non_stop check. (remote_update_thread_list): Replace non_stop check with target_is_non_stop_p() check. (print_one_stopped_thread): New function. (process_initial_stop_replies): New 'from_tty' parameter. "Notice" all new live inferiors after storing initial stops as pending status in each corresponding thread. If all-stop, stop all threads, try picking a signalled thread as current, and print the status of that one thread. Record the last target status. (remote_start_remote): Replace non_stop checks with target_is_non_stop_p() checks. Don't query for the remote current thread of use qOffsets here. Pass from_tty to process_initial_stop_replies. (extended_remote_attach): Replace non_stop checks with target_is_non_stop_p() checks. (extended_remote_post_attach): Send qOffsets here. (remote_vcont_resume, remote_resume, remote_stop) (remote_interrupt, remote_parse_stop_reply, remote_wait): Replace non_stop checks with target_is_non_stop_p() checks. (remote_async): If target is non-stop, mark/clear the pending events token. * thread.c (switch_to_thread_no_regs): New function.
2015-11-30 17:05:13 +01:00
/* True if setup_inferior wasn't called for this inferior yet.
Until that is done, we must not access inferior memory or
registers, as we haven't determined the target
architecture/description. */
bool needs_setup = false;
Remote all-stop-on-top-of-non-stop This is the first pass at implementing support for all-stop mode running against the remote target using the non-stop variant of the protocol. The trickiest part here is the initial connection setup/synching. We need to fetch all inferiors' target descriptions etc. before stopping threads, because stop_all_threads needs to read the threads' registers (to record each thread's stop_pc). But OTOH, the initial inferior setup (target_post_attach, post_create_inferior, etc.), only works correctly if the inferior is stopped... So I've split that initial setup part from attach_command_post_wait to a separate function, and added a "still needs setup" flag to the inferior structure. This is similar to gdbserver/linux-low.c's handling of discovering the process's target description). Then if on connection all threads of the remote inferior are running, when we go about stopping them, as soon as they stop we call setup_inferior, from within stop_all_threads. Also, in all-stop, we need to process all the initial stop replies to learn about all the pending signal the threads may already be stopped for, and pick the one to report as current. This is exposed by gdb.threads/reconnect-signal.exp. gdb/ 2015-11-30 Pedro Alves <palves@redhat.com> * gdbthread.h (switch_to_thread_no_regs): Declare. * infcmd.c (setup_inferior): New function, factored out from ... (attach_command_post_wait): ... this. Rename to ... (attach_post_wait): ... this. Replace parameter async_exec with attach_post_wait_mode parameter. Adjust. (enum attach_post_wait_mode): New enum. (struct attach_command_continuation_args): Replace 'async_exec' field with 'mode' field. (attach_command_continuation): Adjust. (attach_command): Add comment. Mark the inferior as needing setup. Adjust to use enum attach_post_wait_mode. (notice_new_inferior): Use switch_to_thread_no_regs. Adjust to use enum attach_post_wait_mode. * inferior.h (setup_inferior): Declare. (struct inferior) <needs_setup>: New field. * infrun.c (set_last_target_status): Make extern. (stop_all_threads): Make extern. Setup inferior, if necessary. * infrun.h (set_last_target_status, stop_all_threads): Declare. * remote-notif.c (remote_async_get_pending_events_handler) (handle_notification): Replace non_stop checks with target_is_non_stop_p() checks. * remote.c (remote_notice_new_inferior): Remove non_stop check. (remote_update_thread_list): Replace non_stop check with target_is_non_stop_p() check. (print_one_stopped_thread): New function. (process_initial_stop_replies): New 'from_tty' parameter. "Notice" all new live inferiors after storing initial stops as pending status in each corresponding thread. If all-stop, stop all threads, try picking a signalled thread as current, and print the status of that one thread. Record the last target status. (remote_start_remote): Replace non_stop checks with target_is_non_stop_p() checks. Don't query for the remote current thread of use qOffsets here. Pass from_tty to process_initial_stop_replies. (extended_remote_attach): Replace non_stop checks with target_is_non_stop_p() checks. (extended_remote_post_attach): Send qOffsets here. (remote_vcont_resume, remote_resume, remote_stop) (remote_interrupt, remote_parse_stop_reply, remote_wait): Replace non_stop checks with target_is_non_stop_p() checks. (remote_async): If target is non-stop, mark/clear the pending events token. * thread.c (switch_to_thread_no_regs): New function.
2015-11-30 17:05:13 +01:00
/* Private data used by the target vector implementation. */
Create private_inferior class hierarchy There are currently multiple definitions of private_inferior, defined in remote.c and darwin-nat.h. The patch that poisons XNEW and friends for non-POD types trips on that, because private_inferior is freed in ~inferior(), where it is an opaque type. Since the compiler can't tell whether the type is POD, it gives an error. Also, we can't start using C++ features in these structures (make them non-POD) as long as there are multiple definitions with the same name. For these reasons, this patch makes a class hierarchy, with private_inferior being the abstract base class, and darwin_inferior & remote_inferior inheriting from it. Destruction is done through the virtual destructor. I stumbled on some suspicious code in the darwin implementation though. darwin_check_new_threads does an XCNEW(darwin_thread_t) when it finds a new thread, allocating a new structure for it (darwin_thread_t is a typedef for private_thread_info). It then VEC_safe_pushes it in a vector defined as DEF_VEC_O (a vector of objects). This means that the structure content gets copied in the vector. The thread_info object is created with the XCNEW'ed structure as the private thread info, while the rest of the code works with the instance in the vector. We have therefore two distinct instances of darwin_thread_t/private_thread_info for each thread. This is not really a problem in practice, because thread_info::priv is not used in the darwin code. I still find it weird and far from ideal, so I tried to fix it by changing the vector to be a vector of pointers. There should now be a single instance of the structure for each thread. The deallocation of the darwin_thread_t/private_thread_info structure is done by the thread_info destructor. I am able to build on macOS, but not really test, since the port seems a bit broken. I am not able to debug reliably on the machine I have access to, which runs macOS 10.12.6. gdb/ChangeLog: * inferior.h (private_inferior): Define structure type, add virtual pure destructor. (inferior) <priv>: Change type to unique_ptr. * inferior.c (private_inferior::~private_inferior): Provide default implementation. (inferior::~inferior): Don't free priv field. (exit_inferior_1): Likewise. * darwin-nat.h (struct darwin_exception_info): Initialize fields. (darwin_exception_info): Remove typedef. (DEF_VEC_O (darwin_thread_t)); Remove. (private_inferior): Rename to ... (darwin_private_inferior): ... this, extend private_inferior. (get_darwin_inferior): New. <threads>: Change type to std::vector of darwin_thread_t pointers. * darwin-nat.c (darwin_check_new_threads): Adjust. (find_inferior_task_it): Adjust. (darwin_find_thread); Adjust. (darwin_suspend_inferior): Adjust. (darwin_resume_inferior): Adjust. (darwin_find_new_inferior): Adjust. (darwin_decode_notify_message): Adjust. (darwin_send_reply): Adjust. (darwin_resume_inferior_threads): Adjust. (darwin_suspend_inferior_threads): Adjust. (darwin_decode_message): Adjust. (darwin_wait): Adjust. (darwin_interrupt): Adjust. (darwin_deallocate_threads): Adjust. (darwin_mourn_inferior): Adjust, don't free private data. (darwin_reply_to_all_pending_messages): Adjust. (darwin_stop_inferior): Adjust. (darwin_setup_exceptions): Adjust. (darwin_kill_inferior): Adjust. (darwin_setup_request_notification): Adjust. (darwin_attach_pid): Adjust. (darwin_init_thread_list): Adjust. (darwin_setup_fake_stop_event): Adjust. (darwin_attach): Adjust. (darwin_detach): Adjust. (darwin_xfer_partial): Adjust. (set_enable_mach_exceptions): Adjust. (darwin_pid_to_exec_file): Adjust. (darwin_get_ada_task_ptid): Adjust. * darwin-nat-info.c (get_task_from_args): Adjust. (info_mach_ports_command): Adjust. (info_mach_region_command): Adjust. (info_mach_exceptions_command): Adjust. * remote.c (private_inferior): Rename to ... (remote_private_inferior): ... this, initialize fields. (get_remote_inferior); New. (remote_commit_resume): Use get_remote_inferior. (check_pending_event_prevents_wildcard_vcont_callback): Likewise.
2017-11-24 16:39:30 +01:00
std::unique_ptr<private_inferior> priv;
Implementing catch syscall. * amd64-linux-tdep.c: Include xml-syscall.h header, define the XML syscall name for the architecture. (amd64_linux_get_syscall_number): New function. (amd64_linux_init_abi): Register the correct functions for syscall catchpoint; set the correct syscall file name. * breakpoint.c: New include: xml-syscall.h. (set_raw_breakpoint_without_location): Setting the parameters for the catch syscall feature. (insert_catch_syscall): New. (remove_catch_syscall): New. (breakpoint_hit_catch_syscall): New. (print_it_catch_syscall): New. (print_one_catch_syscall): New. (print_mention_catch_syscall): New. (catch_syscall_breakpoint_ops): New. (syscall_catchpoint_p): New. (create_catchpoint_without_mention): New. (create_catchpoint): Modified in order to use create_catchpoint_without_mention. (create_syscall_event_catchpoint): New. (clean_up_filters): New. (catch_syscall_split_args): New. (catch_syscall_command_1): New. (delete_breakpoint): Add cleanup for catch syscall. (is_syscall_catchpoint_enabled): New. (catch_syscall_enabled): New. (catching_syscall_number): New. (catch_syscall_completer): New completer function. (add_catch_command): Add the completer function for catchpoints. * breakpoint.h (syscalls_to_be_caught): New vector. (catch_syscall_enabled): New. (catching_syscall_number): New. * gdbarch.c: Regenerated. * gdbarch.h: Regenerated. * gdbarch.sh: Add syscall catchpoint functions and structures. (get_syscall_number): New. (UNKNOWN_SYSCALL): New definition. * i386-linux-nat.c (i386_linux_resume): Select the proper request to be made for ptrace() considering if we are catching syscalls or not. * i386-linux-tdep.c: Include xml-syscall.h header, define the XML syscall name for the architecture. (i386_linux_get_syscall_number): New. (i386_linux_init_abi): Register the correct functions for syscall catchpoint; set the correct syscall file name. * inf-child.c (inf_child_set_syscall_catchpoint): New. (inf_child_target): Assign default values to target_ops. * inf-ptrace.c (inf_ptrace_resume): Select the proper request to be made for ptrace() considering if we are catching syscalls or not. * inferior.h (struct inferior): Included new variables any_syscall_count, syscalls_counts and total_syscalls_count, used to keep track of requested syscall catchpoints. * infrun.c (resume): Add syscall catchpoint. (deal_with_syscall_event): New. (handle_inferior_event): Add syscall entry/return events. (inferior_has_called_syscall): New. * linux-nat.c: Define some helpful variables to track wether we have support for the needed ptrace option. (linux_test_for_tracesysgood): New. (linux_supports_tracesysgood): New. (linux_enable_tracesysgood): New. (linux_enable_event_reporting): Save the current used ptrace options. (linux_child_post_attach): Calling linux_enable_tracesysgood. (linux_child_post_startup_inferior): Likewise. (linux_child_set_syscall_catchpoint): New function. (linux_handle_extended_wait): Handle the case which the inferior stops because it has called or returned from a syscall. (linux_target_install_ops): Install the necessary functions to handle syscall catchpoints. * linux-nat.h (struct lwp_info): Include syscall_state into the structure, which indicates if we are in a syscall entry or return. * ppc-linux-tdep.c: Include xml-syscall.h header, define the XML syscall filename for the arch. (ppc_linux_get_syscall_number): New. (ppc_linux_init_abi): Register the correct functions for syscall catchpoint; setting the correct name for the XML syscall file. * target.c (update_current_target): Update/copy functions related to syscall catchpoint. (target_waitstatus_to_string): Add syscall catchpoint entry/return events. * target.h (struct target_waitstatus): Add syscall number. (struct syscall): New struct to hold information about syscalls in the system. (struct target_ops): Add ops for syscall catchpoint. (inferior_has_called_syscall): New. (target_set_syscall_catchpoint): New. * xml-support.c (xml_fetch_content_from_file): New function, transferred from xml-tdesc.c. * xml-support.h (xml_fetch_content_from_file): New. * xml-tdesc.c (fetch_xml_from_file): Function removed; transferred to xml-support.c. (file_read_description_xml): Updated to use the new xml_fetch_content_from_file function. * syscalls/gdb-syscalls.dtd: New definition file for syscall's XML support. * syscalls/amd64-linux.xml: New file containing information about syscalls for GNU/Linux systems that use amd64 architecture. * syscalls/i386-linux.xml: New file containing information about syscalls for GNU/Linux systems that use i386 architecture. * syscalls/ppc-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC architecture. * syscalls/ppc64-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC64 architecture. * xml-syscall.c: New file containing functions for manipulating syscall's XML files. * xml-syscall.h: New file, exporting the functions above mentioned. * Makefile.in: Support for relocatable GDB datadir and XML syscall. * NEWS: Added information about the catch syscall feature. * doc/gdb.texinfo (Set Catchpoints): Documentation about the new feature. * testsuite/Makefile.in: Inclusion of catch-syscall object. * testsuite/gdb.base/catch-syscall.c: New file. * testsuite/gdb.base/catch-syscall.exp: New file.
2009-09-15 05:30:08 +02:00
/* HAS_EXIT_CODE is true if the inferior exited with an exit code.
In this case, the EXIT_CODE field is also valid. */
bool has_exit_code = false;
LONGEST exit_code = 0;
/* Default flags to pass to the symbol reading functions. These are
Make symfile_add_flags and objfile->flags strongly typed This makes these flag types be "enum flag" types. The benefit is making use of C++'s stronger typing -- mixing the flags types by mistake errors at compile time. This caught one old bug in symbol_file_add_main_1 already, fixed by this patch as well: @@ -1318,7 +1326,7 @@ symbol_file_add_main_1 (const char *args, int from_tty, int flags) what is frameless. */ reinit_frame_cache (); - if ((flags & SYMFILE_NO_READ) == 0) + if ((add_flags & SYMFILE_NO_READ) == 0) set_initial_language (); } Above, "flags" are objfile flags, not symfile_add_flags. So that was actually checking for "flag & OBJF_PSYMTABS_READ", which has the same value as SYMFILE_NO_READ... I moved the flags definitions to separate files to break circular dependencies. Built with --enable-targets=all and tested on x86-64 Fedora 23. gdb/ChangeLog: 2016-10-26 Pedro Alves <palves@redhat.com> * coffread.c (coff_symfile_read): Use symfile_add_flags. * dbxread.c (dbx_symfile_read): Ditto. * elfread.c (elf_symfile_read): Ditto. * inferior.h: Include symfile-add-flags.h. (struct inferior) <symfile_flags>: Now symfile_add_flags. * machoread.c (macho_add_oso_symfile, macho_symfile_read_all_oso) (macho_symfile_read, mipscoff_symfile_read): Use symfile_add_flags. * objfile-flags.h: New file. * objfiles.c (allocate_objfile): Use objfile_flags. * objfiles.h: Include objfile-flags.h. (struct objfile) <flags>: Now an objfile_flags. (OBJF_REORDERED, OBJF_SHARED, OBJF_READNOW, OBJF_USERLOADED) (OBJF_PSYMTABS_READ, OBJF_MAINLINE, OBJF_NOT_FILENAME): Delete. Converted to an enum-flags in objfile-flags.h. (allocate_objfile): Use objfile_flags. * python/py-objfile.c (objfpy_add_separate_debug_file): Remove unnecessary local. * solib.c (solib_read_symbols, solib_add) (reload_shared_libraries_1): Use symfile_add_flags. * solib.h: Include "symfile-add-flags.h". (solib_read_symbols): Use symfile_add_flags. * symfile-add-flags.h: New file. * symfile-debug.c (debug_sym_read): Use symfile_add_flags. * symfile-mem.c (symbol_file_add_from_memory): Use symfile_add_flags. * symfile.c (read_symbols, syms_from_objfile_1) (syms_from_objfile, finish_new_objfile): Use symfile_add_flags. (symbol_file_add_with_addrs): Use symfile_add_flags and objfile_flags. (symbol_file_add_separate): Use symfile_add_flags. (symbol_file_add_from_bfd, symbol_file_add): Use symfile_add_flags and objfile_flags. (symbol_file_add_main_1): : Use objfile_flags. Fix add_flags vs flags confusion. (symbol_file_command): Use objfile_flags. (add_symbol_file_command): Use symfile_add_flags and objfile_flags. (clear_symtab_users): Use symfile_add_flags. * symfile.h: Include "symfile-add-flags.h" and "objfile-flags.h". (struct sym_fns) <sym_read>: Use symfile_add_flags. (clear_symtab_users): Use symfile_add_flags. (enum symfile_add_flags): Delete, moved to symfile-add-flags.h and converted to enum-flags. (symbol_file_add, symbol_file_add_from_bfd) (symbol_file_add_separate): Use symfile_add_flags. * xcoffread.c (xcoff_initial_scan): Use symfile_add_flags.
2016-10-26 17:47:10 +02:00
used whenever a new objfile is created. */
symfile_add_flags symfile_flags = 0;
gdb/ 2012-11-09 Pedro Alves <palves@redhat.com> * gdbarch.sh (target_gdbarch) <gdbarch.h>: Reimplement as macro. (get_target_gdbarch) <gdbarch.h>: New function. (startup_gdbarch) <gdbarch.h>: Declare. <gdbarch.c> (target_gdbarch): Delete. <gdbarch.c> (deprecated_target_gdbarch_select_hack): Set the current inferior's gdbarch. <gdbarch.c> (get_target_gdbarch): New function. * inferior.c: Include target-descriptions.h. (free_inferior): Free target description info. (add_inferior_with_spaces): Set the inferior's initial architecture. (clone_inferior_command): Copy the original inferior's target description if it was user specified. (initialize_inferiors): Add comment. * inferior.h (struct target_desc_info): Forward declare. (struct inferior) <gdbarch>: New field. * linux-nat.c: Include target-descriptions.h. (linux_child_follow_fork): Copy the parent's architecture and target description to the child. * target-descriptions.c: Include inferior.h. (struct target_desc_info): New structure, holding the equivalents of ... (target_desc_fetched, current_target_desc) (target_description_filename): ... these removed globals. (get_tdesc_info, target_desc_info_from_user_p) (copy_inferior_target_desc_info, target_desc_info_free): New. (target_desc_fetched, current_target_desc) (target_description_filename): Reimplemented as convenience macros. (tdesc_filename_cmd_string): New global. (set_tdesc_filename_cmd): Copy the string manipulated by the "set tdescs filename ..." commands to the per-inferior equivalent. (show_tdesc_filename_cmd): Get the value to show from the per-inferior description filename. (_initilize_target_descriptions): Change the "set/show tdesc filename" commands' variable. * target-descriptions.h (struct target_desc, struct target_desc_info) (struct inferior): Forward declare. (target_find_description, target_clear_description) (target_current_description): Adjust comments. (copy_inferior_target_desc_info, target_desc_info_free) (target_desc_info_from_user_p). Declare. gdb/testsuite/ 2012-11-09 Pedro Alves <palves@redhat.com> * gdb.multi/multi-arch.exp: New.
2012-11-09 02:47:20 +01:00
/* Info about an inferior's target description (if it's fetched; the
user supplied description's filename, if any; etc.). */
target_desc_info *tdesc_info = NULL;
gdb/ 2012-11-09 Pedro Alves <palves@redhat.com> * gdbarch.sh (target_gdbarch) <gdbarch.h>: Reimplement as macro. (get_target_gdbarch) <gdbarch.h>: New function. (startup_gdbarch) <gdbarch.h>: Declare. <gdbarch.c> (target_gdbarch): Delete. <gdbarch.c> (deprecated_target_gdbarch_select_hack): Set the current inferior's gdbarch. <gdbarch.c> (get_target_gdbarch): New function. * inferior.c: Include target-descriptions.h. (free_inferior): Free target description info. (add_inferior_with_spaces): Set the inferior's initial architecture. (clone_inferior_command): Copy the original inferior's target description if it was user specified. (initialize_inferiors): Add comment. * inferior.h (struct target_desc_info): Forward declare. (struct inferior) <gdbarch>: New field. * linux-nat.c: Include target-descriptions.h. (linux_child_follow_fork): Copy the parent's architecture and target description to the child. * target-descriptions.c: Include inferior.h. (struct target_desc_info): New structure, holding the equivalents of ... (target_desc_fetched, current_target_desc) (target_description_filename): ... these removed globals. (get_tdesc_info, target_desc_info_from_user_p) (copy_inferior_target_desc_info, target_desc_info_free): New. (target_desc_fetched, current_target_desc) (target_description_filename): Reimplemented as convenience macros. (tdesc_filename_cmd_string): New global. (set_tdesc_filename_cmd): Copy the string manipulated by the "set tdescs filename ..." commands to the per-inferior equivalent. (show_tdesc_filename_cmd): Get the value to show from the per-inferior description filename. (_initilize_target_descriptions): Change the "set/show tdesc filename" commands' variable. * target-descriptions.h (struct target_desc, struct target_desc_info) (struct inferior): Forward declare. (target_find_description, target_clear_description) (target_current_description): Adjust comments. (copy_inferior_target_desc_info, target_desc_info_free) (target_desc_info_from_user_p). Declare. gdb/testsuite/ 2012-11-09 Pedro Alves <palves@redhat.com> * gdb.multi/multi-arch.exp: New.
2012-11-09 02:47:20 +01:00
/* The architecture associated with the inferior through the
connection to the target.
The architecture vector provides some information that is really
a property of the inferior, accessed through a particular target:
ptrace operations; the layout of certain RSP packets; the
solib_ops vector; etc. To differentiate architecture accesses to
per-inferior/target properties from
per-thread/per-frame/per-objfile properties, accesses to
per-inferior/target properties should be made through
this gdbarch. */
struct gdbarch *gdbarch = NULL;
gdb/ 2012-11-09 Pedro Alves <palves@redhat.com> * gdbarch.sh (target_gdbarch) <gdbarch.h>: Reimplement as macro. (get_target_gdbarch) <gdbarch.h>: New function. (startup_gdbarch) <gdbarch.h>: Declare. <gdbarch.c> (target_gdbarch): Delete. <gdbarch.c> (deprecated_target_gdbarch_select_hack): Set the current inferior's gdbarch. <gdbarch.c> (get_target_gdbarch): New function. * inferior.c: Include target-descriptions.h. (free_inferior): Free target description info. (add_inferior_with_spaces): Set the inferior's initial architecture. (clone_inferior_command): Copy the original inferior's target description if it was user specified. (initialize_inferiors): Add comment. * inferior.h (struct target_desc_info): Forward declare. (struct inferior) <gdbarch>: New field. * linux-nat.c: Include target-descriptions.h. (linux_child_follow_fork): Copy the parent's architecture and target description to the child. * target-descriptions.c: Include inferior.h. (struct target_desc_info): New structure, holding the equivalents of ... (target_desc_fetched, current_target_desc) (target_description_filename): ... these removed globals. (get_tdesc_info, target_desc_info_from_user_p) (copy_inferior_target_desc_info, target_desc_info_free): New. (target_desc_fetched, current_target_desc) (target_description_filename): Reimplemented as convenience macros. (tdesc_filename_cmd_string): New global. (set_tdesc_filename_cmd): Copy the string manipulated by the "set tdescs filename ..." commands to the per-inferior equivalent. (show_tdesc_filename_cmd): Get the value to show from the per-inferior description filename. (_initilize_target_descriptions): Change the "set/show tdesc filename" commands' variable. * target-descriptions.h (struct target_desc, struct target_desc_info) (struct inferior): Forward declare. (target_find_description, target_clear_description) (target_current_description): Adjust comments. (copy_inferior_target_desc_info, target_desc_info_free) (target_desc_info_from_user_p). Declare. gdb/testsuite/ 2012-11-09 Pedro Alves <palves@redhat.com> * gdb.multi/multi-arch.exp: New.
2012-11-09 02:47:20 +01:00
Place displaced step data directly in inferior structure This patch moves the per-inferior data related to displaced stepping to be directly in the inferior structure, rather than in a container on the side. On notable difference is that previously, we deleted the state on inferior exit, which guaranteed a clean state if re-using the inferior for a new run or attach. We now need to reset the state manually. At the same time, I changed step_saved_copy to be a gdb::byte_vector, so it is automatically freed on destruction (which should plug the leak reported here [1]). [1] https://sourceware.org/ml/gdb-patches/2018-11/msg00202.html gdb/ChangeLog: * inferior.h (class inferior) <displaced_step_state>: New field. * infrun.h (struct displaced_step_state): Move here from infrun.c. Initialize fields, add constructor. <inf>: Remove field. <reset>: New method. * infrun.c (struct displaced_step_inferior_state): Move to infrun.h. (displaced_step_inferior_states): Remove. (get_displaced_stepping_state): Adust. (displaced_step_in_progress_any_inferior): Adjust. (displaced_step_in_progress_thread): Adjust. (displaced_step_in_progress): Adjust. (add_displaced_stepping_state): Remove. (get_displaced_step_closure_by_addr): Adjust. (remove_displaced_stepping_state): Remove. (infrun_inferior_exit): Call displaced_step_state.reset. (use_displaced_stepping): Don't check for NULL. (displaced_step_prepare_throw): Call get_displaced_stepping_state. (displaced_step_fixup): Don't check for NULL. (prepare_for_detach): Don't check for NULL.
2019-01-02 23:31:08 +01:00
/* Data related to displaced stepping. */
displaced_step_inferior_state displaced_step_state;
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* Per inferior data-pointers required by other GDB modules. */
* auto-load.c (_initialize_auto_load): Update. * solib-svr4.c (_initialize_svr4_solib): Update * solib-dsbt.c (_initialize_dsbt_solib): Update. * solib-darwin.c (_initialize_darwin_solib): Update. * registry.h: New file. * python/py-progspace.c (gdbpy_initialize_pspace): Update. * python/py-inferior.c (gdbpy_initialize_inferior): Update. * progspace.h: Include registry.h. Use DECLARE_REGISTRY. (register_program_space_data_with_cleanup) (register_program_space_data, program_space_alloc_data) (clear_program_space_data, set_program_space_data) (program_space_data): Don't declare. * progspace.c: Use DEFINE_REGISTRY. (struct program_space_data, struct program_space_data_registration, struct program_space_data_registry, program_space_data_registry) (register_program_space_data_with_cleanup) (register_program_space_data, program_space_alloc_data) (program_space_free_data, clear_program_space_data) (set_program_space_data, program_space_data): Remove. * objfiles.h: Include registry.h. Use DECLARE_REGISTRY. (struct objfile) <data, num_data>: Replace with REGISTRY_FIELDS. (register_objfile_data_with_cleanup, register_objfile_data) (clear_objfile_data, set_objfile_data, objfile_data): Don't declare. * objfiles.c: Use DEFINE_REGISTRY. (struct objfile_data, struct objfile_data_registration, struct objfile_data_registry, objfile_data_registry) (register_objfile_data_with_cleanup, register_objfile_data) (objfile_alloc_data, objfile_free_data, clear_objfile_data) (set_objfile_data, objfile_data): Remove. (_initialize_objfiles): Update. * jit.c (_initialize_jit): Update. * inflow.c (_initialize_inflow): Update. * inferior.h: Include registry.h. Use DECLARE_REGISTRY. (struct inferior) <data, num_data>: Replace with REGISTRY_FIELDS. (register_inferior_data_with_cleanup, register_inferior_data) (clear_inferior_data, set_inferior_data, inferior_data): Don't declare. * inferior.c: Use DEFINE_REGISTRY. (struct inferior_data, struct inferior_data_registration, struct inferior_data_registry, inferior_data_registry) (register_inferior_data_with_cleanup, register_inferior_data) (inferior_alloc_data, inferior_free_data clear_inferior_data) (set_inferior_data, inferior_data): Remove. * auxv.c (_initialize_auxv): Update. * ada-lang.c (_initialize_ada_language): Update. * breakpoint.c (_initialize_breakpoint): Update. * i386-nat.c (i386_use_watchpoints): Update.
2012-08-22 17:17:21 +02:00
REGISTRY_FIELDS;
Multi-target support This commit adds multi-target support to GDB. What this means is that with this commit, GDB can now be connected to different targets at the same time. E.g., you can debug a live native process and a core dump at the same time, connect to multiple gdbservers, etc. Actually, the word "target" is overloaded in gdb. We already have a target stack, with pushes several target_ops instances on top of one another. We also have "info target" already, which means something completely different to what this patch does. So from here on, I'll be using the "target connections" term, to mean an open process_stratum target, pushed on a target stack. This patch makes gdb have multiple target stacks, and multiple process_stratum targets open simultaneously. The user-visible changes / commands will also use this terminology, but of course it's all open to debate. User-interface-wise, not that much changes. The main difference is that each inferior may have its own target connection. A target connection (e.g., a target extended-remote connection) may support debugging multiple processes, just as before. Say you're debugging against gdbserver in extended-remote mode, and you do "add-inferior" to prepare to spawn a new process, like: (gdb) target extended-remote :9999 ... (gdb) start ... (gdb) add-inferior Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) file a.out ... (gdb) start ... At this point, you have two inferiors connected to the same gdbserver. With this commit, GDB will maintain a target stack per inferior, instead of a global target stack. To preserve the behavior above, by default, "add-inferior" makes the new inferior inherit a copy of the target stack of the current inferior. Same across a fork - the child inherits a copy of the target stack of the parent. While the target stacks are copied, the targets themselves are not. Instead, target_ops is made a refcounted_object, which means that target_ops instances are refcounted, which each inferior counting for a reference. What if you want to create an inferior and connect it to some _other_ target? For that, this commit introduces a new "add-inferior -no-connection" option that makes the new inferior not share the current inferior's target. So you could do: (gdb) target extended-remote :9999 Remote debugging using :9999 ... (gdb) add-inferior -no-connection [New inferior 2] Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 <null> (gdb) tar extended-remote :10000 Remote debugging using :10000 ... (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 process 18450 target:/home/pedro/tmp/main (gdb) A following patch will extended "info inferiors" to include a column indicating which connection an inferior is bound to, along with a couple other UI tweaks. Other than that, debugging is the same as before. Users interact with inferiors and threads as before. The only difference is that inferiors may be bound to processes running in different machines. That's pretty much all there is to it in terms of noticeable UI changes. On to implementation. Since we can be connected to different systems at the same time, a ptid_t is no longer a unique identifier. Instead a thread can be identified by a pair of ptid_t and 'process_stratum_target *', the later being the instance of the process_stratum target that owns the process/thread. Note that process_stratum_target inherits from target_ops, and all process_stratum targets inherit from process_stratum_target. In earlier patches, many places in gdb were converted to refer to threads by thread_info pointer instead of ptid_t, but there are still places in gdb where we start with a pid/tid and need to find the corresponding inferior or thread_info objects. So you'll see in the patch many places adding a process_stratum_target parameter to functions that used to take only a ptid_t. Since each inferior has its own target stack now, we can always find the process_stratum target for an inferior. That is done via a inf->process_target() convenience method. Since each inferior has its own target stack, we need to handle the "beneath" calls when servicing target calls. The solution I settled with is just to make sure to switch the current inferior to the inferior you want before making a target call. Not relying on global context is just not feasible in current GDB. Fortunately, there aren't that many places that need to do that, because generally most code that calls target methods already has the current context pointing to the right inferior/thread. Note, to emphasize -- there's no method to "switch to this target stack". Instead, you switch the current inferior, and that implicitly switches the target stack. In some spots, we need to iterate over all inferiors so that we reach all target stacks. Native targets are still singletons. There's always only a single instance of such targets. Remote targets however, we'll have one instance per remote connection. The exec target is still a singleton. There's only one instance. I did not see the point of instanciating more than one exec_target object. After vfork, we need to make sure to push the exec target on the new inferior. See exec_on_vfork. For type safety, functions that need a {target, ptid} pair to identify a thread, take a process_stratum_target pointer for target parameter instead of target_ops *. Some shared code in gdb/nat/ also need to gain a target pointer parameter. This poses an issue, since gdbserver doesn't have process_stratum_target, only target_ops. To fix this, this commit renames gdbserver's target_ops to process_stratum_target. I think this makes sense. There's no concept of target stack in gdbserver, and gdbserver's target_ops really implements a process_stratum-like target. The thread and inferior iterator functions also gain process_stratum_target parameters. These are used to be able to iterate over threads and inferiors of a given target. Following usual conventions, if the target pointer is null, then we iterate over threads and inferiors of all targets. I tried converting "add-inferior" to the gdb::option framework, as a preparatory patch, but that stumbled on the fact that gdb::option does not support file options yet, for "add-inferior -exec". I have a WIP patchset that adds that, but it's not a trivial patch, mainly due to need to integrate readline's filename completion, so I deferred that to some other time. In infrun.c/infcmd.c, the main change is that we need to poll events out of all targets. See do_target_wait. Right after collecting an event, we switch the current inferior to an inferior bound to the target that reported the event, so that target methods can be used while handling the event. This makes most of the code transparent to multi-targets. See fetch_inferior_event. infrun.c:stop_all_threads is interesting -- in this function we need to stop all threads of all targets. What the function does is send an asynchronous stop request to all threads, and then synchronously waits for events, with target_wait, rinse repeat, until all it finds are stopped threads. Now that we have multiple targets, it's not efficient to synchronously block in target_wait waiting for events out of one target. Instead, we implement a mini event loop, with interruptible_select, select'ing on one file descriptor per target. For this to work, we need to be able to ask the target for a waitable file descriptor. Such file descriptors already exist, they are the descriptors registered in the main event loop with add_file_handler, inside the target_async implementations. This commit adds a new target_async_wait_fd target method that just returns the file descriptor in question. See wait_one / stop_all_threads in infrun.c. The 'threads_executing' global is made a per-target variable. Since it is only relevant to process_stratum_target targets, this is where it is put, instead of in target_ops. You'll notice that remote.c includes some FIXME notes. These refer to the fact that the global arrays that hold data for the remote packets supported are still globals. For example, if we connect to two different servers/stubs, then each might support different remote protocol features. They might even be different architectures, like e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a host/controller scenario as a single program. That isn't going to work correctly today, because of said globals. I'm leaving fixing that for another pass, since it does not appear to be trivial, and I'd rather land the base work first. It's already useful to be able to debug multiple instances of the same server (e.g., a distributed cluster, where you have full control over the servers installed), so I think as is it's already reasonable incremental progress. Current limitations: - You can only resume more that one target at the same time if all targets support asynchronous debugging, and support non-stop mode. It should be possible to support mixed all-stop + non-stop backends, but that is left for another time. This means that currently in order to do multi-target with gdbserver you need to issue "maint set target-non-stop on". I would like to make that mode be the default, but we're not there yet. Note that I'm talking about how the target backend works, only. User-visible all-stop mode works just fine. - As explained above, connecting to different remote servers at the same time is likely to produce bad results if they don't support the exact set of RSP features. FreeBSD updates courtesy of John Baldwin. gdb/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> John Baldwin <jhb@FreeBSD.org> * aarch64-linux-nat.c (aarch64_linux_nat_target::thread_architecture): Adjust. * ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call. (task_command_1): Likewise. * aix-thread.c (sync_threadlists, aix_thread_target::resume) (aix_thread_target::wait, aix_thread_target::fetch_registers) (aix_thread_target::store_registers) (aix_thread_target::thread_alive): Adjust. * amd64-fbsd-tdep.c: Include "inferior.h". (amd64fbsd_get_thread_local_address): Pass down target. * amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle thread's gdbarch instead of target_gdbarch. * break-catch-sig.c (signal_catchpoint_print_it): Adjust call to get_last_target_status. * break-catch-syscall.c (print_it_catch_syscall): Likewise. * breakpoint.c (breakpoints_should_be_inserted_now): Consider all inferiors. (update_inserted_breakpoint_locations): Skip if inferiors with no execution. (update_global_location_list): When handling moribund locations, find representative inferior for location's pspace, and use thread count of its process_stratum target. * bsd-kvm.c (bsd_kvm_target_open): Pass target down. * bsd-uthread.c (bsd_uthread_target::wait): Use as_process_stratum_target and adjust thread_change_ptid and add_thread calls. (bsd_uthread_target::update_thread_list): Use as_process_stratum_target and adjust find_thread_ptid, thread_change_ptid and add_thread calls. * btrace.c (maint_btrace_packet_history_cmd): Adjust find_thread_ptid call. * corelow.c (add_to_thread_list): Adjust add_thread call. (core_target_open): Adjust add_thread_silent and thread_count calls. (core_target::pid_to_str): Adjust find_inferior_ptid call. * ctf.c (ctf_target_open): Adjust add_thread_silent call. * event-top.c (async_disconnect): Pop targets from all inferiors. * exec.c (add_target_sections): Push exec target on all inferiors sharing the program space. (remove_target_sections): Remove the exec target from all inferiors sharing the program space. (exec_on_vfork): New. * exec.h (exec_on_vfork): Declare. * fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::update_thread_list): Adjust. (fbsd_nat_target::resume): Adjust. (fbsd_handle_debug_trap): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust. * fbsd-tdep.c (fbsd_corefile_thread): Adjust get_thread_arch_regcache call. * fork-child.c (gdb_startup_inferior): Pass target down to startup_inferior and set_executing. * gdbthread.h (struct process_stratum_target): Forward declare. (add_thread, add_thread_silent, add_thread_with_info) (in_thread_list): Add process_stratum_target parameter. (find_thread_ptid(inferior*, ptid_t)): New overload. (find_thread_ptid, thread_change_ptid): Add process_stratum_target parameter. (all_threads()): Delete overload. (all_threads, all_non_exited_threads): Add process_stratum_target parameter. (all_threads_safe): Use brace initialization. (thread_count): Add process_stratum_target parameter. (set_resumed, set_running, set_stop_requested, set_executing) (threads_are_executing, finish_thread_state): Add process_stratum_target parameter. (switch_to_thread): Use is_current_thread. * i386-fbsd-tdep.c: Include "inferior.h". (i386fbsd_get_thread_local_address): Pass down target. * i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust. * inf-child.c (inf_child_target::maybe_unpush_target): Remove have_inferiors check. * inf-ptrace.c (inf_ptrace_target::create_inferior) (inf_ptrace_target::attach): Adjust. * infcall.c (run_inferior_call): Adjust. * infcmd.c (run_command_1): Pass target to scoped_finish_thread_state. (proceed_thread_callback): Skip inferiors with no execution. (continue_command): Rename 'all_threads' local to avoid hiding 'all_threads' function. Adjust get_last_target_status call. (prepare_one_step): Adjust set_running call. (signal_command): Use user_visible_resume_target. Compare thread pointers instead of inferior_ptid. (info_program_command): Adjust to pass down target. (attach_command): Mark target's 'thread_executing' flag. (stop_current_target_threads_ns): New, factored out from ... (interrupt_target_1): ... this. Switch inferior before making target calls. * inferior-iter.h (struct all_inferiors_iterator, struct all_inferiors_range) (struct all_inferiors_safe_range) (struct all_non_exited_inferiors_range): Filter on process_stratum_target too. Remove explicit. * inferior.c (inferior::inferior): Push dummy target on target stack. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors): Add process_stratum_target parameter, and pass it down. (have_live_inferiors): Adjust. (switch_to_inferior_and_push_target): New. (add_inferior_command, clone_inferior_command): Handle "-no-connection" parameter. Use switch_to_inferior_and_push_target. (_initialize_inferior): Mention "-no-connection" option in the help of "add-inferior" and "clone-inferior" commands. * inferior.h: Include "process-stratum-target.h". (interrupt_target_1): Use bool. (struct inferior) <push_target, unpush_target, target_is_pushed, find_target_beneath, top_target, process_target, target_at, m_stack>: New. (discard_all_inferiors): Delete. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors) (all_inferiors, all_non_exited_inferiors): Add process_stratum_target parameter. * infrun.c: Include "gdb_select.h" and <unordered_map>. (target_last_proc_target): New global. (follow_fork_inferior): Push target on new inferior. Pass target to add_thread_silent. Call exec_on_vfork. Handle target's reference count. (follow_fork): Adjust get_last_target_status call. Also consider target. (follow_exec): Push target on new inferior. (struct execution_control_state) <target>: New field. (user_visible_resume_target): New. (do_target_resume): Call target_async. (resume_1): Set target's threads_executing flag. Consider resume target. (commit_resume_all_targets): New. (proceed): Also consider resume target. Skip threads of inferiors with no execution. Commit resumtion in all targets. (start_remote): Pass current inferior to wait_for_inferior. (infrun_thread_stop_requested): Consider target as well. Pass thread_info pointer to clear_inline_frame_state instead of ptid. (infrun_thread_thread_exit): Consider target as well. (random_pending_event_thread): New inferior parameter. Use it. (do_target_wait): Rename to ... (do_target_wait_1): ... this. Add inferior parameter, and pass it down. (threads_are_resumed_pending_p, do_target_wait): New. (prepare_for_detach): Adjust calls. (wait_for_inferior): New inferior parameter. Handle it. Use do_target_wait_1 instead of do_target_wait. (fetch_inferior_event): Adjust. Switch to representative inferior. Pass target down. (set_last_target_status): Add process_stratum_target parameter. Save target in global. (get_last_target_status): Add process_stratum_target parameter and handle it. (nullify_last_target_wait_ptid): Clear 'target_last_proc_target'. (context_switch): Check inferior_ptid == null_ptid before calling inferior_thread(). (get_inferior_stop_soon): Pass down target. (wait_one): Rename to ... (poll_one_curr_target): ... this. (struct wait_one_event): New. (wait_one): New. (stop_all_threads): Adjust. (handle_no_resumed, handle_inferior_event): Adjust to consider the event's target. (switch_back_to_stepped_thread): Also consider target. (print_stop_event): Update. (normal_stop): Update. Also consider the resume target. * infrun.h (wait_for_inferior): Remove declaration. (user_visible_resume_target): New declaration. (get_last_target_status, set_last_target_status): New process_stratum_target parameter. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter, and use it. (clear_inline_frame_state (thread_info*)): New. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter. (clear_inline_frame_state (thread_info*)): Declare. * linux-fork.c (delete_checkpoint_command): Pass target down to find_thread_ptid. (checkpoint_command): Adjust. * linux-nat.c (linux_nat_target::follow_fork): Switch to thread instead of just tweaking inferior_ptid. (linux_nat_switch_fork): Pass target down to thread_change_ptid. (exit_lwp): Pass target down to find_thread_ptid. (attach_proc_task_lwp_callback): Pass target down to add_thread/set_running/set_executing. (linux_nat_target::attach): Pass target down to thread_change_ptid. (get_detach_signal): Pass target down to find_thread_ptid. Consider last target status's target. (linux_resume_one_lwp_throw, resume_lwp) (linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp) (stop_wait_callback, save_stop_reason, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down. (linux_nat_target::async_wait_fd): New. (linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass target down. * linux-nat.h (linux_nat_target::async_wait_fd): Declare. * linux-tdep.c (get_thread_arch_regcache): Pass target down. * linux-thread-db.c (struct thread_db_info::process_target): New field. (add_thread_db_info): Save target. (get_thread_db_info): New process_stratum_target parameter. Also match target. (delete_thread_db_info): New process_stratum_target parameter. Also match target. (thread_from_lwp): Adjust to pass down target. (thread_db_notice_clone): Pass down target. (check_thread_db_callback): Pass down target. (try_thread_db_load_1): Always push the thread_db target. (try_thread_db_load, record_thread): Pass target down. (thread_db_target::detach): Pass target down. Always unpush the thread_db target. (thread_db_target::wait, thread_db_target::mourn_inferior): Pass target down. Always unpush the thread_db target. (find_new_threads_callback, thread_db_find_new_threads_2) (thread_db_target::update_thread_list): Pass target down. (thread_db_target::pid_to_str): Pass current inferior down. (thread_db_target::get_thread_local_address): Pass target down. (thread_db_target::resume, maintenance_check_libthread_db): Pass target down. * nto-procfs.c (nto_procfs_target::update_thread_list): Adjust. * procfs.c (procfs_target::procfs_init_inferior): Declare. (proc_set_current_signal, do_attach, procfs_target::wait): Adjust. (procfs_init_inferior): Rename to ... (procfs_target::procfs_init_inferior): ... this and adjust. (procfs_target::create_inferior, procfs_notice_thread) (procfs_do_thread_registers): Adjust. * ppc-fbsd-tdep.c: Include "inferior.h". (ppcfbsd_get_thread_local_address): Pass down target. * proc-service.c (ps_xfer_memory): Switch current inferior and program space as well. (get_ps_regcache): Pass target down. * process-stratum-target.c (process_stratum_target::thread_address_space) (process_stratum_target::thread_architecture): Pass target down. * process-stratum-target.h (process_stratum_target::threads_executing): New field. (as_process_stratum_target): New. * ravenscar-thread.c (ravenscar_thread_target::update_inferior_ptid): Pass target down. (ravenscar_thread_target::wait, ravenscar_add_thread): Pass target down. * record-btrace.c (record_btrace_target::info_record): Adjust. (record_btrace_target::record_method) (record_btrace_target::record_is_replaying) (record_btrace_target::fetch_registers) (get_thread_current_frame_id, record_btrace_target::resume) (record_btrace_target::wait, record_btrace_target::stop): Pass target down. * record-full.c (record_full_wait_1): Switch to event thread. Pass target down. * regcache.c (regcache::regcache) (get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add process_stratum_target parameter and handle it. (current_thread_target): New global. (get_thread_regcache): Add process_stratum_target parameter and handle it. Switch inferior before calling target method. (get_thread_regcache): Pass target down. (get_thread_regcache_for_ptid): Pass target down. (registers_changed_ptid): Add process_stratum_target parameter and handle it. (registers_changed_thread, registers_changed): Pass target down. (test_get_thread_arch_aspace_regcache): New. (current_regcache_test): Define a couple local test_target_ops instances and use them for testing. (readwrite_regcache): Pass process_stratum_target parameter. (cooked_read_test, cooked_write_test): Pass mock_target down. * regcache.h (get_thread_regcache, get_thread_arch_regcache) (get_thread_arch_aspace_regcache): Add process_stratum_target parameter. (regcache::target): New method. (regcache::regcache, regcache::get_thread_arch_aspace_regcache) (regcache::registers_changed_ptid): Add process_stratum_target parameter. (regcache::m_target): New field. (registers_changed_ptid): Add process_stratum_target parameter. * remote.c (remote_state::supports_vCont_probed): New field. (remote_target::async_wait_fd): New method. (remote_unpush_and_throw): Add remote_target parameter. (get_current_remote_target): Adjust. (remote_target::remote_add_inferior): Push target. (remote_target::remote_add_thread) (remote_target::remote_notice_new_inferior) (get_remote_thread_info): Pass target down. (remote_target::update_thread_list): Skip threads of inferiors bound to other targets. (remote_target::close): Don't discard inferiors. (remote_target::add_current_inferior_and_thread) (remote_target::process_initial_stop_replies) (remote_target::start_remote) (remote_target::remote_serial_quit_handler): Pass down target. (remote_target::remote_unpush_target): New remote_target parameter. Unpush the target from all inferiors. (remote_target::remote_unpush_and_throw): New remote_target parameter. Pass it down. (remote_target::open_1): Check whether the current inferior has execution instead of checking whether any inferior is live. Pass target down. (remote_target::remote_detach_1): Pass down target. Use remote_unpush_target. (extended_remote_target::attach): Pass down target. (remote_target::remote_vcont_probe): Set supports_vCont_probed. (remote_target::append_resumption): Pass down target. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc, remote_target::resume) (remote_target::commit_resume): Pass down target. (remote_target::remote_stop_ns): Check supports_vCont_probed. (remote_target::interrupt_query) (remote_target::remove_new_fork_children) (remote_target::check_pending_events_prevent_wildcard_vcont) (remote_target::remote_parse_stop_reply) (remote_target::process_stop_reply): Pass down target. (first_remote_resumed_thread): New remote_target parameter. Pass it down. (remote_target::wait_as): Pass down target. (unpush_and_perror): New remote_target parameter. Pass it down. (remote_target::readchar, remote_target::remote_serial_write) (remote_target::getpkt_or_notif_sane_1) (remote_target::kill_new_fork_children, remote_target::kill): Pass down target. (remote_target::mourn_inferior): Pass down target. Use remote_unpush_target. (remote_target::core_of_thread) (remote_target::remote_btrace_maybe_reopen): Pass down target. (remote_target::pid_to_exec_file) (remote_target::thread_handle_to_thread_info): Pass down target. (remote_target::async_wait_fd): New. * riscv-fbsd-tdep.c: Include "inferior.h". (riscv_fbsd_get_thread_local_address): Pass down target. * sol2-tdep.c (sol2_core_pid_to_str): Pass down target. * sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs) (ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback): Adjust. * solib-spu.c (spu_skip_standalone_loader): Pass down target. * solib-svr4.c (enable_break): Pass down target. * spu-multiarch.c (parse_spufs_run): Pass down target. * spu-tdep.c (spu2ppu_sniffer): Pass down target. * target-delegates.c: Regenerate. * target.c (g_target_stack): Delete. (current_top_target): Return the current inferior's top target. (target_has_execution_1): Refer to the passed-in inferior's top target. (target_supports_terminal_ours): Check whether the initial inferior was already created. (decref_target): New. (target_stack::push): Incref/decref the target. (push_target, push_target, unpush_target): Adjust. (target_stack::unpush): Defref target. (target_is_pushed): Return bool. Adjust to refer to the current inferior's target stack. (dispose_inferior): Delete, and inline parts ... (target_preopen): ... here. Only dispose of the current inferior. (target_detach): Hold strong target reference while detaching. Pass target down. (target_thread_name): Add assertion. (target_resume): Pass down target. (target_ops::beneath, find_target_at): Adjust to refer to the current inferior's target stack. (get_dummy_target): New. (target_pass_ctrlc): Pass the Ctrl-C to the first inferior that has a thread running. (initialize_targets): Rename to ... (_initialize_target): ... this. * target.h: Include "gdbsupport/refcounted-object.h". (struct target_ops): Inherit refcounted_object. (target_ops::shortname, target_ops::longname): Make const. (target_ops::async_wait_fd): New method. (decref_target): Declare. (struct target_ops_ref_policy): New. (target_ops_ref): New typedef. (get_dummy_target): Declare function. (target_is_pushed): Return bool. * thread-iter.c (all_matching_threads_iterator::m_inf_matches) (all_matching_threads_iterator::all_matching_threads_iterator): Handle filter target. * thread-iter.h (struct all_matching_threads_iterator, struct all_matching_threads_range, class all_non_exited_threads_range): Filter by target too. Remove explicit. * thread.c (threads_executing): Delete. (inferior_thread): Pass down current inferior. (clear_thread_inferior_resources): Pass down thread pointer instead of ptid_t. (add_thread_silent, add_thread_with_info, add_thread): Add process_stratum_target parameter. Use it for thread and inferior searches. (is_current_thread): New. (thread_info::deletable): Use it. (find_thread_ptid, thread_count, in_thread_list) (thread_change_ptid, set_resumed, set_running): New process_stratum_target parameter. Pass it down. (set_executing): New process_stratum_target parameter. Pass it down. Adjust reference to 'threads_executing'. (threads_are_executing): New process_stratum_target parameter. Adjust reference to 'threads_executing'. (set_stop_requested, finish_thread_state): New process_stratum_target parameter. Pass it down. (switch_to_thread): Also match inferior. (switch_to_thread): New process_stratum_target parameter. Pass it down. (update_threads_executing): Reimplement. * top.c (quit_force): Pop targets from all inferior. (gdb_init): Don't call initialize_targets. * windows-nat.c (windows_nat_target) <get_windows_debug_event>: Declare. (windows_add_thread, windows_delete_thread): Adjust. (get_windows_debug_event): Rename to ... (windows_nat_target::get_windows_debug_event): ... this. Adjust. * tracefile-tfile.c (tfile_target_open): Pass down target. * gdbsupport/common-gdbthread.h (struct process_stratum_target): Forward declare. (switch_to_thread): Add process_stratum_target parameter. * mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target parameter. Use it. (mi_on_resume): Pass target down. * nat/fork-inferior.c (startup_inferior): Add process_stratum_target parameter. Pass it down. * nat/fork-inferior.h (startup_inferior): Add process_stratum_target parameter. * python/py-threadevent.c (py_get_event_thread): Pass target down. gdb/gdbserver/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> * fork-child.c (post_fork_inferior): Pass target down to startup_inferior. * inferiors.c (switch_to_thread): Add process_stratum_target parameter. * lynx-low.c (lynx_target_ops): Now a process_stratum_target. * nto-low.c (nto_target_ops): Now a process_stratum_target. * linux-low.c (linux_target_ops): Now a process_stratum_target. * remote-utils.c (prepare_resume_reply): Pass the target to switch_to_thread. * target.c (the_target): Now a process_stratum_target. (done_accessing_memory): Pass the target to switch_to_thread. (set_target_ops): Ajust to use process_stratum_target. * target.h (struct target_ops): Rename to ... (struct process_stratum_target): ... this. (the_target, set_target_ops): Adjust. (prepare_to_access_memory): Adjust comment. * win32-low.c (child_xfer_memory): Adjust to use process_stratum_target. (win32_target_ops): Now a process_stratum_target.
2020-01-10 21:06:08 +01:00
private:
/* The inferior's target stack. */
target_stack m_target_stack;
/* The name of terminal device to use for I/O. */
gdb::unique_xmalloc_ptr<char> m_terminal;
};
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* Keep a registry of per-inferior data-pointers required by other GDB
modules. */
* auto-load.c (_initialize_auto_load): Update. * solib-svr4.c (_initialize_svr4_solib): Update * solib-dsbt.c (_initialize_dsbt_solib): Update. * solib-darwin.c (_initialize_darwin_solib): Update. * registry.h: New file. * python/py-progspace.c (gdbpy_initialize_pspace): Update. * python/py-inferior.c (gdbpy_initialize_inferior): Update. * progspace.h: Include registry.h. Use DECLARE_REGISTRY. (register_program_space_data_with_cleanup) (register_program_space_data, program_space_alloc_data) (clear_program_space_data, set_program_space_data) (program_space_data): Don't declare. * progspace.c: Use DEFINE_REGISTRY. (struct program_space_data, struct program_space_data_registration, struct program_space_data_registry, program_space_data_registry) (register_program_space_data_with_cleanup) (register_program_space_data, program_space_alloc_data) (program_space_free_data, clear_program_space_data) (set_program_space_data, program_space_data): Remove. * objfiles.h: Include registry.h. Use DECLARE_REGISTRY. (struct objfile) <data, num_data>: Replace with REGISTRY_FIELDS. (register_objfile_data_with_cleanup, register_objfile_data) (clear_objfile_data, set_objfile_data, objfile_data): Don't declare. * objfiles.c: Use DEFINE_REGISTRY. (struct objfile_data, struct objfile_data_registration, struct objfile_data_registry, objfile_data_registry) (register_objfile_data_with_cleanup, register_objfile_data) (objfile_alloc_data, objfile_free_data, clear_objfile_data) (set_objfile_data, objfile_data): Remove. (_initialize_objfiles): Update. * jit.c (_initialize_jit): Update. * inflow.c (_initialize_inflow): Update. * inferior.h: Include registry.h. Use DECLARE_REGISTRY. (struct inferior) <data, num_data>: Replace with REGISTRY_FIELDS. (register_inferior_data_with_cleanup, register_inferior_data) (clear_inferior_data, set_inferior_data, inferior_data): Don't declare. * inferior.c: Use DEFINE_REGISTRY. (struct inferior_data, struct inferior_data_registration, struct inferior_data_registry, inferior_data_registry) (register_inferior_data_with_cleanup, register_inferior_data) (inferior_alloc_data, inferior_free_data clear_inferior_data) (set_inferior_data, inferior_data): Remove. * auxv.c (_initialize_auxv): Update. * ada-lang.c (_initialize_ada_language): Update. * breakpoint.c (_initialize_breakpoint): Update. * i386-nat.c (i386_use_watchpoints): Update.
2012-08-22 17:17:21 +02:00
DECLARE_REGISTRY (inferior);
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* Add an inferior to the inferior list, print a message that a new
inferior is found, and return the pointer to the new inferior.
Caller may use this pointer to initialize the private inferior
data. */
extern struct inferior *add_inferior (int pid);
/* Same as add_inferior, but don't print new inferior notifications to
the CLI. */
extern struct inferior *add_inferior_silent (int pid);
Delete program spaces directly when removing inferiors When deleting an inferior, delete the associated program space as well if it becomes unused. This replaces the "pruning" approach, with which you could forget to call prune_program_spaces (as seen, with the -remove-inferior command, see [1]). This allows to remove the prune_program_spaces function. At the same time, I was able to clean up the delete_inferior* family: - delete_inferior is unused - delete_inferior_silent is only used in monitor_close, but is replaced with discard_all_inferiors [2], so it becomes unused - All remaining calls to delete_inferior_1 are with silent=1, so the parameter is removed - delete_inferior_1 is renamed to delete_inferior I renamed pspace_empty_p to program_space_empty_p. I prefer if the "exported" functions have a more explicit and standard name. Tested on Ubuntu 14.10. [1] https://sourceware.org/ml/gdb-patches/2014-09/msg00717.html [2] See https://sourceware.org/ml/gdb-patches/2015-07/msg00228.html and follow-ups for details. gdb/Changelog: * inferior.c (delete_inferior_1): Rename to ... (delete_inferior): ..., remove 'silent' parameter, delete program space when unused and remove call to prune_program_spaces. Remove the old, unused, delete_inferior. (delete_inferior_silent): Remove. (prune_inferiors): Change call from delete_inferior_1 to delete_inferior and remove 'silent' parameter. Remove call to prune_program_spaces. (remove_inferior_command): Idem. * inferior.h (delete_inferior_1): Rename to... (delete_inferior): ..., remove 'silent' parameter and remove the original delete_inferior. (delete_inferior_silent): Remove. * mi/mi-main.c (mi_cmd_remove_inferior): Change call from delete_inferior_1 to delete_inferior and remove 'silent' parameter. * progspace.c (prune_program_spaces): Remove. (pspace_empty_p): Rename to... (program_space_empty_p): ... and make non-static. (delete_program_space): New. * progspace.h (prune_program_spaces): Remove declaration. (program_space_empty_p): New declaration. (delete_program_space): New declaration. * monitor.c (monitor_close): Replace call to delete_thread_silent and delete_inferior_silent with discard_all_inferiors.
2015-07-08 21:41:01 +02:00
extern void delete_inferior (struct inferior *todel);
/* Delete an existing inferior list entry, due to inferior detaching. */
extern void detach_inferior (inferior *inf);
Use thread_info and inferior pointers more throughout 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.
2018-06-21 18:09:31 +02:00
extern void exit_inferior (inferior *inf);
Use thread_info and inferior pointers more throughout 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.
2018-06-21 18:09:31 +02:00
extern void exit_inferior_silent (inferior *inf);
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
extern void exit_inferior_num_silent (int num);
extern void inferior_appeared (struct inferior *inf, int pid);
Multi-target support This commit adds multi-target support to GDB. What this means is that with this commit, GDB can now be connected to different targets at the same time. E.g., you can debug a live native process and a core dump at the same time, connect to multiple gdbservers, etc. Actually, the word "target" is overloaded in gdb. We already have a target stack, with pushes several target_ops instances on top of one another. We also have "info target" already, which means something completely different to what this patch does. So from here on, I'll be using the "target connections" term, to mean an open process_stratum target, pushed on a target stack. This patch makes gdb have multiple target stacks, and multiple process_stratum targets open simultaneously. The user-visible changes / commands will also use this terminology, but of course it's all open to debate. User-interface-wise, not that much changes. The main difference is that each inferior may have its own target connection. A target connection (e.g., a target extended-remote connection) may support debugging multiple processes, just as before. Say you're debugging against gdbserver in extended-remote mode, and you do "add-inferior" to prepare to spawn a new process, like: (gdb) target extended-remote :9999 ... (gdb) start ... (gdb) add-inferior Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) file a.out ... (gdb) start ... At this point, you have two inferiors connected to the same gdbserver. With this commit, GDB will maintain a target stack per inferior, instead of a global target stack. To preserve the behavior above, by default, "add-inferior" makes the new inferior inherit a copy of the target stack of the current inferior. Same across a fork - the child inherits a copy of the target stack of the parent. While the target stacks are copied, the targets themselves are not. Instead, target_ops is made a refcounted_object, which means that target_ops instances are refcounted, which each inferior counting for a reference. What if you want to create an inferior and connect it to some _other_ target? For that, this commit introduces a new "add-inferior -no-connection" option that makes the new inferior not share the current inferior's target. So you could do: (gdb) target extended-remote :9999 Remote debugging using :9999 ... (gdb) add-inferior -no-connection [New inferior 2] Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 <null> (gdb) tar extended-remote :10000 Remote debugging using :10000 ... (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 process 18450 target:/home/pedro/tmp/main (gdb) A following patch will extended "info inferiors" to include a column indicating which connection an inferior is bound to, along with a couple other UI tweaks. Other than that, debugging is the same as before. Users interact with inferiors and threads as before. The only difference is that inferiors may be bound to processes running in different machines. That's pretty much all there is to it in terms of noticeable UI changes. On to implementation. Since we can be connected to different systems at the same time, a ptid_t is no longer a unique identifier. Instead a thread can be identified by a pair of ptid_t and 'process_stratum_target *', the later being the instance of the process_stratum target that owns the process/thread. Note that process_stratum_target inherits from target_ops, and all process_stratum targets inherit from process_stratum_target. In earlier patches, many places in gdb were converted to refer to threads by thread_info pointer instead of ptid_t, but there are still places in gdb where we start with a pid/tid and need to find the corresponding inferior or thread_info objects. So you'll see in the patch many places adding a process_stratum_target parameter to functions that used to take only a ptid_t. Since each inferior has its own target stack now, we can always find the process_stratum target for an inferior. That is done via a inf->process_target() convenience method. Since each inferior has its own target stack, we need to handle the "beneath" calls when servicing target calls. The solution I settled with is just to make sure to switch the current inferior to the inferior you want before making a target call. Not relying on global context is just not feasible in current GDB. Fortunately, there aren't that many places that need to do that, because generally most code that calls target methods already has the current context pointing to the right inferior/thread. Note, to emphasize -- there's no method to "switch to this target stack". Instead, you switch the current inferior, and that implicitly switches the target stack. In some spots, we need to iterate over all inferiors so that we reach all target stacks. Native targets are still singletons. There's always only a single instance of such targets. Remote targets however, we'll have one instance per remote connection. The exec target is still a singleton. There's only one instance. I did not see the point of instanciating more than one exec_target object. After vfork, we need to make sure to push the exec target on the new inferior. See exec_on_vfork. For type safety, functions that need a {target, ptid} pair to identify a thread, take a process_stratum_target pointer for target parameter instead of target_ops *. Some shared code in gdb/nat/ also need to gain a target pointer parameter. This poses an issue, since gdbserver doesn't have process_stratum_target, only target_ops. To fix this, this commit renames gdbserver's target_ops to process_stratum_target. I think this makes sense. There's no concept of target stack in gdbserver, and gdbserver's target_ops really implements a process_stratum-like target. The thread and inferior iterator functions also gain process_stratum_target parameters. These are used to be able to iterate over threads and inferiors of a given target. Following usual conventions, if the target pointer is null, then we iterate over threads and inferiors of all targets. I tried converting "add-inferior" to the gdb::option framework, as a preparatory patch, but that stumbled on the fact that gdb::option does not support file options yet, for "add-inferior -exec". I have a WIP patchset that adds that, but it's not a trivial patch, mainly due to need to integrate readline's filename completion, so I deferred that to some other time. In infrun.c/infcmd.c, the main change is that we need to poll events out of all targets. See do_target_wait. Right after collecting an event, we switch the current inferior to an inferior bound to the target that reported the event, so that target methods can be used while handling the event. This makes most of the code transparent to multi-targets. See fetch_inferior_event. infrun.c:stop_all_threads is interesting -- in this function we need to stop all threads of all targets. What the function does is send an asynchronous stop request to all threads, and then synchronously waits for events, with target_wait, rinse repeat, until all it finds are stopped threads. Now that we have multiple targets, it's not efficient to synchronously block in target_wait waiting for events out of one target. Instead, we implement a mini event loop, with interruptible_select, select'ing on one file descriptor per target. For this to work, we need to be able to ask the target for a waitable file descriptor. Such file descriptors already exist, they are the descriptors registered in the main event loop with add_file_handler, inside the target_async implementations. This commit adds a new target_async_wait_fd target method that just returns the file descriptor in question. See wait_one / stop_all_threads in infrun.c. The 'threads_executing' global is made a per-target variable. Since it is only relevant to process_stratum_target targets, this is where it is put, instead of in target_ops. You'll notice that remote.c includes some FIXME notes. These refer to the fact that the global arrays that hold data for the remote packets supported are still globals. For example, if we connect to two different servers/stubs, then each might support different remote protocol features. They might even be different architectures, like e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a host/controller scenario as a single program. That isn't going to work correctly today, because of said globals. I'm leaving fixing that for another pass, since it does not appear to be trivial, and I'd rather land the base work first. It's already useful to be able to debug multiple instances of the same server (e.g., a distributed cluster, where you have full control over the servers installed), so I think as is it's already reasonable incremental progress. Current limitations: - You can only resume more that one target at the same time if all targets support asynchronous debugging, and support non-stop mode. It should be possible to support mixed all-stop + non-stop backends, but that is left for another time. This means that currently in order to do multi-target with gdbserver you need to issue "maint set target-non-stop on". I would like to make that mode be the default, but we're not there yet. Note that I'm talking about how the target backend works, only. User-visible all-stop mode works just fine. - As explained above, connecting to different remote servers at the same time is likely to produce bad results if they don't support the exact set of RSP features. FreeBSD updates courtesy of John Baldwin. gdb/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> John Baldwin <jhb@FreeBSD.org> * aarch64-linux-nat.c (aarch64_linux_nat_target::thread_architecture): Adjust. * ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call. (task_command_1): Likewise. * aix-thread.c (sync_threadlists, aix_thread_target::resume) (aix_thread_target::wait, aix_thread_target::fetch_registers) (aix_thread_target::store_registers) (aix_thread_target::thread_alive): Adjust. * amd64-fbsd-tdep.c: Include "inferior.h". (amd64fbsd_get_thread_local_address): Pass down target. * amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle thread's gdbarch instead of target_gdbarch. * break-catch-sig.c (signal_catchpoint_print_it): Adjust call to get_last_target_status. * break-catch-syscall.c (print_it_catch_syscall): Likewise. * breakpoint.c (breakpoints_should_be_inserted_now): Consider all inferiors. (update_inserted_breakpoint_locations): Skip if inferiors with no execution. (update_global_location_list): When handling moribund locations, find representative inferior for location's pspace, and use thread count of its process_stratum target. * bsd-kvm.c (bsd_kvm_target_open): Pass target down. * bsd-uthread.c (bsd_uthread_target::wait): Use as_process_stratum_target and adjust thread_change_ptid and add_thread calls. (bsd_uthread_target::update_thread_list): Use as_process_stratum_target and adjust find_thread_ptid, thread_change_ptid and add_thread calls. * btrace.c (maint_btrace_packet_history_cmd): Adjust find_thread_ptid call. * corelow.c (add_to_thread_list): Adjust add_thread call. (core_target_open): Adjust add_thread_silent and thread_count calls. (core_target::pid_to_str): Adjust find_inferior_ptid call. * ctf.c (ctf_target_open): Adjust add_thread_silent call. * event-top.c (async_disconnect): Pop targets from all inferiors. * exec.c (add_target_sections): Push exec target on all inferiors sharing the program space. (remove_target_sections): Remove the exec target from all inferiors sharing the program space. (exec_on_vfork): New. * exec.h (exec_on_vfork): Declare. * fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::update_thread_list): Adjust. (fbsd_nat_target::resume): Adjust. (fbsd_handle_debug_trap): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust. * fbsd-tdep.c (fbsd_corefile_thread): Adjust get_thread_arch_regcache call. * fork-child.c (gdb_startup_inferior): Pass target down to startup_inferior and set_executing. * gdbthread.h (struct process_stratum_target): Forward declare. (add_thread, add_thread_silent, add_thread_with_info) (in_thread_list): Add process_stratum_target parameter. (find_thread_ptid(inferior*, ptid_t)): New overload. (find_thread_ptid, thread_change_ptid): Add process_stratum_target parameter. (all_threads()): Delete overload. (all_threads, all_non_exited_threads): Add process_stratum_target parameter. (all_threads_safe): Use brace initialization. (thread_count): Add process_stratum_target parameter. (set_resumed, set_running, set_stop_requested, set_executing) (threads_are_executing, finish_thread_state): Add process_stratum_target parameter. (switch_to_thread): Use is_current_thread. * i386-fbsd-tdep.c: Include "inferior.h". (i386fbsd_get_thread_local_address): Pass down target. * i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust. * inf-child.c (inf_child_target::maybe_unpush_target): Remove have_inferiors check. * inf-ptrace.c (inf_ptrace_target::create_inferior) (inf_ptrace_target::attach): Adjust. * infcall.c (run_inferior_call): Adjust. * infcmd.c (run_command_1): Pass target to scoped_finish_thread_state. (proceed_thread_callback): Skip inferiors with no execution. (continue_command): Rename 'all_threads' local to avoid hiding 'all_threads' function. Adjust get_last_target_status call. (prepare_one_step): Adjust set_running call. (signal_command): Use user_visible_resume_target. Compare thread pointers instead of inferior_ptid. (info_program_command): Adjust to pass down target. (attach_command): Mark target's 'thread_executing' flag. (stop_current_target_threads_ns): New, factored out from ... (interrupt_target_1): ... this. Switch inferior before making target calls. * inferior-iter.h (struct all_inferiors_iterator, struct all_inferiors_range) (struct all_inferiors_safe_range) (struct all_non_exited_inferiors_range): Filter on process_stratum_target too. Remove explicit. * inferior.c (inferior::inferior): Push dummy target on target stack. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors): Add process_stratum_target parameter, and pass it down. (have_live_inferiors): Adjust. (switch_to_inferior_and_push_target): New. (add_inferior_command, clone_inferior_command): Handle "-no-connection" parameter. Use switch_to_inferior_and_push_target. (_initialize_inferior): Mention "-no-connection" option in the help of "add-inferior" and "clone-inferior" commands. * inferior.h: Include "process-stratum-target.h". (interrupt_target_1): Use bool. (struct inferior) <push_target, unpush_target, target_is_pushed, find_target_beneath, top_target, process_target, target_at, m_stack>: New. (discard_all_inferiors): Delete. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors) (all_inferiors, all_non_exited_inferiors): Add process_stratum_target parameter. * infrun.c: Include "gdb_select.h" and <unordered_map>. (target_last_proc_target): New global. (follow_fork_inferior): Push target on new inferior. Pass target to add_thread_silent. Call exec_on_vfork. Handle target's reference count. (follow_fork): Adjust get_last_target_status call. Also consider target. (follow_exec): Push target on new inferior. (struct execution_control_state) <target>: New field. (user_visible_resume_target): New. (do_target_resume): Call target_async. (resume_1): Set target's threads_executing flag. Consider resume target. (commit_resume_all_targets): New. (proceed): Also consider resume target. Skip threads of inferiors with no execution. Commit resumtion in all targets. (start_remote): Pass current inferior to wait_for_inferior. (infrun_thread_stop_requested): Consider target as well. Pass thread_info pointer to clear_inline_frame_state instead of ptid. (infrun_thread_thread_exit): Consider target as well. (random_pending_event_thread): New inferior parameter. Use it. (do_target_wait): Rename to ... (do_target_wait_1): ... this. Add inferior parameter, and pass it down. (threads_are_resumed_pending_p, do_target_wait): New. (prepare_for_detach): Adjust calls. (wait_for_inferior): New inferior parameter. Handle it. Use do_target_wait_1 instead of do_target_wait. (fetch_inferior_event): Adjust. Switch to representative inferior. Pass target down. (set_last_target_status): Add process_stratum_target parameter. Save target in global. (get_last_target_status): Add process_stratum_target parameter and handle it. (nullify_last_target_wait_ptid): Clear 'target_last_proc_target'. (context_switch): Check inferior_ptid == null_ptid before calling inferior_thread(). (get_inferior_stop_soon): Pass down target. (wait_one): Rename to ... (poll_one_curr_target): ... this. (struct wait_one_event): New. (wait_one): New. (stop_all_threads): Adjust. (handle_no_resumed, handle_inferior_event): Adjust to consider the event's target. (switch_back_to_stepped_thread): Also consider target. (print_stop_event): Update. (normal_stop): Update. Also consider the resume target. * infrun.h (wait_for_inferior): Remove declaration. (user_visible_resume_target): New declaration. (get_last_target_status, set_last_target_status): New process_stratum_target parameter. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter, and use it. (clear_inline_frame_state (thread_info*)): New. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter. (clear_inline_frame_state (thread_info*)): Declare. * linux-fork.c (delete_checkpoint_command): Pass target down to find_thread_ptid. (checkpoint_command): Adjust. * linux-nat.c (linux_nat_target::follow_fork): Switch to thread instead of just tweaking inferior_ptid. (linux_nat_switch_fork): Pass target down to thread_change_ptid. (exit_lwp): Pass target down to find_thread_ptid. (attach_proc_task_lwp_callback): Pass target down to add_thread/set_running/set_executing. (linux_nat_target::attach): Pass target down to thread_change_ptid. (get_detach_signal): Pass target down to find_thread_ptid. Consider last target status's target. (linux_resume_one_lwp_throw, resume_lwp) (linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp) (stop_wait_callback, save_stop_reason, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down. (linux_nat_target::async_wait_fd): New. (linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass target down. * linux-nat.h (linux_nat_target::async_wait_fd): Declare. * linux-tdep.c (get_thread_arch_regcache): Pass target down. * linux-thread-db.c (struct thread_db_info::process_target): New field. (add_thread_db_info): Save target. (get_thread_db_info): New process_stratum_target parameter. Also match target. (delete_thread_db_info): New process_stratum_target parameter. Also match target. (thread_from_lwp): Adjust to pass down target. (thread_db_notice_clone): Pass down target. (check_thread_db_callback): Pass down target. (try_thread_db_load_1): Always push the thread_db target. (try_thread_db_load, record_thread): Pass target down. (thread_db_target::detach): Pass target down. Always unpush the thread_db target. (thread_db_target::wait, thread_db_target::mourn_inferior): Pass target down. Always unpush the thread_db target. (find_new_threads_callback, thread_db_find_new_threads_2) (thread_db_target::update_thread_list): Pass target down. (thread_db_target::pid_to_str): Pass current inferior down. (thread_db_target::get_thread_local_address): Pass target down. (thread_db_target::resume, maintenance_check_libthread_db): Pass target down. * nto-procfs.c (nto_procfs_target::update_thread_list): Adjust. * procfs.c (procfs_target::procfs_init_inferior): Declare. (proc_set_current_signal, do_attach, procfs_target::wait): Adjust. (procfs_init_inferior): Rename to ... (procfs_target::procfs_init_inferior): ... this and adjust. (procfs_target::create_inferior, procfs_notice_thread) (procfs_do_thread_registers): Adjust. * ppc-fbsd-tdep.c: Include "inferior.h". (ppcfbsd_get_thread_local_address): Pass down target. * proc-service.c (ps_xfer_memory): Switch current inferior and program space as well. (get_ps_regcache): Pass target down. * process-stratum-target.c (process_stratum_target::thread_address_space) (process_stratum_target::thread_architecture): Pass target down. * process-stratum-target.h (process_stratum_target::threads_executing): New field. (as_process_stratum_target): New. * ravenscar-thread.c (ravenscar_thread_target::update_inferior_ptid): Pass target down. (ravenscar_thread_target::wait, ravenscar_add_thread): Pass target down. * record-btrace.c (record_btrace_target::info_record): Adjust. (record_btrace_target::record_method) (record_btrace_target::record_is_replaying) (record_btrace_target::fetch_registers) (get_thread_current_frame_id, record_btrace_target::resume) (record_btrace_target::wait, record_btrace_target::stop): Pass target down. * record-full.c (record_full_wait_1): Switch to event thread. Pass target down. * regcache.c (regcache::regcache) (get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add process_stratum_target parameter and handle it. (current_thread_target): New global. (get_thread_regcache): Add process_stratum_target parameter and handle it. Switch inferior before calling target method. (get_thread_regcache): Pass target down. (get_thread_regcache_for_ptid): Pass target down. (registers_changed_ptid): Add process_stratum_target parameter and handle it. (registers_changed_thread, registers_changed): Pass target down. (test_get_thread_arch_aspace_regcache): New. (current_regcache_test): Define a couple local test_target_ops instances and use them for testing. (readwrite_regcache): Pass process_stratum_target parameter. (cooked_read_test, cooked_write_test): Pass mock_target down. * regcache.h (get_thread_regcache, get_thread_arch_regcache) (get_thread_arch_aspace_regcache): Add process_stratum_target parameter. (regcache::target): New method. (regcache::regcache, regcache::get_thread_arch_aspace_regcache) (regcache::registers_changed_ptid): Add process_stratum_target parameter. (regcache::m_target): New field. (registers_changed_ptid): Add process_stratum_target parameter. * remote.c (remote_state::supports_vCont_probed): New field. (remote_target::async_wait_fd): New method. (remote_unpush_and_throw): Add remote_target parameter. (get_current_remote_target): Adjust. (remote_target::remote_add_inferior): Push target. (remote_target::remote_add_thread) (remote_target::remote_notice_new_inferior) (get_remote_thread_info): Pass target down. (remote_target::update_thread_list): Skip threads of inferiors bound to other targets. (remote_target::close): Don't discard inferiors. (remote_target::add_current_inferior_and_thread) (remote_target::process_initial_stop_replies) (remote_target::start_remote) (remote_target::remote_serial_quit_handler): Pass down target. (remote_target::remote_unpush_target): New remote_target parameter. Unpush the target from all inferiors. (remote_target::remote_unpush_and_throw): New remote_target parameter. Pass it down. (remote_target::open_1): Check whether the current inferior has execution instead of checking whether any inferior is live. Pass target down. (remote_target::remote_detach_1): Pass down target. Use remote_unpush_target. (extended_remote_target::attach): Pass down target. (remote_target::remote_vcont_probe): Set supports_vCont_probed. (remote_target::append_resumption): Pass down target. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc, remote_target::resume) (remote_target::commit_resume): Pass down target. (remote_target::remote_stop_ns): Check supports_vCont_probed. (remote_target::interrupt_query) (remote_target::remove_new_fork_children) (remote_target::check_pending_events_prevent_wildcard_vcont) (remote_target::remote_parse_stop_reply) (remote_target::process_stop_reply): Pass down target. (first_remote_resumed_thread): New remote_target parameter. Pass it down. (remote_target::wait_as): Pass down target. (unpush_and_perror): New remote_target parameter. Pass it down. (remote_target::readchar, remote_target::remote_serial_write) (remote_target::getpkt_or_notif_sane_1) (remote_target::kill_new_fork_children, remote_target::kill): Pass down target. (remote_target::mourn_inferior): Pass down target. Use remote_unpush_target. (remote_target::core_of_thread) (remote_target::remote_btrace_maybe_reopen): Pass down target. (remote_target::pid_to_exec_file) (remote_target::thread_handle_to_thread_info): Pass down target. (remote_target::async_wait_fd): New. * riscv-fbsd-tdep.c: Include "inferior.h". (riscv_fbsd_get_thread_local_address): Pass down target. * sol2-tdep.c (sol2_core_pid_to_str): Pass down target. * sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs) (ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback): Adjust. * solib-spu.c (spu_skip_standalone_loader): Pass down target. * solib-svr4.c (enable_break): Pass down target. * spu-multiarch.c (parse_spufs_run): Pass down target. * spu-tdep.c (spu2ppu_sniffer): Pass down target. * target-delegates.c: Regenerate. * target.c (g_target_stack): Delete. (current_top_target): Return the current inferior's top target. (target_has_execution_1): Refer to the passed-in inferior's top target. (target_supports_terminal_ours): Check whether the initial inferior was already created. (decref_target): New. (target_stack::push): Incref/decref the target. (push_target, push_target, unpush_target): Adjust. (target_stack::unpush): Defref target. (target_is_pushed): Return bool. Adjust to refer to the current inferior's target stack. (dispose_inferior): Delete, and inline parts ... (target_preopen): ... here. Only dispose of the current inferior. (target_detach): Hold strong target reference while detaching. Pass target down. (target_thread_name): Add assertion. (target_resume): Pass down target. (target_ops::beneath, find_target_at): Adjust to refer to the current inferior's target stack. (get_dummy_target): New. (target_pass_ctrlc): Pass the Ctrl-C to the first inferior that has a thread running. (initialize_targets): Rename to ... (_initialize_target): ... this. * target.h: Include "gdbsupport/refcounted-object.h". (struct target_ops): Inherit refcounted_object. (target_ops::shortname, target_ops::longname): Make const. (target_ops::async_wait_fd): New method. (decref_target): Declare. (struct target_ops_ref_policy): New. (target_ops_ref): New typedef. (get_dummy_target): Declare function. (target_is_pushed): Return bool. * thread-iter.c (all_matching_threads_iterator::m_inf_matches) (all_matching_threads_iterator::all_matching_threads_iterator): Handle filter target. * thread-iter.h (struct all_matching_threads_iterator, struct all_matching_threads_range, class all_non_exited_threads_range): Filter by target too. Remove explicit. * thread.c (threads_executing): Delete. (inferior_thread): Pass down current inferior. (clear_thread_inferior_resources): Pass down thread pointer instead of ptid_t. (add_thread_silent, add_thread_with_info, add_thread): Add process_stratum_target parameter. Use it for thread and inferior searches. (is_current_thread): New. (thread_info::deletable): Use it. (find_thread_ptid, thread_count, in_thread_list) (thread_change_ptid, set_resumed, set_running): New process_stratum_target parameter. Pass it down. (set_executing): New process_stratum_target parameter. Pass it down. Adjust reference to 'threads_executing'. (threads_are_executing): New process_stratum_target parameter. Adjust reference to 'threads_executing'. (set_stop_requested, finish_thread_state): New process_stratum_target parameter. Pass it down. (switch_to_thread): Also match inferior. (switch_to_thread): New process_stratum_target parameter. Pass it down. (update_threads_executing): Reimplement. * top.c (quit_force): Pop targets from all inferior. (gdb_init): Don't call initialize_targets. * windows-nat.c (windows_nat_target) <get_windows_debug_event>: Declare. (windows_add_thread, windows_delete_thread): Adjust. (get_windows_debug_event): Rename to ... (windows_nat_target::get_windows_debug_event): ... this. Adjust. * tracefile-tfile.c (tfile_target_open): Pass down target. * gdbsupport/common-gdbthread.h (struct process_stratum_target): Forward declare. (switch_to_thread): Add process_stratum_target parameter. * mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target parameter. Use it. (mi_on_resume): Pass target down. * nat/fork-inferior.c (startup_inferior): Add process_stratum_target parameter. Pass it down. * nat/fork-inferior.h (startup_inferior): Add process_stratum_target parameter. * python/py-threadevent.c (py_get_event_thread): Pass target down. gdb/gdbserver/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> * fork-child.c (post_fork_inferior): Pass target down to startup_inferior. * inferiors.c (switch_to_thread): Add process_stratum_target parameter. * lynx-low.c (lynx_target_ops): Now a process_stratum_target. * nto-low.c (nto_target_ops): Now a process_stratum_target. * linux-low.c (linux_target_ops): Now a process_stratum_target. * remote-utils.c (prepare_resume_reply): Pass the target to switch_to_thread. * target.c (the_target): Now a process_stratum_target. (done_accessing_memory): Pass the target to switch_to_thread. (set_target_ops): Ajust to use process_stratum_target. * target.h (struct target_ops): Rename to ... (struct process_stratum_target): ... this. (the_target, set_target_ops): Adjust. (prepare_to_access_memory): Adjust comment. * win32-low.c (child_xfer_memory): Adjust to use process_stratum_target. (win32_target_ops): Now a process_stratum_target.
2020-01-10 21:06:08 +01:00
/* Search function to lookup an inferior of TARG by target 'pid'. */
extern struct inferior *find_inferior_pid (process_stratum_target *targ,
int pid);
Implement remote multi-process extensions. * remote.c (struct remote_state): Add extended and multi_process_aware fields. (remote_multi_process_p): New. (PACKET_vKill): New. (record_currthread): Use thread_change_ptid. Notice new inferiors. (set_thread, remote_thread_alive): Use write_ptid. (write_ptid, read_ptid): New. (remote_current_thread, remote_threads_extra_info): Use them. (remote_threads_info): Likewise. Detect new inferiors. (remote_start_remote): Add inferior to inferior list. (remote_multi_process_feature): New. (remote_protocol_features): Add "multiprocess" feature. (remote_query_supported): Pass "multiprocess+" as supported features. (remote_open_1): Clear multi_process_aware. Set extended accordingly. (remote_detach_1): Detach current process. Use extended packet format for extended-remote multi-process. Detach process from the inferior list. Only mourn after printing output. (extended_remote_attach_1): Add process to the inferior list. (remote_vcont_resume): Use write_ptid to pass the thread ids. (remote_wait): Use read_ptid. Implement the extended multi-process extension format of the 'W' and 'X' reply packets. Remove exited inferiors from inferior list. (remote_xfer_memory): Set general thread. (remote_vkill): New. (extended_remote_kill): New. (remote_mourn_1): Discard all inferiors. (select_new_thread_callback): New. (extended_remote_mourn_1): If there are more processes to debug, switch to a thread in another process, and don't pop the target. (extended_remote_create_inferior_1): Add the new process to the inferior list. (remote_stopped_by_watchpoint): Indenting. (remote_xfer_partial): Set the general thread. (remote_pid_to_str): If the remote is multi-process aware, print the process id as well as the thread id. (remote_get_thread_local_address): Use write_ptid. (init_extended_remote_ops): Register extended_remote_kill. (_initialize_remote): Register new packets. Change magic_null_ptid's, not_sent_ptid's and any_thread_ptid's pid member to 42000. * thread.c (thread_change_ptid): Also account for the inferior pid changing. * inferior.h (discard_all_inferiors): Declare. * inferior.c (discard_all_inferiors): New.
2008-09-22 17:18:30 +02:00
Multi-target support This commit adds multi-target support to GDB. What this means is that with this commit, GDB can now be connected to different targets at the same time. E.g., you can debug a live native process and a core dump at the same time, connect to multiple gdbservers, etc. Actually, the word "target" is overloaded in gdb. We already have a target stack, with pushes several target_ops instances on top of one another. We also have "info target" already, which means something completely different to what this patch does. So from here on, I'll be using the "target connections" term, to mean an open process_stratum target, pushed on a target stack. This patch makes gdb have multiple target stacks, and multiple process_stratum targets open simultaneously. The user-visible changes / commands will also use this terminology, but of course it's all open to debate. User-interface-wise, not that much changes. The main difference is that each inferior may have its own target connection. A target connection (e.g., a target extended-remote connection) may support debugging multiple processes, just as before. Say you're debugging against gdbserver in extended-remote mode, and you do "add-inferior" to prepare to spawn a new process, like: (gdb) target extended-remote :9999 ... (gdb) start ... (gdb) add-inferior Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) file a.out ... (gdb) start ... At this point, you have two inferiors connected to the same gdbserver. With this commit, GDB will maintain a target stack per inferior, instead of a global target stack. To preserve the behavior above, by default, "add-inferior" makes the new inferior inherit a copy of the target stack of the current inferior. Same across a fork - the child inherits a copy of the target stack of the parent. While the target stacks are copied, the targets themselves are not. Instead, target_ops is made a refcounted_object, which means that target_ops instances are refcounted, which each inferior counting for a reference. What if you want to create an inferior and connect it to some _other_ target? For that, this commit introduces a new "add-inferior -no-connection" option that makes the new inferior not share the current inferior's target. So you could do: (gdb) target extended-remote :9999 Remote debugging using :9999 ... (gdb) add-inferior -no-connection [New inferior 2] Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 <null> (gdb) tar extended-remote :10000 Remote debugging using :10000 ... (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 process 18450 target:/home/pedro/tmp/main (gdb) A following patch will extended "info inferiors" to include a column indicating which connection an inferior is bound to, along with a couple other UI tweaks. Other than that, debugging is the same as before. Users interact with inferiors and threads as before. The only difference is that inferiors may be bound to processes running in different machines. That's pretty much all there is to it in terms of noticeable UI changes. On to implementation. Since we can be connected to different systems at the same time, a ptid_t is no longer a unique identifier. Instead a thread can be identified by a pair of ptid_t and 'process_stratum_target *', the later being the instance of the process_stratum target that owns the process/thread. Note that process_stratum_target inherits from target_ops, and all process_stratum targets inherit from process_stratum_target. In earlier patches, many places in gdb were converted to refer to threads by thread_info pointer instead of ptid_t, but there are still places in gdb where we start with a pid/tid and need to find the corresponding inferior or thread_info objects. So you'll see in the patch many places adding a process_stratum_target parameter to functions that used to take only a ptid_t. Since each inferior has its own target stack now, we can always find the process_stratum target for an inferior. That is done via a inf->process_target() convenience method. Since each inferior has its own target stack, we need to handle the "beneath" calls when servicing target calls. The solution I settled with is just to make sure to switch the current inferior to the inferior you want before making a target call. Not relying on global context is just not feasible in current GDB. Fortunately, there aren't that many places that need to do that, because generally most code that calls target methods already has the current context pointing to the right inferior/thread. Note, to emphasize -- there's no method to "switch to this target stack". Instead, you switch the current inferior, and that implicitly switches the target stack. In some spots, we need to iterate over all inferiors so that we reach all target stacks. Native targets are still singletons. There's always only a single instance of such targets. Remote targets however, we'll have one instance per remote connection. The exec target is still a singleton. There's only one instance. I did not see the point of instanciating more than one exec_target object. After vfork, we need to make sure to push the exec target on the new inferior. See exec_on_vfork. For type safety, functions that need a {target, ptid} pair to identify a thread, take a process_stratum_target pointer for target parameter instead of target_ops *. Some shared code in gdb/nat/ also need to gain a target pointer parameter. This poses an issue, since gdbserver doesn't have process_stratum_target, only target_ops. To fix this, this commit renames gdbserver's target_ops to process_stratum_target. I think this makes sense. There's no concept of target stack in gdbserver, and gdbserver's target_ops really implements a process_stratum-like target. The thread and inferior iterator functions also gain process_stratum_target parameters. These are used to be able to iterate over threads and inferiors of a given target. Following usual conventions, if the target pointer is null, then we iterate over threads and inferiors of all targets. I tried converting "add-inferior" to the gdb::option framework, as a preparatory patch, but that stumbled on the fact that gdb::option does not support file options yet, for "add-inferior -exec". I have a WIP patchset that adds that, but it's not a trivial patch, mainly due to need to integrate readline's filename completion, so I deferred that to some other time. In infrun.c/infcmd.c, the main change is that we need to poll events out of all targets. See do_target_wait. Right after collecting an event, we switch the current inferior to an inferior bound to the target that reported the event, so that target methods can be used while handling the event. This makes most of the code transparent to multi-targets. See fetch_inferior_event. infrun.c:stop_all_threads is interesting -- in this function we need to stop all threads of all targets. What the function does is send an asynchronous stop request to all threads, and then synchronously waits for events, with target_wait, rinse repeat, until all it finds are stopped threads. Now that we have multiple targets, it's not efficient to synchronously block in target_wait waiting for events out of one target. Instead, we implement a mini event loop, with interruptible_select, select'ing on one file descriptor per target. For this to work, we need to be able to ask the target for a waitable file descriptor. Such file descriptors already exist, they are the descriptors registered in the main event loop with add_file_handler, inside the target_async implementations. This commit adds a new target_async_wait_fd target method that just returns the file descriptor in question. See wait_one / stop_all_threads in infrun.c. The 'threads_executing' global is made a per-target variable. Since it is only relevant to process_stratum_target targets, this is where it is put, instead of in target_ops. You'll notice that remote.c includes some FIXME notes. These refer to the fact that the global arrays that hold data for the remote packets supported are still globals. For example, if we connect to two different servers/stubs, then each might support different remote protocol features. They might even be different architectures, like e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a host/controller scenario as a single program. That isn't going to work correctly today, because of said globals. I'm leaving fixing that for another pass, since it does not appear to be trivial, and I'd rather land the base work first. It's already useful to be able to debug multiple instances of the same server (e.g., a distributed cluster, where you have full control over the servers installed), so I think as is it's already reasonable incremental progress. Current limitations: - You can only resume more that one target at the same time if all targets support asynchronous debugging, and support non-stop mode. It should be possible to support mixed all-stop + non-stop backends, but that is left for another time. This means that currently in order to do multi-target with gdbserver you need to issue "maint set target-non-stop on". I would like to make that mode be the default, but we're not there yet. Note that I'm talking about how the target backend works, only. User-visible all-stop mode works just fine. - As explained above, connecting to different remote servers at the same time is likely to produce bad results if they don't support the exact set of RSP features. FreeBSD updates courtesy of John Baldwin. gdb/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> John Baldwin <jhb@FreeBSD.org> * aarch64-linux-nat.c (aarch64_linux_nat_target::thread_architecture): Adjust. * ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call. (task_command_1): Likewise. * aix-thread.c (sync_threadlists, aix_thread_target::resume) (aix_thread_target::wait, aix_thread_target::fetch_registers) (aix_thread_target::store_registers) (aix_thread_target::thread_alive): Adjust. * amd64-fbsd-tdep.c: Include "inferior.h". (amd64fbsd_get_thread_local_address): Pass down target. * amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle thread's gdbarch instead of target_gdbarch. * break-catch-sig.c (signal_catchpoint_print_it): Adjust call to get_last_target_status. * break-catch-syscall.c (print_it_catch_syscall): Likewise. * breakpoint.c (breakpoints_should_be_inserted_now): Consider all inferiors. (update_inserted_breakpoint_locations): Skip if inferiors with no execution. (update_global_location_list): When handling moribund locations, find representative inferior for location's pspace, and use thread count of its process_stratum target. * bsd-kvm.c (bsd_kvm_target_open): Pass target down. * bsd-uthread.c (bsd_uthread_target::wait): Use as_process_stratum_target and adjust thread_change_ptid and add_thread calls. (bsd_uthread_target::update_thread_list): Use as_process_stratum_target and adjust find_thread_ptid, thread_change_ptid and add_thread calls. * btrace.c (maint_btrace_packet_history_cmd): Adjust find_thread_ptid call. * corelow.c (add_to_thread_list): Adjust add_thread call. (core_target_open): Adjust add_thread_silent and thread_count calls. (core_target::pid_to_str): Adjust find_inferior_ptid call. * ctf.c (ctf_target_open): Adjust add_thread_silent call. * event-top.c (async_disconnect): Pop targets from all inferiors. * exec.c (add_target_sections): Push exec target on all inferiors sharing the program space. (remove_target_sections): Remove the exec target from all inferiors sharing the program space. (exec_on_vfork): New. * exec.h (exec_on_vfork): Declare. * fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::update_thread_list): Adjust. (fbsd_nat_target::resume): Adjust. (fbsd_handle_debug_trap): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust. * fbsd-tdep.c (fbsd_corefile_thread): Adjust get_thread_arch_regcache call. * fork-child.c (gdb_startup_inferior): Pass target down to startup_inferior and set_executing. * gdbthread.h (struct process_stratum_target): Forward declare. (add_thread, add_thread_silent, add_thread_with_info) (in_thread_list): Add process_stratum_target parameter. (find_thread_ptid(inferior*, ptid_t)): New overload. (find_thread_ptid, thread_change_ptid): Add process_stratum_target parameter. (all_threads()): Delete overload. (all_threads, all_non_exited_threads): Add process_stratum_target parameter. (all_threads_safe): Use brace initialization. (thread_count): Add process_stratum_target parameter. (set_resumed, set_running, set_stop_requested, set_executing) (threads_are_executing, finish_thread_state): Add process_stratum_target parameter. (switch_to_thread): Use is_current_thread. * i386-fbsd-tdep.c: Include "inferior.h". (i386fbsd_get_thread_local_address): Pass down target. * i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust. * inf-child.c (inf_child_target::maybe_unpush_target): Remove have_inferiors check. * inf-ptrace.c (inf_ptrace_target::create_inferior) (inf_ptrace_target::attach): Adjust. * infcall.c (run_inferior_call): Adjust. * infcmd.c (run_command_1): Pass target to scoped_finish_thread_state. (proceed_thread_callback): Skip inferiors with no execution. (continue_command): Rename 'all_threads' local to avoid hiding 'all_threads' function. Adjust get_last_target_status call. (prepare_one_step): Adjust set_running call. (signal_command): Use user_visible_resume_target. Compare thread pointers instead of inferior_ptid. (info_program_command): Adjust to pass down target. (attach_command): Mark target's 'thread_executing' flag. (stop_current_target_threads_ns): New, factored out from ... (interrupt_target_1): ... this. Switch inferior before making target calls. * inferior-iter.h (struct all_inferiors_iterator, struct all_inferiors_range) (struct all_inferiors_safe_range) (struct all_non_exited_inferiors_range): Filter on process_stratum_target too. Remove explicit. * inferior.c (inferior::inferior): Push dummy target on target stack. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors): Add process_stratum_target parameter, and pass it down. (have_live_inferiors): Adjust. (switch_to_inferior_and_push_target): New. (add_inferior_command, clone_inferior_command): Handle "-no-connection" parameter. Use switch_to_inferior_and_push_target. (_initialize_inferior): Mention "-no-connection" option in the help of "add-inferior" and "clone-inferior" commands. * inferior.h: Include "process-stratum-target.h". (interrupt_target_1): Use bool. (struct inferior) <push_target, unpush_target, target_is_pushed, find_target_beneath, top_target, process_target, target_at, m_stack>: New. (discard_all_inferiors): Delete. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors) (all_inferiors, all_non_exited_inferiors): Add process_stratum_target parameter. * infrun.c: Include "gdb_select.h" and <unordered_map>. (target_last_proc_target): New global. (follow_fork_inferior): Push target on new inferior. Pass target to add_thread_silent. Call exec_on_vfork. Handle target's reference count. (follow_fork): Adjust get_last_target_status call. Also consider target. (follow_exec): Push target on new inferior. (struct execution_control_state) <target>: New field. (user_visible_resume_target): New. (do_target_resume): Call target_async. (resume_1): Set target's threads_executing flag. Consider resume target. (commit_resume_all_targets): New. (proceed): Also consider resume target. Skip threads of inferiors with no execution. Commit resumtion in all targets. (start_remote): Pass current inferior to wait_for_inferior. (infrun_thread_stop_requested): Consider target as well. Pass thread_info pointer to clear_inline_frame_state instead of ptid. (infrun_thread_thread_exit): Consider target as well. (random_pending_event_thread): New inferior parameter. Use it. (do_target_wait): Rename to ... (do_target_wait_1): ... this. Add inferior parameter, and pass it down. (threads_are_resumed_pending_p, do_target_wait): New. (prepare_for_detach): Adjust calls. (wait_for_inferior): New inferior parameter. Handle it. Use do_target_wait_1 instead of do_target_wait. (fetch_inferior_event): Adjust. Switch to representative inferior. Pass target down. (set_last_target_status): Add process_stratum_target parameter. Save target in global. (get_last_target_status): Add process_stratum_target parameter and handle it. (nullify_last_target_wait_ptid): Clear 'target_last_proc_target'. (context_switch): Check inferior_ptid == null_ptid before calling inferior_thread(). (get_inferior_stop_soon): Pass down target. (wait_one): Rename to ... (poll_one_curr_target): ... this. (struct wait_one_event): New. (wait_one): New. (stop_all_threads): Adjust. (handle_no_resumed, handle_inferior_event): Adjust to consider the event's target. (switch_back_to_stepped_thread): Also consider target. (print_stop_event): Update. (normal_stop): Update. Also consider the resume target. * infrun.h (wait_for_inferior): Remove declaration. (user_visible_resume_target): New declaration. (get_last_target_status, set_last_target_status): New process_stratum_target parameter. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter, and use it. (clear_inline_frame_state (thread_info*)): New. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter. (clear_inline_frame_state (thread_info*)): Declare. * linux-fork.c (delete_checkpoint_command): Pass target down to find_thread_ptid. (checkpoint_command): Adjust. * linux-nat.c (linux_nat_target::follow_fork): Switch to thread instead of just tweaking inferior_ptid. (linux_nat_switch_fork): Pass target down to thread_change_ptid. (exit_lwp): Pass target down to find_thread_ptid. (attach_proc_task_lwp_callback): Pass target down to add_thread/set_running/set_executing. (linux_nat_target::attach): Pass target down to thread_change_ptid. (get_detach_signal): Pass target down to find_thread_ptid. Consider last target status's target. (linux_resume_one_lwp_throw, resume_lwp) (linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp) (stop_wait_callback, save_stop_reason, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down. (linux_nat_target::async_wait_fd): New. (linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass target down. * linux-nat.h (linux_nat_target::async_wait_fd): Declare. * linux-tdep.c (get_thread_arch_regcache): Pass target down. * linux-thread-db.c (struct thread_db_info::process_target): New field. (add_thread_db_info): Save target. (get_thread_db_info): New process_stratum_target parameter. Also match target. (delete_thread_db_info): New process_stratum_target parameter. Also match target. (thread_from_lwp): Adjust to pass down target. (thread_db_notice_clone): Pass down target. (check_thread_db_callback): Pass down target. (try_thread_db_load_1): Always push the thread_db target. (try_thread_db_load, record_thread): Pass target down. (thread_db_target::detach): Pass target down. Always unpush the thread_db target. (thread_db_target::wait, thread_db_target::mourn_inferior): Pass target down. Always unpush the thread_db target. (find_new_threads_callback, thread_db_find_new_threads_2) (thread_db_target::update_thread_list): Pass target down. (thread_db_target::pid_to_str): Pass current inferior down. (thread_db_target::get_thread_local_address): Pass target down. (thread_db_target::resume, maintenance_check_libthread_db): Pass target down. * nto-procfs.c (nto_procfs_target::update_thread_list): Adjust. * procfs.c (procfs_target::procfs_init_inferior): Declare. (proc_set_current_signal, do_attach, procfs_target::wait): Adjust. (procfs_init_inferior): Rename to ... (procfs_target::procfs_init_inferior): ... this and adjust. (procfs_target::create_inferior, procfs_notice_thread) (procfs_do_thread_registers): Adjust. * ppc-fbsd-tdep.c: Include "inferior.h". (ppcfbsd_get_thread_local_address): Pass down target. * proc-service.c (ps_xfer_memory): Switch current inferior and program space as well. (get_ps_regcache): Pass target down. * process-stratum-target.c (process_stratum_target::thread_address_space) (process_stratum_target::thread_architecture): Pass target down. * process-stratum-target.h (process_stratum_target::threads_executing): New field. (as_process_stratum_target): New. * ravenscar-thread.c (ravenscar_thread_target::update_inferior_ptid): Pass target down. (ravenscar_thread_target::wait, ravenscar_add_thread): Pass target down. * record-btrace.c (record_btrace_target::info_record): Adjust. (record_btrace_target::record_method) (record_btrace_target::record_is_replaying) (record_btrace_target::fetch_registers) (get_thread_current_frame_id, record_btrace_target::resume) (record_btrace_target::wait, record_btrace_target::stop): Pass target down. * record-full.c (record_full_wait_1): Switch to event thread. Pass target down. * regcache.c (regcache::regcache) (get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add process_stratum_target parameter and handle it. (current_thread_target): New global. (get_thread_regcache): Add process_stratum_target parameter and handle it. Switch inferior before calling target method. (get_thread_regcache): Pass target down. (get_thread_regcache_for_ptid): Pass target down. (registers_changed_ptid): Add process_stratum_target parameter and handle it. (registers_changed_thread, registers_changed): Pass target down. (test_get_thread_arch_aspace_regcache): New. (current_regcache_test): Define a couple local test_target_ops instances and use them for testing. (readwrite_regcache): Pass process_stratum_target parameter. (cooked_read_test, cooked_write_test): Pass mock_target down. * regcache.h (get_thread_regcache, get_thread_arch_regcache) (get_thread_arch_aspace_regcache): Add process_stratum_target parameter. (regcache::target): New method. (regcache::regcache, regcache::get_thread_arch_aspace_regcache) (regcache::registers_changed_ptid): Add process_stratum_target parameter. (regcache::m_target): New field. (registers_changed_ptid): Add process_stratum_target parameter. * remote.c (remote_state::supports_vCont_probed): New field. (remote_target::async_wait_fd): New method. (remote_unpush_and_throw): Add remote_target parameter. (get_current_remote_target): Adjust. (remote_target::remote_add_inferior): Push target. (remote_target::remote_add_thread) (remote_target::remote_notice_new_inferior) (get_remote_thread_info): Pass target down. (remote_target::update_thread_list): Skip threads of inferiors bound to other targets. (remote_target::close): Don't discard inferiors. (remote_target::add_current_inferior_and_thread) (remote_target::process_initial_stop_replies) (remote_target::start_remote) (remote_target::remote_serial_quit_handler): Pass down target. (remote_target::remote_unpush_target): New remote_target parameter. Unpush the target from all inferiors. (remote_target::remote_unpush_and_throw): New remote_target parameter. Pass it down. (remote_target::open_1): Check whether the current inferior has execution instead of checking whether any inferior is live. Pass target down. (remote_target::remote_detach_1): Pass down target. Use remote_unpush_target. (extended_remote_target::attach): Pass down target. (remote_target::remote_vcont_probe): Set supports_vCont_probed. (remote_target::append_resumption): Pass down target. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc, remote_target::resume) (remote_target::commit_resume): Pass down target. (remote_target::remote_stop_ns): Check supports_vCont_probed. (remote_target::interrupt_query) (remote_target::remove_new_fork_children) (remote_target::check_pending_events_prevent_wildcard_vcont) (remote_target::remote_parse_stop_reply) (remote_target::process_stop_reply): Pass down target. (first_remote_resumed_thread): New remote_target parameter. Pass it down. (remote_target::wait_as): Pass down target. (unpush_and_perror): New remote_target parameter. Pass it down. (remote_target::readchar, remote_target::remote_serial_write) (remote_target::getpkt_or_notif_sane_1) (remote_target::kill_new_fork_children, remote_target::kill): Pass down target. (remote_target::mourn_inferior): Pass down target. Use remote_unpush_target. (remote_target::core_of_thread) (remote_target::remote_btrace_maybe_reopen): Pass down target. (remote_target::pid_to_exec_file) (remote_target::thread_handle_to_thread_info): Pass down target. (remote_target::async_wait_fd): New. * riscv-fbsd-tdep.c: Include "inferior.h". (riscv_fbsd_get_thread_local_address): Pass down target. * sol2-tdep.c (sol2_core_pid_to_str): Pass down target. * sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs) (ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback): Adjust. * solib-spu.c (spu_skip_standalone_loader): Pass down target. * solib-svr4.c (enable_break): Pass down target. * spu-multiarch.c (parse_spufs_run): Pass down target. * spu-tdep.c (spu2ppu_sniffer): Pass down target. * target-delegates.c: Regenerate. * target.c (g_target_stack): Delete. (current_top_target): Return the current inferior's top target. (target_has_execution_1): Refer to the passed-in inferior's top target. (target_supports_terminal_ours): Check whether the initial inferior was already created. (decref_target): New. (target_stack::push): Incref/decref the target. (push_target, push_target, unpush_target): Adjust. (target_stack::unpush): Defref target. (target_is_pushed): Return bool. Adjust to refer to the current inferior's target stack. (dispose_inferior): Delete, and inline parts ... (target_preopen): ... here. Only dispose of the current inferior. (target_detach): Hold strong target reference while detaching. Pass target down. (target_thread_name): Add assertion. (target_resume): Pass down target. (target_ops::beneath, find_target_at): Adjust to refer to the current inferior's target stack. (get_dummy_target): New. (target_pass_ctrlc): Pass the Ctrl-C to the first inferior that has a thread running. (initialize_targets): Rename to ... (_initialize_target): ... this. * target.h: Include "gdbsupport/refcounted-object.h". (struct target_ops): Inherit refcounted_object. (target_ops::shortname, target_ops::longname): Make const. (target_ops::async_wait_fd): New method. (decref_target): Declare. (struct target_ops_ref_policy): New. (target_ops_ref): New typedef. (get_dummy_target): Declare function. (target_is_pushed): Return bool. * thread-iter.c (all_matching_threads_iterator::m_inf_matches) (all_matching_threads_iterator::all_matching_threads_iterator): Handle filter target. * thread-iter.h (struct all_matching_threads_iterator, struct all_matching_threads_range, class all_non_exited_threads_range): Filter by target too. Remove explicit. * thread.c (threads_executing): Delete. (inferior_thread): Pass down current inferior. (clear_thread_inferior_resources): Pass down thread pointer instead of ptid_t. (add_thread_silent, add_thread_with_info, add_thread): Add process_stratum_target parameter. Use it for thread and inferior searches. (is_current_thread): New. (thread_info::deletable): Use it. (find_thread_ptid, thread_count, in_thread_list) (thread_change_ptid, set_resumed, set_running): New process_stratum_target parameter. Pass it down. (set_executing): New process_stratum_target parameter. Pass it down. Adjust reference to 'threads_executing'. (threads_are_executing): New process_stratum_target parameter. Adjust reference to 'threads_executing'. (set_stop_requested, finish_thread_state): New process_stratum_target parameter. Pass it down. (switch_to_thread): Also match inferior. (switch_to_thread): New process_stratum_target parameter. Pass it down. (update_threads_executing): Reimplement. * top.c (quit_force): Pop targets from all inferior. (gdb_init): Don't call initialize_targets. * windows-nat.c (windows_nat_target) <get_windows_debug_event>: Declare. (windows_add_thread, windows_delete_thread): Adjust. (get_windows_debug_event): Rename to ... (windows_nat_target::get_windows_debug_event): ... this. Adjust. * tracefile-tfile.c (tfile_target_open): Pass down target. * gdbsupport/common-gdbthread.h (struct process_stratum_target): Forward declare. (switch_to_thread): Add process_stratum_target parameter. * mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target parameter. Use it. (mi_on_resume): Pass target down. * nat/fork-inferior.c (startup_inferior): Add process_stratum_target parameter. Pass it down. * nat/fork-inferior.h (startup_inferior): Add process_stratum_target parameter. * python/py-threadevent.c (py_get_event_thread): Pass target down. gdb/gdbserver/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> * fork-child.c (post_fork_inferior): Pass target down to startup_inferior. * inferiors.c (switch_to_thread): Add process_stratum_target parameter. * lynx-low.c (lynx_target_ops): Now a process_stratum_target. * nto-low.c (nto_target_ops): Now a process_stratum_target. * linux-low.c (linux_target_ops): Now a process_stratum_target. * remote-utils.c (prepare_resume_reply): Pass the target to switch_to_thread. * target.c (the_target): Now a process_stratum_target. (done_accessing_memory): Pass the target to switch_to_thread. (set_target_ops): Ajust to use process_stratum_target. * target.h (struct target_ops): Rename to ... (struct process_stratum_target): ... this. (the_target, set_target_ops): Adjust. (prepare_to_access_memory): Adjust comment. * win32-low.c (child_xfer_memory): Adjust to use process_stratum_target. (win32_target_ops): Now a process_stratum_target.
2020-01-10 21:06:08 +01:00
/* Search function to lookup an inferior of TARG whose pid is equal to
'ptid.pid'. */
extern struct inferior *find_inferior_ptid (process_stratum_target *targ,
ptid_t ptid);
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* Search function to lookup an inferior by GDB 'num'. */
extern struct inferior *find_inferior_id (int num);
Reduce Hg packet (select remote general thread) bouncing A patch I wrote made GDB pull the thread list sooner when debugging with target remote, and I noticed an intended consequence. GDB started bouncing around the currently selected remote/general thread more frequently. E.g.: Sending packet: $qTMinFTPILen#3b...Packet received: 5 +Sending packet: $Hgp726d.726d#53...Packet received: OK Sending packet: $m400680,40#2f...Packet received: 85c0741455bff00d60004889e5ffd05de97bffffff0f1f00e973ffffff0f1f00554889e5c745fc00000000c745fc01000000e900000000c745fc02000000b800 +Sending packet: $Hgp726d.7278#28...Packet received: OK Sending packet: $m4006b2,1#28...Packet received: e9 Fast tracepoint 2 at 0x4006b2: file gdb/testsuite/gdb.trace/range-stepping.c, line 53. Sending packet: $qTStatus#49...Packet received: T0;tnotrun:0;tframes:0;tcreated:0;tfree:500000;tsize:500000;circular:0;disconn:0;starttime:0;stoptime:0;username:;notes:: This ended up breaking "tstart" when one has fast tracepoints set, because gdbserver isn't expecting an Hg packet in response to qRelocInsn: (gdb) ftrace *set_point Fast tracepoint 3 at 0x4006b2: file gdb/testsuite/gdb.trace/range-stepping.c, line 53. (gdb) PASS: gdb.trace/range-stepping.exp: ftrace: ftrace *set_point tstart gdbserver: Malformed response to qRelocInsn, ignoring: Hgp2783.2783 Target does not support this command. (gdb) FAIL: gdb.trace/range-stepping.exp: ftrace: tstart remote_trace_start should probably start by making sure the remote current thread matches inferior_ptid (calling set_general_thread), but still, reducing unnecessary bouncing is a good idea. It happens because the memory/symbol/breakpoint routines use switch_to_program_space_and_thread to do something in the right context and then revert back to the previously current thread. The fix is to simply make any_thread_of_process, find_inferior_for_program_space, etc. give preference to the current thread/inferior it if matches. gdb/ 2014-10-02 Pedro Alves <palves@redhat.com> * gdbthread.h (any_thread_of_process, any_live_thread_of_process): Adjust comments. * inferior.c (find_inferior_for_program_space): Give preference to the current inferior. * inferior.h (find_inferior_for_program_space): Update comment. * progspace.c (switch_to_program_space_and_thread): Prefer the current inferior if it's bound to the program space requested. If the inferior found doesn't have a PID yet, don't bother looking up a thread. * progspace.h (switch_to_program_space_and_thread): Adjust comment. * thread.c (any_thread_of_process, any_live_thread_of_process): Give preference to the current thread.
2014-10-02 10:55:38 +02:00
/* Find an inferior bound to PSPACE, giving preference to the current
inferior. */
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
extern struct inferior *
find_inferior_for_program_space (struct program_space *pspace);
/* Returns true if the inferior list is not empty. */
extern int have_inferiors (void);
Multi-target support This commit adds multi-target support to GDB. What this means is that with this commit, GDB can now be connected to different targets at the same time. E.g., you can debug a live native process and a core dump at the same time, connect to multiple gdbservers, etc. Actually, the word "target" is overloaded in gdb. We already have a target stack, with pushes several target_ops instances on top of one another. We also have "info target" already, which means something completely different to what this patch does. So from here on, I'll be using the "target connections" term, to mean an open process_stratum target, pushed on a target stack. This patch makes gdb have multiple target stacks, and multiple process_stratum targets open simultaneously. The user-visible changes / commands will also use this terminology, but of course it's all open to debate. User-interface-wise, not that much changes. The main difference is that each inferior may have its own target connection. A target connection (e.g., a target extended-remote connection) may support debugging multiple processes, just as before. Say you're debugging against gdbserver in extended-remote mode, and you do "add-inferior" to prepare to spawn a new process, like: (gdb) target extended-remote :9999 ... (gdb) start ... (gdb) add-inferior Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) file a.out ... (gdb) start ... At this point, you have two inferiors connected to the same gdbserver. With this commit, GDB will maintain a target stack per inferior, instead of a global target stack. To preserve the behavior above, by default, "add-inferior" makes the new inferior inherit a copy of the target stack of the current inferior. Same across a fork - the child inherits a copy of the target stack of the parent. While the target stacks are copied, the targets themselves are not. Instead, target_ops is made a refcounted_object, which means that target_ops instances are refcounted, which each inferior counting for a reference. What if you want to create an inferior and connect it to some _other_ target? For that, this commit introduces a new "add-inferior -no-connection" option that makes the new inferior not share the current inferior's target. So you could do: (gdb) target extended-remote :9999 Remote debugging using :9999 ... (gdb) add-inferior -no-connection [New inferior 2] Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 <null> (gdb) tar extended-remote :10000 Remote debugging using :10000 ... (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 process 18450 target:/home/pedro/tmp/main (gdb) A following patch will extended "info inferiors" to include a column indicating which connection an inferior is bound to, along with a couple other UI tweaks. Other than that, debugging is the same as before. Users interact with inferiors and threads as before. The only difference is that inferiors may be bound to processes running in different machines. That's pretty much all there is to it in terms of noticeable UI changes. On to implementation. Since we can be connected to different systems at the same time, a ptid_t is no longer a unique identifier. Instead a thread can be identified by a pair of ptid_t and 'process_stratum_target *', the later being the instance of the process_stratum target that owns the process/thread. Note that process_stratum_target inherits from target_ops, and all process_stratum targets inherit from process_stratum_target. In earlier patches, many places in gdb were converted to refer to threads by thread_info pointer instead of ptid_t, but there are still places in gdb where we start with a pid/tid and need to find the corresponding inferior or thread_info objects. So you'll see in the patch many places adding a process_stratum_target parameter to functions that used to take only a ptid_t. Since each inferior has its own target stack now, we can always find the process_stratum target for an inferior. That is done via a inf->process_target() convenience method. Since each inferior has its own target stack, we need to handle the "beneath" calls when servicing target calls. The solution I settled with is just to make sure to switch the current inferior to the inferior you want before making a target call. Not relying on global context is just not feasible in current GDB. Fortunately, there aren't that many places that need to do that, because generally most code that calls target methods already has the current context pointing to the right inferior/thread. Note, to emphasize -- there's no method to "switch to this target stack". Instead, you switch the current inferior, and that implicitly switches the target stack. In some spots, we need to iterate over all inferiors so that we reach all target stacks. Native targets are still singletons. There's always only a single instance of such targets. Remote targets however, we'll have one instance per remote connection. The exec target is still a singleton. There's only one instance. I did not see the point of instanciating more than one exec_target object. After vfork, we need to make sure to push the exec target on the new inferior. See exec_on_vfork. For type safety, functions that need a {target, ptid} pair to identify a thread, take a process_stratum_target pointer for target parameter instead of target_ops *. Some shared code in gdb/nat/ also need to gain a target pointer parameter. This poses an issue, since gdbserver doesn't have process_stratum_target, only target_ops. To fix this, this commit renames gdbserver's target_ops to process_stratum_target. I think this makes sense. There's no concept of target stack in gdbserver, and gdbserver's target_ops really implements a process_stratum-like target. The thread and inferior iterator functions also gain process_stratum_target parameters. These are used to be able to iterate over threads and inferiors of a given target. Following usual conventions, if the target pointer is null, then we iterate over threads and inferiors of all targets. I tried converting "add-inferior" to the gdb::option framework, as a preparatory patch, but that stumbled on the fact that gdb::option does not support file options yet, for "add-inferior -exec". I have a WIP patchset that adds that, but it's not a trivial patch, mainly due to need to integrate readline's filename completion, so I deferred that to some other time. In infrun.c/infcmd.c, the main change is that we need to poll events out of all targets. See do_target_wait. Right after collecting an event, we switch the current inferior to an inferior bound to the target that reported the event, so that target methods can be used while handling the event. This makes most of the code transparent to multi-targets. See fetch_inferior_event. infrun.c:stop_all_threads is interesting -- in this function we need to stop all threads of all targets. What the function does is send an asynchronous stop request to all threads, and then synchronously waits for events, with target_wait, rinse repeat, until all it finds are stopped threads. Now that we have multiple targets, it's not efficient to synchronously block in target_wait waiting for events out of one target. Instead, we implement a mini event loop, with interruptible_select, select'ing on one file descriptor per target. For this to work, we need to be able to ask the target for a waitable file descriptor. Such file descriptors already exist, they are the descriptors registered in the main event loop with add_file_handler, inside the target_async implementations. This commit adds a new target_async_wait_fd target method that just returns the file descriptor in question. See wait_one / stop_all_threads in infrun.c. The 'threads_executing' global is made a per-target variable. Since it is only relevant to process_stratum_target targets, this is where it is put, instead of in target_ops. You'll notice that remote.c includes some FIXME notes. These refer to the fact that the global arrays that hold data for the remote packets supported are still globals. For example, if we connect to two different servers/stubs, then each might support different remote protocol features. They might even be different architectures, like e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a host/controller scenario as a single program. That isn't going to work correctly today, because of said globals. I'm leaving fixing that for another pass, since it does not appear to be trivial, and I'd rather land the base work first. It's already useful to be able to debug multiple instances of the same server (e.g., a distributed cluster, where you have full control over the servers installed), so I think as is it's already reasonable incremental progress. Current limitations: - You can only resume more that one target at the same time if all targets support asynchronous debugging, and support non-stop mode. It should be possible to support mixed all-stop + non-stop backends, but that is left for another time. This means that currently in order to do multi-target with gdbserver you need to issue "maint set target-non-stop on". I would like to make that mode be the default, but we're not there yet. Note that I'm talking about how the target backend works, only. User-visible all-stop mode works just fine. - As explained above, connecting to different remote servers at the same time is likely to produce bad results if they don't support the exact set of RSP features. FreeBSD updates courtesy of John Baldwin. gdb/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> John Baldwin <jhb@FreeBSD.org> * aarch64-linux-nat.c (aarch64_linux_nat_target::thread_architecture): Adjust. * ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call. (task_command_1): Likewise. * aix-thread.c (sync_threadlists, aix_thread_target::resume) (aix_thread_target::wait, aix_thread_target::fetch_registers) (aix_thread_target::store_registers) (aix_thread_target::thread_alive): Adjust. * amd64-fbsd-tdep.c: Include "inferior.h". (amd64fbsd_get_thread_local_address): Pass down target. * amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle thread's gdbarch instead of target_gdbarch. * break-catch-sig.c (signal_catchpoint_print_it): Adjust call to get_last_target_status. * break-catch-syscall.c (print_it_catch_syscall): Likewise. * breakpoint.c (breakpoints_should_be_inserted_now): Consider all inferiors. (update_inserted_breakpoint_locations): Skip if inferiors with no execution. (update_global_location_list): When handling moribund locations, find representative inferior for location's pspace, and use thread count of its process_stratum target. * bsd-kvm.c (bsd_kvm_target_open): Pass target down. * bsd-uthread.c (bsd_uthread_target::wait): Use as_process_stratum_target and adjust thread_change_ptid and add_thread calls. (bsd_uthread_target::update_thread_list): Use as_process_stratum_target and adjust find_thread_ptid, thread_change_ptid and add_thread calls. * btrace.c (maint_btrace_packet_history_cmd): Adjust find_thread_ptid call. * corelow.c (add_to_thread_list): Adjust add_thread call. (core_target_open): Adjust add_thread_silent and thread_count calls. (core_target::pid_to_str): Adjust find_inferior_ptid call. * ctf.c (ctf_target_open): Adjust add_thread_silent call. * event-top.c (async_disconnect): Pop targets from all inferiors. * exec.c (add_target_sections): Push exec target on all inferiors sharing the program space. (remove_target_sections): Remove the exec target from all inferiors sharing the program space. (exec_on_vfork): New. * exec.h (exec_on_vfork): Declare. * fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::update_thread_list): Adjust. (fbsd_nat_target::resume): Adjust. (fbsd_handle_debug_trap): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust. * fbsd-tdep.c (fbsd_corefile_thread): Adjust get_thread_arch_regcache call. * fork-child.c (gdb_startup_inferior): Pass target down to startup_inferior and set_executing. * gdbthread.h (struct process_stratum_target): Forward declare. (add_thread, add_thread_silent, add_thread_with_info) (in_thread_list): Add process_stratum_target parameter. (find_thread_ptid(inferior*, ptid_t)): New overload. (find_thread_ptid, thread_change_ptid): Add process_stratum_target parameter. (all_threads()): Delete overload. (all_threads, all_non_exited_threads): Add process_stratum_target parameter. (all_threads_safe): Use brace initialization. (thread_count): Add process_stratum_target parameter. (set_resumed, set_running, set_stop_requested, set_executing) (threads_are_executing, finish_thread_state): Add process_stratum_target parameter. (switch_to_thread): Use is_current_thread. * i386-fbsd-tdep.c: Include "inferior.h". (i386fbsd_get_thread_local_address): Pass down target. * i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust. * inf-child.c (inf_child_target::maybe_unpush_target): Remove have_inferiors check. * inf-ptrace.c (inf_ptrace_target::create_inferior) (inf_ptrace_target::attach): Adjust. * infcall.c (run_inferior_call): Adjust. * infcmd.c (run_command_1): Pass target to scoped_finish_thread_state. (proceed_thread_callback): Skip inferiors with no execution. (continue_command): Rename 'all_threads' local to avoid hiding 'all_threads' function. Adjust get_last_target_status call. (prepare_one_step): Adjust set_running call. (signal_command): Use user_visible_resume_target. Compare thread pointers instead of inferior_ptid. (info_program_command): Adjust to pass down target. (attach_command): Mark target's 'thread_executing' flag. (stop_current_target_threads_ns): New, factored out from ... (interrupt_target_1): ... this. Switch inferior before making target calls. * inferior-iter.h (struct all_inferiors_iterator, struct all_inferiors_range) (struct all_inferiors_safe_range) (struct all_non_exited_inferiors_range): Filter on process_stratum_target too. Remove explicit. * inferior.c (inferior::inferior): Push dummy target on target stack. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors): Add process_stratum_target parameter, and pass it down. (have_live_inferiors): Adjust. (switch_to_inferior_and_push_target): New. (add_inferior_command, clone_inferior_command): Handle "-no-connection" parameter. Use switch_to_inferior_and_push_target. (_initialize_inferior): Mention "-no-connection" option in the help of "add-inferior" and "clone-inferior" commands. * inferior.h: Include "process-stratum-target.h". (interrupt_target_1): Use bool. (struct inferior) <push_target, unpush_target, target_is_pushed, find_target_beneath, top_target, process_target, target_at, m_stack>: New. (discard_all_inferiors): Delete. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors) (all_inferiors, all_non_exited_inferiors): Add process_stratum_target parameter. * infrun.c: Include "gdb_select.h" and <unordered_map>. (target_last_proc_target): New global. (follow_fork_inferior): Push target on new inferior. Pass target to add_thread_silent. Call exec_on_vfork. Handle target's reference count. (follow_fork): Adjust get_last_target_status call. Also consider target. (follow_exec): Push target on new inferior. (struct execution_control_state) <target>: New field. (user_visible_resume_target): New. (do_target_resume): Call target_async. (resume_1): Set target's threads_executing flag. Consider resume target. (commit_resume_all_targets): New. (proceed): Also consider resume target. Skip threads of inferiors with no execution. Commit resumtion in all targets. (start_remote): Pass current inferior to wait_for_inferior. (infrun_thread_stop_requested): Consider target as well. Pass thread_info pointer to clear_inline_frame_state instead of ptid. (infrun_thread_thread_exit): Consider target as well. (random_pending_event_thread): New inferior parameter. Use it. (do_target_wait): Rename to ... (do_target_wait_1): ... this. Add inferior parameter, and pass it down. (threads_are_resumed_pending_p, do_target_wait): New. (prepare_for_detach): Adjust calls. (wait_for_inferior): New inferior parameter. Handle it. Use do_target_wait_1 instead of do_target_wait. (fetch_inferior_event): Adjust. Switch to representative inferior. Pass target down. (set_last_target_status): Add process_stratum_target parameter. Save target in global. (get_last_target_status): Add process_stratum_target parameter and handle it. (nullify_last_target_wait_ptid): Clear 'target_last_proc_target'. (context_switch): Check inferior_ptid == null_ptid before calling inferior_thread(). (get_inferior_stop_soon): Pass down target. (wait_one): Rename to ... (poll_one_curr_target): ... this. (struct wait_one_event): New. (wait_one): New. (stop_all_threads): Adjust. (handle_no_resumed, handle_inferior_event): Adjust to consider the event's target. (switch_back_to_stepped_thread): Also consider target. (print_stop_event): Update. (normal_stop): Update. Also consider the resume target. * infrun.h (wait_for_inferior): Remove declaration. (user_visible_resume_target): New declaration. (get_last_target_status, set_last_target_status): New process_stratum_target parameter. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter, and use it. (clear_inline_frame_state (thread_info*)): New. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter. (clear_inline_frame_state (thread_info*)): Declare. * linux-fork.c (delete_checkpoint_command): Pass target down to find_thread_ptid. (checkpoint_command): Adjust. * linux-nat.c (linux_nat_target::follow_fork): Switch to thread instead of just tweaking inferior_ptid. (linux_nat_switch_fork): Pass target down to thread_change_ptid. (exit_lwp): Pass target down to find_thread_ptid. (attach_proc_task_lwp_callback): Pass target down to add_thread/set_running/set_executing. (linux_nat_target::attach): Pass target down to thread_change_ptid. (get_detach_signal): Pass target down to find_thread_ptid. Consider last target status's target. (linux_resume_one_lwp_throw, resume_lwp) (linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp) (stop_wait_callback, save_stop_reason, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down. (linux_nat_target::async_wait_fd): New. (linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass target down. * linux-nat.h (linux_nat_target::async_wait_fd): Declare. * linux-tdep.c (get_thread_arch_regcache): Pass target down. * linux-thread-db.c (struct thread_db_info::process_target): New field. (add_thread_db_info): Save target. (get_thread_db_info): New process_stratum_target parameter. Also match target. (delete_thread_db_info): New process_stratum_target parameter. Also match target. (thread_from_lwp): Adjust to pass down target. (thread_db_notice_clone): Pass down target. (check_thread_db_callback): Pass down target. (try_thread_db_load_1): Always push the thread_db target. (try_thread_db_load, record_thread): Pass target down. (thread_db_target::detach): Pass target down. Always unpush the thread_db target. (thread_db_target::wait, thread_db_target::mourn_inferior): Pass target down. Always unpush the thread_db target. (find_new_threads_callback, thread_db_find_new_threads_2) (thread_db_target::update_thread_list): Pass target down. (thread_db_target::pid_to_str): Pass current inferior down. (thread_db_target::get_thread_local_address): Pass target down. (thread_db_target::resume, maintenance_check_libthread_db): Pass target down. * nto-procfs.c (nto_procfs_target::update_thread_list): Adjust. * procfs.c (procfs_target::procfs_init_inferior): Declare. (proc_set_current_signal, do_attach, procfs_target::wait): Adjust. (procfs_init_inferior): Rename to ... (procfs_target::procfs_init_inferior): ... this and adjust. (procfs_target::create_inferior, procfs_notice_thread) (procfs_do_thread_registers): Adjust. * ppc-fbsd-tdep.c: Include "inferior.h". (ppcfbsd_get_thread_local_address): Pass down target. * proc-service.c (ps_xfer_memory): Switch current inferior and program space as well. (get_ps_regcache): Pass target down. * process-stratum-target.c (process_stratum_target::thread_address_space) (process_stratum_target::thread_architecture): Pass target down. * process-stratum-target.h (process_stratum_target::threads_executing): New field. (as_process_stratum_target): New. * ravenscar-thread.c (ravenscar_thread_target::update_inferior_ptid): Pass target down. (ravenscar_thread_target::wait, ravenscar_add_thread): Pass target down. * record-btrace.c (record_btrace_target::info_record): Adjust. (record_btrace_target::record_method) (record_btrace_target::record_is_replaying) (record_btrace_target::fetch_registers) (get_thread_current_frame_id, record_btrace_target::resume) (record_btrace_target::wait, record_btrace_target::stop): Pass target down. * record-full.c (record_full_wait_1): Switch to event thread. Pass target down. * regcache.c (regcache::regcache) (get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add process_stratum_target parameter and handle it. (current_thread_target): New global. (get_thread_regcache): Add process_stratum_target parameter and handle it. Switch inferior before calling target method. (get_thread_regcache): Pass target down. (get_thread_regcache_for_ptid): Pass target down. (registers_changed_ptid): Add process_stratum_target parameter and handle it. (registers_changed_thread, registers_changed): Pass target down. (test_get_thread_arch_aspace_regcache): New. (current_regcache_test): Define a couple local test_target_ops instances and use them for testing. (readwrite_regcache): Pass process_stratum_target parameter. (cooked_read_test, cooked_write_test): Pass mock_target down. * regcache.h (get_thread_regcache, get_thread_arch_regcache) (get_thread_arch_aspace_regcache): Add process_stratum_target parameter. (regcache::target): New method. (regcache::regcache, regcache::get_thread_arch_aspace_regcache) (regcache::registers_changed_ptid): Add process_stratum_target parameter. (regcache::m_target): New field. (registers_changed_ptid): Add process_stratum_target parameter. * remote.c (remote_state::supports_vCont_probed): New field. (remote_target::async_wait_fd): New method. (remote_unpush_and_throw): Add remote_target parameter. (get_current_remote_target): Adjust. (remote_target::remote_add_inferior): Push target. (remote_target::remote_add_thread) (remote_target::remote_notice_new_inferior) (get_remote_thread_info): Pass target down. (remote_target::update_thread_list): Skip threads of inferiors bound to other targets. (remote_target::close): Don't discard inferiors. (remote_target::add_current_inferior_and_thread) (remote_target::process_initial_stop_replies) (remote_target::start_remote) (remote_target::remote_serial_quit_handler): Pass down target. (remote_target::remote_unpush_target): New remote_target parameter. Unpush the target from all inferiors. (remote_target::remote_unpush_and_throw): New remote_target parameter. Pass it down. (remote_target::open_1): Check whether the current inferior has execution instead of checking whether any inferior is live. Pass target down. (remote_target::remote_detach_1): Pass down target. Use remote_unpush_target. (extended_remote_target::attach): Pass down target. (remote_target::remote_vcont_probe): Set supports_vCont_probed. (remote_target::append_resumption): Pass down target. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc, remote_target::resume) (remote_target::commit_resume): Pass down target. (remote_target::remote_stop_ns): Check supports_vCont_probed. (remote_target::interrupt_query) (remote_target::remove_new_fork_children) (remote_target::check_pending_events_prevent_wildcard_vcont) (remote_target::remote_parse_stop_reply) (remote_target::process_stop_reply): Pass down target. (first_remote_resumed_thread): New remote_target parameter. Pass it down. (remote_target::wait_as): Pass down target. (unpush_and_perror): New remote_target parameter. Pass it down. (remote_target::readchar, remote_target::remote_serial_write) (remote_target::getpkt_or_notif_sane_1) (remote_target::kill_new_fork_children, remote_target::kill): Pass down target. (remote_target::mourn_inferior): Pass down target. Use remote_unpush_target. (remote_target::core_of_thread) (remote_target::remote_btrace_maybe_reopen): Pass down target. (remote_target::pid_to_exec_file) (remote_target::thread_handle_to_thread_info): Pass down target. (remote_target::async_wait_fd): New. * riscv-fbsd-tdep.c: Include "inferior.h". (riscv_fbsd_get_thread_local_address): Pass down target. * sol2-tdep.c (sol2_core_pid_to_str): Pass down target. * sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs) (ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback): Adjust. * solib-spu.c (spu_skip_standalone_loader): Pass down target. * solib-svr4.c (enable_break): Pass down target. * spu-multiarch.c (parse_spufs_run): Pass down target. * spu-tdep.c (spu2ppu_sniffer): Pass down target. * target-delegates.c: Regenerate. * target.c (g_target_stack): Delete. (current_top_target): Return the current inferior's top target. (target_has_execution_1): Refer to the passed-in inferior's top target. (target_supports_terminal_ours): Check whether the initial inferior was already created. (decref_target): New. (target_stack::push): Incref/decref the target. (push_target, push_target, unpush_target): Adjust. (target_stack::unpush): Defref target. (target_is_pushed): Return bool. Adjust to refer to the current inferior's target stack. (dispose_inferior): Delete, and inline parts ... (target_preopen): ... here. Only dispose of the current inferior. (target_detach): Hold strong target reference while detaching. Pass target down. (target_thread_name): Add assertion. (target_resume): Pass down target. (target_ops::beneath, find_target_at): Adjust to refer to the current inferior's target stack. (get_dummy_target): New. (target_pass_ctrlc): Pass the Ctrl-C to the first inferior that has a thread running. (initialize_targets): Rename to ... (_initialize_target): ... this. * target.h: Include "gdbsupport/refcounted-object.h". (struct target_ops): Inherit refcounted_object. (target_ops::shortname, target_ops::longname): Make const. (target_ops::async_wait_fd): New method. (decref_target): Declare. (struct target_ops_ref_policy): New. (target_ops_ref): New typedef. (get_dummy_target): Declare function. (target_is_pushed): Return bool. * thread-iter.c (all_matching_threads_iterator::m_inf_matches) (all_matching_threads_iterator::all_matching_threads_iterator): Handle filter target. * thread-iter.h (struct all_matching_threads_iterator, struct all_matching_threads_range, class all_non_exited_threads_range): Filter by target too. Remove explicit. * thread.c (threads_executing): Delete. (inferior_thread): Pass down current inferior. (clear_thread_inferior_resources): Pass down thread pointer instead of ptid_t. (add_thread_silent, add_thread_with_info, add_thread): Add process_stratum_target parameter. Use it for thread and inferior searches. (is_current_thread): New. (thread_info::deletable): Use it. (find_thread_ptid, thread_count, in_thread_list) (thread_change_ptid, set_resumed, set_running): New process_stratum_target parameter. Pass it down. (set_executing): New process_stratum_target parameter. Pass it down. Adjust reference to 'threads_executing'. (threads_are_executing): New process_stratum_target parameter. Adjust reference to 'threads_executing'. (set_stop_requested, finish_thread_state): New process_stratum_target parameter. Pass it down. (switch_to_thread): Also match inferior. (switch_to_thread): New process_stratum_target parameter. Pass it down. (update_threads_executing): Reimplement. * top.c (quit_force): Pop targets from all inferior. (gdb_init): Don't call initialize_targets. * windows-nat.c (windows_nat_target) <get_windows_debug_event>: Declare. (windows_add_thread, windows_delete_thread): Adjust. (get_windows_debug_event): Rename to ... (windows_nat_target::get_windows_debug_event): ... this. Adjust. * tracefile-tfile.c (tfile_target_open): Pass down target. * gdbsupport/common-gdbthread.h (struct process_stratum_target): Forward declare. (switch_to_thread): Add process_stratum_target parameter. * mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target parameter. Use it. (mi_on_resume): Pass target down. * nat/fork-inferior.c (startup_inferior): Add process_stratum_target parameter. Pass it down. * nat/fork-inferior.h (startup_inferior): Add process_stratum_target parameter. * python/py-threadevent.c (py_get_event_thread): Pass target down. gdb/gdbserver/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> * fork-child.c (post_fork_inferior): Pass target down to startup_inferior. * inferiors.c (switch_to_thread): Add process_stratum_target parameter. * lynx-low.c (lynx_target_ops): Now a process_stratum_target. * nto-low.c (nto_target_ops): Now a process_stratum_target. * linux-low.c (linux_target_ops): Now a process_stratum_target. * remote-utils.c (prepare_resume_reply): Pass the target to switch_to_thread. * target.c (the_target): Now a process_stratum_target. (done_accessing_memory): Pass the target to switch_to_thread. (set_target_ops): Ajust to use process_stratum_target. * target.h (struct target_ops): Rename to ... (struct process_stratum_target): ... this. (the_target, set_target_ops): Adjust. (prepare_to_access_memory): Adjust comment. * win32-low.c (child_xfer_memory): Adjust to use process_stratum_target. (win32_target_ops): Now a process_stratum_target.
2020-01-10 21:06:08 +01:00
/* Returns the number of live inferiors running on PROC_TARGET (real
live processes with execution). */
extern int number_of_live_inferiors (process_stratum_target *proc_target);
Target remote mode fork and exec event support This patch implements support for fork and exec events with target remote mode Linux targets. For such targets with Linux kernels 2.5.46 and later, this enables follow-fork-mode, detach-on-fork and fork and exec catchpoints. The changes required to implement this included: * Don't exit from gdbserver if there are still active inferiors. * Allow changing the active process in remote mode. * Enable fork and exec events in remote mode. * Print "Ending remote debugging" only when disconnecting. * Combine remote_kill and extended_remote_kill into a single function that can handle the multiple inferior case for target remote. Also, the same thing for remote_mourn and extended_remote_mourn. * Enable process-style ptids in target remote. * Remove restriction on multiprocess mode in target remote. gdb/gdbserver/ChangeLog: * server.c (process_serial_event): Don't exit from gdbserver in remote mode if there are still active inferiors. gdb/ChangeLog: * inferior.c (number_of_live_inferiors): New function. (have_live_inferiors): Use number_of_live_inferiors in place of duplicate code. * inferior.h (number_of_live_inferiors): Declare new function. * remote.c (set_general_process): Remove restriction on target remote mode. (remote_query_supported): Likewise. (remote_detach_1): Exit in target remote mode only when there is just one live inferior left. (remote_disconnect): Unpush the target directly instead of calling remote_mourn. (remote_kill): Rewrite function to handle both target remote and extended-remote. Call remote_kill_k. (remote_kill_k): New function. (extended_remote_kill): Delete function. (remote_mourn, extended_remote_mourn): Combine functions into one, remote_mourn, and enable extended functionality for target remote. (remote_pid_to_str): Enable "process" style ptid string for target remote. (remote_supports_multi_process): Remove restriction on target remote mode.
2015-12-14 20:18:05 +01:00
* target.h (struct target_ops): Make to_has_all_memory, to_has_memory, to_has_stack, to_has_registers and to_has_execution methods instead of variables. (target_has_all_memory_1, target_has_memory_1, target_has_stack_1) (target_has_registers_1, target_has_execution_1): Declare functions. (target_has_all_memory): Rewrite to call target_has_all_memory_1. (target_has_memory): Rewrite to call target_has_memory_1. (target_has_stack): Rewrite to call target_has_all_stack_1. (target_has_registers): Rewrite to call target_has_registers_1. (target_has_execution): Rewrite to call target_has_execution_1. (default_child_has_all_memory, default_child_has_memory) (default_child_has_stack, default_child_has_registers) (default_child_has_execution): Declare. (target_mark_running, target_mark_exited): Delete declarations. * target.c (default_child_has_all_memory, default_child_has_memory, default_child_has_stack, default_child_has_registers, default_child_has_execution): New. (target_has_all_memory_1, target_has_memory_1, target_has_stack_1, target_has_registers_1, target_has_execution_1): New. (add_target): Default the to_has_all_memory, to_has_all_memory, to_has_memory, to_has_stack, to_has_registers and to_has_execution callbacks to return 0. (update_current_target): Do not inherit to_has_all_memory, to_has_memory, to_has_stack, to_has_registers or to_has_execution. (target_mark_running, target_mark_exited): Delete. (memory_xfer_partial): Adjust. (target_read_memory, target_write_memory, target_search_memory): Dispatch to the the top-most target, not the flattened current_target. (target_info): Adjust. (init_dummy_target): Install return_zero as callback for to_has_all_memory, to_has_memory, to_has_stack, to_has_registers, to_has_execution. (set_maintenance_target_async_permitted): Use have_live_inferiors instead of target_has_execution. * target-memory.c (target_write_memory_blocks): Dispatch memory writes to the the top-most target, not the flattened current_target. * breakpoint.c (insert_breakpoints): Don't check for target_has_execution here. (update_global_location_list): Check if there are live inferiors to debug instead of target_has_execution. * infcmd.c (kill_command, detach_command): Check if there are inferiors instead of target_has_execution. * inferior.h (have_live_inferiors): Declare. * inferior.c (have_live_inferiors): New. * infrun.c (normal_stop): Don't check for target_has_execution to finish the thread states. * thread.c (is_thread_state, is_stopped, is_exited, is_running) (any_running, is_executing): Remove checks for target_has_execution. * top.c (kill_or_detach): Don't try to kill core inferiors. (quit_target): Don't check for target_has_execution. * corelow.c (core_has_memory, core_has_stack, core_has_registers): New. (init_core_ops): Install core_has_memory, core_has_stack and core_has_registers. * exec.c (exec_has_memory): New. (init_exec_ops): Install exec_has_memory. * remote.c (remote_add_inferior): Don't call target_mark_running. (remote_start_remote): Don't call target_mark_exited or call target_mark_running. (remote_open_1): Use have_inferiors instead of target_has_execution. Don't use target_mark_exited. (init_remote_ops): Install deafult_child_has_all_memory, default_child_has_memory, default_child_has_stack, default_child_has_registers, default_child_has_execution. * bsd-kvm.c (bsd_kvm_return_one): New. (bsd_kvm_add_target): Register bsd_kvm_return_one as to_has_memory, to_has_stack and to_has_registers callbacks. * remote-m32r-sdi.c (m32r_return_one): New. (init_m32r_ops): Register it. * inf-child.c (inf_child_target): Adjust to register default_child_has_all_memory, default_child_has_memory, default_child_has_stack, default_child_has_registers, default_child_has_execution callbacks. * gnu-nat.c (init_gnu_ops): Likewise. * go32-nat.c (init_go32_ops): Likewise. * hpux-thread.c (init_hpux_thread_ops): Likewise. * monitor.c (init_base_monitor_ops): Likewise. * nto-procfs.c (init_procfs_ops): Likewise. * remote-mips.c (_initialize_remote_mips): Likewise. * windows-nat.c (init_windows_ops): Likewise. * remote-sim.c (gdbsim_create_inferior): Don't use target_mark_running or target_mark_exited. (gdbsim_mourn_inferior): Don't call target_mark_exited. (init_gdbsim_ops): Adjust to register default_child_has_all_memory, default_child_has_memory, default_child_has_stack, default_child_has_registers, default_child_has_execution callbacks. * linux-nat.c (linux_nat_xfer_partial): If reading memory, and there's no inferior selected, defer to a lower stratum.
2009-06-07 18:46:48 +02:00
/* Returns true if there are any live inferiors in the inferior list
(not cores, not executables, real live processes). */
extern int have_live_inferiors (void);
RAII-fy make_cleanup_restore_current_thread & friends 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.
2017-05-04 13:46:44 +02:00
/* Save/restore the current inferior. */
class scoped_restore_current_inferior
{
public:
scoped_restore_current_inferior ()
: m_saved_inf (current_inferior ())
{}
~scoped_restore_current_inferior ()
{ set_current_inferior (m_saved_inf); }
DISABLE_COPY_AND_ASSIGN (scoped_restore_current_inferior);
RAII-fy make_cleanup_restore_current_thread & friends 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.
2017-05-04 13:46:44 +02:00
private:
inferior *m_saved_inf;
};
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* Traverse all inferiors. */
Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc. As preparation for multi-target, this patch makes each inferior have its own thread list. This isn't absolutely necessary for multi-target, but simplifies things. It originally stemmed from the desire to eliminate the init_thread_list calls sprinkled around, plus it makes it more efficient to iterate over threads of a given inferior (no need to always iterate over threads of all inferiors). We still need to iterate over threads of all inferiors in a number of places, which means we'd need adjust the ALL_THREADS / ALL_NON_EXITED_THREADS macros. However, naively tweaking those macros to have an extra for loop, like: #define ALL_THREADS (thr, inf) \ for (inf = inferior_list; inf; inf = inf->next) \ for (thr = inf->thread_list; thr; thr = thr->next) causes problems with code that does "break" or "continue" within the ALL_THREADS loop body. Plus, we need to declare the extra "inf" local variable in order to pass it as temporary variable to ALL_THREADS (etc.) It gets even trickier when we consider extending the macros to filter out threads matching a ptid_t and a target. The macros become tricker to read/write. Been there. An alternative (which was my next attempt), is to replace the ALL_THREADS etc. iteration style with for_each_all_threads, for_each_non_exited_threads, etc. functions which would take a callback as parameter, which would usually be passed a lambda. However, I did not find that satisfactory at all, because the resulting code ends up a little less natural / more noisy to read, write and debug/step-through (due to use of lambdas), and in many places where we use "continue;" to skip to the next thread now need to use "return;". (I ran into hard to debug bugs caused by a continue/return confusion.) I.e., before: ALL_NON_EXITED_THREADS (tp) { if (tp->not_what_I_want) continue; // do something } would turn into: for_each_non_exited_thread ([&] (thread_info *tp) { if (tp->not_what_I_want) return; // do something }); Lastly, the solution I settled with was to replace the ALL_THREADS / ALL_NON_EXITED_THREADS / ALL_INFERIORS macros with (C++20-like) ranges and iterators, such that you can instead naturaly iterate over threads/inferiors using range-for, like e.g,.: // all threads, including THREAD_EXITED threads. for (thread_info *tp : all_threads ()) { .... } // all non-exited threads. for (thread_info *tp : all_non_exited_threads ()) { .... } // all non-exited threads of INF inferior. for (thread_info *tp : inf->non_exited_threads ()) { .... } The all_non_exited_threads() function takes an optional filter ptid_t as parameter, which is quite convenient when we need to iterate over threads matching that filter. See e.g., how the set_executing/set_stop_requested/finish_thread_state etc. functions in thread.c end up being simplified. Most of the patch thus is about adding the infrustructure for allowing the above. Later on when we get to actual multi-target, these functions/ranges/iterators will gain a "target_ops *" parameter so that e.g., we can iterate over all threads of a given target that match a given filter ptid_t. The only entry points users needs to be aware of are the all_threads/all_non_exited_threads etc. functions seen above. Thus, those functions are declared in gdbthread.h/inferior.h. The actual iterators/ranges are mainly "internals" and thus are put out of view in the new thread-iter.h/thread-iter.c/inferior-iter.h files. That keeps the gdbthread.h/inferior.h headers quite a bit more readable. A common/safe-iterator.h header is added which adds a template that can be used to build "safe" iterators, which are forward iterators that can be used to replace the ALL_THREADS_SAFE macro and other instances of the same idiom in future. There's a little bit of shuffling of code between gdbthread.h/thread.c/inferior.h in the patch. That is necessary in order to avoid circular dependencies between the gdbthread.h/inferior.h headers. As for the init_thread_list calls sprinkled around, they're all eliminated by this patch, and a new, central call is added to inferior_appeared. Note how also related to that, there's a call to init_wait_for_inferior in remote.c that is eliminated. init_wait_for_inferior is currently responsible for discarding skipped inline frames, which had to be moved elsewhere. Given that nowadays we always have a thread even for single-threaded processes, the natural place is to delete a frame's inline frame info when we delete the thread. I.e., from clear_thread_inferior_resources. gdb/ChangeLog: 2018-11-22 Pedro Alves <palves@redhat.com> * Makefile.in (COMMON_SFILES): Add thread-iter.c. * breakpoint.c (breakpoints_should_be_inserted_now): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (print_one_breakpoint_location): Replace ALL_INFERIORS with all_inferiors. * bsd-kvm.c: Include inferior.h. * btrace.c (btrace_free_objfile): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * common/filtered-iterator.h: New. * common/safe-iterator.h: New. * corelow.c (core_target_open): Don't call init_thread_list here. * darwin-nat.c (thread_info_from_private_thread_info): Replace ALL_THREADS with all_threads. * fbsd-nat.c (fbsd_nat_target::resume): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fbsd-tdep.c (fbsd_make_corefile_notes): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fork-child.c (postfork_hook): Don't call init_thread_list here. * gdbarch-selftests.c (register_to_value_test): Adjust. * gdbthread.h: Don't include "inferior.h" here. (struct inferior): Forward declare. (enum step_over_calls_kind): Moved here from inferior.h. (thread_info::deletable): Definition moved to thread.c. (find_thread_ptid (inferior *, ptid_t)): Declare. (ALL_THREADS, ALL_THREADS_BY_INFERIOR, ALL_THREADS_SAFE): Delete. Include "thread-iter.h". (all_threads, all_non_exited_threads, all_threads_safe): New. (any_thread_p): Declare. (thread_list): Delete. * infcmd.c (signal_command): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (proceed_after_attach_callback): Delete. (proceed_after_attach): Take an inferior pointer instead of an integer PID. Adjust to use range-for. (attach_post_wait): Pass down inferior pointer instead of pid. Use range-for instead of ALL_NON_EXITED_THREADS. (detach_command): Remove init_thread_list call. * inferior-iter.h: New. * inferior.c (struct delete_thread_of_inferior_arg): Delete. (delete_thread_of_inferior): Delete. (delete_inferior, exit_inferior_1): Use range-for with inf->threads_safe() instead of iterate_over_threads. (inferior_appeared): Call init_thread_list here. (discard_all_inferiors): Use all_non_exited_inferiors. (find_inferior_id, find_inferior_pid): Use all_inferiors. (iterate_over_inferiors): Use all_inferiors_safe. (have_inferiors, number_of_live_inferiors): Use all_non_exited_inferiors. (number_of_inferiors): Use all_inferiors and std::distance. (print_inferior): Use all_inferiors. * inferior.h: Include gdbthread.h. (enum step_over_calls_kind): Moved to gdbthread.h. (struct inferior) <thread_list>: New field. <threads, non_exited_threads, threads_safe>: New methods. (ALL_INFERIORS): Delete. Include "inferior-iter.h". (ALL_NON_EXITED_INFERIORS): Delete. (all_inferiors_safe, all_inferiors, all_non_exited_inferiors): New functions. * inflow.c (child_interrupt, child_pass_ctrlc): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * infrun.c (follow_exec): Use all_threads_safe. (clear_proceed_status, proceed): Use all_non_exited_threads. (init_wait_for_inferior): Don't clear inline frame state here. (infrun_thread_stop_requested, for_each_just_stopped_thread): Use all_threads instead of ALL_NON_EXITED_THREADS. (random_pending_event_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use a lambda for repeated code. (clean_up_just_stopped_threads_fsms): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (handle_no_resumed): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use all_inferiors instead of ALL_INFERIORS. (restart_threads, switch_back_to_stepped_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-nat.c (check_zombie_leaders): Replace ALL_INFERIORS with all_inferiors. (kill_unfollowed_fork_children): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-tdep.c (linux_make_corefile_notes): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-thread-db.c (thread_db_target::update_thread_list): Replace ALL_INFERIORS with all_inferiors. (thread_db_target::thread_handle_to_thread_info): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * mi/mi-interp.c (multiple_inferiors_p): New. (mi_on_resume_1): Simplify using all_non_exited_threads and multiple_inferiors_p. * mi/mi-main.c (mi_cmd_thread_list_ids): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * nto-procfs.c (nto_procfs_target::open): Don't call init_thread_list here. * record-btrace.c (record_btrace_target_open) (record_btrace_target::stop_recording) (record_btrace_target::close) (record_btrace_target::record_is_replaying) (record_btrace_target::resume, record_btrace_target::wait) (record_btrace_target::record_stop_replaying): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * record-full.c (record_full_wait_1): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * regcache.c (cooked_read_test): Remove reference to global thread_list. * remote-sim.c (gdbsim_target::create_inferior): Don't call init_thread_list here. * remote.c (remote_target::update_thread_list): Use all_threads_safe instead of ALL_NON_EXITED_THREADS. (remote_target::process_initial_stop_replies): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::open_1): Don't call init_thread_list here. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::commit_resume) (remote_target::remove_new_fork_children): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::kill_new_fork_children): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Remove init_thread_list and init_wait_for_inferior calls. (remote_target::remote_btrace_maybe_reopen) (remote_target::thread_handle_to_thread_info): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * target.c (target_terminal::restore_inferior) (target_terminal_is_ours_kind): Replace ALL_INFERIORS with all_non_exited_inferiors. * thread-iter.c: New file. * thread-iter.h: New file. * thread.c: Include "inline-frame.h". (thread_list): Delete. (clear_thread_inferior_resources): Call clear_inline_frame_state. (init_thread_list): Use all_threads_safe instead of ALL_THREADS_SAFE. Adjust to per-inferior thread lists. (new_thread): Adjust to per-inferior thread lists. (add_thread_silent): Pass inferior to find_thread_ptid. (thread_info::deletable): New, moved from the header. (delete_thread_1): Adjust to per-inferior thread lists. (find_thread_global_id): Use inf->threads(). (find_thread_ptid): Use find_inferior_ptid and pass inferior to find_thread_ptid. (find_thread_ptid(inferior*, ptid_t)): New overload. (iterate_over_threads): Use all_threads_safe. (any_thread_p): New. (thread_count): Use all_threads and std::distance. (live_threads_count): Use all_non_exited_threads and std::distance. (valid_global_thread_id): Use all_threads. (in_thread_list): Use find_thread_ptid. (first_thread_of_inferior): Adjust to per-inferior thread lists. (any_thread_of_inferior, any_live_thread_of_inferior): Use inf->non_exited_threads(). (prune_threads, delete_exited_threads): Use all_threads_safe. (thread_change_ptid): Pass inferior pointer to find_thread_ptid. (set_resumed, set_running): Use all_non_exited_threads. (is_thread_state, is_stopped, is_exited, is_running) (is_executing): Delete. (set_executing, set_stop_requested, finish_thread_state): Use all_non_exited_threads. (print_thread_info_1): Use all_inferiors and all_threads. (thread_apply_all_command): Use all_non_exited_threads. (thread_find_command): Use all_threads. (update_threads_executing): Use all_non_exited_threads. * tid-parse.c (parse_thread_id): Use inf->threads. * x86-bsd-nat.c (x86bsd_dr_set): Use inf->non_exited_threads ().
2018-11-22 17:09:14 +01:00
extern struct inferior *inferior_list;
Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc. As preparation for multi-target, this patch makes each inferior have its own thread list. This isn't absolutely necessary for multi-target, but simplifies things. It originally stemmed from the desire to eliminate the init_thread_list calls sprinkled around, plus it makes it more efficient to iterate over threads of a given inferior (no need to always iterate over threads of all inferiors). We still need to iterate over threads of all inferiors in a number of places, which means we'd need adjust the ALL_THREADS / ALL_NON_EXITED_THREADS macros. However, naively tweaking those macros to have an extra for loop, like: #define ALL_THREADS (thr, inf) \ for (inf = inferior_list; inf; inf = inf->next) \ for (thr = inf->thread_list; thr; thr = thr->next) causes problems with code that does "break" or "continue" within the ALL_THREADS loop body. Plus, we need to declare the extra "inf" local variable in order to pass it as temporary variable to ALL_THREADS (etc.) It gets even trickier when we consider extending the macros to filter out threads matching a ptid_t and a target. The macros become tricker to read/write. Been there. An alternative (which was my next attempt), is to replace the ALL_THREADS etc. iteration style with for_each_all_threads, for_each_non_exited_threads, etc. functions which would take a callback as parameter, which would usually be passed a lambda. However, I did not find that satisfactory at all, because the resulting code ends up a little less natural / more noisy to read, write and debug/step-through (due to use of lambdas), and in many places where we use "continue;" to skip to the next thread now need to use "return;". (I ran into hard to debug bugs caused by a continue/return confusion.) I.e., before: ALL_NON_EXITED_THREADS (tp) { if (tp->not_what_I_want) continue; // do something } would turn into: for_each_non_exited_thread ([&] (thread_info *tp) { if (tp->not_what_I_want) return; // do something }); Lastly, the solution I settled with was to replace the ALL_THREADS / ALL_NON_EXITED_THREADS / ALL_INFERIORS macros with (C++20-like) ranges and iterators, such that you can instead naturaly iterate over threads/inferiors using range-for, like e.g,.: // all threads, including THREAD_EXITED threads. for (thread_info *tp : all_threads ()) { .... } // all non-exited threads. for (thread_info *tp : all_non_exited_threads ()) { .... } // all non-exited threads of INF inferior. for (thread_info *tp : inf->non_exited_threads ()) { .... } The all_non_exited_threads() function takes an optional filter ptid_t as parameter, which is quite convenient when we need to iterate over threads matching that filter. See e.g., how the set_executing/set_stop_requested/finish_thread_state etc. functions in thread.c end up being simplified. Most of the patch thus is about adding the infrustructure for allowing the above. Later on when we get to actual multi-target, these functions/ranges/iterators will gain a "target_ops *" parameter so that e.g., we can iterate over all threads of a given target that match a given filter ptid_t. The only entry points users needs to be aware of are the all_threads/all_non_exited_threads etc. functions seen above. Thus, those functions are declared in gdbthread.h/inferior.h. The actual iterators/ranges are mainly "internals" and thus are put out of view in the new thread-iter.h/thread-iter.c/inferior-iter.h files. That keeps the gdbthread.h/inferior.h headers quite a bit more readable. A common/safe-iterator.h header is added which adds a template that can be used to build "safe" iterators, which are forward iterators that can be used to replace the ALL_THREADS_SAFE macro and other instances of the same idiom in future. There's a little bit of shuffling of code between gdbthread.h/thread.c/inferior.h in the patch. That is necessary in order to avoid circular dependencies between the gdbthread.h/inferior.h headers. As for the init_thread_list calls sprinkled around, they're all eliminated by this patch, and a new, central call is added to inferior_appeared. Note how also related to that, there's a call to init_wait_for_inferior in remote.c that is eliminated. init_wait_for_inferior is currently responsible for discarding skipped inline frames, which had to be moved elsewhere. Given that nowadays we always have a thread even for single-threaded processes, the natural place is to delete a frame's inline frame info when we delete the thread. I.e., from clear_thread_inferior_resources. gdb/ChangeLog: 2018-11-22 Pedro Alves <palves@redhat.com> * Makefile.in (COMMON_SFILES): Add thread-iter.c. * breakpoint.c (breakpoints_should_be_inserted_now): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (print_one_breakpoint_location): Replace ALL_INFERIORS with all_inferiors. * bsd-kvm.c: Include inferior.h. * btrace.c (btrace_free_objfile): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * common/filtered-iterator.h: New. * common/safe-iterator.h: New. * corelow.c (core_target_open): Don't call init_thread_list here. * darwin-nat.c (thread_info_from_private_thread_info): Replace ALL_THREADS with all_threads. * fbsd-nat.c (fbsd_nat_target::resume): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fbsd-tdep.c (fbsd_make_corefile_notes): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fork-child.c (postfork_hook): Don't call init_thread_list here. * gdbarch-selftests.c (register_to_value_test): Adjust. * gdbthread.h: Don't include "inferior.h" here. (struct inferior): Forward declare. (enum step_over_calls_kind): Moved here from inferior.h. (thread_info::deletable): Definition moved to thread.c. (find_thread_ptid (inferior *, ptid_t)): Declare. (ALL_THREADS, ALL_THREADS_BY_INFERIOR, ALL_THREADS_SAFE): Delete. Include "thread-iter.h". (all_threads, all_non_exited_threads, all_threads_safe): New. (any_thread_p): Declare. (thread_list): Delete. * infcmd.c (signal_command): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (proceed_after_attach_callback): Delete. (proceed_after_attach): Take an inferior pointer instead of an integer PID. Adjust to use range-for. (attach_post_wait): Pass down inferior pointer instead of pid. Use range-for instead of ALL_NON_EXITED_THREADS. (detach_command): Remove init_thread_list call. * inferior-iter.h: New. * inferior.c (struct delete_thread_of_inferior_arg): Delete. (delete_thread_of_inferior): Delete. (delete_inferior, exit_inferior_1): Use range-for with inf->threads_safe() instead of iterate_over_threads. (inferior_appeared): Call init_thread_list here. (discard_all_inferiors): Use all_non_exited_inferiors. (find_inferior_id, find_inferior_pid): Use all_inferiors. (iterate_over_inferiors): Use all_inferiors_safe. (have_inferiors, number_of_live_inferiors): Use all_non_exited_inferiors. (number_of_inferiors): Use all_inferiors and std::distance. (print_inferior): Use all_inferiors. * inferior.h: Include gdbthread.h. (enum step_over_calls_kind): Moved to gdbthread.h. (struct inferior) <thread_list>: New field. <threads, non_exited_threads, threads_safe>: New methods. (ALL_INFERIORS): Delete. Include "inferior-iter.h". (ALL_NON_EXITED_INFERIORS): Delete. (all_inferiors_safe, all_inferiors, all_non_exited_inferiors): New functions. * inflow.c (child_interrupt, child_pass_ctrlc): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * infrun.c (follow_exec): Use all_threads_safe. (clear_proceed_status, proceed): Use all_non_exited_threads. (init_wait_for_inferior): Don't clear inline frame state here. (infrun_thread_stop_requested, for_each_just_stopped_thread): Use all_threads instead of ALL_NON_EXITED_THREADS. (random_pending_event_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use a lambda for repeated code. (clean_up_just_stopped_threads_fsms): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (handle_no_resumed): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use all_inferiors instead of ALL_INFERIORS. (restart_threads, switch_back_to_stepped_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-nat.c (check_zombie_leaders): Replace ALL_INFERIORS with all_inferiors. (kill_unfollowed_fork_children): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-tdep.c (linux_make_corefile_notes): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-thread-db.c (thread_db_target::update_thread_list): Replace ALL_INFERIORS with all_inferiors. (thread_db_target::thread_handle_to_thread_info): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * mi/mi-interp.c (multiple_inferiors_p): New. (mi_on_resume_1): Simplify using all_non_exited_threads and multiple_inferiors_p. * mi/mi-main.c (mi_cmd_thread_list_ids): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * nto-procfs.c (nto_procfs_target::open): Don't call init_thread_list here. * record-btrace.c (record_btrace_target_open) (record_btrace_target::stop_recording) (record_btrace_target::close) (record_btrace_target::record_is_replaying) (record_btrace_target::resume, record_btrace_target::wait) (record_btrace_target::record_stop_replaying): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * record-full.c (record_full_wait_1): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * regcache.c (cooked_read_test): Remove reference to global thread_list. * remote-sim.c (gdbsim_target::create_inferior): Don't call init_thread_list here. * remote.c (remote_target::update_thread_list): Use all_threads_safe instead of ALL_NON_EXITED_THREADS. (remote_target::process_initial_stop_replies): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::open_1): Don't call init_thread_list here. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::commit_resume) (remote_target::remove_new_fork_children): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::kill_new_fork_children): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Remove init_thread_list and init_wait_for_inferior calls. (remote_target::remote_btrace_maybe_reopen) (remote_target::thread_handle_to_thread_info): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * target.c (target_terminal::restore_inferior) (target_terminal_is_ours_kind): Replace ALL_INFERIORS with all_non_exited_inferiors. * thread-iter.c: New file. * thread-iter.h: New file. * thread.c: Include "inline-frame.h". (thread_list): Delete. (clear_thread_inferior_resources): Call clear_inline_frame_state. (init_thread_list): Use all_threads_safe instead of ALL_THREADS_SAFE. Adjust to per-inferior thread lists. (new_thread): Adjust to per-inferior thread lists. (add_thread_silent): Pass inferior to find_thread_ptid. (thread_info::deletable): New, moved from the header. (delete_thread_1): Adjust to per-inferior thread lists. (find_thread_global_id): Use inf->threads(). (find_thread_ptid): Use find_inferior_ptid and pass inferior to find_thread_ptid. (find_thread_ptid(inferior*, ptid_t)): New overload. (iterate_over_threads): Use all_threads_safe. (any_thread_p): New. (thread_count): Use all_threads and std::distance. (live_threads_count): Use all_non_exited_threads and std::distance. (valid_global_thread_id): Use all_threads. (in_thread_list): Use find_thread_ptid. (first_thread_of_inferior): Adjust to per-inferior thread lists. (any_thread_of_inferior, any_live_thread_of_inferior): Use inf->non_exited_threads(). (prune_threads, delete_exited_threads): Use all_threads_safe. (thread_change_ptid): Pass inferior pointer to find_thread_ptid. (set_resumed, set_running): Use all_non_exited_threads. (is_thread_state, is_stopped, is_exited, is_running) (is_executing): Delete. (set_executing, set_stop_requested, finish_thread_state): Use all_non_exited_threads. (print_thread_info_1): Use all_inferiors and all_threads. (thread_apply_all_command): Use all_non_exited_threads. (thread_find_command): Use all_threads. (update_threads_executing): Use all_non_exited_threads. * tid-parse.c (parse_thread_id): Use inf->threads. * x86-bsd-nat.c (x86bsd_dr_set): Use inf->non_exited_threads ().
2018-11-22 17:09:14 +01:00
/* Pull in the internals of the inferiors ranges and iterators. Must
be done after struct inferior is defined. */
#include "inferior-iter.h"
gdb: Coalesce/aggregate (async) vCont packets/actions Currently, with "maint set target-non-stop on", that is, when gdb connects with the non-stop/asynchronous variant of the remote protocol, even with "set non-stop off", GDB always sends one vCont packet per thread resumed. This patch makes GDB aggregate and coalesce vCont packets, so we send vCont packets like "vCont;s:p1.1;c" in non-stop mode too. Basically, this is done by: - Adding a new target method target_commit_resume that is called after calling target_resume one or more times. When resuming a batch of threads, we'll only call target_commit_resume once after calling target_resume for all threads. - Making the remote target defer sending the actual vCont packet to target_commit_resume. Special care must be taken to avoid sending a vCont action with a "wildcard" thread-id (all threads of process / all threads) when that would resume threads/processes that should not be resumed. See remote_commit_resume comments for details. Unlike all-stop's remote_resume implementation, this handles the case of too many actions resulting in a too-big vCont packet, by flushing the vCont packet and starting a new one. E.g., imagining that the "c" action in: vCont;s:1;c overflows the packet buffer, we split the actions like: vCont;s:1 vCont;c Tested on x86_64 Fedora 20, with and without "maint set target-non-stop on". Also tested with a hack that makes remote_commit_resume flush the vCont packet after every action appended (which caught a few bugs). gdb/ChangeLog: 2016-10-26 Pedro Alves <palves@redhat.com> * inferior.h (ALL_NON_EXITED_INFERIORS): New macro. * infrun.c (do_target_resume): Call target_commit_resume. (proceed): Defer target_commit_resume while looping over threads, resuming them. Call target_commit_resume at the end. * record-btrace.c (record_btrace_commit_resume): New function. (init_record_btrace_ops): Install it as to_commit_resume method. * record-full.c (record_full_commit_resume): New function. (record_full_wait_1): Call the beneath target's to_commit_resume method. (init_record_full_ops): Install record_full_commit_resume as to_commit_resume method. * remote.c (struct private_thread_info) <last_resume_step, last_resume_sig, vcont_resumed>: New fields. (remote_add_thread): Set the new thread's vcont_resumed flag. (demand_private_info): Delete. (get_private_info_thread, get_private_info_ptid): New functions. (remote_update_thread_list): Adjust. (process_initial_stop_replies): Clear the thread's vcont_resumed flag. (remote_resume): If connected in non-stop mode, record the resume request and return early. (struct private_inferior): New. (struct vcont_builder): New. (vcont_builder_restart, vcont_builder_flush) (vcont_builder_push_action): New functions. (MAX_ACTION_SIZE): New macro. (remote_commit_resume): New function. (thread_pending_fork_status, is_pending_fork_parent_thread): New functions. (check_pending_event_prevents_wildcard_vcont_callback) (check_pending_events_prevent_wildcard_vcont): New functions. (process_stop_reply): Adjust. Clear the thread's vcont_resumed flag. (init_remote_ops): Install remote_commit_resume. * target-delegates.c: Regenerate. * target.c (defer_target_commit_resume): New global. (target_commit_resume, make_cleanup_defer_target_commit_resume): New functions. * target.h (struct target_ops) <to_commit_resume>: New field. (target_resume): Update comments. (target_commit_resume): New declaration.
2016-10-26 12:08:28 +02:00
Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc. As preparation for multi-target, this patch makes each inferior have its own thread list. This isn't absolutely necessary for multi-target, but simplifies things. It originally stemmed from the desire to eliminate the init_thread_list calls sprinkled around, plus it makes it more efficient to iterate over threads of a given inferior (no need to always iterate over threads of all inferiors). We still need to iterate over threads of all inferiors in a number of places, which means we'd need adjust the ALL_THREADS / ALL_NON_EXITED_THREADS macros. However, naively tweaking those macros to have an extra for loop, like: #define ALL_THREADS (thr, inf) \ for (inf = inferior_list; inf; inf = inf->next) \ for (thr = inf->thread_list; thr; thr = thr->next) causes problems with code that does "break" or "continue" within the ALL_THREADS loop body. Plus, we need to declare the extra "inf" local variable in order to pass it as temporary variable to ALL_THREADS (etc.) It gets even trickier when we consider extending the macros to filter out threads matching a ptid_t and a target. The macros become tricker to read/write. Been there. An alternative (which was my next attempt), is to replace the ALL_THREADS etc. iteration style with for_each_all_threads, for_each_non_exited_threads, etc. functions which would take a callback as parameter, which would usually be passed a lambda. However, I did not find that satisfactory at all, because the resulting code ends up a little less natural / more noisy to read, write and debug/step-through (due to use of lambdas), and in many places where we use "continue;" to skip to the next thread now need to use "return;". (I ran into hard to debug bugs caused by a continue/return confusion.) I.e., before: ALL_NON_EXITED_THREADS (tp) { if (tp->not_what_I_want) continue; // do something } would turn into: for_each_non_exited_thread ([&] (thread_info *tp) { if (tp->not_what_I_want) return; // do something }); Lastly, the solution I settled with was to replace the ALL_THREADS / ALL_NON_EXITED_THREADS / ALL_INFERIORS macros with (C++20-like) ranges and iterators, such that you can instead naturaly iterate over threads/inferiors using range-for, like e.g,.: // all threads, including THREAD_EXITED threads. for (thread_info *tp : all_threads ()) { .... } // all non-exited threads. for (thread_info *tp : all_non_exited_threads ()) { .... } // all non-exited threads of INF inferior. for (thread_info *tp : inf->non_exited_threads ()) { .... } The all_non_exited_threads() function takes an optional filter ptid_t as parameter, which is quite convenient when we need to iterate over threads matching that filter. See e.g., how the set_executing/set_stop_requested/finish_thread_state etc. functions in thread.c end up being simplified. Most of the patch thus is about adding the infrustructure for allowing the above. Later on when we get to actual multi-target, these functions/ranges/iterators will gain a "target_ops *" parameter so that e.g., we can iterate over all threads of a given target that match a given filter ptid_t. The only entry points users needs to be aware of are the all_threads/all_non_exited_threads etc. functions seen above. Thus, those functions are declared in gdbthread.h/inferior.h. The actual iterators/ranges are mainly "internals" and thus are put out of view in the new thread-iter.h/thread-iter.c/inferior-iter.h files. That keeps the gdbthread.h/inferior.h headers quite a bit more readable. A common/safe-iterator.h header is added which adds a template that can be used to build "safe" iterators, which are forward iterators that can be used to replace the ALL_THREADS_SAFE macro and other instances of the same idiom in future. There's a little bit of shuffling of code between gdbthread.h/thread.c/inferior.h in the patch. That is necessary in order to avoid circular dependencies between the gdbthread.h/inferior.h headers. As for the init_thread_list calls sprinkled around, they're all eliminated by this patch, and a new, central call is added to inferior_appeared. Note how also related to that, there's a call to init_wait_for_inferior in remote.c that is eliminated. init_wait_for_inferior is currently responsible for discarding skipped inline frames, which had to be moved elsewhere. Given that nowadays we always have a thread even for single-threaded processes, the natural place is to delete a frame's inline frame info when we delete the thread. I.e., from clear_thread_inferior_resources. gdb/ChangeLog: 2018-11-22 Pedro Alves <palves@redhat.com> * Makefile.in (COMMON_SFILES): Add thread-iter.c. * breakpoint.c (breakpoints_should_be_inserted_now): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (print_one_breakpoint_location): Replace ALL_INFERIORS with all_inferiors. * bsd-kvm.c: Include inferior.h. * btrace.c (btrace_free_objfile): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * common/filtered-iterator.h: New. * common/safe-iterator.h: New. * corelow.c (core_target_open): Don't call init_thread_list here. * darwin-nat.c (thread_info_from_private_thread_info): Replace ALL_THREADS with all_threads. * fbsd-nat.c (fbsd_nat_target::resume): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fbsd-tdep.c (fbsd_make_corefile_notes): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fork-child.c (postfork_hook): Don't call init_thread_list here. * gdbarch-selftests.c (register_to_value_test): Adjust. * gdbthread.h: Don't include "inferior.h" here. (struct inferior): Forward declare. (enum step_over_calls_kind): Moved here from inferior.h. (thread_info::deletable): Definition moved to thread.c. (find_thread_ptid (inferior *, ptid_t)): Declare. (ALL_THREADS, ALL_THREADS_BY_INFERIOR, ALL_THREADS_SAFE): Delete. Include "thread-iter.h". (all_threads, all_non_exited_threads, all_threads_safe): New. (any_thread_p): Declare. (thread_list): Delete. * infcmd.c (signal_command): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (proceed_after_attach_callback): Delete. (proceed_after_attach): Take an inferior pointer instead of an integer PID. Adjust to use range-for. (attach_post_wait): Pass down inferior pointer instead of pid. Use range-for instead of ALL_NON_EXITED_THREADS. (detach_command): Remove init_thread_list call. * inferior-iter.h: New. * inferior.c (struct delete_thread_of_inferior_arg): Delete. (delete_thread_of_inferior): Delete. (delete_inferior, exit_inferior_1): Use range-for with inf->threads_safe() instead of iterate_over_threads. (inferior_appeared): Call init_thread_list here. (discard_all_inferiors): Use all_non_exited_inferiors. (find_inferior_id, find_inferior_pid): Use all_inferiors. (iterate_over_inferiors): Use all_inferiors_safe. (have_inferiors, number_of_live_inferiors): Use all_non_exited_inferiors. (number_of_inferiors): Use all_inferiors and std::distance. (print_inferior): Use all_inferiors. * inferior.h: Include gdbthread.h. (enum step_over_calls_kind): Moved to gdbthread.h. (struct inferior) <thread_list>: New field. <threads, non_exited_threads, threads_safe>: New methods. (ALL_INFERIORS): Delete. Include "inferior-iter.h". (ALL_NON_EXITED_INFERIORS): Delete. (all_inferiors_safe, all_inferiors, all_non_exited_inferiors): New functions. * inflow.c (child_interrupt, child_pass_ctrlc): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * infrun.c (follow_exec): Use all_threads_safe. (clear_proceed_status, proceed): Use all_non_exited_threads. (init_wait_for_inferior): Don't clear inline frame state here. (infrun_thread_stop_requested, for_each_just_stopped_thread): Use all_threads instead of ALL_NON_EXITED_THREADS. (random_pending_event_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use a lambda for repeated code. (clean_up_just_stopped_threads_fsms): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (handle_no_resumed): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use all_inferiors instead of ALL_INFERIORS. (restart_threads, switch_back_to_stepped_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-nat.c (check_zombie_leaders): Replace ALL_INFERIORS with all_inferiors. (kill_unfollowed_fork_children): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-tdep.c (linux_make_corefile_notes): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-thread-db.c (thread_db_target::update_thread_list): Replace ALL_INFERIORS with all_inferiors. (thread_db_target::thread_handle_to_thread_info): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * mi/mi-interp.c (multiple_inferiors_p): New. (mi_on_resume_1): Simplify using all_non_exited_threads and multiple_inferiors_p. * mi/mi-main.c (mi_cmd_thread_list_ids): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * nto-procfs.c (nto_procfs_target::open): Don't call init_thread_list here. * record-btrace.c (record_btrace_target_open) (record_btrace_target::stop_recording) (record_btrace_target::close) (record_btrace_target::record_is_replaying) (record_btrace_target::resume, record_btrace_target::wait) (record_btrace_target::record_stop_replaying): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * record-full.c (record_full_wait_1): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * regcache.c (cooked_read_test): Remove reference to global thread_list. * remote-sim.c (gdbsim_target::create_inferior): Don't call init_thread_list here. * remote.c (remote_target::update_thread_list): Use all_threads_safe instead of ALL_NON_EXITED_THREADS. (remote_target::process_initial_stop_replies): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::open_1): Don't call init_thread_list here. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::commit_resume) (remote_target::remove_new_fork_children): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::kill_new_fork_children): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Remove init_thread_list and init_wait_for_inferior calls. (remote_target::remote_btrace_maybe_reopen) (remote_target::thread_handle_to_thread_info): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * target.c (target_terminal::restore_inferior) (target_terminal_is_ours_kind): Replace ALL_INFERIORS with all_non_exited_inferiors. * thread-iter.c: New file. * thread-iter.h: New file. * thread.c: Include "inline-frame.h". (thread_list): Delete. (clear_thread_inferior_resources): Call clear_inline_frame_state. (init_thread_list): Use all_threads_safe instead of ALL_THREADS_SAFE. Adjust to per-inferior thread lists. (new_thread): Adjust to per-inferior thread lists. (add_thread_silent): Pass inferior to find_thread_ptid. (thread_info::deletable): New, moved from the header. (delete_thread_1): Adjust to per-inferior thread lists. (find_thread_global_id): Use inf->threads(). (find_thread_ptid): Use find_inferior_ptid and pass inferior to find_thread_ptid. (find_thread_ptid(inferior*, ptid_t)): New overload. (iterate_over_threads): Use all_threads_safe. (any_thread_p): New. (thread_count): Use all_threads and std::distance. (live_threads_count): Use all_non_exited_threads and std::distance. (valid_global_thread_id): Use all_threads. (in_thread_list): Use find_thread_ptid. (first_thread_of_inferior): Adjust to per-inferior thread lists. (any_thread_of_inferior, any_live_thread_of_inferior): Use inf->non_exited_threads(). (prune_threads, delete_exited_threads): Use all_threads_safe. (thread_change_ptid): Pass inferior pointer to find_thread_ptid. (set_resumed, set_running): Use all_non_exited_threads. (is_thread_state, is_stopped, is_exited, is_running) (is_executing): Delete. (set_executing, set_stop_requested, finish_thread_state): Use all_non_exited_threads. (print_thread_info_1): Use all_inferiors and all_threads. (thread_apply_all_command): Use all_non_exited_threads. (thread_find_command): Use all_threads. (update_threads_executing): Use all_non_exited_threads. * tid-parse.c (parse_thread_id): Use inf->threads. * x86-bsd-nat.c (x86bsd_dr_set): Use inf->non_exited_threads ().
2018-11-22 17:09:14 +01:00
/* Return a range that can be used to walk over all inferiors
inferiors, with range-for, safely. I.e., it is safe to delete the
currently-iterated inferior. When combined with range-for, this
allow convenient patterns like this:
gdb: Coalesce/aggregate (async) vCont packets/actions Currently, with "maint set target-non-stop on", that is, when gdb connects with the non-stop/asynchronous variant of the remote protocol, even with "set non-stop off", GDB always sends one vCont packet per thread resumed. This patch makes GDB aggregate and coalesce vCont packets, so we send vCont packets like "vCont;s:p1.1;c" in non-stop mode too. Basically, this is done by: - Adding a new target method target_commit_resume that is called after calling target_resume one or more times. When resuming a batch of threads, we'll only call target_commit_resume once after calling target_resume for all threads. - Making the remote target defer sending the actual vCont packet to target_commit_resume. Special care must be taken to avoid sending a vCont action with a "wildcard" thread-id (all threads of process / all threads) when that would resume threads/processes that should not be resumed. See remote_commit_resume comments for details. Unlike all-stop's remote_resume implementation, this handles the case of too many actions resulting in a too-big vCont packet, by flushing the vCont packet and starting a new one. E.g., imagining that the "c" action in: vCont;s:1;c overflows the packet buffer, we split the actions like: vCont;s:1 vCont;c Tested on x86_64 Fedora 20, with and without "maint set target-non-stop on". Also tested with a hack that makes remote_commit_resume flush the vCont packet after every action appended (which caught a few bugs). gdb/ChangeLog: 2016-10-26 Pedro Alves <palves@redhat.com> * inferior.h (ALL_NON_EXITED_INFERIORS): New macro. * infrun.c (do_target_resume): Call target_commit_resume. (proceed): Defer target_commit_resume while looping over threads, resuming them. Call target_commit_resume at the end. * record-btrace.c (record_btrace_commit_resume): New function. (init_record_btrace_ops): Install it as to_commit_resume method. * record-full.c (record_full_commit_resume): New function. (record_full_wait_1): Call the beneath target's to_commit_resume method. (init_record_full_ops): Install record_full_commit_resume as to_commit_resume method. * remote.c (struct private_thread_info) <last_resume_step, last_resume_sig, vcont_resumed>: New fields. (remote_add_thread): Set the new thread's vcont_resumed flag. (demand_private_info): Delete. (get_private_info_thread, get_private_info_ptid): New functions. (remote_update_thread_list): Adjust. (process_initial_stop_replies): Clear the thread's vcont_resumed flag. (remote_resume): If connected in non-stop mode, record the resume request and return early. (struct private_inferior): New. (struct vcont_builder): New. (vcont_builder_restart, vcont_builder_flush) (vcont_builder_push_action): New functions. (MAX_ACTION_SIZE): New macro. (remote_commit_resume): New function. (thread_pending_fork_status, is_pending_fork_parent_thread): New functions. (check_pending_event_prevents_wildcard_vcont_callback) (check_pending_events_prevent_wildcard_vcont): New functions. (process_stop_reply): Adjust. Clear the thread's vcont_resumed flag. (init_remote_ops): Install remote_commit_resume. * target-delegates.c: Regenerate. * target.c (defer_target_commit_resume): New global. (target_commit_resume, make_cleanup_defer_target_commit_resume): New functions. * target.h (struct target_ops) <to_commit_resume>: New field. (target_resume): Update comments. (target_commit_resume): New declaration.
2016-10-26 12:08:28 +02:00
Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc. As preparation for multi-target, this patch makes each inferior have its own thread list. This isn't absolutely necessary for multi-target, but simplifies things. It originally stemmed from the desire to eliminate the init_thread_list calls sprinkled around, plus it makes it more efficient to iterate over threads of a given inferior (no need to always iterate over threads of all inferiors). We still need to iterate over threads of all inferiors in a number of places, which means we'd need adjust the ALL_THREADS / ALL_NON_EXITED_THREADS macros. However, naively tweaking those macros to have an extra for loop, like: #define ALL_THREADS (thr, inf) \ for (inf = inferior_list; inf; inf = inf->next) \ for (thr = inf->thread_list; thr; thr = thr->next) causes problems with code that does "break" or "continue" within the ALL_THREADS loop body. Plus, we need to declare the extra "inf" local variable in order to pass it as temporary variable to ALL_THREADS (etc.) It gets even trickier when we consider extending the macros to filter out threads matching a ptid_t and a target. The macros become tricker to read/write. Been there. An alternative (which was my next attempt), is to replace the ALL_THREADS etc. iteration style with for_each_all_threads, for_each_non_exited_threads, etc. functions which would take a callback as parameter, which would usually be passed a lambda. However, I did not find that satisfactory at all, because the resulting code ends up a little less natural / more noisy to read, write and debug/step-through (due to use of lambdas), and in many places where we use "continue;" to skip to the next thread now need to use "return;". (I ran into hard to debug bugs caused by a continue/return confusion.) I.e., before: ALL_NON_EXITED_THREADS (tp) { if (tp->not_what_I_want) continue; // do something } would turn into: for_each_non_exited_thread ([&] (thread_info *tp) { if (tp->not_what_I_want) return; // do something }); Lastly, the solution I settled with was to replace the ALL_THREADS / ALL_NON_EXITED_THREADS / ALL_INFERIORS macros with (C++20-like) ranges and iterators, such that you can instead naturaly iterate over threads/inferiors using range-for, like e.g,.: // all threads, including THREAD_EXITED threads. for (thread_info *tp : all_threads ()) { .... } // all non-exited threads. for (thread_info *tp : all_non_exited_threads ()) { .... } // all non-exited threads of INF inferior. for (thread_info *tp : inf->non_exited_threads ()) { .... } The all_non_exited_threads() function takes an optional filter ptid_t as parameter, which is quite convenient when we need to iterate over threads matching that filter. See e.g., how the set_executing/set_stop_requested/finish_thread_state etc. functions in thread.c end up being simplified. Most of the patch thus is about adding the infrustructure for allowing the above. Later on when we get to actual multi-target, these functions/ranges/iterators will gain a "target_ops *" parameter so that e.g., we can iterate over all threads of a given target that match a given filter ptid_t. The only entry points users needs to be aware of are the all_threads/all_non_exited_threads etc. functions seen above. Thus, those functions are declared in gdbthread.h/inferior.h. The actual iterators/ranges are mainly "internals" and thus are put out of view in the new thread-iter.h/thread-iter.c/inferior-iter.h files. That keeps the gdbthread.h/inferior.h headers quite a bit more readable. A common/safe-iterator.h header is added which adds a template that can be used to build "safe" iterators, which are forward iterators that can be used to replace the ALL_THREADS_SAFE macro and other instances of the same idiom in future. There's a little bit of shuffling of code between gdbthread.h/thread.c/inferior.h in the patch. That is necessary in order to avoid circular dependencies between the gdbthread.h/inferior.h headers. As for the init_thread_list calls sprinkled around, they're all eliminated by this patch, and a new, central call is added to inferior_appeared. Note how also related to that, there's a call to init_wait_for_inferior in remote.c that is eliminated. init_wait_for_inferior is currently responsible for discarding skipped inline frames, which had to be moved elsewhere. Given that nowadays we always have a thread even for single-threaded processes, the natural place is to delete a frame's inline frame info when we delete the thread. I.e., from clear_thread_inferior_resources. gdb/ChangeLog: 2018-11-22 Pedro Alves <palves@redhat.com> * Makefile.in (COMMON_SFILES): Add thread-iter.c. * breakpoint.c (breakpoints_should_be_inserted_now): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (print_one_breakpoint_location): Replace ALL_INFERIORS with all_inferiors. * bsd-kvm.c: Include inferior.h. * btrace.c (btrace_free_objfile): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * common/filtered-iterator.h: New. * common/safe-iterator.h: New. * corelow.c (core_target_open): Don't call init_thread_list here. * darwin-nat.c (thread_info_from_private_thread_info): Replace ALL_THREADS with all_threads. * fbsd-nat.c (fbsd_nat_target::resume): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fbsd-tdep.c (fbsd_make_corefile_notes): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fork-child.c (postfork_hook): Don't call init_thread_list here. * gdbarch-selftests.c (register_to_value_test): Adjust. * gdbthread.h: Don't include "inferior.h" here. (struct inferior): Forward declare. (enum step_over_calls_kind): Moved here from inferior.h. (thread_info::deletable): Definition moved to thread.c. (find_thread_ptid (inferior *, ptid_t)): Declare. (ALL_THREADS, ALL_THREADS_BY_INFERIOR, ALL_THREADS_SAFE): Delete. Include "thread-iter.h". (all_threads, all_non_exited_threads, all_threads_safe): New. (any_thread_p): Declare. (thread_list): Delete. * infcmd.c (signal_command): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (proceed_after_attach_callback): Delete. (proceed_after_attach): Take an inferior pointer instead of an integer PID. Adjust to use range-for. (attach_post_wait): Pass down inferior pointer instead of pid. Use range-for instead of ALL_NON_EXITED_THREADS. (detach_command): Remove init_thread_list call. * inferior-iter.h: New. * inferior.c (struct delete_thread_of_inferior_arg): Delete. (delete_thread_of_inferior): Delete. (delete_inferior, exit_inferior_1): Use range-for with inf->threads_safe() instead of iterate_over_threads. (inferior_appeared): Call init_thread_list here. (discard_all_inferiors): Use all_non_exited_inferiors. (find_inferior_id, find_inferior_pid): Use all_inferiors. (iterate_over_inferiors): Use all_inferiors_safe. (have_inferiors, number_of_live_inferiors): Use all_non_exited_inferiors. (number_of_inferiors): Use all_inferiors and std::distance. (print_inferior): Use all_inferiors. * inferior.h: Include gdbthread.h. (enum step_over_calls_kind): Moved to gdbthread.h. (struct inferior) <thread_list>: New field. <threads, non_exited_threads, threads_safe>: New methods. (ALL_INFERIORS): Delete. Include "inferior-iter.h". (ALL_NON_EXITED_INFERIORS): Delete. (all_inferiors_safe, all_inferiors, all_non_exited_inferiors): New functions. * inflow.c (child_interrupt, child_pass_ctrlc): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * infrun.c (follow_exec): Use all_threads_safe. (clear_proceed_status, proceed): Use all_non_exited_threads. (init_wait_for_inferior): Don't clear inline frame state here. (infrun_thread_stop_requested, for_each_just_stopped_thread): Use all_threads instead of ALL_NON_EXITED_THREADS. (random_pending_event_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use a lambda for repeated code. (clean_up_just_stopped_threads_fsms): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (handle_no_resumed): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use all_inferiors instead of ALL_INFERIORS. (restart_threads, switch_back_to_stepped_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-nat.c (check_zombie_leaders): Replace ALL_INFERIORS with all_inferiors. (kill_unfollowed_fork_children): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-tdep.c (linux_make_corefile_notes): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-thread-db.c (thread_db_target::update_thread_list): Replace ALL_INFERIORS with all_inferiors. (thread_db_target::thread_handle_to_thread_info): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * mi/mi-interp.c (multiple_inferiors_p): New. (mi_on_resume_1): Simplify using all_non_exited_threads and multiple_inferiors_p. * mi/mi-main.c (mi_cmd_thread_list_ids): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * nto-procfs.c (nto_procfs_target::open): Don't call init_thread_list here. * record-btrace.c (record_btrace_target_open) (record_btrace_target::stop_recording) (record_btrace_target::close) (record_btrace_target::record_is_replaying) (record_btrace_target::resume, record_btrace_target::wait) (record_btrace_target::record_stop_replaying): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * record-full.c (record_full_wait_1): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * regcache.c (cooked_read_test): Remove reference to global thread_list. * remote-sim.c (gdbsim_target::create_inferior): Don't call init_thread_list here. * remote.c (remote_target::update_thread_list): Use all_threads_safe instead of ALL_NON_EXITED_THREADS. (remote_target::process_initial_stop_replies): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::open_1): Don't call init_thread_list here. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::commit_resume) (remote_target::remove_new_fork_children): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::kill_new_fork_children): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Remove init_thread_list and init_wait_for_inferior calls. (remote_target::remote_btrace_maybe_reopen) (remote_target::thread_handle_to_thread_info): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * target.c (target_terminal::restore_inferior) (target_terminal_is_ours_kind): Replace ALL_INFERIORS with all_non_exited_inferiors. * thread-iter.c: New file. * thread-iter.h: New file. * thread.c: Include "inline-frame.h". (thread_list): Delete. (clear_thread_inferior_resources): Call clear_inline_frame_state. (init_thread_list): Use all_threads_safe instead of ALL_THREADS_SAFE. Adjust to per-inferior thread lists. (new_thread): Adjust to per-inferior thread lists. (add_thread_silent): Pass inferior to find_thread_ptid. (thread_info::deletable): New, moved from the header. (delete_thread_1): Adjust to per-inferior thread lists. (find_thread_global_id): Use inf->threads(). (find_thread_ptid): Use find_inferior_ptid and pass inferior to find_thread_ptid. (find_thread_ptid(inferior*, ptid_t)): New overload. (iterate_over_threads): Use all_threads_safe. (any_thread_p): New. (thread_count): Use all_threads and std::distance. (live_threads_count): Use all_non_exited_threads and std::distance. (valid_global_thread_id): Use all_threads. (in_thread_list): Use find_thread_ptid. (first_thread_of_inferior): Adjust to per-inferior thread lists. (any_thread_of_inferior, any_live_thread_of_inferior): Use inf->non_exited_threads(). (prune_threads, delete_exited_threads): Use all_threads_safe. (thread_change_ptid): Pass inferior pointer to find_thread_ptid. (set_resumed, set_running): Use all_non_exited_threads. (is_thread_state, is_stopped, is_exited, is_running) (is_executing): Delete. (set_executing, set_stop_requested, finish_thread_state): Use all_non_exited_threads. (print_thread_info_1): Use all_inferiors and all_threads. (thread_apply_all_command): Use all_non_exited_threads. (thread_find_command): Use all_threads. (update_threads_executing): Use all_non_exited_threads. * tid-parse.c (parse_thread_id): Use inf->threads. * x86-bsd-nat.c (x86bsd_dr_set): Use inf->non_exited_threads ().
2018-11-22 17:09:14 +01:00
for (inferior *inf : all_inferiors_safe ())
if (some_condition ())
delete inf;
*/
inline all_inferiors_safe_range
all_inferiors_safe ()
{
return {};
}
/* Returns a range representing all inferiors, suitable to use with
range-for, like this:
for (inferior *inf : all_inferiors ())
[...]
*/
inline all_inferiors_range
Multi-target support This commit adds multi-target support to GDB. What this means is that with this commit, GDB can now be connected to different targets at the same time. E.g., you can debug a live native process and a core dump at the same time, connect to multiple gdbservers, etc. Actually, the word "target" is overloaded in gdb. We already have a target stack, with pushes several target_ops instances on top of one another. We also have "info target" already, which means something completely different to what this patch does. So from here on, I'll be using the "target connections" term, to mean an open process_stratum target, pushed on a target stack. This patch makes gdb have multiple target stacks, and multiple process_stratum targets open simultaneously. The user-visible changes / commands will also use this terminology, but of course it's all open to debate. User-interface-wise, not that much changes. The main difference is that each inferior may have its own target connection. A target connection (e.g., a target extended-remote connection) may support debugging multiple processes, just as before. Say you're debugging against gdbserver in extended-remote mode, and you do "add-inferior" to prepare to spawn a new process, like: (gdb) target extended-remote :9999 ... (gdb) start ... (gdb) add-inferior Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) file a.out ... (gdb) start ... At this point, you have two inferiors connected to the same gdbserver. With this commit, GDB will maintain a target stack per inferior, instead of a global target stack. To preserve the behavior above, by default, "add-inferior" makes the new inferior inherit a copy of the target stack of the current inferior. Same across a fork - the child inherits a copy of the target stack of the parent. While the target stacks are copied, the targets themselves are not. Instead, target_ops is made a refcounted_object, which means that target_ops instances are refcounted, which each inferior counting for a reference. What if you want to create an inferior and connect it to some _other_ target? For that, this commit introduces a new "add-inferior -no-connection" option that makes the new inferior not share the current inferior's target. So you could do: (gdb) target extended-remote :9999 Remote debugging using :9999 ... (gdb) add-inferior -no-connection [New inferior 2] Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 <null> (gdb) tar extended-remote :10000 Remote debugging using :10000 ... (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 process 18450 target:/home/pedro/tmp/main (gdb) A following patch will extended "info inferiors" to include a column indicating which connection an inferior is bound to, along with a couple other UI tweaks. Other than that, debugging is the same as before. Users interact with inferiors and threads as before. The only difference is that inferiors may be bound to processes running in different machines. That's pretty much all there is to it in terms of noticeable UI changes. On to implementation. Since we can be connected to different systems at the same time, a ptid_t is no longer a unique identifier. Instead a thread can be identified by a pair of ptid_t and 'process_stratum_target *', the later being the instance of the process_stratum target that owns the process/thread. Note that process_stratum_target inherits from target_ops, and all process_stratum targets inherit from process_stratum_target. In earlier patches, many places in gdb were converted to refer to threads by thread_info pointer instead of ptid_t, but there are still places in gdb where we start with a pid/tid and need to find the corresponding inferior or thread_info objects. So you'll see in the patch many places adding a process_stratum_target parameter to functions that used to take only a ptid_t. Since each inferior has its own target stack now, we can always find the process_stratum target for an inferior. That is done via a inf->process_target() convenience method. Since each inferior has its own target stack, we need to handle the "beneath" calls when servicing target calls. The solution I settled with is just to make sure to switch the current inferior to the inferior you want before making a target call. Not relying on global context is just not feasible in current GDB. Fortunately, there aren't that many places that need to do that, because generally most code that calls target methods already has the current context pointing to the right inferior/thread. Note, to emphasize -- there's no method to "switch to this target stack". Instead, you switch the current inferior, and that implicitly switches the target stack. In some spots, we need to iterate over all inferiors so that we reach all target stacks. Native targets are still singletons. There's always only a single instance of such targets. Remote targets however, we'll have one instance per remote connection. The exec target is still a singleton. There's only one instance. I did not see the point of instanciating more than one exec_target object. After vfork, we need to make sure to push the exec target on the new inferior. See exec_on_vfork. For type safety, functions that need a {target, ptid} pair to identify a thread, take a process_stratum_target pointer for target parameter instead of target_ops *. Some shared code in gdb/nat/ also need to gain a target pointer parameter. This poses an issue, since gdbserver doesn't have process_stratum_target, only target_ops. To fix this, this commit renames gdbserver's target_ops to process_stratum_target. I think this makes sense. There's no concept of target stack in gdbserver, and gdbserver's target_ops really implements a process_stratum-like target. The thread and inferior iterator functions also gain process_stratum_target parameters. These are used to be able to iterate over threads and inferiors of a given target. Following usual conventions, if the target pointer is null, then we iterate over threads and inferiors of all targets. I tried converting "add-inferior" to the gdb::option framework, as a preparatory patch, but that stumbled on the fact that gdb::option does not support file options yet, for "add-inferior -exec". I have a WIP patchset that adds that, but it's not a trivial patch, mainly due to need to integrate readline's filename completion, so I deferred that to some other time. In infrun.c/infcmd.c, the main change is that we need to poll events out of all targets. See do_target_wait. Right after collecting an event, we switch the current inferior to an inferior bound to the target that reported the event, so that target methods can be used while handling the event. This makes most of the code transparent to multi-targets. See fetch_inferior_event. infrun.c:stop_all_threads is interesting -- in this function we need to stop all threads of all targets. What the function does is send an asynchronous stop request to all threads, and then synchronously waits for events, with target_wait, rinse repeat, until all it finds are stopped threads. Now that we have multiple targets, it's not efficient to synchronously block in target_wait waiting for events out of one target. Instead, we implement a mini event loop, with interruptible_select, select'ing on one file descriptor per target. For this to work, we need to be able to ask the target for a waitable file descriptor. Such file descriptors already exist, they are the descriptors registered in the main event loop with add_file_handler, inside the target_async implementations. This commit adds a new target_async_wait_fd target method that just returns the file descriptor in question. See wait_one / stop_all_threads in infrun.c. The 'threads_executing' global is made a per-target variable. Since it is only relevant to process_stratum_target targets, this is where it is put, instead of in target_ops. You'll notice that remote.c includes some FIXME notes. These refer to the fact that the global arrays that hold data for the remote packets supported are still globals. For example, if we connect to two different servers/stubs, then each might support different remote protocol features. They might even be different architectures, like e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a host/controller scenario as a single program. That isn't going to work correctly today, because of said globals. I'm leaving fixing that for another pass, since it does not appear to be trivial, and I'd rather land the base work first. It's already useful to be able to debug multiple instances of the same server (e.g., a distributed cluster, where you have full control over the servers installed), so I think as is it's already reasonable incremental progress. Current limitations: - You can only resume more that one target at the same time if all targets support asynchronous debugging, and support non-stop mode. It should be possible to support mixed all-stop + non-stop backends, but that is left for another time. This means that currently in order to do multi-target with gdbserver you need to issue "maint set target-non-stop on". I would like to make that mode be the default, but we're not there yet. Note that I'm talking about how the target backend works, only. User-visible all-stop mode works just fine. - As explained above, connecting to different remote servers at the same time is likely to produce bad results if they don't support the exact set of RSP features. FreeBSD updates courtesy of John Baldwin. gdb/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> John Baldwin <jhb@FreeBSD.org> * aarch64-linux-nat.c (aarch64_linux_nat_target::thread_architecture): Adjust. * ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call. (task_command_1): Likewise. * aix-thread.c (sync_threadlists, aix_thread_target::resume) (aix_thread_target::wait, aix_thread_target::fetch_registers) (aix_thread_target::store_registers) (aix_thread_target::thread_alive): Adjust. * amd64-fbsd-tdep.c: Include "inferior.h". (amd64fbsd_get_thread_local_address): Pass down target. * amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle thread's gdbarch instead of target_gdbarch. * break-catch-sig.c (signal_catchpoint_print_it): Adjust call to get_last_target_status. * break-catch-syscall.c (print_it_catch_syscall): Likewise. * breakpoint.c (breakpoints_should_be_inserted_now): Consider all inferiors. (update_inserted_breakpoint_locations): Skip if inferiors with no execution. (update_global_location_list): When handling moribund locations, find representative inferior for location's pspace, and use thread count of its process_stratum target. * bsd-kvm.c (bsd_kvm_target_open): Pass target down. * bsd-uthread.c (bsd_uthread_target::wait): Use as_process_stratum_target and adjust thread_change_ptid and add_thread calls. (bsd_uthread_target::update_thread_list): Use as_process_stratum_target and adjust find_thread_ptid, thread_change_ptid and add_thread calls. * btrace.c (maint_btrace_packet_history_cmd): Adjust find_thread_ptid call. * corelow.c (add_to_thread_list): Adjust add_thread call. (core_target_open): Adjust add_thread_silent and thread_count calls. (core_target::pid_to_str): Adjust find_inferior_ptid call. * ctf.c (ctf_target_open): Adjust add_thread_silent call. * event-top.c (async_disconnect): Pop targets from all inferiors. * exec.c (add_target_sections): Push exec target on all inferiors sharing the program space. (remove_target_sections): Remove the exec target from all inferiors sharing the program space. (exec_on_vfork): New. * exec.h (exec_on_vfork): Declare. * fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::update_thread_list): Adjust. (fbsd_nat_target::resume): Adjust. (fbsd_handle_debug_trap): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust. * fbsd-tdep.c (fbsd_corefile_thread): Adjust get_thread_arch_regcache call. * fork-child.c (gdb_startup_inferior): Pass target down to startup_inferior and set_executing. * gdbthread.h (struct process_stratum_target): Forward declare. (add_thread, add_thread_silent, add_thread_with_info) (in_thread_list): Add process_stratum_target parameter. (find_thread_ptid(inferior*, ptid_t)): New overload. (find_thread_ptid, thread_change_ptid): Add process_stratum_target parameter. (all_threads()): Delete overload. (all_threads, all_non_exited_threads): Add process_stratum_target parameter. (all_threads_safe): Use brace initialization. (thread_count): Add process_stratum_target parameter. (set_resumed, set_running, set_stop_requested, set_executing) (threads_are_executing, finish_thread_state): Add process_stratum_target parameter. (switch_to_thread): Use is_current_thread. * i386-fbsd-tdep.c: Include "inferior.h". (i386fbsd_get_thread_local_address): Pass down target. * i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust. * inf-child.c (inf_child_target::maybe_unpush_target): Remove have_inferiors check. * inf-ptrace.c (inf_ptrace_target::create_inferior) (inf_ptrace_target::attach): Adjust. * infcall.c (run_inferior_call): Adjust. * infcmd.c (run_command_1): Pass target to scoped_finish_thread_state. (proceed_thread_callback): Skip inferiors with no execution. (continue_command): Rename 'all_threads' local to avoid hiding 'all_threads' function. Adjust get_last_target_status call. (prepare_one_step): Adjust set_running call. (signal_command): Use user_visible_resume_target. Compare thread pointers instead of inferior_ptid. (info_program_command): Adjust to pass down target. (attach_command): Mark target's 'thread_executing' flag. (stop_current_target_threads_ns): New, factored out from ... (interrupt_target_1): ... this. Switch inferior before making target calls. * inferior-iter.h (struct all_inferiors_iterator, struct all_inferiors_range) (struct all_inferiors_safe_range) (struct all_non_exited_inferiors_range): Filter on process_stratum_target too. Remove explicit. * inferior.c (inferior::inferior): Push dummy target on target stack. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors): Add process_stratum_target parameter, and pass it down. (have_live_inferiors): Adjust. (switch_to_inferior_and_push_target): New. (add_inferior_command, clone_inferior_command): Handle "-no-connection" parameter. Use switch_to_inferior_and_push_target. (_initialize_inferior): Mention "-no-connection" option in the help of "add-inferior" and "clone-inferior" commands. * inferior.h: Include "process-stratum-target.h". (interrupt_target_1): Use bool. (struct inferior) <push_target, unpush_target, target_is_pushed, find_target_beneath, top_target, process_target, target_at, m_stack>: New. (discard_all_inferiors): Delete. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors) (all_inferiors, all_non_exited_inferiors): Add process_stratum_target parameter. * infrun.c: Include "gdb_select.h" and <unordered_map>. (target_last_proc_target): New global. (follow_fork_inferior): Push target on new inferior. Pass target to add_thread_silent. Call exec_on_vfork. Handle target's reference count. (follow_fork): Adjust get_last_target_status call. Also consider target. (follow_exec): Push target on new inferior. (struct execution_control_state) <target>: New field. (user_visible_resume_target): New. (do_target_resume): Call target_async. (resume_1): Set target's threads_executing flag. Consider resume target. (commit_resume_all_targets): New. (proceed): Also consider resume target. Skip threads of inferiors with no execution. Commit resumtion in all targets. (start_remote): Pass current inferior to wait_for_inferior. (infrun_thread_stop_requested): Consider target as well. Pass thread_info pointer to clear_inline_frame_state instead of ptid. (infrun_thread_thread_exit): Consider target as well. (random_pending_event_thread): New inferior parameter. Use it. (do_target_wait): Rename to ... (do_target_wait_1): ... this. Add inferior parameter, and pass it down. (threads_are_resumed_pending_p, do_target_wait): New. (prepare_for_detach): Adjust calls. (wait_for_inferior): New inferior parameter. Handle it. Use do_target_wait_1 instead of do_target_wait. (fetch_inferior_event): Adjust. Switch to representative inferior. Pass target down. (set_last_target_status): Add process_stratum_target parameter. Save target in global. (get_last_target_status): Add process_stratum_target parameter and handle it. (nullify_last_target_wait_ptid): Clear 'target_last_proc_target'. (context_switch): Check inferior_ptid == null_ptid before calling inferior_thread(). (get_inferior_stop_soon): Pass down target. (wait_one): Rename to ... (poll_one_curr_target): ... this. (struct wait_one_event): New. (wait_one): New. (stop_all_threads): Adjust. (handle_no_resumed, handle_inferior_event): Adjust to consider the event's target. (switch_back_to_stepped_thread): Also consider target. (print_stop_event): Update. (normal_stop): Update. Also consider the resume target. * infrun.h (wait_for_inferior): Remove declaration. (user_visible_resume_target): New declaration. (get_last_target_status, set_last_target_status): New process_stratum_target parameter. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter, and use it. (clear_inline_frame_state (thread_info*)): New. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter. (clear_inline_frame_state (thread_info*)): Declare. * linux-fork.c (delete_checkpoint_command): Pass target down to find_thread_ptid. (checkpoint_command): Adjust. * linux-nat.c (linux_nat_target::follow_fork): Switch to thread instead of just tweaking inferior_ptid. (linux_nat_switch_fork): Pass target down to thread_change_ptid. (exit_lwp): Pass target down to find_thread_ptid. (attach_proc_task_lwp_callback): Pass target down to add_thread/set_running/set_executing. (linux_nat_target::attach): Pass target down to thread_change_ptid. (get_detach_signal): Pass target down to find_thread_ptid. Consider last target status's target. (linux_resume_one_lwp_throw, resume_lwp) (linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp) (stop_wait_callback, save_stop_reason, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down. (linux_nat_target::async_wait_fd): New. (linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass target down. * linux-nat.h (linux_nat_target::async_wait_fd): Declare. * linux-tdep.c (get_thread_arch_regcache): Pass target down. * linux-thread-db.c (struct thread_db_info::process_target): New field. (add_thread_db_info): Save target. (get_thread_db_info): New process_stratum_target parameter. Also match target. (delete_thread_db_info): New process_stratum_target parameter. Also match target. (thread_from_lwp): Adjust to pass down target. (thread_db_notice_clone): Pass down target. (check_thread_db_callback): Pass down target. (try_thread_db_load_1): Always push the thread_db target. (try_thread_db_load, record_thread): Pass target down. (thread_db_target::detach): Pass target down. Always unpush the thread_db target. (thread_db_target::wait, thread_db_target::mourn_inferior): Pass target down. Always unpush the thread_db target. (find_new_threads_callback, thread_db_find_new_threads_2) (thread_db_target::update_thread_list): Pass target down. (thread_db_target::pid_to_str): Pass current inferior down. (thread_db_target::get_thread_local_address): Pass target down. (thread_db_target::resume, maintenance_check_libthread_db): Pass target down. * nto-procfs.c (nto_procfs_target::update_thread_list): Adjust. * procfs.c (procfs_target::procfs_init_inferior): Declare. (proc_set_current_signal, do_attach, procfs_target::wait): Adjust. (procfs_init_inferior): Rename to ... (procfs_target::procfs_init_inferior): ... this and adjust. (procfs_target::create_inferior, procfs_notice_thread) (procfs_do_thread_registers): Adjust. * ppc-fbsd-tdep.c: Include "inferior.h". (ppcfbsd_get_thread_local_address): Pass down target. * proc-service.c (ps_xfer_memory): Switch current inferior and program space as well. (get_ps_regcache): Pass target down. * process-stratum-target.c (process_stratum_target::thread_address_space) (process_stratum_target::thread_architecture): Pass target down. * process-stratum-target.h (process_stratum_target::threads_executing): New field. (as_process_stratum_target): New. * ravenscar-thread.c (ravenscar_thread_target::update_inferior_ptid): Pass target down. (ravenscar_thread_target::wait, ravenscar_add_thread): Pass target down. * record-btrace.c (record_btrace_target::info_record): Adjust. (record_btrace_target::record_method) (record_btrace_target::record_is_replaying) (record_btrace_target::fetch_registers) (get_thread_current_frame_id, record_btrace_target::resume) (record_btrace_target::wait, record_btrace_target::stop): Pass target down. * record-full.c (record_full_wait_1): Switch to event thread. Pass target down. * regcache.c (regcache::regcache) (get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add process_stratum_target parameter and handle it. (current_thread_target): New global. (get_thread_regcache): Add process_stratum_target parameter and handle it. Switch inferior before calling target method. (get_thread_regcache): Pass target down. (get_thread_regcache_for_ptid): Pass target down. (registers_changed_ptid): Add process_stratum_target parameter and handle it. (registers_changed_thread, registers_changed): Pass target down. (test_get_thread_arch_aspace_regcache): New. (current_regcache_test): Define a couple local test_target_ops instances and use them for testing. (readwrite_regcache): Pass process_stratum_target parameter. (cooked_read_test, cooked_write_test): Pass mock_target down. * regcache.h (get_thread_regcache, get_thread_arch_regcache) (get_thread_arch_aspace_regcache): Add process_stratum_target parameter. (regcache::target): New method. (regcache::regcache, regcache::get_thread_arch_aspace_regcache) (regcache::registers_changed_ptid): Add process_stratum_target parameter. (regcache::m_target): New field. (registers_changed_ptid): Add process_stratum_target parameter. * remote.c (remote_state::supports_vCont_probed): New field. (remote_target::async_wait_fd): New method. (remote_unpush_and_throw): Add remote_target parameter. (get_current_remote_target): Adjust. (remote_target::remote_add_inferior): Push target. (remote_target::remote_add_thread) (remote_target::remote_notice_new_inferior) (get_remote_thread_info): Pass target down. (remote_target::update_thread_list): Skip threads of inferiors bound to other targets. (remote_target::close): Don't discard inferiors. (remote_target::add_current_inferior_and_thread) (remote_target::process_initial_stop_replies) (remote_target::start_remote) (remote_target::remote_serial_quit_handler): Pass down target. (remote_target::remote_unpush_target): New remote_target parameter. Unpush the target from all inferiors. (remote_target::remote_unpush_and_throw): New remote_target parameter. Pass it down. (remote_target::open_1): Check whether the current inferior has execution instead of checking whether any inferior is live. Pass target down. (remote_target::remote_detach_1): Pass down target. Use remote_unpush_target. (extended_remote_target::attach): Pass down target. (remote_target::remote_vcont_probe): Set supports_vCont_probed. (remote_target::append_resumption): Pass down target. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc, remote_target::resume) (remote_target::commit_resume): Pass down target. (remote_target::remote_stop_ns): Check supports_vCont_probed. (remote_target::interrupt_query) (remote_target::remove_new_fork_children) (remote_target::check_pending_events_prevent_wildcard_vcont) (remote_target::remote_parse_stop_reply) (remote_target::process_stop_reply): Pass down target. (first_remote_resumed_thread): New remote_target parameter. Pass it down. (remote_target::wait_as): Pass down target. (unpush_and_perror): New remote_target parameter. Pass it down. (remote_target::readchar, remote_target::remote_serial_write) (remote_target::getpkt_or_notif_sane_1) (remote_target::kill_new_fork_children, remote_target::kill): Pass down target. (remote_target::mourn_inferior): Pass down target. Use remote_unpush_target. (remote_target::core_of_thread) (remote_target::remote_btrace_maybe_reopen): Pass down target. (remote_target::pid_to_exec_file) (remote_target::thread_handle_to_thread_info): Pass down target. (remote_target::async_wait_fd): New. * riscv-fbsd-tdep.c: Include "inferior.h". (riscv_fbsd_get_thread_local_address): Pass down target. * sol2-tdep.c (sol2_core_pid_to_str): Pass down target. * sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs) (ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback): Adjust. * solib-spu.c (spu_skip_standalone_loader): Pass down target. * solib-svr4.c (enable_break): Pass down target. * spu-multiarch.c (parse_spufs_run): Pass down target. * spu-tdep.c (spu2ppu_sniffer): Pass down target. * target-delegates.c: Regenerate. * target.c (g_target_stack): Delete. (current_top_target): Return the current inferior's top target. (target_has_execution_1): Refer to the passed-in inferior's top target. (target_supports_terminal_ours): Check whether the initial inferior was already created. (decref_target): New. (target_stack::push): Incref/decref the target. (push_target, push_target, unpush_target): Adjust. (target_stack::unpush): Defref target. (target_is_pushed): Return bool. Adjust to refer to the current inferior's target stack. (dispose_inferior): Delete, and inline parts ... (target_preopen): ... here. Only dispose of the current inferior. (target_detach): Hold strong target reference while detaching. Pass target down. (target_thread_name): Add assertion. (target_resume): Pass down target. (target_ops::beneath, find_target_at): Adjust to refer to the current inferior's target stack. (get_dummy_target): New. (target_pass_ctrlc): Pass the Ctrl-C to the first inferior that has a thread running. (initialize_targets): Rename to ... (_initialize_target): ... this. * target.h: Include "gdbsupport/refcounted-object.h". (struct target_ops): Inherit refcounted_object. (target_ops::shortname, target_ops::longname): Make const. (target_ops::async_wait_fd): New method. (decref_target): Declare. (struct target_ops_ref_policy): New. (target_ops_ref): New typedef. (get_dummy_target): Declare function. (target_is_pushed): Return bool. * thread-iter.c (all_matching_threads_iterator::m_inf_matches) (all_matching_threads_iterator::all_matching_threads_iterator): Handle filter target. * thread-iter.h (struct all_matching_threads_iterator, struct all_matching_threads_range, class all_non_exited_threads_range): Filter by target too. Remove explicit. * thread.c (threads_executing): Delete. (inferior_thread): Pass down current inferior. (clear_thread_inferior_resources): Pass down thread pointer instead of ptid_t. (add_thread_silent, add_thread_with_info, add_thread): Add process_stratum_target parameter. Use it for thread and inferior searches. (is_current_thread): New. (thread_info::deletable): Use it. (find_thread_ptid, thread_count, in_thread_list) (thread_change_ptid, set_resumed, set_running): New process_stratum_target parameter. Pass it down. (set_executing): New process_stratum_target parameter. Pass it down. Adjust reference to 'threads_executing'. (threads_are_executing): New process_stratum_target parameter. Adjust reference to 'threads_executing'. (set_stop_requested, finish_thread_state): New process_stratum_target parameter. Pass it down. (switch_to_thread): Also match inferior. (switch_to_thread): New process_stratum_target parameter. Pass it down. (update_threads_executing): Reimplement. * top.c (quit_force): Pop targets from all inferior. (gdb_init): Don't call initialize_targets. * windows-nat.c (windows_nat_target) <get_windows_debug_event>: Declare. (windows_add_thread, windows_delete_thread): Adjust. (get_windows_debug_event): Rename to ... (windows_nat_target::get_windows_debug_event): ... this. Adjust. * tracefile-tfile.c (tfile_target_open): Pass down target. * gdbsupport/common-gdbthread.h (struct process_stratum_target): Forward declare. (switch_to_thread): Add process_stratum_target parameter. * mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target parameter. Use it. (mi_on_resume): Pass target down. * nat/fork-inferior.c (startup_inferior): Add process_stratum_target parameter. Pass it down. * nat/fork-inferior.h (startup_inferior): Add process_stratum_target parameter. * python/py-threadevent.c (py_get_event_thread): Pass target down. gdb/gdbserver/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> * fork-child.c (post_fork_inferior): Pass target down to startup_inferior. * inferiors.c (switch_to_thread): Add process_stratum_target parameter. * lynx-low.c (lynx_target_ops): Now a process_stratum_target. * nto-low.c (nto_target_ops): Now a process_stratum_target. * linux-low.c (linux_target_ops): Now a process_stratum_target. * remote-utils.c (prepare_resume_reply): Pass the target to switch_to_thread. * target.c (the_target): Now a process_stratum_target. (done_accessing_memory): Pass the target to switch_to_thread. (set_target_ops): Ajust to use process_stratum_target. * target.h (struct target_ops): Rename to ... (struct process_stratum_target): ... this. (the_target, set_target_ops): Adjust. (prepare_to_access_memory): Adjust comment. * win32-low.c (child_xfer_memory): Adjust to use process_stratum_target. (win32_target_ops): Now a process_stratum_target.
2020-01-10 21:06:08 +01:00
all_inferiors (process_stratum_target *proc_target = nullptr)
Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc. As preparation for multi-target, this patch makes each inferior have its own thread list. This isn't absolutely necessary for multi-target, but simplifies things. It originally stemmed from the desire to eliminate the init_thread_list calls sprinkled around, plus it makes it more efficient to iterate over threads of a given inferior (no need to always iterate over threads of all inferiors). We still need to iterate over threads of all inferiors in a number of places, which means we'd need adjust the ALL_THREADS / ALL_NON_EXITED_THREADS macros. However, naively tweaking those macros to have an extra for loop, like: #define ALL_THREADS (thr, inf) \ for (inf = inferior_list; inf; inf = inf->next) \ for (thr = inf->thread_list; thr; thr = thr->next) causes problems with code that does "break" or "continue" within the ALL_THREADS loop body. Plus, we need to declare the extra "inf" local variable in order to pass it as temporary variable to ALL_THREADS (etc.) It gets even trickier when we consider extending the macros to filter out threads matching a ptid_t and a target. The macros become tricker to read/write. Been there. An alternative (which was my next attempt), is to replace the ALL_THREADS etc. iteration style with for_each_all_threads, for_each_non_exited_threads, etc. functions which would take a callback as parameter, which would usually be passed a lambda. However, I did not find that satisfactory at all, because the resulting code ends up a little less natural / more noisy to read, write and debug/step-through (due to use of lambdas), and in many places where we use "continue;" to skip to the next thread now need to use "return;". (I ran into hard to debug bugs caused by a continue/return confusion.) I.e., before: ALL_NON_EXITED_THREADS (tp) { if (tp->not_what_I_want) continue; // do something } would turn into: for_each_non_exited_thread ([&] (thread_info *tp) { if (tp->not_what_I_want) return; // do something }); Lastly, the solution I settled with was to replace the ALL_THREADS / ALL_NON_EXITED_THREADS / ALL_INFERIORS macros with (C++20-like) ranges and iterators, such that you can instead naturaly iterate over threads/inferiors using range-for, like e.g,.: // all threads, including THREAD_EXITED threads. for (thread_info *tp : all_threads ()) { .... } // all non-exited threads. for (thread_info *tp : all_non_exited_threads ()) { .... } // all non-exited threads of INF inferior. for (thread_info *tp : inf->non_exited_threads ()) { .... } The all_non_exited_threads() function takes an optional filter ptid_t as parameter, which is quite convenient when we need to iterate over threads matching that filter. See e.g., how the set_executing/set_stop_requested/finish_thread_state etc. functions in thread.c end up being simplified. Most of the patch thus is about adding the infrustructure for allowing the above. Later on when we get to actual multi-target, these functions/ranges/iterators will gain a "target_ops *" parameter so that e.g., we can iterate over all threads of a given target that match a given filter ptid_t. The only entry points users needs to be aware of are the all_threads/all_non_exited_threads etc. functions seen above. Thus, those functions are declared in gdbthread.h/inferior.h. The actual iterators/ranges are mainly "internals" and thus are put out of view in the new thread-iter.h/thread-iter.c/inferior-iter.h files. That keeps the gdbthread.h/inferior.h headers quite a bit more readable. A common/safe-iterator.h header is added which adds a template that can be used to build "safe" iterators, which are forward iterators that can be used to replace the ALL_THREADS_SAFE macro and other instances of the same idiom in future. There's a little bit of shuffling of code between gdbthread.h/thread.c/inferior.h in the patch. That is necessary in order to avoid circular dependencies between the gdbthread.h/inferior.h headers. As for the init_thread_list calls sprinkled around, they're all eliminated by this patch, and a new, central call is added to inferior_appeared. Note how also related to that, there's a call to init_wait_for_inferior in remote.c that is eliminated. init_wait_for_inferior is currently responsible for discarding skipped inline frames, which had to be moved elsewhere. Given that nowadays we always have a thread even for single-threaded processes, the natural place is to delete a frame's inline frame info when we delete the thread. I.e., from clear_thread_inferior_resources. gdb/ChangeLog: 2018-11-22 Pedro Alves <palves@redhat.com> * Makefile.in (COMMON_SFILES): Add thread-iter.c. * breakpoint.c (breakpoints_should_be_inserted_now): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (print_one_breakpoint_location): Replace ALL_INFERIORS with all_inferiors. * bsd-kvm.c: Include inferior.h. * btrace.c (btrace_free_objfile): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * common/filtered-iterator.h: New. * common/safe-iterator.h: New. * corelow.c (core_target_open): Don't call init_thread_list here. * darwin-nat.c (thread_info_from_private_thread_info): Replace ALL_THREADS with all_threads. * fbsd-nat.c (fbsd_nat_target::resume): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fbsd-tdep.c (fbsd_make_corefile_notes): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fork-child.c (postfork_hook): Don't call init_thread_list here. * gdbarch-selftests.c (register_to_value_test): Adjust. * gdbthread.h: Don't include "inferior.h" here. (struct inferior): Forward declare. (enum step_over_calls_kind): Moved here from inferior.h. (thread_info::deletable): Definition moved to thread.c. (find_thread_ptid (inferior *, ptid_t)): Declare. (ALL_THREADS, ALL_THREADS_BY_INFERIOR, ALL_THREADS_SAFE): Delete. Include "thread-iter.h". (all_threads, all_non_exited_threads, all_threads_safe): New. (any_thread_p): Declare. (thread_list): Delete. * infcmd.c (signal_command): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (proceed_after_attach_callback): Delete. (proceed_after_attach): Take an inferior pointer instead of an integer PID. Adjust to use range-for. (attach_post_wait): Pass down inferior pointer instead of pid. Use range-for instead of ALL_NON_EXITED_THREADS. (detach_command): Remove init_thread_list call. * inferior-iter.h: New. * inferior.c (struct delete_thread_of_inferior_arg): Delete. (delete_thread_of_inferior): Delete. (delete_inferior, exit_inferior_1): Use range-for with inf->threads_safe() instead of iterate_over_threads. (inferior_appeared): Call init_thread_list here. (discard_all_inferiors): Use all_non_exited_inferiors. (find_inferior_id, find_inferior_pid): Use all_inferiors. (iterate_over_inferiors): Use all_inferiors_safe. (have_inferiors, number_of_live_inferiors): Use all_non_exited_inferiors. (number_of_inferiors): Use all_inferiors and std::distance. (print_inferior): Use all_inferiors. * inferior.h: Include gdbthread.h. (enum step_over_calls_kind): Moved to gdbthread.h. (struct inferior) <thread_list>: New field. <threads, non_exited_threads, threads_safe>: New methods. (ALL_INFERIORS): Delete. Include "inferior-iter.h". (ALL_NON_EXITED_INFERIORS): Delete. (all_inferiors_safe, all_inferiors, all_non_exited_inferiors): New functions. * inflow.c (child_interrupt, child_pass_ctrlc): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * infrun.c (follow_exec): Use all_threads_safe. (clear_proceed_status, proceed): Use all_non_exited_threads. (init_wait_for_inferior): Don't clear inline frame state here. (infrun_thread_stop_requested, for_each_just_stopped_thread): Use all_threads instead of ALL_NON_EXITED_THREADS. (random_pending_event_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use a lambda for repeated code. (clean_up_just_stopped_threads_fsms): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (handle_no_resumed): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use all_inferiors instead of ALL_INFERIORS. (restart_threads, switch_back_to_stepped_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-nat.c (check_zombie_leaders): Replace ALL_INFERIORS with all_inferiors. (kill_unfollowed_fork_children): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-tdep.c (linux_make_corefile_notes): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-thread-db.c (thread_db_target::update_thread_list): Replace ALL_INFERIORS with all_inferiors. (thread_db_target::thread_handle_to_thread_info): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * mi/mi-interp.c (multiple_inferiors_p): New. (mi_on_resume_1): Simplify using all_non_exited_threads and multiple_inferiors_p. * mi/mi-main.c (mi_cmd_thread_list_ids): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * nto-procfs.c (nto_procfs_target::open): Don't call init_thread_list here. * record-btrace.c (record_btrace_target_open) (record_btrace_target::stop_recording) (record_btrace_target::close) (record_btrace_target::record_is_replaying) (record_btrace_target::resume, record_btrace_target::wait) (record_btrace_target::record_stop_replaying): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * record-full.c (record_full_wait_1): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * regcache.c (cooked_read_test): Remove reference to global thread_list. * remote-sim.c (gdbsim_target::create_inferior): Don't call init_thread_list here. * remote.c (remote_target::update_thread_list): Use all_threads_safe instead of ALL_NON_EXITED_THREADS. (remote_target::process_initial_stop_replies): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::open_1): Don't call init_thread_list here. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::commit_resume) (remote_target::remove_new_fork_children): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::kill_new_fork_children): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Remove init_thread_list and init_wait_for_inferior calls. (remote_target::remote_btrace_maybe_reopen) (remote_target::thread_handle_to_thread_info): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * target.c (target_terminal::restore_inferior) (target_terminal_is_ours_kind): Replace ALL_INFERIORS with all_non_exited_inferiors. * thread-iter.c: New file. * thread-iter.h: New file. * thread.c: Include "inline-frame.h". (thread_list): Delete. (clear_thread_inferior_resources): Call clear_inline_frame_state. (init_thread_list): Use all_threads_safe instead of ALL_THREADS_SAFE. Adjust to per-inferior thread lists. (new_thread): Adjust to per-inferior thread lists. (add_thread_silent): Pass inferior to find_thread_ptid. (thread_info::deletable): New, moved from the header. (delete_thread_1): Adjust to per-inferior thread lists. (find_thread_global_id): Use inf->threads(). (find_thread_ptid): Use find_inferior_ptid and pass inferior to find_thread_ptid. (find_thread_ptid(inferior*, ptid_t)): New overload. (iterate_over_threads): Use all_threads_safe. (any_thread_p): New. (thread_count): Use all_threads and std::distance. (live_threads_count): Use all_non_exited_threads and std::distance. (valid_global_thread_id): Use all_threads. (in_thread_list): Use find_thread_ptid. (first_thread_of_inferior): Adjust to per-inferior thread lists. (any_thread_of_inferior, any_live_thread_of_inferior): Use inf->non_exited_threads(). (prune_threads, delete_exited_threads): Use all_threads_safe. (thread_change_ptid): Pass inferior pointer to find_thread_ptid. (set_resumed, set_running): Use all_non_exited_threads. (is_thread_state, is_stopped, is_exited, is_running) (is_executing): Delete. (set_executing, set_stop_requested, finish_thread_state): Use all_non_exited_threads. (print_thread_info_1): Use all_inferiors and all_threads. (thread_apply_all_command): Use all_non_exited_threads. (thread_find_command): Use all_threads. (update_threads_executing): Use all_non_exited_threads. * tid-parse.c (parse_thread_id): Use inf->threads. * x86-bsd-nat.c (x86bsd_dr_set): Use inf->non_exited_threads ().
2018-11-22 17:09:14 +01:00
{
Multi-target support This commit adds multi-target support to GDB. What this means is that with this commit, GDB can now be connected to different targets at the same time. E.g., you can debug a live native process and a core dump at the same time, connect to multiple gdbservers, etc. Actually, the word "target" is overloaded in gdb. We already have a target stack, with pushes several target_ops instances on top of one another. We also have "info target" already, which means something completely different to what this patch does. So from here on, I'll be using the "target connections" term, to mean an open process_stratum target, pushed on a target stack. This patch makes gdb have multiple target stacks, and multiple process_stratum targets open simultaneously. The user-visible changes / commands will also use this terminology, but of course it's all open to debate. User-interface-wise, not that much changes. The main difference is that each inferior may have its own target connection. A target connection (e.g., a target extended-remote connection) may support debugging multiple processes, just as before. Say you're debugging against gdbserver in extended-remote mode, and you do "add-inferior" to prepare to spawn a new process, like: (gdb) target extended-remote :9999 ... (gdb) start ... (gdb) add-inferior Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) file a.out ... (gdb) start ... At this point, you have two inferiors connected to the same gdbserver. With this commit, GDB will maintain a target stack per inferior, instead of a global target stack. To preserve the behavior above, by default, "add-inferior" makes the new inferior inherit a copy of the target stack of the current inferior. Same across a fork - the child inherits a copy of the target stack of the parent. While the target stacks are copied, the targets themselves are not. Instead, target_ops is made a refcounted_object, which means that target_ops instances are refcounted, which each inferior counting for a reference. What if you want to create an inferior and connect it to some _other_ target? For that, this commit introduces a new "add-inferior -no-connection" option that makes the new inferior not share the current inferior's target. So you could do: (gdb) target extended-remote :9999 Remote debugging using :9999 ... (gdb) add-inferior -no-connection [New inferior 2] Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 <null> (gdb) tar extended-remote :10000 Remote debugging using :10000 ... (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 process 18450 target:/home/pedro/tmp/main (gdb) A following patch will extended "info inferiors" to include a column indicating which connection an inferior is bound to, along with a couple other UI tweaks. Other than that, debugging is the same as before. Users interact with inferiors and threads as before. The only difference is that inferiors may be bound to processes running in different machines. That's pretty much all there is to it in terms of noticeable UI changes. On to implementation. Since we can be connected to different systems at the same time, a ptid_t is no longer a unique identifier. Instead a thread can be identified by a pair of ptid_t and 'process_stratum_target *', the later being the instance of the process_stratum target that owns the process/thread. Note that process_stratum_target inherits from target_ops, and all process_stratum targets inherit from process_stratum_target. In earlier patches, many places in gdb were converted to refer to threads by thread_info pointer instead of ptid_t, but there are still places in gdb where we start with a pid/tid and need to find the corresponding inferior or thread_info objects. So you'll see in the patch many places adding a process_stratum_target parameter to functions that used to take only a ptid_t. Since each inferior has its own target stack now, we can always find the process_stratum target for an inferior. That is done via a inf->process_target() convenience method. Since each inferior has its own target stack, we need to handle the "beneath" calls when servicing target calls. The solution I settled with is just to make sure to switch the current inferior to the inferior you want before making a target call. Not relying on global context is just not feasible in current GDB. Fortunately, there aren't that many places that need to do that, because generally most code that calls target methods already has the current context pointing to the right inferior/thread. Note, to emphasize -- there's no method to "switch to this target stack". Instead, you switch the current inferior, and that implicitly switches the target stack. In some spots, we need to iterate over all inferiors so that we reach all target stacks. Native targets are still singletons. There's always only a single instance of such targets. Remote targets however, we'll have one instance per remote connection. The exec target is still a singleton. There's only one instance. I did not see the point of instanciating more than one exec_target object. After vfork, we need to make sure to push the exec target on the new inferior. See exec_on_vfork. For type safety, functions that need a {target, ptid} pair to identify a thread, take a process_stratum_target pointer for target parameter instead of target_ops *. Some shared code in gdb/nat/ also need to gain a target pointer parameter. This poses an issue, since gdbserver doesn't have process_stratum_target, only target_ops. To fix this, this commit renames gdbserver's target_ops to process_stratum_target. I think this makes sense. There's no concept of target stack in gdbserver, and gdbserver's target_ops really implements a process_stratum-like target. The thread and inferior iterator functions also gain process_stratum_target parameters. These are used to be able to iterate over threads and inferiors of a given target. Following usual conventions, if the target pointer is null, then we iterate over threads and inferiors of all targets. I tried converting "add-inferior" to the gdb::option framework, as a preparatory patch, but that stumbled on the fact that gdb::option does not support file options yet, for "add-inferior -exec". I have a WIP patchset that adds that, but it's not a trivial patch, mainly due to need to integrate readline's filename completion, so I deferred that to some other time. In infrun.c/infcmd.c, the main change is that we need to poll events out of all targets. See do_target_wait. Right after collecting an event, we switch the current inferior to an inferior bound to the target that reported the event, so that target methods can be used while handling the event. This makes most of the code transparent to multi-targets. See fetch_inferior_event. infrun.c:stop_all_threads is interesting -- in this function we need to stop all threads of all targets. What the function does is send an asynchronous stop request to all threads, and then synchronously waits for events, with target_wait, rinse repeat, until all it finds are stopped threads. Now that we have multiple targets, it's not efficient to synchronously block in target_wait waiting for events out of one target. Instead, we implement a mini event loop, with interruptible_select, select'ing on one file descriptor per target. For this to work, we need to be able to ask the target for a waitable file descriptor. Such file descriptors already exist, they are the descriptors registered in the main event loop with add_file_handler, inside the target_async implementations. This commit adds a new target_async_wait_fd target method that just returns the file descriptor in question. See wait_one / stop_all_threads in infrun.c. The 'threads_executing' global is made a per-target variable. Since it is only relevant to process_stratum_target targets, this is where it is put, instead of in target_ops. You'll notice that remote.c includes some FIXME notes. These refer to the fact that the global arrays that hold data for the remote packets supported are still globals. For example, if we connect to two different servers/stubs, then each might support different remote protocol features. They might even be different architectures, like e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a host/controller scenario as a single program. That isn't going to work correctly today, because of said globals. I'm leaving fixing that for another pass, since it does not appear to be trivial, and I'd rather land the base work first. It's already useful to be able to debug multiple instances of the same server (e.g., a distributed cluster, where you have full control over the servers installed), so I think as is it's already reasonable incremental progress. Current limitations: - You can only resume more that one target at the same time if all targets support asynchronous debugging, and support non-stop mode. It should be possible to support mixed all-stop + non-stop backends, but that is left for another time. This means that currently in order to do multi-target with gdbserver you need to issue "maint set target-non-stop on". I would like to make that mode be the default, but we're not there yet. Note that I'm talking about how the target backend works, only. User-visible all-stop mode works just fine. - As explained above, connecting to different remote servers at the same time is likely to produce bad results if they don't support the exact set of RSP features. FreeBSD updates courtesy of John Baldwin. gdb/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> John Baldwin <jhb@FreeBSD.org> * aarch64-linux-nat.c (aarch64_linux_nat_target::thread_architecture): Adjust. * ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call. (task_command_1): Likewise. * aix-thread.c (sync_threadlists, aix_thread_target::resume) (aix_thread_target::wait, aix_thread_target::fetch_registers) (aix_thread_target::store_registers) (aix_thread_target::thread_alive): Adjust. * amd64-fbsd-tdep.c: Include "inferior.h". (amd64fbsd_get_thread_local_address): Pass down target. * amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle thread's gdbarch instead of target_gdbarch. * break-catch-sig.c (signal_catchpoint_print_it): Adjust call to get_last_target_status. * break-catch-syscall.c (print_it_catch_syscall): Likewise. * breakpoint.c (breakpoints_should_be_inserted_now): Consider all inferiors. (update_inserted_breakpoint_locations): Skip if inferiors with no execution. (update_global_location_list): When handling moribund locations, find representative inferior for location's pspace, and use thread count of its process_stratum target. * bsd-kvm.c (bsd_kvm_target_open): Pass target down. * bsd-uthread.c (bsd_uthread_target::wait): Use as_process_stratum_target and adjust thread_change_ptid and add_thread calls. (bsd_uthread_target::update_thread_list): Use as_process_stratum_target and adjust find_thread_ptid, thread_change_ptid and add_thread calls. * btrace.c (maint_btrace_packet_history_cmd): Adjust find_thread_ptid call. * corelow.c (add_to_thread_list): Adjust add_thread call. (core_target_open): Adjust add_thread_silent and thread_count calls. (core_target::pid_to_str): Adjust find_inferior_ptid call. * ctf.c (ctf_target_open): Adjust add_thread_silent call. * event-top.c (async_disconnect): Pop targets from all inferiors. * exec.c (add_target_sections): Push exec target on all inferiors sharing the program space. (remove_target_sections): Remove the exec target from all inferiors sharing the program space. (exec_on_vfork): New. * exec.h (exec_on_vfork): Declare. * fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::update_thread_list): Adjust. (fbsd_nat_target::resume): Adjust. (fbsd_handle_debug_trap): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust. * fbsd-tdep.c (fbsd_corefile_thread): Adjust get_thread_arch_regcache call. * fork-child.c (gdb_startup_inferior): Pass target down to startup_inferior and set_executing. * gdbthread.h (struct process_stratum_target): Forward declare. (add_thread, add_thread_silent, add_thread_with_info) (in_thread_list): Add process_stratum_target parameter. (find_thread_ptid(inferior*, ptid_t)): New overload. (find_thread_ptid, thread_change_ptid): Add process_stratum_target parameter. (all_threads()): Delete overload. (all_threads, all_non_exited_threads): Add process_stratum_target parameter. (all_threads_safe): Use brace initialization. (thread_count): Add process_stratum_target parameter. (set_resumed, set_running, set_stop_requested, set_executing) (threads_are_executing, finish_thread_state): Add process_stratum_target parameter. (switch_to_thread): Use is_current_thread. * i386-fbsd-tdep.c: Include "inferior.h". (i386fbsd_get_thread_local_address): Pass down target. * i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust. * inf-child.c (inf_child_target::maybe_unpush_target): Remove have_inferiors check. * inf-ptrace.c (inf_ptrace_target::create_inferior) (inf_ptrace_target::attach): Adjust. * infcall.c (run_inferior_call): Adjust. * infcmd.c (run_command_1): Pass target to scoped_finish_thread_state. (proceed_thread_callback): Skip inferiors with no execution. (continue_command): Rename 'all_threads' local to avoid hiding 'all_threads' function. Adjust get_last_target_status call. (prepare_one_step): Adjust set_running call. (signal_command): Use user_visible_resume_target. Compare thread pointers instead of inferior_ptid. (info_program_command): Adjust to pass down target. (attach_command): Mark target's 'thread_executing' flag. (stop_current_target_threads_ns): New, factored out from ... (interrupt_target_1): ... this. Switch inferior before making target calls. * inferior-iter.h (struct all_inferiors_iterator, struct all_inferiors_range) (struct all_inferiors_safe_range) (struct all_non_exited_inferiors_range): Filter on process_stratum_target too. Remove explicit. * inferior.c (inferior::inferior): Push dummy target on target stack. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors): Add process_stratum_target parameter, and pass it down. (have_live_inferiors): Adjust. (switch_to_inferior_and_push_target): New. (add_inferior_command, clone_inferior_command): Handle "-no-connection" parameter. Use switch_to_inferior_and_push_target. (_initialize_inferior): Mention "-no-connection" option in the help of "add-inferior" and "clone-inferior" commands. * inferior.h: Include "process-stratum-target.h". (interrupt_target_1): Use bool. (struct inferior) <push_target, unpush_target, target_is_pushed, find_target_beneath, top_target, process_target, target_at, m_stack>: New. (discard_all_inferiors): Delete. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors) (all_inferiors, all_non_exited_inferiors): Add process_stratum_target parameter. * infrun.c: Include "gdb_select.h" and <unordered_map>. (target_last_proc_target): New global. (follow_fork_inferior): Push target on new inferior. Pass target to add_thread_silent. Call exec_on_vfork. Handle target's reference count. (follow_fork): Adjust get_last_target_status call. Also consider target. (follow_exec): Push target on new inferior. (struct execution_control_state) <target>: New field. (user_visible_resume_target): New. (do_target_resume): Call target_async. (resume_1): Set target's threads_executing flag. Consider resume target. (commit_resume_all_targets): New. (proceed): Also consider resume target. Skip threads of inferiors with no execution. Commit resumtion in all targets. (start_remote): Pass current inferior to wait_for_inferior. (infrun_thread_stop_requested): Consider target as well. Pass thread_info pointer to clear_inline_frame_state instead of ptid. (infrun_thread_thread_exit): Consider target as well. (random_pending_event_thread): New inferior parameter. Use it. (do_target_wait): Rename to ... (do_target_wait_1): ... this. Add inferior parameter, and pass it down. (threads_are_resumed_pending_p, do_target_wait): New. (prepare_for_detach): Adjust calls. (wait_for_inferior): New inferior parameter. Handle it. Use do_target_wait_1 instead of do_target_wait. (fetch_inferior_event): Adjust. Switch to representative inferior. Pass target down. (set_last_target_status): Add process_stratum_target parameter. Save target in global. (get_last_target_status): Add process_stratum_target parameter and handle it. (nullify_last_target_wait_ptid): Clear 'target_last_proc_target'. (context_switch): Check inferior_ptid == null_ptid before calling inferior_thread(). (get_inferior_stop_soon): Pass down target. (wait_one): Rename to ... (poll_one_curr_target): ... this. (struct wait_one_event): New. (wait_one): New. (stop_all_threads): Adjust. (handle_no_resumed, handle_inferior_event): Adjust to consider the event's target. (switch_back_to_stepped_thread): Also consider target. (print_stop_event): Update. (normal_stop): Update. Also consider the resume target. * infrun.h (wait_for_inferior): Remove declaration. (user_visible_resume_target): New declaration. (get_last_target_status, set_last_target_status): New process_stratum_target parameter. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter, and use it. (clear_inline_frame_state (thread_info*)): New. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter. (clear_inline_frame_state (thread_info*)): Declare. * linux-fork.c (delete_checkpoint_command): Pass target down to find_thread_ptid. (checkpoint_command): Adjust. * linux-nat.c (linux_nat_target::follow_fork): Switch to thread instead of just tweaking inferior_ptid. (linux_nat_switch_fork): Pass target down to thread_change_ptid. (exit_lwp): Pass target down to find_thread_ptid. (attach_proc_task_lwp_callback): Pass target down to add_thread/set_running/set_executing. (linux_nat_target::attach): Pass target down to thread_change_ptid. (get_detach_signal): Pass target down to find_thread_ptid. Consider last target status's target. (linux_resume_one_lwp_throw, resume_lwp) (linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp) (stop_wait_callback, save_stop_reason, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down. (linux_nat_target::async_wait_fd): New. (linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass target down. * linux-nat.h (linux_nat_target::async_wait_fd): Declare. * linux-tdep.c (get_thread_arch_regcache): Pass target down. * linux-thread-db.c (struct thread_db_info::process_target): New field. (add_thread_db_info): Save target. (get_thread_db_info): New process_stratum_target parameter. Also match target. (delete_thread_db_info): New process_stratum_target parameter. Also match target. (thread_from_lwp): Adjust to pass down target. (thread_db_notice_clone): Pass down target. (check_thread_db_callback): Pass down target. (try_thread_db_load_1): Always push the thread_db target. (try_thread_db_load, record_thread): Pass target down. (thread_db_target::detach): Pass target down. Always unpush the thread_db target. (thread_db_target::wait, thread_db_target::mourn_inferior): Pass target down. Always unpush the thread_db target. (find_new_threads_callback, thread_db_find_new_threads_2) (thread_db_target::update_thread_list): Pass target down. (thread_db_target::pid_to_str): Pass current inferior down. (thread_db_target::get_thread_local_address): Pass target down. (thread_db_target::resume, maintenance_check_libthread_db): Pass target down. * nto-procfs.c (nto_procfs_target::update_thread_list): Adjust. * procfs.c (procfs_target::procfs_init_inferior): Declare. (proc_set_current_signal, do_attach, procfs_target::wait): Adjust. (procfs_init_inferior): Rename to ... (procfs_target::procfs_init_inferior): ... this and adjust. (procfs_target::create_inferior, procfs_notice_thread) (procfs_do_thread_registers): Adjust. * ppc-fbsd-tdep.c: Include "inferior.h". (ppcfbsd_get_thread_local_address): Pass down target. * proc-service.c (ps_xfer_memory): Switch current inferior and program space as well. (get_ps_regcache): Pass target down. * process-stratum-target.c (process_stratum_target::thread_address_space) (process_stratum_target::thread_architecture): Pass target down. * process-stratum-target.h (process_stratum_target::threads_executing): New field. (as_process_stratum_target): New. * ravenscar-thread.c (ravenscar_thread_target::update_inferior_ptid): Pass target down. (ravenscar_thread_target::wait, ravenscar_add_thread): Pass target down. * record-btrace.c (record_btrace_target::info_record): Adjust. (record_btrace_target::record_method) (record_btrace_target::record_is_replaying) (record_btrace_target::fetch_registers) (get_thread_current_frame_id, record_btrace_target::resume) (record_btrace_target::wait, record_btrace_target::stop): Pass target down. * record-full.c (record_full_wait_1): Switch to event thread. Pass target down. * regcache.c (regcache::regcache) (get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add process_stratum_target parameter and handle it. (current_thread_target): New global. (get_thread_regcache): Add process_stratum_target parameter and handle it. Switch inferior before calling target method. (get_thread_regcache): Pass target down. (get_thread_regcache_for_ptid): Pass target down. (registers_changed_ptid): Add process_stratum_target parameter and handle it. (registers_changed_thread, registers_changed): Pass target down. (test_get_thread_arch_aspace_regcache): New. (current_regcache_test): Define a couple local test_target_ops instances and use them for testing. (readwrite_regcache): Pass process_stratum_target parameter. (cooked_read_test, cooked_write_test): Pass mock_target down. * regcache.h (get_thread_regcache, get_thread_arch_regcache) (get_thread_arch_aspace_regcache): Add process_stratum_target parameter. (regcache::target): New method. (regcache::regcache, regcache::get_thread_arch_aspace_regcache) (regcache::registers_changed_ptid): Add process_stratum_target parameter. (regcache::m_target): New field. (registers_changed_ptid): Add process_stratum_target parameter. * remote.c (remote_state::supports_vCont_probed): New field. (remote_target::async_wait_fd): New method. (remote_unpush_and_throw): Add remote_target parameter. (get_current_remote_target): Adjust. (remote_target::remote_add_inferior): Push target. (remote_target::remote_add_thread) (remote_target::remote_notice_new_inferior) (get_remote_thread_info): Pass target down. (remote_target::update_thread_list): Skip threads of inferiors bound to other targets. (remote_target::close): Don't discard inferiors. (remote_target::add_current_inferior_and_thread) (remote_target::process_initial_stop_replies) (remote_target::start_remote) (remote_target::remote_serial_quit_handler): Pass down target. (remote_target::remote_unpush_target): New remote_target parameter. Unpush the target from all inferiors. (remote_target::remote_unpush_and_throw): New remote_target parameter. Pass it down. (remote_target::open_1): Check whether the current inferior has execution instead of checking whether any inferior is live. Pass target down. (remote_target::remote_detach_1): Pass down target. Use remote_unpush_target. (extended_remote_target::attach): Pass down target. (remote_target::remote_vcont_probe): Set supports_vCont_probed. (remote_target::append_resumption): Pass down target. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc, remote_target::resume) (remote_target::commit_resume): Pass down target. (remote_target::remote_stop_ns): Check supports_vCont_probed. (remote_target::interrupt_query) (remote_target::remove_new_fork_children) (remote_target::check_pending_events_prevent_wildcard_vcont) (remote_target::remote_parse_stop_reply) (remote_target::process_stop_reply): Pass down target. (first_remote_resumed_thread): New remote_target parameter. Pass it down. (remote_target::wait_as): Pass down target. (unpush_and_perror): New remote_target parameter. Pass it down. (remote_target::readchar, remote_target::remote_serial_write) (remote_target::getpkt_or_notif_sane_1) (remote_target::kill_new_fork_children, remote_target::kill): Pass down target. (remote_target::mourn_inferior): Pass down target. Use remote_unpush_target. (remote_target::core_of_thread) (remote_target::remote_btrace_maybe_reopen): Pass down target. (remote_target::pid_to_exec_file) (remote_target::thread_handle_to_thread_info): Pass down target. (remote_target::async_wait_fd): New. * riscv-fbsd-tdep.c: Include "inferior.h". (riscv_fbsd_get_thread_local_address): Pass down target. * sol2-tdep.c (sol2_core_pid_to_str): Pass down target. * sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs) (ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback): Adjust. * solib-spu.c (spu_skip_standalone_loader): Pass down target. * solib-svr4.c (enable_break): Pass down target. * spu-multiarch.c (parse_spufs_run): Pass down target. * spu-tdep.c (spu2ppu_sniffer): Pass down target. * target-delegates.c: Regenerate. * target.c (g_target_stack): Delete. (current_top_target): Return the current inferior's top target. (target_has_execution_1): Refer to the passed-in inferior's top target. (target_supports_terminal_ours): Check whether the initial inferior was already created. (decref_target): New. (target_stack::push): Incref/decref the target. (push_target, push_target, unpush_target): Adjust. (target_stack::unpush): Defref target. (target_is_pushed): Return bool. Adjust to refer to the current inferior's target stack. (dispose_inferior): Delete, and inline parts ... (target_preopen): ... here. Only dispose of the current inferior. (target_detach): Hold strong target reference while detaching. Pass target down. (target_thread_name): Add assertion. (target_resume): Pass down target. (target_ops::beneath, find_target_at): Adjust to refer to the current inferior's target stack. (get_dummy_target): New. (target_pass_ctrlc): Pass the Ctrl-C to the first inferior that has a thread running. (initialize_targets): Rename to ... (_initialize_target): ... this. * target.h: Include "gdbsupport/refcounted-object.h". (struct target_ops): Inherit refcounted_object. (target_ops::shortname, target_ops::longname): Make const. (target_ops::async_wait_fd): New method. (decref_target): Declare. (struct target_ops_ref_policy): New. (target_ops_ref): New typedef. (get_dummy_target): Declare function. (target_is_pushed): Return bool. * thread-iter.c (all_matching_threads_iterator::m_inf_matches) (all_matching_threads_iterator::all_matching_threads_iterator): Handle filter target. * thread-iter.h (struct all_matching_threads_iterator, struct all_matching_threads_range, class all_non_exited_threads_range): Filter by target too. Remove explicit. * thread.c (threads_executing): Delete. (inferior_thread): Pass down current inferior. (clear_thread_inferior_resources): Pass down thread pointer instead of ptid_t. (add_thread_silent, add_thread_with_info, add_thread): Add process_stratum_target parameter. Use it for thread and inferior searches. (is_current_thread): New. (thread_info::deletable): Use it. (find_thread_ptid, thread_count, in_thread_list) (thread_change_ptid, set_resumed, set_running): New process_stratum_target parameter. Pass it down. (set_executing): New process_stratum_target parameter. Pass it down. Adjust reference to 'threads_executing'. (threads_are_executing): New process_stratum_target parameter. Adjust reference to 'threads_executing'. (set_stop_requested, finish_thread_state): New process_stratum_target parameter. Pass it down. (switch_to_thread): Also match inferior. (switch_to_thread): New process_stratum_target parameter. Pass it down. (update_threads_executing): Reimplement. * top.c (quit_force): Pop targets from all inferior. (gdb_init): Don't call initialize_targets. * windows-nat.c (windows_nat_target) <get_windows_debug_event>: Declare. (windows_add_thread, windows_delete_thread): Adjust. (get_windows_debug_event): Rename to ... (windows_nat_target::get_windows_debug_event): ... this. Adjust. * tracefile-tfile.c (tfile_target_open): Pass down target. * gdbsupport/common-gdbthread.h (struct process_stratum_target): Forward declare. (switch_to_thread): Add process_stratum_target parameter. * mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target parameter. Use it. (mi_on_resume): Pass target down. * nat/fork-inferior.c (startup_inferior): Add process_stratum_target parameter. Pass it down. * nat/fork-inferior.h (startup_inferior): Add process_stratum_target parameter. * python/py-threadevent.c (py_get_event_thread): Pass target down. gdb/gdbserver/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> * fork-child.c (post_fork_inferior): Pass target down to startup_inferior. * inferiors.c (switch_to_thread): Add process_stratum_target parameter. * lynx-low.c (lynx_target_ops): Now a process_stratum_target. * nto-low.c (nto_target_ops): Now a process_stratum_target. * linux-low.c (linux_target_ops): Now a process_stratum_target. * remote-utils.c (prepare_resume_reply): Pass the target to switch_to_thread. * target.c (the_target): Now a process_stratum_target. (done_accessing_memory): Pass the target to switch_to_thread. (set_target_ops): Ajust to use process_stratum_target. * target.h (struct target_ops): Rename to ... (struct process_stratum_target): ... this. (the_target, set_target_ops): Adjust. (prepare_to_access_memory): Adjust comment. * win32-low.c (child_xfer_memory): Adjust to use process_stratum_target. (win32_target_ops): Now a process_stratum_target.
2020-01-10 21:06:08 +01:00
return all_inferiors_range (proc_target);
Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc. As preparation for multi-target, this patch makes each inferior have its own thread list. This isn't absolutely necessary for multi-target, but simplifies things. It originally stemmed from the desire to eliminate the init_thread_list calls sprinkled around, plus it makes it more efficient to iterate over threads of a given inferior (no need to always iterate over threads of all inferiors). We still need to iterate over threads of all inferiors in a number of places, which means we'd need adjust the ALL_THREADS / ALL_NON_EXITED_THREADS macros. However, naively tweaking those macros to have an extra for loop, like: #define ALL_THREADS (thr, inf) \ for (inf = inferior_list; inf; inf = inf->next) \ for (thr = inf->thread_list; thr; thr = thr->next) causes problems with code that does "break" or "continue" within the ALL_THREADS loop body. Plus, we need to declare the extra "inf" local variable in order to pass it as temporary variable to ALL_THREADS (etc.) It gets even trickier when we consider extending the macros to filter out threads matching a ptid_t and a target. The macros become tricker to read/write. Been there. An alternative (which was my next attempt), is to replace the ALL_THREADS etc. iteration style with for_each_all_threads, for_each_non_exited_threads, etc. functions which would take a callback as parameter, which would usually be passed a lambda. However, I did not find that satisfactory at all, because the resulting code ends up a little less natural / more noisy to read, write and debug/step-through (due to use of lambdas), and in many places where we use "continue;" to skip to the next thread now need to use "return;". (I ran into hard to debug bugs caused by a continue/return confusion.) I.e., before: ALL_NON_EXITED_THREADS (tp) { if (tp->not_what_I_want) continue; // do something } would turn into: for_each_non_exited_thread ([&] (thread_info *tp) { if (tp->not_what_I_want) return; // do something }); Lastly, the solution I settled with was to replace the ALL_THREADS / ALL_NON_EXITED_THREADS / ALL_INFERIORS macros with (C++20-like) ranges and iterators, such that you can instead naturaly iterate over threads/inferiors using range-for, like e.g,.: // all threads, including THREAD_EXITED threads. for (thread_info *tp : all_threads ()) { .... } // all non-exited threads. for (thread_info *tp : all_non_exited_threads ()) { .... } // all non-exited threads of INF inferior. for (thread_info *tp : inf->non_exited_threads ()) { .... } The all_non_exited_threads() function takes an optional filter ptid_t as parameter, which is quite convenient when we need to iterate over threads matching that filter. See e.g., how the set_executing/set_stop_requested/finish_thread_state etc. functions in thread.c end up being simplified. Most of the patch thus is about adding the infrustructure for allowing the above. Later on when we get to actual multi-target, these functions/ranges/iterators will gain a "target_ops *" parameter so that e.g., we can iterate over all threads of a given target that match a given filter ptid_t. The only entry points users needs to be aware of are the all_threads/all_non_exited_threads etc. functions seen above. Thus, those functions are declared in gdbthread.h/inferior.h. The actual iterators/ranges are mainly "internals" and thus are put out of view in the new thread-iter.h/thread-iter.c/inferior-iter.h files. That keeps the gdbthread.h/inferior.h headers quite a bit more readable. A common/safe-iterator.h header is added which adds a template that can be used to build "safe" iterators, which are forward iterators that can be used to replace the ALL_THREADS_SAFE macro and other instances of the same idiom in future. There's a little bit of shuffling of code between gdbthread.h/thread.c/inferior.h in the patch. That is necessary in order to avoid circular dependencies between the gdbthread.h/inferior.h headers. As for the init_thread_list calls sprinkled around, they're all eliminated by this patch, and a new, central call is added to inferior_appeared. Note how also related to that, there's a call to init_wait_for_inferior in remote.c that is eliminated. init_wait_for_inferior is currently responsible for discarding skipped inline frames, which had to be moved elsewhere. Given that nowadays we always have a thread even for single-threaded processes, the natural place is to delete a frame's inline frame info when we delete the thread. I.e., from clear_thread_inferior_resources. gdb/ChangeLog: 2018-11-22 Pedro Alves <palves@redhat.com> * Makefile.in (COMMON_SFILES): Add thread-iter.c. * breakpoint.c (breakpoints_should_be_inserted_now): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (print_one_breakpoint_location): Replace ALL_INFERIORS with all_inferiors. * bsd-kvm.c: Include inferior.h. * btrace.c (btrace_free_objfile): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * common/filtered-iterator.h: New. * common/safe-iterator.h: New. * corelow.c (core_target_open): Don't call init_thread_list here. * darwin-nat.c (thread_info_from_private_thread_info): Replace ALL_THREADS with all_threads. * fbsd-nat.c (fbsd_nat_target::resume): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fbsd-tdep.c (fbsd_make_corefile_notes): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fork-child.c (postfork_hook): Don't call init_thread_list here. * gdbarch-selftests.c (register_to_value_test): Adjust. * gdbthread.h: Don't include "inferior.h" here. (struct inferior): Forward declare. (enum step_over_calls_kind): Moved here from inferior.h. (thread_info::deletable): Definition moved to thread.c. (find_thread_ptid (inferior *, ptid_t)): Declare. (ALL_THREADS, ALL_THREADS_BY_INFERIOR, ALL_THREADS_SAFE): Delete. Include "thread-iter.h". (all_threads, all_non_exited_threads, all_threads_safe): New. (any_thread_p): Declare. (thread_list): Delete. * infcmd.c (signal_command): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (proceed_after_attach_callback): Delete. (proceed_after_attach): Take an inferior pointer instead of an integer PID. Adjust to use range-for. (attach_post_wait): Pass down inferior pointer instead of pid. Use range-for instead of ALL_NON_EXITED_THREADS. (detach_command): Remove init_thread_list call. * inferior-iter.h: New. * inferior.c (struct delete_thread_of_inferior_arg): Delete. (delete_thread_of_inferior): Delete. (delete_inferior, exit_inferior_1): Use range-for with inf->threads_safe() instead of iterate_over_threads. (inferior_appeared): Call init_thread_list here. (discard_all_inferiors): Use all_non_exited_inferiors. (find_inferior_id, find_inferior_pid): Use all_inferiors. (iterate_over_inferiors): Use all_inferiors_safe. (have_inferiors, number_of_live_inferiors): Use all_non_exited_inferiors. (number_of_inferiors): Use all_inferiors and std::distance. (print_inferior): Use all_inferiors. * inferior.h: Include gdbthread.h. (enum step_over_calls_kind): Moved to gdbthread.h. (struct inferior) <thread_list>: New field. <threads, non_exited_threads, threads_safe>: New methods. (ALL_INFERIORS): Delete. Include "inferior-iter.h". (ALL_NON_EXITED_INFERIORS): Delete. (all_inferiors_safe, all_inferiors, all_non_exited_inferiors): New functions. * inflow.c (child_interrupt, child_pass_ctrlc): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * infrun.c (follow_exec): Use all_threads_safe. (clear_proceed_status, proceed): Use all_non_exited_threads. (init_wait_for_inferior): Don't clear inline frame state here. (infrun_thread_stop_requested, for_each_just_stopped_thread): Use all_threads instead of ALL_NON_EXITED_THREADS. (random_pending_event_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use a lambda for repeated code. (clean_up_just_stopped_threads_fsms): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (handle_no_resumed): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use all_inferiors instead of ALL_INFERIORS. (restart_threads, switch_back_to_stepped_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-nat.c (check_zombie_leaders): Replace ALL_INFERIORS with all_inferiors. (kill_unfollowed_fork_children): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-tdep.c (linux_make_corefile_notes): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-thread-db.c (thread_db_target::update_thread_list): Replace ALL_INFERIORS with all_inferiors. (thread_db_target::thread_handle_to_thread_info): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * mi/mi-interp.c (multiple_inferiors_p): New. (mi_on_resume_1): Simplify using all_non_exited_threads and multiple_inferiors_p. * mi/mi-main.c (mi_cmd_thread_list_ids): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * nto-procfs.c (nto_procfs_target::open): Don't call init_thread_list here. * record-btrace.c (record_btrace_target_open) (record_btrace_target::stop_recording) (record_btrace_target::close) (record_btrace_target::record_is_replaying) (record_btrace_target::resume, record_btrace_target::wait) (record_btrace_target::record_stop_replaying): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * record-full.c (record_full_wait_1): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * regcache.c (cooked_read_test): Remove reference to global thread_list. * remote-sim.c (gdbsim_target::create_inferior): Don't call init_thread_list here. * remote.c (remote_target::update_thread_list): Use all_threads_safe instead of ALL_NON_EXITED_THREADS. (remote_target::process_initial_stop_replies): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::open_1): Don't call init_thread_list here. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::commit_resume) (remote_target::remove_new_fork_children): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::kill_new_fork_children): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Remove init_thread_list and init_wait_for_inferior calls. (remote_target::remote_btrace_maybe_reopen) (remote_target::thread_handle_to_thread_info): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * target.c (target_terminal::restore_inferior) (target_terminal_is_ours_kind): Replace ALL_INFERIORS with all_non_exited_inferiors. * thread-iter.c: New file. * thread-iter.h: New file. * thread.c: Include "inline-frame.h". (thread_list): Delete. (clear_thread_inferior_resources): Call clear_inline_frame_state. (init_thread_list): Use all_threads_safe instead of ALL_THREADS_SAFE. Adjust to per-inferior thread lists. (new_thread): Adjust to per-inferior thread lists. (add_thread_silent): Pass inferior to find_thread_ptid. (thread_info::deletable): New, moved from the header. (delete_thread_1): Adjust to per-inferior thread lists. (find_thread_global_id): Use inf->threads(). (find_thread_ptid): Use find_inferior_ptid and pass inferior to find_thread_ptid. (find_thread_ptid(inferior*, ptid_t)): New overload. (iterate_over_threads): Use all_threads_safe. (any_thread_p): New. (thread_count): Use all_threads and std::distance. (live_threads_count): Use all_non_exited_threads and std::distance. (valid_global_thread_id): Use all_threads. (in_thread_list): Use find_thread_ptid. (first_thread_of_inferior): Adjust to per-inferior thread lists. (any_thread_of_inferior, any_live_thread_of_inferior): Use inf->non_exited_threads(). (prune_threads, delete_exited_threads): Use all_threads_safe. (thread_change_ptid): Pass inferior pointer to find_thread_ptid. (set_resumed, set_running): Use all_non_exited_threads. (is_thread_state, is_stopped, is_exited, is_running) (is_executing): Delete. (set_executing, set_stop_requested, finish_thread_state): Use all_non_exited_threads. (print_thread_info_1): Use all_inferiors and all_threads. (thread_apply_all_command): Use all_non_exited_threads. (thread_find_command): Use all_threads. (update_threads_executing): Use all_non_exited_threads. * tid-parse.c (parse_thread_id): Use inf->threads. * x86-bsd-nat.c (x86bsd_dr_set): Use inf->non_exited_threads ().
2018-11-22 17:09:14 +01:00
}
/* Return a range that can be used to walk over all inferiors with PID
not zero, with range-for. */
inline all_non_exited_inferiors_range
Multi-target support This commit adds multi-target support to GDB. What this means is that with this commit, GDB can now be connected to different targets at the same time. E.g., you can debug a live native process and a core dump at the same time, connect to multiple gdbservers, etc. Actually, the word "target" is overloaded in gdb. We already have a target stack, with pushes several target_ops instances on top of one another. We also have "info target" already, which means something completely different to what this patch does. So from here on, I'll be using the "target connections" term, to mean an open process_stratum target, pushed on a target stack. This patch makes gdb have multiple target stacks, and multiple process_stratum targets open simultaneously. The user-visible changes / commands will also use this terminology, but of course it's all open to debate. User-interface-wise, not that much changes. The main difference is that each inferior may have its own target connection. A target connection (e.g., a target extended-remote connection) may support debugging multiple processes, just as before. Say you're debugging against gdbserver in extended-remote mode, and you do "add-inferior" to prepare to spawn a new process, like: (gdb) target extended-remote :9999 ... (gdb) start ... (gdb) add-inferior Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) file a.out ... (gdb) start ... At this point, you have two inferiors connected to the same gdbserver. With this commit, GDB will maintain a target stack per inferior, instead of a global target stack. To preserve the behavior above, by default, "add-inferior" makes the new inferior inherit a copy of the target stack of the current inferior. Same across a fork - the child inherits a copy of the target stack of the parent. While the target stacks are copied, the targets themselves are not. Instead, target_ops is made a refcounted_object, which means that target_ops instances are refcounted, which each inferior counting for a reference. What if you want to create an inferior and connect it to some _other_ target? For that, this commit introduces a new "add-inferior -no-connection" option that makes the new inferior not share the current inferior's target. So you could do: (gdb) target extended-remote :9999 Remote debugging using :9999 ... (gdb) add-inferior -no-connection [New inferior 2] Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 <null> (gdb) tar extended-remote :10000 Remote debugging using :10000 ... (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 process 18450 target:/home/pedro/tmp/main (gdb) A following patch will extended "info inferiors" to include a column indicating which connection an inferior is bound to, along with a couple other UI tweaks. Other than that, debugging is the same as before. Users interact with inferiors and threads as before. The only difference is that inferiors may be bound to processes running in different machines. That's pretty much all there is to it in terms of noticeable UI changes. On to implementation. Since we can be connected to different systems at the same time, a ptid_t is no longer a unique identifier. Instead a thread can be identified by a pair of ptid_t and 'process_stratum_target *', the later being the instance of the process_stratum target that owns the process/thread. Note that process_stratum_target inherits from target_ops, and all process_stratum targets inherit from process_stratum_target. In earlier patches, many places in gdb were converted to refer to threads by thread_info pointer instead of ptid_t, but there are still places in gdb where we start with a pid/tid and need to find the corresponding inferior or thread_info objects. So you'll see in the patch many places adding a process_stratum_target parameter to functions that used to take only a ptid_t. Since each inferior has its own target stack now, we can always find the process_stratum target for an inferior. That is done via a inf->process_target() convenience method. Since each inferior has its own target stack, we need to handle the "beneath" calls when servicing target calls. The solution I settled with is just to make sure to switch the current inferior to the inferior you want before making a target call. Not relying on global context is just not feasible in current GDB. Fortunately, there aren't that many places that need to do that, because generally most code that calls target methods already has the current context pointing to the right inferior/thread. Note, to emphasize -- there's no method to "switch to this target stack". Instead, you switch the current inferior, and that implicitly switches the target stack. In some spots, we need to iterate over all inferiors so that we reach all target stacks. Native targets are still singletons. There's always only a single instance of such targets. Remote targets however, we'll have one instance per remote connection. The exec target is still a singleton. There's only one instance. I did not see the point of instanciating more than one exec_target object. After vfork, we need to make sure to push the exec target on the new inferior. See exec_on_vfork. For type safety, functions that need a {target, ptid} pair to identify a thread, take a process_stratum_target pointer for target parameter instead of target_ops *. Some shared code in gdb/nat/ also need to gain a target pointer parameter. This poses an issue, since gdbserver doesn't have process_stratum_target, only target_ops. To fix this, this commit renames gdbserver's target_ops to process_stratum_target. I think this makes sense. There's no concept of target stack in gdbserver, and gdbserver's target_ops really implements a process_stratum-like target. The thread and inferior iterator functions also gain process_stratum_target parameters. These are used to be able to iterate over threads and inferiors of a given target. Following usual conventions, if the target pointer is null, then we iterate over threads and inferiors of all targets. I tried converting "add-inferior" to the gdb::option framework, as a preparatory patch, but that stumbled on the fact that gdb::option does not support file options yet, for "add-inferior -exec". I have a WIP patchset that adds that, but it's not a trivial patch, mainly due to need to integrate readline's filename completion, so I deferred that to some other time. In infrun.c/infcmd.c, the main change is that we need to poll events out of all targets. See do_target_wait. Right after collecting an event, we switch the current inferior to an inferior bound to the target that reported the event, so that target methods can be used while handling the event. This makes most of the code transparent to multi-targets. See fetch_inferior_event. infrun.c:stop_all_threads is interesting -- in this function we need to stop all threads of all targets. What the function does is send an asynchronous stop request to all threads, and then synchronously waits for events, with target_wait, rinse repeat, until all it finds are stopped threads. Now that we have multiple targets, it's not efficient to synchronously block in target_wait waiting for events out of one target. Instead, we implement a mini event loop, with interruptible_select, select'ing on one file descriptor per target. For this to work, we need to be able to ask the target for a waitable file descriptor. Such file descriptors already exist, they are the descriptors registered in the main event loop with add_file_handler, inside the target_async implementations. This commit adds a new target_async_wait_fd target method that just returns the file descriptor in question. See wait_one / stop_all_threads in infrun.c. The 'threads_executing' global is made a per-target variable. Since it is only relevant to process_stratum_target targets, this is where it is put, instead of in target_ops. You'll notice that remote.c includes some FIXME notes. These refer to the fact that the global arrays that hold data for the remote packets supported are still globals. For example, if we connect to two different servers/stubs, then each might support different remote protocol features. They might even be different architectures, like e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a host/controller scenario as a single program. That isn't going to work correctly today, because of said globals. I'm leaving fixing that for another pass, since it does not appear to be trivial, and I'd rather land the base work first. It's already useful to be able to debug multiple instances of the same server (e.g., a distributed cluster, where you have full control over the servers installed), so I think as is it's already reasonable incremental progress. Current limitations: - You can only resume more that one target at the same time if all targets support asynchronous debugging, and support non-stop mode. It should be possible to support mixed all-stop + non-stop backends, but that is left for another time. This means that currently in order to do multi-target with gdbserver you need to issue "maint set target-non-stop on". I would like to make that mode be the default, but we're not there yet. Note that I'm talking about how the target backend works, only. User-visible all-stop mode works just fine. - As explained above, connecting to different remote servers at the same time is likely to produce bad results if they don't support the exact set of RSP features. FreeBSD updates courtesy of John Baldwin. gdb/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> John Baldwin <jhb@FreeBSD.org> * aarch64-linux-nat.c (aarch64_linux_nat_target::thread_architecture): Adjust. * ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call. (task_command_1): Likewise. * aix-thread.c (sync_threadlists, aix_thread_target::resume) (aix_thread_target::wait, aix_thread_target::fetch_registers) (aix_thread_target::store_registers) (aix_thread_target::thread_alive): Adjust. * amd64-fbsd-tdep.c: Include "inferior.h". (amd64fbsd_get_thread_local_address): Pass down target. * amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle thread's gdbarch instead of target_gdbarch. * break-catch-sig.c (signal_catchpoint_print_it): Adjust call to get_last_target_status. * break-catch-syscall.c (print_it_catch_syscall): Likewise. * breakpoint.c (breakpoints_should_be_inserted_now): Consider all inferiors. (update_inserted_breakpoint_locations): Skip if inferiors with no execution. (update_global_location_list): When handling moribund locations, find representative inferior for location's pspace, and use thread count of its process_stratum target. * bsd-kvm.c (bsd_kvm_target_open): Pass target down. * bsd-uthread.c (bsd_uthread_target::wait): Use as_process_stratum_target and adjust thread_change_ptid and add_thread calls. (bsd_uthread_target::update_thread_list): Use as_process_stratum_target and adjust find_thread_ptid, thread_change_ptid and add_thread calls. * btrace.c (maint_btrace_packet_history_cmd): Adjust find_thread_ptid call. * corelow.c (add_to_thread_list): Adjust add_thread call. (core_target_open): Adjust add_thread_silent and thread_count calls. (core_target::pid_to_str): Adjust find_inferior_ptid call. * ctf.c (ctf_target_open): Adjust add_thread_silent call. * event-top.c (async_disconnect): Pop targets from all inferiors. * exec.c (add_target_sections): Push exec target on all inferiors sharing the program space. (remove_target_sections): Remove the exec target from all inferiors sharing the program space. (exec_on_vfork): New. * exec.h (exec_on_vfork): Declare. * fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::update_thread_list): Adjust. (fbsd_nat_target::resume): Adjust. (fbsd_handle_debug_trap): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust. * fbsd-tdep.c (fbsd_corefile_thread): Adjust get_thread_arch_regcache call. * fork-child.c (gdb_startup_inferior): Pass target down to startup_inferior and set_executing. * gdbthread.h (struct process_stratum_target): Forward declare. (add_thread, add_thread_silent, add_thread_with_info) (in_thread_list): Add process_stratum_target parameter. (find_thread_ptid(inferior*, ptid_t)): New overload. (find_thread_ptid, thread_change_ptid): Add process_stratum_target parameter. (all_threads()): Delete overload. (all_threads, all_non_exited_threads): Add process_stratum_target parameter. (all_threads_safe): Use brace initialization. (thread_count): Add process_stratum_target parameter. (set_resumed, set_running, set_stop_requested, set_executing) (threads_are_executing, finish_thread_state): Add process_stratum_target parameter. (switch_to_thread): Use is_current_thread. * i386-fbsd-tdep.c: Include "inferior.h". (i386fbsd_get_thread_local_address): Pass down target. * i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust. * inf-child.c (inf_child_target::maybe_unpush_target): Remove have_inferiors check. * inf-ptrace.c (inf_ptrace_target::create_inferior) (inf_ptrace_target::attach): Adjust. * infcall.c (run_inferior_call): Adjust. * infcmd.c (run_command_1): Pass target to scoped_finish_thread_state. (proceed_thread_callback): Skip inferiors with no execution. (continue_command): Rename 'all_threads' local to avoid hiding 'all_threads' function. Adjust get_last_target_status call. (prepare_one_step): Adjust set_running call. (signal_command): Use user_visible_resume_target. Compare thread pointers instead of inferior_ptid. (info_program_command): Adjust to pass down target. (attach_command): Mark target's 'thread_executing' flag. (stop_current_target_threads_ns): New, factored out from ... (interrupt_target_1): ... this. Switch inferior before making target calls. * inferior-iter.h (struct all_inferiors_iterator, struct all_inferiors_range) (struct all_inferiors_safe_range) (struct all_non_exited_inferiors_range): Filter on process_stratum_target too. Remove explicit. * inferior.c (inferior::inferior): Push dummy target on target stack. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors): Add process_stratum_target parameter, and pass it down. (have_live_inferiors): Adjust. (switch_to_inferior_and_push_target): New. (add_inferior_command, clone_inferior_command): Handle "-no-connection" parameter. Use switch_to_inferior_and_push_target. (_initialize_inferior): Mention "-no-connection" option in the help of "add-inferior" and "clone-inferior" commands. * inferior.h: Include "process-stratum-target.h". (interrupt_target_1): Use bool. (struct inferior) <push_target, unpush_target, target_is_pushed, find_target_beneath, top_target, process_target, target_at, m_stack>: New. (discard_all_inferiors): Delete. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors) (all_inferiors, all_non_exited_inferiors): Add process_stratum_target parameter. * infrun.c: Include "gdb_select.h" and <unordered_map>. (target_last_proc_target): New global. (follow_fork_inferior): Push target on new inferior. Pass target to add_thread_silent. Call exec_on_vfork. Handle target's reference count. (follow_fork): Adjust get_last_target_status call. Also consider target. (follow_exec): Push target on new inferior. (struct execution_control_state) <target>: New field. (user_visible_resume_target): New. (do_target_resume): Call target_async. (resume_1): Set target's threads_executing flag. Consider resume target. (commit_resume_all_targets): New. (proceed): Also consider resume target. Skip threads of inferiors with no execution. Commit resumtion in all targets. (start_remote): Pass current inferior to wait_for_inferior. (infrun_thread_stop_requested): Consider target as well. Pass thread_info pointer to clear_inline_frame_state instead of ptid. (infrun_thread_thread_exit): Consider target as well. (random_pending_event_thread): New inferior parameter. Use it. (do_target_wait): Rename to ... (do_target_wait_1): ... this. Add inferior parameter, and pass it down. (threads_are_resumed_pending_p, do_target_wait): New. (prepare_for_detach): Adjust calls. (wait_for_inferior): New inferior parameter. Handle it. Use do_target_wait_1 instead of do_target_wait. (fetch_inferior_event): Adjust. Switch to representative inferior. Pass target down. (set_last_target_status): Add process_stratum_target parameter. Save target in global. (get_last_target_status): Add process_stratum_target parameter and handle it. (nullify_last_target_wait_ptid): Clear 'target_last_proc_target'. (context_switch): Check inferior_ptid == null_ptid before calling inferior_thread(). (get_inferior_stop_soon): Pass down target. (wait_one): Rename to ... (poll_one_curr_target): ... this. (struct wait_one_event): New. (wait_one): New. (stop_all_threads): Adjust. (handle_no_resumed, handle_inferior_event): Adjust to consider the event's target. (switch_back_to_stepped_thread): Also consider target. (print_stop_event): Update. (normal_stop): Update. Also consider the resume target. * infrun.h (wait_for_inferior): Remove declaration. (user_visible_resume_target): New declaration. (get_last_target_status, set_last_target_status): New process_stratum_target parameter. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter, and use it. (clear_inline_frame_state (thread_info*)): New. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter. (clear_inline_frame_state (thread_info*)): Declare. * linux-fork.c (delete_checkpoint_command): Pass target down to find_thread_ptid. (checkpoint_command): Adjust. * linux-nat.c (linux_nat_target::follow_fork): Switch to thread instead of just tweaking inferior_ptid. (linux_nat_switch_fork): Pass target down to thread_change_ptid. (exit_lwp): Pass target down to find_thread_ptid. (attach_proc_task_lwp_callback): Pass target down to add_thread/set_running/set_executing. (linux_nat_target::attach): Pass target down to thread_change_ptid. (get_detach_signal): Pass target down to find_thread_ptid. Consider last target status's target. (linux_resume_one_lwp_throw, resume_lwp) (linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp) (stop_wait_callback, save_stop_reason, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down. (linux_nat_target::async_wait_fd): New. (linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass target down. * linux-nat.h (linux_nat_target::async_wait_fd): Declare. * linux-tdep.c (get_thread_arch_regcache): Pass target down. * linux-thread-db.c (struct thread_db_info::process_target): New field. (add_thread_db_info): Save target. (get_thread_db_info): New process_stratum_target parameter. Also match target. (delete_thread_db_info): New process_stratum_target parameter. Also match target. (thread_from_lwp): Adjust to pass down target. (thread_db_notice_clone): Pass down target. (check_thread_db_callback): Pass down target. (try_thread_db_load_1): Always push the thread_db target. (try_thread_db_load, record_thread): Pass target down. (thread_db_target::detach): Pass target down. Always unpush the thread_db target. (thread_db_target::wait, thread_db_target::mourn_inferior): Pass target down. Always unpush the thread_db target. (find_new_threads_callback, thread_db_find_new_threads_2) (thread_db_target::update_thread_list): Pass target down. (thread_db_target::pid_to_str): Pass current inferior down. (thread_db_target::get_thread_local_address): Pass target down. (thread_db_target::resume, maintenance_check_libthread_db): Pass target down. * nto-procfs.c (nto_procfs_target::update_thread_list): Adjust. * procfs.c (procfs_target::procfs_init_inferior): Declare. (proc_set_current_signal, do_attach, procfs_target::wait): Adjust. (procfs_init_inferior): Rename to ... (procfs_target::procfs_init_inferior): ... this and adjust. (procfs_target::create_inferior, procfs_notice_thread) (procfs_do_thread_registers): Adjust. * ppc-fbsd-tdep.c: Include "inferior.h". (ppcfbsd_get_thread_local_address): Pass down target. * proc-service.c (ps_xfer_memory): Switch current inferior and program space as well. (get_ps_regcache): Pass target down. * process-stratum-target.c (process_stratum_target::thread_address_space) (process_stratum_target::thread_architecture): Pass target down. * process-stratum-target.h (process_stratum_target::threads_executing): New field. (as_process_stratum_target): New. * ravenscar-thread.c (ravenscar_thread_target::update_inferior_ptid): Pass target down. (ravenscar_thread_target::wait, ravenscar_add_thread): Pass target down. * record-btrace.c (record_btrace_target::info_record): Adjust. (record_btrace_target::record_method) (record_btrace_target::record_is_replaying) (record_btrace_target::fetch_registers) (get_thread_current_frame_id, record_btrace_target::resume) (record_btrace_target::wait, record_btrace_target::stop): Pass target down. * record-full.c (record_full_wait_1): Switch to event thread. Pass target down. * regcache.c (regcache::regcache) (get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add process_stratum_target parameter and handle it. (current_thread_target): New global. (get_thread_regcache): Add process_stratum_target parameter and handle it. Switch inferior before calling target method. (get_thread_regcache): Pass target down. (get_thread_regcache_for_ptid): Pass target down. (registers_changed_ptid): Add process_stratum_target parameter and handle it. (registers_changed_thread, registers_changed): Pass target down. (test_get_thread_arch_aspace_regcache): New. (current_regcache_test): Define a couple local test_target_ops instances and use them for testing. (readwrite_regcache): Pass process_stratum_target parameter. (cooked_read_test, cooked_write_test): Pass mock_target down. * regcache.h (get_thread_regcache, get_thread_arch_regcache) (get_thread_arch_aspace_regcache): Add process_stratum_target parameter. (regcache::target): New method. (regcache::regcache, regcache::get_thread_arch_aspace_regcache) (regcache::registers_changed_ptid): Add process_stratum_target parameter. (regcache::m_target): New field. (registers_changed_ptid): Add process_stratum_target parameter. * remote.c (remote_state::supports_vCont_probed): New field. (remote_target::async_wait_fd): New method. (remote_unpush_and_throw): Add remote_target parameter. (get_current_remote_target): Adjust. (remote_target::remote_add_inferior): Push target. (remote_target::remote_add_thread) (remote_target::remote_notice_new_inferior) (get_remote_thread_info): Pass target down. (remote_target::update_thread_list): Skip threads of inferiors bound to other targets. (remote_target::close): Don't discard inferiors. (remote_target::add_current_inferior_and_thread) (remote_target::process_initial_stop_replies) (remote_target::start_remote) (remote_target::remote_serial_quit_handler): Pass down target. (remote_target::remote_unpush_target): New remote_target parameter. Unpush the target from all inferiors. (remote_target::remote_unpush_and_throw): New remote_target parameter. Pass it down. (remote_target::open_1): Check whether the current inferior has execution instead of checking whether any inferior is live. Pass target down. (remote_target::remote_detach_1): Pass down target. Use remote_unpush_target. (extended_remote_target::attach): Pass down target. (remote_target::remote_vcont_probe): Set supports_vCont_probed. (remote_target::append_resumption): Pass down target. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc, remote_target::resume) (remote_target::commit_resume): Pass down target. (remote_target::remote_stop_ns): Check supports_vCont_probed. (remote_target::interrupt_query) (remote_target::remove_new_fork_children) (remote_target::check_pending_events_prevent_wildcard_vcont) (remote_target::remote_parse_stop_reply) (remote_target::process_stop_reply): Pass down target. (first_remote_resumed_thread): New remote_target parameter. Pass it down. (remote_target::wait_as): Pass down target. (unpush_and_perror): New remote_target parameter. Pass it down. (remote_target::readchar, remote_target::remote_serial_write) (remote_target::getpkt_or_notif_sane_1) (remote_target::kill_new_fork_children, remote_target::kill): Pass down target. (remote_target::mourn_inferior): Pass down target. Use remote_unpush_target. (remote_target::core_of_thread) (remote_target::remote_btrace_maybe_reopen): Pass down target. (remote_target::pid_to_exec_file) (remote_target::thread_handle_to_thread_info): Pass down target. (remote_target::async_wait_fd): New. * riscv-fbsd-tdep.c: Include "inferior.h". (riscv_fbsd_get_thread_local_address): Pass down target. * sol2-tdep.c (sol2_core_pid_to_str): Pass down target. * sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs) (ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback): Adjust. * solib-spu.c (spu_skip_standalone_loader): Pass down target. * solib-svr4.c (enable_break): Pass down target. * spu-multiarch.c (parse_spufs_run): Pass down target. * spu-tdep.c (spu2ppu_sniffer): Pass down target. * target-delegates.c: Regenerate. * target.c (g_target_stack): Delete. (current_top_target): Return the current inferior's top target. (target_has_execution_1): Refer to the passed-in inferior's top target. (target_supports_terminal_ours): Check whether the initial inferior was already created. (decref_target): New. (target_stack::push): Incref/decref the target. (push_target, push_target, unpush_target): Adjust. (target_stack::unpush): Defref target. (target_is_pushed): Return bool. Adjust to refer to the current inferior's target stack. (dispose_inferior): Delete, and inline parts ... (target_preopen): ... here. Only dispose of the current inferior. (target_detach): Hold strong target reference while detaching. Pass target down. (target_thread_name): Add assertion. (target_resume): Pass down target. (target_ops::beneath, find_target_at): Adjust to refer to the current inferior's target stack. (get_dummy_target): New. (target_pass_ctrlc): Pass the Ctrl-C to the first inferior that has a thread running. (initialize_targets): Rename to ... (_initialize_target): ... this. * target.h: Include "gdbsupport/refcounted-object.h". (struct target_ops): Inherit refcounted_object. (target_ops::shortname, target_ops::longname): Make const. (target_ops::async_wait_fd): New method. (decref_target): Declare. (struct target_ops_ref_policy): New. (target_ops_ref): New typedef. (get_dummy_target): Declare function. (target_is_pushed): Return bool. * thread-iter.c (all_matching_threads_iterator::m_inf_matches) (all_matching_threads_iterator::all_matching_threads_iterator): Handle filter target. * thread-iter.h (struct all_matching_threads_iterator, struct all_matching_threads_range, class all_non_exited_threads_range): Filter by target too. Remove explicit. * thread.c (threads_executing): Delete. (inferior_thread): Pass down current inferior. (clear_thread_inferior_resources): Pass down thread pointer instead of ptid_t. (add_thread_silent, add_thread_with_info, add_thread): Add process_stratum_target parameter. Use it for thread and inferior searches. (is_current_thread): New. (thread_info::deletable): Use it. (find_thread_ptid, thread_count, in_thread_list) (thread_change_ptid, set_resumed, set_running): New process_stratum_target parameter. Pass it down. (set_executing): New process_stratum_target parameter. Pass it down. Adjust reference to 'threads_executing'. (threads_are_executing): New process_stratum_target parameter. Adjust reference to 'threads_executing'. (set_stop_requested, finish_thread_state): New process_stratum_target parameter. Pass it down. (switch_to_thread): Also match inferior. (switch_to_thread): New process_stratum_target parameter. Pass it down. (update_threads_executing): Reimplement. * top.c (quit_force): Pop targets from all inferior. (gdb_init): Don't call initialize_targets. * windows-nat.c (windows_nat_target) <get_windows_debug_event>: Declare. (windows_add_thread, windows_delete_thread): Adjust. (get_windows_debug_event): Rename to ... (windows_nat_target::get_windows_debug_event): ... this. Adjust. * tracefile-tfile.c (tfile_target_open): Pass down target. * gdbsupport/common-gdbthread.h (struct process_stratum_target): Forward declare. (switch_to_thread): Add process_stratum_target parameter. * mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target parameter. Use it. (mi_on_resume): Pass target down. * nat/fork-inferior.c (startup_inferior): Add process_stratum_target parameter. Pass it down. * nat/fork-inferior.h (startup_inferior): Add process_stratum_target parameter. * python/py-threadevent.c (py_get_event_thread): Pass target down. gdb/gdbserver/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> * fork-child.c (post_fork_inferior): Pass target down to startup_inferior. * inferiors.c (switch_to_thread): Add process_stratum_target parameter. * lynx-low.c (lynx_target_ops): Now a process_stratum_target. * nto-low.c (nto_target_ops): Now a process_stratum_target. * linux-low.c (linux_target_ops): Now a process_stratum_target. * remote-utils.c (prepare_resume_reply): Pass the target to switch_to_thread. * target.c (the_target): Now a process_stratum_target. (done_accessing_memory): Pass the target to switch_to_thread. (set_target_ops): Ajust to use process_stratum_target. * target.h (struct target_ops): Rename to ... (struct process_stratum_target): ... this. (the_target, set_target_ops): Adjust. (prepare_to_access_memory): Adjust comment. * win32-low.c (child_xfer_memory): Adjust to use process_stratum_target. (win32_target_ops): Now a process_stratum_target.
2020-01-10 21:06:08 +01:00
all_non_exited_inferiors (process_stratum_target *proc_target = nullptr)
Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc. As preparation for multi-target, this patch makes each inferior have its own thread list. This isn't absolutely necessary for multi-target, but simplifies things. It originally stemmed from the desire to eliminate the init_thread_list calls sprinkled around, plus it makes it more efficient to iterate over threads of a given inferior (no need to always iterate over threads of all inferiors). We still need to iterate over threads of all inferiors in a number of places, which means we'd need adjust the ALL_THREADS / ALL_NON_EXITED_THREADS macros. However, naively tweaking those macros to have an extra for loop, like: #define ALL_THREADS (thr, inf) \ for (inf = inferior_list; inf; inf = inf->next) \ for (thr = inf->thread_list; thr; thr = thr->next) causes problems with code that does "break" or "continue" within the ALL_THREADS loop body. Plus, we need to declare the extra "inf" local variable in order to pass it as temporary variable to ALL_THREADS (etc.) It gets even trickier when we consider extending the macros to filter out threads matching a ptid_t and a target. The macros become tricker to read/write. Been there. An alternative (which was my next attempt), is to replace the ALL_THREADS etc. iteration style with for_each_all_threads, for_each_non_exited_threads, etc. functions which would take a callback as parameter, which would usually be passed a lambda. However, I did not find that satisfactory at all, because the resulting code ends up a little less natural / more noisy to read, write and debug/step-through (due to use of lambdas), and in many places where we use "continue;" to skip to the next thread now need to use "return;". (I ran into hard to debug bugs caused by a continue/return confusion.) I.e., before: ALL_NON_EXITED_THREADS (tp) { if (tp->not_what_I_want) continue; // do something } would turn into: for_each_non_exited_thread ([&] (thread_info *tp) { if (tp->not_what_I_want) return; // do something }); Lastly, the solution I settled with was to replace the ALL_THREADS / ALL_NON_EXITED_THREADS / ALL_INFERIORS macros with (C++20-like) ranges and iterators, such that you can instead naturaly iterate over threads/inferiors using range-for, like e.g,.: // all threads, including THREAD_EXITED threads. for (thread_info *tp : all_threads ()) { .... } // all non-exited threads. for (thread_info *tp : all_non_exited_threads ()) { .... } // all non-exited threads of INF inferior. for (thread_info *tp : inf->non_exited_threads ()) { .... } The all_non_exited_threads() function takes an optional filter ptid_t as parameter, which is quite convenient when we need to iterate over threads matching that filter. See e.g., how the set_executing/set_stop_requested/finish_thread_state etc. functions in thread.c end up being simplified. Most of the patch thus is about adding the infrustructure for allowing the above. Later on when we get to actual multi-target, these functions/ranges/iterators will gain a "target_ops *" parameter so that e.g., we can iterate over all threads of a given target that match a given filter ptid_t. The only entry points users needs to be aware of are the all_threads/all_non_exited_threads etc. functions seen above. Thus, those functions are declared in gdbthread.h/inferior.h. The actual iterators/ranges are mainly "internals" and thus are put out of view in the new thread-iter.h/thread-iter.c/inferior-iter.h files. That keeps the gdbthread.h/inferior.h headers quite a bit more readable. A common/safe-iterator.h header is added which adds a template that can be used to build "safe" iterators, which are forward iterators that can be used to replace the ALL_THREADS_SAFE macro and other instances of the same idiom in future. There's a little bit of shuffling of code between gdbthread.h/thread.c/inferior.h in the patch. That is necessary in order to avoid circular dependencies between the gdbthread.h/inferior.h headers. As for the init_thread_list calls sprinkled around, they're all eliminated by this patch, and a new, central call is added to inferior_appeared. Note how also related to that, there's a call to init_wait_for_inferior in remote.c that is eliminated. init_wait_for_inferior is currently responsible for discarding skipped inline frames, which had to be moved elsewhere. Given that nowadays we always have a thread even for single-threaded processes, the natural place is to delete a frame's inline frame info when we delete the thread. I.e., from clear_thread_inferior_resources. gdb/ChangeLog: 2018-11-22 Pedro Alves <palves@redhat.com> * Makefile.in (COMMON_SFILES): Add thread-iter.c. * breakpoint.c (breakpoints_should_be_inserted_now): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (print_one_breakpoint_location): Replace ALL_INFERIORS with all_inferiors. * bsd-kvm.c: Include inferior.h. * btrace.c (btrace_free_objfile): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * common/filtered-iterator.h: New. * common/safe-iterator.h: New. * corelow.c (core_target_open): Don't call init_thread_list here. * darwin-nat.c (thread_info_from_private_thread_info): Replace ALL_THREADS with all_threads. * fbsd-nat.c (fbsd_nat_target::resume): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fbsd-tdep.c (fbsd_make_corefile_notes): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fork-child.c (postfork_hook): Don't call init_thread_list here. * gdbarch-selftests.c (register_to_value_test): Adjust. * gdbthread.h: Don't include "inferior.h" here. (struct inferior): Forward declare. (enum step_over_calls_kind): Moved here from inferior.h. (thread_info::deletable): Definition moved to thread.c. (find_thread_ptid (inferior *, ptid_t)): Declare. (ALL_THREADS, ALL_THREADS_BY_INFERIOR, ALL_THREADS_SAFE): Delete. Include "thread-iter.h". (all_threads, all_non_exited_threads, all_threads_safe): New. (any_thread_p): Declare. (thread_list): Delete. * infcmd.c (signal_command): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (proceed_after_attach_callback): Delete. (proceed_after_attach): Take an inferior pointer instead of an integer PID. Adjust to use range-for. (attach_post_wait): Pass down inferior pointer instead of pid. Use range-for instead of ALL_NON_EXITED_THREADS. (detach_command): Remove init_thread_list call. * inferior-iter.h: New. * inferior.c (struct delete_thread_of_inferior_arg): Delete. (delete_thread_of_inferior): Delete. (delete_inferior, exit_inferior_1): Use range-for with inf->threads_safe() instead of iterate_over_threads. (inferior_appeared): Call init_thread_list here. (discard_all_inferiors): Use all_non_exited_inferiors. (find_inferior_id, find_inferior_pid): Use all_inferiors. (iterate_over_inferiors): Use all_inferiors_safe. (have_inferiors, number_of_live_inferiors): Use all_non_exited_inferiors. (number_of_inferiors): Use all_inferiors and std::distance. (print_inferior): Use all_inferiors. * inferior.h: Include gdbthread.h. (enum step_over_calls_kind): Moved to gdbthread.h. (struct inferior) <thread_list>: New field. <threads, non_exited_threads, threads_safe>: New methods. (ALL_INFERIORS): Delete. Include "inferior-iter.h". (ALL_NON_EXITED_INFERIORS): Delete. (all_inferiors_safe, all_inferiors, all_non_exited_inferiors): New functions. * inflow.c (child_interrupt, child_pass_ctrlc): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * infrun.c (follow_exec): Use all_threads_safe. (clear_proceed_status, proceed): Use all_non_exited_threads. (init_wait_for_inferior): Don't clear inline frame state here. (infrun_thread_stop_requested, for_each_just_stopped_thread): Use all_threads instead of ALL_NON_EXITED_THREADS. (random_pending_event_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use a lambda for repeated code. (clean_up_just_stopped_threads_fsms): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (handle_no_resumed): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use all_inferiors instead of ALL_INFERIORS. (restart_threads, switch_back_to_stepped_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-nat.c (check_zombie_leaders): Replace ALL_INFERIORS with all_inferiors. (kill_unfollowed_fork_children): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-tdep.c (linux_make_corefile_notes): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-thread-db.c (thread_db_target::update_thread_list): Replace ALL_INFERIORS with all_inferiors. (thread_db_target::thread_handle_to_thread_info): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * mi/mi-interp.c (multiple_inferiors_p): New. (mi_on_resume_1): Simplify using all_non_exited_threads and multiple_inferiors_p. * mi/mi-main.c (mi_cmd_thread_list_ids): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * nto-procfs.c (nto_procfs_target::open): Don't call init_thread_list here. * record-btrace.c (record_btrace_target_open) (record_btrace_target::stop_recording) (record_btrace_target::close) (record_btrace_target::record_is_replaying) (record_btrace_target::resume, record_btrace_target::wait) (record_btrace_target::record_stop_replaying): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * record-full.c (record_full_wait_1): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * regcache.c (cooked_read_test): Remove reference to global thread_list. * remote-sim.c (gdbsim_target::create_inferior): Don't call init_thread_list here. * remote.c (remote_target::update_thread_list): Use all_threads_safe instead of ALL_NON_EXITED_THREADS. (remote_target::process_initial_stop_replies): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::open_1): Don't call init_thread_list here. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::commit_resume) (remote_target::remove_new_fork_children): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::kill_new_fork_children): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Remove init_thread_list and init_wait_for_inferior calls. (remote_target::remote_btrace_maybe_reopen) (remote_target::thread_handle_to_thread_info): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * target.c (target_terminal::restore_inferior) (target_terminal_is_ours_kind): Replace ALL_INFERIORS with all_non_exited_inferiors. * thread-iter.c: New file. * thread-iter.h: New file. * thread.c: Include "inline-frame.h". (thread_list): Delete. (clear_thread_inferior_resources): Call clear_inline_frame_state. (init_thread_list): Use all_threads_safe instead of ALL_THREADS_SAFE. Adjust to per-inferior thread lists. (new_thread): Adjust to per-inferior thread lists. (add_thread_silent): Pass inferior to find_thread_ptid. (thread_info::deletable): New, moved from the header. (delete_thread_1): Adjust to per-inferior thread lists. (find_thread_global_id): Use inf->threads(). (find_thread_ptid): Use find_inferior_ptid and pass inferior to find_thread_ptid. (find_thread_ptid(inferior*, ptid_t)): New overload. (iterate_over_threads): Use all_threads_safe. (any_thread_p): New. (thread_count): Use all_threads and std::distance. (live_threads_count): Use all_non_exited_threads and std::distance. (valid_global_thread_id): Use all_threads. (in_thread_list): Use find_thread_ptid. (first_thread_of_inferior): Adjust to per-inferior thread lists. (any_thread_of_inferior, any_live_thread_of_inferior): Use inf->non_exited_threads(). (prune_threads, delete_exited_threads): Use all_threads_safe. (thread_change_ptid): Pass inferior pointer to find_thread_ptid. (set_resumed, set_running): Use all_non_exited_threads. (is_thread_state, is_stopped, is_exited, is_running) (is_executing): Delete. (set_executing, set_stop_requested, finish_thread_state): Use all_non_exited_threads. (print_thread_info_1): Use all_inferiors and all_threads. (thread_apply_all_command): Use all_non_exited_threads. (thread_find_command): Use all_threads. (update_threads_executing): Use all_non_exited_threads. * tid-parse.c (parse_thread_id): Use inf->threads. * x86-bsd-nat.c (x86bsd_dr_set): Use inf->non_exited_threads ().
2018-11-22 17:09:14 +01:00
{
Multi-target support This commit adds multi-target support to GDB. What this means is that with this commit, GDB can now be connected to different targets at the same time. E.g., you can debug a live native process and a core dump at the same time, connect to multiple gdbservers, etc. Actually, the word "target" is overloaded in gdb. We already have a target stack, with pushes several target_ops instances on top of one another. We also have "info target" already, which means something completely different to what this patch does. So from here on, I'll be using the "target connections" term, to mean an open process_stratum target, pushed on a target stack. This patch makes gdb have multiple target stacks, and multiple process_stratum targets open simultaneously. The user-visible changes / commands will also use this terminology, but of course it's all open to debate. User-interface-wise, not that much changes. The main difference is that each inferior may have its own target connection. A target connection (e.g., a target extended-remote connection) may support debugging multiple processes, just as before. Say you're debugging against gdbserver in extended-remote mode, and you do "add-inferior" to prepare to spawn a new process, like: (gdb) target extended-remote :9999 ... (gdb) start ... (gdb) add-inferior Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) file a.out ... (gdb) start ... At this point, you have two inferiors connected to the same gdbserver. With this commit, GDB will maintain a target stack per inferior, instead of a global target stack. To preserve the behavior above, by default, "add-inferior" makes the new inferior inherit a copy of the target stack of the current inferior. Same across a fork - the child inherits a copy of the target stack of the parent. While the target stacks are copied, the targets themselves are not. Instead, target_ops is made a refcounted_object, which means that target_ops instances are refcounted, which each inferior counting for a reference. What if you want to create an inferior and connect it to some _other_ target? For that, this commit introduces a new "add-inferior -no-connection" option that makes the new inferior not share the current inferior's target. So you could do: (gdb) target extended-remote :9999 Remote debugging using :9999 ... (gdb) add-inferior -no-connection [New inferior 2] Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [<null>] (<noexec>)] (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 <null> (gdb) tar extended-remote :10000 Remote debugging using :10000 ... (gdb) info inferiors Num Description Executable 1 process 18401 target:/home/pedro/tmp/main * 2 process 18450 target:/home/pedro/tmp/main (gdb) A following patch will extended "info inferiors" to include a column indicating which connection an inferior is bound to, along with a couple other UI tweaks. Other than that, debugging is the same as before. Users interact with inferiors and threads as before. The only difference is that inferiors may be bound to processes running in different machines. That's pretty much all there is to it in terms of noticeable UI changes. On to implementation. Since we can be connected to different systems at the same time, a ptid_t is no longer a unique identifier. Instead a thread can be identified by a pair of ptid_t and 'process_stratum_target *', the later being the instance of the process_stratum target that owns the process/thread. Note that process_stratum_target inherits from target_ops, and all process_stratum targets inherit from process_stratum_target. In earlier patches, many places in gdb were converted to refer to threads by thread_info pointer instead of ptid_t, but there are still places in gdb where we start with a pid/tid and need to find the corresponding inferior or thread_info objects. So you'll see in the patch many places adding a process_stratum_target parameter to functions that used to take only a ptid_t. Since each inferior has its own target stack now, we can always find the process_stratum target for an inferior. That is done via a inf->process_target() convenience method. Since each inferior has its own target stack, we need to handle the "beneath" calls when servicing target calls. The solution I settled with is just to make sure to switch the current inferior to the inferior you want before making a target call. Not relying on global context is just not feasible in current GDB. Fortunately, there aren't that many places that need to do that, because generally most code that calls target methods already has the current context pointing to the right inferior/thread. Note, to emphasize -- there's no method to "switch to this target stack". Instead, you switch the current inferior, and that implicitly switches the target stack. In some spots, we need to iterate over all inferiors so that we reach all target stacks. Native targets are still singletons. There's always only a single instance of such targets. Remote targets however, we'll have one instance per remote connection. The exec target is still a singleton. There's only one instance. I did not see the point of instanciating more than one exec_target object. After vfork, we need to make sure to push the exec target on the new inferior. See exec_on_vfork. For type safety, functions that need a {target, ptid} pair to identify a thread, take a process_stratum_target pointer for target parameter instead of target_ops *. Some shared code in gdb/nat/ also need to gain a target pointer parameter. This poses an issue, since gdbserver doesn't have process_stratum_target, only target_ops. To fix this, this commit renames gdbserver's target_ops to process_stratum_target. I think this makes sense. There's no concept of target stack in gdbserver, and gdbserver's target_ops really implements a process_stratum-like target. The thread and inferior iterator functions also gain process_stratum_target parameters. These are used to be able to iterate over threads and inferiors of a given target. Following usual conventions, if the target pointer is null, then we iterate over threads and inferiors of all targets. I tried converting "add-inferior" to the gdb::option framework, as a preparatory patch, but that stumbled on the fact that gdb::option does not support file options yet, for "add-inferior -exec". I have a WIP patchset that adds that, but it's not a trivial patch, mainly due to need to integrate readline's filename completion, so I deferred that to some other time. In infrun.c/infcmd.c, the main change is that we need to poll events out of all targets. See do_target_wait. Right after collecting an event, we switch the current inferior to an inferior bound to the target that reported the event, so that target methods can be used while handling the event. This makes most of the code transparent to multi-targets. See fetch_inferior_event. infrun.c:stop_all_threads is interesting -- in this function we need to stop all threads of all targets. What the function does is send an asynchronous stop request to all threads, and then synchronously waits for events, with target_wait, rinse repeat, until all it finds are stopped threads. Now that we have multiple targets, it's not efficient to synchronously block in target_wait waiting for events out of one target. Instead, we implement a mini event loop, with interruptible_select, select'ing on one file descriptor per target. For this to work, we need to be able to ask the target for a waitable file descriptor. Such file descriptors already exist, they are the descriptors registered in the main event loop with add_file_handler, inside the target_async implementations. This commit adds a new target_async_wait_fd target method that just returns the file descriptor in question. See wait_one / stop_all_threads in infrun.c. The 'threads_executing' global is made a per-target variable. Since it is only relevant to process_stratum_target targets, this is where it is put, instead of in target_ops. You'll notice that remote.c includes some FIXME notes. These refer to the fact that the global arrays that hold data for the remote packets supported are still globals. For example, if we connect to two different servers/stubs, then each might support different remote protocol features. They might even be different architectures, like e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a host/controller scenario as a single program. That isn't going to work correctly today, because of said globals. I'm leaving fixing that for another pass, since it does not appear to be trivial, and I'd rather land the base work first. It's already useful to be able to debug multiple instances of the same server (e.g., a distributed cluster, where you have full control over the servers installed), so I think as is it's already reasonable incremental progress. Current limitations: - You can only resume more that one target at the same time if all targets support asynchronous debugging, and support non-stop mode. It should be possible to support mixed all-stop + non-stop backends, but that is left for another time. This means that currently in order to do multi-target with gdbserver you need to issue "maint set target-non-stop on". I would like to make that mode be the default, but we're not there yet. Note that I'm talking about how the target backend works, only. User-visible all-stop mode works just fine. - As explained above, connecting to different remote servers at the same time is likely to produce bad results if they don't support the exact set of RSP features. FreeBSD updates courtesy of John Baldwin. gdb/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> John Baldwin <jhb@FreeBSD.org> * aarch64-linux-nat.c (aarch64_linux_nat_target::thread_architecture): Adjust. * ada-tasks.c (print_ada_task_info): Adjust find_thread_ptid call. (task_command_1): Likewise. * aix-thread.c (sync_threadlists, aix_thread_target::resume) (aix_thread_target::wait, aix_thread_target::fetch_registers) (aix_thread_target::store_registers) (aix_thread_target::thread_alive): Adjust. * amd64-fbsd-tdep.c: Include "inferior.h". (amd64fbsd_get_thread_local_address): Pass down target. * amd64-linux-nat.c (ps_get_thread_area): Use ps_prochandle thread's gdbarch instead of target_gdbarch. * break-catch-sig.c (signal_catchpoint_print_it): Adjust call to get_last_target_status. * break-catch-syscall.c (print_it_catch_syscall): Likewise. * breakpoint.c (breakpoints_should_be_inserted_now): Consider all inferiors. (update_inserted_breakpoint_locations): Skip if inferiors with no execution. (update_global_location_list): When handling moribund locations, find representative inferior for location's pspace, and use thread count of its process_stratum target. * bsd-kvm.c (bsd_kvm_target_open): Pass target down. * bsd-uthread.c (bsd_uthread_target::wait): Use as_process_stratum_target and adjust thread_change_ptid and add_thread calls. (bsd_uthread_target::update_thread_list): Use as_process_stratum_target and adjust find_thread_ptid, thread_change_ptid and add_thread calls. * btrace.c (maint_btrace_packet_history_cmd): Adjust find_thread_ptid call. * corelow.c (add_to_thread_list): Adjust add_thread call. (core_target_open): Adjust add_thread_silent and thread_count calls. (core_target::pid_to_str): Adjust find_inferior_ptid call. * ctf.c (ctf_target_open): Adjust add_thread_silent call. * event-top.c (async_disconnect): Pop targets from all inferiors. * exec.c (add_target_sections): Push exec target on all inferiors sharing the program space. (remove_target_sections): Remove the exec target from all inferiors sharing the program space. (exec_on_vfork): New. * exec.h (exec_on_vfork): Declare. * fbsd-nat.c (fbsd_add_threads): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::update_thread_list): Adjust. (fbsd_nat_target::resume): Adjust. (fbsd_handle_debug_trap): Add fbsd_nat_target parameter. Pass it down. (fbsd_nat_target::wait, fbsd_nat_target::post_attach): Adjust. * fbsd-tdep.c (fbsd_corefile_thread): Adjust get_thread_arch_regcache call. * fork-child.c (gdb_startup_inferior): Pass target down to startup_inferior and set_executing. * gdbthread.h (struct process_stratum_target): Forward declare. (add_thread, add_thread_silent, add_thread_with_info) (in_thread_list): Add process_stratum_target parameter. (find_thread_ptid(inferior*, ptid_t)): New overload. (find_thread_ptid, thread_change_ptid): Add process_stratum_target parameter. (all_threads()): Delete overload. (all_threads, all_non_exited_threads): Add process_stratum_target parameter. (all_threads_safe): Use brace initialization. (thread_count): Add process_stratum_target parameter. (set_resumed, set_running, set_stop_requested, set_executing) (threads_are_executing, finish_thread_state): Add process_stratum_target parameter. (switch_to_thread): Use is_current_thread. * i386-fbsd-tdep.c: Include "inferior.h". (i386fbsd_get_thread_local_address): Pass down target. * i386-linux-nat.c (i386_linux_nat_target::low_resume): Adjust. * inf-child.c (inf_child_target::maybe_unpush_target): Remove have_inferiors check. * inf-ptrace.c (inf_ptrace_target::create_inferior) (inf_ptrace_target::attach): Adjust. * infcall.c (run_inferior_call): Adjust. * infcmd.c (run_command_1): Pass target to scoped_finish_thread_state. (proceed_thread_callback): Skip inferiors with no execution. (continue_command): Rename 'all_threads' local to avoid hiding 'all_threads' function. Adjust get_last_target_status call. (prepare_one_step): Adjust set_running call. (signal_command): Use user_visible_resume_target. Compare thread pointers instead of inferior_ptid. (info_program_command): Adjust to pass down target. (attach_command): Mark target's 'thread_executing' flag. (stop_current_target_threads_ns): New, factored out from ... (interrupt_target_1): ... this. Switch inferior before making target calls. * inferior-iter.h (struct all_inferiors_iterator, struct all_inferiors_range) (struct all_inferiors_safe_range) (struct all_non_exited_inferiors_range): Filter on process_stratum_target too. Remove explicit. * inferior.c (inferior::inferior): Push dummy target on target stack. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors): Add process_stratum_target parameter, and pass it down. (have_live_inferiors): Adjust. (switch_to_inferior_and_push_target): New. (add_inferior_command, clone_inferior_command): Handle "-no-connection" parameter. Use switch_to_inferior_and_push_target. (_initialize_inferior): Mention "-no-connection" option in the help of "add-inferior" and "clone-inferior" commands. * inferior.h: Include "process-stratum-target.h". (interrupt_target_1): Use bool. (struct inferior) <push_target, unpush_target, target_is_pushed, find_target_beneath, top_target, process_target, target_at, m_stack>: New. (discard_all_inferiors): Delete. (find_inferior_pid, find_inferior_ptid, number_of_live_inferiors) (all_inferiors, all_non_exited_inferiors): Add process_stratum_target parameter. * infrun.c: Include "gdb_select.h" and <unordered_map>. (target_last_proc_target): New global. (follow_fork_inferior): Push target on new inferior. Pass target to add_thread_silent. Call exec_on_vfork. Handle target's reference count. (follow_fork): Adjust get_last_target_status call. Also consider target. (follow_exec): Push target on new inferior. (struct execution_control_state) <target>: New field. (user_visible_resume_target): New. (do_target_resume): Call target_async. (resume_1): Set target's threads_executing flag. Consider resume target. (commit_resume_all_targets): New. (proceed): Also consider resume target. Skip threads of inferiors with no execution. Commit resumtion in all targets. (start_remote): Pass current inferior to wait_for_inferior. (infrun_thread_stop_requested): Consider target as well. Pass thread_info pointer to clear_inline_frame_state instead of ptid. (infrun_thread_thread_exit): Consider target as well. (random_pending_event_thread): New inferior parameter. Use it. (do_target_wait): Rename to ... (do_target_wait_1): ... this. Add inferior parameter, and pass it down. (threads_are_resumed_pending_p, do_target_wait): New. (prepare_for_detach): Adjust calls. (wait_for_inferior): New inferior parameter. Handle it. Use do_target_wait_1 instead of do_target_wait. (fetch_inferior_event): Adjust. Switch to representative inferior. Pass target down. (set_last_target_status): Add process_stratum_target parameter. Save target in global. (get_last_target_status): Add process_stratum_target parameter and handle it. (nullify_last_target_wait_ptid): Clear 'target_last_proc_target'. (context_switch): Check inferior_ptid == null_ptid before calling inferior_thread(). (get_inferior_stop_soon): Pass down target. (wait_one): Rename to ... (poll_one_curr_target): ... this. (struct wait_one_event): New. (wait_one): New. (stop_all_threads): Adjust. (handle_no_resumed, handle_inferior_event): Adjust to consider the event's target. (switch_back_to_stepped_thread): Also consider target. (print_stop_event): Update. (normal_stop): Update. Also consider the resume target. * infrun.h (wait_for_inferior): Remove declaration. (user_visible_resume_target): New declaration. (get_last_target_status, set_last_target_status): New process_stratum_target parameter. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter, and use it. (clear_inline_frame_state (thread_info*)): New. * inline-frame.c (clear_inline_frame_state(ptid_t)): Add process_stratum_target parameter. (clear_inline_frame_state (thread_info*)): Declare. * linux-fork.c (delete_checkpoint_command): Pass target down to find_thread_ptid. (checkpoint_command): Adjust. * linux-nat.c (linux_nat_target::follow_fork): Switch to thread instead of just tweaking inferior_ptid. (linux_nat_switch_fork): Pass target down to thread_change_ptid. (exit_lwp): Pass target down to find_thread_ptid. (attach_proc_task_lwp_callback): Pass target down to add_thread/set_running/set_executing. (linux_nat_target::attach): Pass target down to thread_change_ptid. (get_detach_signal): Pass target down to find_thread_ptid. Consider last target status's target. (linux_resume_one_lwp_throw, resume_lwp) (linux_handle_syscall_trap, linux_handle_extended_wait, wait_lwp) (stop_wait_callback, save_stop_reason, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps): Pass target down. (linux_nat_target::async_wait_fd): New. (linux_nat_stop_lwp, linux_nat_target::thread_address_space): Pass target down. * linux-nat.h (linux_nat_target::async_wait_fd): Declare. * linux-tdep.c (get_thread_arch_regcache): Pass target down. * linux-thread-db.c (struct thread_db_info::process_target): New field. (add_thread_db_info): Save target. (get_thread_db_info): New process_stratum_target parameter. Also match target. (delete_thread_db_info): New process_stratum_target parameter. Also match target. (thread_from_lwp): Adjust to pass down target. (thread_db_notice_clone): Pass down target. (check_thread_db_callback): Pass down target. (try_thread_db_load_1): Always push the thread_db target. (try_thread_db_load, record_thread): Pass target down. (thread_db_target::detach): Pass target down. Always unpush the thread_db target. (thread_db_target::wait, thread_db_target::mourn_inferior): Pass target down. Always unpush the thread_db target. (find_new_threads_callback, thread_db_find_new_threads_2) (thread_db_target::update_thread_list): Pass target down. (thread_db_target::pid_to_str): Pass current inferior down. (thread_db_target::get_thread_local_address): Pass target down. (thread_db_target::resume, maintenance_check_libthread_db): Pass target down. * nto-procfs.c (nto_procfs_target::update_thread_list): Adjust. * procfs.c (procfs_target::procfs_init_inferior): Declare. (proc_set_current_signal, do_attach, procfs_target::wait): Adjust. (procfs_init_inferior): Rename to ... (procfs_target::procfs_init_inferior): ... this and adjust. (procfs_target::create_inferior, procfs_notice_thread) (procfs_do_thread_registers): Adjust. * ppc-fbsd-tdep.c: Include "inferior.h". (ppcfbsd_get_thread_local_address): Pass down target. * proc-service.c (ps_xfer_memory): Switch current inferior and program space as well. (get_ps_regcache): Pass target down. * process-stratum-target.c (process_stratum_target::thread_address_space) (process_stratum_target::thread_architecture): Pass target down. * process-stratum-target.h (process_stratum_target::threads_executing): New field. (as_process_stratum_target): New. * ravenscar-thread.c (ravenscar_thread_target::update_inferior_ptid): Pass target down. (ravenscar_thread_target::wait, ravenscar_add_thread): Pass target down. * record-btrace.c (record_btrace_target::info_record): Adjust. (record_btrace_target::record_method) (record_btrace_target::record_is_replaying) (record_btrace_target::fetch_registers) (get_thread_current_frame_id, record_btrace_target::resume) (record_btrace_target::wait, record_btrace_target::stop): Pass target down. * record-full.c (record_full_wait_1): Switch to event thread. Pass target down. * regcache.c (regcache::regcache) (get_thread_arch_aspace_regcache, get_thread_arch_regcache): Add process_stratum_target parameter and handle it. (current_thread_target): New global. (get_thread_regcache): Add process_stratum_target parameter and handle it. Switch inferior before calling target method. (get_thread_regcache): Pass target down. (get_thread_regcache_for_ptid): Pass target down. (registers_changed_ptid): Add process_stratum_target parameter and handle it. (registers_changed_thread, registers_changed): Pass target down. (test_get_thread_arch_aspace_regcache): New. (current_regcache_test): Define a couple local test_target_ops instances and use them for testing. (readwrite_regcache): Pass process_stratum_target parameter. (cooked_read_test, cooked_write_test): Pass mock_target down. * regcache.h (get_thread_regcache, get_thread_arch_regcache) (get_thread_arch_aspace_regcache): Add process_stratum_target parameter. (regcache::target): New method. (regcache::regcache, regcache::get_thread_arch_aspace_regcache) (regcache::registers_changed_ptid): Add process_stratum_target parameter. (regcache::m_target): New field. (registers_changed_ptid): Add process_stratum_target parameter. * remote.c (remote_state::supports_vCont_probed): New field. (remote_target::async_wait_fd): New method. (remote_unpush_and_throw): Add remote_target parameter. (get_current_remote_target): Adjust. (remote_target::remote_add_inferior): Push target. (remote_target::remote_add_thread) (remote_target::remote_notice_new_inferior) (get_remote_thread_info): Pass target down. (remote_target::update_thread_list): Skip threads of inferiors bound to other targets. (remote_target::close): Don't discard inferiors. (remote_target::add_current_inferior_and_thread) (remote_target::process_initial_stop_replies) (remote_target::start_remote) (remote_target::remote_serial_quit_handler): Pass down target. (remote_target::remote_unpush_target): New remote_target parameter. Unpush the target from all inferiors. (remote_target::remote_unpush_and_throw): New remote_target parameter. Pass it down. (remote_target::open_1): Check whether the current inferior has execution instead of checking whether any inferior is live. Pass target down. (remote_target::remote_detach_1): Pass down target. Use remote_unpush_target. (extended_remote_target::attach): Pass down target. (remote_target::remote_vcont_probe): Set supports_vCont_probed. (remote_target::append_resumption): Pass down target. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc, remote_target::resume) (remote_target::commit_resume): Pass down target. (remote_target::remote_stop_ns): Check supports_vCont_probed. (remote_target::interrupt_query) (remote_target::remove_new_fork_children) (remote_target::check_pending_events_prevent_wildcard_vcont) (remote_target::remote_parse_stop_reply) (remote_target::process_stop_reply): Pass down target. (first_remote_resumed_thread): New remote_target parameter. Pass it down. (remote_target::wait_as): Pass down target. (unpush_and_perror): New remote_target parameter. Pass it down. (remote_target::readchar, remote_target::remote_serial_write) (remote_target::getpkt_or_notif_sane_1) (remote_target::kill_new_fork_children, remote_target::kill): Pass down target. (remote_target::mourn_inferior): Pass down target. Use remote_unpush_target. (remote_target::core_of_thread) (remote_target::remote_btrace_maybe_reopen): Pass down target. (remote_target::pid_to_exec_file) (remote_target::thread_handle_to_thread_info): Pass down target. (remote_target::async_wait_fd): New. * riscv-fbsd-tdep.c: Include "inferior.h". (riscv_fbsd_get_thread_local_address): Pass down target. * sol2-tdep.c (sol2_core_pid_to_str): Pass down target. * sol-thread.c (sol_thread_target::wait, ps_lgetregs, ps_lsetregs) (ps_lgetfpregs, ps_lsetfpregs, sol_update_thread_list_callback): Adjust. * solib-spu.c (spu_skip_standalone_loader): Pass down target. * solib-svr4.c (enable_break): Pass down target. * spu-multiarch.c (parse_spufs_run): Pass down target. * spu-tdep.c (spu2ppu_sniffer): Pass down target. * target-delegates.c: Regenerate. * target.c (g_target_stack): Delete. (current_top_target): Return the current inferior's top target. (target_has_execution_1): Refer to the passed-in inferior's top target. (target_supports_terminal_ours): Check whether the initial inferior was already created. (decref_target): New. (target_stack::push): Incref/decref the target. (push_target, push_target, unpush_target): Adjust. (target_stack::unpush): Defref target. (target_is_pushed): Return bool. Adjust to refer to the current inferior's target stack. (dispose_inferior): Delete, and inline parts ... (target_preopen): ... here. Only dispose of the current inferior. (target_detach): Hold strong target reference while detaching. Pass target down. (target_thread_name): Add assertion. (target_resume): Pass down target. (target_ops::beneath, find_target_at): Adjust to refer to the current inferior's target stack. (get_dummy_target): New. (target_pass_ctrlc): Pass the Ctrl-C to the first inferior that has a thread running. (initialize_targets): Rename to ... (_initialize_target): ... this. * target.h: Include "gdbsupport/refcounted-object.h". (struct target_ops): Inherit refcounted_object. (target_ops::shortname, target_ops::longname): Make const. (target_ops::async_wait_fd): New method. (decref_target): Declare. (struct target_ops_ref_policy): New. (target_ops_ref): New typedef. (get_dummy_target): Declare function. (target_is_pushed): Return bool. * thread-iter.c (all_matching_threads_iterator::m_inf_matches) (all_matching_threads_iterator::all_matching_threads_iterator): Handle filter target. * thread-iter.h (struct all_matching_threads_iterator, struct all_matching_threads_range, class all_non_exited_threads_range): Filter by target too. Remove explicit. * thread.c (threads_executing): Delete. (inferior_thread): Pass down current inferior. (clear_thread_inferior_resources): Pass down thread pointer instead of ptid_t. (add_thread_silent, add_thread_with_info, add_thread): Add process_stratum_target parameter. Use it for thread and inferior searches. (is_current_thread): New. (thread_info::deletable): Use it. (find_thread_ptid, thread_count, in_thread_list) (thread_change_ptid, set_resumed, set_running): New process_stratum_target parameter. Pass it down. (set_executing): New process_stratum_target parameter. Pass it down. Adjust reference to 'threads_executing'. (threads_are_executing): New process_stratum_target parameter. Adjust reference to 'threads_executing'. (set_stop_requested, finish_thread_state): New process_stratum_target parameter. Pass it down. (switch_to_thread): Also match inferior. (switch_to_thread): New process_stratum_target parameter. Pass it down. (update_threads_executing): Reimplement. * top.c (quit_force): Pop targets from all inferior. (gdb_init): Don't call initialize_targets. * windows-nat.c (windows_nat_target) <get_windows_debug_event>: Declare. (windows_add_thread, windows_delete_thread): Adjust. (get_windows_debug_event): Rename to ... (windows_nat_target::get_windows_debug_event): ... this. Adjust. * tracefile-tfile.c (tfile_target_open): Pass down target. * gdbsupport/common-gdbthread.h (struct process_stratum_target): Forward declare. (switch_to_thread): Add process_stratum_target parameter. * mi/mi-interp.c (mi_on_resume_1): Add process_stratum_target parameter. Use it. (mi_on_resume): Pass target down. * nat/fork-inferior.c (startup_inferior): Add process_stratum_target parameter. Pass it down. * nat/fork-inferior.h (startup_inferior): Add process_stratum_target parameter. * python/py-threadevent.c (py_get_event_thread): Pass target down. gdb/gdbserver/ChangeLog: 2020-01-10 Pedro Alves <palves@redhat.com> * fork-child.c (post_fork_inferior): Pass target down to startup_inferior. * inferiors.c (switch_to_thread): Add process_stratum_target parameter. * lynx-low.c (lynx_target_ops): Now a process_stratum_target. * nto-low.c (nto_target_ops): Now a process_stratum_target. * linux-low.c (linux_target_ops): Now a process_stratum_target. * remote-utils.c (prepare_resume_reply): Pass the target to switch_to_thread. * target.c (the_target): Now a process_stratum_target. (done_accessing_memory): Pass the target to switch_to_thread. (set_target_ops): Ajust to use process_stratum_target. * target.h (struct target_ops): Rename to ... (struct process_stratum_target): ... this. (the_target, set_target_ops): Adjust. (prepare_to_access_memory): Adjust comment. * win32-low.c (child_xfer_memory): Adjust to use process_stratum_target. (win32_target_ops): Now a process_stratum_target.
2020-01-10 21:06:08 +01:00
return all_non_exited_inferiors_range (proc_target);
Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc. As preparation for multi-target, this patch makes each inferior have its own thread list. This isn't absolutely necessary for multi-target, but simplifies things. It originally stemmed from the desire to eliminate the init_thread_list calls sprinkled around, plus it makes it more efficient to iterate over threads of a given inferior (no need to always iterate over threads of all inferiors). We still need to iterate over threads of all inferiors in a number of places, which means we'd need adjust the ALL_THREADS / ALL_NON_EXITED_THREADS macros. However, naively tweaking those macros to have an extra for loop, like: #define ALL_THREADS (thr, inf) \ for (inf = inferior_list; inf; inf = inf->next) \ for (thr = inf->thread_list; thr; thr = thr->next) causes problems with code that does "break" or "continue" within the ALL_THREADS loop body. Plus, we need to declare the extra "inf" local variable in order to pass it as temporary variable to ALL_THREADS (etc.) It gets even trickier when we consider extending the macros to filter out threads matching a ptid_t and a target. The macros become tricker to read/write. Been there. An alternative (which was my next attempt), is to replace the ALL_THREADS etc. iteration style with for_each_all_threads, for_each_non_exited_threads, etc. functions which would take a callback as parameter, which would usually be passed a lambda. However, I did not find that satisfactory at all, because the resulting code ends up a little less natural / more noisy to read, write and debug/step-through (due to use of lambdas), and in many places where we use "continue;" to skip to the next thread now need to use "return;". (I ran into hard to debug bugs caused by a continue/return confusion.) I.e., before: ALL_NON_EXITED_THREADS (tp) { if (tp->not_what_I_want) continue; // do something } would turn into: for_each_non_exited_thread ([&] (thread_info *tp) { if (tp->not_what_I_want) return; // do something }); Lastly, the solution I settled with was to replace the ALL_THREADS / ALL_NON_EXITED_THREADS / ALL_INFERIORS macros with (C++20-like) ranges and iterators, such that you can instead naturaly iterate over threads/inferiors using range-for, like e.g,.: // all threads, including THREAD_EXITED threads. for (thread_info *tp : all_threads ()) { .... } // all non-exited threads. for (thread_info *tp : all_non_exited_threads ()) { .... } // all non-exited threads of INF inferior. for (thread_info *tp : inf->non_exited_threads ()) { .... } The all_non_exited_threads() function takes an optional filter ptid_t as parameter, which is quite convenient when we need to iterate over threads matching that filter. See e.g., how the set_executing/set_stop_requested/finish_thread_state etc. functions in thread.c end up being simplified. Most of the patch thus is about adding the infrustructure for allowing the above. Later on when we get to actual multi-target, these functions/ranges/iterators will gain a "target_ops *" parameter so that e.g., we can iterate over all threads of a given target that match a given filter ptid_t. The only entry points users needs to be aware of are the all_threads/all_non_exited_threads etc. functions seen above. Thus, those functions are declared in gdbthread.h/inferior.h. The actual iterators/ranges are mainly "internals" and thus are put out of view in the new thread-iter.h/thread-iter.c/inferior-iter.h files. That keeps the gdbthread.h/inferior.h headers quite a bit more readable. A common/safe-iterator.h header is added which adds a template that can be used to build "safe" iterators, which are forward iterators that can be used to replace the ALL_THREADS_SAFE macro and other instances of the same idiom in future. There's a little bit of shuffling of code between gdbthread.h/thread.c/inferior.h in the patch. That is necessary in order to avoid circular dependencies between the gdbthread.h/inferior.h headers. As for the init_thread_list calls sprinkled around, they're all eliminated by this patch, and a new, central call is added to inferior_appeared. Note how also related to that, there's a call to init_wait_for_inferior in remote.c that is eliminated. init_wait_for_inferior is currently responsible for discarding skipped inline frames, which had to be moved elsewhere. Given that nowadays we always have a thread even for single-threaded processes, the natural place is to delete a frame's inline frame info when we delete the thread. I.e., from clear_thread_inferior_resources. gdb/ChangeLog: 2018-11-22 Pedro Alves <palves@redhat.com> * Makefile.in (COMMON_SFILES): Add thread-iter.c. * breakpoint.c (breakpoints_should_be_inserted_now): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (print_one_breakpoint_location): Replace ALL_INFERIORS with all_inferiors. * bsd-kvm.c: Include inferior.h. * btrace.c (btrace_free_objfile): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * common/filtered-iterator.h: New. * common/safe-iterator.h: New. * corelow.c (core_target_open): Don't call init_thread_list here. * darwin-nat.c (thread_info_from_private_thread_info): Replace ALL_THREADS with all_threads. * fbsd-nat.c (fbsd_nat_target::resume): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fbsd-tdep.c (fbsd_make_corefile_notes): Replace ALL_NON_EXITED_THREADS with inf->non_exited_threads. * fork-child.c (postfork_hook): Don't call init_thread_list here. * gdbarch-selftests.c (register_to_value_test): Adjust. * gdbthread.h: Don't include "inferior.h" here. (struct inferior): Forward declare. (enum step_over_calls_kind): Moved here from inferior.h. (thread_info::deletable): Definition moved to thread.c. (find_thread_ptid (inferior *, ptid_t)): Declare. (ALL_THREADS, ALL_THREADS_BY_INFERIOR, ALL_THREADS_SAFE): Delete. Include "thread-iter.h". (all_threads, all_non_exited_threads, all_threads_safe): New. (any_thread_p): Declare. (thread_list): Delete. * infcmd.c (signal_command): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. (proceed_after_attach_callback): Delete. (proceed_after_attach): Take an inferior pointer instead of an integer PID. Adjust to use range-for. (attach_post_wait): Pass down inferior pointer instead of pid. Use range-for instead of ALL_NON_EXITED_THREADS. (detach_command): Remove init_thread_list call. * inferior-iter.h: New. * inferior.c (struct delete_thread_of_inferior_arg): Delete. (delete_thread_of_inferior): Delete. (delete_inferior, exit_inferior_1): Use range-for with inf->threads_safe() instead of iterate_over_threads. (inferior_appeared): Call init_thread_list here. (discard_all_inferiors): Use all_non_exited_inferiors. (find_inferior_id, find_inferior_pid): Use all_inferiors. (iterate_over_inferiors): Use all_inferiors_safe. (have_inferiors, number_of_live_inferiors): Use all_non_exited_inferiors. (number_of_inferiors): Use all_inferiors and std::distance. (print_inferior): Use all_inferiors. * inferior.h: Include gdbthread.h. (enum step_over_calls_kind): Moved to gdbthread.h. (struct inferior) <thread_list>: New field. <threads, non_exited_threads, threads_safe>: New methods. (ALL_INFERIORS): Delete. Include "inferior-iter.h". (ALL_NON_EXITED_INFERIORS): Delete. (all_inferiors_safe, all_inferiors, all_non_exited_inferiors): New functions. * inflow.c (child_interrupt, child_pass_ctrlc): Replace ALL_NON_EXITED_THREADS with all_non_exited_threads. * infrun.c (follow_exec): Use all_threads_safe. (clear_proceed_status, proceed): Use all_non_exited_threads. (init_wait_for_inferior): Don't clear inline frame state here. (infrun_thread_stop_requested, for_each_just_stopped_thread): Use all_threads instead of ALL_NON_EXITED_THREADS. (random_pending_event_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use a lambda for repeated code. (clean_up_just_stopped_threads_fsms): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (handle_no_resumed): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Use all_inferiors instead of ALL_INFERIORS. (restart_threads, switch_back_to_stepped_thread): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-nat.c (check_zombie_leaders): Replace ALL_INFERIORS with all_inferiors. (kill_unfollowed_fork_children): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-tdep.c (linux_make_corefile_notes): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * linux-thread-db.c (thread_db_target::update_thread_list): Replace ALL_INFERIORS with all_inferiors. (thread_db_target::thread_handle_to_thread_info): Use inf->non_exited_threads instead of ALL_NON_EXITED_THREADS. * mi/mi-interp.c (multiple_inferiors_p): New. (mi_on_resume_1): Simplify using all_non_exited_threads and multiple_inferiors_p. * mi/mi-main.c (mi_cmd_thread_list_ids): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * nto-procfs.c (nto_procfs_target::open): Don't call init_thread_list here. * record-btrace.c (record_btrace_target_open) (record_btrace_target::stop_recording) (record_btrace_target::close) (record_btrace_target::record_is_replaying) (record_btrace_target::resume, record_btrace_target::wait) (record_btrace_target::record_stop_replaying): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * record-full.c (record_full_wait_1): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * regcache.c (cooked_read_test): Remove reference to global thread_list. * remote-sim.c (gdbsim_target::create_inferior): Don't call init_thread_list here. * remote.c (remote_target::update_thread_list): Use all_threads_safe instead of ALL_NON_EXITED_THREADS. (remote_target::process_initial_stop_replies): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::open_1): Don't call init_thread_list here. (remote_target::append_pending_thread_resumptions) (remote_target::remote_resume_with_hc): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::commit_resume) (remote_target::remove_new_fork_children): Replace ALL_INFERIORS with all_non_exited_inferiors and use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. (remote_target::kill_new_fork_children): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. Remove init_thread_list and init_wait_for_inferior calls. (remote_target::remote_btrace_maybe_reopen) (remote_target::thread_handle_to_thread_info): Use all_non_exited_threads instead of ALL_NON_EXITED_THREADS. * target.c (target_terminal::restore_inferior) (target_terminal_is_ours_kind): Replace ALL_INFERIORS with all_non_exited_inferiors. * thread-iter.c: New file. * thread-iter.h: New file. * thread.c: Include "inline-frame.h". (thread_list): Delete. (clear_thread_inferior_resources): Call clear_inline_frame_state. (init_thread_list): Use all_threads_safe instead of ALL_THREADS_SAFE. Adjust to per-inferior thread lists. (new_thread): Adjust to per-inferior thread lists. (add_thread_silent): Pass inferior to find_thread_ptid. (thread_info::deletable): New, moved from the header. (delete_thread_1): Adjust to per-inferior thread lists. (find_thread_global_id): Use inf->threads(). (find_thread_ptid): Use find_inferior_ptid and pass inferior to find_thread_ptid. (find_thread_ptid(inferior*, ptid_t)): New overload. (iterate_over_threads): Use all_threads_safe. (any_thread_p): New. (thread_count): Use all_threads and std::distance. (live_threads_count): Use all_non_exited_threads and std::distance. (valid_global_thread_id): Use all_threads. (in_thread_list): Use find_thread_ptid. (first_thread_of_inferior): Adjust to per-inferior thread lists. (any_thread_of_inferior, any_live_thread_of_inferior): Use inf->non_exited_threads(). (prune_threads, delete_exited_threads): Use all_threads_safe. (thread_change_ptid): Pass inferior pointer to find_thread_ptid. (set_resumed, set_running): Use all_non_exited_threads. (is_thread_state, is_stopped, is_exited, is_running) (is_executing): Delete. (set_executing, set_stop_requested, finish_thread_state): Use all_non_exited_threads. (print_thread_info_1): Use all_inferiors and all_threads. (thread_apply_all_command): Use all_non_exited_threads. (thread_find_command): Use all_threads. (update_threads_executing): Use all_non_exited_threads. * tid-parse.c (parse_thread_id): Use inf->threads. * x86-bsd-nat.c (x86bsd_dr_set): Use inf->non_exited_threads ().
2018-11-22 17:09:14 +01:00
}
2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> Add base multi-executable/process support to GDB. gdb/ * Makefile.in (SFILES): Add progspace.c. (COMMON_OBS): Add progspace.o. * progspace.h: New. * progspace.c: New. * breakpoint.h (struct bp_target_info) <placed_address_space>: New field. (struct bp_location) <pspace>: New field. (struct breakpoint) <pspace>: New field. (bpstat_stop_status, breakpoint_here_p) (moribund_breakpoint_here_p, breakpoint_inserted_here_p) (regular_breakpoint_inserted_here_p) (software_breakpoint_inserted_here_p, breakpoint_thread_match) (set_default_breakpoint): Adjust prototypes. (remove_breakpoints_pid, breakpoint_program_space_exit): Declare. (insert_single_step_breakpoint, deprecated_insert_raw_breakpoint): Adjust prototypes. * breakpoint.c (executing_startup): Delete. (default_breakpoint_sspace): New. (breakpoint_restore_shadows): Skip if the address space doesn't match. (update_watchpoint): Record the frame's program space in the breakpoint location. (insert_bp_location): Record the address space in target_info. Adjust to pass the symbol space to solib_name_from_address. (breakpoint_program_space_exit): New. (insert_breakpoint_locations): Switch the symbol space and thread when inserting breakpoints. Don't insert breakpoints in a vfork parent waiting for vfork done if we're not attached to the vfork child. (remove_breakpoints_pid): New. (reattach_breakpoints): Switch to a thread of PID. Ignore breakpoints of other symbol spaces. (create_internal_breakpoint): Store the symbol space in the sal. (create_longjmp_master_breakpoint): Iterate over all symbol spaces. (update_breakpoints_after_exec): Ignore breakpoints for other symbol spaces. (remove_breakpoint): Rename to ... (remove_breakpoint_1): ... this. Pass the breakpoints symbol space to solib_name_from_address. (remove_breakpoint): New. (mark_breakpoints_out): Ignore breakpoints from other symbol spaces. (breakpoint_init_inferior): Ditto. (breakpoint_here_p): Add an address space argument and adjust to use breakpoint_address_match. (moribund_breakpoint_here_p): Ditto. (regular_breakpoint_inserted_here_p): Ditto. (breakpoint_inserted_here_p): Ditto. (software_breakpoint_inserted_here_p): Ditto. (breakpoint_thread_match): Ditto. (bpstat_check_location): Ditto. (bpstat_stop_status): Ditto. (print_breakpoint_location): If there's a location to print, switch the current symbol space. (print_one_breakpoint_location): Add `allflag' argument. (print_one_breakpoint): Ditto. Adjust. (do_captured_breakpoint_query): Adjust. (breakpoint_1): Adjust. (breakpoint_has_pc): Also match the symbol space. (describe_other_breakpoints): Add a symbol space argument and adjust. (set_default_breakpoint): Add a symbol space argument. Set default_breakpoint_sspace. (breakpoint_address_match): New. (check_duplicates_for): Add an address space argument, and adjust. (set_raw_breakpoint): Record the symbol space in the location and in the breakpoint. (set_longjmp_breakpoint): Skip longjmp master breakpoints from other symbol spaces. (remove_thread_event_breakpoints, remove_solib_event_breakpoints) (disable_breakpoints_in_shlibs): Skip breakpoints from other symbol spaces. (disable_breakpoints_in_unloaded_shlib): Match symbol spaces. (create_catchpoint): Set the symbol space in the sal. (disable_breakpoints_before_startup): Skip breakpoints from other symbol spaces. Set executing_startup in the current symbol space. (enable_breakpoints_after_startup): Clear executing_startup in the current symbol space. Skip breakpoints from other symbol spaces. (clone_momentary_breakpoint): Also copy the symbol space. (add_location_to_breakpoint): Set the location's symbol space. (bp_loc_is_permanent): Switch thread and symbol space. (create_breakpoint): Adjust. (expand_line_sal_maybe): Expand comment to mention symbol spaces. Switch thread and symbol space when reading memory. (parse_breakpoint_sals): Set the symbol space in the sal. (break_command_really): Ditto. (skip_prologue_sal): Switch and space. (resolve_sal_pc): Ditto. (watch_command_1): Record the symbol space in the sal. (create_ada_exception_breakpoint): Adjust. (clear_command): Adjust. Match symbol spaces. (update_global_location_list): Use breakpoint_address_match. (breakpoint_re_set_one): Switch thread and space. (breakpoint_re_set): Save symbol space. (breakpoint_re_set_thread): Also reset the symbol space. (deprecated_insert_raw_breakpoint): Add an address space argument. Adjust. (insert_single_step_breakpoint): Ditto. (single_step_breakpoint_inserted_here_p): Ditto. (clear_syscall_counts): New. (_initialize_breakpoint): Install it as inferior_exit observer. * exec.h: Include "progspace.h". (exec_bfd, exec_bfd_mtime): New defines. (exec_close): Declare. * exec.c: Include "gdbthread.h" and "progspace.h". (exec_bfd, exec_bfd_mtime, current_target_sections_1): Delete. (using_exec_ops): New. (exec_close_1): Rename to exec_close, and make public. (exec_close): Rename to exec_close_1, and adjust all callers. Add description. Remove target sections and close executables from all program spaces. (exec_file_attach): Add comment. (add_target_sections): Check on `using_exec_ops' to check if the target should be pushed. (remove_target_sections): Only unpush the target if there are no more target sections in any symbol space. * gdbcore.h: Include "exec.h". (exec_bfd, exec_bfd_mtime): Remove declarations. * frame.h (get_frame_program_space, get_frame_address_space) (frame_unwind_program_space): Declare. * frame.c (struct frame_info) <pspace, aspace>: New fields. (create_sentinel_frame): Add program space argument. Set the pspace and aspace fields of the frame object. (get_current_frame, create_new_frame): Adjust. (get_frame_program_space): New. (frame_unwind_program_space): New. (get_frame_address_space): New. * stack.c (print_frame_info): Adjust. (print_frame): Use the frame's program space. * gdbthread.h (any_live_thread_of_process): Declare. * thread.c (any_live_thread_of_process): New. (switch_to_thread): Switch the program space as well. (restore_selected_frame): Don't warn if trying to restore frame level 0. * inferior.h: Include "progspace.h". (detach_fork): Declare. (struct inferior) <removable, aspace, pspace> <vfork_parent, vfork_child, pending_detach> <waiting_for_vfork_done>: New fields. <terminal_info>: Remove field. <data, num_data>: New fields. (register_inferior_data, register_inferior_data_with_cleanup) (clear_inferior_data, set_inferior_data, inferior_data): Declare. (exit_inferior, exit_inferior_silent, exit_inferior_num_silent) (inferior_appeared): Declare. (find_inferior_pid): Typo. (find_inferior_id, find_inferior_for_program_space): Declare. (set_current_inferior, save_current_inferior, prune_inferiors) (number_of_inferiors): Declare. (inferior_list): Declare. * inferior.c: Include "gdbcore.h" and "symfile.h". (inferior_list): Make public. (delete_inferior_1): Always delete thread silently. (find_inferior_id): Make public. (current_inferior_): New. (current_inferior): Use it. (set_current_inferior): New. (restore_inferior): New. (save_current_inferior): New. (free_inferior): Free the per-inferior data. (add_inferior_silent): Allocate per-inferior data. Call inferior_appeared. (delete_threads_of_inferior): New. (delete_inferior_1): Adjust interface to take an inferior pointer. (delete_inferior): Adjust. (delete_inferior_silent): Adjust. (exit_inferior_1): New. (exit_inferior): New. (exit_inferior_silent): New. (exit_inferior_num_silent): New. (detach_inferior): Adjust. (inferior_appeared): New. (discard_all_inferiors): Adjust. (find_inferior_id): Make public. Assert pid is not zero. (find_inferior_for_program_space): New. (have_inferiors): Check if we have any inferior with pid not zero. (have_live_inferiors): Go over all pushed targets looking for process_stratum. (prune_inferiors): New. (number_of_inferiors): New. (print_inferior): Add executable column. Print vfork parent/child relationships. (inferior_command): Adjust to cope with not running inferiors. (remove_inferior_command): New. (add_inferior_command): New. (clone_inferior_command): New. (struct inferior_data): New. (struct inferior_data_registration): New. (struct inferior_data_registry): New. (inferior_data_registry): New. (register_inferior_data_with_cleanup): New. (register_inferior_data): New. (inferior_alloc_data): New. (inferior_free_data): New. (clear_inferior_data): New. (set_inferior_data): New. (inferior_data): New. (initialize_inferiors): New. (_initialize_inferiors): Register "add-inferior", "remove-inferior" and "clone-inferior" commands. * objfiles.h: Include "progspace.h". (struct objfile) <pspace>: New field. (symfile_objfile, object_files): Don't declare. (ALL_PSPACE_OBJFILES): New. (ALL_PSPACE_OBJFILES_SAFE): New. (ALL_OBJFILES, ALL_OBJFILES_SAFE): Adjust. (ALL_PSPACE_SYMTABS): New. (ALL_PRIMARY_SYMTABS): Adjust. (ALL_PSPACE_PRIMARY_SYMTABS): New. (ALL_PSYMTABS): Adjust. (ALL_PSPACE_PSYMTABS): New. * objfiles.c (object_files, symfile_objfile): Delete. (struct objfile_sspace_info): New. (objfiles_pspace_data): New. (objfiles_pspace_data_cleanup): New. (get_objfile_pspace_data): New. (objfiles_changed_p): Delete. (allocate_objfile): Set the objfile's program space. Adjust to reference objfiles_changed_p in pspace data. (free_objfile): Adjust to reference objfiles_changed_p in pspace data. (objfile_relocate): Ditto. (update_section_map): Add pspace argument. Adjust to iterate over objfiles in the passed in pspace. (find_pc_section): Delete sections and num_sections statics. Adjust to refer to program space's objfiles_changed_p. Adjust to refer to sections and num_sections store in the objfile's pspace data. (objfiles_changed): Adjust to reference objfiles_changed_p in pspace data. (_initialize_objfiles): New. * linespec.c (decode_all_digits, decode_dollar): Set the sal's program space. * source.c (current_source_pspace): New. (get_current_source_symtab_and_line): Set the sal's program space. (set_current_source_symtab_and_line): Set current_source_pspace. (select_source_symtab): Ditto. Use ALL_OBJFILES. (forget_cached_source_info): Iterate over all program spaces. * symfile.c (clear_symtab_users): Adjust. * symmisc.c (print_symbol_bcache_statistics): Iterate over all program spaces. (print_objfile_statistics): Ditto. (maintenance_print_msymbols): Ditto. (maintenance_print_objfiles): Ditto. (maintenance_info_symtabs): Ditto. (maintenance_info_psymtabs): Ditto. * symtab.h (SYMTAB_PSPACE): New. (struct symtab_and_line) <pspace>: New field. * symtab.c (init_sal): Clear the sal's program space. (find_pc_sect_symtab): Set the sal's program space. Switch thread and space. (append_expanded_sal): Add program space argument. Iterate over all program spaces. (expand_line_sal): Iterate over all program spaces. Switch program space. * target.h (enum target_waitkind) <TARGET_WAITKIND_VFORK_DONE>: New. (struct target_ops) <to_thread_address_space>: New field. (target_thread_address_space): Define. * target.c (target_detach): Only remove breakpoints from the inferior we're detaching. (target_thread_address_space): New. * defs.h (initialize_progspace): Declare. * top.c (gdb_init): Call it. * solist.h (struct so_list) <sspace>: New field. * solib.h (struct program_space): Forward declare. (solib_name_from_address): Adjust prototype. * solib.c (so_list_head): Replace with a macro referencing the program space. (update_solib_list): Set the so's program space. (solib_name_from_address): Add a program space argument and adjust. * solib-svr4.c (struct svr4_info) <pid>: Delete field. <interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low> <interp_plt_sect_high>: New fields. (svr4_info_p, svr4_info): Delete. (solib_svr4_sspace_data): New. (get_svr4_info): Rewrite. (svr4_sspace_data_cleanup): New. (open_symbol_file_object): Adjust. (svr4_default_sos): Adjust. (svr4_fetch_objfile_link_map): Adjust. (interp_text_sect_low, interp_text_sect_high, interp_plt_sect_low) (interp_plt_sect_high): Delete. (svr4_in_dynsym_resolve_code): Adjust. (enable_break): Adjust. (svr4_clear_solib): Revert bit that removed the svr4_info here, and reinstate clearing debug_base, debug_loader_offset_p, debug_loader_offset and debug_loader_name. (_initialize_svr4_solib): Register solib_svr4_pspace_data. Don't install an inferior_exit observer anymore. * printcmd.c (struct display) <pspace>: New field. (display_command): Set the display's sspace. (do_one_display): Match the display's sspace. (display_uses_solib_p): Ditto. * linux-fork.c (detach_fork): Moved to infrun.c. (_initialize_linux_fork): Moved "detach-on-fork" command to infrun.c. * infrun.c (detach_fork): Moved from linux-fork.c. (proceed_after_vfork_done): New. (handle_vfork_child_exec_or_exit): New. (follow_exec_mode_replace, follow_exec_mode_keep) (follow_exec_mode_names, follow_exec_mode_string) (show_follow_exec_mode_string): New. (follow_exec): New. Reinstate the mark_breakpoints_out call. Remove shared libraries before attaching new executable. If user wants to keep the inferior, keep it. (displaced_step_fixup): Adjust to pass an address space to the breakpoints module. (resume): Ditto. (clear_proceed_status): In all-stop mode, always clear the proceed status of all threads. (prepare_to_proceed): Adjust to pass an address space to the breakpoints module. (proceed): Ditto. (adjust_pc_after_break): Ditto. (handle_inferior_event): When handling a process exit, switch the program space to the inferior's that had exited. Call handle_vfork_child_exec_or_exit. Adjust to pass an address space to the breakpoints module. In non-stop mode, when following a fork and detach-fork is off, also resume the other branch. Handle TARGET_WAITKIND_VFORK_DONE. Set the program space in sals. (normal_stop): Prune inferiors. (_initialize_infrun): Install the new "follow-exec-mode" command. "detach-on-fork" moved here. * regcache.h (get_regcache_aspace): Declare. * regcache.c (struct regcache) <aspace>: New field. (regcache_xmalloc): Clear the aspace. (get_regcache_aspace): New. (regcache_cpy): Copy the aspace field. (regcache_cpy_no_passthrough): Ditto. (get_thread_regcache): Fetch the thread's address space from the target, and store it in the regcache. * infcall.c (call_function_by_hand): Set the sal's pspace. * arch-utils.c (default_has_shared_address_space): New. * arch-utils.h (default_has_shared_address_space): Declare. * gdbarch.sh (has_shared_address_space): New. * gdbarch.h, gdbarch.c: Regenerate. * linux-tdep.c: Include auxv.h, target.h, elf/common.h. (linux_has_shared_address_space): New. (_initialize_linux_tdep): Declare. * arm-tdep.c (arm_software_single_step): Pass the frame's address space to insert_single_step_breakpoint. * arm-linux-tdep.c (arm_linux_software_single_step): Pass the frame's pspace to breakpoint functions. * cris-tdep.c (crisv32_single_step_through_delay): Ditto. (cris_software_single_step): Ditto. * mips-tdep.c (deal_with_atomic_sequence): Add frame argument. Pass the frame's pspace to breakpoint functions. (mips_software_single_step): Adjust. (mips_single_step_through_delay): Adjust. * rs6000-aix-tdep.c (rs6000_software_single_step): Adjust. * rs6000-tdep.c (ppc_deal_with_atomic_sequence): Adjust. * solib-irix.c (enable_break): Adjust to pass the current frame's address space to breakpoint functions. * sparc-tdep.c (sparc_software_single_step): Ditto. * spu-tdep.c (spu_software_single_step): Ditto. * alpha-tdep.c (alpha_software_single_step): Ditto. * record.c (record_wait): Adjust to pass an address space to the breakpoints module. * fork-child.c (fork_inferior): Set the new inferior's program and address spaces. * inf-ptrace.c (inf_ptrace_follow_fork): Copy the parent's program and address spaces. (inf_ptrace_attach): Set the inferior's program and address spaces. * linux-nat.c: Include "solib.h". (linux_child_follow_fork): Manage parent and child's program and address spaces. Clone the parent's program space if necessary. Don't wait for the vfork to be done here. Refuse to resume if following the vfork parent while leaving the child stopped. (resume_callback): Don't resume a vfork parent. (linux_nat_resume): Also check for pending events in the lp->waitstatus field. (linux_handle_extended_wait): Report TARGET_WAITKIND_VFORK_DONE events to the core. (stop_wait_callback): Don't wait for SIGSTOP on vfork parents. (cancel_breakpoint): Adjust. * linux-thread-db.c (thread_db_wait): Don't remove thread event breakpoints here. (thread_db_mourn_inferior): Don't mark breakpoints out here. Remove thread event breakpoints after mourning. * corelow.c: Include progspace.h. (core_open): Set the inferior's program and address spaces. * remote.c (remote_add_inferior): Set the new inferior's program and address spaces. (remote_start_remote): Update address spaces. (extended_remote_create_inferior_1): Don't init the thread list if we already debugging other inferiors. * darwin-nat.c (darwin_attach): Set the new inferior's program and address spaces. * gnu-nat.c (gnu_attach): Ditto. * go32-nat.c (go32_create_inferior): Ditto. * inf-ttrace.c (inf_ttrace_follow_fork, inf_ttrace_attach): Ditto. * monitor.c (monitor_open): Ditto. * nto-procfs.c (procfs_attach, procfs_create_inferior): Ditto. * procfs.c (do_attach): Ditto. * windows-nat.c (do_initial_windows_stuff): Ditto. * inflow.c (inferior_process_group) (terminal_init_inferior_with_pgrp, terminal_inferior, (terminal_ours_1, inflow_inferior_exit, copy_terminal_info) (child_terminal_info, new_tty_postfork, set_sigint_trap): Adjust to use per-inferior data instead of inferior->terminal_info. (inflow_inferior_data): New. (inflow_new_inferior): Delete. (inflow_inferior_data_cleanup): New. (get_inflow_inferior_data): New. * mi/mi-interp.c (mi_new_inferior): Rename to... (mi_inferior_appeared): ... this. (mi_interpreter_init): Adjust. * tui/tui-disasm.c: Include "progspace.h". (tui_set_disassem_content): Pass an address space to breakpoint_here_p. * NEWS: Mention multi-program debugging support. Mention new commands "add-inferior", "clone-inferior", "remove-inferior", "maint info program-spaces", and new option "set follow-exec-mode". 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * observer.texi (new_inferior): Rename to... (inferior_appeared): ... this. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/testsuite/ * gdb.base/foll-vfork.exp: Adjust to spell out "follow-fork". * gdb.base/foll-exec.exp: Adjust to expect a process id before "Executing new program". * gdb.base/foll-fork.exp: Adjust to spell out "follow-fork". * gdb.base/multi-forks.exp: Ditto. Adjust to the inferior being left listed after having been killed. * gdb.base/attach.exp: Adjust to spell out "symbol-file". * gdb.base/maint.exp: Adjust test. * Makefile.in (ALL_SUBDIRS): Add gdb.multi. * gdb.multi/Makefile.in: New. * gdb.multi/base.exp: New. * gdb.multi/goodbye.c: New. * gdb.multi/hangout.c: New. * gdb.multi/hello.c: New. * gdb.multi/bkpt-multi-exec.c: New. * gdb.multi/bkpt-multi-exec.exp: New. * gdb.multi/crashme.c: New. 2009-10-19 Pedro Alves <pedro@codesourcery.com> Stan Shebs <stan@codesourcery.com> gdb/doc/ * gdb.texinfo (Inferiors): Rename node to ... (Inferiors and Programs): ... this. Mention running multiple programs in the same debug session. <info inferiors>: Mention the new 'Executable' column if "info inferiors". Update examples. Document the "add-inferior", "clone-inferior", "remove-inferior" and "maint info program-spaces" commands. (Process): Rename node to... (Forks): ... this. Document "set|show follow-exec-mode".
2009-10-19 11:51:43 +02:00
/* Prune away automatically added inferiors that aren't required
anymore. */
extern void prune_inferiors (void);
extern int number_of_inferiors (void);
Multiexec MI * breakpoint.c (clear_syscall_counts): Take struct inferior*. * inferior.c (add_inferior_silent): Notify inferior_added observer. (delete_inferior_1): Notify inferior_removed observer. (exit_inferior_1): Pass inferior, not pid, to observer. (inferior_appeared): Likewise. (add_inferior_with_spaces): New. (add_inferior_command): Use the above. * inferior.h (delete_inferior_1, add_inferior_with_spaces): Declare. * inflow.c (inflow_inferior_exit): Likewise. * jit.c (jit_inferior_exit_hook): Likewise. * mi/mi-cmds.c (mi_cmds): Register add-inferior and remove-inferior. * mi/mi-cmds.h (mi_cmd_add_inferior, mi_cmd_remove_inferior): New. * mi/mi-interp.c (mi_inferior_added, mi_inferior_removed): New. (report_initial_inferior): New. (mi_inferior_removed): Register the above. Make sure inferior_added observer is called on the first inferior. (mi_new_thread, mi_thread_exit): Thread group is now identified by inferior number, not pid. (mi_solib_loaded, mi_solib_unloaded): Report which inferiors are affected. * mi/mi-main.c (current_context): New. (proceed_thread_callback): Use typed closure. Proceed everything if pid is 0. Most implementation split into (proceed_thread): ... this. (run_one_inferior): New. (mi_cmd_exec_continue, mi_cmd_exec_interrupt, mi_cmd_exec_run): Adjust for multiexec behaviour. (mi_cmd_add_inferior, mi_cmd_remove_inferior): New. (mi_cmd_execute): Handle the 'thread-group' option here. Do some extra checks. * mi-parse.c (mi_parse): Handle the --all and --thread-group options. * mi-parse.h (struct mi_parse): New fields all and thread_group.
2010-02-24 08:51:46 +01:00
extern struct inferior *add_inferior_with_spaces (void);
Emit inferior, thread and frame selection events to all UIs With this patch, when an inferior, thread or frame is explicitly selected by the user, notifications will appear on all CLI and MI UIs. When a GDB console is integrated in a front-end, this allows the front-end to follow a selection made by the user ont he CLI, and it informs the user about selection changes made behind the scenes by the front-end. This patch addresses PR gdb/20487. In order to communicate frame changes to the front-end, this patch adds a new field to the =thread-selected event for the selected frame. The idea is that since inferior/thread/frame can be seen as a composition, it makes sense to send them together in the same event. The vision would be to eventually send the inferior information as well, if we find that it's needed, although the "=thread-selected" event would be ill-named for that job. Front-ends need to handle this new field if they want to follow the frame selection changes that originate from the console. The format of the frame attribute is the same as what is found in the *stopped events. Here's a detailed example for each command and the events they generate: thread ------ 1. CLI command: thread 1.3 MI event: =thread-selected,id="3",frame={...} 2. MI command: -thread-select 3 CLI event: [Switching to thread 1.3 ...] 3. MI command (CLI-in-MI): thread 1.3 MI event/reply: &"thread 1.3\n" ~"#0 child_sub_function () ... =thread-selected,id="3",frame={level="0",...} ^done frame ----- 1. CLI command: frame 1 MI event: =thread-selected,id="3",frame={level="1",...} 2. MI command: -stack-select-frame 1 CLI event: #1 0x00000000004007f0 in child_function... 3. MI command (CLI-in-MI): frame 1 MI event/reply: &"frame 1\n" ~"#1 0x00000000004007f9 in ..." =thread-selected,id="3",frame={level="1"...} ^done inferior -------- Inferior selection events only go from the console to MI, since there's no way to select the inferior in pure MI. 1. CLI command: inferior 2 MI event: =thread-selected,id="3" Note that if the user selects an inferior that is not started or exited, the MI doesn't receive a notification. Since there is no threads to select, the =thread-selected event does not apply... 2. MI command (CLI-in-MI): inferior 2 MI event/reply: &"inferior 2\n" ~"[Switching to inferior 2 ...]" =thread-selected,id="4",frame={level="0"...} ^done Internal implementation detail: this patch makes it possible to suppress notifications caused by a CLI command, like what is done in mi-interp.c. This means that it's now possible to use the add_com_suppress_notification function to register a command with some event suppressed. It is used to implement the select-frame command in this patch. The function command_notifies_uscc_observer was added to extract the rather complicated logical expression from the if statement. It is also now clearer what that logic does: if the command used by the user already notifies the user_selected_context_changed observer, there is not need to notify it again. It therefore protects again emitting the event twice. No regressions, tested on ubuntu 14.04 x86 with target boards unix and native-extended-gdbserver. gdb/ChangeLog: YYYY-MM-DD Antoine Tremblay <antoine.tremblay@ericsson.com> YYYY-MM-DD Simon Marchi <simon.marchi@ericsson.com> PR gdb/20487 * NEWS: Mention new frame field of =thread-selected event. * cli/cli-decode.c (add_cmd): Initialize c->suppress_notification. (add_com_suppress_notification): New function definition. (cmd_func): Set and restore the suppress_notification flag. * cli/cli-deicode.h (struct cmd_list_element) <suppress_notification>: New field. * cli/cli-interp.c (cli_suppress_notification): New global variable. (cli_on_user_selected_context_changed): New function. (_initialize_cli_interp): Attach to user_selected_context_changed observer. * command.h (struct cli_suppress_notification): New structure. (cli_suppress_notification): New global variable declaration. (add_com_suppress_notification): New function declaration. * defs.h (enum user_selected_what_flag): New enum. (user_selected_what): New enum flag type. * frame.h (print_stack_frame_to_uiout): New function declaration. * gdbthread.h (print_selected_thread_frame): New function declaration. * inferior.c (print_selected_inferior): New function definition. (inferior_command): Remove printing of inferior/thread/frame switch notifications, notify user_selected_context_changed observer. * inferior.h (print_selected_inferior): New function declaration. * mi/mi-cmds.c (struct mi_cmd): Add user_selected_context suppression to stack-select-frame and thread-select commands. * mi/mi-interp.c (struct mi_suppress_notification) <user_selected_context>: Initialize. (mi_user_selected_context_changed): New function definition. (_initialize_mi_interp): Attach to user_selected_context_changed. * mi/mi-main.c (mi_cmd_thread_select): Print thread selection reply. (mi_execute_command): Handle notification suppression. Notify user_selected_context_changed observer on thread change instead of printing event directly. Don't send it if command already sends the notification. (command_notifies_uscc_observer): New function. (mi_cmd_execute): Don't handle notification suppression. * mi/mi-main.h (struct mi_suppress_notification) <user_selected_context>: New field. * stack.c (print_stack_frame_to_uiout): New function definition. (select_frame_command): Notify user_selected_context_changed observer. (frame_command): Call print_selected_thread_frame if there's no frame change or notify user_selected_context_changed observer if there is. (up_command): Notify user_selected_context_changed observer. (down_command): Likewise. (_initialize_stack): Suppress user_selected_context notification for command select-frame. * thread.c (thread_command): Notify user_selected_context_changed if the thread has changed, print thread info directly if it hasn't. (do_captured_thread_select): Do not print thread switch event. (print_selected_thread_frame): New function definition. * tui/tui-interp.c (tui_on_user_selected_context_changed): New function definition. (_initialize_tui_interp): Attach to user_selected_context_changed observer. gdb/doc/ChangeLog: PR gdb/20487 * gdb.texinfo (Context management): Update mention of frame change notifications. (gdb/mi Async Records): Document frame field in =thread-select event. * observer.texi (GDB Observers): New user_selected_context_changed observer. gdb/testsuite/ChangeLog: PR gdb/20487 * gdb.mi/mi-pthreads.exp (check_mi_thread_command_set): Adapt =thread-select-event check.
2016-10-03 22:52:44 +02:00
/* Print the current selected inferior. */
extern void print_selected_inferior (struct ui_out *uiout);
#endif /* !defined (INFERIOR_H) */