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 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 Alan Hayward <alan.hayward@arm.com>
* regcache.c (readable_regcache::read_part): Avoid memcpy when
static LONGEST
aarch64_linux_get_syscall_number (struct gdbarch *gdbarch,
- ptid_t ptid)
+ thread_info *thread)
{
- struct regcache *regs = get_thread_regcache (ptid);
+ struct regcache *regs = get_thread_regcache (thread);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
/* The content of register x8. */
extern struct ada_task_info *ada_get_task_info_from_ptid (ptid_t ptid);
-extern int ada_get_task_number (ptid_t);
+extern int ada_get_task_number (thread_info *thread);
typedef void (ada_task_list_iterator_ftype) (struct ada_task_info *task);
extern void iterate_over_live_ada_tasks
return data;
}
-/* Return the task number of the task whose ptid is PTID, or zero
+/* Return the task number of the task whose thread is THREAD, or zero
if the task could not be found. */
int
-ada_get_task_number (ptid_t ptid)
+ada_get_task_number (thread_info *thread)
{
int i;
- struct inferior *inf = find_inferior_ptid (ptid);
+ struct inferior *inf = thread->inf;
struct ada_tasks_inferior_data *data;
gdb_assert (inf != NULL);
for (i = 0; i < VEC_length (ada_task_info_s, data->task_list); i++)
if (ptid_equal (VEC_index (ada_task_info_s, data->task_list, i)->ptid,
- ptid))
+ thread->ptid))
return i + 1;
return 0; /* No matching task found. */
/* Print the associated Thread ID. */
if (uiout->is_mi_like_p ())
{
- const int thread_id = ptid_to_global_thread_id (task_info->ptid);
+ thread_info *thread = find_thread_ptid (task_info->ptid);
- if (thread_id != 0)
- uiout->field_int ("thread-id", thread_id);
+ if (thread != NULL)
+ uiout->field_int ("thread-id", thread->global_num);
else
/* This should never happen unless there is a bug somewhere,
but be resilient when that happens. */
static void
display_current_task_id (void)
{
- const int current_task = ada_get_task_number (inferior_ptid);
+ const int current_task = ada_get_task_number (inferior_thread ());
if (current_task == 0)
printf_filtered (_("[Current task is unknown]\n"));
computed if target_get_ada_task_ptid has not been implemented for
our target (yet). Rather than cause an assertion error in that case,
it's nicer for the user to just refuse to perform the task switch. */
- if (!find_thread_ptid (task_info->ptid))
+ thread_info *tp = find_thread_ptid (task_info->ptid);
+ if (tp == NULL)
error (_("Unable to compute thread ID for task %d.\n"
"Cannot switch to this task."),
taskno);
- switch_to_thread (task_info->ptid);
+ switch_to_thread (tp);
ada_find_printable_frame (get_selected_frame (NULL));
printf_filtered (_("[Switching to task %d]\n"), taskno);
print_stack_frame (get_selected_frame (NULL),
static LONGEST
amd64_linux_get_syscall_number (struct gdbarch *gdbarch,
- ptid_t ptid)
+ thread_info *thread)
{
- struct regcache *regcache = get_thread_regcache (ptid);
+ struct regcache *regcache = get_thread_regcache (thread);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
/* The content of a register. */
gdb_byte buf[8];
static LONGEST
arm_linux_get_syscall_number (struct gdbarch *gdbarch,
- ptid_t ptid)
+ thread_info *thread)
{
- struct regcache *regs = get_thread_regcache (ptid);
+ struct regcache *regs = get_thread_regcache (thread);
ULONGEST pc;
ULONGEST cpsr;
static LONGEST
bfin_linux_get_syscall_number (struct gdbarch *gdbarch,
- ptid_t ptid)
+ thread_info *thread)
{
- struct regcache *regcache = get_thread_regcache (ptid);
+ struct regcache *regcache = get_thread_regcache (thread);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
/* The content of a register. */
gdb_byte buf[4];
return (b->pspace == current_program_space
&& (ptid_equal (b->watchpoint_thread, null_ptid)
|| (ptid_equal (inferior_ptid, b->watchpoint_thread)
- && !is_executing (inferior_ptid))));
+ && !inferior_thread ()->executing)));
}
/* Set watchpoint B to disp_del_at_next_stop, even including its possible
struct thread_info *thr = find_thread_global_id (bl->owner->thread);
struct regcache *regcache;
- regcache = get_thread_regcache (thr->ptid);
+ regcache = get_thread_regcache (thr);
return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch,
regcache, addr);
}
}
-/* Remove breakpoints of process PID. */
+/* Remove breakpoints of inferior INF. */
int
-remove_breakpoints_pid (int pid)
+remove_breakpoints_inf (inferior *inf)
{
struct bp_location *bl, **blp_tmp;
int val;
- struct inferior *inf = find_inferior_pid (pid);
ALL_BP_LOCATIONS (bl, blp_tmp)
{
void
bpstat_clear_actions (void)
{
- struct thread_info *tp;
bpstat bs;
- if (ptid_equal (inferior_ptid, null_ptid))
- return;
-
- tp = find_thread_ptid (inferior_ptid);
- if (tp == NULL)
+ if (inferior_ptid == null_ptid)
return;
+ thread_info *tp = inferior_thread ();
for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next)
{
bs->commands = NULL;
return again;
}
+/* Helper for bpstat_do_actions. Get the current thread, if there's
+ one, is alive and has execution. Return NULL otherwise. */
+
+static thread_info *
+get_bpstat_thread ()
+{
+ if (inferior_ptid == null_ptid || !target_has_execution)
+ return NULL;
+
+ thread_info *tp = inferior_thread ();
+ if (tp->state == THREAD_EXITED || tp->executing)
+ return NULL;
+ return tp;
+}
+
void
bpstat_do_actions (void)
{
struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup ();
+ thread_info *tp;
/* Do any commands attached to breakpoint we are stopped at. */
- while (!ptid_equal (inferior_ptid, null_ptid)
- && target_has_execution
- && !is_exited (inferior_ptid)
- && !is_executing (inferior_ptid))
- /* Since in sync mode, bpstat_do_actions may resume the inferior,
- and only return when it is stopped at the next breakpoint, we
- keep doing breakpoint actions until it returns false to
- indicate the inferior was not resumed. */
- if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat))
- break;
+ while ((tp = get_bpstat_thread ()) != NULL)
+ {
+ /* Since in sync mode, bpstat_do_actions may resume the
+ inferior, and only return when it is stopped at the next
+ breakpoint, we keep doing breakpoint actions until it returns
+ false to indicate the inferior was not resumed. */
+ if (!bpstat_do_actions_1 (&tp->control.stop_bpstat))
+ break;
+ }
discard_cleanups (cleanup_if_error);
}
breakpoint, set BS->stop to 0. */
static void
-bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
+bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread)
{
const struct bp_location *bl;
struct breakpoint *b;
/* If this is a thread/task-specific breakpoint, don't waste cpu
evaluating the condition if this isn't the specified
thread/task. */
- if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid))
- || (b->task != 0 && b->task != ada_get_task_number (ptid)))
-
+ if ((b->thread != -1 && b->thread != thread->global_num)
+ || (b->task != 0 && b->task != ada_get_task_number (thread)))
{
bs->stop = 0;
return;
bpstat
bpstat_stop_status (const address_space *aspace,
- CORE_ADDR bp_addr, ptid_t ptid,
+ CORE_ADDR bp_addr, thread_info *thread,
const struct target_waitstatus *ws,
bpstat stop_chain)
{
b->ops->check_status (bs);
if (bs->stop)
{
- bpstat_check_breakpoint_conditions (bs, ptid);
+ bpstat_check_breakpoint_conditions (bs, thread);
if (bs->stop)
{
new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy,
&momentary_breakpoint_ops,
1);
- new_b->thread = ptid_to_global_thread_id (inferior_ptid);
+ new_b->thread = inferior_thread ()->global_num;
/* Link NEW_B into the chain of RETVAL breakpoints. */
|| frame_find_by_id (dummy_b->frame_id) != NULL)
continue;
- dummy_frame_discard (dummy_b->frame_id, tp->ptid);
+ dummy_frame_discard (dummy_b->frame_id, tp);
while (b->related_breakpoint != b)
{
b->disposition = disp_donttouch;
b->frame_id = frame_id;
- /* If we're debugging a multi-threaded program, then we want
- momentary breakpoints to be active in only a single thread of
- control. */
- if (in_thread_list (inferior_ptid))
- b->thread = ptid_to_global_thread_id (inferior_ptid);
+ b->thread = inferior_thread ()->global_num;
update_global_location_list_nothrow (UGLL_MAY_INSERT);
{
if (b->thread != -1)
{
- if (in_thread_list (inferior_ptid))
- b->thread = ptid_to_global_thread_id (inferior_ptid);
+ b->thread = inferior_thread ()->global_num;
/* We're being called after following a fork. The new fork is
selected as current, and unless this was a vfork will have a
struct bp_location;
struct linespec_result;
struct linespec_sals;
+struct inferior;
/* Why are we removing the breakpoint from the target? */
commands, FIXME??? fields. */
extern bpstat bpstat_stop_status (const address_space *aspace,
- CORE_ADDR pc, ptid_t ptid,
+ CORE_ADDR pc, thread_info *thread,
const struct target_waitstatus *ws,
bpstat stop_chain = NULL);
\f
extern int remove_breakpoints (void);
-extern int remove_breakpoints_pid (int pid);
+extern int remove_breakpoints_inf (inferior *inf);
/* This function can be used to update the breakpoint package's state
after an exec() system call has been executed.
thread_change_ptid (inferior_ptid, ptid);
/* Don't let the core see a ptid without a corresponding thread. */
- if (!in_thread_list (ptid) || is_exited (ptid))
+ thread_info *thread = find_thread_ptid (ptid);
+ if (thread == NULL || thread->state == THREAD_EXITED)
add_thread (ptid);
return ptid;
{
ptid_t ptid = ptid_build (pid, 0, addr);
- if (!in_thread_list (ptid) || is_exited (ptid))
+ thread_info *thread = find_thread_ptid (ptid);
+ if (thread == nullptr || thread->state == THREAD_EXITED)
{
/* If INFERIOR_PTID doesn't have a tid member yet, then ptid
is still the initial thread of the process. Notify GDB
struct regcache *regcache;
CORE_ADDR pc;
- regcache = get_thread_regcache (tp->ptid);
+ regcache = get_thread_regcache (tp);
pc = regcache_read_pc (regcache);
btrace.format = BTRACE_FORMAT_BTS;
This is not relevant for BTRACE_FORMAT_PT since the trace will already
start at the PC at which tracing was enabled. */
if (conf->format != BTRACE_FORMAT_PT
- && can_access_registers_ptid (tp->ptid))
+ && can_access_registers_thread (tp))
btrace_add_pc (tp);
}
CATCH (exception, RETURN_MASK_ALL)
inferior_ptid = tp->ptid;
/* We should not be called on running or exited threads. */
- gdb_assert (can_access_registers_ptid (tp->ptid));
+ gdb_assert (can_access_registers_thread (tp));
/* Let's first try to extend the trace we already have. */
if (!btinfo->functions.empty ())
maint_btrace_packet_history_cmd (const char *arg, int from_tty)
{
struct btrace_thread_info *btinfo;
- struct thread_info *tp;
unsigned int size, begin, end, from, to;
- tp = find_thread_ptid (inferior_ptid);
+ thread_info *tp = find_thread_ptid (inferior_ptid);
if (tp == NULL)
error (_("No thread."));
static void
maint_btrace_clear_packet_history_cmd (const char *args, int from_tty)
{
- struct btrace_thread_info *btinfo;
- struct thread_info *tp;
-
if (args != NULL && *args != 0)
error (_("Invalid argument."));
- tp = find_thread_ptid (inferior_ptid);
- if (tp == NULL)
+ if (inferior_ptid == null_ptid)
error (_("No thread."));
- btinfo = &tp->btrace;
+ thread_info *tp = inferior_thread ();
+ btrace_thread_info *btinfo = &tp->btrace;
/* Must clear the maint data before - it depends on BTINFO->DATA. */
btrace_maint_clear (btinfo);
static void
maint_btrace_clear_cmd (const char *args, int from_tty)
{
- struct thread_info *tp;
-
if (args != NULL && *args != 0)
error (_("Invalid argument."));
- tp = find_thread_ptid (inferior_ptid);
- if (tp == NULL)
+ if (inferior_ptid == null_ptid)
error (_("No thread."));
+ thread_info *tp = inferior_thread ();
btrace_clear (tp);
}
maint_info_btrace_cmd (const char *args, int from_tty)
{
struct btrace_thread_info *btinfo;
- struct thread_info *tp;
const struct btrace_config *conf;
if (args != NULL && *args != 0)
error (_("Invalid argument."));
- tp = find_thread_ptid (inferior_ptid);
- if (tp == NULL)
+ if (inferior_ptid == null_ptid)
error (_("No thread."));
+ thread_info *tp = inferior_thread ();
+
btinfo = &tp->btrace;
conf = btrace_conf (btinfo);
#include "observable.h"
#include "gdbthread.h"
#include "thread-fsm.h"
+#include "inferior.h"
cli_interp_base::cli_interp_base (const char *name)
: interp (name)
int m_refcount = 0;
};
+/* A policy class to interface gdb::ref_ptr with a
+ refcounted_object. */
+
+struct refcounted_object_ref_policy
+{
+ static void incref (refcounted_object *ptr)
+ {
+ ptr->incref ();
+ }
+
+ static void decref (refcounted_object *ptr)
+ {
+ ptr->decref ();
+ }
+};
+
#endif /* REFCOUNTED_OBJECT_H */
#include "gdbcmd.h"
#include "regcache.h"
#include "inferior.h"
+#include "gdbthread.h"
#include "compile.h"
#include "block.h"
#include "arch-utils.h"
static void
store_regs (struct type *regs_type, CORE_ADDR regs_base)
{
+ thread_info *thread = inferior_thread ();
struct gdbarch *gdbarch = target_gdbarch ();
- struct regcache *regcache = get_thread_regcache (inferior_ptid);
+ struct regcache *regcache = get_thread_regcache (thread);
int fieldno;
for (fieldno = 0; fieldno < TYPE_NFIELDS (regs_type); fieldno++)
{
if (core_bfd)
{
- int pid = ptid_get_pid (inferior_ptid);
inferior_ptid = null_ptid; /* Avoid confusion from thread
stuff. */
- if (pid != 0)
- exit_inferior_silent (pid);
+ exit_inferior_silent (current_inferior ());
/* Clear out solib state while the bfd is still open. See
comments in clear_solib in solib.c. */
which was the "main" thread. The latter case shouldn't
usually happen, but we're dealing with input here, which can
always be broken in different ways. */
- struct thread_info *thread = first_thread_of_process (-1);
+ thread_info *thread = first_thread_of_inferior (current_inferior ());
if (thread == NULL)
{
add_thread_silent (inferior_ptid);
}
else
- switch_to_thread (thread->ptid);
+ switch_to_thread (thread);
}
post_create_inferior (target, from_tty);
void
ctf_target::close ()
{
- int pid;
-
ctf_destroy ();
xfree (trace_dirname);
trace_dirname = NULL;
- pid = ptid_get_pid (inferior_ptid);
inferior_ptid = null_ptid; /* Avoid confusion from thread stuff. */
- exit_inferior_silent (pid);
+ exit_inferior_silent (current_inferior ());
trace_reset_local_state ();
}
struct frame_id id;
/* The thread this dummy_frame relates to. */
- ptid_t ptid;
+ thread_info *thread;
};
/* Return whether dummy_frame_id *ID1 and *ID2 are equal. */
dummy_frame_id_eq (struct dummy_frame_id *id1,
struct dummy_frame_id *id2)
{
- return frame_id_eq (id1->id, id2->id) && ptid_equal (id1->ptid, id2->ptid);
+ return frame_id_eq (id1->id, id2->id) && id1->thread == id2->thread;
}
/* List of dummy_frame destructors. */
void
dummy_frame_push (struct infcall_suspend_state *caller_state,
- const struct frame_id *dummy_id, ptid_t ptid)
+ const frame_id *dummy_id, thread_info *thread)
{
struct dummy_frame *dummy_frame;
dummy_frame = XCNEW (struct dummy_frame);
dummy_frame->caller_state = caller_state;
dummy_frame->id.id = (*dummy_id);
- dummy_frame->id.ptid = ptid;
+ dummy_frame->id.thread = thread;
dummy_frame->next = dummy_frame_stack;
dummy_frame_stack = dummy_frame;
}
{
struct dummy_frame *dummy = (struct dummy_frame *) dummy_voidp;
- if (b->thread == ptid_to_global_thread_id (dummy->id.ptid)
+ if (b->thread == dummy->id.thread->global_num
&& b->disposition == disp_del && frame_id_eq (b->frame_id, dummy->id.id))
{
while (b->related_breakpoint != b)
{
struct dummy_frame *dummy = *dummy_ptr;
- gdb_assert (ptid_equal (dummy->id.ptid, inferior_ptid));
+ gdb_assert (dummy->id.thread == inferior_thread ());
while (dummy->dtor_list != NULL)
{
return NULL;
}
-/* Find the dummy frame by DUMMY_ID and PTID, and pop it, restoring
+/* Find the dummy frame by DUMMY_ID and THREAD, and pop it, restoring
program state to that before the frame was created.
On return reinit_frame_cache has been called.
If the frame isn't found, flag an internal error. */
void
-dummy_frame_pop (struct frame_id dummy_id, ptid_t ptid)
+dummy_frame_pop (frame_id dummy_id, thread_info *thread)
{
struct dummy_frame **dp;
- struct dummy_frame_id id = { dummy_id, ptid };
+ struct dummy_frame_id id = { dummy_id, thread };
dp = lookup_dummy_frame (&id);
gdb_assert (dp != NULL);
free its memory. */
void
-dummy_frame_discard (struct frame_id dummy_id, ptid_t ptid)
+dummy_frame_discard (struct frame_id dummy_id, thread_info *thread)
{
struct dummy_frame **dp;
- struct dummy_frame_id id = { dummy_id, ptid };
+ struct dummy_frame_id id = { dummy_id, thread };
dp = lookup_dummy_frame (&id);
if (dp)
/* See dummy-frame.h. */
void
-register_dummy_frame_dtor (struct frame_id dummy_id, ptid_t ptid,
+register_dummy_frame_dtor (frame_id dummy_id, thread_info *thread,
dummy_frame_dtor_ftype *dtor, void *dtor_data)
{
- struct dummy_frame_id id = { dummy_id, ptid };
+ struct dummy_frame_id id = { dummy_id, thread };
struct dummy_frame **dp, *d;
struct dummy_frame_dtor_list *list;
dummy ID, assuming it is a dummy frame. */
struct frame_id this_id
= gdbarch_dummy_id (get_frame_arch (this_frame), this_frame);
- struct dummy_frame_id dummy_id = { this_id, inferior_ptid };
+ struct dummy_frame_id dummy_id = { this_id, inferior_thread () };
/* Use that ID to find the corresponding cache entry. */
for (dummyframe = dummy_frame_stack;
fprintf_unfiltered (file, " id=");
fprint_frame_id (file, s->id.id);
fprintf_unfiltered (file, ", ptid=%s",
- target_pid_to_str (s->id.ptid));
+ target_pid_to_str (s->id.thread->ptid));
fprintf_unfiltered (file, "\n");
}
}
be expanded so that it knowns the lower/upper extent of the dummy
frame's code. */
-extern void dummy_frame_push (struct infcall_suspend_state *caller_state,
- const struct frame_id *dummy_id, ptid_t ptid);
+extern void dummy_frame_push (infcall_suspend_state *caller_state,
+ const frame_id *dummy_id,
+ thread_info *thread);
/* Pop the dummy frame DUMMY_ID, restoring program state to that before the
frame was created.
stack, because the other frames may be for different threads, and there's
currently no way to tell which stack frame is for which thread. */
-extern void dummy_frame_pop (struct frame_id dummy_id, ptid_t ptid);
+extern void dummy_frame_pop (frame_id dummy_id, thread_info *thread);
-extern void dummy_frame_discard (struct frame_id dummy_id, ptid_t ptid);
+extern void dummy_frame_discard (frame_id dummy_id, thread_info *thread);
/* If the PC falls in a dummy frame, return a dummy frame
unwinder. */
REGISTERS_VALID is 1 for dummy_frame_pop, 0 for dummy_frame_discard. */
typedef void (dummy_frame_dtor_ftype) (void *data, int registers_valid);
-/* Call DTOR with DTOR_DATA when DUMMY_ID frame of thread PTID gets discarded.
- Dummy frame with DUMMY_ID must exist. Multiple destructors may be
- registered, they will be called in the reverse order of registrations
- (LIFO). */
-extern void register_dummy_frame_dtor (struct frame_id dummy_id, ptid_t ptid,
+/* Call DTOR with DTOR_DATA when DUMMY_ID frame of thread THREAD gets
+ discarded. Dummy frame with DUMMY_ID must exist. Multiple
+ destructors may be registered, they will be called in the reverse
+ order of registrations (LIFO). */
+extern void register_dummy_frame_dtor (frame_id dummy_id,
+ thread_info *thread,
dummy_frame_dtor_ftype *dtor,
void *dtor_data);
#include "value.h"
#include "infcall.h"
#include "gdbthread.h"
+#include "inferior.h"
#include "regcache.h"
#include "bcache.h"
#include "gdb_bfd.h"
struct frame_info *prev_frame = get_prev_frame (get_current_frame ());
struct frame_id prev_frame_id = get_stack_frame_id (prev_frame);
CORE_ADDR prev_pc = get_frame_pc (prev_frame);
- int thread_id = ptid_to_global_thread_id (inferior_ptid);
+ int thread_id = inferior_thread ()->global_num;
gdb_assert (b->type == bp_gnu_ifunc_resolver);
static void
elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
{
+ thread_info *thread = inferior_thread ();
struct gdbarch *gdbarch = get_frame_arch (get_current_frame ());
struct type *func_func_type = builtin_type (gdbarch)->builtin_func_func;
struct type *value_type = TYPE_TARGET_TYPE (func_func_type);
- struct regcache *regcache = get_thread_regcache (inferior_ptid);
+ struct regcache *regcache = get_thread_regcache (thread);
struct value *func_func;
struct value *value;
CORE_ADDR resolved_address, resolved_pc;
gdb::optional<enable_thread_stack_temporaries> stack_temporaries;
if (*pos == 0 && target_has_execution
&& exp->language_defn->la_language == language_cplus
- && !thread_stack_temporaries_enabled_p (inferior_ptid))
- stack_temporaries.emplace (inferior_ptid);
+ && !thread_stack_temporaries_enabled_p (inferior_thread ()))
+ stack_temporaries.emplace (inferior_thread ());
retval = (*exp->language_defn->la_exp_desc->evaluate_exp)
(expect_type, exp, pos, noside);
if (stack_temporaries.has_value ()
- && value_in_thread_stack_temporaries (retval, inferior_ptid))
+ && value_in_thread_stack_temporaries (retval, inferior_thread ()))
retval = value_non_lval (retval);
return retval;
/* Implement the "get_syscall_number" gdbarch method. */
static LONGEST
-fbsd_get_syscall_number (struct gdbarch *gdbarch,
- ptid_t ptid)
+fbsd_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
{
/* FreeBSD doesn't use gdbarch_get_syscall_number since FreeBSD
{
/* Popping a dummy frame involves restoring more than just registers.
dummy_frame_pop does all the work. */
- dummy_frame_pop (get_frame_id (this_frame), inferior_ptid);
+ dummy_frame_pop (get_frame_id (this_frame), inferior_thread ());
return;
}
if (get_traceframe_number () < 0)
{
/* No current inferior, no frame. */
- if (ptid_equal (inferior_ptid, null_ptid))
+ if (inferior_ptid == null_ptid)
return 0;
+ thread_info *tp = inferior_thread ();
/* Don't try to read from a dead thread. */
- if (is_exited (inferior_ptid))
+ if (tp->state == THREAD_EXITED)
return 0;
/* ... or from a spinning thread. */
- if (is_executing (inferior_ptid))
+ if (tp->executing)
return 0;
}
if (next_frame)
sym = get_frame_function (next_frame);
else
- sym = inline_skipped_symbol (inferior_ptid);
+ sym = inline_skipped_symbol (inferior_thread ());
/* If frame is inline, it certainly has symbols. */
gdb_assert (sym);
#include "gregset.h"
+struct thread_info;
+
#ifdef HAVE_PROC_SERVICE_H
/* glibc's proc_service.h doesn't wrap itself with extern "C". Need
struct ps_prochandle
{
/* The LWP we use for memory reads. */
- ptid_t ptid;
+ thread_info *thread;
};
#endif /* gdb_proc_service.h */
}
LONGEST
-gdbarch_get_syscall_number (struct gdbarch *gdbarch, ptid_t ptid)
+gdbarch_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
{
gdb_assert (gdbarch != NULL);
gdb_assert (gdbarch->get_syscall_number != NULL);
if (gdbarch_debug >= 2)
fprintf_unfiltered (gdb_stdlog, "gdbarch_get_syscall_number called\n");
- return gdbarch->get_syscall_number (gdbarch, ptid);
+ return gdbarch->get_syscall_number (gdbarch, thread);
}
void
extern int gdbarch_get_syscall_number_p (struct gdbarch *gdbarch);
-typedef LONGEST (gdbarch_get_syscall_number_ftype) (struct gdbarch *gdbarch, ptid_t ptid);
-extern LONGEST gdbarch_get_syscall_number (struct gdbarch *gdbarch, ptid_t ptid);
+typedef LONGEST (gdbarch_get_syscall_number_ftype) (struct gdbarch *gdbarch, thread_info *thread);
+extern LONGEST gdbarch_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread);
extern void set_gdbarch_get_syscall_number (struct gdbarch *gdbarch, gdbarch_get_syscall_number_ftype *get_syscall_number);
/* The filename of the XML syscall for this architecture. */
# Function for the 'catch syscall' feature.
# Get architecture-specific system calls information from registers.
-M;LONGEST;get_syscall_number;ptid_t ptid;ptid
+M;LONGEST;get_syscall_number;thread_info *thread;thread
# The filename of the XML syscall for this architecture.
v;const char *;xml_syscall_file;;;0;0;;0;pstring (gdbarch->xml_syscall_file)
return (refcount () == 0 && !ptid_equal (ptid, inferior_ptid));
}
+ /* Mark this thread as running and notify observers. */
+ void set_running (bool running);
+
struct thread_info *next = NULL;
ptid_t ptid; /* "Actual process id";
In fact, this may be overloaded with
struct thread_info *step_over_next = NULL;
};
+/* A gdb::ref_ptr pointer to a thread_info. */
+
+using thread_info_ref
+ = gdb::ref_ptr<thread_info, refcounted_object_ref_policy>;
+
/* Create an empty thread list, or empty the existing one. */
extern void init_thread_list (void);
struct private_thread_info *);
/* Delete an existing thread list entry. */
-extern void delete_thread (ptid_t);
+extern void delete_thread (thread_info *thread);
/* Delete an existing thread list entry, and be quiet about it. Used
after the process this thread having belonged to having already
exited, for example. */
-extern void delete_thread_silent (ptid_t);
+extern void delete_thread_silent (thread_info *thread);
/* Delete a step_resume_breakpoint from the thread database. */
extern void delete_step_resume_breakpoint (struct thread_info *);
const address_space *aspace,
CORE_ADDR addr);
-/* Translate the global integer thread id (GDB's homegrown id, not the
- system's) into a "pid" (which may be overloaded with extra thread
- information). */
-extern ptid_t global_thread_id_to_ptid (int num);
-
-/* Translate a 'pid' (which may be overloaded with extra thread
- information) into the global integer thread id (GDB's homegrown id,
- not the system's). */
-extern int ptid_to_global_thread_id (ptid_t ptid);
-
/* Returns whether to show inferior-qualified thread IDs, or plain
thread numbers. Inferior-qualified IDs are shown whenever we have
multiple inferiors, or the only inferior left has number > 1. */
circular static buffer, NUMCELLS deep. */
const char *print_thread_id (struct thread_info *thr);
-/* Boolean test for an already-known pid (which may be overloaded with
- extra thread information). */
+/* Boolean test for an already-known ptid. */
extern int in_thread_list (ptid_t ptid);
/* Boolean test for an already-known global thread id (GDB's homegrown
struct thread_info *find_thread_by_handle (struct value *thread_handle,
struct inferior *inf);
-/* Finds the first thread of the inferior given by PID. If PID is -1,
- returns the first thread in the list. */
-struct thread_info *first_thread_of_process (int pid);
+/* Finds the first thread of the specified inferior. */
+extern thread_info *first_thread_of_inferior (inferior *inf);
-/* Returns any thread of process PID, giving preference to the current
- thread. */
-extern struct thread_info *any_thread_of_process (int pid);
+/* Returns any thread of inferior INF, giving preference to the
+ current thread. */
+extern thread_info *any_thread_of_inferior (inferior *inf);
-/* Returns any non-exited thread of process PID, giving preference to
+/* Returns any non-exited thread of inferior INF, giving preference to
the current thread, and to not executing threads. */
-extern struct thread_info *any_live_thread_of_process (int pid);
+extern thread_info *any_live_thread_of_inferior (inferior *inf);
/* Change the ptid of thread OLD_PTID to NEW_PTID. */
void thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid);
extern int thread_count (void);
+/* Switch context to thread THR. Also sets the STOP_PC global. */
+extern void switch_to_thread (thread_info *thr);
+
+/* Switch context to no thread selected. */
+extern void switch_to_no_thread ();
+
/* Switch from one thread to another. Does not read registers and
sets STOP_PC to -1. */
extern void switch_to_thread_no_regs (struct thread_info *thread);
thread_info. */
extern void set_executing (ptid_t ptid, int executing);
-/* Reports if thread PTID is executing. */
-extern int is_executing (ptid_t ptid);
-
/* True if any (known or unknown) thread is or may be executing. */
extern int threads_are_executing (void);
int pc_in_thread_step_range (CORE_ADDR pc, struct thread_info *thread);
-/* Enable storing stack temporaries for thread with id PTID and
- disable and clear the stack temporaries on destruction. */
+/* Enable storing stack temporaries for thread THR and disable and
+ clear the stack temporaries on destruction. Holds a strong
+ reference to THR. */
class enable_thread_stack_temporaries
{
public:
- explicit enable_thread_stack_temporaries (ptid_t ptid)
- : m_ptid (ptid)
+ explicit enable_thread_stack_temporaries (thread_info *thr)
+ : m_thr (thr)
{
- struct thread_info *tp = find_thread_ptid (ptid);
+ gdb_assert (m_thr != NULL);
- gdb_assert (tp != NULL);
- tp->stack_temporaries_enabled = true;
- tp->stack_temporaries.clear ();
+ m_thr->incref ();
+
+ m_thr->stack_temporaries_enabled = true;
+ m_thr->stack_temporaries.clear ();
}
~enable_thread_stack_temporaries ()
{
- struct thread_info *tp = find_thread_ptid (m_ptid);
+ m_thr->stack_temporaries_enabled = false;
+ m_thr->stack_temporaries.clear ();
- if (tp != NULL)
- {
- tp->stack_temporaries_enabled = false;
- tp->stack_temporaries.clear ();
- }
+ m_thr->decref ();
}
DISABLE_COPY_AND_ASSIGN (enable_thread_stack_temporaries);
private:
- ptid_t m_ptid;
+ thread_info *m_thr;
};
-extern bool thread_stack_temporaries_enabled_p (ptid_t ptid);
+extern bool thread_stack_temporaries_enabled_p (thread_info *tp);
-extern void push_thread_stack_temporary (ptid_t ptid, struct value *v);
+extern void push_thread_stack_temporary (thread_info *tp, struct value *v);
-extern struct value *get_last_thread_stack_temporary (ptid_t);
+extern value *get_last_thread_stack_temporary (thread_info *tp);
-extern bool value_in_thread_stack_temporaries (struct value *, ptid_t);
+extern bool value_in_thread_stack_temporaries (struct value *,
+ thread_info *thr);
/* Add TP to the end of its inferior's pending step-over chain. */
executing). */
extern void validate_registers_access (void);
-/* Check whether it makes sense to access a register of PTID at this point.
+/* Check whether it makes sense to access a register of THREAD at this point.
Returns true if registers may be accessed; false otherwise. */
-extern bool can_access_registers_ptid (ptid_t ptid);
+extern bool can_access_registers_thread (thread_info *thread);
/* Returns whether to show which thread hit the breakpoint, received a
signal, etc. and ended up causing a user-visible stop. This is
static LONGEST
i386_linux_get_syscall_number (struct gdbarch *gdbarch,
- ptid_t ptid)
+ thread_info *thread)
{
- struct regcache *regcache = get_thread_regcache (ptid);
+ struct regcache *regcache = get_thread_regcache (thread);
return i386_linux_get_syscall_number_from_regcache (regcache);
}
get_call_return_value (struct call_return_meta_info *ri)
{
struct value *retval = NULL;
- bool stack_temporaries = thread_stack_temporaries_enabled_p (inferior_ptid);
+ thread_info *thr = inferior_thread ();
+ bool stack_temporaries = thread_stack_temporaries_enabled_p (thr);
if (TYPE_CODE (ri->value_type) == TYPE_CODE_VOID)
retval = allocate_value (ri->value_type);
{
retval = value_from_contents_and_address (ri->value_type, NULL,
ri->struct_addr);
- push_thread_stack_temporary (inferior_ptid, retval);
+ push_thread_stack_temporary (thr, retval);
}
else
{
the this pointer, GDB needs the memory address of the
value. */
value_force_lval (retval, ri->struct_addr);
- push_thread_stack_temporary (inferior_ptid, retval);
+ push_thread_stack_temporary (thr, retval);
}
}
struct gdb_exception caught_error = exception_none;
int saved_in_infcall = call_thread->control.in_infcall;
ptid_t call_thread_ptid = call_thread->ptid;
+ inferior *call_thread_inf = call_thread->inf;
enum prompt_state saved_prompt_state = current_ui->prompt_state;
int was_running = call_thread->state == THREAD_RUNNING;
int saved_ui_async = current_ui->async;
ui_register_input_event_handler (current_ui);
current_ui->async = saved_ui_async;
- /* At this point the current thread may have changed. Refresh
- CALL_THREAD as it could be invalid if its thread has exited. */
- call_thread = find_thread_ptid (call_thread_ptid);
-
/* If the infcall does NOT succeed, normal_stop will have already
finished the thread states. However, on success, normal_stop
defers here, so that we can set back the thread states to what
evaluates true and thus we'll present a user-visible stop is
decided elsewhere. */
if (!was_running
- && ptid_equal (call_thread_ptid, inferior_ptid)
+ && call_thread_ptid == inferior_ptid
&& stop_stack_dummy == STOP_STACK_DUMMY)
finish_thread_state (user_visible_resume_ptid (0));
of error out of resume()), then we wouldn't need this. */
if (caught_error.reason < 0)
{
- if (call_thread != NULL)
+ if (call_thread->state != THREAD_EXITED)
breakpoint_auto_delete (call_thread->control.stop_bpstat);
}
- if (call_thread != NULL)
- call_thread->control.in_infcall = saved_in_infcall;
+ call_thread->control.in_infcall = saved_in_infcall;
return caught_error;
}
ptid_t call_thread_ptid;
struct gdb_exception e;
char name_buf[RAW_FUNCTION_ADDRESS_SIZE];
- bool stack_temporaries = thread_stack_temporaries_enabled_p (inferior_ptid);
if (!target_has_execution)
noprocess ();
if (execution_direction == EXEC_REVERSE)
error (_("Cannot call functions in reverse mode."));
+ /* We're going to run the target, and inspect the thread's state
+ afterwards. Hold a strong reference so that the pointer remains
+ valid even if the thread exits. */
+ thread_info_ref call_thread
+ = thread_info_ref::new_reference (inferior_thread ());
+
+ bool stack_temporaries = thread_stack_temporaries_enabled_p (call_thread.get ());
+
frame = get_current_frame ();
gdbarch = get_frame_arch (frame);
{
struct value *lastval;
- lastval = get_last_thread_stack_temporary (inferior_ptid);
+ lastval = get_last_thread_stack_temporary (call_thread.get ());
if (lastval != NULL)
{
CORE_ADDR lastval_addr = value_address (lastval);
/* Everything's ready, push all the info needed to restore the
caller (and identify the dummy-frame) onto the dummy-frame
stack. */
- dummy_frame_push (caller_state, &dummy_id, inferior_ptid);
+ dummy_frame_push (caller_state, &dummy_id, call_thread.get ());
if (dummy_dtor != NULL)
- register_dummy_frame_dtor (dummy_id, inferior_ptid,
+ register_dummy_frame_dtor (dummy_id, call_thread.get (),
dummy_dtor, dummy_dtor_data);
/* Register a clean-up for unwind_on_terminating_exception_breakpoint. */
If you're looking to implement asynchronous dummy-frames, then
just below is the place to chop this function in two.. */
- /* TP is invalid after run_inferior_call returns, so enclose this
- in a block so that it's only in scope during the time it's valid. */
{
- struct thread_info *tp = inferior_thread ();
struct thread_fsm *saved_sm;
struct call_thread_fsm *sm;
/* Save the current FSM. We'll override it. */
- saved_sm = tp->thread_fsm;
- tp->thread_fsm = NULL;
+ saved_sm = call_thread->thread_fsm;
+ call_thread->thread_fsm = NULL;
/* Save this thread's ptid, we need it later but the thread
may have exited. */
- call_thread_ptid = tp->ptid;
+ call_thread_ptid = call_thread->ptid;
/* Run the inferior until it stops. */
struct_return || hidden_first_param_p,
struct_addr);
- e = run_inferior_call (sm, tp, real_pc);
+ e = run_inferior_call (sm, call_thread.get (), real_pc);
gdb::observers::inferior_call_post.notify (call_thread_ptid, funaddr);
- tp = find_thread_ptid (call_thread_ptid);
- if (tp != NULL)
+ if (call_thread->state != THREAD_EXITED)
{
/* The FSM should still be the same. */
- gdb_assert (tp->thread_fsm == &sm->thread_fsm);
+ gdb_assert (call_thread->thread_fsm == &sm->thread_fsm);
- if (thread_fsm_finished_p (tp->thread_fsm))
+ if (thread_fsm_finished_p (call_thread->thread_fsm))
{
struct value *retval;
which runs its destructors and restores the inferior's
suspend state, and restore the inferior control
state. */
- dummy_frame_pop (dummy_id, call_thread_ptid);
+ dummy_frame_pop (dummy_id, call_thread.get ());
restore_infcall_control_state (inf_status);
/* Get the return value. */
/* Clean up / destroy the call FSM, and restore the
original one. */
- thread_fsm_clean_up (tp->thread_fsm, tp);
- thread_fsm_delete (tp->thread_fsm);
- tp->thread_fsm = saved_sm;
+ thread_fsm_clean_up (call_thread->thread_fsm, call_thread.get ());
+ thread_fsm_delete (call_thread->thread_fsm);
+ call_thread->thread_fsm = saved_sm;
maybe_remove_breakpoints ();
/* Didn't complete. Restore previous state machine, and
handle the error. */
- tp->thread_fsm = saved_sm;
+ call_thread->thread_fsm = saved_sm;
}
}
/* We must get back to the frame we were before the
dummy call. */
- dummy_frame_pop (dummy_id, call_thread_ptid);
+ dummy_frame_pop (dummy_id, call_thread.get ());
/* We also need to restore inferior status to that before the
dummy call. */
{
/* We must get back to the frame we were before the dummy
call. */
- dummy_frame_pop (dummy_id, call_thread_ptid);
+ dummy_frame_pop (dummy_id, call_thread.get ());
/* We also need to restore inferior status to that before
the dummy call. */
much. If/when GDB gains a way to tell the target `hold this
thread stopped until I say otherwise', then we can optimize
this. */
- if (!is_stopped (thread->ptid))
+ if (thread->state != THREAD_STOPPED)
return 0;
- switch_to_thread (thread->ptid);
+ switch_to_thread (thread);
clear_proceed_status (0);
proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
return 0;
static void
ensure_valid_thread (void)
{
- if (ptid_equal (inferior_ptid, null_ptid)
- || is_exited (inferior_ptid))
+ if (inferior_ptid == null_ptid
+ || inferior_thread ()->state == THREAD_EXITED)
error (_("Cannot execute this command without a live selected thread."));
}
static void
ensure_not_running (void)
{
- if (is_running (inferior_ptid))
+ if (inferior_thread ()->state == THREAD_RUNNING)
error_is_running ();
}
struct thread_info *tp;
if (non_stop)
- tp = find_thread_ptid (inferior_ptid);
+ tp = inferior_thread ();
else
{
ptid_t last_ptid;
/* Step at an inlined function behaves like "down". */
if (!sm->skip_subroutines
- && inline_skipped_frames (inferior_ptid))
+ && inline_skipped_frames (tp))
{
ptid_t resume_ptid;
resume_ptid = user_visible_resume_ptid (1);
set_running (resume_ptid, 1);
- step_into_inline_frame (inferior_ptid);
+ step_into_inline_frame (tp);
sm->count--;
return prepare_one_step (sm);
}
{
bpstat bs;
int num, stat;
- struct thread_info *tp;
ptid_t ptid;
if (!target_has_execution)
get_last_target_status (&ptid, &ws);
}
- if (ptid_equal (ptid, null_ptid) || is_exited (ptid))
+ if (ptid == null_ptid)
+ error (_("No selected thread."));
+
+ thread_info *tp = find_thread_ptid (ptid);
+
+ if (tp->state == THREAD_EXITED)
error (_("Invalid selected thread."));
- else if (is_running (ptid))
+ else if (tp->state == THREAD_RUNNING)
error (_("Selected thread is running."));
- tp = find_thread_ptid (ptid);
bs = tp->control.stop_bpstat;
stat = bpstat_num (&bs, &num);
int pid = * (int *) arg;
if (ptid_get_pid (thread->ptid) == pid
- && !is_exited (thread->ptid)
- && !is_executing (thread->ptid)
+ && thread->state != THREAD_EXITED
+ && !thread->executing
&& !thread->stop_requested
&& thread->suspend.stop_signal == GDB_SIGNAL_0)
{
- switch_to_thread (thread->ptid);
+ switch_to_thread (thread);
clear_proceed_status (0);
proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
}
}
}
- switch_to_thread (lowest->ptid);
+ switch_to_thread (lowest);
}
/* Tell the user/frontend where we're stopped. */
as stopped. */
void
-notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
+notice_new_inferior (thread_info *thr, int leave_running, int from_tty)
{
enum attach_post_wait_mode mode
= leave_running ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_NOTHING;
/* Avoid reading registers -- we haven't fetched the target
description yet. */
- switch_to_thread_no_regs (find_thread_ptid (ptid));
+ switch_to_thread_no_regs (thr);
/* When we "notice" a new inferior we need to do all the things we
would normally do if we had just attached to it. */
- if (is_executing (inferior_ptid))
+ if (thr->executing)
{
struct attach_command_continuation_args *a;
struct inferior *inferior = current_inferior ();
if (ptid_get_pid (tp->ptid) == arg->pid)
{
if (arg->silent)
- delete_thread_silent (tp->ptid);
+ delete_thread_silent (tp);
else
- delete_thread (tp->ptid);
+ delete_thread (tp);
}
return 0;
}
void
-exit_inferior (int pid)
+exit_inferior (inferior *inf)
{
- struct inferior *inf = find_inferior_pid (pid);
-
+ int pid = inf->pid;
exit_inferior_1 (inf, 0);
}
exit_inferior_1 (inf, 1);
}
+void
+exit_inferior_silent (inferior *inf)
+{
+ exit_inferior_1 (inf, 1);
+}
+
void
exit_inferior_num_silent (int num)
{
target_pid_to_str (pid_to_ptid (pid)));
}
-/* See inferior.h. */
-
-void
-detach_inferior (int pid)
-{
- detach_inferior (find_inferior_pid (pid));
-}
-
void
inferior_appeared (struct inferior *inf, int pid)
{
for (inf = inferior_list; inf; inf = inf->next)
{
if (inf->pid != 0)
- exit_inferior_silent (inf->pid);
+ exit_inferior_silent (inf);
}
}
return NULL;
}
-int
-valid_gdb_inferior_id (int num)
-{
- struct inferior *inf;
-
- for (inf = inferior_list; inf; inf = inf->next)
- if (inf->num == num)
- return 1;
-
- return 0;
-}
-
-int
-pid_to_gdb_inferior_id (int pid)
-{
- struct inferior *inf;
-
- for (inf = inferior_list; inf; inf = inf->next)
- if (inf->pid == pid)
- return inf->num;
-
- return 0;
-}
-
-int
-gdb_inferior_id_to_pid (int num)
-{
- struct inferior *inferior = find_inferior_id (num);
- if (inferior)
- return inferior->pid;
- else
- return -1;
-}
-
-int
-in_inferior_list (int pid)
-{
- struct inferior *inf;
-
- for (inf = inferior_list; inf; inf = inf->next)
- if (inf->pid == pid)
- return 1;
-
- return 0;
-}
-
int
have_inferiors (void)
{
static void
detach_inferior_command (const char *args, int from_tty)
{
- struct thread_info *tp;
-
if (!args || !*args)
error (_("Requires argument (inferior id(s) to detach)"));
{
int num = parser.get_number ();
- if (!valid_gdb_inferior_id (num))
+ inferior *inf = find_inferior_id (num);
+ if (inf == NULL)
{
warning (_("Inferior ID %d not known."), num);
continue;
}
- int pid = gdb_inferior_id_to_pid (num);
- if (pid == 0)
+ if (inf->pid == 0)
{
warning (_("Inferior ID %d is not running."), num);
continue;
}
- tp = any_thread_of_process (pid);
- if (!tp)
+ thread_info *tp = any_thread_of_inferior (inf);
+ if (tp == NULL)
{
warning (_("Inferior ID %d has no threads."), num);
continue;
}
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
detach_command (NULL, from_tty);
}
static void
kill_inferior_command (const char *args, int from_tty)
{
- struct thread_info *tp;
-
if (!args || !*args)
error (_("Requires argument (inferior id(s) to kill)"));
{
int num = parser.get_number ();
- if (!valid_gdb_inferior_id (num))
+ inferior *inf = find_inferior_id (num);
+ if (inf == NULL)
{
warning (_("Inferior ID %d not known."), num);
continue;
}
- int pid = gdb_inferior_id_to_pid (num);
- if (pid == 0)
+ if (inf->pid == 0)
{
warning (_("Inferior ID %d is not running."), num);
continue;
}
- tp = any_thread_of_process (pid);
- if (!tp)
+ thread_info *tp = any_thread_of_inferior (inf);
+ if (tp == NULL)
{
warning (_("Inferior ID %d has no threads."), num);
continue;
}
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
target_kill ();
}
if (inf->pid != 0)
{
- if (inf->pid != ptid_get_pid (inferior_ptid))
+ if (inf != current_inferior ())
{
- struct thread_info *tp;
-
- tp = any_thread_of_process (inf->pid);
- if (!tp)
+ thread_info *tp = any_thread_of_inferior (inf);
+ if (tp == NULL)
error (_("Inferior has no threads."));
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
}
gdb::observers::user_selected_context_changed.notify
else
{
set_current_inferior (inf);
- switch_to_thread (null_ptid);
+ switch_to_no_thread ();
set_current_program_space (inf->pspace);
gdb::observers::user_selected_context_changed.notify
symbols.q. */
set_current_program_space (inf->pspace);
set_current_inferior (inf);
- switch_to_thread (null_ptid);
+ switch_to_no_thread ();
exec_file_attach (exec.get (), from_tty);
symbol_file_add_main (exec.get (), add_flags);
printf_filtered (_("Added inferior %d.\n"), inf->num);
set_current_inferior (inf);
- switch_to_thread (null_ptid);
+ switch_to_no_thread ();
clone_program_space (pspace, orginf->pspace);
}
}
struct target_desc_info;
struct continuation;
struct inferior;
+struct thread_info;
/* For bpstat. */
#include "breakpoint.h"
extern void detach_command (const char *, int);
-extern void notice_new_inferior (ptid_t, int, int);
+extern void notice_new_inferior (thread_info *, int, int);
extern struct value *get_return_value (struct value *function,
struct type *value_type);
/* Delete an existing inferior list entry, due to inferior detaching. */
extern void detach_inferior (inferior *inf);
-/* Same as the above, but with the inferior specified by PID. */
-extern void detach_inferior (int pid);
+extern void exit_inferior (inferior *inf);
-extern void exit_inferior (int pid);
-
-extern void exit_inferior_silent (int pid);
+extern void exit_inferior_silent (inferior *inf);
extern void exit_inferior_num_silent (int num);
/* Get rid of all inferiors. */
extern void discard_all_inferiors (void);
-/* Translate the integer inferior id (GDB's homegrown id, not the system's)
- into a "pid" (which may be overloaded with extra inferior information). */
-extern int gdb_inferior_id_to_pid (int);
-
-/* Translate a target 'pid' into the integer inferior id (GDB's
- homegrown id, not the system's). */
-extern int pid_to_gdb_inferior_id (int pid);
-
-/* Boolean test for an already-known pid. */
-extern int in_inferior_list (int pid);
-
-/* Boolean test for an already-known inferior id (GDB's homegrown id,
- not the system's). */
-extern int valid_gdb_inferior_id (int num);
-
/* Search function to lookup an inferior by target 'pid'. */
extern struct inferior *find_inferior_pid (int pid);
static ptid_t target_last_wait_ptid;
static struct target_waitstatus target_last_waitstatus;
-static void context_switch (ptid_t ptid);
-
void init_thread_stepping_state (struct thread_info *tss);
static const char follow_fork_mode_child[] = "child";
if (has_vforked)
{
/* Keep breakpoints list in sync. */
- remove_breakpoints_pid (ptid_get_pid (inferior_ptid));
+ remove_breakpoints_inf (current_inferior ());
}
if (print_inferior_events)
/* Check if we switched over from WAIT_PTID, since the event was
reported. */
- if (!ptid_equal (wait_ptid, minus_one_ptid)
- && !ptid_equal (inferior_ptid, wait_ptid))
+ if (wait_ptid != minus_one_ptid
+ && inferior_ptid != wait_ptid)
{
/* We did. Switch back to WAIT_PTID thread, to tell the
target to follow it (in either direction). We'll
afterwards refuse to resume, and inform the user what
happened. */
- switch_to_thread (wait_ptid);
+ thread_info *wait_thread
+ = find_thread_ptid (wait_ptid);
+ switch_to_thread (wait_thread);
should_resume = 0;
}
}
/* If we followed the child, switch to it... */
if (follow_child)
{
- switch_to_thread (child);
+ thread_info *child_thr = find_thread_ptid (child);
+ switch_to_thread (child_thr);
/* ... and preserve the stepping state, in case the
user was stepping over the fork call. */
/* Reset breakpoints in the child as appropriate. */
follow_inferior_reset_breakpoints ();
}
- else
- switch_to_thread (parent);
}
}
break;
{
int pid = * (int *) arg;
- if (ptid_get_pid (thread->ptid) == pid
- && is_running (thread->ptid)
- && !is_executing (thread->ptid)
+ if (thread->ptid.pid () == pid
+ && thread->state == THREAD_RUNNING
+ && !thread->executing
&& !thread->stop_requested
&& thread->suspend.stop_signal == GDB_SIGNAL_0)
{
"infrun: resuming vfork parent thread %s\n",
target_pid_to_str (thread->ptid));
- switch_to_thread (thread->ptid);
+ switch_to_thread (thread);
clear_proceed_status (0);
proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
}
maybe_restore_thread.emplace ();
/* We're letting loose of the parent. */
- tp = any_live_thread_of_process (inf->vfork_parent->pid);
- switch_to_thread (tp->ptid);
+ tp = any_live_thread_of_inferior (inf->vfork_parent);
+ switch_to_thread (tp);
/* We're about to detach from the parent, which implicitly
removes breakpoints from its address space. There's a
notifications. */
ALL_THREADS_SAFE (th, tmp)
if (ptid_get_pid (th->ptid) == pid && !ptid_equal (th->ptid, ptid))
- delete_thread (th->ptid);
+ delete_thread (th);
/* We also need to clear any left over stale state for the
leader/event thread. E.g., if there was any step-resume
struct displaced_step_inferior_state *next;
/* The process this displaced step state refers to. */
- int pid;
+ inferior *inf;
/* True if preparing a displaced step ever failed. If so, we won't
try displaced stepping for this inferior again. */
int failed_before;
- /* If this is not null_ptid, this is the thread carrying out a
+ /* If this is not nullptr, this is the thread carrying out a
displaced single-step in process PID. This thread's state will
require fixing up once it has completed its step. */
- ptid_t step_ptid;
+ thread_info *step_thread;
/* The architecture the thread had when we stepped it. */
struct gdbarch *step_gdbarch;
/* Get the displaced stepping state of process PID. */
static struct displaced_step_inferior_state *
-get_displaced_stepping_state (int pid)
+get_displaced_stepping_state (inferior *inf)
{
struct displaced_step_inferior_state *state;
for (state = displaced_step_inferior_states;
state != NULL;
state = state->next)
- if (state->pid == pid)
+ if (state->inf == inf)
return state;
return NULL;
for (state = displaced_step_inferior_states;
state != NULL;
state = state->next)
- if (!ptid_equal (state->step_ptid, null_ptid))
+ if (state->step_thread != nullptr)
return 1;
return 0;
step. */
static int
-displaced_step_in_progress_thread (ptid_t ptid)
+displaced_step_in_progress_thread (thread_info *thread)
{
struct displaced_step_inferior_state *displaced;
- gdb_assert (!ptid_equal (ptid, null_ptid));
+ gdb_assert (thread != NULL);
- displaced = get_displaced_stepping_state (ptid_get_pid (ptid));
+ displaced = get_displaced_stepping_state (thread->inf);
- return (displaced != NULL && ptid_equal (displaced->step_ptid, ptid));
+ return (displaced != NULL && displaced->step_thread == thread);
}
/* Return true if process PID has a thread doing a displaced step. */
static int
-displaced_step_in_progress (int pid)
+displaced_step_in_progress (inferior *inf)
{
struct displaced_step_inferior_state *displaced;
- displaced = get_displaced_stepping_state (pid);
- if (displaced != NULL && !ptid_equal (displaced->step_ptid, null_ptid))
+ displaced = get_displaced_stepping_state (inf);
+ if (displaced != NULL && displaced->step_thread != nullptr)
return 1;
return 0;
entry, if it already exists. Never returns NULL. */
static struct displaced_step_inferior_state *
-add_displaced_stepping_state (int pid)
+add_displaced_stepping_state (inferior *inf)
{
struct displaced_step_inferior_state *state;
for (state = displaced_step_inferior_states;
state != NULL;
state = state->next)
- if (state->pid == pid)
+ if (state->inf == inf)
return state;
state = XCNEW (struct displaced_step_inferior_state);
- state->pid = pid;
+ state->inf = inf;
state->next = displaced_step_inferior_states;
displaced_step_inferior_states = state;
get_displaced_step_closure_by_addr (CORE_ADDR addr)
{
struct displaced_step_inferior_state *displaced
- = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
+ = get_displaced_stepping_state (current_inferior ());
/* If checking the mode of displaced instruction in copy area. */
- if (displaced && !ptid_equal (displaced->step_ptid, null_ptid)
- && (displaced->step_copy == addr))
+ if (displaced != NULL
+ && displaced->step_thread != nullptr
+ && displaced->step_copy == addr)
return displaced->step_closure;
return NULL;
/* Remove the displaced stepping state of process PID. */
static void
-remove_displaced_stepping_state (int pid)
+remove_displaced_stepping_state (inferior *inf)
{
struct displaced_step_inferior_state *it, **prev_next_p;
- gdb_assert (pid != 0);
+ gdb_assert (inf != nullptr);
it = displaced_step_inferior_states;
prev_next_p = &displaced_step_inferior_states;
while (it)
{
- if (it->pid == pid)
+ if (it->inf == inf)
{
*prev_next_p = it->next;
xfree (it);
static void
infrun_inferior_exit (struct inferior *inf)
{
- remove_displaced_stepping_state (inf->pid);
+ remove_displaced_stepping_state (inf);
}
/* If ON, and the architecture supports it, GDB will use displaced
static int
use_displaced_stepping (struct thread_info *tp)
{
- struct regcache *regcache = get_thread_regcache (tp->ptid);
+ struct regcache *regcache = get_thread_regcache (tp);
struct gdbarch *gdbarch = regcache->arch ();
struct displaced_step_inferior_state *displaced_state;
- displaced_state = get_displaced_stepping_state (ptid_get_pid (tp->ptid));
+ displaced_state = get_displaced_stepping_state (tp->inf);
return (((can_use_displaced_stepping == AUTO_BOOLEAN_AUTO
&& target_is_non_stop_p ())
displaced_step_clear (struct displaced_step_inferior_state *displaced)
{
/* Indicate that there is no cleanup pending. */
- displaced->step_ptid = null_ptid;
+ displaced->step_thread = nullptr;
delete displaced->step_closure;
displaced->step_closure = NULL;
if this instruction can't be displaced stepped. */
static int
-displaced_step_prepare_throw (ptid_t ptid)
+displaced_step_prepare_throw (thread_info *tp)
{
struct cleanup *ignore_cleanups;
- struct thread_info *tp = find_thread_ptid (ptid);
- struct regcache *regcache = get_thread_regcache (ptid);
+ regcache *regcache = get_thread_regcache (tp);
struct gdbarch *gdbarch = regcache->arch ();
const address_space *aspace = regcache->aspace ();
CORE_ADDR original, copy;
/* We have to displaced step one thread at a time, as we only have
access to a single scratch space per inferior. */
- displaced = add_displaced_stepping_state (ptid_get_pid (ptid));
+ displaced = add_displaced_stepping_state (tp->inf);
- if (!ptid_equal (displaced->step_ptid, null_ptid))
+ if (displaced->step_thread != nullptr)
{
/* Already waiting for a displaced step to finish. Defer this
request and place in queue. */
if (debug_displaced)
fprintf_unfiltered (gdb_stdlog,
"displaced: deferring step of %s\n",
- target_pid_to_str (ptid));
+ target_pid_to_str (tp->ptid));
thread_step_over_chain_enqueue (tp);
return 0;
if (debug_displaced)
fprintf_unfiltered (gdb_stdlog,
"displaced: stepping %s now\n",
- target_pid_to_str (ptid));
+ target_pid_to_str (tp->ptid));
}
displaced_step_clear (displaced);
- scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
- inferior_ptid = ptid;
+ scoped_restore_current_thread restore_thread;
+
+ switch_to_thread (tp);
original = regcache_read_pc (regcache);
/* Save the information we need to fix things up if the step
succeeds. */
- displaced->step_ptid = ptid;
+ displaced->step_thread = tp;
displaced->step_gdbarch = gdbarch;
displaced->step_closure = closure;
displaced->step_original = original;
attempts at displaced stepping if we get a memory error. */
static int
-displaced_step_prepare (ptid_t ptid)
+displaced_step_prepare (thread_info *thread)
{
int prepared = -1;
TRY
{
- prepared = displaced_step_prepare_throw (ptid);
+ prepared = displaced_step_prepare_throw (thread);
}
CATCH (ex, RETURN_MASK_ERROR)
{
/* Disable further displaced stepping attempts. */
displaced_state
- = get_displaced_stepping_state (ptid_get_pid (ptid));
+ = get_displaced_stepping_state (thread->inf);
displaced_state->failed_before = 1;
}
END_CATCH
-1. If the thread wasn't displaced stepping, return 0. */
static int
-displaced_step_fixup (ptid_t event_ptid, enum gdb_signal signal)
+displaced_step_fixup (thread_info *event_thread, enum gdb_signal signal)
{
struct cleanup *old_cleanups;
struct displaced_step_inferior_state *displaced
- = get_displaced_stepping_state (ptid_get_pid (event_ptid));
+ = get_displaced_stepping_state (event_thread->inf);
int ret;
/* Was any thread of this process doing a displaced step? */
if (displaced == NULL)
return 0;
- /* Was this event for the pid we displaced? */
- if (ptid_equal (displaced->step_ptid, null_ptid)
- || ! ptid_equal (displaced->step_ptid, event_ptid))
+ /* Was this event for the thread we displaced? */
+ if (displaced->step_thread != event_thread)
return 0;
old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced);
- displaced_step_restore (displaced, displaced->step_ptid);
+ displaced_step_restore (displaced, displaced->step_thread->ptid);
/* Fixup may need to read memory/registers. Switch to the thread
that we're fixing up. Also, target_stopped_by_watchpoint checks
the current thread. */
- switch_to_thread (event_ptid);
+ switch_to_thread (event_thread);
/* Did the instruction complete successfully? */
if (signal == GDB_SIGNAL_TRAP
displaced->step_closure,
displaced->step_original,
displaced->step_copy,
- get_thread_regcache (displaced->step_ptid));
+ get_thread_regcache (displaced->step_thread));
ret = 1;
}
else
{
/* Since the instruction didn't complete, all we can do is
relocate the PC. */
- struct regcache *regcache = get_thread_regcache (event_ptid);
+ struct regcache *regcache = get_thread_regcache (event_thread);
CORE_ADDR pc = regcache_read_pc (regcache);
pc = displaced->step_original + (pc - displaced->step_copy);
do_cleanups (old_cleanups);
- displaced->step_ptid = null_ptid;
+ displaced->step_thread = nullptr;
return ret;
}
/* If this inferior already has a displaced step in process,
don't start a new one. */
- if (displaced_step_in_progress (ptid_get_pid (tp->ptid)))
+ if (displaced_step_in_progress (tp->inf))
continue;
step_what = thread_still_needs_step_over (tp);
if (!target_is_non_stop_p () && !step_what)
continue;
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
reset_ecs (ecs, tp);
keep_going_pass_signal (ecs);
if (ptid_equal (inferior_ptid, old_ptid))
inferior_ptid = new_ptid;
-
- for (displaced = displaced_step_inferior_states;
- displaced;
- displaced = displaced->next)
- {
- if (ptid_equal (displaced->step_ptid, old_ptid))
- displaced->step_ptid = new_ptid;
- }
}
\f
return to the scratch pad area, which would no longer be
valid. */
if (step_over_info_valid_p ()
- || displaced_step_in_progress (ptid_get_pid (tp->ptid)))
+ || displaced_step_in_progress (tp->inf))
target_pass_signals (0, NULL);
else
target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
&& sig == GDB_SIGNAL_0
&& !current_inferior ()->waiting_for_vfork_done)
{
- int prepared = displaced_step_prepare (inferior_ptid);
+ int prepared = displaced_step_prepare (tp);
if (prepared == 0)
{
/* Update pc to reflect the new address from which we will
execute instructions due to displaced stepping. */
- pc = regcache_read_pc (get_thread_regcache (inferior_ptid));
+ pc = regcache_read_pc (get_thread_regcache (tp));
- displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
+ displaced = get_displaced_stepping_state (tp->inf);
step = gdbarch_displaced_step_hw_singlestep (gdbarch,
displaced->step_closure);
}
&& use_displaced_stepping (tp)
&& !step_over_info_valid_p ())
{
- struct regcache *resume_regcache = get_thread_regcache (tp->ptid);
+ struct regcache *resume_regcache = get_thread_regcache (tp);
struct gdbarch *resume_gdbarch = resume_regcache->arch ();
CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
gdb_byte buf[4];
{
if (tp->stepping_over_breakpoint)
{
- struct regcache *regcache = get_thread_regcache (tp->ptid);
+ struct regcache *regcache = get_thread_regcache (tp);
if (breakpoint_here_p (regcache->aspace (),
regcache_read_pc (regcache))
target_pid_to_str (tp->ptid));
reset_ecs (ecs, tp);
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
keep_going_pass_signal (ecs);
if (!ecs->wait_some_more)
error (_("Command aborted."));
{
/* The thread wasn't started, and isn't queued, run it now. */
reset_ecs (ecs, tp);
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
keep_going_pass_signal (ecs);
if (!ecs->wait_some_more)
error (_("Command aborted."));
&& (tp->suspend.stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT
|| tp->suspend.stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT))
{
- struct regcache *regcache = get_thread_regcache (tp->ptid);
+ struct regcache *regcache = get_thread_regcache (tp);
struct gdbarch *gdbarch = regcache->arch ();
CORE_ADDR pc;
int discard = 0;
struct gdbarch *gdbarch;
int decr_pc;
- regcache = get_thread_regcache (tp->ptid);
+ regcache = get_thread_regcache (tp);
gdbarch = regcache->arch ();
decr_pc = gdbarch_decr_pc_after_break (gdbarch);
{
struct inferior *inf = current_inferior ();
ptid_t pid_ptid = pid_to_ptid (inf->pid);
- struct displaced_step_inferior_state *displaced;
- displaced = get_displaced_stepping_state (inf->pid);
+ displaced_step_inferior_state *displaced = get_displaced_stepping_state (inf);
/* Is any thread of this process displaced stepping? If not,
there's nothing else to do. */
- if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid))
+ if (displaced == NULL || displaced->step_thread == nullptr)
return;
if (debug_infrun)
scoped_restore restore_detaching = make_scoped_restore (&inf->detaching, true);
- while (!ptid_equal (displaced->step_ptid, null_ptid))
+ while (displaced->step_thread != nullptr)
{
struct execution_control_state ecss;
struct execution_control_state *ecs;
if (thr == ecs->event_thread)
continue;
- switch_to_thread (thr->ptid);
+ switch_to_thread (thr);
thread_fsm_clean_up (thr->thread_fsm, thr);
}
if (ecs->event_thread != NULL)
- switch_to_thread (ecs->event_thread->ptid);
+ switch_to_thread (ecs->event_thread);
}
}
if (cmd_done
&& exec_done_display_p
- && (ptid_equal (inferior_ptid, null_ptid)
- || !is_running (inferior_ptid)))
+ && (inferior_ptid == null_ptid
+ || inferior_thread ()->state != THREAD_RUNNING))
printf_unfiltered (_("completed.\n"));
}
/* Switch thread contexts. */
static void
-context_switch (ptid_t ptid)
+context_switch (execution_control_state *ecs)
{
- if (debug_infrun && !ptid_equal (ptid, inferior_ptid))
+ if (debug_infrun
+ && ecs->ptid != inferior_ptid
+ && ecs->event_thread != inferior_thread ())
{
fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
target_pid_to_str (inferior_ptid));
fprintf_unfiltered (gdb_stdlog, "to %s\n",
- target_pid_to_str (ptid));
+ target_pid_to_str (ecs->ptid));
}
- switch_to_thread (ptid);
+ switch_to_thread (ecs->event_thread);
}
/* If the target can't tell whether we've hit breakpoints
/* If this target does not decrement the PC after breakpoints, then
we have nothing to do. */
- regcache = get_thread_regcache (thread->ptid);
+ regcache = get_thread_regcache (thread);
gdbarch = regcache->arch ();
decr_pc = gdbarch_decr_pc_after_break (gdbarch);
struct regcache *regcache;
int syscall_number;
- if (!ptid_equal (ecs->ptid, inferior_ptid))
- context_switch (ecs->ptid);
+ context_switch (ecs);
- regcache = get_thread_regcache (ecs->ptid);
+ regcache = get_thread_regcache (ecs->event_thread);
syscall_number = ecs->ws.value.syscall_number;
stop_pc = regcache_read_pc (regcache);
ecs->event_thread->control.stop_bpstat
= bpstat_stop_status (regcache->aspace (),
- stop_pc, ecs->ptid, &ecs->ws);
+ stop_pc, ecs->event_thread, &ecs->ws);
if (handle_stop_requested (ecs))
return 0;
}
-/* Return the STOP_SOON field of the inferior pointed at by PTID. */
+/* Return the STOP_SOON field of the inferior pointed at by ECS. */
static enum stop_kind
-get_inferior_stop_soon (ptid_t ptid)
+get_inferior_stop_soon (execution_control_state *ecs)
{
- struct inferior *inf = find_inferior_ptid (ptid);
+ struct inferior *inf = find_inferior_ptid (ecs->ptid);
gdb_assert (inf != NULL);
return inf->control.stop_soon;
/* Generate thread_stopped_by_hw_breakpoint. */
THREAD_STOPPED_BY (hw_breakpoint)
-/* Cleanups that switches to the PTID pointed at by PTID_P. */
-
-static void
-switch_to_thread_cleanup (void *ptid_p)
-{
- ptid_t ptid = *(ptid_t *) ptid_p;
-
- switch_to_thread (ptid);
-}
-
/* Save the thread's event and stop reason to process it later. */
static void
save_waitstatus (struct thread_info *tp, struct target_waitstatus *ws)
{
- struct regcache *regcache;
-
if (debug_infrun)
{
std::string statstr = target_waitstatus_to_string (ws);
tp->suspend.waitstatus = *ws;
tp->suspend.waitstatus_pending_p = 1;
- regcache = get_thread_regcache (tp->ptid);
+ struct regcache *regcache = get_thread_regcache (tp);
const address_space *aspace = regcache->aspace ();
if (ws->kind == TARGET_WAITKIND_STOPPED
/* We may need multiple passes to discover all threads. */
int pass;
int iterations = 0;
- ptid_t entry_ptid;
struct cleanup *old_chain;
gdb_assert (target_is_non_stop_p ());
if (debug_infrun)
fprintf_unfiltered (gdb_stdlog, "infrun: stop_all_threads\n");
- entry_ptid = inferior_ptid;
- old_chain = make_cleanup (switch_to_thread_cleanup, &entry_ptid);
+ scoped_restore_current_thread restore_thread;
target_thread_events (1);
- make_cleanup (disable_thread_events, NULL);
+ old_chain = make_cleanup (disable_thread_events, NULL);
/* Request threads to stop, and then wait for the stops. Because
threads we already know about can spawn more threads while we're
pass = -1;
event_ptid = wait_one (&ws);
+
if (ws.kind == TARGET_WAITKIND_NO_RESUMED)
{
/* All resumed threads exited. */
}
else
{
- struct inferior *inf;
+ inferior *inf;
t = find_thread_ptid (event_ptid);
if (t == NULL)
t->suspend.waitstatus.kind = TARGET_WAITKIND_IGNORE;
t->suspend.waitstatus_pending_p = 0;
- if (displaced_step_fixup (t->ptid, GDB_SIGNAL_0) < 0)
+ if (displaced_step_fixup (t, GDB_SIGNAL_0) < 0)
{
/* Add it back to the step-over queue. */
if (debug_infrun)
sig = (ws.kind == TARGET_WAITKIND_STOPPED
? ws.value.sig : GDB_SIGNAL_0);
- if (displaced_step_fixup (t->ptid, sig) < 0)
+ if (displaced_step_fixup (t, sig) < 0)
{
/* Add it back to the step-over queue. */
t->control.trap_expected = 0;
thread_step_over_chain_enqueue (t);
}
- regcache = get_thread_regcache (t->ptid);
+ regcache = get_thread_regcache (t);
t->suspend.stop_pc = regcache_read_pc (regcache);
if (debug_infrun)
if (inf->pid == 0)
continue;
- thread = any_live_thread_of_process (inf->pid);
+ thread_info *thread = any_live_thread_of_inferior (inf);
if (thread == NULL)
{
if (debug_infrun)
|| ecs->ws.value.sig == GDB_SIGNAL_SEGV
|| ecs->ws.value.sig == GDB_SIGNAL_EMT))
{
- struct regcache *regcache = get_thread_regcache (ecs->ptid);
+ struct regcache *regcache = get_thread_regcache (ecs->event_thread);
if (breakpoint_inserted_here_p (regcache->aspace (),
regcache_read_pc (regcache)))
case TARGET_WAITKIND_LOADED:
if (debug_infrun)
fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
- if (!ptid_equal (ecs->ptid, inferior_ptid))
- context_switch (ecs->ptid);
+ context_switch (ecs);
/* Ignore gracefully during startup of the inferior, as it might
be the shell which has just loaded some objects, otherwise
add the symbols for the newly loaded objects. Also ignore at
the full list of libraries once the connection is
established. */
- stop_soon = get_inferior_stop_soon (ecs->ptid);
+ stop_soon = get_inferior_stop_soon (ecs);
if (stop_soon == NO_STOP_QUIETLY)
{
struct regcache *regcache;
- regcache = get_thread_regcache (ecs->ptid);
+ regcache = get_thread_regcache (ecs->event_thread);
handle_solib_event ();
ecs->event_thread->control.stop_bpstat
= bpstat_stop_status (regcache->aspace (),
- stop_pc, ecs->ptid, &ecs->ws);
+ stop_pc, ecs->event_thread, &ecs->ws);
if (handle_stop_requested (ecs))
return;
fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
if (handle_stop_requested (ecs))
return;
- if (!ptid_equal (ecs->ptid, inferior_ptid))
- context_switch (ecs->ptid);
+ context_switch (ecs);
resume (GDB_SIGNAL_0);
prepare_to_wait (ecs);
return;
fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_THREAD_CREATED\n");
if (handle_stop_requested (ecs))
return;
- if (!ptid_equal (ecs->ptid, inferior_ptid))
- context_switch (ecs->ptid);
+ context_switch (ecs);
if (!switch_back_to_stepped_thread (ecs))
keep_going (ecs);
return;
}
else
{
- struct regcache *regcache = get_thread_regcache (ecs->ptid);
- struct gdbarch *gdbarch = regcache->arch ();
+ struct gdbarch *gdbarch = current_inferior ()->gdbarch;
if (gdbarch_gdb_signal_to_target_p (gdbarch))
{
/* Check whether the inferior is displaced stepping. */
{
- struct regcache *regcache = get_thread_regcache (ecs->ptid);
+ struct regcache *regcache = get_thread_regcache (ecs->event_thread);
struct gdbarch *gdbarch = regcache->arch ();
/* If checking displaced stepping is supported, and thread
ecs->ptid is displaced stepping. */
- if (displaced_step_in_progress_thread (ecs->ptid))
+ if (displaced_step_in_progress_thread (ecs->event_thread))
{
struct inferior *parent_inf
= find_inferior_ptid (ecs->ptid);
has been done. Perform cleanup for parent process here. Note
that this operation also cleans up the child process for vfork,
because their pages are shared. */
- displaced_step_fixup (ecs->ptid, GDB_SIGNAL_TRAP);
+ displaced_step_fixup (ecs->event_thread, GDB_SIGNAL_TRAP);
/* Start a new step-over in another thread if there's one
that needs it. */
start_step_over ();
if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
{
struct displaced_step_inferior_state *displaced
- = get_displaced_stepping_state (ptid_get_pid (ecs->ptid));
+ = get_displaced_stepping_state (parent_inf);
/* Restore scratch pad for child process. */
displaced_step_restore (displaced, ecs->ws.value.related_pid);
}
}
- if (!ptid_equal (ecs->ptid, inferior_ptid))
- context_switch (ecs->ptid);
+ context_switch (ecs);
/* Immediately detach breakpoints from the child before there's
any chance of letting the user delete breakpoints from the
and not immediately. */
ecs->event_thread->pending_follow = ecs->ws;
- stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
+ stop_pc = regcache_read_pc (get_thread_regcache (ecs->event_thread));
ecs->event_thread->control.stop_bpstat
= bpstat_stop_status (get_current_regcache ()->aspace (),
- stop_pc, ecs->ptid, &ecs->ws);
+ stop_pc, ecs->event_thread, &ecs->ws);
if (handle_stop_requested (ecs))
return;
watchpoints, for example, always appear in the bpstat. */
if (!bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
{
- ptid_t parent;
- ptid_t child;
int should_resume;
int follow_child
= (follow_fork_mode_string == follow_fork_mode_child);
should_resume = follow_fork ();
- parent = ecs->ptid;
- child = ecs->ws.value.related_pid;
+ thread_info *parent = ecs->event_thread;
+ thread_info *child = find_thread_ptid (ecs->ws.value.related_pid);
/* At this point, the parent is marked running, and the
child is marked stopped. */
/* If not resuming the parent, mark it stopped. */
if (follow_child && !detach_fork && !non_stop && !sched_multi)
- set_running (parent, 0);
+ parent->set_running (false);
/* If resuming the child, mark it running. */
if (follow_child || (!detach_fork && (non_stop || sched_multi)))
- set_running (child, 1);
+ child->set_running (true);
/* In non-stop mode, also resume the other branch. */
if (!detach_fork && (non_stop
fprintf_unfiltered (gdb_stdlog,
"infrun: TARGET_WAITKIND_VFORK_DONE\n");
- if (!ptid_equal (ecs->ptid, inferior_ptid))
- context_switch (ecs->ptid);
+ context_switch (ecs);
current_inferior ()->waiting_for_vfork_done = 0;
current_inferior ()->pspace->breakpoints_not_allowed = 0;
/* Note we can't read registers yet (the stop_pc), because we
don't yet know the inferior's post-exec architecture.
'stop_pc' is explicitly read below instead. */
- if (!ptid_equal (ecs->ptid, inferior_ptid))
- switch_to_thread_no_regs (ecs->event_thread);
+ switch_to_thread_no_regs (ecs->event_thread);
/* Do whatever is necessary to the parent branch of the vfork. */
handle_vfork_child_exec_or_exit (1);
stop. */
follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
- stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
+ stop_pc = regcache_read_pc (get_thread_regcache (ecs->event_thread));
/* In follow_exec we may have deleted the original thread and
created a new one. Make sure that the event thread is the
ecs->event_thread->control.stop_bpstat
= bpstat_stop_status (get_current_regcache ()->aspace (),
- stop_pc, ecs->ptid, &ecs->ws);
+ stop_pc, ecs->event_thread, &ecs->ws);
/* Note that this may be referenced from inside
bpstat_stop_status above, through inferior_has_execd. */
/* Reverse execution: target ran out of history info. */
/* Switch to the stopped thread. */
- if (!ptid_equal (ecs->ptid, inferior_ptid))
- context_switch (ecs->ptid);
+ context_switch (ecs);
if (debug_infrun)
fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
delete_just_stopped_threads_single_step_breakpoints ();
- stop_pc = regcache_read_pc (get_thread_regcache (inferior_ptid));
+ stop_pc = regcache_read_pc (get_thread_regcache (inferior_thread ()));
if (handle_stop_requested (ecs))
return;
"infrun: restart threads: [%s] continuing\n",
target_pid_to_str (tp->ptid));
reset_ecs (ecs, tp);
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
keep_going_pass_signal (ecs);
}
}
{
int had_step_over_info;
- displaced_step_fixup (ecs->ptid,
+ displaced_step_fixup (ecs->event_thread,
ecs->event_thread->suspend.stop_signal);
had_step_over_info = step_over_info_valid_p ();
another thread has a pending event for this breakpoint too,
we'd discard its event (because the breakpoint that
originally caused the event was no longer inserted). */
- context_switch (ecs->ptid);
+ context_switch (ecs);
insert_breakpoints ();
restart_threads (ecs->event_thread);
gdb_assert (!tp->executing);
- regcache = get_thread_regcache (tp->ptid);
+ regcache = get_thread_regcache (tp);
tp->suspend.stop_pc = regcache_read_pc (regcache);
if (debug_infrun)
&& ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
- stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
+ stop_pc = regcache_read_pc (get_thread_regcache (ecs->event_thread));
if (debug_infrun)
{
- struct regcache *regcache = get_thread_regcache (ecs->ptid);
+ struct regcache *regcache = get_thread_regcache (ecs->event_thread);
struct gdbarch *gdbarch = regcache->arch ();
scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
/* This is originated from start_remote(), start_inferior() and
shared libraries hook functions. */
- stop_soon = get_inferior_stop_soon (ecs->ptid);
+ stop_soon = get_inferior_stop_soon (ecs);
if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
{
- if (!ptid_equal (ecs->ptid, inferior_ptid))
- context_switch (ecs->ptid);
+ context_switch (ecs);
if (debug_infrun)
fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
stop_print_frame = 1;
if (debug_infrun)
fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
- context_switch (ecs->ptid);
+ context_switch (ecs);
if (deprecated_context_hook)
- deprecated_context_hook (ptid_to_global_thread_id (ecs->ptid));
+ deprecated_context_hook (ecs->event_thread->global_num);
}
/* At this point, get hold of the now-current thread's frame. */
struct regcache *regcache;
CORE_ADDR pc;
- regcache = get_thread_regcache (ecs->ptid);
+ regcache = get_thread_regcache (ecs->event_thread);
const address_space *aspace = regcache->aspace ();
pc = regcache_read_pc (regcache);
inline function call sites). */
if (ecs->event_thread->control.step_range_end != 1)
{
- const address_space *aspace =
- get_thread_regcache (ecs->ptid)->aspace ();
+ const address_space *aspace
+ = get_thread_regcache (ecs->event_thread)->aspace ();
/* skip_inline_frames is expensive, so we avoid it if we can
determine that the address is one where functions cannot have
&ecs->ws)))
{
stop_chain = build_bpstat_chain (aspace, stop_pc, &ecs->ws);
- skip_inline_frames (ecs->ptid, stop_chain);
+ skip_inline_frames (ecs->event_thread, stop_chain);
/* Re-fetch current thread's frame in case that invalidated
the frame cache. */
handles this event. */
ecs->event_thread->control.stop_bpstat
= bpstat_stop_status (get_current_regcache ()->aspace (),
- stop_pc, ecs->ptid, &ecs->ws, stop_chain);
+ stop_pc, ecs->event_thread, &ecs->ws, stop_chain);
/* Following in case break condition called a
function. */
/* Re-adjust PC to what the program would see if GDB was not
debugging it. */
- regcache = get_thread_regcache (ecs->event_thread->ptid);
+ regcache = get_thread_regcache (ecs->event_thread);
decr_pc = gdbarch_decr_pc_after_break (gdbarch);
if (decr_pc != 0)
{
if (frame_id_eq (get_frame_id (get_current_frame ()),
ecs->event_thread->control.step_frame_id)
- && inline_skipped_frames (ecs->ptid))
+ && inline_skipped_frames (ecs->event_thread))
{
if (debug_infrun)
fprintf_unfiltered (gdb_stdlog,
if (call_sal.line == ecs->event_thread->current_line
&& call_sal.symtab == ecs->event_thread->current_symtab)
- step_into_inline_frame (ecs->ptid);
+ step_into_inline_frame (ecs->event_thread);
end_stepping_range (ecs);
return;
stepping thread is still alive. For that reason, we need to
synchronously query the target now. */
- if (is_exited (tp->ptid)
- || !target_thread_alive (tp->ptid))
+ if (tp->state == THREAD_EXITED || !target_thread_alive (tp->ptid))
{
if (debug_infrun)
fprintf_unfiltered (gdb_stdlog,
"infrun: not resuming previously "
"stepped thread, it has vanished\n");
- delete_thread (tp->ptid);
+ delete_thread (tp);
return 0;
}
"infrun: resuming previously stepped thread\n");
reset_ecs (ecs, tp);
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
- stop_pc = regcache_read_pc (get_thread_regcache (tp->ptid));
+ stop_pc = regcache_read_pc (get_thread_regcache (tp));
frame = get_current_frame ();
/* If the PC of the thread we were trying to single-step has
/* Save the pc before execution, to compare with pc after stop. */
ecs->event_thread->prev_pc
- = regcache_read_pc (get_thread_regcache (ecs->ptid));
+ = regcache_read_pc (get_thread_regcache (ecs->event_thread));
if (ecs->event_thread->control.trap_expected)
{
#include "block.h"
#include "frame-unwind.h"
#include "inferior.h"
+#include "gdbthread.h"
#include "regcache.h"
#include "symtab.h"
#include "vec.h"
keep our own list. */
struct inline_state
{
- inline_state (ptid_t ptid_, int skipped_frames_, CORE_ADDR saved_pc_,
+ inline_state (thread_info *thread_, int skipped_frames_, CORE_ADDR saved_pc_,
symbol *skipped_symbol_)
- : ptid (ptid_), skipped_frames (skipped_frames_), saved_pc (saved_pc_),
+ : thread (thread_), skipped_frames (skipped_frames_), saved_pc (saved_pc_),
skipped_symbol (skipped_symbol_)
{}
/* The thread this data relates to. It should be a currently
- stopped thread; we assume thread IDs never change while the
- thread is stopped. */
- ptid_t ptid;
+ stopped thread. */
+ thread_info *thread;
/* The number of inlined functions we are skipping. Each of these
functions can be stepped in to. */
static std::vector<inline_state> inline_states;
-/* Locate saved inlined frame state for PTID, if it exists
- and is valid. */
+/* Locate saved inlined frame state for THREAD, if it exists and is
+ valid. */
static struct inline_state *
-find_inline_frame_state (ptid_t ptid)
+find_inline_frame_state (thread_info *thread)
{
auto state_it = std::find_if (inline_states.begin (), inline_states.end (),
- [&ptid] (const inline_state &state)
+ [thread] (const inline_state &state)
{
- return ptid == state.ptid;
+ return state.thread == thread;
});
if (state_it == inline_states.end ())
return nullptr;
inline_state &state = *state_it;
- struct regcache *regcache = get_thread_regcache (ptid);
+ struct regcache *regcache = get_thread_regcache (thread);
CORE_ADDR current_pc = regcache_read_pc (regcache);
if (current_pc != state.saved_pc)
auto it = std::remove_if (inline_states.begin (), inline_states.end (),
[pid] (const inline_state &state)
{
- return pid == state.ptid.pid ();
+ return pid == state.thread->inf->pid;
});
inline_states.erase (it, inline_states.end ());
auto it = std::find_if (inline_states.begin (), inline_states.end (),
[&ptid] (const inline_state &state)
{
- return ptid == state.ptid;
+ return ptid == state.thread->ptid;
});
if (it != inline_states.end ())
const struct block *frame_block, *cur_block;
int depth;
struct frame_info *next_frame;
- struct inline_state *state = find_inline_frame_state (inferior_ptid);
+ struct inline_state *state = find_inline_frame_state (inferior_thread ());
this_pc = get_frame_address_in_block (this_frame);
frame_block = block_for_pc (this_pc);
/* See inline-frame.h. */
void
-skip_inline_frames (ptid_t ptid, bpstat stop_chain)
+skip_inline_frames (thread_info *thread, bpstat stop_chain)
{
const struct block *frame_block, *cur_block;
struct symbol *last_sym = NULL;
}
}
- gdb_assert (find_inline_frame_state (ptid) == NULL);
- inline_states.emplace_back (ptid, skip_count, this_pc, last_sym);
+ gdb_assert (find_inline_frame_state (thread) == NULL);
+ inline_states.emplace_back (thread, skip_count, this_pc, last_sym);
if (skip_count != 0)
reinit_frame_cache ();
/* Step into an inlined function by unhiding it. */
void
-step_into_inline_frame (ptid_t ptid)
+step_into_inline_frame (thread_info *thread)
{
- struct inline_state *state = find_inline_frame_state (ptid);
+ inline_state *state = find_inline_frame_state (thread);
gdb_assert (state != NULL && state->skipped_frames > 0);
state->skipped_frames--;
frame. */
int
-inline_skipped_frames (ptid_t ptid)
+inline_skipped_frames (thread_info *thread)
{
- struct inline_state *state = find_inline_frame_state (ptid);
+ inline_state *state = find_inline_frame_state (thread);
if (state == NULL)
return 0;
the function inlined into the current frame. */
struct symbol *
-inline_skipped_symbol (ptid_t ptid)
+inline_skipped_symbol (thread_info *thread)
{
- struct inline_state *state = find_inline_frame_state (ptid);
+ inline_state *state = find_inline_frame_state (thread);
gdb_assert (state != NULL);
return state->skipped_symbol;
they can be stepped into later. If we are unwinding already
outer frames from some non-inlined frame this does not apply. */
if (next_frame == NULL)
- inline_count += inline_skipped_frames (inferior_ptid);
+ inline_count += inline_skipped_frames (inferior_thread ());
return inline_count;
}
user's perspective. GDB will stop "in" the inlined frame instead of
the caller. */
-void skip_inline_frames (ptid_t ptid, struct bpstats *stop_chain);
+void skip_inline_frames (thread_info *thread, struct bpstats *stop_chain);
/* Forget about any hidden inlined functions in PTID, which is new or
about to be resumed. If PTID is minus_one_ptid, forget about all
/* Step into an inlined function by unhiding it. */
-void step_into_inline_frame (ptid_t ptid);
+void step_into_inline_frame (thread_info *thread);
/* Return the number of hidden functions inlined into the current
frame. */
-int inline_skipped_frames (ptid_t ptid);
+int inline_skipped_frames (thread_info *thread);
/* If one or more inlined functions are hidden, return the symbol for
the function inlined into the current frame. */
-struct symbol *inline_skipped_symbol (ptid_t ptid);
+struct symbol *inline_skipped_symbol (thread_info *thread);
/* Return the number of functions inlined into THIS_FRAME. Some of
the callees may not have associated frames (see
/* If fi->parent_ptid is not a part of lwp but it's a part of checkpoint
list, waitpid the ptid.
- If fi->parent_ptid is a part of lwp and it is stoped, waitpid the
+ If fi->parent_ptid is a part of lwp and it is stopped, waitpid the
ptid. */
- if ((!find_thread_ptid (pptid) && find_fork_ptid (pptid))
- || (find_thread_ptid (pptid) && is_stopped (pptid)))
+ thread_info *parent = find_thread_ptid (pptid);
+ if ((parent == NULL && find_fork_ptid (pptid))
+ || (parent != NULL && parent->state == THREAD_STOPPED))
{
if (inferior_call_waitpid (pptid, ptid_get_pid (ptid)))
warning (_("Unable to wait pid %s"), target_pid_to_str (ptid));
if (print_thread_events)
printf_unfiltered (_("[%s exited]\n"), target_pid_to_str (lp->ptid));
- delete_thread (lp->ptid);
+ delete_thread (th);
}
delete_lwp (lp->ptid);
signo = GDB_SIGNAL_0; /* a pending ptrace event, not a real signal. */
else if (lp->status)
signo = gdb_signal_from_host (WSTOPSIG (lp->status));
- else if (target_is_non_stop_p () && !is_executing (lp->ptid))
+ else
{
struct thread_info *tp = find_thread_ptid (lp->ptid);
- if (tp->suspend.waitstatus_pending_p)
- signo = tp->suspend.waitstatus.value.sig;
- else
- signo = tp->suspend.stop_signal;
- }
- else if (!target_is_non_stop_p ())
- {
- struct target_waitstatus last;
- ptid_t last_ptid;
-
- get_last_target_status (&last_ptid, &last);
-
- if (ptid_get_lwp (lp->ptid) == ptid_get_lwp (last_ptid))
+ if (target_is_non_stop_p () && !tp->executing)
{
- struct thread_info *tp = find_thread_ptid (lp->ptid);
+ if (tp->suspend.waitstatus_pending_p)
+ signo = tp->suspend.waitstatus.value.sig;
+ else
+ signo = tp->suspend.stop_signal;
+ }
+ else if (!target_is_non_stop_p ())
+ {
+ struct target_waitstatus last;
+ ptid_t last_ptid;
+
+ get_last_target_status (&last_ptid, &last);
- signo = tp->suspend.stop_signal;
+ if (ptid_get_lwp (lp->ptid) == ptid_get_lwp (last_ptid))
+ signo = tp->suspend.stop_signal;
}
}
{
struct target_waitstatus *ourstatus = &lp->waitstatus;
struct gdbarch *gdbarch = target_thread_architecture (lp->ptid);
- int syscall_number = (int) gdbarch_get_syscall_number (gdbarch, lp->ptid);
+ thread_info *thread = find_thread_ptid (lp->ptid);
+ int syscall_number = (int) gdbarch_get_syscall_number (gdbarch, thread);
if (stopping)
{
bookkeeping. */
struct thread_db_info *thread_db_list;
-static void thread_db_find_new_threads_1 (ptid_t ptid);
-static void thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new);
+static void thread_db_find_new_threads_1 (thread_info *stopped);
+static void thread_db_find_new_threads_2 (thread_info *stopped,
+ bool until_no_new);
static void check_thread_signals (void);
}
}
-/* Fetch the user-level thread id of PTID. */
+/* Fetch the user-level thread id of PTID. STOPPED is a stopped
+ thread that we can use to access memory. */
static struct thread_info *
-thread_from_lwp (ptid_t ptid)
+thread_from_lwp (thread_info *stopped, ptid_t ptid)
{
td_thrhandle_t th;
td_thrinfo_t ti;
info = get_thread_db_info (ptid_get_pid (ptid));
/* Access an lwp we know is stopped. */
- info->proc_handle.ptid = ptid;
+ info->proc_handle.thread = stopped;
err = info->td_ta_map_lwp2thr_p (info->thread_agent, ptid_get_lwp (ptid),
&th);
if (err != TD_OK)
if (info == NULL)
return 0;
- thread_from_lwp (child);
+ thread_info *stopped = find_thread_ptid (parent);
- /* If we do not know about the main thread yet, this would be a good
- time to find it. */
- thread_from_lwp (parent);
+ thread_from_lwp (stopped, child);
+
+ /* If we do not know about the main thread's pthread info yet, this
+ would be a good time to find it. */
+ thread_from_lwp (stopped, parent);
return 1;
}
otherwise. */
static int
-thread_db_find_new_threads_silently (ptid_t ptid)
+thread_db_find_new_threads_silently (thread_info *stopped)
{
TRY
{
- thread_db_find_new_threads_2 (ptid, 1);
+ thread_db_find_new_threads_2 (stopped, true);
}
CATCH (except, RETURN_MASK_ERROR)
CHK (TDB_VERBOSE_DLSYM (info, td_ta_new));
/* Initialize the structure that identifies the child process. */
- info->proc_handle.ptid = inferior_ptid;
+ info->proc_handle.thread = inferior_thread ();
/* Now attempt to open a connection to the thread library. */
err = info->td_ta_new_p (&info->proc_handle, &info->thread_agent);
{
struct lwp_info *lp;
int pid = ptid_get_pid (inferior_ptid);
+ thread_info *curr_thread = inferior_thread ();
linux_stop_and_wait_all_lwps ();
ALL_LWPS (lp)
if (ptid_get_pid (lp->ptid) == pid)
- thread_from_lwp (lp->ptid);
+ thread_from_lwp (curr_thread, lp->ptid);
linux_unstop_all_lwps ();
}
- else if (thread_db_find_new_threads_silently (inferior_ptid) != 0)
+ else if (thread_db_find_new_threads_silently (inferior_thread ()) != 0)
{
/* Even if libthread_db initializes, if the thread list is
corrupted, we'd not manage to list any threads. Better reject this
}
/* Fill in the thread's user-level thread id and status. */
- thread_from_lwp (ptid);
+ thread_from_lwp (find_thread_ptid (ptid), ptid);
return ptid;
}
{
td_thrinfo_t ti;
td_err_e err;
- ptid_t ptid;
struct thread_info *tp;
struct callback_data *cb_data = (struct callback_data *) data;
struct thread_db_info *info = cb_data->info;
return 0;
}
- ptid = ptid_build (info->pid, ti.ti_lid, 0);
+ ptid_t ptid (info->pid, ti.ti_lid);
tp = find_thread_ptid (ptid);
if (tp == NULL || tp->priv == NULL)
record_thread (info, tp, ptid, th_p, &ti);
searches in a row do not discover any new threads. */
static void
-thread_db_find_new_threads_2 (ptid_t ptid, int until_no_new)
+thread_db_find_new_threads_2 (thread_info *stopped, bool until_no_new)
{
td_err_e err = TD_OK;
struct thread_db_info *info;
int i, loop;
- info = get_thread_db_info (ptid_get_pid (ptid));
+ info = get_thread_db_info (stopped->ptid.pid ());
/* Access an lwp we know is stopped. */
- info->proc_handle.ptid = ptid;
+ info->proc_handle.thread = stopped;
if (until_no_new)
{
}
static void
-thread_db_find_new_threads_1 (ptid_t ptid)
+thread_db_find_new_threads_1 (thread_info *stopped)
{
- thread_db_find_new_threads_2 (ptid, 0);
+ thread_db_find_new_threads_2 (stopped, 0);
}
/* Implement the to_update_thread_list target method for this
if (info == NULL)
continue;
- thread = any_live_thread_of_process (inf->pid);
+ thread = any_live_thread_of_inferior (inf);
if (thread == NULL || thread->executing)
continue;
if (target_has_execution_1 (thread->ptid))
continue;
- thread_db_find_new_threads_1 (thread->ptid);
+ thread_db_find_new_threads_1 (thread);
}
/* Give the beneath target a chance to do extra processing. */
/* We may not have discovered the thread yet. */
if (thread_info != NULL && thread_info->priv == NULL)
- thread_info = thread_from_lwp (ptid);
+ thread_info = thread_from_lwp (thread_info, ptid);
if (thread_info != NULL && thread_info->priv != NULL)
{
#include "gdbthread.h"
#include "mi-parse.h"
#include "common/gdb_optional.h"
+#include "inferior.h"
extern unsigned int varobjdebug; /* defined in varobj.c. */
mi_cmd_var_update_iter (struct varobj *var, void *data_pointer)
{
struct mi_cmd_var_update *data = (struct mi_cmd_var_update *) data_pointer;
- int thread_id, thread_stopped;
+ bool thread_stopped;
- thread_id = varobj_get_thread_id (var);
+ int thread_id = varobj_get_thread_id (var);
- if (thread_id == -1
- && (ptid_equal (inferior_ptid, null_ptid)
- || is_stopped (inferior_ptid)))
- thread_stopped = 1;
+ if (thread_id == -1)
+ {
+ thread_stopped = (inferior_ptid == null_ptid
+ || inferior_thread ()->state == THREAD_STOPPED);
+ }
else
{
- struct thread_info *tp = find_thread_global_id (thread_id);
+ thread_info *tp = find_thread_global_id (thread_id);
- if (tp)
- thread_stopped = is_stopped (tp->ptid);
- else
- thread_stopped = 1;
+ thread_stopped = (tp == NULL
+ || tp->state == THREAD_STOPPED);
}
if (thread_stopped
static void
mi_new_thread (struct thread_info *t)
{
- struct inferior *inf = find_inferior_ptid (t->ptid);
-
- gdb_assert (inf);
-
SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
fprintf_unfiltered (mi->event_channel,
"thread-created,id=\"%d\",group-id=\"i%d\"",
- t->global_num, inf->num);
+ t->global_num, t->inf->num);
gdb_flush (mi->event_channel);
}
}
else
mi_uiout->field_string ("stopped-threads", "all");
- core = target_core_of_thread (inferior_ptid);
+ core = target_core_of_thread (tp->ptid);
if (core != -1)
mi_uiout->field_int ("core", core);
}
}
}
-static int
-mi_output_running_pid (struct thread_info *info, void *arg)
+static void
+mi_output_running (struct thread_info *thread)
{
- ptid_t *ptid = (ptid_t *) arg;
-
SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
if (mi == NULL)
continue;
- if (ptid_get_pid (*ptid) == ptid_get_pid (info->ptid))
- fprintf_unfiltered (mi->raw_stdout,
- "*running,thread-id=\"%d\"\n",
- info->global_num);
+ fprintf_unfiltered (mi->raw_stdout,
+ "*running,thread-id=\"%d\"\n",
+ thread->global_num);
}
-
- return 0;
-}
-
-static int
-mi_inferior_count (struct inferior *inf, void *arg)
-{
- if (inf->pid != 0)
- {
- int *count_p = (int *) arg;
- (*count_p)++;
- }
-
- return 0;
}
static void
else if (ptid_is_pid (ptid))
{
int count = 0;
+ inferior *inf;
/* Backwards compatibility. If there's only one inferior,
output "all", otherwise, output each resumed thread
individually. */
- iterate_over_inferiors (mi_inferior_count, &count);
+ ALL_INFERIORS (inf)
+ if (inf->pid != 0)
+ {
+ count++;
+ if (count > 1)
+ break;
+ }
if (count == 1)
fprintf_unfiltered (mi->raw_stdout, "*running,thread-id=\"all\"\n");
else
- iterate_over_threads (mi_output_running_pid, &ptid);
+ {
+ thread_info *tp;
+ inferior *curinf = current_inferior ();
+
+ ALL_NON_EXITED_THREADS (tp)
+ if (tp->inf == curinf)
+ mi_output_running (tp);
+ }
}
else
{
- struct thread_info *ti = find_thread_ptid (ptid);
+ thread_info *ti = find_thread_ptid (ptid);
gdb_assert (ti);
- fprintf_unfiltered (mi->raw_stdout, "*running,thread-id=\"%d\"\n",
- ti->global_num);
+ mi_output_running (ti);
}
if (!running_result_record_printed && mi_proceeded)
if (mi_suppress_notification.user_selected_context)
return;
- tp = find_thread_ptid (inferior_ptid);
+ if (inferior_ptid != null_ptid)
+ tp = inferior_thread ();
+ else
+ tp = NULL;
SWITCH_THRU_ALL_UIS ()
{
static void
proceed_thread (struct thread_info *thread, int pid)
{
- if (!is_stopped (thread->ptid))
+ if (thread->state != THREAD_STOPPED)
return;
if (pid != 0 && ptid_get_pid (thread->ptid) != pid)
return;
- switch_to_thread (thread->ptid);
+ switch_to_thread (thread);
clear_proceed_status (0);
proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
}
{
int pid = *(int *)arg;
- if (!is_running (thread->ptid))
+ if (thread->state != THREAD_RUNNING)
return 0;
if (ptid_get_pid (thread->ptid) != pid)
if (inf->pid != 0)
{
- if (inf->pid != ptid_get_pid (inferior_ptid))
- {
- struct thread_info *tp;
-
- tp = any_thread_of_process (inf->pid);
- if (!tp)
- error (_("Inferior has no threads."));
+ thread_info *tp = any_thread_of_inferior (inf);
+ if (tp == NULL)
+ error (_("Inferior has no threads."));
- switch_to_thread (tp->ptid);
- }
+ switch_to_thread (tp);
}
else
{
set_current_inferior (inf);
- switch_to_thread (null_ptid);
+ switch_to_no_thread ();
set_current_program_space (inf->pspace);
}
mi_execute_cli_command (run_cmd, async_p,
{
int pid = *(int *)p;
- if (ptid_get_pid (ti->ptid) == pid && !is_exited (ti->ptid))
+ if (ptid_get_pid (ti->ptid) == pid && ti->state != THREAD_EXITED)
return 1;
return 0;
if (!tp)
error (_("Thread group is empty"));
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
}
detach_command (NULL, 0);
set_current_inferior (new_inferior);
if (new_inferior->pid != 0)
- tp = any_thread_of_process (new_inferior->pid);
- switch_to_thread (tp ? tp->ptid : null_ptid);
+ tp = any_thread_of_inferior (new_inferior);
+ if (tp != NULL)
+ switch_to_thread (tp);
+ else
+ switch_to_no_thread ();
set_current_program_space (new_inferior->pspace);
}
provide --thread if it wishes to operate on a specific
thread. */
if (inf->pid != 0)
- tp = any_live_thread_of_process (inf->pid);
- switch_to_thread (tp ? tp->ptid : null_ptid);
+ tp = any_live_thread_of_inferior (inf);
+ if (tp != NULL)
+ switch_to_thread (tp);
+ else
+ switch_to_no_thread ();
set_current_program_space (inf->pspace);
}
if (parse->thread != -1)
{
- struct thread_info *tp = find_thread_global_id (parse->thread);
+ thread_info *tp = find_thread_global_id (parse->thread);
- if (!tp)
+ if (tp == NULL)
error (_("Invalid thread id: %d"), parse->thread);
- if (is_exited (tp->ptid))
+ if (tp->state == THREAD_EXITED)
error (_("Thread id: %d has terminated"), parse->thread);
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
}
if (parse->frame != -1)
static LONGEST
mips_linux_get_syscall_number (struct gdbarch *gdbarch,
- ptid_t ptid)
+ thread_info *thread)
{
- struct regcache *regcache = get_thread_regcache (ptid);
+ struct regcache *regcache = get_thread_regcache (thread);
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
r0 register. When the function fails, it returns -1. */
static LONGEST
ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
- ptid_t ptid)
+ thread_info *thread)
{
- struct regcache *regcache = get_thread_regcache (ptid);
+ struct regcache *regcache = get_thread_regcache (thread);
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
#include "gdbcore.h"
#include "inferior.h"
+#include "gdbthread.h"
#include "symtab.h"
#include "target.h"
#include "regcache.h"
int ret;
CORE_ADDR core_addr = ps_addr_to_core_addr (addr);
- inferior_ptid = ph->ptid;
+ inferior_ptid = ph->thread->ptid;
if (write)
ret = target_write_memory (core_addr, buf, len);
ps_pglobal_lookup (struct ps_prochandle *ph, const char *obj,
const char *name, psaddr_t *sym_addr)
{
- struct inferior *inf = find_inferior_ptid (ph->ptid);
+ inferior *inf = ph->thread->inf;
scoped_restore_current_program_space restore_pspace;
ps_err_e
ps_lgetregs (struct ps_prochandle *ph, lwpid_t lwpid, prgregset_t gregset)
{
- ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
- struct regcache *regcache
- = get_thread_arch_regcache (ptid, target_gdbarch ());
+ struct regcache *regcache = get_thread_regcache (ph->thread);
target_fetch_registers (regcache, -1);
fill_gregset (regcache, (gdb_gregset_t *) gregset, -1);
ps_err_e
ps_lsetregs (struct ps_prochandle *ph, lwpid_t lwpid, const prgregset_t gregset)
{
- ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
- struct regcache *regcache
- = get_thread_arch_regcache (ptid, target_gdbarch ());
+ struct regcache *regcache = get_thread_regcache (ph->thread);
supply_gregset (regcache, (const gdb_gregset_t *) gregset);
target_store_registers (regcache, -1);
ps_err_e
ps_lgetfpregs (struct ps_prochandle *ph, lwpid_t lwpid, gdb_prfpregset_t *fpregset)
{
- ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
- struct regcache *regcache
- = get_thread_arch_regcache (ptid, target_gdbarch ());
+ struct regcache *regcache = get_thread_regcache (ph->thread);
target_fetch_registers (regcache, -1);
fill_fpregset (regcache, (gdb_fpregset_t *) fpregset, -1);
ps_lsetfpregs (struct ps_prochandle *ph, lwpid_t lwpid,
const gdb_prfpregset_t *fpregset)
{
- ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
- struct regcache *regcache
- = get_thread_arch_regcache (ptid, target_gdbarch ());
+ struct regcache *regcache = get_thread_regcache (ph->thread);
supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset);
target_store_registers (regcache, -1);
pid_t
ps_getpid (struct ps_prochandle *ph)
{
- return ptid_get_pid (ph->ptid);
+ return ptid_get_pid (ph->thread->ptid);
}
void
#include "defs.h"
#include "progspace-and-thread.h"
+#include "inferior.h"
/* See progspace-and-thread.h */
if (inf != NULL && inf->pid != 0)
{
- thread_info *tp = any_live_thread_of_process (inf->pid);
+ thread_info *tp = any_live_thread_of_inferior (inf);
if (tp != NULL)
{
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
/* Switching thread switches pspace implicitly. We're
done. */
return;
}
}
- switch_to_thread (null_ptid);
+ switch_to_no_thread ();
set_current_program_space (pspace);
}
#include "gdbcore.h"
#include "solib.h"
#include "gdbthread.h"
+#include "inferior.h"
/* The last program space number assigned. */
int last_program_space_num = 0;
return NULL;
}
- gdbpy_ref<> inf_obj (inferior_to_inferior_object (inf));
+ gdbpy_ref<inferior_object> inf_obj (inferior_to_inferior_object (inf));
if (inf_obj == NULL || evpy_add_attribute (exited_event.get (),
"inferior",
- inf_obj.get ()) < 0)
+ (PyObject *) inf_obj.get ()) < 0)
return NULL;
return exited_event.release ();
if (PyErr_Occurred ())
return -1;
- thread = ptid_to_global_thread_id (inferior_ptid);
- if (thread == 0)
+ if (inferior_ptid == null_ptid)
{
PyErr_SetString (PyExc_ValueError,
_("No thread currently selected."));
return -1;
}
+ thread = inferior_thread ()->global_num;
+
if (internal)
{
internal_bp = PyObject_IsTrue (internal);
struct threadlist_entry *next;
};
-typedef struct
+struct inferior_object
{
PyObject_HEAD
/* Number of threads in the list. */
int nthreads;
-} inferior_object;
+};
extern PyTypeObject inferior_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("inferior_object");
representing INFERIOR. If the object has already been created,
return it and increment the reference count, otherwise, create it.
Return NULL on failure. */
-PyObject *
+
+inferior_object *
inferior_to_inferior_object (struct inferior *inferior)
{
inferior_object *inf_obj;
/* We are returning a new reference. */
Py_INCREF ((PyObject *)inf_obj);
- return (PyObject *) inf_obj;
+ return inf_obj;
}
/* Called when a new inferior is created. Notifies any Python event
if (evregpy_no_listeners_p (gdb_py_events.new_inferior))
return;
- gdbpy_ref<> inf_obj (inferior_to_inferior_object (inf));
+ gdbpy_ref<inferior_object> inf_obj (inferior_to_inferior_object (inf));
if (inf_obj == NULL)
{
gdbpy_print_stack ();
gdbpy_ref<> event (create_event_object (&new_inferior_event_object_type));
if (event == NULL
- || evpy_add_attribute (event.get (), "inferior", inf_obj.get ()) < 0
+ || evpy_add_attribute (event.get (), "inferior",
+ (PyObject *) inf_obj.get ()) < 0
|| evpy_emit_event (event.get (), gdb_py_events.new_inferior) < 0)
gdbpy_print_stack ();
}
if (evregpy_no_listeners_p (gdb_py_events.inferior_deleted))
return;
- gdbpy_ref<> inf_obj (inferior_to_inferior_object (inf));
+ gdbpy_ref<inferior_object> inf_obj (inferior_to_inferior_object (inf));
if (inf_obj == NULL)
{
gdbpy_print_stack ();
gdbpy_ref<> event (create_event_object (&inferior_deleted_event_object_type));
if (event == NULL
- || evpy_add_attribute (event.get (), "inferior", inf_obj.get ()) < 0
+ || evpy_add_attribute (event.get (), "inferior",
+ (PyObject *) inf_obj.get ()) < 0
|| evpy_emit_event (event.get (), gdb_py_events.inferior_deleted) < 0)
gdbpy_print_stack ();
}
struct inferior *inf = find_inferior_pid (pid);
if (inf)
- return inferior_to_inferior_object (inf);
+ return (PyObject *) inferior_to_inferior_object (inf);
return NULL;
}
thread_object *
-find_thread_object (ptid_t ptid)
+thread_to_thread_object (thread_info *thr)
{
- int pid;
- struct threadlist_entry *thread;
-
- pid = ptid_get_pid (ptid);
- if (pid == 0)
- return NULL;
-
- gdbpy_ref<> inf_obj (find_inferior_object (pid));
+ gdbpy_ref<inferior_object> inf_obj (inferior_to_inferior_object (thr->inf));
if (inf_obj == NULL)
return NULL;
- for (thread = ((inferior_object *)(inf_obj.get ()))->threads; thread;
+ for (threadlist_entry *thread = inf_obj->threads;
+ thread != NULL;
thread = thread->next)
- if (ptid_equal (thread->thread_obj->thread->ptid, ptid))
+ if (thread->thread_obj->thread == thr)
return thread->thread_obj;
return NULL;
gdbpy_enter enter_py (python_gdbarch, python_language);
gdbpy_ref<inferior_object> inf_obj
- ((inferior_object *) find_inferior_object (ptid_get_pid (tp->ptid)));
+ ((inferior_object *) inferior_to_inferior_object (tp->inf));
if (inf_obj == NULL)
return;
build_inferior_list (struct inferior *inf, void *arg)
{
PyObject *list = (PyObject *) arg;
- gdbpy_ref<> inferior (inferior_to_inferior_object (inf));
+ gdbpy_ref<inferior_object> inferior (inferior_to_inferior_object (inf));
- if (inferior == NULL)
+ if (inferior == NULL)
return 0;
- return PyList_Append (list, inferior.get ()) ? 1 : 0;
+ return PyList_Append (list, (PyObject *) inferior.get ()) ? 1 : 0;
}
/* Implementation of gdb.inferiors () -> (gdb.Inferior, ...).
thread_info = find_thread_by_handle (val, inf_obj->inferior);
if (thread_info != NULL)
{
- result = (PyObject *) find_thread_object (thread_info->ptid);
+ result = (PyObject *) thread_to_thread_object (thread_info);
if (result != NULL)
Py_INCREF (result);
}
PyObject *
gdbpy_selected_inferior (PyObject *self, PyObject *args)
{
- return inferior_to_inferior_object (current_inferior ());
+ return (PyObject *) inferior_to_inferior_object (current_inferior ());
}
int
return NULL;
thread_obj->thread = tp;
- thread_obj->inf_obj = find_inferior_object (ptid_get_pid (tp->ptid));
+ thread_obj->inf_obj = (PyObject *) inferior_to_inferior_object (tp->inf);
return thread_obj;
}
TRY
{
- switch_to_thread (thread_obj->thread->ptid);
+ switch_to_thread (thread_obj->thread);
}
CATCH (except, RETURN_MASK_ALL)
{
THPY_REQUIRE_VALID (thread_obj);
- if (is_stopped (thread_obj->thread->ptid))
+ if (thread_obj->thread->state == THREAD_STOPPED)
Py_RETURN_TRUE;
Py_RETURN_FALSE;
THPY_REQUIRE_VALID (thread_obj);
- if (is_running (thread_obj->thread->ptid))
+ if (thread_obj->thread->state == THREAD_RUNNING)
Py_RETURN_TRUE;
Py_RETURN_FALSE;
THPY_REQUIRE_VALID (thread_obj);
- if (is_exited (thread_obj->thread->ptid))
+ if (thread_obj->thread->state == THREAD_EXITED)
Py_RETURN_TRUE;
Py_RETURN_FALSE;
PyObject *
gdbpy_selected_thread (PyObject *self, PyObject *args)
{
- PyObject *thread_obj;
-
- thread_obj = (PyObject *) find_thread_object (inferior_ptid);
- if (thread_obj)
+ if (inferior_ptid != null_ptid)
{
- Py_INCREF (thread_obj);
- return thread_obj;
+ PyObject *thread_obj
+ = (PyObject *) thread_to_thread_object (inferior_thread ());
+ if (thread_obj != NULL)
+ {
+ Py_INCREF (thread_obj);
+ return thread_obj;
+ }
}
Py_RETURN_NONE;
PyObject_HEAD
/* The thread this list belongs to. */
- ptid_t ptid;
+ thread_info *thread;
/* The first index being part of this list. */
Py_ssize_t first;
}
obj = (const recpy_element_object *) pyobject;
- tinfo = find_thread_ptid (obj->ptid);
+ tinfo = obj->thread;
if (tinfo == NULL || btrace_is_empty (tinfo))
{
}
obj = (const recpy_element_object *) pyobject;
- tinfo = find_thread_ptid (obj->ptid);
+ tinfo = obj->thread;
if (tinfo == NULL || btrace_is_empty (tinfo))
{
gdb.RecordInstruction or gdb.RecordGap object for it accordingly. */
static PyObject *
-btpy_insn_or_gap_new (const thread_info *tinfo, Py_ssize_t number)
+btpy_insn_or_gap_new (thread_info *tinfo, Py_ssize_t number)
{
btrace_insn_iterator iter;
int err_code;
return recpy_gap_new (err_code, err_string, number);
}
- return recpy_insn_new (tinfo->ptid, RECORD_METHOD_BTRACE, number);
+ return recpy_insn_new (tinfo, RECORD_METHOD_BTRACE, number);
}
/* Create a new gdb.BtraceList object. */
static PyObject *
-btpy_list_new (ptid_t ptid, Py_ssize_t first, Py_ssize_t last, Py_ssize_t step,
+btpy_list_new (thread_info *thread, Py_ssize_t first, Py_ssize_t last, Py_ssize_t step,
PyTypeObject *element_type)
{
btpy_list_object * const obj = PyObject_New (btpy_list_object,
if (obj == NULL)
return NULL;
- obj->ptid = ptid;
+ obj->thread = thread;
obj->first = first;
obj->last = last;
obj->step = step;
if (func == NULL)
return NULL;
- tinfo = find_thread_ptid (((recpy_element_object *) self)->ptid);
+ tinfo = ((recpy_element_object *) self)->thread;
return PyInt_FromLong (tinfo->btrace.level + func->level);
}
if (len == 0)
len = 1;
- return btpy_list_new (((recpy_element_object *) self)->ptid,
+ return btpy_list_new (((recpy_element_object *) self)->thread,
func->insn_offset, func->insn_offset + len, 1,
&recpy_insn_type);
}
if (func->up == 0)
Py_RETURN_NONE;
- return recpy_func_new (((recpy_element_object *) self)->ptid,
+ return recpy_func_new (((recpy_element_object *) self)->thread,
RECORD_METHOD_BTRACE, func->up);
}
if (func->prev == 0)
Py_RETURN_NONE;
- return recpy_func_new (((recpy_element_object *) self)->ptid,
+ return recpy_func_new (((recpy_element_object *) self)->thread,
RECORD_METHOD_BTRACE, func->prev);
}
if (func->next == 0)
Py_RETURN_NONE;
- return recpy_func_new (((recpy_element_object *) self)->ptid,
+ return recpy_func_new (((recpy_element_object *) self)->thread,
RECORD_METHOD_BTRACE, func->next);
}
number = obj->first + (obj->step * index);
if (obj->element_type == &recpy_insn_type)
- return recpy_insn_new (obj->ptid, RECORD_METHOD_BTRACE, number);
+ return recpy_insn_new (obj->thread, RECORD_METHOD_BTRACE, number);
else
- return recpy_func_new (obj->ptid, RECORD_METHOD_BTRACE, number);
+ return recpy_func_new (obj->thread, RECORD_METHOD_BTRACE, number);
}
/* Implementation of BtraceList.__getitem__ (self, slice) -> BtraceList. */
&step, &slicelength))
return NULL;
- return btpy_list_new (obj->ptid, obj->first + obj->step * start,
+ return btpy_list_new (obj->thread, obj->first + obj->step * start,
obj->first + obj->step * stop, obj->step * step,
obj->element_type);
}
if (list_obj->element_type != Py_TYPE (value))
return -1;
- if (!ptid_equal (list_obj->ptid, obj->ptid))
+ if (list_obj->thread != obj->thread)
return -1;
if (index < list_obj->first || index > list_obj->last)
switch (op)
{
case Py_EQ:
- if (ptid_equal (obj1->ptid, obj2->ptid)
+ if (obj1->thread == obj2->thread
&& obj1->element_type == obj2->element_type
&& obj1->first == obj2->first
&& obj1->last == obj2->last
Py_RETURN_FALSE;
case Py_NE:
- if (!ptid_equal (obj1->ptid, obj2->ptid)
+ if (obj1->thread != obj2->thread
|| obj1->element_type != obj2->element_type
|| obj1->first != obj2->first
|| obj1->last != obj2->last
recpy_bt_format (PyObject *self, void *closure)
{
const recpy_record_object * const record = (recpy_record_object *) self;
- const struct thread_info * const tinfo = find_thread_ptid (record->ptid);
+ const struct thread_info * const tinfo = record->thread;
const struct btrace_config * config;
if (tinfo == NULL)
recpy_bt_replay_position (PyObject *self, void *closure)
{
const recpy_record_object * const record = (recpy_record_object *) self;
- const struct thread_info * const tinfo = find_thread_ptid (record->ptid);
+ thread_info * tinfo = record->thread;
if (tinfo == NULL)
Py_RETURN_NONE;
recpy_bt_begin (PyObject *self, void *closure)
{
const recpy_record_object * const record = (recpy_record_object *) self;
- struct thread_info * const tinfo = find_thread_ptid (record->ptid);
+ thread_info *const tinfo = record->thread;
struct btrace_insn_iterator iterator;
if (tinfo == NULL)
recpy_bt_end (PyObject *self, void *closure)
{
const recpy_record_object * const record = (recpy_record_object *) self;
- struct thread_info * const tinfo = find_thread_ptid (record->ptid);
+ thread_info *const tinfo = record->thread;
struct btrace_insn_iterator iterator;
if (tinfo == NULL)
recpy_bt_instruction_history (PyObject *self, void *closure)
{
const recpy_record_object * const record = (recpy_record_object *) self;
- struct thread_info * const tinfo = find_thread_ptid (record->ptid);
+ thread_info *const tinfo = record->thread;
struct btrace_insn_iterator iterator;
unsigned long first = 0;
unsigned long last = 0;
btrace_insn_end (&iterator, &tinfo->btrace);
last = btrace_insn_number (&iterator);
- return btpy_list_new (record->ptid, first, last, 1, &recpy_insn_type);
+ return btpy_list_new (tinfo, first, last, 1, &recpy_insn_type);
}
/* Implementation of
recpy_bt_function_call_history (PyObject *self, void *closure)
{
const recpy_record_object * const record = (recpy_record_object *) self;
- struct thread_info * const tinfo = find_thread_ptid (record->ptid);
+ thread_info *const tinfo = record->thread;
struct btrace_call_iterator iterator;
unsigned long first = 0;
unsigned long last = 0;
btrace_call_end (&iterator, &tinfo->btrace);
last = btrace_call_number (&iterator);
- return btpy_list_new (record->ptid, first, last, 1, &recpy_func_type);
+ return btpy_list_new (tinfo, first, last, 1, &recpy_func_type);
}
/* Implementation of BtraceRecord.goto (self, BtraceInstruction) -> None. */
recpy_bt_goto (PyObject *self, PyObject *args)
{
const recpy_record_object * const record = (recpy_record_object *) self;
- struct thread_info * const tinfo = find_thread_ptid (record->ptid);
+ thread_info *const tinfo = record->thread;
const recpy_element_object *obj;
if (tinfo == NULL || btrace_is_empty (tinfo))
#include "py-record-btrace.h"
#include "py-record-full.h"
#include "target.h"
+#include "gdbthread.h"
/* Python Record type. */
/* Create a new gdb.RecordInstruction object. */
PyObject *
-recpy_insn_new (ptid_t ptid, enum record_method method, Py_ssize_t number)
+recpy_insn_new (thread_info *thread, enum record_method method, Py_ssize_t number)
{
recpy_element_object * const obj = PyObject_New (recpy_element_object,
&recpy_insn_type);
if (obj == NULL)
return NULL;
- obj->ptid = ptid;
+ obj->thread = thread;
obj->method = method;
obj->number = number;
/* Create a new gdb.RecordFunctionSegment object. */
PyObject *
-recpy_func_new (ptid_t ptid, enum record_method method, Py_ssize_t number)
+recpy_func_new (thread_info *thread, enum record_method method, Py_ssize_t number)
{
recpy_element_object * const obj = PyObject_New (recpy_element_object,
&recpy_func_type);
if (obj == NULL)
return NULL;
- obj->ptid = ptid;
+ obj->thread = thread;
obj->method = method;
obj->number = number;
switch (op)
{
case Py_EQ:
- if (ptid_equal (obj1->ptid, obj2->ptid)
+ if (obj1->thread == obj2->thread
&& obj1->method == obj2->method
&& obj1->number == obj2->number)
Py_RETURN_TRUE;
Py_RETURN_FALSE;
case Py_NE:
- if (!ptid_equal (obj1->ptid, obj2->ptid)
+ if (obj1->thread != obj2->thread
|| obj1->method != obj2->method
|| obj1->number != obj2->number)
Py_RETURN_TRUE;
Py_RETURN_NONE;
ret = PyObject_New (recpy_record_object, &recpy_record_type);
- ret->ptid = inferior_ptid;
- ret->method = target_record_method (inferior_ptid);
+ ret->thread = inferior_thread ();
+ ret->method = target_record_method (ret->thread->ptid);
return (PyObject *) ret;
}
{
PyObject_HEAD
- /* The ptid this object refers to. */
- ptid_t ptid;
+ /* The thread this object refers to. */
+ thread_info *thread;
/* The current recording method. */
enum record_method method;
{
PyObject_HEAD
- /* The ptid this object refers to. */
- ptid_t ptid;
+ /* The thread this object refers to. */
+ thread_info *thread;
/* The current recording method. */
enum record_method method;
extern PyTypeObject recpy_func_type;
/* Create a new gdb.RecordInstruction object. */
-extern PyObject *recpy_insn_new (ptid_t ptid, enum record_method method,
+extern PyObject *recpy_insn_new (thread_info *thread, enum record_method method,
Py_ssize_t number);
/* Create a new gdb.RecordFunctionSegment object. */
-extern PyObject *recpy_func_new (ptid_t ptid, enum record_method method,
+extern PyObject *recpy_func_new (thread_info *thread, enum record_method method,
Py_ssize_t number);
/* Create a new gdb.RecordGap object. */
#include "defs.h"
#include "py-event.h"
#include "infrun.h"
+#include "gdbthread.h"
/* thread events can either be thread specific or process wide. If gdb is
running in non-stop mode then the event is thread specific, otherwise
static PyObject *
get_event_thread (void)
{
- PyObject *thread = NULL;
+ PyObject *thread;
if (non_stop)
- thread = (PyObject *) find_thread_object (inferior_ptid);
+ thread = (PyObject *) thread_to_thread_object (inferior_thread ());
else
thread = Py_None;
PyObject *inf_obj;
} thread_object;
+struct inferior_object;
+
extern struct cmd_list_element *set_python_list;
extern struct cmd_list_element *show_python_list;
\f
PyObject *gdbarch_to_arch_object (struct gdbarch *gdbarch);
thread_object *create_thread_object (struct thread_info *tp);
-thread_object *find_thread_object (ptid_t ptid)
- CPYCHECKER_RETURNS_BORROWED_REF;
-PyObject *find_inferior_object (int pid);
-PyObject *inferior_to_inferior_object (struct inferior *inferior);
+thread_object *thread_to_thread_object (thread_info *thr)
+ CPYCHECKER_RETURNS_BORROWED_REF;
+inferior_object *inferior_to_inferior_object (inferior *inf);
const struct block *block_object_to_block (PyObject *obj);
struct symbol *symbol_object_to_symbol (PyObject *obj);
#include "event-loop.h"
#include "inf-loop.h"
#include "vec.h"
+#include "inferior.h"
#include <algorithm>
static const target_info record_btrace_target_info = {
static struct thread_info *
require_btrace_thread (void)
{
- struct thread_info *tp;
-
DEBUG ("require");
- tp = find_thread_ptid (inferior_ptid);
- if (tp == NULL)
+ if (inferior_ptid == null_ptid)
error (_("No thread."));
+ thread_info *tp = inferior_thread ();
+
validate_registers_access ();
btrace_fetch (tp, record_btrace_get_cpu ());
struct frame_info *next;
/* THIS_FRAME does not contain a reference to its thread. */
- tp = find_thread_ptid (inferior_ptid);
- gdb_assert (tp != NULL);
+ tp = inferior_thread ();
bfun = NULL;
next = get_next_frame (this_frame);
if ((callee->flags & BFUN_UP_LINKS_TO_TAILCALL) == 0)
return 0;
- tinfo = find_thread_ptid (inferior_ptid);
+ tinfo = inferior_thread ();
if (btrace_find_call_by_number (&it, &tinfo->btrace, callee->up) == 0)
return 0;
ptid_t old_inferior_ptid;
int executing;
- /* Set INFERIOR_PTID, which is implicitly used by get_current_frame. */
- old_inferior_ptid = inferior_ptid;
- inferior_ptid = tp->ptid;
+ /* Set current thread, which is implicitly used by
+ get_current_frame. */
+ scoped_restore_current_thread restore_thread;
+
+ switch_to_thread (tp);
/* Clear the executing flag to allow changes to the current frame.
We are not actually running, yet. We just started a reverse execution
For the former, EXECUTING is true and we're in wait, about to
move the thread. Since we need to recompute the stack, we temporarily
set EXECUTING to flase. */
- executing = is_executing (inferior_ptid);
- set_executing (inferior_ptid, 0);
+ executing = tp->executing;
+ set_executing (inferior_ptid, false);
frame = NULL;
TRY
/* Restore the previous execution state. */
set_executing (inferior_ptid, executing);
- /* Restore the previous inferior_ptid. */
- inferior_ptid = old_inferior_ptid;
-
throw_exception (except);
}
END_CATCH
/* Restore the previous execution state. */
set_executing (inferior_ptid, executing);
- /* Restore the previous inferior_ptid. */
- inferior_ptid = old_inferior_ptid;
-
return frame;
}
btinfo->replay = replay;
/* Make sure we're not using any stale registers. */
- registers_changed_ptid (tp->ptid);
+ registers_changed_thread (tp);
/* The current frame with replaying - computed via btrace unwind. */
frame = get_thread_current_frame (tp);
xfree (btinfo->replay);
btinfo->replay = NULL;
- registers_changed_ptid (tp->ptid);
+ registers_changed_thread (tp);
throw_exception (except);
}
btinfo->replay = NULL;
/* Make sure we're not leaving any stale registers. */
- registers_changed_ptid (tp->ptid);
+ registers_changed_thread (tp);
}
/* Stop replaying TP if it is at the end of its execution history. */
struct btrace_insn_iterator *replay;
struct btrace_thread_info *btinfo;
const struct btrace_insn *insn;
- struct inferior *inf;
btinfo = &tp->btrace;
replay = btinfo->replay;
if (insn == NULL)
return 0;
- inf = find_inferior_ptid (tp->ptid);
- if (inf == NULL)
- return 0;
-
- return record_check_stopped_by_breakpoint (inf->aspace, insn->pc,
+ return record_check_stopped_by_breakpoint (tp->inf->aspace, insn->pc,
&btinfo->stop_reason);
}
record_btrace_clear_histories (&eventing->btrace);
/* We moved the replay position but did not update registers. */
- registers_changed_ptid (eventing->ptid);
+ registers_changed_thread (eventing);
DEBUG ("wait ended by thread %s (%s): %s",
print_thread_id (eventing),
{
/* We don't add or remove threads during replay. */
if (record_is_replaying (minus_one_ptid))
- return find_thread_ptid (ptid) != NULL;
+ return true;
/* Forward the request. */
return this->beneath ()->thread_alive (ptid);
return;
*btinfo->replay = *it;
- registers_changed_ptid (tp->ptid);
+ registers_changed_thread (tp);
}
/* Start anew from the new replay position. */
#include "gdbcmd.h"
#include "regcache.h"
#include "gdbthread.h"
+#include "inferior.h"
#include "event-top.h"
#include "completer.h"
#include "arch-utils.h"
#include "defs.h"
#include "inferior.h"
+#include "gdbthread.h"
#include "target.h"
#include "gdbarch.h"
#include "gdbcmd.h"
return get_thread_arch_regcache (ptid, current_thread_arch);
}
+/* See regcache.h. */
+
+struct regcache *
+get_thread_regcache (thread_info *thread)
+{
+ return get_thread_regcache (thread->ptid);
+}
+
struct regcache *
get_current_regcache (void)
{
- return get_thread_regcache (inferior_ptid);
+ return get_thread_regcache (inferior_thread ());
}
/* See common/common-regcache.h. */
}
}
+/* See regcache.h. */
+
+void
+registers_changed_thread (thread_info *thread)
+{
+ registers_changed_ptid (thread->ptid);
+}
+
void
registers_changed (void)
{
extern struct regcache *get_current_regcache (void);
extern struct regcache *get_thread_regcache (ptid_t ptid);
+
+/* Get the regcache of THREAD. */
+extern struct regcache *get_thread_regcache (thread_info *thread);
+
extern struct regcache *get_thread_arch_regcache (ptid_t, struct gdbarch *);
extern struct regcache *get_thread_arch_aspace_regcache (ptid_t,
struct gdbarch *,
static void regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid);
protected:
regcache (gdbarch *gdbarch, const address_space *aspace_);
+
static std::forward_list<regcache *> current_regcache;
private:
extern void registers_changed (void);
extern void registers_changed_ptid (ptid_t);
+/* Indicate that registers of THREAD may have changed, so invalidate
+ the cache. */
+extern void registers_changed_thread (thread_info *thread);
+
/* An abstract base class for register dump. */
class register_dump
ptid_t ptid);
static void open_1 (const char *name, int from_tty, int extended_p);
void start_remote (int from_tty, int extended_p);
- void remote_detach_1 (int from_tty, struct inferior *inf);
+ void remote_detach_1 (struct inferior *inf, int from_tty);
char *append_resumption (char *p, char *endp,
ptid_t ptid, int step, gdb_signal siggnal);
void process_initial_stop_replies (int from_tty);
- void remote_add_thread (ptid_t ptid, bool running, bool executing);
+ thread_info *remote_add_thread (ptid_t ptid, bool running, bool executing);
void btrace_sync_conf (const btrace_config *conf);
}
static remote_thread_info *get_remote_thread_info (thread_info *thread);
+static remote_thread_info *get_remote_thread_info (ptid_t ptid);
/* Add thread PTID to GDB's thread list. Tag it as executing/running
according to RUNNING. */
-void
+thread_info *
remote_target::remote_add_thread (ptid_t ptid, bool running, bool executing)
{
struct remote_state *rs = get_remote_state ();
get_remote_thread_info (thread)->vcont_resumed = executing;
set_executing (ptid, executing);
set_running (ptid, running);
+
+ return thread;
}
/* Come here when we learn about a thread id from the remote target.
/* If this is a new thread, add it to GDB's thread list.
If we leave it up to WFI to do this, bad things will happen. */
- if (in_thread_list (currthread) && is_exited (currthread))
+ thread_info *tp = find_thread_ptid (currthread);
+ if (tp != NULL && tp->state == THREAD_EXITED)
{
/* We're seeing an event on a thread id we knew had exited.
This has to be a new thread reusing the old id. Add it. */
extended-remote which already was debugging an inferior, we
may not know about it yet. Add it before adding its child
thread, so notifications are emitted in a sensible order. */
- if (!in_inferior_list (ptid_get_pid (currthread)))
+ if (find_inferior_pid (ptid_get_pid (currthread)) == NULL)
{
struct remote_state *rs = get_remote_state ();
int fake_pid_p = !remote_multi_process_p (rs);
}
/* This is really a new thread. Add it. */
- remote_add_thread (currthread, running, executing);
+ thread_info *new_thr
+ = remote_add_thread (currthread, running, executing);
/* If we found a new inferior, let the common code do whatever
it needs to with it (e.g., read shared libraries, insert
struct remote_state *rs = get_remote_state ();
if (!rs->starting_up)
- notice_new_inferior (currthread, executing, 0);
+ notice_new_inferior (new_thr, executing, 0);
}
}
}
return static_cast<remote_thread_info *> (thread->priv.get ());
}
-/* Return PTID's private thread data, creating it if necessary. */
-
static remote_thread_info *
get_remote_thread_info (ptid_t ptid)
{
- struct thread_info *info = find_thread_ptid (ptid);
-
- return get_remote_thread_info (info);
+ thread_info *thr = find_thread_ptid (ptid);
+ return get_remote_thread_info (thr);
}
/* Call this function as a result of
if (!context.contains_thread (tp->ptid))
{
/* Not found. */
- delete_thread (tp->ptid);
+ delete_thread (tp);
}
}
remote_notice_new_inferior (item.ptid, executing);
- remote_thread_info *info = get_remote_thread_info (item.ptid);
+ thread_info *tp = find_thread_ptid (item.ptid);
+ remote_thread_info *info = get_remote_thread_info (tp);
info->core = item.core;
info->extra = std::move (item.extra);
info->name = std::move (item.name);
if (packet_support (PACKET_qXfer_threads) == PACKET_ENABLE)
{
- struct thread_info *info = find_thread_ptid (tp->ptid);
-
- if (info != NULL && info->priv != NULL)
+ if (tp->priv != NULL)
{
- const std::string &extra = get_remote_thread_info (info)->extra;
+ const std::string &extra = get_remote_thread_info (tp)->extra;
return !extra.empty () ? extra.c_str () : NULL;
}
else
{
struct target_waitstatus *ws = &thread->suspend.waitstatus;
- switch_to_thread (thread->ptid);
+ switch_to_thread (thread);
stop_pc = get_frame_pc (get_current_frame ());
set_current_sal_from_frame (get_current_frame ());
if (non_stop)
{
- thread = any_live_thread_of_process (inf->pid);
- notice_new_inferior (thread->ptid,
- thread->state == THREAD_RUNNING,
+ thread = any_live_thread_of_inferior (inf);
+ notice_new_inferior (thread, thread->state == THREAD_RUNNING,
from_tty);
}
}
if (inf->needs_setup)
{
- thread = any_live_thread_of_process (inf->pid);
+ thread = any_live_thread_of_inferior (inf);
switch_to_thread_no_regs (thread);
setup_inferior (0);
}
first = thread;
if (!non_stop)
- set_running (thread->ptid, 0);
+ thread->set_running (false);
else if (thread->state != THREAD_STOPPED)
continue;
one. */
void
-remote_target::remote_detach_1 (int from_tty, inferior *inf)
+remote_target::remote_detach_1 (inferior *inf, int from_tty)
{
int pid = ptid_get_pid (inferior_ptid);
struct remote_state *rs = get_remote_state ();
- struct thread_info *tp = find_thread_ptid (inferior_ptid);
int is_fork_parent;
if (!target_has_execution)
if (from_tty && !rs->extended && number_of_live_inferiors () == 1)
puts_filtered (_("Ending remote debugging.\n"));
+ struct thread_info *tp = find_thread_ptid (inferior_ptid);
+
/* Check to see if we are detaching a fork parent. Note that if we
are detaching a fork child, tp == NULL. */
is_fork_parent = (tp != NULL
else
{
inferior_ptid = null_ptid;
- detach_inferior (pid);
+ detach_inferior (current_inferior ());
}
}
void
remote_target::detach (inferior *inf, int from_tty)
{
- remote_detach_1 (from_tty, inf);
+ remote_detach_1 (inf, from_tty);
}
void
extended_remote_target::detach (inferior *inf, int from_tty)
{
- remote_detach_1 (from_tty, inf);
+ remote_detach_1 (inf, from_tty);
}
/* Target follow-fork function for remote targets. On entry, and
/* Get list of threads. */
update_thread_list ();
- thread = first_thread_of_process (pid);
+ thread = first_thread_of_inferior (current_inferior ());
if (thread)
inferior_ptid = thread->ptid;
else
static LONGEST
s390_linux_get_syscall_number (struct gdbarch *gdbarch,
- ptid_t ptid)
+ thread_info *thread)
{
- struct regcache *regs = get_thread_regcache (ptid);
+ struct regcache *regs = get_thread_regcache (thread);
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
ULONGEST pc;
static LONGEST
sparc32_linux_get_syscall_number (struct gdbarch *gdbarch,
- ptid_t ptid)
+ thread_info *thread)
{
- struct regcache *regcache = get_thread_regcache (ptid);
+ struct regcache *regcache = get_thread_regcache (thread);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
/* The content of a register. */
gdb_byte buf[4];
static LONGEST
sparc64_linux_get_syscall_number (struct gdbarch *gdbarch,
- ptid_t ptid)
+ thread_info *thread)
{
- struct regcache *regcache = get_thread_regcache (ptid);
+ struct regcache *regcache = get_thread_regcache (thread);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
/* The content of a register. */
gdb_byte buf[8];
if (sal.line != 0 && sal.pc == 0 && sal.end == 0)
{
if (get_next_frame (frame) == NULL)
- gdb_assert (inline_skipped_frames (inferior_ptid) > 0);
+ gdb_assert (inline_skipped_frames (inferior_thread ()) > 0);
else
gdb_assert (get_frame_type (get_next_frame (frame)) == INLINE_FRAME);
return 0;
target_debug_do_print (plongest (X))
#define target_debug_print_thread_info_p(X) \
target_debug_do_print (host_address_to_string (X))
+#define target_debug_print_thread_info_pp(X) \
+ target_debug_do_print (host_address_to_string (X))
static void
target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)
return TARGET_XFER_E_IO;
if (!ptid_equal (inferior_ptid, null_ptid))
- inf = find_inferior_ptid (inferior_ptid);
+ inf = current_inferior ();
else
inf = NULL;
static int
dispose_inferior (struct inferior *inf, void *args)
{
- struct thread_info *thread;
-
- thread = any_thread_of_process (inf->pid);
- if (thread)
+ thread_info *thread = any_thread_of_inferior (inf);
+ if (thread != NULL)
{
- switch_to_thread (thread->ptid);
+ switch_to_thread (thread);
/* Core inferiors actually should be detached, not killed. */
if (target_has_execution)
;
else
/* If we're in breakpoints-always-inserted mode, have to remove
- them before detaching. */
- remove_breakpoints_pid (ptid_get_pid (inferior_ptid));
+ breakpoints before detaching. */
+ remove_breakpoints_inf (current_inferior ());
prepare_for_detach ();
void
generic_mourn_inferior (void)
{
- ptid_t ptid;
+ inferior *inf = current_inferior ();
- ptid = inferior_ptid;
inferior_ptid = null_ptid;
/* Mark breakpoints uninserted in case something tries to delete a
fail, since the inferior is long gone). */
mark_breakpoints_out ();
- if (!ptid_equal (ptid, null_ptid))
- {
- int pid = ptid_get_pid (ptid);
- exit_inferior (pid);
- }
+ if (inf->pid != 0)
+ exit_inferior (inf);
/* Note this wipes step-resume breakpoints, so needs to be done
after exit_inferior, which ends up referencing the step-resume
void
init_thread_list (void)
{
- struct thread_info *tp, *tpnext;
+ struct thread_info *tp, *tmp;
highest_thread_num = 0;
- if (!thread_list)
- return;
-
- for (tp = thread_list; tp; tp = tpnext)
+ ALL_THREADS_SAFE (tp, tmp)
{
- tpnext = tp->next;
if (tp->deletable ())
delete tp;
else
if (inferior_ptid == ptid)
{
- tp = new_thread (inf, null_ptid);
+ thread_info *new_thr = new_thread (inf, null_ptid);
/* Make switch_to_thread not read from the thread. */
- tp->state = THREAD_EXITED;
- switch_to_thread (null_ptid);
+ new_thr->state = THREAD_EXITED;
+ switch_to_no_thread ();
/* Now we can delete it. */
- delete_thread (ptid);
+ delete_thread (tp);
/* Now reset its ptid, and reswitch inferior_ptid to it. */
- tp->ptid = ptid;
- tp->state = THREAD_STOPPED;
- switch_to_thread (ptid);
+ new_thr->ptid = ptid;
+ new_thr->state = THREAD_STOPPED;
+ switch_to_thread (new_thr);
- gdb::observers::new_thread.notify (tp);
+ gdb::observers::new_thread.notify (new_thr);
/* All done. */
- return tp;
+ return new_thr;
}
else
/* Just go ahead and delete it. */
- delete_thread (ptid);
+ delete_thread (tp);
}
tp = new_thread (inf, ptid);
step_over_chain_remove (&step_over_queue_head, tp);
}
-/* Delete thread PTID. If SILENT, don't notify the observer of this
+/* Delete thread TP. If SILENT, don't notify the observer of this
exit. */
+
static void
-delete_thread_1 (ptid_t ptid, int silent)
+delete_thread_1 (thread_info *thr, bool silent)
{
struct thread_info *tp, *tpprev;
tpprev = NULL;
for (tp = thread_list; tp; tpprev = tp, tp = tp->next)
- if (tp->ptid == ptid)
+ if (tp == thr)
break;
if (!tp)
delete tp;
}
-/* Delete thread PTID and notify of thread exit. If this is
- inferior_ptid, don't actually delete it, but tag it as exited and
- do the notification. If PTID is the user selected thread, clear
+/* Delete thread THREAD and notify of thread exit. If this is the
+ current thread, don't actually delete it, but tag it as exited and
+ do the notification. If this is the user selected thread, clear
it. */
+
void
-delete_thread (ptid_t ptid)
+delete_thread (thread_info *thread)
{
- delete_thread_1 (ptid, 0 /* not silent */);
+ delete_thread_1 (thread, false /* not silent */);
}
void
-delete_thread_silent (ptid_t ptid)
+delete_thread_silent (thread_info *thread)
{
- delete_thread_1 (ptid, 1 /* silent */);
+ delete_thread_1 (thread, true /* silent */);
}
struct thread_info *
return 0;
}
-int
-ptid_to_global_thread_id (ptid_t ptid)
-{
- struct thread_info *tp;
-
- for (tp = thread_list; tp; tp = tp->next)
- if (tp->ptid == ptid)
- return tp->global_num;
-
- return 0;
-}
-
-ptid_t
-global_thread_id_to_ptid (int global_id)
-{
- struct thread_info *thread = find_thread_global_id (global_id);
-
- if (thread)
- return thread->ptid;
- else
- return minus_one_ptid;
-}
-
int
in_thread_list (ptid_t ptid)
{
return 0; /* Never heard of 'im. */
}
-/* Finds the first thread of the inferior given by PID. If PID is -1,
- return the first thread in the list. */
+/* Finds the first thread of the inferior. */
-struct thread_info *
-first_thread_of_process (int pid)
+thread_info *
+first_thread_of_inferior (inferior *inf)
{
struct thread_info *tp, *ret = NULL;
for (tp = thread_list; tp; tp = tp->next)
- if (pid == -1 || ptid_get_pid (tp->ptid) == pid)
+ if (tp->inf == inf)
if (ret == NULL || tp->global_num < ret->global_num)
ret = tp;
return ret;
}
-struct thread_info *
-any_thread_of_process (int pid)
+thread_info *
+any_thread_of_inferior (inferior *inf)
{
struct thread_info *tp;
- gdb_assert (pid != 0);
+ gdb_assert (inf->pid != 0);
/* Prefer the current thread. */
- if (ptid_get_pid (inferior_ptid) == pid)
+ if (inf == current_inferior ())
return inferior_thread ();
ALL_NON_EXITED_THREADS (tp)
- if (ptid_get_pid (tp->ptid) == pid)
+ if (tp->inf == inf)
return tp;
return NULL;
}
-struct thread_info *
-any_live_thread_of_process (int pid)
+thread_info *
+any_live_thread_of_inferior (inferior *inf)
{
struct thread_info *curr_tp = NULL;
struct thread_info *tp;
struct thread_info *tp_executing = NULL;
- gdb_assert (pid != 0);
+ gdb_assert (inf != NULL && inf->pid != 0);
/* Prefer the current thread if it's not executing. */
- if (ptid_get_pid (inferior_ptid) == pid)
+ if (inferior_ptid != null_ptid && current_inferior () == inf)
{
/* If the current thread is dead, forget it. If it's not
executing, use it. Otherwise, still choose it (below), but
}
ALL_NON_EXITED_THREADS (tp)
- if (ptid_get_pid (tp->ptid) == pid)
+ if (tp->inf == inf)
{
if (!tp->executing)
return tp;
ALL_THREADS_SAFE (tp, tmp)
{
if (!thread_alive (tp))
- delete_thread (tp->ptid);
+ delete_thread (tp);
}
}
ALL_THREADS_SAFE (tp, tmp)
{
if (tp->state == THREAD_EXITED)
- delete_thread (tp->ptid);
+ delete_thread (tp);
}
}
/* Return true value if stack temporaies are enabled for the thread
- with id PTID. */
+ TP. */
bool
-thread_stack_temporaries_enabled_p (ptid_t ptid)
+thread_stack_temporaries_enabled_p (thread_info *tp)
{
- struct thread_info *tp = find_thread_ptid (ptid);
-
if (tp == NULL)
return false;
else
/* Push V on to the stack temporaries of the thread with id PTID. */
void
-push_thread_stack_temporary (ptid_t ptid, struct value *v)
+push_thread_stack_temporary (thread_info *tp, struct value *v)
{
- struct thread_info *tp = find_thread_ptid (ptid);
-
gdb_assert (tp != NULL && tp->stack_temporaries_enabled);
tp->stack_temporaries.push_back (v);
}
/* Return true if VAL is among the stack temporaries of the thread
- with id PTID. Return false otherwise. */
+ TP. Return false otherwise. */
bool
-value_in_thread_stack_temporaries (struct value *val, ptid_t ptid)
+value_in_thread_stack_temporaries (struct value *val, thread_info *tp)
{
- struct thread_info *tp = find_thread_ptid (ptid);
-
gdb_assert (tp != NULL && tp->stack_temporaries_enabled);
for (value *v : tp->stack_temporaries)
if (v == val)
/* Return the last of the stack temporaries for thread with id PTID.
Return NULL if there are no stack temporaries for the thread. */
-struct value *
-get_last_thread_stack_temporary (ptid_t ptid)
+value *
+get_last_thread_stack_temporary (thread_info *tp)
{
struct value *lastval = NULL;
- struct thread_info *tp = find_thread_ptid (ptid);
gdb_assert (tp != NULL);
if (!tp->stack_temporaries.empty ())
return started;
}
+/* See gdbthread.h. */
+
+void
+thread_info::set_running (bool running)
+{
+ if (set_running_thread (this, running))
+ gdb::observers::target_resumed.notify (this->ptid);
+}
+
void
set_running (ptid_t ptid, int running)
{
if (inferior_ptid == null_ptid)
error (_("No thread selected."));
+ thread_info *tp = inferior_thread ();
+
/* Don't try to read from a dead thread. */
- if (is_exited (inferior_ptid))
+ if (tp->state == THREAD_EXITED)
error (_("The current thread has terminated"));
/* ... or from a spinning thread. FIXME: This isn't actually fully
at the prompt) when a thread is not executing for some internal
reason, but is marked running from the user's perspective. E.g.,
the thread is waiting for its turn in the step-over queue. */
- if (is_executing (inferior_ptid))
+ if (tp->executing)
error (_("Selected thread is running."));
}
/* See gdbthread.h. */
bool
-can_access_registers_ptid (ptid_t ptid)
+can_access_registers_thread (thread_info *thread)
{
/* No thread, no registers. */
- if (ptid == null_ptid)
+ if (thread == NULL)
return false;
/* Don't try to read from a dead thread. */
- if (is_exited (ptid))
+ if (thread->state == THREAD_EXITED)
return false;
/* ... or from a spinning thread. FIXME: see validate_registers_access. */
- if (is_executing (ptid))
+ if (thread->executing)
return false;
return true;
int show_global_ids)
{
struct thread_info *tp;
- ptid_t current_ptid;
const char *extra_info, *name, *target_id;
struct inferior *inf;
int default_inf_num = current_inferior ()->num;
update_thread_list ();
- current_ptid = inferior_ptid;
+
+ /* Whether we saw any thread. */
+ bool any_thread = false;
+ /* Whether the current thread is exited. */
+ bool current_exited = false;
+
+ thread_info *current_thread = (inferior_ptid != null_ptid
+ ? inferior_thread () : NULL);
{
/* For backward compatibility, we make a list for MI. A table is
{
int n_threads = 0;
- for (tp = thread_list; tp; tp = tp->next)
+ ALL_THREADS (tp)
{
if (!should_print_thread (requested_threads, default_inf_num,
global_ids, pid, tp))
{
int core;
+ any_thread = true;
+ if (tp == current_thread && tp->state == THREAD_EXITED)
+ current_exited = true;
+
if (!should_print_thread (requested_threads, default_inf_num,
global_ids, pid, tp))
continue;
if (!uiout->is_mi_like_p ())
{
- if (tp->ptid == current_ptid)
+ if (tp == current_thread)
uiout->field_string ("current", "*");
else
uiout->field_skip ("current");
{
/* The switch below puts us at the top of the stack (leaf
frame). */
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
print_stack_frame (get_selected_frame (NULL),
/* For MI output, print frame level. */
uiout->is_mi_like_p (),
if (pid == -1 && requested_threads == NULL)
{
- if (uiout->is_mi_like_p ()
- && inferior_ptid != null_ptid)
- {
- int num = ptid_to_global_thread_id (inferior_ptid);
+ if (uiout->is_mi_like_p () && inferior_ptid != null_ptid)
+ uiout->field_int ("current-thread-id", current_thread->global_num);
- gdb_assert (num != 0);
- uiout->field_int ("current-thread-id", num);
- }
-
- if (inferior_ptid != null_ptid && is_exited (inferior_ptid))
+ if (inferior_ptid != null_ptid && current_exited)
uiout->message ("\n\
The current thread <Thread ID %s> has terminated. See `help thread'.\n",
print_thread_id (inferior_thread ()));
- else if (thread_list != NULL && inferior_ptid == null_ptid)
+ else if (any_thread && inferior_ptid == null_ptid)
uiout->message ("\n\
No selected thread. See `help thread'.\n");
}
stop_pc = ~(CORE_ADDR) 0;
}
-/* Switch to no thread selected. */
+/* See gdbthread.h. */
-static void
+void
switch_to_no_thread ()
{
if (inferior_ptid == null_ptid)
stop_pc = ~(CORE_ADDR) 0;
}
-/* Switch from one thread to another. */
+/* See gdbthread.h. */
-static void
+void
switch_to_thread (thread_info *thr)
{
gdb_assert (thr != NULL);
internal event. */
if (thr->state != THREAD_EXITED
&& !thr->executing)
- stop_pc = regcache_read_pc (get_thread_regcache (thr->ptid));
+ stop_pc = regcache_read_pc (get_thread_regcache (thr));
}
-/* See gdbthread.h. */
+/* See common/common-gdbthread.h. */
void
switch_to_thread (ptid_t ptid)
{
- if (ptid == null_ptid)
- switch_to_no_thread ();
- else
- switch_to_thread (find_thread_ptid (ptid));
+ thread_info *thr = find_thread_ptid (ptid);
+ switch_to_thread (thr);
}
static void
changed, so we have to recheck it here. */
if (inferior_ptid != null_ptid
&& m_was_stopped
- && is_stopped (inferior_ptid)
+ && m_thread->state == THREAD_STOPPED
&& target_has_registers
&& target_has_stack
&& target_has_memory)
if (inferior_ptid != null_ptid)
{
- thread_info *tp = find_thread_ptid (inferior_ptid);
+ thread_info *tp = inferior_thread ();
struct frame_info *frame;
- gdb_assert (tp != NULL);
-
m_was_stopped = tp->state == THREAD_STOPPED;
if (m_was_stopped
&& target_has_registers
for (thread_info *thr : thr_list_cpy)
if (thread_alive (thr))
{
- switch_to_thread (thr->ptid);
+ switch_to_thread (thr);
printf_filtered (_("\nThread %s (%s):\n"),
print_thread_id (thr),
target_pid_to_str (inferior_ptid));
continue;
}
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
printf_filtered (_("\nThread %s (%s):\n"), print_thread_id (tp),
target_pid_to_str (inferior_ptid));
{
struct thread_info *tp = inferior_thread ();
- if (is_exited (inferior_ptid))
+ if (tp->state == THREAD_EXITED)
printf_filtered (_("[Current thread is %s (%s) (exited)]\n"),
print_thread_id (tp),
target_pid_to_str (inferior_ptid));
if (!thread_alive (tp))
error (_("Thread ID %s has terminated."), tidstr);
- switch_to_thread (tp->ptid);
+ switch_to_thread (tp);
annotate_thread_changed ();
static struct value *
thread_num_make_value_helper (struct gdbarch *gdbarch, int global)
{
- struct thread_info *tp = find_thread_ptid (inferior_ptid);
int int_val;
- if (tp == NULL)
+ if (inferior_ptid == null_ptid)
int_val = 0;
- else if (global)
- int_val = tp->global_num;
else
- int_val = tp->per_inf_num;
+ {
+ thread_info *tp = inferior_thread ();
+ if (global)
+ int_val = tp->global_num;
+ else
+ int_val = tp->per_inf_num;
+ }
return value_from_longest (builtin_type (gdbarch)->builtin_int, int_val);
}
we just finished executing did not resume the inferior's execution.
If it did resume the inferior, we will do that check after
the inferior stopped. */
- if (has_stack_frames () && !is_running (inferior_ptid))
+ if (has_stack_frames () && inferior_thread ()->state != THREAD_RUNNING)
check_frame_language_change ();
discard_cleanups (cleanup_if_error);
kill_or_detach (struct inferior *inf, void *args)
{
struct qt_args *qt = (struct qt_args *) args;
- struct thread_info *thread;
if (inf->pid == 0)
return 0;
- thread = any_thread_of_process (inf->pid);
+ thread_info *thread = any_thread_of_inferior (inf);
if (thread != NULL)
{
- switch_to_thread (thread->ptid);
+ switch_to_thread (thread);
/* Leave core files alone. */
if (target_has_execution)
void
tfile_target::close ()
{
- int pid;
-
if (trace_fd < 0)
return;
- pid = ptid_get_pid (inferior_ptid);
inferior_ptid = null_ptid; /* Avoid confusion from thread stuff. */
- exit_inferior_silent (pid);
+ exit_inferior_silent (current_inferior ());
::close (trace_fd);
trace_fd = -1;
#include "infrun.h"
#include "observable.h"
#include "gdbthread.h"
+#include "inferior.h"
/* Set to 1 when the TUI mode must be activated when we first start
gdb. */
error (_("Failed to find the specified frame"));
var->root->frame = get_frame_id (fi);
- var->root->thread_id = ptid_to_global_thread_id (inferior_ptid);
+ var->root->thread_id = inferior_thread ()->global_num;
old_id = get_frame_id (get_selected_frame (NULL));
select_frame (fi);
}
}
else
{
- ptid_t ptid = global_thread_id_to_ptid (var->root->thread_id);
+ thread_info *thread = find_thread_global_id (var->root->thread_id);
- if (!ptid_equal (minus_one_ptid, ptid))
+ if (thread != NULL)
{
- switch_to_thread (ptid);
+ switch_to_thread (thread);
within_scope = check_scope (var);
}
}