Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | #include <string> |
| 13 | |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 17 | #include "lldb/Breakpoint/BreakpointID.h" |
| 18 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
Jim Ingham | e5ed8e9 | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 19 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Log.h" |
| 21 | #include "lldb/Target/Target.h" |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 22 | #include "lldb/Target/ThreadPlan.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Process.h" |
| 24 | #include "lldb/Core/StreamString.h" |
| 25 | #include "lldb/lldb-private-log.h" |
| 26 | #include "lldb/Target/Thread.h" |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 27 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | |
| 29 | using namespace lldb; |
| 30 | using namespace lldb_private; |
| 31 | |
| 32 | BreakpointLocation::BreakpointLocation |
| 33 | ( |
| 34 | break_id_t loc_id, |
| 35 | Breakpoint &owner, |
Greg Clayton | 19a1ab8 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 36 | const Address &addr, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | lldb::tid_t tid, |
| 38 | bool hardware |
| 39 | ) : |
Greg Clayton | c0fa533 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 40 | StoppointLocation (loc_id, addr.GetOpcodeLoadAddress(&owner.GetTarget()), hardware), |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 41 | m_being_created(true), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | m_address (addr), |
| 43 | m_owner (owner), |
| 44 | m_options_ap (), |
| 45 | m_bp_site_sp () |
| 46 | { |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 47 | SetThreadID (tid); |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 48 | m_being_created = false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | BreakpointLocation::~BreakpointLocation() |
| 52 | { |
| 53 | ClearBreakpointSite(); |
| 54 | } |
| 55 | |
| 56 | lldb::addr_t |
Greg Clayton | 273a8e5 | 2010-06-14 04:18:27 +0000 | [diff] [blame] | 57 | BreakpointLocation::GetLoadAddress () const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | { |
Greg Clayton | c0fa533 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 59 | return m_address.GetOpcodeLoadAddress (&m_owner.GetTarget()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | Address & |
| 63 | BreakpointLocation::GetAddress () |
| 64 | { |
| 65 | return m_address; |
| 66 | } |
| 67 | |
| 68 | Breakpoint & |
| 69 | BreakpointLocation::GetBreakpoint () |
| 70 | { |
| 71 | return m_owner; |
| 72 | } |
| 73 | |
| 74 | bool |
Johnny Chen | ca4fe80 | 2012-02-01 19:05:20 +0000 | [diff] [blame] | 75 | BreakpointLocation::IsEnabled () const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | { |
Johnny Chen | fd60a60 | 2012-01-30 22:48:10 +0000 | [diff] [blame] | 77 | if (!m_owner.IsEnabled()) |
| 78 | return false; |
| 79 | else if (m_options_ap.get() != NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | return m_options_ap->IsEnabled(); |
| 81 | else |
Johnny Chen | fd60a60 | 2012-01-30 22:48:10 +0000 | [diff] [blame] | 82 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void |
| 86 | BreakpointLocation::SetEnabled (bool enabled) |
| 87 | { |
| 88 | GetLocationOptions()->SetEnabled(enabled); |
| 89 | if (enabled) |
| 90 | { |
| 91 | ResolveBreakpointSite(); |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | ClearBreakpointSite(); |
| 96 | } |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 97 | SendBreakpointLocationChangedEvent (enabled ? eBreakpointEventTypeEnabled : eBreakpointEventTypeDisabled); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | void |
| 101 | BreakpointLocation::SetThreadID (lldb::tid_t thread_id) |
| 102 | { |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 103 | if (thread_id != LLDB_INVALID_THREAD_ID) |
| 104 | GetLocationOptions()->SetThreadID(thread_id); |
| 105 | else |
| 106 | { |
| 107 | // If we're resetting this to an invalid thread id, then |
| 108 | // don't make an options pointer just to do that. |
| 109 | if (m_options_ap.get() != NULL) |
| 110 | m_options_ap->SetThreadID (thread_id); |
| 111 | } |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 112 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged); |
| 113 | } |
| 114 | |
| 115 | lldb::tid_t |
| 116 | BreakpointLocation::GetThreadID () |
| 117 | { |
| 118 | if (GetOptionsNoCreate()->GetThreadSpecNoCreate()) |
| 119 | return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetTID(); |
| 120 | else |
| 121 | return LLDB_INVALID_THREAD_ID; |
| 122 | } |
| 123 | |
| 124 | void |
| 125 | BreakpointLocation::SetThreadIndex (uint32_t index) |
| 126 | { |
| 127 | if (index != 0) |
| 128 | GetLocationOptions()->GetThreadSpec()->SetIndex(index); |
| 129 | else |
| 130 | { |
| 131 | // If we're resetting this to an invalid thread id, then |
| 132 | // don't make an options pointer just to do that. |
| 133 | if (m_options_ap.get() != NULL) |
| 134 | m_options_ap->GetThreadSpec()->SetIndex(index); |
| 135 | } |
| 136 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged); |
| 137 | |
| 138 | } |
| 139 | |
| 140 | uint32_t |
| 141 | BreakpointLocation::GetThreadIndex() const |
| 142 | { |
| 143 | if (GetOptionsNoCreate()->GetThreadSpecNoCreate()) |
| 144 | return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetIndex(); |
| 145 | else |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | void |
| 150 | BreakpointLocation::SetThreadName (const char *thread_name) |
| 151 | { |
| 152 | if (thread_name != NULL) |
| 153 | GetLocationOptions()->GetThreadSpec()->SetName(thread_name); |
| 154 | else |
| 155 | { |
| 156 | // If we're resetting this to an invalid thread id, then |
| 157 | // don't make an options pointer just to do that. |
| 158 | if (m_options_ap.get() != NULL) |
| 159 | m_options_ap->GetThreadSpec()->SetName(thread_name); |
| 160 | } |
| 161 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged); |
| 162 | } |
| 163 | |
| 164 | const char * |
| 165 | BreakpointLocation::GetThreadName () const |
| 166 | { |
| 167 | if (GetOptionsNoCreate()->GetThreadSpecNoCreate()) |
| 168 | return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetName(); |
| 169 | else |
| 170 | return NULL; |
| 171 | } |
| 172 | |
| 173 | void |
| 174 | BreakpointLocation::SetQueueName (const char *queue_name) |
| 175 | { |
| 176 | if (queue_name != NULL) |
| 177 | GetLocationOptions()->GetThreadSpec()->SetQueueName(queue_name); |
| 178 | else |
| 179 | { |
| 180 | // If we're resetting this to an invalid thread id, then |
| 181 | // don't make an options pointer just to do that. |
| 182 | if (m_options_ap.get() != NULL) |
| 183 | m_options_ap->GetThreadSpec()->SetQueueName(queue_name); |
| 184 | } |
| 185 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged); |
| 186 | } |
| 187 | |
| 188 | const char * |
| 189 | BreakpointLocation::GetQueueName () const |
| 190 | { |
| 191 | if (GetOptionsNoCreate()->GetThreadSpecNoCreate()) |
| 192 | return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetQueueName(); |
| 193 | else |
| 194 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | bool |
| 198 | BreakpointLocation::InvokeCallback (StoppointCallbackContext *context) |
| 199 | { |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 200 | if (m_options_ap.get() != NULL && m_options_ap->HasCallback()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 201 | return m_options_ap->InvokeCallback (context, m_owner.GetID(), GetID()); |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 202 | else |
| 203 | return m_owner.InvokeCallback (context, GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void |
| 207 | BreakpointLocation::SetCallback (BreakpointHitCallback callback, void *baton, |
| 208 | bool is_synchronous) |
| 209 | { |
| 210 | // The default "Baton" class will keep a copy of "baton" and won't free |
| 211 | // or delete it when it goes goes out of scope. |
| 212 | GetLocationOptions()->SetCallback(callback, BatonSP (new Baton(baton)), is_synchronous); |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 213 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeCommandChanged); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | void |
| 217 | BreakpointLocation::SetCallback (BreakpointHitCallback callback, const BatonSP &baton_sp, |
| 218 | bool is_synchronous) |
| 219 | { |
| 220 | GetLocationOptions()->SetCallback (callback, baton_sp, is_synchronous); |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 221 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeCommandChanged); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 224 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 225 | void |
| 226 | BreakpointLocation::ClearCallback () |
| 227 | { |
| 228 | GetLocationOptions()->ClearCallback(); |
| 229 | } |
| 230 | |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 231 | void |
| 232 | BreakpointLocation::SetCondition (const char *condition) |
| 233 | { |
| 234 | GetLocationOptions()->SetCondition (condition); |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 235 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeConditionChanged); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 238 | const char * |
Jim Ingham | ac35442 | 2011-06-15 21:16:00 +0000 | [diff] [blame] | 239 | BreakpointLocation::GetConditionText () const |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 240 | { |
Jim Ingham | ac35442 | 2011-06-15 21:16:00 +0000 | [diff] [blame] | 241 | return GetOptionsNoCreate()->GetConditionText(); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 244 | uint32_t |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 245 | BreakpointLocation::GetIgnoreCount () |
| 246 | { |
Jim Ingham | 9c6898b | 2010-06-22 21:12:54 +0000 | [diff] [blame] | 247 | return GetOptionsNoCreate()->GetIgnoreCount(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 251 | BreakpointLocation::SetIgnoreCount (uint32_t n) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 252 | { |
| 253 | GetLocationOptions()->SetIgnoreCount(n); |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 254 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeIgnoreChanged); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Jim Ingham | fdbd10a | 2012-06-26 22:27:55 +0000 | [diff] [blame] | 257 | void |
| 258 | BreakpointLocation::DecrementIgnoreCount() |
| 259 | { |
| 260 | if (m_options_ap.get() != NULL) |
| 261 | { |
| 262 | uint32_t loc_ignore = m_options_ap->GetIgnoreCount(); |
| 263 | if (loc_ignore != 0) |
| 264 | m_options_ap->SetIgnoreCount(loc_ignore - 1); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | bool |
| 269 | BreakpointLocation::IgnoreCountShouldStop() |
| 270 | { |
| 271 | if (m_options_ap.get() != NULL) |
| 272 | { |
| 273 | uint32_t loc_ignore = m_options_ap->GetIgnoreCount(); |
| 274 | if (loc_ignore != 0) |
| 275 | { |
| 276 | m_owner.DecrementIgnoreCount(); |
| 277 | DecrementIgnoreCount(); // Have to decrement our owners' ignore count, since it won't get a |
| 278 | // chance to. |
| 279 | return false; |
| 280 | } |
| 281 | } |
| 282 | return true; |
| 283 | } |
| 284 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 285 | const BreakpointOptions * |
Jim Ingham | 9c6898b | 2010-06-22 21:12:54 +0000 | [diff] [blame] | 286 | BreakpointLocation::GetOptionsNoCreate () const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 287 | { |
| 288 | if (m_options_ap.get() != NULL) |
| 289 | return m_options_ap.get(); |
| 290 | else |
| 291 | return m_owner.GetOptions (); |
| 292 | } |
| 293 | |
| 294 | BreakpointOptions * |
| 295 | BreakpointLocation::GetLocationOptions () |
| 296 | { |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 297 | // If we make the copy we don't copy the callbacks because that is potentially |
| 298 | // expensive and we don't want to do that for the simple case where someone is |
| 299 | // just disabling the location. |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 300 | if (m_options_ap.get() == NULL) |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 301 | m_options_ap.reset(BreakpointOptions::CopyOptionsNoCallback(*m_owner.GetOptions ())); |
| 302 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 303 | return m_options_ap.get(); |
| 304 | } |
| 305 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 306 | bool |
| 307 | BreakpointLocation::ValidForThisThread (Thread *thread) |
| 308 | { |
Jim Ingham | 9c6898b | 2010-06-22 21:12:54 +0000 | [diff] [blame] | 309 | return thread->MatchesSpec(GetOptionsNoCreate()->GetThreadSpecNoCreate()); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 312 | // RETURNS - true if we should stop at this breakpoint, false if we |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 313 | // should continue. Note, we don't check the thread spec for the breakpoint |
| 314 | // here, since if the breakpoint is not for this thread, then the event won't |
| 315 | // even get reported, so the check is redundant. |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 316 | |
| 317 | bool |
| 318 | BreakpointLocation::ShouldStop (StoppointCallbackContext *context) |
| 319 | { |
| 320 | bool should_stop = true; |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 321 | LogSP log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 322 | |
Johnny Chen | 51b7c5f | 2012-01-23 23:03:59 +0000 | [diff] [blame] | 323 | IncrementHitCount(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 324 | |
| 325 | if (!IsEnabled()) |
| 326 | return false; |
| 327 | |
Jim Ingham | fdbd10a | 2012-06-26 22:27:55 +0000 | [diff] [blame] | 328 | if (!IgnoreCountShouldStop()) |
| 329 | return false; |
| 330 | |
| 331 | if (!m_owner.IgnoreCountShouldStop()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 332 | return false; |
| 333 | |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 334 | // We only run synchronous callbacks in ShouldStop: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 335 | context->is_synchronous = true; |
| 336 | should_stop = InvokeCallback (context); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 337 | |
Jim Ingham | e5ed8e9 | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 338 | if (log) |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 339 | { |
Jim Ingham | e5ed8e9 | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 340 | StreamString s; |
| 341 | GetDescription (&s, lldb::eDescriptionLevelVerbose); |
| 342 | log->Printf ("Hit breakpoint location: %s, %s.\n", s.GetData(), should_stop ? "stopping" : "continuing"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 343 | } |
Jim Ingham | e5ed8e9 | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 344 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 345 | return should_stop; |
| 346 | } |
| 347 | |
| 348 | bool |
| 349 | BreakpointLocation::IsResolved () const |
| 350 | { |
| 351 | return m_bp_site_sp.get() != NULL; |
| 352 | } |
| 353 | |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 354 | lldb::BreakpointSiteSP |
| 355 | BreakpointLocation::GetBreakpointSite() const |
| 356 | { |
| 357 | return m_bp_site_sp; |
| 358 | } |
| 359 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 360 | bool |
| 361 | BreakpointLocation::ResolveBreakpointSite () |
| 362 | { |
| 363 | if (m_bp_site_sp) |
| 364 | return true; |
| 365 | |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 366 | Process *process = m_owner.GetTarget().GetProcessSP().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 367 | if (process == NULL) |
| 368 | return false; |
| 369 | |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 370 | if (m_owner.GetTarget().GetSectionLoadList().IsEmpty()) |
| 371 | return false; |
| 372 | |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 373 | lldb::break_id_t new_id = process->CreateBreakpointSite (shared_from_this(), false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 374 | |
Stephen Wilson | 3fd1f36 | 2010-07-17 00:56:13 +0000 | [diff] [blame] | 375 | if (new_id == LLDB_INVALID_BREAK_ID) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 376 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 377 | LogSP log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 378 | if (log) |
| 379 | log->Warning ("Tried to add breakpoint site at 0x%llx but it was already present.\n", |
Greg Clayton | c0fa533 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 380 | m_address.GetOpcodeLoadAddress (&m_owner.GetTarget())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 381 | return false; |
| 382 | } |
| 383 | |
| 384 | return true; |
| 385 | } |
| 386 | |
| 387 | bool |
| 388 | BreakpointLocation::SetBreakpointSite (BreakpointSiteSP& bp_site_sp) |
| 389 | { |
| 390 | m_bp_site_sp = bp_site_sp; |
| 391 | return true; |
| 392 | } |
| 393 | |
| 394 | bool |
| 395 | BreakpointLocation::ClearBreakpointSite () |
| 396 | { |
| 397 | if (m_bp_site_sp.get()) |
| 398 | { |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 399 | m_owner.GetTarget().GetProcessSP()->RemoveOwnerFromBreakpointSite (GetBreakpoint().GetID(), |
| 400 | GetID(), m_bp_site_sp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 401 | m_bp_site_sp.reset(); |
| 402 | return true; |
| 403 | } |
| 404 | return false; |
| 405 | } |
| 406 | |
| 407 | void |
| 408 | BreakpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 409 | { |
| 410 | SymbolContext sc; |
| 411 | s->Indent(); |
| 412 | BreakpointID::GetCanonicalReference(s, m_owner.GetID(), GetID()); |
| 413 | |
| 414 | if (level == lldb::eDescriptionLevelBrief) |
| 415 | return; |
| 416 | |
| 417 | s->PutCString(": "); |
| 418 | |
| 419 | if (level == lldb::eDescriptionLevelVerbose) |
| 420 | s->IndentMore(); |
| 421 | |
| 422 | if (m_address.IsSectionOffset()) |
| 423 | { |
| 424 | m_address.CalculateSymbolContext(&sc); |
| 425 | |
| 426 | if (level == lldb::eDescriptionLevelFull) |
| 427 | { |
| 428 | s->PutCString("where = "); |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 429 | sc.DumpStopContext (s, m_owner.GetTarget().GetProcessSP().get(), m_address, false, true, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 430 | } |
| 431 | else |
| 432 | { |
| 433 | if (sc.module_sp) |
| 434 | { |
| 435 | s->EOL(); |
| 436 | s->Indent("module = "); |
| 437 | sc.module_sp->GetFileSpec().Dump (s); |
| 438 | } |
| 439 | |
| 440 | if (sc.comp_unit != NULL) |
| 441 | { |
| 442 | s->EOL(); |
| 443 | s->Indent("compile unit = "); |
Jim Ingham | 7ea3523 | 2010-10-27 22:58:34 +0000 | [diff] [blame] | 444 | static_cast<FileSpec*>(sc.comp_unit)->GetFilename().Dump (s); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 445 | |
| 446 | if (sc.function != NULL) |
| 447 | { |
| 448 | s->EOL(); |
| 449 | s->Indent("function = "); |
| 450 | s->PutCString (sc.function->GetMangled().GetName().AsCString("<unknown>")); |
| 451 | } |
| 452 | |
| 453 | if (sc.line_entry.line > 0) |
| 454 | { |
| 455 | s->EOL(); |
| 456 | s->Indent("location = "); |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 457 | sc.line_entry.DumpStopContext (s, true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | } |
| 461 | else |
| 462 | { |
| 463 | // If we don't have a comp unit, see if we have a symbol we can print. |
| 464 | if (sc.symbol) |
| 465 | { |
| 466 | s->EOL(); |
| 467 | s->Indent("symbol = "); |
| 468 | s->PutCString(sc.symbol->GetMangled().GetName().AsCString("<unknown>")); |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | if (level == lldb::eDescriptionLevelVerbose) |
| 475 | { |
| 476 | s->EOL(); |
| 477 | s->Indent(); |
| 478 | } |
| 479 | s->Printf ("%saddress = ", (level == lldb::eDescriptionLevelFull && m_address.IsSectionOffset()) ? ", " : ""); |
| 480 | ExecutionContextScope *exe_scope = NULL; |
| 481 | Target *target = &m_owner.GetTarget(); |
| 482 | if (target) |
| 483 | exe_scope = target->GetProcessSP().get(); |
| 484 | if (exe_scope == NULL) |
| 485 | exe_scope = target; |
| 486 | |
| 487 | m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress); |
| 488 | |
| 489 | if (level == lldb::eDescriptionLevelVerbose) |
| 490 | { |
| 491 | s->EOL(); |
| 492 | s->Indent(); |
| 493 | s->Printf("resolved = %s\n", IsResolved() ? "true" : "false"); |
| 494 | |
| 495 | s->Indent(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 496 | s->Printf ("hit count = %-4u\n", GetHitCount()); |
| 497 | |
| 498 | if (m_options_ap.get()) |
| 499 | { |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 500 | s->Indent(); |
| 501 | m_options_ap->GetDescription (s, level); |
| 502 | s->EOL(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 503 | } |
| 504 | s->IndentLess(); |
| 505 | } |
| 506 | else |
| 507 | { |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 508 | s->Printf(", %sresolved, hit count = %u ", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 509 | (IsResolved() ? "" : "un"), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | GetHitCount()); |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 511 | if (m_options_ap.get()) |
| 512 | { |
| 513 | m_options_ap->GetDescription (s, level); |
| 514 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | |
| 518 | void |
| 519 | BreakpointLocation::Dump(Stream *s) const |
| 520 | { |
| 521 | if (s == NULL) |
| 522 | return; |
| 523 | |
Greg Clayton | d9919d3 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 524 | s->Printf("BreakpointLocation %u: tid = %4.4llx load addr = 0x%8.8llx state = %s type = %s breakpoint " |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 525 | "hw_index = %i hit_count = %-4u ignore_count = %-4u", |
Johnny Chen | f8c0fc5 | 2012-01-26 00:08:14 +0000 | [diff] [blame] | 526 | GetID(), |
| 527 | GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetTID(), |
| 528 | (uint64_t) m_address.GetOpcodeLoadAddress (&m_owner.GetTarget()), |
Johnny Chen | fd60a60 | 2012-01-30 22:48:10 +0000 | [diff] [blame] | 529 | (m_options_ap.get() ? m_options_ap->IsEnabled() : m_owner.IsEnabled()) ? "enabled " : "disabled", |
Johnny Chen | f8c0fc5 | 2012-01-26 00:08:14 +0000 | [diff] [blame] | 530 | IsHardware() ? "hardware" : "software", |
| 531 | GetHardwareIndex(), |
| 532 | GetHitCount(), |
| 533 | GetOptionsNoCreate()->GetIgnoreCount()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 534 | } |
Jim Ingham | 28e2386 | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 535 | |
| 536 | void |
| 537 | BreakpointLocation::SendBreakpointLocationChangedEvent (lldb::BreakpointEventType eventKind) |
| 538 | { |
| 539 | if (!m_being_created |
| 540 | && !m_owner.IsInternal() |
| 541 | && m_owner.GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged)) |
| 542 | { |
| 543 | Breakpoint::BreakpointEventData *data = new Breakpoint::BreakpointEventData (eventKind, |
| 544 | m_owner.shared_from_this()); |
| 545 | data->GetBreakpointLocationCollection().Add (shared_from_this()); |
| 546 | m_owner.GetTarget().BroadcastEvent (Target::eBroadcastBitBreakpointChanged, data); |
| 547 | } |
| 548 | } |
| 549 | |