+2020-07-10 Pedro Alves <pedro@palves.net>
+
+ * gdbthread.h (inferior_ref): Define.
+ (scoped_restore_current_thread) <m_thread>: Now a thread_info_ref.
+ (scoped_restore_current_thread) <m_inf>: Now an inferior_ref.
+ * thread.c
+ (scoped_restore_current_thread::restore):
+ Adjust to gdb::ref_ptr.
+ (scoped_restore_current_thread::~scoped_restore_current_thread):
+ Remove manual decref handling.
+ (scoped_restore_current_thread::scoped_restore_current_thread):
+ Adjust to use
+ inferior_ref::new_reference/thread_info_ref::new_reference.
+ Incref the thread before calling get_frame_id instead of after.
+ Let TARGET_CLOSE_ERROR propagate.
+
2020-07-10 Pedro Alves <pedro@palves.net>
* frame-tailcall.c (dwarf2_tailcall_sniffer_first): Only swallow
using thread_info_ref
= gdb::ref_ptr<struct thread_info, refcounted_object_ref_policy>;
+/* A gdb::ref_ptr pointer to an inferior. This would ideally be in
+ inferior.h, but it can't due to header dependencies (inferior.h
+ includes gdbthread.h). */
+
+using inferior_ref
+ = gdb::ref_ptr<struct inferior, refcounted_object_ref_policy>;
+
/* Create an empty thread list, or empty the existing one. */
extern void init_thread_list (void);
void restore ();
bool m_dont_restore = false;
- /* Use the "class" keyword here, because of a clash with a "thread_info"
- function in the Darwin API. */
- class thread_info *m_thread;
- inferior *m_inf;
+ thread_info_ref m_thread;
+ inferior_ref m_inf;
+
frame_id m_selected_frame_id;
int m_selected_frame_level;
bool m_was_stopped;
in the mean time exited (or killed, detached, etc.), then don't revert
back to it, but instead simply drop back to no thread selected. */
&& m_inf->pid != 0)
- switch_to_thread (m_thread);
+ switch_to_thread (m_thread.get ());
else
- switch_to_inferior_no_thread (m_inf);
+ switch_to_inferior_no_thread (m_inf.get ());
/* The running state of the originally selected thread may have
changed, so we have to recheck it here. */
but swallow the exception. */
}
}
-
- if (m_thread != NULL)
- m_thread->decref ();
- m_inf->decref ();
}
scoped_restore_current_thread::scoped_restore_current_thread ()
{
- m_thread = NULL;
- m_inf = current_inferior ();
+ m_inf = inferior_ref::new_reference (current_inferior ());
if (inferior_ptid != null_ptid)
{
- thread_info *tp = inferior_thread ();
+ m_thread = thread_info_ref::new_reference (inferior_thread ());
+
struct frame_info *frame;
- m_was_stopped = tp->state == THREAD_STOPPED;
+ m_was_stopped = m_thread->state == THREAD_STOPPED;
if (m_was_stopped
&& target_has_registers
&& target_has_stack
{
m_selected_frame_id = null_frame_id;
m_selected_frame_level = -1;
- }
- tp->incref ();
- m_thread = tp;
+ /* Better let this propagate. */
+ if (ex.error == TARGET_CLOSE_ERROR)
+ throw;
+ }
}
-
- m_inf->incref ();
}
/* See gdbthread.h. */