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