blob: 00c76802922722d63b6e485653428c0cf61c1fac [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 Callanandaa6efe2011-12-21 22:22:58 +0000228 ClangUserExpression::eResultTypeAny,
Sean Callanan47dc4572011-09-15 02:13:07 +0000229 discard_on_error,
230 bp_loc_sp->GetConditionText(),
231 NULL,
232 result_value_sp,
233 error);
Jim Ingham21f37ad2011-08-09 02:12:22 +0000234 if (result_code == eExecutionCompleted)
235 {
236 if (result_value_sp)
237 {
238 Scalar scalar_value;
239 if (result_value_sp->ResolveValue (scalar_value))
240 {
241 if (scalar_value.ULongLong(1) == 0)
Jim Ingham982a6ca2011-12-09 04:17:31 +0000242 condition_says_stop = false;
Jim Ingham21f37ad2011-08-09 02:12:22 +0000243 else
Jim Ingham982a6ca2011-12-09 04:17:31 +0000244 condition_says_stop = true;
Jim Ingham21f37ad2011-08-09 02:12:22 +0000245 if (log)
246 log->Printf("Condition successfully evaluated, result is %s.\n",
247 m_should_stop ? "true" : "false");
248 }
249 else
250 {
Jim Ingham982a6ca2011-12-09 04:17:31 +0000251 condition_says_stop = true;
Jim Ingham21f37ad2011-08-09 02:12:22 +0000252 if (log)
253 log->Printf("Failed to get an integer result from the expression.");
254 }
255 }
256 }
257 else
258 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000259 Debugger &debugger = context.exe_ctx.GetTargetRef().GetDebugger();
Jim Ingham21f37ad2011-08-09 02:12:22 +0000260 StreamSP error_sp = debugger.GetAsyncErrorStream ();
261 error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint ");
262 bp_loc_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
263 error_sp->Printf (": \"%s\"",
264 bp_loc_sp->GetConditionText());
265 error_sp->EOL();
266 const char *err_str = error.AsCString("<Unknown Error>");
267 if (log)
268 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
269
270 error_sp->PutCString (err_str);
271 error_sp->EOL();
272 error_sp->Flush();
273 // If the condition fails to be parsed or run, we should stop.
Jim Ingham982a6ca2011-12-09 04:17:31 +0000274 condition_says_stop = true;
Jim Ingham21f37ad2011-08-09 02:12:22 +0000275 }
276 }
277
Jim Ingham982a6ca2011-12-09 04:17:31 +0000278 // If this location's condition says we should aren't going to stop,
279 // then don't run the callback for this location.
280 if (!condition_says_stop)
281 continue;
282
283 bool callback_says_stop;
284
285 // FIXME: For now the callbacks have to run in async mode - the first time we restart we need
286 // to get out of there. So set it here.
287 // When we figure out how to nest breakpoint hits then this will change.
288
289 Debugger &debugger = m_thread.GetProcess().GetTarget().GetDebugger();
290 bool old_async = debugger.GetAsyncExecution();
291 debugger.SetAsyncExecution (true);
292
293 callback_says_stop = bp_loc_sp->InvokeCallback (&context);
294
295 debugger.SetAsyncExecution (old_async);
296
297 if (callback_says_stop)
298 m_should_stop = true;
299
300 // Also make sure that the callback hasn't continued the target.
301 // If it did, when we'll set m_should_start to false and get out of here.
302 if (HasTargetRunSinceMe ())
303 {
304 m_should_stop = false;
Jim Ingham21f37ad2011-08-09 02:12:22 +0000305 break;
Jim Ingham982a6ca2011-12-09 04:17:31 +0000306 }
Jim Ingham21f37ad2011-08-09 02:12:22 +0000307 }
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000308 }
Jim Ingham982a6ca2011-12-09 04:17:31 +0000309 // We've figured out what this stop wants to do, so mark it as valid so we don't compute it again.
310 m_should_stop_is_valid = true;
311
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000312 }
313 else
314 {
Jim Ingham982a6ca2011-12-09 04:17:31 +0000315 m_should_stop = true;
316 m_should_stop_is_valid = true;
Greg Claytone005f2c2010-11-06 01:53:30 +0000317 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000318
319 if (log)
320 log->Printf ("Process::%s could not find breakpoint site id: %lld...", __FUNCTION__, m_value);
321 }
Jim Ingham21f37ad2011-08-09 02:12:22 +0000322 if (log)
323 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000324 }
Greg Clayton643ee732010-08-04 01:40:35 +0000325
326 virtual bool
327 ShouldNotify (Event *event_ptr)
328 {
329 BreakpointSiteSP bp_site_sp (m_thread.GetProcess().GetBreakpointSiteList().FindByID (m_value));
330 if (bp_site_sp)
331 {
332 bool all_internal = true;
333
334 for (uint32_t i = 0; i < bp_site_sp->GetNumberOfOwners(); i++)
335 {
336 if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal())
337 {
338 all_internal = false;
339 break;
340 }
341 }
342 return all_internal == false;
343 }
344 return true;
345 }
346
347 virtual const char *
348 GetDescription ()
349 {
350 if (m_description.empty())
351 {
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000352 BreakpointSiteSP bp_site_sp (m_thread.GetProcess().GetBreakpointSiteList().FindByID (m_value));
353 if (bp_site_sp)
354 {
355 StreamString strm;
356 strm.Printf("breakpoint ");
357 bp_site_sp->GetDescription(&strm, eDescriptionLevelBrief);
358 m_description.swap (strm.GetString());
359 }
360 else
361 {
362 StreamString strm;
Jim Ingham1c658532011-10-28 01:12:19 +0000363 if (m_address == LLDB_INVALID_ADDRESS)
364 strm.Printf("breakpoint site %lli which has been deleted - unknown address", m_value);
365 else
366 strm.Printf("breakpoint site %lli which has been deleted - was at 0x%llx", m_value, m_address);
Jim Ingham6fb8baa2010-08-10 00:59:59 +0000367 m_description.swap (strm.GetString());
368 }
Greg Clayton643ee732010-08-04 01:40:35 +0000369 }
370 return m_description.c_str();
371 }
372
373private:
374 std::string m_description;
375 bool m_should_stop;
376 bool m_should_stop_is_valid;
Jim Inghamf9f40c22011-02-08 05:20:59 +0000377 bool m_should_perform_action; // Since we are trying to preserve the "state" of the system even if we run functions
378 // etc. behind the users backs, we need to make sure we only REALLY perform the action once.
Jim Ingham1c658532011-10-28 01:12:19 +0000379 lldb::addr_t m_address; // We use this to capture the breakpoint site address when we create the StopInfo,
380 // in case somebody deletes it between the time the StopInfo is made and the
381 // description is asked for.
Greg Clayton643ee732010-08-04 01:40:35 +0000382};
383
384
385//----------------------------------------------------------------------
386// StopInfoWatchpoint
387//----------------------------------------------------------------------
388
389class StopInfoWatchpoint : public StopInfo
390{
391public:
392
393 StopInfoWatchpoint (Thread &thread, break_id_t watch_id) :
Johnny Chen043f8c22011-09-21 22:47:15 +0000394 StopInfo(thread, watch_id),
395 m_description(),
396 m_should_stop(false),
397 m_should_stop_is_valid(false)
Greg Clayton643ee732010-08-04 01:40:35 +0000398 {
399 }
400
401 virtual ~StopInfoWatchpoint ()
402 {
403 }
404
405 virtual StopReason
406 GetStopReason () const
407 {
408 return eStopReasonWatchpoint;
409 }
410
Johnny Chen043f8c22011-09-21 22:47:15 +0000411 virtual bool
412 ShouldStop (Event *event_ptr)
413 {
414 // ShouldStop() method is idempotent and should not affect hit count.
Johnny Chen712a6282011-10-17 18:58:00 +0000415 // See Process::RunPrivateStateThread()->Process()->HandlePrivateEvent()
416 // -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()->
417 // Thread::ShouldStop()->ThreadPlanBase::ShouldStop()->
418 // StopInfoWatchpoint::ShouldStop() and
419 // Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()->
420 // StopInfoWatchpoint::PerformAction().
Johnny Chen043f8c22011-09-21 22:47:15 +0000421 if (m_should_stop_is_valid)
422 return m_should_stop;
423
Johnny Chenecd4feb2011-10-14 00:42:25 +0000424 WatchpointSP wp_sp =
425 m_thread.GetProcess().GetTarget().GetWatchpointList().FindByID(GetValue());
426 if (wp_sp)
Johnny Chen043f8c22011-09-21 22:47:15 +0000427 {
428 // Check if we should stop at a watchpoint.
429 StoppointCallbackContext context (event_ptr,
430 &m_thread.GetProcess(),
431 &m_thread,
432 m_thread.GetStackFrameAtIndex(0).get(),
433 true);
434
Johnny Chenecd4feb2011-10-14 00:42:25 +0000435 m_should_stop = wp_sp->ShouldStop (&context);
Johnny Chen043f8c22011-09-21 22:47:15 +0000436 }
437 else
438 {
439 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
440
441 if (log)
442 log->Printf ("Process::%s could not find watchpoint location id: %lld...",
443 __FUNCTION__, GetValue());
444
445 m_should_stop = true;
446 }
447 m_should_stop_is_valid = true;
448 return m_should_stop;
449 }
450
Johnny Chen712a6282011-10-17 18:58:00 +0000451 // Perform any action that is associated with this stop. This is done as the
452 // Event is removed from the event queue.
453 virtual void
454 PerformAction (Event *event_ptr)
455 {
456 LogSP log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
457 // We're going to calculate if we should stop or not in some way during the course of
458 // this code. Also by default we're going to stop, so set that here.
459 m_should_stop = true;
460
461 WatchpointSP wp_sp =
462 m_thread.GetProcess().GetTarget().GetWatchpointList().FindByID(GetValue());
463 if (wp_sp)
464 {
465 StoppointCallbackContext context (event_ptr,
466 &m_thread.GetProcess(),
467 &m_thread,
468 m_thread.GetStackFrameAtIndex(0).get(),
469 false);
470 bool stop_requested = wp_sp->InvokeCallback (&context);
471 // Also make sure that the callback hasn't continued the target.
472 // If it did, when we'll set m_should_start to false and get out of here.
Jim Ingham0296fe72011-11-08 03:00:11 +0000473 if (HasTargetRunSinceMe ())
Johnny Chen712a6282011-10-17 18:58:00 +0000474 m_should_stop = false;
475
476 if (m_should_stop && !stop_requested)
477 {
478 // We have been vetoed.
479 m_should_stop = false;
480 }
481
482 if (m_should_stop && wp_sp->GetConditionText() != NULL)
483 {
484 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
485 // constructor errors up to the debugger's Async I/O.
486 StoppointCallbackContext context (event_ptr,
487 &m_thread.GetProcess(),
488 &m_thread,
489 m_thread.GetStackFrameAtIndex(0).get(),
490 false);
491 ExecutionResults result_code;
492 ValueObjectSP result_value_sp;
493 const bool discard_on_error = true;
494 Error error;
495 result_code = ClangUserExpression::EvaluateWithError (context.exe_ctx,
496 eExecutionPolicyAlways,
Sean Callanan5b658cc2011-11-07 23:35:40 +0000497 lldb::eLanguageTypeUnknown,
Sean Callanandaa6efe2011-12-21 22:22:58 +0000498 ClangUserExpression::eResultTypeAny,
Johnny Chen712a6282011-10-17 18:58:00 +0000499 discard_on_error,
500 wp_sp->GetConditionText(),
501 NULL,
502 result_value_sp,
503 error);
504 if (result_code == eExecutionCompleted)
505 {
506 if (result_value_sp)
507 {
508 Scalar scalar_value;
509 if (result_value_sp->ResolveValue (scalar_value))
510 {
511 if (scalar_value.ULongLong(1) == 0)
512 {
513 // We have been vetoed. This takes precedence over querying
514 // the watchpoint whether it should stop (aka ignore count and
515 // friends). See also StopInfoWatchpoint::ShouldStop() as well
516 // as Process::ProcessEventData::DoOnRemoval().
517 m_should_stop = false;
518 }
519 else
520 m_should_stop = true;
521 if (log)
522 log->Printf("Condition successfully evaluated, result is %s.\n",
523 m_should_stop ? "true" : "false");
524 }
525 else
526 {
527 m_should_stop = true;
528 if (log)
529 log->Printf("Failed to get an integer result from the expression.");
530 }
531 }
532 }
533 else
534 {
535 Debugger &debugger = context.exe_ctx.GetTargetRef().GetDebugger();
536 StreamSP error_sp = debugger.GetAsyncErrorStream ();
537 error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint ");
538 wp_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
539 error_sp->Printf (": \"%s\"",
540 wp_sp->GetConditionText());
541 error_sp->EOL();
542 const char *err_str = error.AsCString("<Unknown Error>");
543 if (log)
544 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
545
546 error_sp->PutCString (err_str);
547 error_sp->EOL();
548 error_sp->Flush();
549 // If the condition fails to be parsed or run, we should stop.
550 m_should_stop = true;
551 }
552 }
553 }
554 else
555 {
556 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
557
558 if (log)
559 log->Printf ("Process::%s could not find watchpoint id: %lld...", __FUNCTION__, m_value);
560 }
561 if (log)
562 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
563 }
564
Greg Clayton643ee732010-08-04 01:40:35 +0000565 virtual const char *
566 GetDescription ()
567 {
568 if (m_description.empty())
569 {
570 StreamString strm;
571 strm.Printf("watchpoint %lli", m_value);
572 m_description.swap (strm.GetString());
573 }
574 return m_description.c_str();
575 }
576
Greg Clayton643ee732010-08-04 01:40:35 +0000577private:
578 std::string m_description;
Johnny Chen043f8c22011-09-21 22:47:15 +0000579 bool m_should_stop;
580 bool m_should_stop_is_valid;
Greg Clayton643ee732010-08-04 01:40:35 +0000581};
582
583
584
585//----------------------------------------------------------------------
586// StopInfoUnixSignal
587//----------------------------------------------------------------------
588
589class StopInfoUnixSignal : public StopInfo
590{
591public:
592
593 StopInfoUnixSignal (Thread &thread, int signo) :
Greg Clayton65611552011-06-04 01:26:29 +0000594 StopInfo (thread, signo)
Greg Clayton643ee732010-08-04 01:40:35 +0000595 {
596 }
597
598 virtual ~StopInfoUnixSignal ()
599 {
600 }
601
602
603 virtual StopReason
604 GetStopReason () const
605 {
606 return eStopReasonSignal;
607 }
608
609 virtual bool
610 ShouldStop (Event *event_ptr)
611 {
612 return m_thread.GetProcess().GetUnixSignals().GetShouldStop (m_value);
613 }
614
615
616 // If should stop returns false, check if we should notify of this event
617 virtual bool
618 ShouldNotify (Event *event_ptr)
619 {
620 return m_thread.GetProcess().GetUnixSignals().GetShouldNotify (m_value);
621 }
622
623
624 virtual void
625 WillResume (lldb::StateType resume_state)
626 {
627 if (m_thread.GetProcess().GetUnixSignals().GetShouldSuppress(m_value) == false)
628 m_thread.SetResumeSignal(m_value);
629 }
630
631 virtual const char *
632 GetDescription ()
633 {
634 if (m_description.empty())
635 {
636 StreamString strm;
637 const char *signal_name = m_thread.GetProcess().GetUnixSignals().GetSignalAsCString (m_value);
638 if (signal_name)
Greg Claytona830adb2010-10-04 01:05:56 +0000639 strm.Printf("signal %s", signal_name);
Greg Clayton643ee732010-08-04 01:40:35 +0000640 else
Greg Claytona830adb2010-10-04 01:05:56 +0000641 strm.Printf("signal %lli", m_value);
Greg Clayton643ee732010-08-04 01:40:35 +0000642 m_description.swap (strm.GetString());
643 }
644 return m_description.c_str();
645 }
Greg Clayton643ee732010-08-04 01:40:35 +0000646};
647
648//----------------------------------------------------------------------
649// StopInfoTrace
650//----------------------------------------------------------------------
651
652class StopInfoTrace : public StopInfo
653{
654public:
655
656 StopInfoTrace (Thread &thread) :
657 StopInfo (thread, LLDB_INVALID_UID)
658 {
659 }
660
661 virtual ~StopInfoTrace ()
662 {
663 }
664
665 virtual StopReason
666 GetStopReason () const
667 {
668 return eStopReasonTrace;
669 }
670
671 virtual const char *
672 GetDescription ()
673 {
Greg Clayton65611552011-06-04 01:26:29 +0000674 if (m_description.empty())
Greg Clayton643ee732010-08-04 01:40:35 +0000675 return "trace";
Greg Clayton65611552011-06-04 01:26:29 +0000676 else
677 return m_description.c_str();
678 }
679};
680
681
682//----------------------------------------------------------------------
683// StopInfoException
684//----------------------------------------------------------------------
685
686class StopInfoException : public StopInfo
687{
688public:
689
690 StopInfoException (Thread &thread, const char *description) :
691 StopInfo (thread, LLDB_INVALID_UID)
692 {
693 if (description)
694 SetDescription (description);
695 }
696
697 virtual
698 ~StopInfoException ()
699 {
700 }
701
702 virtual StopReason
703 GetStopReason () const
704 {
705 return eStopReasonException;
706 }
707
708 virtual const char *
709 GetDescription ()
710 {
711 if (m_description.empty())
712 return "exception";
713 else
714 return m_description.c_str();
Greg Clayton643ee732010-08-04 01:40:35 +0000715 }
716};
717
718
719//----------------------------------------------------------------------
720// StopInfoThreadPlan
721//----------------------------------------------------------------------
722
723class StopInfoThreadPlan : public StopInfo
724{
725public:
726
Jim Ingham1586d972011-12-17 01:35:57 +0000727 StopInfoThreadPlan (ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp) :
Greg Clayton643ee732010-08-04 01:40:35 +0000728 StopInfo (plan_sp->GetThread(), LLDB_INVALID_UID),
Jim Ingham1586d972011-12-17 01:35:57 +0000729 m_plan_sp (plan_sp),
730 m_return_valobj_sp (return_valobj_sp)
Greg Clayton643ee732010-08-04 01:40:35 +0000731 {
732 }
733
734 virtual ~StopInfoThreadPlan ()
735 {
736 }
737
738 virtual StopReason
739 GetStopReason () const
740 {
741 return eStopReasonPlanComplete;
742 }
743
744 virtual const char *
745 GetDescription ()
746 {
747 if (m_description.empty())
748 {
749 StreamString strm;
750 m_plan_sp->GetDescription (&strm, eDescriptionLevelBrief);
751 m_description.swap (strm.GetString());
752 }
753 return m_description.c_str();
754 }
Jim Ingham1586d972011-12-17 01:35:57 +0000755
756 ValueObjectSP
757 GetReturnValueObject()
758 {
759 return m_return_valobj_sp;
760 }
Greg Clayton643ee732010-08-04 01:40:35 +0000761
762private:
763 ThreadPlanSP m_plan_sp;
Jim Ingham1586d972011-12-17 01:35:57 +0000764 ValueObjectSP m_return_valobj_sp;
Greg Clayton643ee732010-08-04 01:40:35 +0000765};
Jim Ingham21f37ad2011-08-09 02:12:22 +0000766} // namespace lldb_private
Greg Clayton643ee732010-08-04 01:40:35 +0000767
768StopInfoSP
769StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id)
770{
771 return StopInfoSP (new StopInfoBreakpoint (thread, break_id));
772}
773
774StopInfoSP
Jim Inghamd1686902010-10-14 23:45:03 +0000775StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id, bool should_stop)
776{
777 return StopInfoSP (new StopInfoBreakpoint (thread, break_id, should_stop));
778}
779
780StopInfoSP
Greg Clayton643ee732010-08-04 01:40:35 +0000781StopInfo::CreateStopReasonWithWatchpointID (Thread &thread, break_id_t watch_id)
782{
783 return StopInfoSP (new StopInfoWatchpoint (thread, watch_id));
784}
785
786StopInfoSP
787StopInfo::CreateStopReasonWithSignal (Thread &thread, int signo)
788{
789 return StopInfoSP (new StopInfoUnixSignal (thread, signo));
790}
791
792StopInfoSP
793StopInfo::CreateStopReasonToTrace (Thread &thread)
794{
795 return StopInfoSP (new StopInfoTrace (thread));
796}
797
798StopInfoSP
Jim Ingham1586d972011-12-17 01:35:57 +0000799StopInfo::CreateStopReasonWithPlan (ThreadPlanSP &plan_sp, ValueObjectSP return_valobj_sp)
Greg Clayton643ee732010-08-04 01:40:35 +0000800{
Jim Ingham1586d972011-12-17 01:35:57 +0000801 return StopInfoSP (new StopInfoThreadPlan (plan_sp, return_valobj_sp));
Greg Clayton643ee732010-08-04 01:40:35 +0000802}
Greg Clayton65611552011-06-04 01:26:29 +0000803
804StopInfoSP
805StopInfo::CreateStopReasonWithException (Thread &thread, const char *description)
806{
807 return StopInfoSP (new StopInfoException (thread, description));
808}
Jim Ingham1586d972011-12-17 01:35:57 +0000809
810ValueObjectSP
811StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp)
812{
813 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete)
814 {
815 StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
816 return plan_stop_info->GetReturnValueObject();
817 }
818 else
819 return ValueObjectSP();
820}