From: Markus Metzger Date: Wed, 26 Aug 2015 13:37:55 +0000 (+0200) Subject: btrace: temporarily set inferior_ptid in record_btrace_start_replaying X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ec71cc2fc6d319ebe4aebbe65a6a56ea1376200e;p=binutils-gdb.git btrace: temporarily set inferior_ptid in record_btrace_start_replaying Get_current_frame uses inferior_ptid. In record_btrace_start_replaying, we need to get the current frame of the argument thread. So far, this has always been inferior_ptid. With non-stop, this is not guaranteed. Temporarily set inferior_ptid to the ptid of the argument thread. We already temporarily set the argument thread's executing flag to false. Move both into a new function get_thread_current_frame that does the temporary adjustments, calls get_current_frame, and restores the previous values. gdb/ * record-btrace.c (get_thread_current_frame): New. (record_btrace_start_replaying): Call get_thread_current_frame. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d6901c8835b..4c6d0e1bc5b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2015-09-18 Markus Metzger + + * record-btrace.c (get_thread_current_frame): New. + (record_btrace_start_replaying): Call get_thread_current_frame. + 2015-09-18 Markus Metzger * record-btrace.c (record_btrace_resume_thread): A move request diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index c25b8f49b3c..0514471a74c 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -1707,6 +1707,55 @@ record_btrace_resume_thread (struct thread_info *tp, btinfo->flags |= flag; } +/* Get the current frame for TP. */ + +static struct frame_info * +get_thread_current_frame (struct thread_info *tp) +{ + struct frame_info *frame; + 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; + + /* Clear the executing flag to allow changes to the current frame. + We are not actually running, yet. We just started a reverse execution + command or a record goto command. + For the latter, EXECUTING is false and this has no effect. + For the former, EXECUTING is true and we're in to_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); + + frame = NULL; + TRY + { + frame = get_current_frame (); + } + CATCH (except, RETURN_MASK_ALL) + { + /* 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; +} + /* Start replaying a thread. */ static struct btrace_insn_iterator * @@ -1714,7 +1763,6 @@ record_btrace_start_replaying (struct thread_info *tp) { struct btrace_insn_iterator *replay; struct btrace_thread_info *btinfo; - int executing; btinfo = &tp->btrace; replay = NULL; @@ -1723,16 +1771,6 @@ record_btrace_start_replaying (struct thread_info *tp) if (btinfo->begin == NULL) return NULL; - /* Clear the executing flag to allow changes to the current frame. - We are not actually running, yet. We just started a reverse execution - command or a record goto command. - For the latter, EXECUTING is false and this has no effect. - For the former, EXECUTING is true and we're in to_wait, about to - move the thread. Since we need to recompute the stack, we temporarily - set EXECUTING to flase. */ - executing = is_executing (tp->ptid); - set_executing (tp->ptid, 0); - /* GDB stores the current frame_id when stepping in order to detects steps into subroutines. Since frames are computed differently when we're replaying, we need to @@ -1745,7 +1783,7 @@ record_btrace_start_replaying (struct thread_info *tp) int upd_step_frame_id, upd_step_stack_frame_id; /* The current frame without replaying - computed via normal unwind. */ - frame = get_current_frame (); + frame = get_thread_current_frame (tp); frame_id = get_frame_id (frame); /* Check if we need to update any stepping-related frame id's. */ @@ -1777,7 +1815,7 @@ record_btrace_start_replaying (struct thread_info *tp) registers_changed_ptid (tp->ptid); /* The current frame with replaying - computed via btrace unwind. */ - frame = get_current_frame (); + frame = get_thread_current_frame (tp); frame_id = get_frame_id (frame); /* Replace stepping related frames where necessary. */ @@ -1788,9 +1826,6 @@ record_btrace_start_replaying (struct thread_info *tp) } CATCH (except, RETURN_MASK_ALL) { - /* Restore the previous execution state. */ - set_executing (tp->ptid, executing); - xfree (btinfo->replay); btinfo->replay = NULL; @@ -1800,9 +1835,6 @@ record_btrace_start_replaying (struct thread_info *tp) } END_CATCH - /* Restore the previous execution state. */ - set_executing (tp->ptid, executing); - return replay; }