Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1 | //===-- StopInfo.cpp ---------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 12 | #include "lldb/Target/StopInfo.h" |
| 13 | |
| 14 | // C Includes |
| 15 | // C++ Includes |
| 16 | #include <string> |
| 17 | |
| 18 | // Other libraries and framework includes |
| 19 | // Project includes |
| 20 | #include "lldb/Core/Log.h" |
Greg Clayton | 4e78f60 | 2010-11-18 18:52:36 +0000 | [diff] [blame] | 21 | #include "lldb/Breakpoint/Breakpoint.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 22 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 23 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 24 | #include "lldb/Breakpoint/Watchpoint.h" |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 25 | #include "lldb/Core/Debugger.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 26 | #include "lldb/Core/StreamString.h" |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 27 | #include "lldb/Expression/ClangUserExpression.h" |
| 28 | #include "lldb/Target/Target.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 29 | #include "lldb/Target/Thread.h" |
| 30 | #include "lldb/Target/ThreadPlan.h" |
| 31 | #include "lldb/Target/Process.h" |
| 32 | #include "lldb/Target/UnixSignals.h" |
| 33 | |
| 34 | using namespace lldb; |
| 35 | using namespace lldb_private; |
| 36 | |
| 37 | StopInfo::StopInfo (Thread &thread, uint64_t value) : |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 38 | m_thread_wp (thread.shared_from_this()), |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 39 | m_stop_id (thread.GetProcess()->GetStopID()), |
| 40 | m_resume_id (thread.GetProcess()->GetResumeID()), |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 41 | m_value (value), |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 42 | m_override_should_notify (eLazyBoolCalculate), |
| 43 | m_override_should_stop (eLazyBoolCalculate) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 44 | { |
| 45 | } |
| 46 | |
| 47 | bool |
| 48 | StopInfo::IsValid () const |
| 49 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 50 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 51 | if (thread_sp) |
| 52 | return thread_sp->GetProcess()->GetStopID() == m_stop_id; |
| 53 | return false; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 56 | void |
| 57 | StopInfo::MakeStopInfoValid () |
| 58 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 59 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 60 | if (thread_sp) |
| 61 | { |
| 62 | m_stop_id = thread_sp->GetProcess()->GetStopID(); |
| 63 | m_resume_id = thread_sp->GetProcess()->GetResumeID(); |
| 64 | } |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 67 | bool |
| 68 | StopInfo::HasTargetRunSinceMe () |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 69 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 70 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 71 | |
| 72 | if (thread_sp) |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 73 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 74 | lldb::StateType ret_type = thread_sp->GetProcess()->GetPrivateState(); |
| 75 | if (ret_type == eStateRunning) |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 76 | { |
| 77 | return true; |
| 78 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 79 | else if (ret_type == eStateStopped) |
| 80 | { |
| 81 | // This is a little tricky. We want to count "run and stopped again before you could |
| 82 | // ask this question as a "TRUE" answer to HasTargetRunSinceMe. But we don't want to |
| 83 | // include any running of the target done for expressions. So we track both resumes, |
| 84 | // and resumes caused by expressions, and check if there are any resumes NOT caused |
| 85 | // by expressions. |
| 86 | |
| 87 | uint32_t curr_resume_id = thread_sp->GetProcess()->GetResumeID(); |
| 88 | uint32_t last_user_expression_id = thread_sp->GetProcess()->GetLastUserExpressionResumeID (); |
| 89 | if (curr_resume_id == m_resume_id) |
| 90 | { |
| 91 | return false; |
| 92 | } |
| 93 | else if (curr_resume_id > last_user_expression_id) |
| 94 | { |
| 95 | return true; |
| 96 | } |
| 97 | } |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 98 | } |
| 99 | return false; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 102 | //---------------------------------------------------------------------- |
| 103 | // StopInfoBreakpoint |
| 104 | //---------------------------------------------------------------------- |
| 105 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 106 | namespace lldb_private |
| 107 | { |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 108 | class StopInfoBreakpoint : public StopInfo |
| 109 | { |
| 110 | public: |
| 111 | |
| 112 | StopInfoBreakpoint (Thread &thread, break_id_t break_id) : |
| 113 | StopInfo (thread, break_id), |
| 114 | m_description(), |
| 115 | m_should_stop (false), |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 116 | m_should_stop_is_valid (false), |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 117 | m_should_perform_action (true), |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 118 | m_address (LLDB_INVALID_ADDRESS), |
| 119 | m_break_id(LLDB_INVALID_BREAK_ID), |
| 120 | m_was_one_shot (false) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 121 | { |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 122 | StoreBPInfo(); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 125 | StopInfoBreakpoint (Thread &thread, break_id_t break_id, bool should_stop) : |
| 126 | StopInfo (thread, break_id), |
| 127 | m_description(), |
| 128 | m_should_stop (should_stop), |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 129 | m_should_stop_is_valid (true), |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 130 | m_should_perform_action (true), |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 131 | m_address (LLDB_INVALID_ADDRESS), |
| 132 | m_break_id(LLDB_INVALID_BREAK_ID), |
| 133 | m_was_one_shot (false) |
| 134 | { |
| 135 | StoreBPInfo(); |
| 136 | } |
| 137 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 138 | void |
| 139 | StoreBPInfo () |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 140 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 141 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 142 | if (thread_sp) |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 143 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 144 | BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
| 145 | if (bp_site_sp) |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 146 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 147 | if (bp_site_sp->GetNumberOfOwners() == 1) |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 148 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 149 | BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(0); |
| 150 | if (bp_loc_sp) |
| 151 | { |
| 152 | m_break_id = bp_loc_sp->GetBreakpoint().GetID(); |
| 153 | m_was_one_shot = bp_loc_sp->GetBreakpoint().IsOneShot(); |
| 154 | } |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 155 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 156 | m_address = bp_site_sp->GetLoadAddress(); |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 157 | } |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 158 | } |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 161 | virtual ~StopInfoBreakpoint () |
| 162 | { |
| 163 | } |
| 164 | |
| 165 | virtual StopReason |
| 166 | GetStopReason () const |
| 167 | { |
| 168 | return eStopReasonBreakpoint; |
| 169 | } |
| 170 | |
| 171 | virtual bool |
Jim Ingham | 6d66ce6 | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 172 | ShouldStopSynchronous (Event *event_ptr) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 173 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 174 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 175 | if (thread_sp) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 176 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 177 | if (!m_should_stop_is_valid) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 178 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 179 | // Only check once if we should stop at a breakpoint |
| 180 | BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
| 181 | if (bp_site_sp) |
| 182 | { |
| 183 | ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0)); |
| 184 | StoppointCallbackContext context (event_ptr, exe_ctx, true); |
| 185 | m_should_stop = bp_site_sp->ShouldStop (&context); |
| 186 | } |
| 187 | else |
| 188 | { |
| 189 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 190 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 191 | if (log) |
| 192 | log->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 193 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 194 | m_should_stop = true; |
| 195 | } |
| 196 | m_should_stop_is_valid = true; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 197 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 198 | return m_should_stop; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 199 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 200 | return false; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 201 | } |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 202 | |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 203 | virtual bool |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 204 | DoShouldNotify (Event *event_ptr) |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 205 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 206 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 207 | if (thread_sp) |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 208 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 209 | BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
| 210 | if (bp_site_sp) |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 211 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 212 | bool all_internal = true; |
| 213 | |
| 214 | for (uint32_t i = 0; i < bp_site_sp->GetNumberOfOwners(); i++) |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 215 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 216 | if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal()) |
| 217 | { |
| 218 | all_internal = false; |
| 219 | break; |
| 220 | } |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 221 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 222 | return all_internal == false; |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 223 | } |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 224 | } |
| 225 | return true; |
| 226 | } |
| 227 | |
| 228 | virtual const char * |
| 229 | GetDescription () |
| 230 | { |
| 231 | if (m_description.empty()) |
| 232 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 233 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 234 | if (thread_sp) |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 235 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 236 | BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
| 237 | if (bp_site_sp) |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 238 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 239 | StreamString strm; |
| 240 | // If we have just hit an internal breakpoint, and it has a kind description, print that instead of the |
| 241 | // full breakpoint printing: |
| 242 | if (bp_site_sp->IsInternal()) |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 243 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 244 | size_t num_owners = bp_site_sp->GetNumberOfOwners(); |
| 245 | for (size_t idx = 0; idx < num_owners; idx++) |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 246 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 247 | const char *kind = bp_site_sp->GetOwnerAtIndex(idx)->GetBreakpoint().GetBreakpointKind(); |
| 248 | if (kind != NULL) |
| 249 | { |
| 250 | m_description.assign (kind); |
| 251 | return kind; |
| 252 | } |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 253 | } |
| 254 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 255 | |
| 256 | strm.Printf("breakpoint "); |
| 257 | bp_site_sp->GetDescription(&strm, eDescriptionLevelBrief); |
| 258 | m_description.swap (strm.GetString()); |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 259 | } |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 260 | else |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 261 | { |
| 262 | StreamString strm; |
| 263 | if (m_break_id != LLDB_INVALID_BREAK_ID) |
| 264 | { |
| 265 | BreakpointSP break_sp = thread_sp->GetProcess()->GetTarget().GetBreakpointByID(m_break_id); |
| 266 | if (break_sp) |
| 267 | { |
| 268 | if (break_sp->IsInternal()) |
| 269 | { |
| 270 | const char *kind = break_sp->GetBreakpointKind(); |
| 271 | if (kind) |
| 272 | strm.Printf ("internal %s breakpoint(%d).", kind, m_break_id); |
| 273 | else |
| 274 | strm.Printf ("internal breakpoint(%d).", m_break_id); |
| 275 | } |
| 276 | else |
| 277 | { |
| 278 | strm.Printf ("breakpoint %d.", m_break_id); |
| 279 | } |
| 280 | } |
| 281 | else |
| 282 | { |
| 283 | if (m_was_one_shot) |
| 284 | strm.Printf ("one-shot breakpoint %d", m_break_id); |
| 285 | else |
| 286 | strm.Printf ("breakpoint %d which has been deleted.", m_break_id); |
| 287 | } |
| 288 | } |
| 289 | else if (m_address == LLDB_INVALID_ADDRESS) |
| 290 | strm.Printf("breakpoint site %" PRIi64 " which has been deleted - unknown address", m_value); |
| 291 | else |
| 292 | strm.Printf("breakpoint site %" PRIi64 " which has been deleted - was at 0x%" PRIx64, m_value, m_address); |
| 293 | |
| 294 | m_description.swap (strm.GetString()); |
| 295 | } |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | return m_description.c_str(); |
| 299 | } |
| 300 | |
| 301 | protected: |
Jim Ingham | 6d66ce6 | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 302 | bool |
| 303 | ShouldStop (Event *event_ptr) |
| 304 | { |
| 305 | // This just reports the work done by PerformAction or the synchronous stop. It should |
| 306 | // only ever get called after they have had a chance to run. |
| 307 | assert (m_should_stop_is_valid); |
| 308 | return m_should_stop; |
| 309 | } |
| 310 | |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 311 | virtual void |
| 312 | PerformAction (Event *event_ptr) |
| 313 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 314 | if (!m_should_perform_action) |
| 315 | return; |
| 316 | m_should_perform_action = false; |
| 317 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 318 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 319 | |
| 320 | if (thread_sp) |
Jim Ingham | 5cb9a18 | 2013-03-28 00:13:30 +0000 | [diff] [blame] | 321 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 322 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
| 323 | |
| 324 | if (!thread_sp->IsValid()) |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 325 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 326 | // This shouldn't ever happen, but just in case, don't do more harm. |
Jason Molenda | 3f032ff | 2013-08-06 23:08:59 +0000 | [diff] [blame] | 327 | if (log) |
| 328 | { |
| 329 | log->Printf ("PerformAction got called with an invalid thread."); |
| 330 | } |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 331 | m_should_stop = true; |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 332 | m_should_stop_is_valid = true; |
| 333 | return; |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 334 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 335 | |
| 336 | BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value)); |
| 337 | |
| 338 | if (bp_site_sp) |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 339 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 340 | size_t num_owners = bp_site_sp->GetNumberOfOwners(); |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 341 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 342 | if (num_owners == 0) |
| 343 | { |
| 344 | m_should_stop = true; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 345 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 346 | else |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 347 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 348 | // We go through each location, and test first its condition. If the condition says to stop, |
| 349 | // then we run the callback for that location. If that callback says to stop as well, then |
| 350 | // we set m_should_stop to true; we are going to stop. |
| 351 | // But we still want to give all the breakpoints whose conditions say we are going to stop a |
| 352 | // chance to run their callbacks. |
| 353 | // Of course if any callback restarts the target by putting "continue" in the callback, then |
| 354 | // we're going to restart, without running the rest of the callbacks. And in this case we will |
| 355 | // end up not stopping even if another location said we should stop. But that's better than not |
| 356 | // running all the callbacks. |
Jim Ingham | dbd3c4d | 2013-04-11 22:53:47 +0000 | [diff] [blame] | 357 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 358 | m_should_stop = false; |
| 359 | |
| 360 | ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0)); |
| 361 | Process *process = exe_ctx.GetProcessPtr(); |
| 362 | if (process->GetModIDRef().IsLastResumeForUserExpression()) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 363 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 364 | // If we are in the middle of evaluating an expression, don't run asynchronous breakpoint commands or |
| 365 | // expressions. That could lead to infinite recursion if the command or condition re-calls the function |
| 366 | // with this breakpoint. |
| 367 | // TODO: We can keep a list of the breakpoints we've seen while running expressions in the nested |
| 368 | // PerformAction calls that can arise when the action runs a function that hits another breakpoint, |
| 369 | // and only stop running commands when we see the same breakpoint hit a second time. |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 370 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 371 | m_should_stop_is_valid = true; |
| 372 | if (log) |
| 373 | log->Printf ("StopInfoBreakpoint::PerformAction - Hit a breakpoint while running an expression," |
| 374 | " not running commands to avoid recursion."); |
| 375 | bool ignoring_breakpoints = process->GetIgnoreBreakpointsInExpressions(); |
| 376 | if (ignoring_breakpoints) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 377 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 378 | m_should_stop = false; |
| 379 | // Internal breakpoints will always stop. |
| 380 | for (size_t j = 0; j < num_owners; j++) |
| 381 | { |
| 382 | lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j); |
| 383 | if (bp_loc_sp->GetBreakpoint().IsInternal()) |
| 384 | { |
| 385 | m_should_stop = true; |
| 386 | break; |
| 387 | } |
| 388 | } |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 389 | } |
Sean Callanan | 3dbf346 | 2013-04-19 07:09:15 +0000 | [diff] [blame] | 390 | else |
| 391 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 392 | m_should_stop = true; |
| 393 | } |
| 394 | if (log) |
| 395 | log->Printf ("StopInfoBreakpoint::PerformAction - in expression, continuing: %s.", |
| 396 | m_should_stop ? "true" : "false"); |
| 397 | process->GetTarget().GetDebugger().GetAsyncOutputStream()->Printf("Warning: hit breakpoint while " |
| 398 | "running function, skipping commands and conditions to prevent recursion."); |
| 399 | return; |
| 400 | } |
| 401 | |
| 402 | StoppointCallbackContext context (event_ptr, exe_ctx, false); |
| 403 | |
| 404 | // Let's copy the breakpoint locations out of the site and store them in a local list. That way if |
| 405 | // one of the breakpoint actions changes the site, then we won't be operating on a bad list. |
| 406 | |
| 407 | BreakpointLocationCollection site_locations; |
| 408 | for (size_t j = 0; j < num_owners; j++) |
| 409 | site_locations.Add(bp_site_sp->GetOwnerAtIndex(j)); |
| 410 | |
| 411 | for (size_t j = 0; j < num_owners; j++) |
| 412 | { |
| 413 | lldb::BreakpointLocationSP bp_loc_sp = site_locations.GetByIndex(j); |
| 414 | |
| 415 | // If another action disabled this breakpoint or its location, then don't run the actions. |
| 416 | if (!bp_loc_sp->IsEnabled() || !bp_loc_sp->GetBreakpoint().IsEnabled()) |
| 417 | continue; |
| 418 | |
| 419 | // The breakpoint site may have many locations associated with it, not all of them valid for |
| 420 | // this thread. Skip the ones that aren't: |
| 421 | if (!bp_loc_sp->ValidForThisThread(thread_sp.get())) |
Jim Ingham | a8b99ca | 2014-01-15 03:30:04 +0000 | [diff] [blame] | 422 | { |
| 423 | if (log) |
| 424 | { |
| 425 | StreamString s; |
| 426 | bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief); |
| 427 | log->Printf ("Breakpoint %s hit on thread 0x%llx but it was not for this thread, continuing.", s.GetData(), thread_sp->GetID()); |
| 428 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 429 | continue; |
Jim Ingham | a8b99ca | 2014-01-15 03:30:04 +0000 | [diff] [blame] | 430 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 431 | // First run the condition for the breakpoint. If that says we should stop, then we'll run |
| 432 | // the callback for the breakpoint. If the callback says we shouldn't stop that will win. |
| 433 | |
| 434 | if (bp_loc_sp->GetConditionText() != NULL) |
| 435 | { |
| 436 | Error condition_error; |
| 437 | bool condition_says_stop = bp_loc_sp->ConditionSaysStop(exe_ctx, condition_error); |
| 438 | |
| 439 | if (!condition_error.Success()) |
| 440 | { |
| 441 | Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger(); |
| 442 | StreamSP error_sp = debugger.GetAsyncErrorStream (); |
| 443 | error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint "); |
| 444 | bp_loc_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief); |
| 445 | error_sp->Printf (": \"%s\"", |
| 446 | bp_loc_sp->GetConditionText()); |
| 447 | error_sp->EOL(); |
| 448 | const char *err_str = condition_error.AsCString("<Unknown Error>"); |
| 449 | if (log) |
| 450 | log->Printf("Error evaluating condition: \"%s\"\n", err_str); |
| 451 | |
| 452 | error_sp->PutCString (err_str); |
| 453 | error_sp->EOL(); |
| 454 | error_sp->Flush(); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 455 | } |
| 456 | else |
| 457 | { |
Jim Ingham | a8b99ca | 2014-01-15 03:30:04 +0000 | [diff] [blame] | 458 | if (log) |
| 459 | { |
| 460 | StreamString s; |
| 461 | bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief); |
| 462 | log->Printf ("Condition evaluated for breakpoint %s on thread 0x%llx conditon_says_stop: %i.", s.GetData(), thread_sp->GetID(), condition_says_stop); |
| 463 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 464 | if (!condition_says_stop) |
| 465 | continue; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | bool callback_says_stop; |
| 470 | |
| 471 | // FIXME: For now the callbacks have to run in async mode - the first time we restart we need |
| 472 | // to get out of there. So set it here. |
| 473 | // When we figure out how to nest breakpoint hits then this will change. |
| 474 | |
| 475 | Debugger &debugger = thread_sp->CalculateTarget()->GetDebugger(); |
| 476 | bool old_async = debugger.GetAsyncExecution(); |
| 477 | debugger.SetAsyncExecution (true); |
| 478 | |
| 479 | callback_says_stop = bp_loc_sp->InvokeCallback (&context); |
| 480 | |
| 481 | debugger.SetAsyncExecution (old_async); |
| 482 | |
| 483 | if (callback_says_stop) |
| 484 | m_should_stop = true; |
| 485 | |
| 486 | // If we are going to stop for this breakpoint, then remove the breakpoint. |
| 487 | if (callback_says_stop && bp_loc_sp && bp_loc_sp->GetBreakpoint().IsOneShot()) |
| 488 | { |
| 489 | thread_sp->GetProcess()->GetTarget().RemoveBreakpointByID (bp_loc_sp->GetBreakpoint().GetID()); |
| 490 | } |
| 491 | |
| 492 | // Also make sure that the callback hasn't continued the target. |
| 493 | // If it did, when we'll set m_should_start to false and get out of here. |
| 494 | if (HasTargetRunSinceMe ()) |
| 495 | { |
| 496 | m_should_stop = false; |
| 497 | break; |
Sean Callanan | 3dbf346 | 2013-04-19 07:09:15 +0000 | [diff] [blame] | 498 | } |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 499 | } |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 500 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 501 | // We've figured out what this stop wants to do, so mark it as valid so we don't compute it again. |
| 502 | m_should_stop_is_valid = true; |
| 503 | |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 504 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 505 | else |
| 506 | { |
| 507 | m_should_stop = true; |
| 508 | m_should_stop_is_valid = true; |
| 509 | Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 79ea1d8 | 2011-12-09 04:17:31 +0000 | [diff] [blame] | 510 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 511 | if (log_process) |
| 512 | log_process->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value); |
| 513 | } |
| 514 | if (log) |
| 515 | log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop); |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 516 | } |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 517 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 518 | |
| 519 | private: |
| 520 | std::string m_description; |
| 521 | bool m_should_stop; |
| 522 | bool m_should_stop_is_valid; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 523 | bool m_should_perform_action; // Since we are trying to preserve the "state" of the system even if we run functions |
| 524 | // etc. behind the users backs, we need to make sure we only REALLY perform the action once. |
Jim Ingham | 52c7d20 | 2011-10-28 01:12:19 +0000 | [diff] [blame] | 525 | lldb::addr_t m_address; // We use this to capture the breakpoint site address when we create the StopInfo, |
| 526 | // in case somebody deletes it between the time the StopInfo is made and the |
| 527 | // description is asked for. |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 528 | lldb::break_id_t m_break_id; |
| 529 | bool m_was_one_shot; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 530 | }; |
| 531 | |
| 532 | |
| 533 | //---------------------------------------------------------------------- |
| 534 | // StopInfoWatchpoint |
| 535 | //---------------------------------------------------------------------- |
| 536 | |
| 537 | class StopInfoWatchpoint : public StopInfo |
| 538 | { |
| 539 | public: |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 540 | // Make sure watchpoint is properly disabled and subsequently enabled while performing watchpoint actions. |
| 541 | class WatchpointSentry { |
| 542 | public: |
| 543 | WatchpointSentry(Process *p, Watchpoint *w): |
| 544 | process(p), |
| 545 | watchpoint(w) |
| 546 | { |
| 547 | if (process && watchpoint) |
| 548 | { |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 549 | const bool notify = false; |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 550 | watchpoint->TurnOnEphemeralMode(); |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 551 | process->DisableWatchpoint(watchpoint, notify); |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | ~WatchpointSentry() |
| 555 | { |
| 556 | if (process && watchpoint) |
| 557 | { |
| 558 | if (!watchpoint->IsDisabledDuringEphemeralMode()) |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 559 | { |
| 560 | const bool notify = false; |
| 561 | process->EnableWatchpoint(watchpoint, notify); |
| 562 | } |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 563 | watchpoint->TurnOffEphemeralMode(); |
| 564 | } |
| 565 | } |
| 566 | private: |
| 567 | Process *process; |
| 568 | Watchpoint *watchpoint; |
| 569 | }; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 570 | |
| 571 | StopInfoWatchpoint (Thread &thread, break_id_t watch_id) : |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 572 | StopInfo(thread, watch_id), |
| 573 | m_description(), |
| 574 | m_should_stop(false), |
| 575 | m_should_stop_is_valid(false) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 576 | { |
| 577 | } |
| 578 | |
| 579 | virtual ~StopInfoWatchpoint () |
| 580 | { |
| 581 | } |
| 582 | |
| 583 | virtual StopReason |
| 584 | GetStopReason () const |
| 585 | { |
| 586 | return eStopReasonWatchpoint; |
| 587 | } |
| 588 | |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 589 | virtual const char * |
| 590 | GetDescription () |
| 591 | { |
| 592 | if (m_description.empty()) |
| 593 | { |
| 594 | StreamString strm; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 595 | strm.Printf("watchpoint %" PRIi64, m_value); |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 596 | m_description.swap (strm.GetString()); |
| 597 | } |
| 598 | return m_description.c_str(); |
| 599 | } |
| 600 | |
| 601 | protected: |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 602 | virtual bool |
Jim Ingham | 9b620f3 | 2013-02-22 21:23:43 +0000 | [diff] [blame] | 603 | ShouldStopSynchronous (Event *event_ptr) |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 604 | { |
| 605 | // ShouldStop() method is idempotent and should not affect hit count. |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 606 | // See Process::RunPrivateStateThread()->Process()->HandlePrivateEvent() |
| 607 | // -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()-> |
| 608 | // Thread::ShouldStop()->ThreadPlanBase::ShouldStop()-> |
| 609 | // StopInfoWatchpoint::ShouldStop() and |
| 610 | // Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()-> |
| 611 | // StopInfoWatchpoint::PerformAction(). |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 612 | if (m_should_stop_is_valid) |
| 613 | return m_should_stop; |
| 614 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 615 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 616 | if (thread_sp) |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 617 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 618 | WatchpointSP wp_sp (thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue())); |
| 619 | if (wp_sp) |
| 620 | { |
| 621 | // Check if we should stop at a watchpoint. |
| 622 | ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0)); |
| 623 | StoppointCallbackContext context (event_ptr, exe_ctx, true); |
| 624 | m_should_stop = wp_sp->ShouldStop (&context); |
| 625 | } |
| 626 | else |
| 627 | { |
| 628 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 629 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 630 | if (log) |
| 631 | log->Printf ("Process::%s could not find watchpoint location id: %" PRId64 "...", |
| 632 | __FUNCTION__, GetValue()); |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 633 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 634 | m_should_stop = true; |
| 635 | } |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 636 | } |
| 637 | m_should_stop_is_valid = true; |
| 638 | return m_should_stop; |
| 639 | } |
| 640 | |
Jim Ingham | 9b620f3 | 2013-02-22 21:23:43 +0000 | [diff] [blame] | 641 | bool |
| 642 | ShouldStop (Event *event_ptr) |
| 643 | { |
| 644 | // This just reports the work done by PerformAction or the synchronous stop. It should |
| 645 | // only ever get called after they have had a chance to run. |
| 646 | assert (m_should_stop_is_valid); |
| 647 | return m_should_stop; |
| 648 | } |
| 649 | |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 650 | virtual void |
| 651 | PerformAction (Event *event_ptr) |
| 652 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 653 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS); |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 654 | // We're going to calculate if we should stop or not in some way during the course of |
| 655 | // this code. Also by default we're going to stop, so set that here. |
| 656 | m_should_stop = true; |
| 657 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 658 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 659 | if (thread_sp) |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 660 | { |
Johnny Chen | 0f7ad8d | 2012-08-21 22:06:34 +0000 | [diff] [blame] | 661 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 662 | WatchpointSP wp_sp (thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue())); |
| 663 | if (wp_sp) |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 664 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 665 | ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0)); |
| 666 | Process* process = exe_ctx.GetProcessPtr(); |
| 667 | |
| 668 | // This sentry object makes sure the current watchpoint is disabled while performing watchpoint actions, |
| 669 | // and it is then enabled after we are finished. |
| 670 | WatchpointSentry sentry(process, wp_sp.get()); |
| 671 | |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 672 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 673 | // check if this process is running on an architecture where watchpoints trigger |
| 674 | // before the associated instruction runs. if so, disable the WP, single-step and then |
| 675 | // re-enable the watchpoint |
| 676 | if (process) |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 677 | { |
Jason Molenda | fe80690 | 2013-05-04 00:39:52 +0000 | [diff] [blame] | 678 | uint32_t num; |
| 679 | bool wp_triggers_after; |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 680 | if (process->GetWatchpointSupportInfo(num, wp_triggers_after).Success()) |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 681 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 682 | if (!wp_triggers_after) |
| 683 | { |
Jim Ingham | 363ddd7 | 2013-07-02 21:12:44 +0000 | [diff] [blame] | 684 | StopInfoSP stored_stop_info_sp = thread_sp->GetStopInfo(); |
| 685 | assert (stored_stop_info_sp.get() == this); |
| 686 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 687 | ThreadPlanSP new_plan_sp(thread_sp->QueueThreadPlanForStepSingleInstruction(false, // step-over |
| 688 | false, // abort_other_plans |
| 689 | true)); // stop_other_threads |
| 690 | new_plan_sp->SetIsMasterPlan (true); |
| 691 | new_plan_sp->SetOkayToDiscard (false); |
| 692 | new_plan_sp->SetPrivate (true); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 693 | process->GetThreadList().SetSelectedThreadByID (thread_sp->GetID()); |
| 694 | process->Resume (); |
| 695 | process->WaitForProcessToStop (NULL); |
| 696 | process->GetThreadList().SetSelectedThreadByID (thread_sp->GetID()); |
Jim Ingham | 363ddd7 | 2013-07-02 21:12:44 +0000 | [diff] [blame] | 697 | thread_sp->SetStopInfo(stored_stop_info_sp); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 698 | } |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | } |
Johnny Chen | 209bd65 | 2012-08-13 21:09:54 +0000 | [diff] [blame] | 702 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 703 | if (m_should_stop && wp_sp->GetConditionText() != NULL) |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 704 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 705 | // We need to make sure the user sees any parse errors in their condition, so we'll hook the |
| 706 | // constructor errors up to the debugger's Async I/O. |
| 707 | ExecutionResults result_code; |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 708 | EvaluateExpressionOptions expr_options; |
| 709 | expr_options.SetUnwindOnError(true); |
| 710 | expr_options.SetIgnoreBreakpoints(true); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 711 | ValueObjectSP result_value_sp; |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 712 | Error error; |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 713 | result_code = ClangUserExpression::Evaluate (exe_ctx, |
| 714 | expr_options, |
| 715 | wp_sp->GetConditionText(), |
| 716 | NULL, |
| 717 | result_value_sp, |
| 718 | error); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 719 | if (result_code == eExecutionCompleted) |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 720 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 721 | if (result_value_sp) |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 722 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 723 | Scalar scalar_value; |
| 724 | if (result_value_sp->ResolveValue (scalar_value)) |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 725 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 726 | if (scalar_value.ULongLong(1) == 0) |
| 727 | { |
| 728 | // We have been vetoed. This takes precedence over querying |
| 729 | // the watchpoint whether it should stop (aka ignore count and |
| 730 | // friends). See also StopInfoWatchpoint::ShouldStop() as well |
| 731 | // as Process::ProcessEventData::DoOnRemoval(). |
| 732 | m_should_stop = false; |
| 733 | } |
| 734 | else |
| 735 | m_should_stop = true; |
| 736 | if (log) |
| 737 | log->Printf("Condition successfully evaluated, result is %s.\n", |
| 738 | m_should_stop ? "true" : "false"); |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 739 | } |
| 740 | else |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 741 | { |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 742 | m_should_stop = true; |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 743 | if (log) |
| 744 | log->Printf("Failed to get an integer result from the expression."); |
| 745 | } |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 746 | } |
| 747 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 748 | else |
| 749 | { |
| 750 | Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger(); |
| 751 | StreamSP error_sp = debugger.GetAsyncErrorStream (); |
| 752 | error_sp->Printf ("Stopped due to an error evaluating condition of watchpoint "); |
| 753 | wp_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief); |
| 754 | error_sp->Printf (": \"%s\"", |
| 755 | wp_sp->GetConditionText()); |
| 756 | error_sp->EOL(); |
| 757 | const char *err_str = error.AsCString("<Unknown Error>"); |
| 758 | if (log) |
| 759 | log->Printf("Error evaluating condition: \"%s\"\n", err_str); |
| 760 | |
| 761 | error_sp->PutCString (err_str); |
| 762 | error_sp->EOL(); |
| 763 | error_sp->Flush(); |
| 764 | // If the condition fails to be parsed or run, we should stop. |
| 765 | m_should_stop = true; |
| 766 | } |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 767 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 768 | |
| 769 | // If the condition says to stop, we run the callback to further decide whether to stop. |
| 770 | if (m_should_stop) |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 771 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 772 | StoppointCallbackContext context (event_ptr, exe_ctx, false); |
| 773 | bool stop_requested = wp_sp->InvokeCallback (&context); |
| 774 | // Also make sure that the callback hasn't continued the target. |
| 775 | // If it did, when we'll set m_should_stop to false and get out of here. |
| 776 | if (HasTargetRunSinceMe ()) |
| 777 | m_should_stop = false; |
| 778 | |
| 779 | if (m_should_stop && !stop_requested) |
| 780 | { |
| 781 | // We have been vetoed by the callback mechanism. |
| 782 | m_should_stop = false; |
| 783 | } |
| 784 | } |
| 785 | // Finally, if we are going to stop, print out the new & old values: |
| 786 | if (m_should_stop) |
| 787 | { |
| 788 | wp_sp->CaptureWatchedValue(exe_ctx); |
| 789 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 790 | Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger(); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 791 | StreamSP output_sp = debugger.GetAsyncOutputStream (); |
| 792 | wp_sp->DumpSnapshots(output_sp.get()); |
| 793 | output_sp->EOL(); |
| 794 | output_sp->Flush(); |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 795 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 796 | |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 797 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 798 | else |
| 799 | { |
| 800 | Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Johnny Chen | 1320641 | 2012-08-09 23:10:57 +0000 | [diff] [blame] | 801 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 802 | if (log_process) |
| 803 | log_process->Printf ("Process::%s could not find watchpoint id: %" PRId64 "...", __FUNCTION__, m_value); |
Johnny Chen | 1320641 | 2012-08-09 23:10:57 +0000 | [diff] [blame] | 804 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 805 | if (log) |
| 806 | log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop); |
Jim Ingham | a7dfb66 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 807 | |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 808 | m_should_stop_is_valid = true; |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 809 | } |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 812 | private: |
| 813 | std::string m_description; |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 814 | bool m_should_stop; |
| 815 | bool m_should_stop_is_valid; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 816 | }; |
| 817 | |
| 818 | |
| 819 | |
| 820 | //---------------------------------------------------------------------- |
| 821 | // StopInfoUnixSignal |
| 822 | //---------------------------------------------------------------------- |
| 823 | |
| 824 | class StopInfoUnixSignal : public StopInfo |
| 825 | { |
| 826 | public: |
| 827 | |
| 828 | StopInfoUnixSignal (Thread &thread, int signo) : |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 829 | StopInfo (thread, signo) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 830 | { |
| 831 | } |
| 832 | |
| 833 | virtual ~StopInfoUnixSignal () |
| 834 | { |
| 835 | } |
| 836 | |
| 837 | |
| 838 | virtual StopReason |
| 839 | GetStopReason () const |
| 840 | { |
| 841 | return eStopReasonSignal; |
| 842 | } |
| 843 | |
| 844 | virtual bool |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 845 | ShouldStopSynchronous (Event *event_ptr) |
| 846 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 847 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 848 | if (thread_sp) |
| 849 | return thread_sp->GetProcess()->GetUnixSignals().GetShouldStop (m_value); |
| 850 | return false; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | virtual bool |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 854 | ShouldStop (Event *event_ptr) |
| 855 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 856 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 857 | if (thread_sp) |
| 858 | return thread_sp->GetProcess()->GetUnixSignals().GetShouldStop (m_value); |
| 859 | return false; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | |
| 863 | // If should stop returns false, check if we should notify of this event |
| 864 | virtual bool |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 865 | DoShouldNotify (Event *event_ptr) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 866 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 867 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 868 | if (thread_sp) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 869 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 870 | bool should_notify = thread_sp->GetProcess()->GetUnixSignals().GetShouldNotify (m_value); |
| 871 | if (should_notify) |
| 872 | { |
| 873 | StreamString strm; |
| 874 | strm.Printf ("thread %d received signal: %s", |
| 875 | thread_sp->GetIndexID(), |
| 876 | thread_sp->GetProcess()->GetUnixSignals().GetSignalAsCString (m_value)); |
| 877 | Process::ProcessEventData::AddRestartedReason(event_ptr, strm.GetData()); |
| 878 | } |
| 879 | return should_notify; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 880 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 881 | return true; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | |
| 885 | virtual void |
| 886 | WillResume (lldb::StateType resume_state) |
| 887 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 888 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 889 | if (thread_sp) |
| 890 | { |
| 891 | if (thread_sp->GetProcess()->GetUnixSignals().GetShouldSuppress(m_value) == false) |
| 892 | thread_sp->SetResumeSignal(m_value); |
| 893 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | virtual const char * |
| 897 | GetDescription () |
| 898 | { |
| 899 | if (m_description.empty()) |
| 900 | { |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 901 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 902 | if (thread_sp) |
| 903 | { |
| 904 | StreamString strm; |
| 905 | const char *signal_name = thread_sp->GetProcess()->GetUnixSignals().GetSignalAsCString (m_value); |
| 906 | if (signal_name) |
| 907 | strm.Printf("signal %s", signal_name); |
| 908 | else |
| 909 | strm.Printf("signal %" PRIi64, m_value); |
| 910 | m_description.swap (strm.GetString()); |
| 911 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 912 | } |
| 913 | return m_description.c_str(); |
| 914 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 915 | }; |
| 916 | |
| 917 | //---------------------------------------------------------------------- |
| 918 | // StopInfoTrace |
| 919 | //---------------------------------------------------------------------- |
| 920 | |
| 921 | class StopInfoTrace : public StopInfo |
| 922 | { |
| 923 | public: |
| 924 | |
| 925 | StopInfoTrace (Thread &thread) : |
| 926 | StopInfo (thread, LLDB_INVALID_UID) |
| 927 | { |
| 928 | } |
| 929 | |
| 930 | virtual ~StopInfoTrace () |
| 931 | { |
| 932 | } |
| 933 | |
| 934 | virtual StopReason |
| 935 | GetStopReason () const |
| 936 | { |
| 937 | return eStopReasonTrace; |
| 938 | } |
| 939 | |
| 940 | virtual const char * |
| 941 | GetDescription () |
| 942 | { |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 943 | if (m_description.empty()) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 944 | return "trace"; |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 945 | else |
| 946 | return m_description.c_str(); |
| 947 | } |
| 948 | }; |
| 949 | |
| 950 | |
| 951 | //---------------------------------------------------------------------- |
| 952 | // StopInfoException |
| 953 | //---------------------------------------------------------------------- |
| 954 | |
| 955 | class StopInfoException : public StopInfo |
| 956 | { |
| 957 | public: |
| 958 | |
| 959 | StopInfoException (Thread &thread, const char *description) : |
| 960 | StopInfo (thread, LLDB_INVALID_UID) |
| 961 | { |
| 962 | if (description) |
| 963 | SetDescription (description); |
| 964 | } |
| 965 | |
| 966 | virtual |
| 967 | ~StopInfoException () |
| 968 | { |
| 969 | } |
| 970 | |
| 971 | virtual StopReason |
| 972 | GetStopReason () const |
| 973 | { |
| 974 | return eStopReasonException; |
| 975 | } |
| 976 | |
| 977 | virtual const char * |
| 978 | GetDescription () |
| 979 | { |
| 980 | if (m_description.empty()) |
| 981 | return "exception"; |
| 982 | else |
| 983 | return m_description.c_str(); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 984 | } |
| 985 | }; |
| 986 | |
| 987 | |
| 988 | //---------------------------------------------------------------------- |
| 989 | // StopInfoThreadPlan |
| 990 | //---------------------------------------------------------------------- |
| 991 | |
| 992 | class StopInfoThreadPlan : public StopInfo |
| 993 | { |
| 994 | public: |
| 995 | |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 996 | StopInfoThreadPlan (ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp) : |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 997 | StopInfo (plan_sp->GetThread(), LLDB_INVALID_UID), |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 998 | m_plan_sp (plan_sp), |
| 999 | m_return_valobj_sp (return_valobj_sp) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1000 | { |
| 1001 | } |
| 1002 | |
| 1003 | virtual ~StopInfoThreadPlan () |
| 1004 | { |
| 1005 | } |
| 1006 | |
| 1007 | virtual StopReason |
| 1008 | GetStopReason () const |
| 1009 | { |
| 1010 | return eStopReasonPlanComplete; |
| 1011 | } |
| 1012 | |
| 1013 | virtual const char * |
| 1014 | GetDescription () |
| 1015 | { |
| 1016 | if (m_description.empty()) |
| 1017 | { |
| 1018 | StreamString strm; |
| 1019 | m_plan_sp->GetDescription (&strm, eDescriptionLevelBrief); |
| 1020 | m_description.swap (strm.GetString()); |
| 1021 | } |
| 1022 | return m_description.c_str(); |
| 1023 | } |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1024 | |
| 1025 | ValueObjectSP |
| 1026 | GetReturnValueObject() |
| 1027 | { |
| 1028 | return m_return_valobj_sp; |
| 1029 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 1030 | |
| 1031 | protected: |
| 1032 | virtual bool |
| 1033 | ShouldStop (Event *event_ptr) |
| 1034 | { |
| 1035 | if (m_plan_sp) |
| 1036 | return m_plan_sp->ShouldStop(event_ptr); |
| 1037 | else |
| 1038 | return StopInfo::ShouldStop(event_ptr); |
| 1039 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1040 | |
| 1041 | private: |
| 1042 | ThreadPlanSP m_plan_sp; |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1043 | ValueObjectSP m_return_valobj_sp; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1044 | }; |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1045 | |
| 1046 | class StopInfoExec : public StopInfo |
| 1047 | { |
| 1048 | public: |
| 1049 | |
| 1050 | StopInfoExec (Thread &thread) : |
| 1051 | StopInfo (thread, LLDB_INVALID_UID), |
| 1052 | m_performed_action (false) |
| 1053 | { |
| 1054 | } |
| 1055 | |
| 1056 | virtual |
| 1057 | ~StopInfoExec () |
| 1058 | { |
| 1059 | } |
| 1060 | |
| 1061 | virtual StopReason |
| 1062 | GetStopReason () const |
| 1063 | { |
| 1064 | return eStopReasonExec; |
| 1065 | } |
| 1066 | |
| 1067 | virtual const char * |
| 1068 | GetDescription () |
| 1069 | { |
| 1070 | return "exec"; |
| 1071 | } |
| 1072 | protected: |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1073 | |
| 1074 | virtual void |
| 1075 | PerformAction (Event *event_ptr) |
| 1076 | { |
| 1077 | // Only perform the action once |
| 1078 | if (m_performed_action) |
| 1079 | return; |
| 1080 | m_performed_action = true; |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 1081 | ThreadSP thread_sp (m_thread_wp.lock()); |
| 1082 | if (thread_sp) |
| 1083 | thread_sp->GetProcess()->DidExec(); |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | bool m_performed_action; |
| 1087 | }; |
| 1088 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1089 | } // namespace lldb_private |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1090 | |
| 1091 | StopInfoSP |
| 1092 | StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id) |
| 1093 | { |
| 1094 | return StopInfoSP (new StopInfoBreakpoint (thread, break_id)); |
| 1095 | } |
| 1096 | |
| 1097 | StopInfoSP |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1098 | StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id, bool should_stop) |
| 1099 | { |
| 1100 | return StopInfoSP (new StopInfoBreakpoint (thread, break_id, should_stop)); |
| 1101 | } |
| 1102 | |
| 1103 | StopInfoSP |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1104 | StopInfo::CreateStopReasonWithWatchpointID (Thread &thread, break_id_t watch_id) |
| 1105 | { |
| 1106 | return StopInfoSP (new StopInfoWatchpoint (thread, watch_id)); |
| 1107 | } |
| 1108 | |
| 1109 | StopInfoSP |
| 1110 | StopInfo::CreateStopReasonWithSignal (Thread &thread, int signo) |
| 1111 | { |
| 1112 | return StopInfoSP (new StopInfoUnixSignal (thread, signo)); |
| 1113 | } |
| 1114 | |
| 1115 | StopInfoSP |
| 1116 | StopInfo::CreateStopReasonToTrace (Thread &thread) |
| 1117 | { |
| 1118 | return StopInfoSP (new StopInfoTrace (thread)); |
| 1119 | } |
| 1120 | |
| 1121 | StopInfoSP |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1122 | StopInfo::CreateStopReasonWithPlan (ThreadPlanSP &plan_sp, ValueObjectSP return_valobj_sp) |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1123 | { |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1124 | return StopInfoSP (new StopInfoThreadPlan (plan_sp, return_valobj_sp)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1125 | } |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 1126 | |
| 1127 | StopInfoSP |
| 1128 | StopInfo::CreateStopReasonWithException (Thread &thread, const char *description) |
| 1129 | { |
| 1130 | return StopInfoSP (new StopInfoException (thread, description)); |
| 1131 | } |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1132 | |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1133 | StopInfoSP |
| 1134 | StopInfo::CreateStopReasonWithExec (Thread &thread) |
| 1135 | { |
| 1136 | return StopInfoSP (new StopInfoExec (thread)); |
| 1137 | } |
| 1138 | |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1139 | ValueObjectSP |
| 1140 | StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp) |
| 1141 | { |
| 1142 | if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete) |
| 1143 | { |
| 1144 | StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get()); |
| 1145 | return plan_stop_info->GetReturnValueObject(); |
| 1146 | } |
| 1147 | else |
| 1148 | return ValueObjectSP(); |
| 1149 | } |