blob: fe8267dcacd552491337b7609e3a9abd29b6e469 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- BreakpointLocation.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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012// C Includes
13// C++ Includes
14#include <string>
15
16// Other libraries and framework includes
17// Project includes
Greg Clayton1f746072012-08-29 21:13:06 +000018#include "lldb/lldb-private-log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Breakpoint/BreakpointLocation.h"
20#include "lldb/Breakpoint/BreakpointID.h"
21#include "lldb/Breakpoint/StoppointCallbackContext.h"
Jim Ingham5b52f0c2011-06-02 23:58:26 +000022#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000024#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/StreamString.h"
Greg Clayton1f746072012-08-29 21:13:06 +000026#include "lldb/Symbol/CompileUnit.h"
27#include "lldb/Symbol/Symbol.h"
28#include "lldb/Target/Target.h"
29#include "lldb/Target/Process.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Target/Thread.h"
Jim Ingham1b54c882010-06-16 02:00:15 +000031#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
33using namespace lldb;
34using namespace lldb_private;
35
36BreakpointLocation::BreakpointLocation
37(
38 break_id_t loc_id,
39 Breakpoint &owner,
Greg Claytonc0d34462011-02-05 00:38:04 +000040 const Address &addr,
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041 lldb::tid_t tid,
42 bool hardware
43) :
Greg Claytonf3ef3d22011-05-22 22:46:53 +000044 StoppointLocation (loc_id, addr.GetOpcodeLoadAddress(&owner.GetTarget()), hardware),
Jim Inghame6bc6cb2012-02-08 05:23:15 +000045 m_being_created(true),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046 m_address (addr),
47 m_owner (owner),
48 m_options_ap (),
49 m_bp_site_sp ()
50{
Jim Ingham1b54c882010-06-16 02:00:15 +000051 SetThreadID (tid);
Jim Inghame6bc6cb2012-02-08 05:23:15 +000052 m_being_created = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053}
54
55BreakpointLocation::~BreakpointLocation()
56{
57 ClearBreakpointSite();
58}
59
60lldb::addr_t
Greg Clayton13238c42010-06-14 04:18:27 +000061BreakpointLocation::GetLoadAddress () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062{
Greg Claytonf3ef3d22011-05-22 22:46:53 +000063 return m_address.GetOpcodeLoadAddress (&m_owner.GetTarget());
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064}
65
66Address &
67BreakpointLocation::GetAddress ()
68{
69 return m_address;
70}
71
72Breakpoint &
73BreakpointLocation::GetBreakpoint ()
74{
75 return m_owner;
76}
77
78bool
Johnny Chenfdad6792012-02-01 19:05:20 +000079BreakpointLocation::IsEnabled () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080{
Johnny Chen50df1f92012-01-30 22:48:10 +000081 if (!m_owner.IsEnabled())
82 return false;
83 else if (m_options_ap.get() != NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000084 return m_options_ap->IsEnabled();
85 else
Johnny Chen50df1f92012-01-30 22:48:10 +000086 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087}
88
89void
90BreakpointLocation::SetEnabled (bool enabled)
91{
92 GetLocationOptions()->SetEnabled(enabled);
93 if (enabled)
94 {
95 ResolveBreakpointSite();
96 }
97 else
98 {
99 ClearBreakpointSite();
100 }
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000101 SendBreakpointLocationChangedEvent (enabled ? eBreakpointEventTypeEnabled : eBreakpointEventTypeDisabled);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102}
103
104void
105BreakpointLocation::SetThreadID (lldb::tid_t thread_id)
106{
Jim Ingham1b54c882010-06-16 02:00:15 +0000107 if (thread_id != LLDB_INVALID_THREAD_ID)
108 GetLocationOptions()->SetThreadID(thread_id);
109 else
110 {
111 // If we're resetting this to an invalid thread id, then
112 // don't make an options pointer just to do that.
113 if (m_options_ap.get() != NULL)
114 m_options_ap->SetThreadID (thread_id);
115 }
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000116 SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged);
117}
118
119lldb::tid_t
120BreakpointLocation::GetThreadID ()
121{
122 if (GetOptionsNoCreate()->GetThreadSpecNoCreate())
123 return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetTID();
124 else
125 return LLDB_INVALID_THREAD_ID;
126}
127
128void
129BreakpointLocation::SetThreadIndex (uint32_t index)
130{
131 if (index != 0)
132 GetLocationOptions()->GetThreadSpec()->SetIndex(index);
133 else
134 {
135 // If we're resetting this to an invalid thread id, then
136 // don't make an options pointer just to do that.
137 if (m_options_ap.get() != NULL)
138 m_options_ap->GetThreadSpec()->SetIndex(index);
139 }
140 SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged);
141
142}
143
144uint32_t
145BreakpointLocation::GetThreadIndex() const
146{
147 if (GetOptionsNoCreate()->GetThreadSpecNoCreate())
148 return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetIndex();
149 else
150 return 0;
151}
152
153void
154BreakpointLocation::SetThreadName (const char *thread_name)
155{
156 if (thread_name != NULL)
157 GetLocationOptions()->GetThreadSpec()->SetName(thread_name);
158 else
159 {
160 // If we're resetting this to an invalid thread id, then
161 // don't make an options pointer just to do that.
162 if (m_options_ap.get() != NULL)
163 m_options_ap->GetThreadSpec()->SetName(thread_name);
164 }
165 SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged);
166}
167
168const char *
169BreakpointLocation::GetThreadName () const
170{
171 if (GetOptionsNoCreate()->GetThreadSpecNoCreate())
172 return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetName();
173 else
174 return NULL;
175}
176
177void
178BreakpointLocation::SetQueueName (const char *queue_name)
179{
180 if (queue_name != NULL)
181 GetLocationOptions()->GetThreadSpec()->SetQueueName(queue_name);
182 else
183 {
184 // If we're resetting this to an invalid thread id, then
185 // don't make an options pointer just to do that.
186 if (m_options_ap.get() != NULL)
187 m_options_ap->GetThreadSpec()->SetQueueName(queue_name);
188 }
189 SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged);
190}
191
192const char *
193BreakpointLocation::GetQueueName () const
194{
195 if (GetOptionsNoCreate()->GetThreadSpecNoCreate())
196 return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetQueueName();
197 else
198 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199}
200
201bool
202BreakpointLocation::InvokeCallback (StoppointCallbackContext *context)
203{
Jim Ingham01363092010-06-18 01:00:58 +0000204 if (m_options_ap.get() != NULL && m_options_ap->HasCallback())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205 return m_options_ap->InvokeCallback (context, m_owner.GetID(), GetID());
Jim Ingham01363092010-06-18 01:00:58 +0000206 else
207 return m_owner.InvokeCallback (context, GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208}
209
210void
211BreakpointLocation::SetCallback (BreakpointHitCallback callback, void *baton,
212 bool is_synchronous)
213{
214 // The default "Baton" class will keep a copy of "baton" and won't free
215 // or delete it when it goes goes out of scope.
216 GetLocationOptions()->SetCallback(callback, BatonSP (new Baton(baton)), is_synchronous);
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000217 SendBreakpointLocationChangedEvent (eBreakpointEventTypeCommandChanged);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000218}
219
220void
221BreakpointLocation::SetCallback (BreakpointHitCallback callback, const BatonSP &baton_sp,
222 bool is_synchronous)
223{
224 GetLocationOptions()->SetCallback (callback, baton_sp, is_synchronous);
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000225 SendBreakpointLocationChangedEvent (eBreakpointEventTypeCommandChanged);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000226}
227
Jim Ingham36f3b362010-10-14 23:45:03 +0000228
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229void
230BreakpointLocation::ClearCallback ()
231{
232 GetLocationOptions()->ClearCallback();
233}
234
Jim Ingham36f3b362010-10-14 23:45:03 +0000235void
236BreakpointLocation::SetCondition (const char *condition)
237{
238 GetLocationOptions()->SetCondition (condition);
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000239 SendBreakpointLocationChangedEvent (eBreakpointEventTypeConditionChanged);
Jim Ingham36f3b362010-10-14 23:45:03 +0000240}
241
Jim Ingham36f3b362010-10-14 23:45:03 +0000242const char *
Sean Callanan3dbf3462013-04-19 07:09:15 +0000243BreakpointLocation::GetConditionText (size_t *hash) const
Jim Ingham36f3b362010-10-14 23:45:03 +0000244{
Sean Callanan3dbf3462013-04-19 07:09:15 +0000245 return GetOptionsNoCreate()->GetConditionText(hash);
246}
247
248bool
249BreakpointLocation::ConditionSaysStop (ExecutionContext &exe_ctx, Error &error)
250{
251 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
252
253 size_t condition_hash;
254 const char *condition_text = GetConditionText(&condition_hash);
255
256 if (!condition_text)
Sean Callananec537a22013-05-10 21:58:45 +0000257 {
258 m_user_expression_sp.reset();
Sean Callanan3dbf3462013-04-19 07:09:15 +0000259 return false;
Sean Callananec537a22013-05-10 21:58:45 +0000260 }
Sean Callanan3dbf3462013-04-19 07:09:15 +0000261
262 if (condition_hash != m_condition_hash ||
263 !m_user_expression_sp ||
264 !m_user_expression_sp->MatchesContext(exe_ctx))
265 {
266 m_user_expression_sp.reset(new ClangUserExpression(condition_text,
267 NULL,
268 lldb::eLanguageTypeUnknown,
269 ClangUserExpression::eResultTypeAny));
270
271 StreamString errors;
272
273 if (!m_user_expression_sp->Parse(errors,
274 exe_ctx,
275 eExecutionPolicyOnlyWhenNeeded,
276 true))
277 {
278 error.SetErrorStringWithFormat("Couldn't parse conditional expression:\n%s",
279 errors.GetData());
280 m_user_expression_sp.reset();
281 return false;
282 }
283
284 m_condition_hash = condition_hash;
285 }
286
287 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
288 // constructor errors up to the debugger's Async I/O.
289
290 ValueObjectSP result_value_sp;
291 const bool unwind_on_error = true;
292 const bool ignore_breakpoints = true;
293 const bool try_all_threads = true;
294
295 Error expr_error;
296
297 StreamString execution_errors;
298
299 ClangExpressionVariableSP result_variable_sp;
300
301 ExecutionResults result_code =
302 m_user_expression_sp->Execute(execution_errors,
303 exe_ctx,
304 unwind_on_error,
305 ignore_breakpoints,
306 m_user_expression_sp,
307 result_variable_sp,
308 try_all_threads,
309 ClangUserExpression::kDefaultTimeout);
310
311 bool ret;
312
313 if (result_code == eExecutionCompleted)
314 {
315 result_value_sp = result_variable_sp->GetValueObject();
316
317 if (result_value_sp)
318 {
319 Scalar scalar_value;
320 if (result_value_sp->ResolveValue (scalar_value))
321 {
322 if (scalar_value.ULongLong(1) == 0)
323 ret = false;
324 else
325 ret = true;
326 if (log)
327 log->Printf("Condition successfully evaluated, result is %s.\n",
328 ret ? "true" : "false");
329 }
330 else
331 {
332 ret = false;
333 error.SetErrorString("Failed to get an integer result from the expression");
334 }
335 }
336 else
337 {
338 ret = false;
339 error.SetErrorString("Failed to get any result from the expression");
340 }
341 }
342 else
343 {
344 ret = false;
345 error.SetErrorStringWithFormat("Couldn't execute expression:\n%s", execution_errors.GetData());
346 }
347
348 return ret;
Jim Ingham36f3b362010-10-14 23:45:03 +0000349}
350
Greg Claytonc982c762010-07-09 20:39:50 +0000351uint32_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000352BreakpointLocation::GetIgnoreCount ()
353{
Jim Ingham05407f62010-06-22 21:12:54 +0000354 return GetOptionsNoCreate()->GetIgnoreCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000355}
356
357void
Greg Claytonc982c762010-07-09 20:39:50 +0000358BreakpointLocation::SetIgnoreCount (uint32_t n)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000359{
360 GetLocationOptions()->SetIgnoreCount(n);
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000361 SendBreakpointLocationChangedEvent (eBreakpointEventTypeIgnoreChanged);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000362}
363
Jim Ingham0fd1b752012-06-26 22:27:55 +0000364void
365BreakpointLocation::DecrementIgnoreCount()
366{
367 if (m_options_ap.get() != NULL)
368 {
369 uint32_t loc_ignore = m_options_ap->GetIgnoreCount();
370 if (loc_ignore != 0)
371 m_options_ap->SetIgnoreCount(loc_ignore - 1);
372 }
373}
374
375bool
376BreakpointLocation::IgnoreCountShouldStop()
377{
378 if (m_options_ap.get() != NULL)
379 {
380 uint32_t loc_ignore = m_options_ap->GetIgnoreCount();
381 if (loc_ignore != 0)
382 {
383 m_owner.DecrementIgnoreCount();
384 DecrementIgnoreCount(); // Have to decrement our owners' ignore count, since it won't get a
385 // chance to.
386 return false;
387 }
388 }
389 return true;
390}
391
Jim Ingham1b54c882010-06-16 02:00:15 +0000392const BreakpointOptions *
Jim Ingham05407f62010-06-22 21:12:54 +0000393BreakpointLocation::GetOptionsNoCreate () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000394{
395 if (m_options_ap.get() != NULL)
396 return m_options_ap.get();
397 else
398 return m_owner.GetOptions ();
399}
400
401BreakpointOptions *
402BreakpointLocation::GetLocationOptions ()
403{
Jim Ingham01363092010-06-18 01:00:58 +0000404 // If we make the copy we don't copy the callbacks because that is potentially
405 // expensive and we don't want to do that for the simple case where someone is
406 // just disabling the location.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407 if (m_options_ap.get() == NULL)
Jim Ingham01363092010-06-18 01:00:58 +0000408 m_options_ap.reset(BreakpointOptions::CopyOptionsNoCallback(*m_owner.GetOptions ()));
409
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410 return m_options_ap.get();
411}
412
Jim Ingham1b54c882010-06-16 02:00:15 +0000413bool
414BreakpointLocation::ValidForThisThread (Thread *thread)
415{
Jim Ingham05407f62010-06-22 21:12:54 +0000416 return thread->MatchesSpec(GetOptionsNoCreate()->GetThreadSpecNoCreate());
Jim Ingham1b54c882010-06-16 02:00:15 +0000417}
418
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419// RETURNS - true if we should stop at this breakpoint, false if we
Jim Ingham1b54c882010-06-16 02:00:15 +0000420// should continue. Note, we don't check the thread spec for the breakpoint
421// here, since if the breakpoint is not for this thread, then the event won't
422// even get reported, so the check is redundant.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423
424bool
425BreakpointLocation::ShouldStop (StoppointCallbackContext *context)
426{
427 bool should_stop = true;
Greg Clayton5160ce52013-03-27 23:08:40 +0000428 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429
Johnny Chenfab7a912012-01-23 23:03:59 +0000430 IncrementHitCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000431
432 if (!IsEnabled())
433 return false;
434
Jim Ingham0fd1b752012-06-26 22:27:55 +0000435 if (!IgnoreCountShouldStop())
436 return false;
437
438 if (!m_owner.IgnoreCountShouldStop())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 return false;
440
Jim Ingham36f3b362010-10-14 23:45:03 +0000441 // We only run synchronous callbacks in ShouldStop:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000442 context->is_synchronous = true;
443 should_stop = InvokeCallback (context);
Jim Ingham36f3b362010-10-14 23:45:03 +0000444
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000445 if (log)
Jim Ingham36f3b362010-10-14 23:45:03 +0000446 {
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000447 StreamString s;
448 GetDescription (&s, lldb::eDescriptionLevelVerbose);
449 log->Printf ("Hit breakpoint location: %s, %s.\n", s.GetData(), should_stop ? "stopping" : "continuing");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450 }
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000451
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452 return should_stop;
453}
454
455bool
456BreakpointLocation::IsResolved () const
457{
458 return m_bp_site_sp.get() != NULL;
459}
460
Jim Ingham36f3b362010-10-14 23:45:03 +0000461lldb::BreakpointSiteSP
462BreakpointLocation::GetBreakpointSite() const
463{
464 return m_bp_site_sp;
465}
466
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000467bool
468BreakpointLocation::ResolveBreakpointSite ()
469{
470 if (m_bp_site_sp)
471 return true;
472
Greg Claytonf5e56de2010-09-14 23:36:40 +0000473 Process *process = m_owner.GetTarget().GetProcessSP().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000474 if (process == NULL)
475 return false;
476
Greg Claytonf5e56de2010-09-14 23:36:40 +0000477 if (m_owner.GetTarget().GetSectionLoadList().IsEmpty())
478 return false;
479
Greg Claytone1cd1be2012-01-29 20:56:30 +0000480 lldb::break_id_t new_id = process->CreateBreakpointSite (shared_from_this(), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481
Stephen Wilson50bd94f2010-07-17 00:56:13 +0000482 if (new_id == LLDB_INVALID_BREAK_ID)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000484 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000485 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000486 log->Warning ("Tried to add breakpoint site at 0x%" PRIx64 " but it was already present.\n",
Greg Claytonf3ef3d22011-05-22 22:46:53 +0000487 m_address.GetOpcodeLoadAddress (&m_owner.GetTarget()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488 return false;
489 }
490
491 return true;
492}
493
494bool
495BreakpointLocation::SetBreakpointSite (BreakpointSiteSP& bp_site_sp)
496{
497 m_bp_site_sp = bp_site_sp;
498 return true;
499}
500
501bool
502BreakpointLocation::ClearBreakpointSite ()
503{
504 if (m_bp_site_sp.get())
505 {
Jim Ingham01363092010-06-18 01:00:58 +0000506 m_owner.GetTarget().GetProcessSP()->RemoveOwnerFromBreakpointSite (GetBreakpoint().GetID(),
507 GetID(), m_bp_site_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000508 m_bp_site_sp.reset();
509 return true;
510 }
511 return false;
512}
513
514void
515BreakpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level)
516{
517 SymbolContext sc;
Jim Ingham1391cc72012-09-22 00:04:04 +0000518
519 // If the description level is "initial" then the breakpoint is printing out our initial state,
520 // and we should let it decide how it wants to print our label.
521 if (level != eDescriptionLevelInitial)
522 {
523 s->Indent();
524 BreakpointID::GetCanonicalReference(s, m_owner.GetID(), GetID());
525 }
526
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527 if (level == lldb::eDescriptionLevelBrief)
528 return;
529
Jim Ingham1391cc72012-09-22 00:04:04 +0000530 if (level != eDescriptionLevelInitial)
531 s->PutCString(": ");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532
533 if (level == lldb::eDescriptionLevelVerbose)
534 s->IndentMore();
535
536 if (m_address.IsSectionOffset())
537 {
538 m_address.CalculateSymbolContext(&sc);
539
Jim Ingham1391cc72012-09-22 00:04:04 +0000540 if (level == lldb::eDescriptionLevelFull || level == eDescriptionLevelInitial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000541 {
542 s->PutCString("where = ");
Greg Clayton2cad65a2010-09-03 17:10:42 +0000543 sc.DumpStopContext (s, m_owner.GetTarget().GetProcessSP().get(), m_address, false, true, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000544 }
545 else
546 {
547 if (sc.module_sp)
548 {
549 s->EOL();
550 s->Indent("module = ");
551 sc.module_sp->GetFileSpec().Dump (s);
552 }
553
554 if (sc.comp_unit != NULL)
555 {
556 s->EOL();
557 s->Indent("compile unit = ");
Jim Ingham517b3b22010-10-27 22:58:34 +0000558 static_cast<FileSpec*>(sc.comp_unit)->GetFilename().Dump (s);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559
560 if (sc.function != NULL)
561 {
562 s->EOL();
563 s->Indent("function = ");
564 s->PutCString (sc.function->GetMangled().GetName().AsCString("<unknown>"));
565 }
566
567 if (sc.line_entry.line > 0)
568 {
569 s->EOL();
570 s->Indent("location = ");
Greg Clayton6dadd502010-09-02 21:44:10 +0000571 sc.line_entry.DumpStopContext (s, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000572 }
573
574 }
575 else
576 {
577 // If we don't have a comp unit, see if we have a symbol we can print.
578 if (sc.symbol)
579 {
580 s->EOL();
581 s->Indent("symbol = ");
582 s->PutCString(sc.symbol->GetMangled().GetName().AsCString("<unknown>"));
583 }
584 }
585 }
586 }
587
588 if (level == lldb::eDescriptionLevelVerbose)
589 {
590 s->EOL();
591 s->Indent();
592 }
Jim Ingham1391cc72012-09-22 00:04:04 +0000593
594 if (m_address.IsSectionOffset() && (level == eDescriptionLevelFull || level == eDescriptionLevelInitial))
595 s->Printf (", ");
596 s->Printf ("address = ");
597
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000598 ExecutionContextScope *exe_scope = NULL;
599 Target *target = &m_owner.GetTarget();
600 if (target)
601 exe_scope = target->GetProcessSP().get();
602 if (exe_scope == NULL)
603 exe_scope = target;
604
Jim Ingham1391cc72012-09-22 00:04:04 +0000605 if (eDescriptionLevelInitial)
606 m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress);
607 else
608 m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000609
610 if (level == lldb::eDescriptionLevelVerbose)
611 {
612 s->EOL();
613 s->Indent();
614 s->Printf("resolved = %s\n", IsResolved() ? "true" : "false");
615
616 s->Indent();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000617 s->Printf ("hit count = %-4u\n", GetHitCount());
618
619 if (m_options_ap.get())
620 {
Jim Ingham01363092010-06-18 01:00:58 +0000621 s->Indent();
622 m_options_ap->GetDescription (s, level);
623 s->EOL();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000624 }
625 s->IndentLess();
626 }
Jim Ingham1391cc72012-09-22 00:04:04 +0000627 else if (level != eDescriptionLevelInitial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000628 {
Jim Ingham01363092010-06-18 01:00:58 +0000629 s->Printf(", %sresolved, hit count = %u ",
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000630 (IsResolved() ? "" : "un"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000631 GetHitCount());
Jim Ingham01363092010-06-18 01:00:58 +0000632 if (m_options_ap.get())
633 {
634 m_options_ap->GetDescription (s, level);
635 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636 }
637}
638
639void
640BreakpointLocation::Dump(Stream *s) const
641{
642 if (s == NULL)
643 return;
644
Daniel Malead01b2952012-11-29 21:49:15 +0000645 s->Printf("BreakpointLocation %u: tid = %4.4" PRIx64 " load addr = 0x%8.8" PRIx64 " state = %s type = %s breakpoint "
Jim Ingham01363092010-06-18 01:00:58 +0000646 "hw_index = %i hit_count = %-4u ignore_count = %-4u",
Johnny Chen9ec3c4f2012-01-26 00:08:14 +0000647 GetID(),
648 GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetTID(),
649 (uint64_t) m_address.GetOpcodeLoadAddress (&m_owner.GetTarget()),
Johnny Chen50df1f92012-01-30 22:48:10 +0000650 (m_options_ap.get() ? m_options_ap->IsEnabled() : m_owner.IsEnabled()) ? "enabled " : "disabled",
Johnny Chen9ec3c4f2012-01-26 00:08:14 +0000651 IsHardware() ? "hardware" : "software",
652 GetHardwareIndex(),
653 GetHitCount(),
654 GetOptionsNoCreate()->GetIgnoreCount());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000655}
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000656
657void
658BreakpointLocation::SendBreakpointLocationChangedEvent (lldb::BreakpointEventType eventKind)
659{
660 if (!m_being_created
661 && !m_owner.IsInternal()
662 && m_owner.GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged))
663 {
664 Breakpoint::BreakpointEventData *data = new Breakpoint::BreakpointEventData (eventKind,
665 m_owner.shared_from_this());
666 data->GetBreakpointLocationCollection().Add (shared_from_this());
667 m_owner.GetTarget().BroadcastEvent (Target::eBroadcastBitBreakpointChanged, data);
668 }
669}
670