diff options
-rw-r--r-- | gdb/gdbthread.h | 32 | ||||
-rw-r--r-- | gdb/infcmd.c | 2 | ||||
-rw-r--r-- | gdb/infrun.c | 3 | ||||
-rw-r--r-- | gdb/thread.c | 2 |
4 files changed, 31 insertions, 8 deletions
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index e6f383c..4b27194 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -197,9 +197,12 @@ struct thread_suspend_state stop_reason: if the thread's PC has changed since the thread last stopped, a pending breakpoint waitstatus is discarded. - - If the thread is running, this is set to -1, to avoid leaving - it with a stale value, to make it easier to catch bugs. */ - CORE_ADDR stop_pc = 0; + - If the thread is running, then this field has its value removed by + calling stop_pc.reset() (see thread_info::set_executing()). + Attempting to read a gdb::optional with no value is undefined + behaviour and will trigger an assertion error when _GLIBCXX_DEBUG is + defined, which should make error easier to track down. */ + gdb::optional<CORE_ADDR> stop_pc; }; /* Base class for target-specific thread data. */ @@ -327,11 +330,15 @@ public: m_suspend = suspend; } - /* Return this thread's stop PC. */ + /* Return this thread's stop PC. This should only be called when it is + known that stop_pc has a value. If this function is being used in a + situation where a thread may not have had a stop_pc assigned, then + stop_pc_p() can be used to check if the stop_pc is defined. */ CORE_ADDR stop_pc () const { - return m_suspend.stop_pc; + gdb_assert (m_suspend.stop_pc.has_value ()); + return *m_suspend.stop_pc; } /* Set this thread's stop PC. */ @@ -341,6 +348,21 @@ public: m_suspend.stop_pc = stop_pc; } + /* Remove the stop_pc stored on this thread. */ + + void clear_stop_pc () + { + m_suspend.stop_pc.reset (); + } + + /* Return true if this thread has a cached stop pc value, otherwise + return false. */ + + bool stop_pc_p () const + { + return m_suspend.stop_pc.has_value (); + } + /* Return true if this thread has a pending wait status. */ bool has_pending_waitstatus () const diff --git a/gdb/infcmd.c b/gdb/infcmd.c index e6ee49b..d948f4b 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -249,7 +249,7 @@ post_create_inferior (int from_tty) missing registers info), ignore it. */ thread_info *thr = inferior_thread (); - thr->set_stop_pc (0); + thr->clear_stop_pc (); try { regcache *rc = get_thread_regcache (thr); diff --git a/gdb/infrun.c b/gdb/infrun.c index 8e77857..d1ac9b4 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -3051,7 +3051,8 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) if (addr == (CORE_ADDR) -1) { - if (pc == cur_thr->stop_pc () + if (cur_thr->stop_pc_p () + && pc == cur_thr->stop_pc () && breakpoint_here_p (aspace, pc) == ordinary_breakpoint_here && execution_direction != EXEC_REVERSE) /* There is a breakpoint at the address we will resume at, diff --git a/gdb/thread.c b/gdb/thread.c index c95a918..10c3dcd 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -324,7 +324,7 @@ thread_info::set_executing (bool executing) { m_executing = executing; if (executing) - this->set_stop_pc (~(CORE_ADDR) 0); + this->clear_stop_pc (); } /* See gdbthread.h. */ |