blob: 04142b268e489f4111656b8fcd10241c73f03fe1 [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)
257 return false;
258
259 if (condition_hash != m_condition_hash ||
260 !m_user_expression_sp ||
261 !m_user_expression_sp->MatchesContext(exe_ctx))
262 {
263 m_user_expression_sp.reset(new ClangUserExpression(condition_text,
264 NULL,
265 lldb::eLanguageTypeUnknown,
266 ClangUserExpression::eResultTypeAny));
267
268 StreamString errors;
269
270 if (!m_user_expression_sp->Parse(errors,
271 exe_ctx,
272 eExecutionPolicyOnlyWhenNeeded,
273 true))
274 {
275 error.SetErrorStringWithFormat("Couldn't parse conditional expression:\n%s",
276 errors.GetData());
277 m_user_expression_sp.reset();
278 return false;
279 }
280
281 m_condition_hash = condition_hash;
282 }
283
284 // We need to make sure the user sees any parse errors in their condition, so we'll hook the
285 // constructor errors up to the debugger's Async I/O.
286
287 ValueObjectSP result_value_sp;
288 const bool unwind_on_error = true;
289 const bool ignore_breakpoints = true;
290 const bool try_all_threads = true;
291
292 Error expr_error;
293
294 StreamString execution_errors;
295
296 ClangExpressionVariableSP result_variable_sp;
297
298 ExecutionResults result_code =
299 m_user_expression_sp->Execute(execution_errors,
300 exe_ctx,
301 unwind_on_error,
302 ignore_breakpoints,
303 m_user_expression_sp,
304 result_variable_sp,
305 try_all_threads,
306 ClangUserExpression::kDefaultTimeout);
307
308 bool ret;
309
310 if (result_code == eExecutionCompleted)
311 {
312 result_value_sp = result_variable_sp->GetValueObject();
313
314 if (result_value_sp)
315 {
316 Scalar scalar_value;
317 if (result_value_sp->ResolveValue (scalar_value))
318 {
319 if (scalar_value.ULongLong(1) == 0)
320 ret = false;
321 else
322 ret = true;
323 if (log)
324 log->Printf("Condition successfully evaluated, result is %s.\n",
325 ret ? "true" : "false");
326 }
327 else
328 {
329 ret = false;
330 error.SetErrorString("Failed to get an integer result from the expression");
331 }
332 }
333 else
334 {
335 ret = false;
336 error.SetErrorString("Failed to get any result from the expression");
337 }
338 }
339 else
340 {
341 ret = false;
342 error.SetErrorStringWithFormat("Couldn't execute expression:\n%s", execution_errors.GetData());
343 }
344
345 return ret;
Jim Ingham36f3b362010-10-14 23:45:03 +0000346}
347
Greg Claytonc982c762010-07-09 20:39:50 +0000348uint32_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000349BreakpointLocation::GetIgnoreCount ()
350{
Jim Ingham05407f62010-06-22 21:12:54 +0000351 return GetOptionsNoCreate()->GetIgnoreCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000352}
353
354void
Greg Claytonc982c762010-07-09 20:39:50 +0000355BreakpointLocation::SetIgnoreCount (uint32_t n)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000356{
357 GetLocationOptions()->SetIgnoreCount(n);
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000358 SendBreakpointLocationChangedEvent (eBreakpointEventTypeIgnoreChanged);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000359}
360
Jim Ingham0fd1b752012-06-26 22:27:55 +0000361void
362BreakpointLocation::DecrementIgnoreCount()
363{
364 if (m_options_ap.get() != NULL)
365 {
366 uint32_t loc_ignore = m_options_ap->GetIgnoreCount();
367 if (loc_ignore != 0)
368 m_options_ap->SetIgnoreCount(loc_ignore - 1);
369 }
370}
371
372bool
373BreakpointLocation::IgnoreCountShouldStop()
374{
375 if (m_options_ap.get() != NULL)
376 {
377 uint32_t loc_ignore = m_options_ap->GetIgnoreCount();
378 if (loc_ignore != 0)
379 {
380 m_owner.DecrementIgnoreCount();
381 DecrementIgnoreCount(); // Have to decrement our owners' ignore count, since it won't get a
382 // chance to.
383 return false;
384 }
385 }
386 return true;
387}
388
Jim Ingham1b54c882010-06-16 02:00:15 +0000389const BreakpointOptions *
Jim Ingham05407f62010-06-22 21:12:54 +0000390BreakpointLocation::GetOptionsNoCreate () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000391{
392 if (m_options_ap.get() != NULL)
393 return m_options_ap.get();
394 else
395 return m_owner.GetOptions ();
396}
397
398BreakpointOptions *
399BreakpointLocation::GetLocationOptions ()
400{
Jim Ingham01363092010-06-18 01:00:58 +0000401 // If we make the copy we don't copy the callbacks because that is potentially
402 // expensive and we don't want to do that for the simple case where someone is
403 // just disabling the location.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404 if (m_options_ap.get() == NULL)
Jim Ingham01363092010-06-18 01:00:58 +0000405 m_options_ap.reset(BreakpointOptions::CopyOptionsNoCallback(*m_owner.GetOptions ()));
406
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407 return m_options_ap.get();
408}
409
Jim Ingham1b54c882010-06-16 02:00:15 +0000410bool
411BreakpointLocation::ValidForThisThread (Thread *thread)
412{
Jim Ingham05407f62010-06-22 21:12:54 +0000413 return thread->MatchesSpec(GetOptionsNoCreate()->GetThreadSpecNoCreate());
Jim Ingham1b54c882010-06-16 02:00:15 +0000414}
415
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416// RETURNS - true if we should stop at this breakpoint, false if we
Jim Ingham1b54c882010-06-16 02:00:15 +0000417// should continue. Note, we don't check the thread spec for the breakpoint
418// here, since if the breakpoint is not for this thread, then the event won't
419// even get reported, so the check is redundant.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420
421bool
422BreakpointLocation::ShouldStop (StoppointCallbackContext *context)
423{
424 bool should_stop = true;
Greg Clayton5160ce52013-03-27 23:08:40 +0000425 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426
Johnny Chenfab7a912012-01-23 23:03:59 +0000427 IncrementHitCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428
429 if (!IsEnabled())
430 return false;
431
Jim Ingham0fd1b752012-06-26 22:27:55 +0000432 if (!IgnoreCountShouldStop())
433 return false;
434
435 if (!m_owner.IgnoreCountShouldStop())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436 return false;
437
Jim Ingham36f3b362010-10-14 23:45:03 +0000438 // We only run synchronous callbacks in ShouldStop:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 context->is_synchronous = true;
440 should_stop = InvokeCallback (context);
Jim Ingham36f3b362010-10-14 23:45:03 +0000441
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000442 if (log)
Jim Ingham36f3b362010-10-14 23:45:03 +0000443 {
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000444 StreamString s;
445 GetDescription (&s, lldb::eDescriptionLevelVerbose);
446 log->Printf ("Hit breakpoint location: %s, %s.\n", s.GetData(), should_stop ? "stopping" : "continuing");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000447 }
Jim Ingham5b52f0c2011-06-02 23:58:26 +0000448
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449 return should_stop;
450}
451
452bool
453BreakpointLocation::IsResolved () const
454{
455 return m_bp_site_sp.get() != NULL;
456}
457
Jim Ingham36f3b362010-10-14 23:45:03 +0000458lldb::BreakpointSiteSP
459BreakpointLocation::GetBreakpointSite() const
460{
461 return m_bp_site_sp;
462}
463
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464bool
465BreakpointLocation::ResolveBreakpointSite ()
466{
467 if (m_bp_site_sp)
468 return true;
469
Greg Claytonf5e56de2010-09-14 23:36:40 +0000470 Process *process = m_owner.GetTarget().GetProcessSP().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471 if (process == NULL)
472 return false;
473
Greg Claytonf5e56de2010-09-14 23:36:40 +0000474 if (m_owner.GetTarget().GetSectionLoadList().IsEmpty())
475 return false;
476
Greg Claytone1cd1be2012-01-29 20:56:30 +0000477 lldb::break_id_t new_id = process->CreateBreakpointSite (shared_from_this(), false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478
Stephen Wilson50bd94f2010-07-17 00:56:13 +0000479 if (new_id == LLDB_INVALID_BREAK_ID)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480 {
Greg Clayton5160ce52013-03-27 23:08:40 +0000481 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000482 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000483 log->Warning ("Tried to add breakpoint site at 0x%" PRIx64 " but it was already present.\n",
Greg Claytonf3ef3d22011-05-22 22:46:53 +0000484 m_address.GetOpcodeLoadAddress (&m_owner.GetTarget()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000485 return false;
486 }
487
488 return true;
489}
490
491bool
492BreakpointLocation::SetBreakpointSite (BreakpointSiteSP& bp_site_sp)
493{
494 m_bp_site_sp = bp_site_sp;
495 return true;
496}
497
498bool
499BreakpointLocation::ClearBreakpointSite ()
500{
501 if (m_bp_site_sp.get())
502 {
Jim Ingham01363092010-06-18 01:00:58 +0000503 m_owner.GetTarget().GetProcessSP()->RemoveOwnerFromBreakpointSite (GetBreakpoint().GetID(),
504 GetID(), m_bp_site_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505 m_bp_site_sp.reset();
506 return true;
507 }
508 return false;
509}
510
511void
512BreakpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level)
513{
514 SymbolContext sc;
Jim Ingham1391cc72012-09-22 00:04:04 +0000515
516 // If the description level is "initial" then the breakpoint is printing out our initial state,
517 // and we should let it decide how it wants to print our label.
518 if (level != eDescriptionLevelInitial)
519 {
520 s->Indent();
521 BreakpointID::GetCanonicalReference(s, m_owner.GetID(), GetID());
522 }
523
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524 if (level == lldb::eDescriptionLevelBrief)
525 return;
526
Jim Ingham1391cc72012-09-22 00:04:04 +0000527 if (level != eDescriptionLevelInitial)
528 s->PutCString(": ");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000529
530 if (level == lldb::eDescriptionLevelVerbose)
531 s->IndentMore();
532
533 if (m_address.IsSectionOffset())
534 {
535 m_address.CalculateSymbolContext(&sc);
536
Jim Ingham1391cc72012-09-22 00:04:04 +0000537 if (level == lldb::eDescriptionLevelFull || level == eDescriptionLevelInitial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538 {
539 s->PutCString("where = ");
Greg Clayton2cad65a2010-09-03 17:10:42 +0000540 sc.DumpStopContext (s, m_owner.GetTarget().GetProcessSP().get(), m_address, false, true, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000541 }
542 else
543 {
544 if (sc.module_sp)
545 {
546 s->EOL();
547 s->Indent("module = ");
548 sc.module_sp->GetFileSpec().Dump (s);
549 }
550
551 if (sc.comp_unit != NULL)
552 {
553 s->EOL();
554 s->Indent("compile unit = ");
Jim Ingham517b3b22010-10-27 22:58:34 +0000555 static_cast<FileSpec*>(sc.comp_unit)->GetFilename().Dump (s);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000556
557 if (sc.function != NULL)
558 {
559 s->EOL();
560 s->Indent("function = ");
561 s->PutCString (sc.function->GetMangled().GetName().AsCString("<unknown>"));
562 }
563
564 if (sc.line_entry.line > 0)
565 {
566 s->EOL();
567 s->Indent("location = ");
Greg Clayton6dadd502010-09-02 21:44:10 +0000568 sc.line_entry.DumpStopContext (s, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569 }
570
571 }
572 else
573 {
574 // If we don't have a comp unit, see if we have a symbol we can print.
575 if (sc.symbol)
576 {
577 s->EOL();
578 s->Indent("symbol = ");
579 s->PutCString(sc.symbol->GetMangled().GetName().AsCString("<unknown>"));
580 }
581 }
582 }
583 }
584
585 if (level == lldb::eDescriptionLevelVerbose)
586 {
587 s->EOL();
588 s->Indent();
589 }
Jim Ingham1391cc72012-09-22 00:04:04 +0000590
591 if (m_address.IsSectionOffset() && (level == eDescriptionLevelFull || level == eDescriptionLevelInitial))
592 s->Printf (", ");
593 s->Printf ("address = ");
594
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595 ExecutionContextScope *exe_scope = NULL;
596 Target *target = &m_owner.GetTarget();
597 if (target)
598 exe_scope = target->GetProcessSP().get();
599 if (exe_scope == NULL)
600 exe_scope = target;
601
Jim Ingham1391cc72012-09-22 00:04:04 +0000602 if (eDescriptionLevelInitial)
603 m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress);
604 else
605 m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000606
607 if (level == lldb::eDescriptionLevelVerbose)
608 {
609 s->EOL();
610 s->Indent();
611 s->Printf("resolved = %s\n", IsResolved() ? "true" : "false");
612
613 s->Indent();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000614 s->Printf ("hit count = %-4u\n", GetHitCount());
615
616 if (m_options_ap.get())
617 {
Jim Ingham01363092010-06-18 01:00:58 +0000618 s->Indent();
619 m_options_ap->GetDescription (s, level);
620 s->EOL();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000621 }
622 s->IndentLess();
623 }
Jim Ingham1391cc72012-09-22 00:04:04 +0000624 else if (level != eDescriptionLevelInitial)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000625 {
Jim Ingham01363092010-06-18 01:00:58 +0000626 s->Printf(", %sresolved, hit count = %u ",
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000627 (IsResolved() ? "" : "un"),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000628 GetHitCount());
Jim Ingham01363092010-06-18 01:00:58 +0000629 if (m_options_ap.get())
630 {
631 m_options_ap->GetDescription (s, level);
632 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000633 }
634}
635
636void
637BreakpointLocation::Dump(Stream *s) const
638{
639 if (s == NULL)
640 return;
641
Daniel Malead01b2952012-11-29 21:49:15 +0000642 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 +0000643 "hw_index = %i hit_count = %-4u ignore_count = %-4u",
Johnny Chen9ec3c4f2012-01-26 00:08:14 +0000644 GetID(),
645 GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetTID(),
646 (uint64_t) m_address.GetOpcodeLoadAddress (&m_owner.GetTarget()),
Johnny Chen50df1f92012-01-30 22:48:10 +0000647 (m_options_ap.get() ? m_options_ap->IsEnabled() : m_owner.IsEnabled()) ? "enabled " : "disabled",
Johnny Chen9ec3c4f2012-01-26 00:08:14 +0000648 IsHardware() ? "hardware" : "software",
649 GetHardwareIndex(),
650 GetHitCount(),
651 GetOptionsNoCreate()->GetIgnoreCount());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000652}
Jim Inghame6bc6cb2012-02-08 05:23:15 +0000653
654void
655BreakpointLocation::SendBreakpointLocationChangedEvent (lldb::BreakpointEventType eventKind)
656{
657 if (!m_being_created
658 && !m_owner.IsInternal()
659 && m_owner.GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged))
660 {
661 Breakpoint::BreakpointEventData *data = new Breakpoint::BreakpointEventData (eventKind,
662 m_owner.shared_from_this());
663 data->GetBreakpointLocationCollection().Add (shared_from_this());
664 m_owner.GetTarget().BroadcastEvent (Target::eBroadcastBitBreakpointChanged, data);
665 }
666}
667