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