blob: 4e089d42c05a36d312033a683389c55c1eda63df [file] [log] [blame]
Greg Clayton643ee732010-08-04 01:40:35 +00001//===-- 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
10#include "lldb/Target/StopInfo.h"
11
12// C Includes
13// C++ Includes
14#include <string>
15
16// Other libraries and framework includes
17// Project includes
18#include "lldb/Core/Log.h"
Greg Clayton640dc6b2010-11-18 18:52:36 +000019#include "lldb/Breakpoint/Breakpoint.h"
Greg Clayton643ee732010-08-04 01:40:35 +000020#include "lldb/Breakpoint/BreakpointLocation.h"
21#include "lldb/Breakpoint/StoppointCallbackContext.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000022#include "lldb/Breakpoint/Watchpoint.h"
Jim Ingham21f37ad2011-08-09 02:12:22 +000023#include "lldb/Core/Debugger.h"
Greg Clayton643ee732010-08-04 01:40:35 +000024#include "lldb/Core/StreamString.h"
Jim Ingham21f37ad2011-08-09 02:12:22 +000025#include "lldb/Expression/ClangUserExpression.h"
26#include "lldb/Target/Target.h"
Greg Clayton643ee732010-08-04 01:40:35 +000027#include "lldb/Target/Thread.h"
28#include "lldb/Target/ThreadPlan.h"
29#include "lldb/Target/Process.h"
30#include "lldb/Target/UnixSignals.h"
31
32using namespace lldb;
33using namespace lldb_private;
34
35StopInfo::StopInfo (Thread &thread, uint64_t value) :
36 m_thread (thread),
37 m_stop_id (thread.GetProcess().GetStopID()),
Jim Ingham0296fe72011-11-08 03:00:11 +000038 m_resume_id (thread.GetProcess().GetResumeID()),
Greg Clayton643ee732010-08-04 01:40:35 +000039 m_value (value)
40{
41}
42
43bool
44StopInfo::IsValid () const
45{
46 return m_thread.GetProcess().GetStopID() == m_stop_id;
47}
48
Jim Ingham15dcb7c2011-01-20 02:03:18 +000049void
50StopInfo::MakeStopInfoValid ()
51{
52 m_stop_id = m_thread.GetProcess().GetStopID();
Jim Ingham0296fe72011-11-08 03:00:11 +000053 m_resume_id = m_thread.GetProcess().GetResumeID();
Jim Ingham15dcb7c2011-01-20 02:03:18 +000054}
55
Jim Ingham0296fe72011-11-08 03:00:11 +000056bool
57StopInfo::HasTargetRunSinceMe ()
Jim Ingham21f37ad2011-08-09 02:12:22 +000058{
Jim Ingham0296fe72011-11-08 03:00:11 +000059 lldb::StateType ret_type = m_thread.GetProcess().GetPrivateState();
60 if (ret_type == eStateRunning)
61 {
62 return true;
63 }
64 else if (ret_type == eStateStopped)
65 {
66 // This is a little tricky. We want to count "run and stopped again before you could
67 // ask this question as a "TRUE" answer to HasTargetRunSinceMe. But we don't want to
68 // include any running of the target done for expressions. So we track both resumes,
69 // and resumes caused by expressions, and check if there are any resumes NOT caused
70 // by expressions.
71
72 uint32_t curr_resume_id = m_thread.GetProcess().GetResumeID();
73 uint32_t last_user_expression_id = m_thread.GetProcess().GetLastUserExpressionResumeID ();
74 if (curr_resume_id == m_resume_id)
75 {
76 return false;
77 }
78 else if (curr_resume_id > last_user_expression_id)
79 {
80 return true;
81 }
82 }
83 return false;
Jim Ingham21f37ad2011-08-09 02:12:22 +000084}
85
Greg Clayton643ee732010-08-04 01:40:35 +000086//----------------------------------------------------------------------
87// StopInfoBreakpoint
88//----------------------------------------------------------------------
89
Jim Ingham21f37ad2011-08-09 02:12:22 +000090namespace lldb_private
91{
Greg Clayton643ee732010-08-04 01:40:35 +000092class StopInfoBreakpoint : public StopInfo
93{
94public:
95
96 StopInfoBreakpoint (Thread &thread, break_id_t break_id) :
97 StopInfo (thread, break_id),
98 m_description(),
99 m_should_stop (false),
Jim Inghamf9f40c22011-02-08 05:20:59 +0000100 m_should_stop_is_valid (false),
Jim Ingham1c658532011-10-28 01:12:19 +0000101 m_should_perform_action (true),
102 m_address (LLDB_INVALID_ADDRESS)
Greg Clayton643ee732010-08-04 01:40:35 +0000103 {
Jim Ingham1c658532011-10-28 01:12:19 +0000104 BreakpointSiteSP bp_site_sp (m_thread.GetProcess().GetBreakpointSiteList().FindByID (m_value));
105 if (bp_site_sp)
106 {
107 m_address = bp_site_sp->GetLoadAddress();
108 }
Greg Clayton643ee732010-08-04 01:40:35 +0000109 }
110
Jim Inghamd1686902010-10-14 23:45:03 +0000111 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 Inghamf9f40c22011-02-08 05:20:59 +0000115 m_should_stop_is_valid (true),
Jim Ingham1c658532011-10-28 01:12:19 +0000116 m_should_perform_action (true),
117 m_address (LLDB_INVALID_ADDRESS)
Jim Inghamd1686902010-10-14 23:45:03 +0000118 {
Jim Ingham1c658532011-10-28 01:12:19 +0000119 BreakpointSiteSP bp_site_sp (m_thread.GetProcess().GetBreakpointSiteList().FindByID (m_value));
120 if (bp_site_sp)
121 {
122 m_address = bp_site_sp->GetLoadAddress();
123 }
Jim Inghamd1686902010-10-14 23:45:03 +0000124 }
125
Greg Clayton643ee732010-08-04 01:40:35 +0000126 virtual ~StopInfoBreakpoint ()
127 {
128 }
129
130 virtual StopReason
131 GetStopReason () const
132 {
133 return eStopReasonBreakpoint;
134 }
135
136 virtual bool
137 ShouldStop (Event *event_ptr)
138 {
139 if (!m_should_stop_is_valid)
140 {
141 // Only check once if we should stop at a breakpoint
142 BreakpointSiteSP bp_site_sp (m_thread.GetProcess().GetBreakpointSiteList().FindByID (m_value));
143 if (bp_site_sp)
144 {
145 StoppointCallbackContext context (event_ptr,
146 &m_thread.GetProcess(),
147 &m_thread,
148 m_thread.GetStackFrameAtIndex(0).get(),
Jim Ingham7508e732010-08-09 23:31:02 +0000149 true);
Greg Clayton643ee732010-08-04 01:40:35 +0000150
151 m_should_stop = bp_site_sp->ShouldStop (&context);
152 }
153 else
154 {
Greg Claytone005f2c2010-11-06 01:53:30 +0000155 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Greg Clayton643ee732010-08-04 01:40:35 +0000156
157 if (log)
158 log->Printf ("Process::%s could not find breakpoint site id: %lld...", __FUNCTION__, m_value);
159
160 m_should_stop = true;
161 }
162 m_should_stop_is_valid = true;
163 }
164 return m_should_stop;
165 }
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000166
167 virtual void
168 PerformAction (Event *event_ptr)
169 {
Jim Inghamf9f40c22011-02-08 05:20:59 +0000170 if (!m_should_perform_action)
171 return;
172 m_should_perform_action = false;
173
Jim Ingham21f37ad2011-08-09 02:12:22 +0000174 LogSP log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
Jim Ingham21f37ad2011-08-09 02:12:22 +0000175
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000176 BreakpointSiteSP bp_site_sp (m_thread.GetProcess().GetBreakpointSiteList().FindByID (m_value));
Jim Ingham982a6ca2011-12-09 04:17:31 +0000177
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000178 if (bp_site_sp)
179 {
180 size_t num_owners = bp_site_sp->GetNumberOfOwners();
Jim Ingham982a6ca2011-12-09 04:17:31 +0000181
182 if (num_owners == 0)
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000183 {
Jim Ingham982a6ca2011-12-09 04:17:31 +0000184 m_should_stop = true;
185 }
186 else
187 {
188 // We go through each location, and test first its condition. If the condition says to stop,
189 // then we run the callback for that location. If that callback says to stop as well, then
190 // we set m_should_stop to true; we are going to stop.
191 // But we still want to give all the breakpoints whose conditions say we are going to stop a
192 // chance to run their callbacks.
193 // Of course if any callback restarts the target by putting "continue" in the callback, then
194 // we're going to restart, without running the rest of the callbacks. And in this case we will
195 // end up not stopping even if another location said we should stop. But that's better than not
196 // running all the callbacks.
197
198 m_should_stop = false;
199
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000200 StoppointCallbackContext context (event_ptr,
201 &m_thread.GetProcess(),
202 &m_thread,
203 m_thread.GetStackFrameAtIndex(0).get(),
204 false);
Jim Ingham21f37ad2011-08-09 02:12:22 +0000205
Jim Ingham21f37ad2011-08-09 02:12:22 +0000206 for (size_t j = 0; j < num_owners; j++)
207 {
208 lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j);
Jim Ingham982a6ca2011-12-09 04:17:31 +0000209
210 // First run the condition for the breakpoint. If that says we should stop, then we'll run
211 // the callback for the breakpoint. If the callback says we shouldn't stop that will win.
212
213 bool condition_says_stop = true;
Jim Ingham21f37ad2011-08-09 02:12:22 +0000214 if (bp_loc_sp->GetConditionText() != NULL)
215 {
216 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
217 // constructor errors up to the debugger's Async I/O.
218
Jim Ingham21f37ad2011-08-09 02:12:22 +0000219 ValueObjectSP result_valobj_sp;
220
221 ExecutionResults result_code;
222 ValueObjectSP result_value_sp;
223 const bool discard_on_error = true;
224 Error error;
225 result_code = ClangUserExpression::EvaluateWithError (context.exe_ctx,
Sean Callanan47dc4572011-09-15 02:13:07 +0000226 eExecutionPolicyAlways,
Sean Callanan5b658cc2011-11-07 23:35:40 +0000227 lldb::eLanguageTypeUnknown,
Sean Callanan47dc4572011-09-15 02:13:07 +0000228 discard_on_error,
229 bp_loc_sp->GetConditionText(),
230 NULL,
231 result_value_sp,
232 error);
Jim Ingham21f37ad2011-08-09 02:12:22 +0000233 if (result_code == eExecutionCompleted)
234 {
235 if (result_value_sp)
236 {
237 Scalar scalar_value;
238 if (result_value_sp->ResolveValue (scalar_value))
239 {
240 if (scalar_value.ULongLong(1) == 0)
Jim Ingham982a6ca2011-12-09 04:17:31 +0000241 condition_says_stop = false;
Jim Ingham21f37ad2011-08-09 02:12:22 +0000242 else
Jim Ingham982a6ca2011-12-09 04:17:31 +0000243 condition_says_stop = true;
Jim Ingham21f37ad2011-08-09 02:12:22 +0000244 if (log)
245 log->Printf("Condition successfully evaluated, result is %s.\n",
246 m_should_stop ? "true" : "false");
247 }
248 else
249 {
Jim Ingham982a6ca2011-12-09 04:17:31 +0000250 condition_says_stop = true;
Jim Ingham21f37ad2011-08-09 02:12:22 +0000251 if (log)
252 log->Printf("Failed to get an integer result from the expression.");
253 }
254 }
255 }
256 else
257 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000258 Debugger &debugger = context.exe_ctx.GetTargetRef().GetDebugger();
Jim Ingham21f37ad2011-08-09 02:12:22 +0000259 StreamSP error_sp = debugger.GetAsyncErrorStream ();
260 error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint ");
261 bp_loc_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
262 error_sp->Printf (": \"%s\"",
263 bp_loc_sp->GetConditionText());
264 error_sp->EOL();
265 const char *err_str = error.AsCString("<Unknown Error>");
266 if (log)
267 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
268
269 error_sp->PutCString (err_str);
270 error_sp->EOL();
271 error_sp->Flush();
272 // If the condition fails to be parsed or run, we should stop.
Jim Ingham982a6ca2011-12-09 04:17:31 +0000273 condition_says_stop = true;
Jim Ingham21f37ad2011-08-09 02:12:22 +0000274 }
275 }
276
Jim Ingham982a6ca2011-12-09 04:17:31 +0000277 // If this location's condition says we should aren't going to stop,
278 // then don't run the callback for this location.
279 if (!condition_says_stop)
280 continue;
281
282 bool callback_says_stop;
283
284 // FIXME: For now the callbacks have to run in async mode - the first time we restart we need
285 // to get out of there. So set it here.
286 // When we figure out how to nest breakpoint hits then this will change.
287
288 Debugger &debugger = m_thread.GetProcess().GetTarget().GetDebugger();
289 bool old_async = debugger.GetAsyncExecution();
290 debugger.SetAsyncExecution (true);
291
292 callback_says_stop = bp_loc_sp->InvokeCallback (&context);
293
294 debugger.SetAsyncExecution (old_async);
295
296 if (callback_says_stop)
297 m_should_stop = true;
298
299 // Also make sure that the callback hasn't continued the target.
300 // If it did, when we'll set m_should_start to false and get out of here.
301 if (HasTargetRunSinceMe ())
302 {
303 m_should_stop = false;
Jim Ingham21f37ad2011-08-09 02:12:22 +0000304 break;
Jim Ingham982a6ca2011-12-09 04:17:31 +0000305 }
Jim Ingham21f37ad2011-08-09 02:12:22 +0000306 }
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000307 }
Jim Ingham982a6ca2011-12-09 04:17:31 +0000308 // We've figured out what this stop wants to do, so mark it as valid so we don't compute it again.
309 m_should_stop_is_valid = true;
310
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000311 }
312 else
313 {
Jim Ingham982a6ca2011-12-09 04:17:31 +0000314 m_should_stop = true;
315 m_should_stop_is_valid = true;
Greg Claytone005f2c2010-11-06 01:53:30 +0000316 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000317
318 if (log)
319 log->Printf ("Process::%s could not find breakpoint site id: %lld...", __FUNCTION__, m_value);
320 }
Jim Ingham21f37ad2011-08-09 02:12:22 +0000321 if (log)
322 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000323 }
Greg Clayton643ee732010-08-04 01:40:35 +0000324
325 virtual bool
326 ShouldNotify (Event *event_ptr)
327 {
328 BreakpointSiteSP bp_site_sp (m_thread.GetProcess().GetBreakpointSiteList().FindByID (m_value));
329 if (bp_site_sp)
330 {
331 bool all_internal = true;
332
333 for (uint32_t i = 0; i < bp_site_sp->GetNumberOfOwners(); i++)
334 {
335 if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal())
336 {
337 all_internal = false;
338 break;
339 }
340 }
341 return all_internal == false;
342 }
343 return true;
344 }
345
346 virtual const char *
347 GetDescription ()
348 {
349 if (m_description.empty())
350 {
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000351 BreakpointSiteSP bp_site_sp (m_thread.GetProcess().GetBreakpointSiteList().FindByID (m_value));
352 if (bp_site_sp)
353 {
354 StreamString strm;
355 strm.Printf("breakpoint ");
356 bp_site_sp->GetDescription(&strm, eDescriptionLevelBrief);
357 m_description.swap (strm.GetString());
358 }
359 else
360 {
361 StreamString strm;
Jim Ingham1c658532011-10-28 01:12:19 +0000362 if (m_address == LLDB_INVALID_ADDRESS)
363 strm.Printf("breakpoint site %lli which has been deleted - unknown address", m_value);
364 else
365 strm.Printf("breakpoint site %lli which has been deleted - was at 0x%llx", m_value, m_address);
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000366 m_description.swap (strm.GetString());
367 }
Greg Clayton643ee732010-08-04 01:40:35 +0000368 }
369 return m_description.c_str();
370 }
371
372private:
373 std::string m_description;
374 bool m_should_stop;
375 bool m_should_stop_is_valid;
Jim Inghamf9f40c22011-02-08 05:20:59 +0000376 bool m_should_perform_action; // Since we are trying to preserve the "state" of the system even if we run functions
377 // etc. behind the users backs, we need to make sure we only REALLY perform the action once.
Jim Ingham1c658532011-10-28 01:12:19 +0000378 lldb::addr_t m_address; // We use this to capture the breakpoint site address when we create the StopInfo,
379 // in case somebody deletes it between the time the StopInfo is made and the
380 // description is asked for.
Greg Clayton643ee732010-08-04 01:40:35 +0000381};
382
383
384//----------------------------------------------------------------------
385// StopInfoWatchpoint
386//----------------------------------------------------------------------
387
388class StopInfoWatchpoint : public StopInfo
389{
390public:
391
392 StopInfoWatchpoint (Thread &thread, break_id_t watch_id) :
Johnny Chen043f8c22011-09-21 22:47:15 +0000393 StopInfo(thread, watch_id),
394 m_description(),
395 m_should_stop(false),
396 m_should_stop_is_valid(false)
Greg Clayton643ee732010-08-04 01:40:35 +0000397 {
398 }
399
400 virtual ~StopInfoWatchpoint ()
401 {
402 }
403
404 virtual StopReason
405 GetStopReason () const
406 {
407 return eStopReasonWatchpoint;
408 }
409
Johnny Chen043f8c22011-09-21 22:47:15 +0000410 virtual bool
411 ShouldStop (Event *event_ptr)
412 {
413 // ShouldStop() method is idempotent and should not affect hit count.
Johnny Chen712a6282011-10-17 18:58:00 +0000414 // See Process::RunPrivateStateThread()->Process()->HandlePrivateEvent()
415 // -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()->
416 // Thread::ShouldStop()->ThreadPlanBase::ShouldStop()->
417 // StopInfoWatchpoint::ShouldStop() and
418 // Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()->
419 // StopInfoWatchpoint::PerformAction().
Johnny Chen043f8c22011-09-21 22:47:15 +0000420 if (m_should_stop_is_valid)
421 return m_should_stop;
422
Johnny Chenecd4feb2011-10-14 00:42:25 +0000423 WatchpointSP wp_sp =
424 m_thread.GetProcess().GetTarget().GetWatchpointList().FindByID(GetValue());
425 if (wp_sp)
Johnny Chen043f8c22011-09-21 22:47:15 +0000426 {
427 // Check if we should stop at a watchpoint.
428 StoppointCallbackContext context (event_ptr,
429 &m_thread.GetProcess(),
430 &m_thread,
431 m_thread.GetStackFrameAtIndex(0).get(),
432 true);
433
Johnny Chenecd4feb2011-10-14 00:42:25 +0000434 m_should_stop = wp_sp->ShouldStop (&context);
Johnny Chen043f8c22011-09-21 22:47:15 +0000435 }
436 else
437 {
438 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
439
440 if (log)
441 log->Printf ("Process::%s could not find watchpoint location id: %lld...",
442 __FUNCTION__, GetValue());
443
444 m_should_stop = true;
445 }
446 m_should_stop_is_valid = true;
447 return m_should_stop;
448 }
449
Johnny Chen712a6282011-10-17 18:58:00 +0000450 // Perform any action that is associated with this stop. This is done as the
451 // Event is removed from the event queue.
452 virtual void
453 PerformAction (Event *event_ptr)
454 {
455 LogSP log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
456 // We're going to calculate if we should stop or not in some way during the course of
457 // this code. Also by default we're going to stop, so set that here.
458 m_should_stop = true;
459
460 WatchpointSP wp_sp =
461 m_thread.GetProcess().GetTarget().GetWatchpointList().FindByID(GetValue());
462 if (wp_sp)
463 {
464 StoppointCallbackContext context (event_ptr,
465 &m_thread.GetProcess(),
466 &m_thread,
467 m_thread.GetStackFrameAtIndex(0).get(),
468 false);
469 bool stop_requested = wp_sp->InvokeCallback (&context);
470 // Also make sure that the callback hasn't continued the target.
471 // If it did, when we'll set m_should_start to false and get out of here.
Jim Ingham0296fe72011-11-08 03:00:11 +0000472 if (HasTargetRunSinceMe ())
Johnny Chen712a6282011-10-17 18:58:00 +0000473 m_should_stop = false;
474
475 if (m_should_stop && !stop_requested)
476 {
477 // We have been vetoed.
478 m_should_stop = false;
479 }
480
481 if (m_should_stop && wp_sp->GetConditionText() != NULL)
482 {
483 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
484 // constructor errors up to the debugger's Async I/O.
485 StoppointCallbackContext context (event_ptr,
486 &m_thread.GetProcess(),
487 &m_thread,
488 m_thread.GetStackFrameAtIndex(0).get(),
489 false);
490 ExecutionResults result_code;
491 ValueObjectSP result_value_sp;
492 const bool discard_on_error = true;
493 Error error;
494 result_code = ClangUserExpression::EvaluateWithError (context.exe_ctx,
495 eExecutionPolicyAlways,
Sean Callanan5b658cc2011-11-07 23:35:40 +0000496 lldb::eLanguageTypeUnknown,
Johnny Chen712a6282011-10-17 18:58:00 +0000497 discard_on_error,
498 wp_sp->GetConditionText(),
499 NULL,
500 result_value_sp,
501 error);
502 if (result_code == eExecutionCompleted)
503 {
504 if (result_value_sp)
505 {
506 Scalar scalar_value;
507 if (result_value_sp->ResolveValue (scalar_value))
508 {
509 if (scalar_value.ULongLong(1) == 0)
510 {
511 // We have been vetoed. This takes precedence over querying
512 // the watchpoint whether it should stop (aka ignore count and
513 // friends). See also StopInfoWatchpoint::ShouldStop() as well
514 // as Process::ProcessEventData::DoOnRemoval().
515 m_should_stop = false;
516 }
517 else
518 m_should_stop = true;
519 if (log)
520 log->Printf("Condition successfully evaluated, result is %s.\n",
521 m_should_stop ? "true" : "false");
522 }
523 else
524 {
525 m_should_stop = true;
526 if (log)
527 log->Printf("Failed to get an integer result from the expression.");
528 }
529 }
530 }
531 else
532 {
533 Debugger &debugger = context.exe_ctx.GetTargetRef().GetDebugger();
534 StreamSP error_sp = debugger.GetAsyncErrorStream ();
535 error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint ");
536 wp_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
537 error_sp->Printf (": \"%s\"",
538 wp_sp->GetConditionText());
539 error_sp->EOL();
540 const char *err_str = error.AsCString("<Unknown Error>");
541 if (log)
542 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
543
544 error_sp->PutCString (err_str);
545 error_sp->EOL();
546 error_sp->Flush();
547 // If the condition fails to be parsed or run, we should stop.
548 m_should_stop = true;
549 }
550 }
551 }
552 else
553 {
554 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
555
556 if (log)
557 log->Printf ("Process::%s could not find watchpoint id: %lld...", __FUNCTION__, m_value);
558 }
559 if (log)
560 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
561 }
562
Greg Clayton643ee732010-08-04 01:40:35 +0000563 virtual const char *
564 GetDescription ()
565 {
566 if (m_description.empty())
567 {
568 StreamString strm;
569 strm.Printf("watchpoint %lli", m_value);
570 m_description.swap (strm.GetString());
571 }
572 return m_description.c_str();
573 }
574
Greg Clayton643ee732010-08-04 01:40:35 +0000575private:
576 std::string m_description;
Johnny Chen043f8c22011-09-21 22:47:15 +0000577 bool m_should_stop;
578 bool m_should_stop_is_valid;
Greg Clayton643ee732010-08-04 01:40:35 +0000579};
580
581
582
583//----------------------------------------------------------------------
584// StopInfoUnixSignal
585//----------------------------------------------------------------------
586
587class StopInfoUnixSignal : public StopInfo
588{
589public:
590
591 StopInfoUnixSignal (Thread &thread, int signo) :
Greg Clayton65611552011-06-04 01:26:29 +0000592 StopInfo (thread, signo)
Greg Clayton643ee732010-08-04 01:40:35 +0000593 {
594 }
595
596 virtual ~StopInfoUnixSignal ()
597 {
598 }
599
600
601 virtual StopReason
602 GetStopReason () const
603 {
604 return eStopReasonSignal;
605 }
606
607 virtual bool
608 ShouldStop (Event *event_ptr)
609 {
610 return m_thread.GetProcess().GetUnixSignals().GetShouldStop (m_value);
611 }
612
613
614 // If should stop returns false, check if we should notify of this event
615 virtual bool
616 ShouldNotify (Event *event_ptr)
617 {
618 return m_thread.GetProcess().GetUnixSignals().GetShouldNotify (m_value);
619 }
620
621
622 virtual void
623 WillResume (lldb::StateType resume_state)
624 {
625 if (m_thread.GetProcess().GetUnixSignals().GetShouldSuppress(m_value) == false)
626 m_thread.SetResumeSignal(m_value);
627 }
628
629 virtual const char *
630 GetDescription ()
631 {
632 if (m_description.empty())
633 {
634 StreamString strm;
635 const char *signal_name = m_thread.GetProcess().GetUnixSignals().GetSignalAsCString (m_value);
636 if (signal_name)
Greg Claytona830adb2010-10-04 01:05:56 +0000637 strm.Printf("signal %s", signal_name);
Greg Clayton643ee732010-08-04 01:40:35 +0000638 else
Greg Claytona830adb2010-10-04 01:05:56 +0000639 strm.Printf("signal %lli", m_value);
Greg Clayton643ee732010-08-04 01:40:35 +0000640 m_description.swap (strm.GetString());
641 }
642 return m_description.c_str();
643 }
Greg Clayton643ee732010-08-04 01:40:35 +0000644};
645
646//----------------------------------------------------------------------
647// StopInfoTrace
648//----------------------------------------------------------------------
649
650class StopInfoTrace : public StopInfo
651{
652public:
653
654 StopInfoTrace (Thread &thread) :
655 StopInfo (thread, LLDB_INVALID_UID)
656 {
657 }
658
659 virtual ~StopInfoTrace ()
660 {
661 }
662
663 virtual StopReason
664 GetStopReason () const
665 {
666 return eStopReasonTrace;
667 }
668
669 virtual const char *
670 GetDescription ()
671 {
Greg Clayton65611552011-06-04 01:26:29 +0000672 if (m_description.empty())
Greg Clayton643ee732010-08-04 01:40:35 +0000673 return "trace";
Greg Clayton65611552011-06-04 01:26:29 +0000674 else
675 return m_description.c_str();
676 }
677};
678
679
680//----------------------------------------------------------------------
681// StopInfoException
682//----------------------------------------------------------------------
683
684class StopInfoException : public StopInfo
685{
686public:
687
688 StopInfoException (Thread &thread, const char *description) :
689 StopInfo (thread, LLDB_INVALID_UID)
690 {
691 if (description)
692 SetDescription (description);
693 }
694
695 virtual
696 ~StopInfoException ()
697 {
698 }
699
700 virtual StopReason
701 GetStopReason () const
702 {
703 return eStopReasonException;
704 }
705
706 virtual const char *
707 GetDescription ()
708 {
709 if (m_description.empty())
710 return "exception";
711 else
712 return m_description.c_str();
Greg Clayton643ee732010-08-04 01:40:35 +0000713 }
714};
715
716
717//----------------------------------------------------------------------
718// StopInfoThreadPlan
719//----------------------------------------------------------------------
720
721class StopInfoThreadPlan : public StopInfo
722{
723public:
724
725 StopInfoThreadPlan (ThreadPlanSP &plan_sp) :
726 StopInfo (plan_sp->GetThread(), LLDB_INVALID_UID),
727 m_plan_sp (plan_sp)
728 {
729 }
730
731 virtual ~StopInfoThreadPlan ()
732 {
733 }
734
735 virtual StopReason
736 GetStopReason () const
737 {
738 return eStopReasonPlanComplete;
739 }
740
741 virtual const char *
742 GetDescription ()
743 {
744 if (m_description.empty())
745 {
746 StreamString strm;
747 m_plan_sp->GetDescription (&strm, eDescriptionLevelBrief);
748 m_description.swap (strm.GetString());
749 }
750 return m_description.c_str();
751 }
752
753private:
754 ThreadPlanSP m_plan_sp;
Greg Clayton643ee732010-08-04 01:40:35 +0000755};
Jim Ingham21f37ad2011-08-09 02:12:22 +0000756} // namespace lldb_private
Greg Clayton643ee732010-08-04 01:40:35 +0000757
758StopInfoSP
759StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id)
760{
761 return StopInfoSP (new StopInfoBreakpoint (thread, break_id));
762}
763
764StopInfoSP
Jim Inghamd1686902010-10-14 23:45:03 +0000765StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id, bool should_stop)
766{
767 return StopInfoSP (new StopInfoBreakpoint (thread, break_id, should_stop));
768}
769
770StopInfoSP
Greg Clayton643ee732010-08-04 01:40:35 +0000771StopInfo::CreateStopReasonWithWatchpointID (Thread &thread, break_id_t watch_id)
772{
773 return StopInfoSP (new StopInfoWatchpoint (thread, watch_id));
774}
775
776StopInfoSP
777StopInfo::CreateStopReasonWithSignal (Thread &thread, int signo)
778{
779 return StopInfoSP (new StopInfoUnixSignal (thread, signo));
780}
781
782StopInfoSP
783StopInfo::CreateStopReasonToTrace (Thread &thread)
784{
785 return StopInfoSP (new StopInfoTrace (thread));
786}
787
788StopInfoSP
789StopInfo::CreateStopReasonWithPlan (ThreadPlanSP &plan_sp)
790{
791 return StopInfoSP (new StopInfoThreadPlan (plan_sp));
792}
Greg Clayton65611552011-06-04 01:26:29 +0000793
794StopInfoSP
795StopInfo::CreateStopReasonWithException (Thread &thread, const char *description)
796{
797 return StopInfoSP (new StopInfoException (thread, description));
798}