blob: bf81c0f316a7d66a459569d4d5df71bf4e3cc218 [file] [log] [blame]
Greg Claytonf4b47e12010-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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Claytonf4b47e12010-08-04 01:40:35 +000012#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 Clayton4e78f602010-11-18 18:52:36 +000021#include "lldb/Breakpoint/Breakpoint.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000022#include "lldb/Breakpoint/BreakpointLocation.h"
23#include "lldb/Breakpoint/StoppointCallbackContext.h"
Johnny Chen01a67862011-10-14 00:42:25 +000024#include "lldb/Breakpoint/Watchpoint.h"
Jim Ingham4b536182011-08-09 02:12:22 +000025#include "lldb/Core/Debugger.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000026#include "lldb/Core/StreamString.h"
Zachary Turnera78bd7f2015-03-03 23:11:11 +000027#include "lldb/Core/ValueObject.h"
Jim Ingham4b536182011-08-09 02:12:22 +000028#include "lldb/Expression/ClangUserExpression.h"
29#include "lldb/Target/Target.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000030#include "lldb/Target/Thread.h"
31#include "lldb/Target/ThreadPlan.h"
32#include "lldb/Target/Process.h"
33#include "lldb/Target/UnixSignals.h"
34
35using namespace lldb;
36using namespace lldb_private;
37
38StopInfo::StopInfo (Thread &thread, uint64_t value) :
Greg Clayton46c2b6e2013-04-29 23:30:46 +000039 m_thread_wp (thread.shared_from_this()),
Greg Clayton1ac04c32012-02-21 00:09:25 +000040 m_stop_id (thread.GetProcess()->GetStopID()),
41 m_resume_id (thread.GetProcess()->GetResumeID()),
Jim Ingham0161b492013-02-09 01:29:05 +000042 m_value (value),
Jim Ingham221d51c2013-05-08 00:35:16 +000043 m_override_should_notify (eLazyBoolCalculate),
Kuba Breckaafdf8422014-10-10 23:43:03 +000044 m_override_should_stop (eLazyBoolCalculate),
45 m_extended_info()
Greg Claytonf4b47e12010-08-04 01:40:35 +000046{
47}
48
49bool
50StopInfo::IsValid () const
51{
Greg Clayton46c2b6e2013-04-29 23:30:46 +000052 ThreadSP thread_sp (m_thread_wp.lock());
53 if (thread_sp)
54 return thread_sp->GetProcess()->GetStopID() == m_stop_id;
55 return false;
Greg Claytonf4b47e12010-08-04 01:40:35 +000056}
57
Jim Ingham77787032011-01-20 02:03:18 +000058void
59StopInfo::MakeStopInfoValid ()
60{
Greg Clayton46c2b6e2013-04-29 23:30:46 +000061 ThreadSP thread_sp (m_thread_wp.lock());
62 if (thread_sp)
63 {
64 m_stop_id = thread_sp->GetProcess()->GetStopID();
65 m_resume_id = thread_sp->GetProcess()->GetResumeID();
66 }
Jim Ingham77787032011-01-20 02:03:18 +000067}
68
Jim Ingham0faa43f2011-11-08 03:00:11 +000069bool
70StopInfo::HasTargetRunSinceMe ()
Jim Ingham4b536182011-08-09 02:12:22 +000071{
Greg Clayton46c2b6e2013-04-29 23:30:46 +000072 ThreadSP thread_sp (m_thread_wp.lock());
73
74 if (thread_sp)
Jim Ingham0faa43f2011-11-08 03:00:11 +000075 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +000076 lldb::StateType ret_type = thread_sp->GetProcess()->GetPrivateState();
77 if (ret_type == eStateRunning)
Jim Ingham0faa43f2011-11-08 03:00:11 +000078 {
79 return true;
80 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +000081 else if (ret_type == eStateStopped)
82 {
83 // This is a little tricky. We want to count "run and stopped again before you could
84 // ask this question as a "TRUE" answer to HasTargetRunSinceMe. But we don't want to
85 // include any running of the target done for expressions. So we track both resumes,
86 // and resumes caused by expressions, and check if there are any resumes NOT caused
87 // by expressions.
88
89 uint32_t curr_resume_id = thread_sp->GetProcess()->GetResumeID();
90 uint32_t last_user_expression_id = thread_sp->GetProcess()->GetLastUserExpressionResumeID ();
91 if (curr_resume_id == m_resume_id)
92 {
93 return false;
94 }
95 else if (curr_resume_id > last_user_expression_id)
96 {
97 return true;
98 }
99 }
Jim Ingham0faa43f2011-11-08 03:00:11 +0000100 }
101 return false;
Jim Ingham4b536182011-08-09 02:12:22 +0000102}
103
Greg Claytonf4b47e12010-08-04 01:40:35 +0000104//----------------------------------------------------------------------
105// StopInfoBreakpoint
106//----------------------------------------------------------------------
107
Jim Ingham4b536182011-08-09 02:12:22 +0000108namespace lldb_private
109{
Greg Claytonf4b47e12010-08-04 01:40:35 +0000110class StopInfoBreakpoint : public StopInfo
111{
112public:
Greg Claytonf4b47e12010-08-04 01:40:35 +0000113 StopInfoBreakpoint (Thread &thread, break_id_t break_id) :
114 StopInfo (thread, break_id),
115 m_description(),
116 m_should_stop (false),
Jim Ingham0f16e732011-02-08 05:20:59 +0000117 m_should_stop_is_valid (false),
Jim Ingham52c7d202011-10-28 01:12:19 +0000118 m_should_perform_action (true),
Jim Inghamca36cd12012-10-05 19:16:31 +0000119 m_address (LLDB_INVALID_ADDRESS),
120 m_break_id(LLDB_INVALID_BREAK_ID),
121 m_was_one_shot (false)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000122 {
Jim Inghamca36cd12012-10-05 19:16:31 +0000123 StoreBPInfo();
Greg Claytonf4b47e12010-08-04 01:40:35 +0000124 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000125
Jim Ingham36f3b362010-10-14 23:45:03 +0000126 StopInfoBreakpoint (Thread &thread, break_id_t break_id, bool should_stop) :
127 StopInfo (thread, break_id),
128 m_description(),
129 m_should_stop (should_stop),
Jim Ingham0f16e732011-02-08 05:20:59 +0000130 m_should_stop_is_valid (true),
Jim Ingham52c7d202011-10-28 01:12:19 +0000131 m_should_perform_action (true),
Jim Inghamca36cd12012-10-05 19:16:31 +0000132 m_address (LLDB_INVALID_ADDRESS),
133 m_break_id(LLDB_INVALID_BREAK_ID),
134 m_was_one_shot (false)
135 {
136 StoreBPInfo();
137 }
138
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000139 void
140 StoreBPInfo ()
Jim Ingham36f3b362010-10-14 23:45:03 +0000141 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000142 ThreadSP thread_sp (m_thread_wp.lock());
143 if (thread_sp)
Jim Ingham52c7d202011-10-28 01:12:19 +0000144 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000145 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
146 if (bp_site_sp)
Jim Inghamca36cd12012-10-05 19:16:31 +0000147 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000148 if (bp_site_sp->GetNumberOfOwners() == 1)
Jim Inghamca36cd12012-10-05 19:16:31 +0000149 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000150 BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(0);
151 if (bp_loc_sp)
152 {
153 m_break_id = bp_loc_sp->GetBreakpoint().GetID();
154 m_was_one_shot = bp_loc_sp->GetBreakpoint().IsOneShot();
155 }
Jim Inghamca36cd12012-10-05 19:16:31 +0000156 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000157 m_address = bp_site_sp->GetLoadAddress();
Jim Inghamca36cd12012-10-05 19:16:31 +0000158 }
Jim Ingham52c7d202011-10-28 01:12:19 +0000159 }
Jim Ingham36f3b362010-10-14 23:45:03 +0000160 }
161
Greg Claytonf4b47e12010-08-04 01:40:35 +0000162 virtual ~StopInfoBreakpoint ()
163 {
164 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000165
Greg Claytonab745c22015-04-07 22:17:41 +0000166 virtual bool
167 IsValidForOperatingSystemThread (Thread &thread)
168 {
169 ProcessSP process_sp (thread.GetProcess());
170 if (process_sp)
171 {
172 BreakpointSiteSP bp_site_sp (process_sp->GetBreakpointSiteList().FindByID (m_value));
173 if (bp_site_sp)
174 return bp_site_sp->ValidForThisThread (&thread);
175 }
176 return false;
177 }
178
Greg Claytonf4b47e12010-08-04 01:40:35 +0000179 virtual StopReason
180 GetStopReason () const
181 {
182 return eStopReasonBreakpoint;
183 }
184
185 virtual bool
Jim Ingham6d66ce62012-04-20 21:16:56 +0000186 ShouldStopSynchronous (Event *event_ptr)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000187 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000188 ThreadSP thread_sp (m_thread_wp.lock());
189 if (thread_sp)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000190 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000191 if (!m_should_stop_is_valid)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000192 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000193 // Only check once if we should stop at a breakpoint
194 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
195 if (bp_site_sp)
196 {
197 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
198 StoppointCallbackContext context (event_ptr, exe_ctx, true);
Jim Inghama672ece2014-10-22 01:54:17 +0000199 bp_site_sp->BumpHitCounts();
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000200 m_should_stop = bp_site_sp->ShouldStop (&context);
201 }
202 else
203 {
204 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Greg Claytonf4b47e12010-08-04 01:40:35 +0000205
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000206 if (log)
207 log->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value);
Greg Claytonf4b47e12010-08-04 01:40:35 +0000208
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000209 m_should_stop = true;
210 }
211 m_should_stop_is_valid = true;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000212 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000213 return m_should_stop;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000214 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000215 return false;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000216 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000217
Jim Inghamf57b4352012-11-10 02:08:14 +0000218 virtual bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000219 DoShouldNotify (Event *event_ptr)
Jim Inghamf57b4352012-11-10 02:08:14 +0000220 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000221 ThreadSP thread_sp (m_thread_wp.lock());
222 if (thread_sp)
Jim Inghamf57b4352012-11-10 02:08:14 +0000223 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000224 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
225 if (bp_site_sp)
Jim Inghamf57b4352012-11-10 02:08:14 +0000226 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000227 bool all_internal = true;
228
229 for (uint32_t i = 0; i < bp_site_sp->GetNumberOfOwners(); i++)
Jim Inghamf57b4352012-11-10 02:08:14 +0000230 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000231 if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal())
232 {
233 all_internal = false;
234 break;
235 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000236 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000237 return all_internal == false;
Jim Inghamf57b4352012-11-10 02:08:14 +0000238 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000239 }
240 return true;
241 }
242
243 virtual const char *
244 GetDescription ()
245 {
246 if (m_description.empty())
247 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000248 ThreadSP thread_sp (m_thread_wp.lock());
249 if (thread_sp)
Jim Inghamf57b4352012-11-10 02:08:14 +0000250 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000251 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
252 if (bp_site_sp)
Jim Ingham29950772013-01-26 02:19:28 +0000253 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000254 StreamString strm;
255 // If we have just hit an internal breakpoint, and it has a kind description, print that instead of the
256 // full breakpoint printing:
257 if (bp_site_sp->IsInternal())
Jim Ingham29950772013-01-26 02:19:28 +0000258 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000259 size_t num_owners = bp_site_sp->GetNumberOfOwners();
260 for (size_t idx = 0; idx < num_owners; idx++)
Jim Ingham29950772013-01-26 02:19:28 +0000261 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000262 const char *kind = bp_site_sp->GetOwnerAtIndex(idx)->GetBreakpoint().GetBreakpointKind();
263 if (kind != NULL)
264 {
265 m_description.assign (kind);
266 return kind;
267 }
Jim Ingham29950772013-01-26 02:19:28 +0000268 }
269 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000270
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000271 strm.Printf("breakpoint ");
272 bp_site_sp->GetDescription(&strm, eDescriptionLevelBrief);
273 m_description.swap (strm.GetString());
Jim Ingham29950772013-01-26 02:19:28 +0000274 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000275 else
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000276 {
277 StreamString strm;
278 if (m_break_id != LLDB_INVALID_BREAK_ID)
279 {
280 BreakpointSP break_sp = thread_sp->GetProcess()->GetTarget().GetBreakpointByID(m_break_id);
281 if (break_sp)
282 {
283 if (break_sp->IsInternal())
284 {
285 const char *kind = break_sp->GetBreakpointKind();
286 if (kind)
287 strm.Printf ("internal %s breakpoint(%d).", kind, m_break_id);
288 else
289 strm.Printf ("internal breakpoint(%d).", m_break_id);
290 }
291 else
292 {
293 strm.Printf ("breakpoint %d.", m_break_id);
294 }
295 }
296 else
297 {
298 if (m_was_one_shot)
299 strm.Printf ("one-shot breakpoint %d", m_break_id);
300 else
301 strm.Printf ("breakpoint %d which has been deleted.", m_break_id);
302 }
303 }
304 else if (m_address == LLDB_INVALID_ADDRESS)
305 strm.Printf("breakpoint site %" PRIi64 " which has been deleted - unknown address", m_value);
306 else
307 strm.Printf("breakpoint site %" PRIi64 " which has been deleted - was at 0x%" PRIx64, m_value, m_address);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000308
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000309 m_description.swap (strm.GetString());
310 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000311 }
312 }
313 return m_description.c_str();
314 }
315
316protected:
Jim Ingham6d66ce62012-04-20 21:16:56 +0000317 bool
318 ShouldStop (Event *event_ptr)
319 {
320 // This just reports the work done by PerformAction or the synchronous stop. It should
321 // only ever get called after they have had a chance to run.
322 assert (m_should_stop_is_valid);
323 return m_should_stop;
324 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000325
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000326 virtual void
327 PerformAction (Event *event_ptr)
328 {
Jim Ingham0f16e732011-02-08 05:20:59 +0000329 if (!m_should_perform_action)
330 return;
331 m_should_perform_action = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000332
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000333 ThreadSP thread_sp (m_thread_wp.lock());
334
335 if (thread_sp)
Jim Ingham5cb9a182013-03-28 00:13:30 +0000336 {
Jim Inghamcca89952014-08-05 01:58:14 +0000337 Log *log = lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS | LIBLLDB_LOG_STEP);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000338
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000339 if (!thread_sp->IsValid())
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000340 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000341 // This shouldn't ever happen, but just in case, don't do more harm.
Jason Molenda3f032ff2013-08-06 23:08:59 +0000342 if (log)
343 {
344 log->Printf ("PerformAction got called with an invalid thread.");
345 }
Jim Ingham79ea1d82011-12-09 04:17:31 +0000346 m_should_stop = true;
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000347 m_should_stop_is_valid = true;
348 return;
Jim Ingham79ea1d82011-12-09 04:17:31 +0000349 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000350
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000351 BreakpointSiteSP bp_site_sp (thread_sp->GetProcess()->GetBreakpointSiteList().FindByID (m_value));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000352
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000353 if (bp_site_sp)
Jim Ingham79ea1d82011-12-09 04:17:31 +0000354 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000355 size_t num_owners = bp_site_sp->GetNumberOfOwners();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000356
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000357 if (num_owners == 0)
358 {
359 m_should_stop = true;
Jim Ingham184e9812013-01-15 02:47:48 +0000360 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000361 else
Jim Ingham4b536182011-08-09 02:12:22 +0000362 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000363 // We go through each location, and test first its condition. If the condition says to stop,
364 // then we run the callback for that location. If that callback says to stop as well, then
365 // we set m_should_stop to true; we are going to stop.
366 // But we still want to give all the breakpoints whose conditions say we are going to stop a
367 // chance to run their callbacks.
368 // Of course if any callback restarts the target by putting "continue" in the callback, then
369 // we're going to restart, without running the rest of the callbacks. And in this case we will
370 // end up not stopping even if another location said we should stop. But that's better than not
371 // running all the callbacks.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000372
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000373 m_should_stop = false;
374
375 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
376 Process *process = exe_ctx.GetProcessPtr();
377 if (process->GetModIDRef().IsLastResumeForUserExpression())
Jim Ingham4b536182011-08-09 02:12:22 +0000378 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000379 // If we are in the middle of evaluating an expression, don't run asynchronous breakpoint commands or
380 // expressions. That could lead to infinite recursion if the command or condition re-calls the function
381 // with this breakpoint.
382 // TODO: We can keep a list of the breakpoints we've seen while running expressions in the nested
383 // PerformAction calls that can arise when the action runs a function that hits another breakpoint,
384 // and only stop running commands when we see the same breakpoint hit a second time.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000385
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000386 m_should_stop_is_valid = true;
387 if (log)
388 log->Printf ("StopInfoBreakpoint::PerformAction - Hit a breakpoint while running an expression,"
389 " not running commands to avoid recursion.");
390 bool ignoring_breakpoints = process->GetIgnoreBreakpointsInExpressions();
391 if (ignoring_breakpoints)
Jim Ingham4b536182011-08-09 02:12:22 +0000392 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000393 m_should_stop = false;
394 // Internal breakpoints will always stop.
395 for (size_t j = 0; j < num_owners; j++)
396 {
397 lldb::BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(j);
398 if (bp_loc_sp->GetBreakpoint().IsInternal())
399 {
400 m_should_stop = true;
401 break;
402 }
403 }
Jim Ingham4b536182011-08-09 02:12:22 +0000404 }
Sean Callanan3dbf3462013-04-19 07:09:15 +0000405 else
406 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000407 m_should_stop = true;
408 }
409 if (log)
410 log->Printf ("StopInfoBreakpoint::PerformAction - in expression, continuing: %s.",
411 m_should_stop ? "true" : "false");
412 process->GetTarget().GetDebugger().GetAsyncOutputStream()->Printf("Warning: hit breakpoint while "
413 "running function, skipping commands and conditions to prevent recursion.");
414 return;
415 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000416
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000417 StoppointCallbackContext context (event_ptr, exe_ctx, false);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000418
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000419 // Let's copy the breakpoint locations out of the site and store them in a local list. That way if
420 // one of the breakpoint actions changes the site, then we won't be operating on a bad list.
Jim Inghama672ece2014-10-22 01:54:17 +0000421 // For safety's sake let's also grab an extra reference to the breakpoint owners of the locations we're
422 // going to examine, since the locations are going to have to get back to their breakpoints, and the
423 // locations don't keep their owners alive. I'm just sticking the BreakpointSP's in a vector since
424 // I'm only really using it to locally increment their retain counts.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000425
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000426 BreakpointLocationCollection site_locations;
Jim Inghama672ece2014-10-22 01:54:17 +0000427 std::vector<lldb::BreakpointSP> location_owners;
428
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000429 for (size_t j = 0; j < num_owners; j++)
Jim Inghama672ece2014-10-22 01:54:17 +0000430 {
431 BreakpointLocationSP loc(bp_site_sp->GetOwnerAtIndex(j));
432 site_locations.Add(loc);
433 location_owners.push_back(loc->GetBreakpoint().shared_from_this());
434
435 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000436
437 for (size_t j = 0; j < num_owners; j++)
438 {
439 lldb::BreakpointLocationSP bp_loc_sp = site_locations.GetByIndex(j);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000440
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000441 // If another action disabled this breakpoint or its location, then don't run the actions.
442 if (!bp_loc_sp->IsEnabled() || !bp_loc_sp->GetBreakpoint().IsEnabled())
443 continue;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000444
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000445 // The breakpoint site may have many locations associated with it, not all of them valid for
446 // this thread. Skip the ones that aren't:
447 if (!bp_loc_sp->ValidForThisThread(thread_sp.get()))
Jim Inghama8b99ca2014-01-15 03:30:04 +0000448 {
449 if (log)
450 {
451 StreamString s;
452 bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000453 log->Printf ("Breakpoint %s hit on thread 0x%llx but it was not for this thread, continuing.",
454 s.GetData(),
455 static_cast<unsigned long long>(thread_sp->GetID()));
Jim Inghama8b99ca2014-01-15 03:30:04 +0000456 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000457 continue;
Jim Inghama8b99ca2014-01-15 03:30:04 +0000458 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000459 // First run the condition for the breakpoint. If that says we should stop, then we'll run
460 // the callback for the breakpoint. If the callback says we shouldn't stop that will win.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000461
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000462 if (bp_loc_sp->GetConditionText() != NULL)
463 {
464 Error condition_error;
465 bool condition_says_stop = bp_loc_sp->ConditionSaysStop(exe_ctx, condition_error);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000466
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000467 if (!condition_error.Success())
468 {
469 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
470 StreamSP error_sp = debugger.GetAsyncErrorStream ();
471 error_sp->Printf ("Stopped due to an error evaluating condition of breakpoint ");
472 bp_loc_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
473 error_sp->Printf (": \"%s\"",
474 bp_loc_sp->GetConditionText());
475 error_sp->EOL();
476 const char *err_str = condition_error.AsCString("<Unknown Error>");
477 if (log)
478 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000479
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000480 error_sp->PutCString (err_str);
481 error_sp->EOL();
482 error_sp->Flush();
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000483 }
484 else
485 {
Jim Inghama8b99ca2014-01-15 03:30:04 +0000486 if (log)
487 {
488 StreamString s;
489 bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000490 log->Printf ("Condition evaluated for breakpoint %s on thread 0x%llx conditon_says_stop: %i.",
491 s.GetData(),
492 static_cast<unsigned long long>(thread_sp->GetID()),
493 condition_says_stop);
Jim Inghama8b99ca2014-01-15 03:30:04 +0000494 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000495 if (!condition_says_stop)
Jim Inghamd762df82015-01-15 01:41:04 +0000496 {
497 // We don't want to increment the hit count of breakpoints if the condition fails.
498 // We've already bumped it by the time we get here, so undo the bump:
499 bp_loc_sp->UndoBumpHitCount();
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000500 continue;
Jim Inghamd762df82015-01-15 01:41:04 +0000501 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000502 }
503 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000504
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000505 bool callback_says_stop;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000506
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000507 // FIXME: For now the callbacks have to run in async mode - the first time we restart we need
508 // to get out of there. So set it here.
509 // When we figure out how to nest breakpoint hits then this will change.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000510
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000511 Debugger &debugger = thread_sp->CalculateTarget()->GetDebugger();
512 bool old_async = debugger.GetAsyncExecution();
513 debugger.SetAsyncExecution (true);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000514
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000515 callback_says_stop = bp_loc_sp->InvokeCallback (&context);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000516
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000517 debugger.SetAsyncExecution (old_async);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000518
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000519 if (callback_says_stop)
520 m_should_stop = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000521
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000522 // If we are going to stop for this breakpoint, then remove the breakpoint.
523 if (callback_says_stop && bp_loc_sp && bp_loc_sp->GetBreakpoint().IsOneShot())
524 {
525 thread_sp->GetProcess()->GetTarget().RemoveBreakpointByID (bp_loc_sp->GetBreakpoint().GetID());
526 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000527
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000528 // Also make sure that the callback hasn't continued the target.
529 // If it did, when we'll set m_should_start to false and get out of here.
530 if (HasTargetRunSinceMe ())
531 {
532 m_should_stop = false;
533 break;
Sean Callanan3dbf3462013-04-19 07:09:15 +0000534 }
Jim Ingham4b536182011-08-09 02:12:22 +0000535 }
Jim Ingham4b536182011-08-09 02:12:22 +0000536 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000537 // We've figured out what this stop wants to do, so mark it as valid so we don't compute it again.
538 m_should_stop_is_valid = true;
539
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000540 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000541 else
542 {
543 m_should_stop = true;
544 m_should_stop_is_valid = true;
545 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Jim Ingham79ea1d82011-12-09 04:17:31 +0000546
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000547 if (log_process)
548 log_process->Printf ("Process::%s could not find breakpoint site id: %" PRId64 "...", __FUNCTION__, m_value);
549 }
550 if (log)
551 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000552 }
Jim Ingham3ebcf7f2010-08-10 00:59:59 +0000553 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000554
555private:
556 std::string m_description;
557 bool m_should_stop;
558 bool m_should_stop_is_valid;
Jim Ingham0f16e732011-02-08 05:20:59 +0000559 bool m_should_perform_action; // Since we are trying to preserve the "state" of the system even if we run functions
560 // etc. behind the users backs, we need to make sure we only REALLY perform the action once.
Jim Ingham52c7d202011-10-28 01:12:19 +0000561 lldb::addr_t m_address; // We use this to capture the breakpoint site address when we create the StopInfo,
562 // in case somebody deletes it between the time the StopInfo is made and the
563 // description is asked for.
Jim Inghamca36cd12012-10-05 19:16:31 +0000564 lldb::break_id_t m_break_id;
565 bool m_was_one_shot;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000566};
567
568
569//----------------------------------------------------------------------
570// StopInfoWatchpoint
571//----------------------------------------------------------------------
572
573class StopInfoWatchpoint : public StopInfo
574{
575public:
Jim Inghamf57b4352012-11-10 02:08:14 +0000576 // Make sure watchpoint is properly disabled and subsequently enabled while performing watchpoint actions.
577 class WatchpointSentry {
578 public:
579 WatchpointSentry(Process *p, Watchpoint *w):
580 process(p),
581 watchpoint(w)
582 {
583 if (process && watchpoint)
584 {
Jim Ingham1b5792e2012-12-18 02:03:49 +0000585 const bool notify = false;
Jim Inghamf57b4352012-11-10 02:08:14 +0000586 watchpoint->TurnOnEphemeralMode();
Jim Ingham1b5792e2012-12-18 02:03:49 +0000587 process->DisableWatchpoint(watchpoint, notify);
Jim Inghamf57b4352012-11-10 02:08:14 +0000588 }
589 }
590 ~WatchpointSentry()
591 {
592 if (process && watchpoint)
593 {
594 if (!watchpoint->IsDisabledDuringEphemeralMode())
Jim Ingham1b5792e2012-12-18 02:03:49 +0000595 {
596 const bool notify = false;
597 process->EnableWatchpoint(watchpoint, notify);
598 }
Jim Inghamf57b4352012-11-10 02:08:14 +0000599 watchpoint->TurnOffEphemeralMode();
600 }
601 }
602 private:
603 Process *process;
604 Watchpoint *watchpoint;
605 };
Greg Claytonf4b47e12010-08-04 01:40:35 +0000606
607 StopInfoWatchpoint (Thread &thread, break_id_t watch_id) :
Johnny Chenfd158f42011-09-21 22:47:15 +0000608 StopInfo(thread, watch_id),
609 m_description(),
610 m_should_stop(false),
611 m_should_stop_is_valid(false)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000612 {
613 }
614
615 virtual ~StopInfoWatchpoint ()
616 {
617 }
618
619 virtual StopReason
620 GetStopReason () const
621 {
622 return eStopReasonWatchpoint;
623 }
624
Jim Inghamf57b4352012-11-10 02:08:14 +0000625 virtual const char *
626 GetDescription ()
627 {
628 if (m_description.empty())
629 {
630 StreamString strm;
Daniel Malead01b2952012-11-29 21:49:15 +0000631 strm.Printf("watchpoint %" PRIi64, m_value);
Jim Inghamf57b4352012-11-10 02:08:14 +0000632 m_description.swap (strm.GetString());
633 }
634 return m_description.c_str();
635 }
636
637protected:
Johnny Chenfd158f42011-09-21 22:47:15 +0000638 virtual bool
Jim Ingham9b620f32013-02-22 21:23:43 +0000639 ShouldStopSynchronous (Event *event_ptr)
Johnny Chenfd158f42011-09-21 22:47:15 +0000640 {
641 // ShouldStop() method is idempotent and should not affect hit count.
Johnny Chen16dcf712011-10-17 18:58:00 +0000642 // See Process::RunPrivateStateThread()->Process()->HandlePrivateEvent()
643 // -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()->
644 // Thread::ShouldStop()->ThreadPlanBase::ShouldStop()->
645 // StopInfoWatchpoint::ShouldStop() and
646 // Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()->
647 // StopInfoWatchpoint::PerformAction().
Johnny Chenfd158f42011-09-21 22:47:15 +0000648 if (m_should_stop_is_valid)
649 return m_should_stop;
650
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000651 ThreadSP thread_sp (m_thread_wp.lock());
652 if (thread_sp)
Johnny Chenfd158f42011-09-21 22:47:15 +0000653 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000654 WatchpointSP wp_sp (thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue()));
655 if (wp_sp)
656 {
657 // Check if we should stop at a watchpoint.
658 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
659 StoppointCallbackContext context (event_ptr, exe_ctx, true);
660 m_should_stop = wp_sp->ShouldStop (&context);
661 }
662 else
663 {
664 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Johnny Chenfd158f42011-09-21 22:47:15 +0000665
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000666 if (log)
667 log->Printf ("Process::%s could not find watchpoint location id: %" PRId64 "...",
668 __FUNCTION__, GetValue());
Johnny Chenfd158f42011-09-21 22:47:15 +0000669
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000670 m_should_stop = true;
671 }
Johnny Chenfd158f42011-09-21 22:47:15 +0000672 }
673 m_should_stop_is_valid = true;
674 return m_should_stop;
675 }
676
Jim Ingham9b620f32013-02-22 21:23:43 +0000677 bool
678 ShouldStop (Event *event_ptr)
679 {
680 // This just reports the work done by PerformAction or the synchronous stop. It should
681 // only ever get called after they have had a chance to run.
682 assert (m_should_stop_is_valid);
683 return m_should_stop;
684 }
685
Johnny Chen16dcf712011-10-17 18:58:00 +0000686 virtual void
687 PerformAction (Event *event_ptr)
688 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000689 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS);
Johnny Chen16dcf712011-10-17 18:58:00 +0000690 // We're going to calculate if we should stop or not in some way during the course of
691 // this code. Also by default we're going to stop, so set that here.
692 m_should_stop = true;
693
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000694 ThreadSP thread_sp (m_thread_wp.lock());
695 if (thread_sp)
Johnny Chen16dcf712011-10-17 18:58:00 +0000696 {
Johnny Chen0f7ad8d2012-08-21 22:06:34 +0000697
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000698 WatchpointSP wp_sp (thread_sp->CalculateTarget()->GetWatchpointList().FindByID(GetValue()));
699 if (wp_sp)
Enrico Granataf04a2192012-07-13 23:18:48 +0000700 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000701 ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
702 Process* process = exe_ctx.GetProcessPtr();
703
704 // This sentry object makes sure the current watchpoint is disabled while performing watchpoint actions,
705 // and it is then enabled after we are finished.
706 WatchpointSentry sentry(process, wp_sp.get());
707
Enrico Granataf04a2192012-07-13 23:18:48 +0000708 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000709 // check if this process is running on an architecture where watchpoints trigger
710 // before the associated instruction runs. if so, disable the WP, single-step and then
711 // re-enable the watchpoint
712 if (process)
Enrico Granataf04a2192012-07-13 23:18:48 +0000713 {
Jason Molendafe806902013-05-04 00:39:52 +0000714 uint32_t num;
715 bool wp_triggers_after;
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000716 if (process->GetWatchpointSupportInfo(num, wp_triggers_after).Success())
Enrico Granataf04a2192012-07-13 23:18:48 +0000717 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000718 if (!wp_triggers_after)
719 {
Jim Ingham363ddd72013-07-02 21:12:44 +0000720 StopInfoSP stored_stop_info_sp = thread_sp->GetStopInfo();
721 assert (stored_stop_info_sp.get() == this);
722
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000723 ThreadPlanSP new_plan_sp(thread_sp->QueueThreadPlanForStepSingleInstruction(false, // step-over
Greg Claytondc6224e2014-10-21 01:00:42 +0000724 false, // abort_other_plans
725 true)); // stop_other_threads
Jim Ingham4d56e9c2013-07-18 21:48:26 +0000726 new_plan_sp->SetIsMasterPlan (true);
727 new_plan_sp->SetOkayToDiscard (false);
728 new_plan_sp->SetPrivate (true);
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000729 process->GetThreadList().SetSelectedThreadByID (thread_sp->GetID());
Greg Claytondc6224e2014-10-21 01:00:42 +0000730 process->ResumeSynchronous(NULL);
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000731 process->GetThreadList().SetSelectedThreadByID (thread_sp->GetID());
Jim Ingham363ddd72013-07-02 21:12:44 +0000732 thread_sp->SetStopInfo(stored_stop_info_sp);
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000733 }
Enrico Granataf04a2192012-07-13 23:18:48 +0000734 }
735 }
736 }
Johnny Chen209bd652012-08-13 21:09:54 +0000737
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000738 if (m_should_stop && wp_sp->GetConditionText() != NULL)
Johnny Chen16dcf712011-10-17 18:58:00 +0000739 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000740 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
741 // constructor errors up to the debugger's Async I/O.
Jim Ingham1624a2d2014-05-05 02:26:40 +0000742 ExpressionResults result_code;
Greg Clayton62afb9f2013-11-04 19:35:17 +0000743 EvaluateExpressionOptions expr_options;
744 expr_options.SetUnwindOnError(true);
745 expr_options.SetIgnoreBreakpoints(true);
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000746 ValueObjectSP result_value_sp;
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000747 Error error;
Greg Clayton62afb9f2013-11-04 19:35:17 +0000748 result_code = ClangUserExpression::Evaluate (exe_ctx,
749 expr_options,
750 wp_sp->GetConditionText(),
751 NULL,
752 result_value_sp,
753 error);
Jim Ingham8646d3c2014-05-05 02:47:44 +0000754 if (result_code == eExpressionCompleted)
Johnny Chen16dcf712011-10-17 18:58:00 +0000755 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000756 if (result_value_sp)
Johnny Chen16dcf712011-10-17 18:58:00 +0000757 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000758 Scalar scalar_value;
759 if (result_value_sp->ResolveValue (scalar_value))
Johnny Chen16dcf712011-10-17 18:58:00 +0000760 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000761 if (scalar_value.ULongLong(1) == 0)
762 {
763 // We have been vetoed. This takes precedence over querying
764 // the watchpoint whether it should stop (aka ignore count and
765 // friends). See also StopInfoWatchpoint::ShouldStop() as well
766 // as Process::ProcessEventData::DoOnRemoval().
767 m_should_stop = false;
768 }
769 else
770 m_should_stop = true;
771 if (log)
772 log->Printf("Condition successfully evaluated, result is %s.\n",
773 m_should_stop ? "true" : "false");
Johnny Chen16dcf712011-10-17 18:58:00 +0000774 }
775 else
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000776 {
Johnny Chen16dcf712011-10-17 18:58:00 +0000777 m_should_stop = true;
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000778 if (log)
779 log->Printf("Failed to get an integer result from the expression.");
780 }
Johnny Chen16dcf712011-10-17 18:58:00 +0000781 }
782 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000783 else
784 {
785 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
786 StreamSP error_sp = debugger.GetAsyncErrorStream ();
787 error_sp->Printf ("Stopped due to an error evaluating condition of watchpoint ");
788 wp_sp->GetDescription (error_sp.get(), eDescriptionLevelBrief);
789 error_sp->Printf (": \"%s\"",
790 wp_sp->GetConditionText());
791 error_sp->EOL();
792 const char *err_str = error.AsCString("<Unknown Error>");
793 if (log)
794 log->Printf("Error evaluating condition: \"%s\"\n", err_str);
795
796 error_sp->PutCString (err_str);
797 error_sp->EOL();
798 error_sp->Flush();
799 // If the condition fails to be parsed or run, we should stop.
800 m_should_stop = true;
801 }
Johnny Chen16dcf712011-10-17 18:58:00 +0000802 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000803
804 // If the condition says to stop, we run the callback to further decide whether to stop.
805 if (m_should_stop)
Johnny Chen16dcf712011-10-17 18:58:00 +0000806 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000807 StoppointCallbackContext context (event_ptr, exe_ctx, false);
808 bool stop_requested = wp_sp->InvokeCallback (&context);
809 // Also make sure that the callback hasn't continued the target.
810 // If it did, when we'll set m_should_stop to false and get out of here.
811 if (HasTargetRunSinceMe ())
812 m_should_stop = false;
813
814 if (m_should_stop && !stop_requested)
815 {
816 // We have been vetoed by the callback mechanism.
817 m_should_stop = false;
818 }
819 }
820 // Finally, if we are going to stop, print out the new & old values:
821 if (m_should_stop)
822 {
823 wp_sp->CaptureWatchedValue(exe_ctx);
824
Greg Clayton1ac04c32012-02-21 00:09:25 +0000825 Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000826 StreamSP output_sp = debugger.GetAsyncOutputStream ();
827 wp_sp->DumpSnapshots(output_sp.get());
828 output_sp->EOL();
829 output_sp->Flush();
Johnny Chen16dcf712011-10-17 18:58:00 +0000830 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000831
Johnny Chen16dcf712011-10-17 18:58:00 +0000832 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000833 else
834 {
835 Log * log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Johnny Chen13206412012-08-09 23:10:57 +0000836
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000837 if (log_process)
838 log_process->Printf ("Process::%s could not find watchpoint id: %" PRId64 "...", __FUNCTION__, m_value);
Johnny Chen13206412012-08-09 23:10:57 +0000839 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000840 if (log)
841 log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
Jim Inghama7dfb662012-10-23 07:20:06 +0000842
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000843 m_should_stop_is_valid = true;
Johnny Chen16dcf712011-10-17 18:58:00 +0000844 }
Johnny Chen16dcf712011-10-17 18:58:00 +0000845 }
846
Greg Claytonf4b47e12010-08-04 01:40:35 +0000847private:
848 std::string m_description;
Johnny Chenfd158f42011-09-21 22:47:15 +0000849 bool m_should_stop;
850 bool m_should_stop_is_valid;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000851};
852
853
854
855//----------------------------------------------------------------------
856// StopInfoUnixSignal
857//----------------------------------------------------------------------
858
859class StopInfoUnixSignal : public StopInfo
860{
861public:
862
863 StopInfoUnixSignal (Thread &thread, int signo) :
Greg Claytona658fd22011-06-04 01:26:29 +0000864 StopInfo (thread, signo)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000865 {
866 }
867
868 virtual ~StopInfoUnixSignal ()
869 {
870 }
871
872
873 virtual StopReason
874 GetStopReason () const
875 {
876 return eStopReasonSignal;
877 }
878
879 virtual bool
Jim Ingham0161b492013-02-09 01:29:05 +0000880 ShouldStopSynchronous (Event *event_ptr)
881 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000882 ThreadSP thread_sp (m_thread_wp.lock());
883 if (thread_sp)
884 return thread_sp->GetProcess()->GetUnixSignals().GetShouldStop (m_value);
885 return false;
Jim Ingham0161b492013-02-09 01:29:05 +0000886 }
887
888 virtual bool
Greg Claytonf4b47e12010-08-04 01:40:35 +0000889 ShouldStop (Event *event_ptr)
890 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000891 ThreadSP thread_sp (m_thread_wp.lock());
892 if (thread_sp)
893 return thread_sp->GetProcess()->GetUnixSignals().GetShouldStop (m_value);
894 return false;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000895 }
896
897
898 // If should stop returns false, check if we should notify of this event
899 virtual bool
Jim Ingham221d51c2013-05-08 00:35:16 +0000900 DoShouldNotify (Event *event_ptr)
Greg Claytonf4b47e12010-08-04 01:40:35 +0000901 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000902 ThreadSP thread_sp (m_thread_wp.lock());
903 if (thread_sp)
Jim Ingham0161b492013-02-09 01:29:05 +0000904 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000905 bool should_notify = thread_sp->GetProcess()->GetUnixSignals().GetShouldNotify (m_value);
906 if (should_notify)
907 {
908 StreamString strm;
909 strm.Printf ("thread %d received signal: %s",
910 thread_sp->GetIndexID(),
911 thread_sp->GetProcess()->GetUnixSignals().GetSignalAsCString (m_value));
912 Process::ProcessEventData::AddRestartedReason(event_ptr, strm.GetData());
913 }
914 return should_notify;
Jim Ingham0161b492013-02-09 01:29:05 +0000915 }
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000916 return true;
Greg Claytonf4b47e12010-08-04 01:40:35 +0000917 }
918
919
920 virtual void
921 WillResume (lldb::StateType resume_state)
922 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000923 ThreadSP thread_sp (m_thread_wp.lock());
924 if (thread_sp)
925 {
926 if (thread_sp->GetProcess()->GetUnixSignals().GetShouldSuppress(m_value) == false)
927 thread_sp->SetResumeSignal(m_value);
928 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000929 }
930
931 virtual const char *
932 GetDescription ()
933 {
934 if (m_description.empty())
935 {
Greg Clayton46c2b6e2013-04-29 23:30:46 +0000936 ThreadSP thread_sp (m_thread_wp.lock());
937 if (thread_sp)
938 {
939 StreamString strm;
940 const char *signal_name = thread_sp->GetProcess()->GetUnixSignals().GetSignalAsCString (m_value);
941 if (signal_name)
942 strm.Printf("signal %s", signal_name);
943 else
944 strm.Printf("signal %" PRIi64, m_value);
945 m_description.swap (strm.GetString());
946 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000947 }
948 return m_description.c_str();
949 }
Greg Claytonf4b47e12010-08-04 01:40:35 +0000950};
951
952//----------------------------------------------------------------------
953// StopInfoTrace
954//----------------------------------------------------------------------
955
956class StopInfoTrace : public StopInfo
957{
958public:
959
960 StopInfoTrace (Thread &thread) :
961 StopInfo (thread, LLDB_INVALID_UID)
962 {
963 }
964
965 virtual ~StopInfoTrace ()
966 {
967 }
968
969 virtual StopReason
970 GetStopReason () const
971 {
972 return eStopReasonTrace;
973 }
974
975 virtual const char *
976 GetDescription ()
977 {
Greg Claytona658fd22011-06-04 01:26:29 +0000978 if (m_description.empty())
Greg Claytonf4b47e12010-08-04 01:40:35 +0000979 return "trace";
Greg Claytona658fd22011-06-04 01:26:29 +0000980 else
981 return m_description.c_str();
982 }
983};
984
985
986//----------------------------------------------------------------------
987// StopInfoException
988//----------------------------------------------------------------------
989
990class StopInfoException : public StopInfo
991{
992public:
993
994 StopInfoException (Thread &thread, const char *description) :
995 StopInfo (thread, LLDB_INVALID_UID)
996 {
997 if (description)
998 SetDescription (description);
999 }
1000
1001 virtual
1002 ~StopInfoException ()
1003 {
1004 }
1005
1006 virtual StopReason
1007 GetStopReason () const
1008 {
1009 return eStopReasonException;
1010 }
1011
1012 virtual const char *
1013 GetDescription ()
1014 {
1015 if (m_description.empty())
1016 return "exception";
1017 else
1018 return m_description.c_str();
Greg Claytonf4b47e12010-08-04 01:40:35 +00001019 }
1020};
1021
1022
1023//----------------------------------------------------------------------
1024// StopInfoThreadPlan
1025//----------------------------------------------------------------------
1026
1027class StopInfoThreadPlan : public StopInfo
1028{
1029public:
1030
Jim Ingham30fadaf2014-07-08 01:07:32 +00001031 StopInfoThreadPlan (ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp, ClangExpressionVariableSP &expression_variable_sp) :
Greg Claytonf4b47e12010-08-04 01:40:35 +00001032 StopInfo (plan_sp->GetThread(), LLDB_INVALID_UID),
Jim Ingham73ca05a2011-12-17 01:35:57 +00001033 m_plan_sp (plan_sp),
Jim Ingham30fadaf2014-07-08 01:07:32 +00001034 m_return_valobj_sp (return_valobj_sp),
1035 m_expression_variable_sp (expression_variable_sp)
Greg Claytonf4b47e12010-08-04 01:40:35 +00001036 {
1037 }
1038
1039 virtual ~StopInfoThreadPlan ()
1040 {
1041 }
1042
1043 virtual StopReason
1044 GetStopReason () const
1045 {
1046 return eStopReasonPlanComplete;
1047 }
1048
1049 virtual const char *
1050 GetDescription ()
1051 {
1052 if (m_description.empty())
1053 {
1054 StreamString strm;
1055 m_plan_sp->GetDescription (&strm, eDescriptionLevelBrief);
1056 m_description.swap (strm.GetString());
1057 }
1058 return m_description.c_str();
1059 }
Jim Ingham73ca05a2011-12-17 01:35:57 +00001060
1061 ValueObjectSP
1062 GetReturnValueObject()
1063 {
1064 return m_return_valobj_sp;
1065 }
Jim Ingham0161b492013-02-09 01:29:05 +00001066
Jim Ingham30fadaf2014-07-08 01:07:32 +00001067 ClangExpressionVariableSP
1068 GetExpressionVariable()
1069 {
1070 return m_expression_variable_sp;
1071 }
1072
Jim Ingham0161b492013-02-09 01:29:05 +00001073protected:
1074 virtual bool
1075 ShouldStop (Event *event_ptr)
1076 {
1077 if (m_plan_sp)
1078 return m_plan_sp->ShouldStop(event_ptr);
1079 else
1080 return StopInfo::ShouldStop(event_ptr);
1081 }
Greg Claytonf4b47e12010-08-04 01:40:35 +00001082
1083private:
1084 ThreadPlanSP m_plan_sp;
Jim Ingham73ca05a2011-12-17 01:35:57 +00001085 ValueObjectSP m_return_valobj_sp;
Jim Ingham30fadaf2014-07-08 01:07:32 +00001086 ClangExpressionVariableSP m_expression_variable_sp;
Greg Claytonf4b47e12010-08-04 01:40:35 +00001087};
Greg Clayton90ba8112012-12-05 00:16:59 +00001088
1089class StopInfoExec : public StopInfo
1090{
1091public:
1092
1093 StopInfoExec (Thread &thread) :
1094 StopInfo (thread, LLDB_INVALID_UID),
1095 m_performed_action (false)
1096 {
1097 }
1098
1099 virtual
1100 ~StopInfoExec ()
1101 {
1102 }
1103
1104 virtual StopReason
1105 GetStopReason () const
1106 {
1107 return eStopReasonExec;
1108 }
1109
1110 virtual const char *
1111 GetDescription ()
1112 {
1113 return "exec";
1114 }
1115protected:
Greg Clayton90ba8112012-12-05 00:16:59 +00001116
1117 virtual void
1118 PerformAction (Event *event_ptr)
1119 {
1120 // Only perform the action once
1121 if (m_performed_action)
1122 return;
1123 m_performed_action = true;
Greg Clayton46c2b6e2013-04-29 23:30:46 +00001124 ThreadSP thread_sp (m_thread_wp.lock());
1125 if (thread_sp)
1126 thread_sp->GetProcess()->DidExec();
Greg Clayton90ba8112012-12-05 00:16:59 +00001127 }
1128
1129 bool m_performed_action;
1130};
1131
Jim Ingham4b536182011-08-09 02:12:22 +00001132} // namespace lldb_private
Greg Claytonf4b47e12010-08-04 01:40:35 +00001133
1134StopInfoSP
1135StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id)
1136{
1137 return StopInfoSP (new StopInfoBreakpoint (thread, break_id));
1138}
1139
1140StopInfoSP
Jim Ingham36f3b362010-10-14 23:45:03 +00001141StopInfo::CreateStopReasonWithBreakpointSiteID (Thread &thread, break_id_t break_id, bool should_stop)
1142{
1143 return StopInfoSP (new StopInfoBreakpoint (thread, break_id, should_stop));
1144}
1145
1146StopInfoSP
Greg Claytonf4b47e12010-08-04 01:40:35 +00001147StopInfo::CreateStopReasonWithWatchpointID (Thread &thread, break_id_t watch_id)
1148{
1149 return StopInfoSP (new StopInfoWatchpoint (thread, watch_id));
1150}
1151
1152StopInfoSP
1153StopInfo::CreateStopReasonWithSignal (Thread &thread, int signo)
1154{
1155 return StopInfoSP (new StopInfoUnixSignal (thread, signo));
1156}
1157
1158StopInfoSP
1159StopInfo::CreateStopReasonToTrace (Thread &thread)
1160{
1161 return StopInfoSP (new StopInfoTrace (thread));
1162}
1163
1164StopInfoSP
Jim Ingham30fadaf2014-07-08 01:07:32 +00001165StopInfo::CreateStopReasonWithPlan (ThreadPlanSP &plan_sp,
1166 ValueObjectSP return_valobj_sp,
1167 ClangExpressionVariableSP expression_variable_sp)
Greg Claytonf4b47e12010-08-04 01:40:35 +00001168{
Jim Ingham30fadaf2014-07-08 01:07:32 +00001169 return StopInfoSP (new StopInfoThreadPlan (plan_sp, return_valobj_sp, expression_variable_sp));
Greg Claytonf4b47e12010-08-04 01:40:35 +00001170}
Greg Claytona658fd22011-06-04 01:26:29 +00001171
1172StopInfoSP
1173StopInfo::CreateStopReasonWithException (Thread &thread, const char *description)
1174{
1175 return StopInfoSP (new StopInfoException (thread, description));
1176}
Jim Ingham73ca05a2011-12-17 01:35:57 +00001177
Greg Clayton90ba8112012-12-05 00:16:59 +00001178StopInfoSP
1179StopInfo::CreateStopReasonWithExec (Thread &thread)
1180{
1181 return StopInfoSP (new StopInfoExec (thread));
1182}
1183
Jim Ingham73ca05a2011-12-17 01:35:57 +00001184ValueObjectSP
1185StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp)
1186{
1187 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete)
1188 {
1189 StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
1190 return plan_stop_info->GetReturnValueObject();
1191 }
1192 else
1193 return ValueObjectSP();
1194}
Jim Ingham30fadaf2014-07-08 01:07:32 +00001195
1196ClangExpressionVariableSP
1197StopInfo::GetExpressionVariable(StopInfoSP &stop_info_sp)
1198{
1199 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonPlanComplete)
1200 {
1201 StopInfoThreadPlan *plan_stop_info = static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
1202 return plan_stop_info->GetExpressionVariable();
1203 }
1204 else
1205 return ClangExpressionVariableSP();
1206}