blob: 62e1b248280f7c42bf715d9dfe01409bed8ec99a [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- Breakpoint.cpp ------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10
11// C Includes
12// C++ Includes
13// Other libraries and framework includes
14// Project includes
15
16#include "lldb/Core/Address.h"
17#include "lldb/Breakpoint/Breakpoint.h"
18#include "lldb/Breakpoint/BreakpointLocation.h"
Johnny Chena62ad7c2010-10-28 17:27:46 +000019#include "lldb/Breakpoint/BreakpointLocationCollection.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Breakpoint/BreakpointResolver.h"
Johnny Chena62ad7c2010-10-28 17:27:46 +000021#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Core/Log.h"
23#include "lldb/Core/ModuleList.h"
24#include "lldb/Core/SearchFilter.h"
25#include "lldb/Core/Stream.h"
26#include "lldb/Core/StreamString.h"
27#include "lldb/Symbol/SymbolContext.h"
28#include "lldb/Target/Target.h"
Jim Ingham3c7b5b92010-06-16 02:00:15 +000029#include "lldb/Target/ThreadSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000030#include "lldb/lldb-private-log.h"
Johnny Chena62ad7c2010-10-28 17:27:46 +000031#include "llvm/Support/Casting.h"
Chris Lattner24943d22010-06-08 16:52:24 +000032
33using namespace lldb;
34using namespace lldb_private;
Johnny Chena62ad7c2010-10-28 17:27:46 +000035using namespace llvm;
Chris Lattner24943d22010-06-08 16:52:24 +000036
37const ConstString &
38Breakpoint::GetEventIdentifier ()
39{
40 static ConstString g_identifier("event-identifier.breakpoint.changed");
41 return g_identifier;
42}
43
44//----------------------------------------------------------------------
45// Breakpoint constructor
46//----------------------------------------------------------------------
47Breakpoint::Breakpoint(Target &target, SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp) :
Jim Ingham28e23862012-02-08 05:23:15 +000048 m_being_created(true),
Chris Lattner24943d22010-06-08 16:52:24 +000049 m_target (target),
50 m_filter_sp (filter_sp),
51 m_resolver_sp (resolver_sp),
52 m_options (),
Jim Ingham28e23862012-02-08 05:23:15 +000053 m_locations (*this)
Chris Lattner24943d22010-06-08 16:52:24 +000054{
Jim Ingham28e23862012-02-08 05:23:15 +000055 m_being_created = false;
Chris Lattner24943d22010-06-08 16:52:24 +000056}
57
58//----------------------------------------------------------------------
59// Destructor
60//----------------------------------------------------------------------
61Breakpoint::~Breakpoint()
62{
63}
64
65bool
66Breakpoint::IsInternal () const
67{
68 return LLDB_BREAK_ID_IS_INTERNAL(m_bid);
69}
70
71
72
73Target&
74Breakpoint::GetTarget ()
75{
76 return m_target;
77}
78
79const Target&
80Breakpoint::GetTarget () const
81{
82 return m_target;
83}
84
85BreakpointLocationSP
Greg Clayton19a1ab82011-02-05 00:38:04 +000086Breakpoint::AddLocation (const Address &addr, bool *new_location)
Chris Lattner24943d22010-06-08 16:52:24 +000087{
Jim Ingham28e23862012-02-08 05:23:15 +000088 return m_locations.AddLocation (addr, new_location);
Chris Lattner24943d22010-06-08 16:52:24 +000089}
90
91BreakpointLocationSP
Greg Clayton19a1ab82011-02-05 00:38:04 +000092Breakpoint::FindLocationByAddress (const Address &addr)
Chris Lattner24943d22010-06-08 16:52:24 +000093{
94 return m_locations.FindByAddress(addr);
95}
96
97break_id_t
Greg Clayton19a1ab82011-02-05 00:38:04 +000098Breakpoint::FindLocationIDByAddress (const Address &addr)
Chris Lattner24943d22010-06-08 16:52:24 +000099{
100 return m_locations.FindIDByAddress(addr);
101}
102
103BreakpointLocationSP
104Breakpoint::FindLocationByID (break_id_t bp_loc_id)
105{
106 return m_locations.FindByID(bp_loc_id);
107}
108
109BreakpointLocationSP
110Breakpoint::GetLocationAtIndex (uint32_t index)
111{
112 return m_locations.GetByIndex(index);
113}
114
Chris Lattner24943d22010-06-08 16:52:24 +0000115// For each of the overall options we need to decide how they propagate to
116// the location options. This will determine the precedence of options on
Johnny Chen736f0d62012-01-25 23:08:23 +0000117// the breakpoint vs. its locations.
Chris Lattner24943d22010-06-08 16:52:24 +0000118
119// Disable at the breakpoint level should override the location settings.
120// That way you can conveniently turn off a whole breakpoint without messing
121// up the individual settings.
122
123void
124Breakpoint::SetEnabled (bool enable)
125{
Jim Ingham28e23862012-02-08 05:23:15 +0000126 if (enable == m_options.IsEnabled())
127 return;
128
Chris Lattner24943d22010-06-08 16:52:24 +0000129 m_options.SetEnabled(enable);
130 if (enable)
131 m_locations.ResolveAllBreakpointSites();
132 else
133 m_locations.ClearAllBreakpointSites();
Jim Ingham28e23862012-02-08 05:23:15 +0000134
135 SendBreakpointChangedEvent (enable ? eBreakpointEventTypeEnabled : eBreakpointEventTypeDisabled);
136
Chris Lattner24943d22010-06-08 16:52:24 +0000137}
138
139bool
140Breakpoint::IsEnabled ()
141{
142 return m_options.IsEnabled();
143}
144
145void
Greg Clayton54e7afa2010-07-09 20:39:50 +0000146Breakpoint::SetIgnoreCount (uint32_t n)
Chris Lattner24943d22010-06-08 16:52:24 +0000147{
Jim Ingham28e23862012-02-08 05:23:15 +0000148 if (m_options.GetIgnoreCount() == n)
149 return;
150
Chris Lattner24943d22010-06-08 16:52:24 +0000151 m_options.SetIgnoreCount(n);
Jim Ingham28e23862012-02-08 05:23:15 +0000152 SendBreakpointChangedEvent (eBreakpointEventTypeIgnoreChanged);
Chris Lattner24943d22010-06-08 16:52:24 +0000153}
154
Greg Clayton54e7afa2010-07-09 20:39:50 +0000155uint32_t
Chris Lattner24943d22010-06-08 16:52:24 +0000156Breakpoint::GetIgnoreCount () const
157{
158 return m_options.GetIgnoreCount();
159}
160
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000161uint32_t
162Breakpoint::GetHitCount () const
163{
164 return m_locations.GetHitCount();
165}
166
Chris Lattner24943d22010-06-08 16:52:24 +0000167void
168Breakpoint::SetThreadID (lldb::tid_t thread_id)
169{
Jim Ingham28e23862012-02-08 05:23:15 +0000170 if (m_options.GetThreadSpec()->GetTID() == thread_id)
171 return;
172
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000173 m_options.GetThreadSpec()->SetTID(thread_id);
Jim Ingham28e23862012-02-08 05:23:15 +0000174 SendBreakpointChangedEvent (eBreakpointEventTypeThreadChanged);
Chris Lattner24943d22010-06-08 16:52:24 +0000175}
176
177lldb::tid_t
Jim Ingham28e23862012-02-08 05:23:15 +0000178Breakpoint::GetThreadID () const
Chris Lattner24943d22010-06-08 16:52:24 +0000179{
Jim Ingham28e23862012-02-08 05:23:15 +0000180 if (m_options.GetThreadSpecNoCreate() == NULL)
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000181 return LLDB_INVALID_THREAD_ID;
182 else
Jim Ingham28e23862012-02-08 05:23:15 +0000183 return m_options.GetThreadSpecNoCreate()->GetTID();
184}
185
186void
187Breakpoint::SetThreadIndex (uint32_t index)
188{
189 if (m_options.GetThreadSpec()->GetIndex() == index)
190 return;
191
192 m_options.GetThreadSpec()->SetIndex(index);
193 SendBreakpointChangedEvent (eBreakpointEventTypeThreadChanged);
194}
195
196uint32_t
197Breakpoint::GetThreadIndex() const
198{
199 if (m_options.GetThreadSpecNoCreate() == NULL)
200 return 0;
201 else
202 return m_options.GetThreadSpecNoCreate()->GetIndex();
203}
204
205void
206Breakpoint::SetThreadName (const char *thread_name)
207{
208 if (::strcmp (m_options.GetThreadSpec()->GetName(), thread_name) == 0)
209 return;
210
211 m_options.GetThreadSpec()->SetName (thread_name);
212 SendBreakpointChangedEvent (eBreakpointEventTypeThreadChanged);
213}
214
215const char *
216Breakpoint::GetThreadName () const
217{
218 if (m_options.GetThreadSpecNoCreate() == NULL)
219 return NULL;
220 else
221 return m_options.GetThreadSpecNoCreate()->GetName();
222}
223
224void
225Breakpoint::SetQueueName (const char *queue_name)
226{
227 if (::strcmp (m_options.GetThreadSpec()->GetQueueName(), queue_name) == 0)
228 return;
229
230 m_options.GetThreadSpec()->SetQueueName (queue_name);
231 SendBreakpointChangedEvent (eBreakpointEventTypeThreadChanged);
232}
233
234const char *
235Breakpoint::GetQueueName () const
236{
237 if (m_options.GetThreadSpecNoCreate() == NULL)
238 return NULL;
239 else
240 return m_options.GetThreadSpecNoCreate()->GetQueueName();
Chris Lattner24943d22010-06-08 16:52:24 +0000241}
242
Jim Inghamd1686902010-10-14 23:45:03 +0000243void
244Breakpoint::SetCondition (const char *condition)
245{
246 m_options.SetCondition (condition);
Jim Ingham28e23862012-02-08 05:23:15 +0000247 SendBreakpointChangedEvent (eBreakpointEventTypeConditionChanged);
Jim Inghamd1686902010-10-14 23:45:03 +0000248}
249
Jim Inghamd1686902010-10-14 23:45:03 +0000250const char *
Jim Inghamac354422011-06-15 21:16:00 +0000251Breakpoint::GetConditionText () const
Jim Inghamd1686902010-10-14 23:45:03 +0000252{
253 return m_options.GetConditionText();
254}
255
Chris Lattner24943d22010-06-08 16:52:24 +0000256// This function is used when "baton" doesn't need to be freed
257void
258Breakpoint::SetCallback (BreakpointHitCallback callback, void *baton, bool is_synchronous)
259{
260 // The default "Baton" class will keep a copy of "baton" and won't free
261 // or delete it when it goes goes out of scope.
262 m_options.SetCallback(callback, BatonSP (new Baton(baton)), is_synchronous);
Jim Ingham28e23862012-02-08 05:23:15 +0000263
264 SendBreakpointChangedEvent (eBreakpointEventTypeCommandChanged);
Chris Lattner24943d22010-06-08 16:52:24 +0000265}
266
267// This function is used when a baton needs to be freed and therefore is
268// contained in a "Baton" subclass.
269void
270Breakpoint::SetCallback (BreakpointHitCallback callback, const BatonSP &callback_baton_sp, bool is_synchronous)
271{
272 m_options.SetCallback(callback, callback_baton_sp, is_synchronous);
273}
274
275void
276Breakpoint::ClearCallback ()
277{
278 m_options.ClearCallback ();
279}
280
281bool
282Breakpoint::InvokeCallback (StoppointCallbackContext *context, break_id_t bp_loc_id)
283{
284 return m_options.InvokeCallback (context, GetID(), bp_loc_id);
285}
286
287BreakpointOptions *
288Breakpoint::GetOptions ()
289{
290 return &m_options;
291}
292
293void
294Breakpoint::ResolveBreakpoint ()
295{
296 if (m_resolver_sp)
297 m_resolver_sp->ResolveBreakpoint(*m_filter_sp);
298}
299
300void
301Breakpoint::ResolveBreakpointInModules (ModuleList &module_list)
302{
303 if (m_resolver_sp)
304 m_resolver_sp->ResolveBreakpointInModules(*m_filter_sp, module_list);
305}
306
307void
308Breakpoint::ClearAllBreakpointSites ()
309{
310 m_locations.ClearAllBreakpointSites();
311}
312
313//----------------------------------------------------------------------
314// ModulesChanged: Pass in a list of new modules, and
315//----------------------------------------------------------------------
316
317void
318Breakpoint::ModulesChanged (ModuleList &module_list, bool load)
319{
320 if (load)
321 {
322 // The logic for handling new modules is:
323 // 1) If the filter rejects this module, then skip it.
324 // 2) Run through the current location list and if there are any locations
325 // for that module, we mark the module as "seen" and we don't try to re-resolve
326 // breakpoint locations for that module.
327 // However, we do add breakpoint sites to these locations if needed.
328 // 3) If we don't see this module in our breakpoint location list, call ResolveInModules.
329
330 ModuleList new_modules; // We'll stuff the "unseen" modules in this list, and then resolve
Greg Clayton19a1ab82011-02-05 00:38:04 +0000331 // them after the locations pass. Have to do it this way because
332 // resolving breakpoints will add new locations potentially.
333
334 const size_t num_locs = m_locations.GetSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000335
Greg Clayton54e7afa2010-07-09 20:39:50 +0000336 for (size_t i = 0; i < module_list.GetSize(); i++)
Chris Lattner24943d22010-06-08 16:52:24 +0000337 {
338 bool seen = false;
339 ModuleSP module_sp (module_list.GetModuleAtIndex (i));
Chris Lattner24943d22010-06-08 16:52:24 +0000340 if (!m_filter_sp->ModulePasses (module_sp))
341 continue;
342
Greg Clayton19a1ab82011-02-05 00:38:04 +0000343 for (size_t loc_idx = 0; loc_idx < num_locs; loc_idx++)
Chris Lattner24943d22010-06-08 16:52:24 +0000344 {
Greg Clayton7b9fcc02010-12-06 23:51:26 +0000345 BreakpointLocationSP break_loc = m_locations.GetByIndex(loc_idx);
Jim Ingham1de036b2010-10-20 03:36:33 +0000346 if (!break_loc->IsEnabled())
347 continue;
Greg Clayton3508c382012-02-24 01:59:29 +0000348 SectionSP section_sp (break_loc->GetAddress().GetSection());
349 if (!section_sp || section_sp->GetModule() == module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000350 {
351 if (!seen)
352 seen = true;
353
354 if (!break_loc->ResolveBreakpointSite())
355 {
Greg Claytone005f2c2010-11-06 01:53:30 +0000356 LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner24943d22010-06-08 16:52:24 +0000357 if (log)
358 log->Printf ("Warning: could not set breakpoint site for breakpoint location %d of breakpoint %d.\n",
359 break_loc->GetID(), GetID());
360 }
361 }
362 }
363
364 if (!seen)
Greg Claytonab429022010-12-12 21:03:32 +0000365 new_modules.AppendIfNeeded (module_sp);
Chris Lattner24943d22010-06-08 16:52:24 +0000366
367 }
Jim Ingham28e23862012-02-08 05:23:15 +0000368
Chris Lattner24943d22010-06-08 16:52:24 +0000369 if (new_modules.GetSize() > 0)
370 {
Jim Ingham28e23862012-02-08 05:23:15 +0000371 // If this is not an internal breakpoint, set up to record the new locations, then dispatch
372 // an event with the new locations.
373 if (!IsInternal())
374 {
375 BreakpointEventData *new_locations_event = new BreakpointEventData (eBreakpointEventTypeLocationsAdded,
376 shared_from_this());
377
378 m_locations.StartRecordingNewLocations(new_locations_event->GetBreakpointLocationCollection());
379
380 ResolveBreakpointInModules(new_modules);
381
382 m_locations.StopRecordingNewLocations();
383 if (new_locations_event->GetBreakpointLocationCollection().GetSize() != 0)
384 {
385 SendBreakpointChangedEvent (new_locations_event);
386 }
387 else
388 delete new_locations_event;
389 }
390 else
391 ResolveBreakpointInModules(new_modules);
392
Chris Lattner24943d22010-06-08 16:52:24 +0000393 }
394 }
395 else
396 {
397 // Go through the currently set locations and if any have breakpoints in
398 // the module list, then remove their breakpoint sites.
399 // FIXME: Think about this... Maybe it's better to delete the locations?
400 // Are we sure that on load-unload-reload the module pointer will remain
401 // the same? Or do we need to do an equality on modules that is an
402 // "equivalence"???
403
Jim Ingham28e23862012-02-08 05:23:15 +0000404 BreakpointEventData *removed_locations_event;
405 if (!IsInternal())
406 removed_locations_event = new BreakpointEventData (eBreakpointEventTypeLocationsRemoved,
407 shared_from_this());
408 else
409 removed_locations_event = NULL;
410
Greg Clayton54e7afa2010-07-09 20:39:50 +0000411 for (size_t i = 0; i < module_list.GetSize(); i++)
Chris Lattner24943d22010-06-08 16:52:24 +0000412 {
413 ModuleSP module_sp (module_list.GetModuleAtIndex (i));
Greg Clayton7b9fcc02010-12-06 23:51:26 +0000414 if (m_filter_sp->ModulePasses (module_sp))
Chris Lattner24943d22010-06-08 16:52:24 +0000415 {
Greg Clayton3508c382012-02-24 01:59:29 +0000416 size_t loc_idx = 0;
417 while (loc_idx < m_locations.GetSize())
Chris Lattner24943d22010-06-08 16:52:24 +0000418 {
Greg Clayton3508c382012-02-24 01:59:29 +0000419 BreakpointLocationSP break_loc_sp (m_locations.GetByIndex(loc_idx));
420 SectionSP section_sp (break_loc_sp->GetAddress().GetSection());
421 if (section_sp && section_sp->GetModule() == module_sp)
Greg Clayton7b9fcc02010-12-06 23:51:26 +0000422 {
423 // Remove this breakpoint since the shared library is
424 // unloaded, but keep the breakpoint location around
425 // so we always get complete hit count and breakpoint
426 // lifetime info
Greg Clayton3508c382012-02-24 01:59:29 +0000427 break_loc_sp->ClearBreakpointSite();
Jim Ingham28e23862012-02-08 05:23:15 +0000428 if (removed_locations_event)
429 {
Greg Clayton3508c382012-02-24 01:59:29 +0000430 removed_locations_event->GetBreakpointLocationCollection().Add(break_loc_sp);
Jim Ingham28e23862012-02-08 05:23:15 +0000431 }
Greg Clayton3508c382012-02-24 01:59:29 +0000432 //m_locations.RemoveLocation (break_loc_sp);
Greg Clayton7b9fcc02010-12-06 23:51:26 +0000433 }
Greg Clayton3508c382012-02-24 01:59:29 +0000434 ++loc_idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000435 }
Chris Lattner24943d22010-06-08 16:52:24 +0000436 }
437 }
Jim Ingham28e23862012-02-08 05:23:15 +0000438 SendBreakpointChangedEvent (removed_locations_event);
Chris Lattner24943d22010-06-08 16:52:24 +0000439 }
440}
441
442void
443Breakpoint::Dump (Stream *)
444{
445}
446
447size_t
448Breakpoint::GetNumResolvedLocations() const
449{
450 // Return the number of breakpoints that are actually resolved and set
451 // down in the inferior process.
452 return m_locations.GetNumResolvedLocations();
453}
454
455size_t
456Breakpoint::GetNumLocations() const
457{
458 return m_locations.GetSize();
459}
460
461void
462Breakpoint::GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_locations)
463{
464 assert (s != NULL);
Greg Clayton12bec712010-06-28 21:30:43 +0000465 s->Printf("%i: ", GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000466 GetResolverDescription (s);
Greg Clayton12bec712010-06-28 21:30:43 +0000467 GetFilterDescription (s);
Chris Lattner24943d22010-06-08 16:52:24 +0000468
Greg Clayton54e7afa2010-07-09 20:39:50 +0000469 const size_t num_locations = GetNumLocations ();
470 const size_t num_resolved_locations = GetNumResolvedLocations ();
Chris Lattner24943d22010-06-08 16:52:24 +0000471
472 switch (level)
473 {
474 case lldb::eDescriptionLevelBrief:
475 case lldb::eDescriptionLevelFull:
476 if (num_locations > 0)
477 {
Greg Clayton54e7afa2010-07-09 20:39:50 +0000478 s->Printf(", locations = %zu", num_locations);
Chris Lattner24943d22010-06-08 16:52:24 +0000479 if (num_resolved_locations > 0)
Greg Clayton54e7afa2010-07-09 20:39:50 +0000480 s->Printf(", resolved = %zu", num_resolved_locations);
Chris Lattner24943d22010-06-08 16:52:24 +0000481 }
482 else
483 {
Jim Ingham4722b102012-03-06 00:37:27 +0000484 // Don't print the pending notification for exception resolvers since we don't generally
485 // know how to set them until the target is run.
486 if (m_resolver_sp->getResolverID() != BreakpointResolver::ExceptionResolver)
487 s->Printf(", locations = 0 (pending)");
Chris Lattner24943d22010-06-08 16:52:24 +0000488 }
489
Jim Ingham649492b2010-06-18 01:00:58 +0000490 GetOptions()->GetDescription(s, level);
491
Chris Lattner24943d22010-06-08 16:52:24 +0000492 if (level == lldb::eDescriptionLevelFull)
493 {
Jim Ingham649492b2010-06-18 01:00:58 +0000494 s->IndentLess();
495 s->EOL();
Chris Lattner24943d22010-06-08 16:52:24 +0000496 }
497 break;
498
499 case lldb::eDescriptionLevelVerbose:
500 // Verbose mode does a debug dump of the breakpoint
501 Dump (s);
Jim Ingham649492b2010-06-18 01:00:58 +0000502 s->EOL ();
Greg Claytonb1888f22011-03-19 01:12:21 +0000503 //s->Indent();
Jim Ingham649492b2010-06-18 01:00:58 +0000504 GetOptions()->GetDescription(s, level);
Chris Lattner24943d22010-06-08 16:52:24 +0000505 break;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000506
507 default:
508 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000509 }
510
Jim Ingham1cd466f2011-05-14 01:11:02 +0000511 // The brief description is just the location name (1.2 or whatever). That's pointless to
512 // show in the breakpoint's description, so suppress it.
513 if (show_locations && level != lldb::eDescriptionLevelBrief)
Chris Lattner24943d22010-06-08 16:52:24 +0000514 {
Chris Lattner24943d22010-06-08 16:52:24 +0000515 s->IndentMore();
Greg Clayton54e7afa2010-07-09 20:39:50 +0000516 for (size_t i = 0; i < num_locations; ++i)
Chris Lattner24943d22010-06-08 16:52:24 +0000517 {
518 BreakpointLocation *loc = GetLocationAtIndex(i).get();
519 loc->GetDescription(s, level);
520 s->EOL();
521 }
522 s->IndentLess();
Chris Lattner24943d22010-06-08 16:52:24 +0000523 }
524}
525
Jim Ingham5f4f3272012-02-09 01:49:26 +0000526void
527Breakpoint::GetResolverDescription (Stream *s)
528{
529 if (m_resolver_sp)
530 m_resolver_sp->GetDescription (s);
531}
532
533
534bool
535Breakpoint::GetMatchingFileLine (const ConstString &filename, uint32_t line_number, BreakpointLocationCollection &loc_coll)
536{
537 // TODO: To be correct, this method needs to fill the breakpoint location collection
538 // with the location IDs which match the filename and line_number.
539 //
540
541 if (m_resolver_sp)
542 {
543 BreakpointResolverFileLine *resolverFileLine = dyn_cast<BreakpointResolverFileLine>(m_resolver_sp.get());
544 if (resolverFileLine &&
545 resolverFileLine->m_file_spec.GetFilename() == filename &&
546 resolverFileLine->m_line_number == line_number)
547 {
548 return true;
549 }
550 }
551 return false;
552}
553
554void
555Breakpoint::GetFilterDescription (Stream *s)
556{
557 m_filter_sp->GetDescription (s);
558}
559
560void
561Breakpoint::SendBreakpointChangedEvent (lldb::BreakpointEventType eventKind)
562{
563 if (!m_being_created
564 && !IsInternal()
565 && GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged))
566 {
567 BreakpointEventData *data = new Breakpoint::BreakpointEventData (eventKind, shared_from_this());
568
569 GetTarget().BroadcastEvent (Target::eBroadcastBitBreakpointChanged, data);
570 }
571}
572
573void
574Breakpoint::SendBreakpointChangedEvent (BreakpointEventData *data)
575{
576
577 if (data == NULL)
578 return;
579
580 if (!m_being_created
581 && !IsInternal()
582 && GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged))
583 GetTarget().BroadcastEvent (Target::eBroadcastBitBreakpointChanged, data);
584 else
585 delete data;
586}
587
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000588Breakpoint::BreakpointEventData::BreakpointEventData (BreakpointEventType sub_type,
Jim Ingham28e23862012-02-08 05:23:15 +0000589 const BreakpointSP &new_breakpoint_sp) :
Chris Lattner24943d22010-06-08 16:52:24 +0000590 EventData (),
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000591 m_breakpoint_event (sub_type),
Chris Lattner24943d22010-06-08 16:52:24 +0000592 m_new_breakpoint_sp (new_breakpoint_sp)
593{
594}
595
596Breakpoint::BreakpointEventData::~BreakpointEventData ()
597{
598}
599
600const ConstString &
601Breakpoint::BreakpointEventData::GetFlavorString ()
602{
603 static ConstString g_flavor ("Breakpoint::BreakpointEventData");
604 return g_flavor;
605}
606
607const ConstString &
608Breakpoint::BreakpointEventData::GetFlavor () const
609{
610 return BreakpointEventData::GetFlavorString ();
611}
612
613
614BreakpointSP &
615Breakpoint::BreakpointEventData::GetBreakpoint ()
616{
617 return m_new_breakpoint_sp;
618}
619
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000620BreakpointEventType
621Breakpoint::BreakpointEventData::GetBreakpointEventType () const
Chris Lattner24943d22010-06-08 16:52:24 +0000622{
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000623 return m_breakpoint_event;
Chris Lattner24943d22010-06-08 16:52:24 +0000624}
625
626void
627Breakpoint::BreakpointEventData::Dump (Stream *s) const
628{
629}
630
Jim Ingham28e23862012-02-08 05:23:15 +0000631const Breakpoint::BreakpointEventData *
632Breakpoint::BreakpointEventData::GetEventDataFromEvent (const Event *event)
Chris Lattner24943d22010-06-08 16:52:24 +0000633{
Jim Ingham28e23862012-02-08 05:23:15 +0000634 if (event)
Chris Lattner24943d22010-06-08 16:52:24 +0000635 {
Jim Ingham28e23862012-02-08 05:23:15 +0000636 const EventData *event_data = event->GetData();
Chris Lattner24943d22010-06-08 16:52:24 +0000637 if (event_data && event_data->GetFlavor() == BreakpointEventData::GetFlavorString())
Jim Ingham28e23862012-02-08 05:23:15 +0000638 return static_cast <const BreakpointEventData *> (event->GetData());
Chris Lattner24943d22010-06-08 16:52:24 +0000639 }
640 return NULL;
641}
642
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000643BreakpointEventType
644Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (const EventSP &event_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000645{
Jim Ingham28e23862012-02-08 05:23:15 +0000646 const BreakpointEventData *data = GetEventDataFromEvent (event_sp.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000647
648 if (data == NULL)
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000649 return eBreakpointEventTypeInvalidType;
Chris Lattner24943d22010-06-08 16:52:24 +0000650 else
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000651 return data->GetBreakpointEventType();
Chris Lattner24943d22010-06-08 16:52:24 +0000652}
653
654BreakpointSP
655Breakpoint::BreakpointEventData::GetBreakpointFromEvent (const EventSP &event_sp)
656{
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000657 BreakpointSP bp_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000658
Jim Ingham28e23862012-02-08 05:23:15 +0000659 const BreakpointEventData *data = GetEventDataFromEvent (event_sp.get());
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000660 if (data)
Jim Ingham28e23862012-02-08 05:23:15 +0000661 bp_sp = data->m_new_breakpoint_sp;
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000662
663 return bp_sp;
664}
665
Jim Ingham28e23862012-02-08 05:23:15 +0000666uint32_t
667Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent (const EventSP &event_sp)
668{
669 const BreakpointEventData *data = GetEventDataFromEvent (event_sp.get());
670 if (data)
671 return data->m_locations.GetSize();
672
673 return 0;
674}
675
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000676lldb::BreakpointLocationSP
677Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (const lldb::EventSP &event_sp, uint32_t bp_loc_idx)
678{
679 lldb::BreakpointLocationSP bp_loc_sp;
680
Jim Ingham28e23862012-02-08 05:23:15 +0000681 const BreakpointEventData *data = GetEventDataFromEvent (event_sp.get());
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000682 if (data)
Chris Lattner24943d22010-06-08 16:52:24 +0000683 {
Jim Ingham28e23862012-02-08 05:23:15 +0000684 bp_loc_sp = data->m_locations.GetByIndex(bp_loc_idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000685 }
Greg Claytonc7f5d5c2010-07-23 23:33:17 +0000686
687 return bp_loc_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000688}