Chris Lattner | 30fdc8d | 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 | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 30fdc8d | 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 | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 18 | #include "lldb/lldb-private-log.h" |
Chris Lattner | 30fdc8d | 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 | 5b52f0c | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Core/Log.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 24 | #include "lldb/Core/Module.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Core/StreamString.h" |
Greg Clayton | 1f74607 | 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 | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Target/Thread.h" |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 31 | #include "lldb/Target/ThreadSpec.h" |
Chris Lattner | 30fdc8d | 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 | c0d3446 | 2011-02-05 00:38:04 +0000 | [diff] [blame] | 40 | const Address &addr, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | lldb::tid_t tid, |
| 42 | bool hardware |
| 43 | ) : |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 44 | StoppointLocation (loc_id, addr.GetOpcodeLoadAddress(&owner.GetTarget()), hardware), |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 45 | m_being_created(true), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | m_address (addr), |
| 47 | m_owner (owner), |
| 48 | m_options_ap (), |
Sean Callanan | b4987e3 | 2013-06-06 20:18:50 +0000 | [diff] [blame] | 49 | m_bp_site_sp (), |
| 50 | m_condition_mutex () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | { |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 52 | SetThreadID (tid); |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 53 | m_being_created = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | BreakpointLocation::~BreakpointLocation() |
| 57 | { |
| 58 | ClearBreakpointSite(); |
| 59 | } |
| 60 | |
| 61 | lldb::addr_t |
Greg Clayton | 13238c4 | 2010-06-14 04:18:27 +0000 | [diff] [blame] | 62 | BreakpointLocation::GetLoadAddress () const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | { |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 64 | return m_address.GetOpcodeLoadAddress (&m_owner.GetTarget()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | Address & |
| 68 | BreakpointLocation::GetAddress () |
| 69 | { |
| 70 | return m_address; |
| 71 | } |
| 72 | |
| 73 | Breakpoint & |
| 74 | BreakpointLocation::GetBreakpoint () |
| 75 | { |
| 76 | return m_owner; |
| 77 | } |
| 78 | |
| 79 | bool |
Johnny Chen | fdad679 | 2012-02-01 19:05:20 +0000 | [diff] [blame] | 80 | BreakpointLocation::IsEnabled () const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 81 | { |
Johnny Chen | 50df1f9 | 2012-01-30 22:48:10 +0000 | [diff] [blame] | 82 | if (!m_owner.IsEnabled()) |
| 83 | return false; |
| 84 | else if (m_options_ap.get() != NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 85 | return m_options_ap->IsEnabled(); |
| 86 | else |
Johnny Chen | 50df1f9 | 2012-01-30 22:48:10 +0000 | [diff] [blame] | 87 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void |
| 91 | BreakpointLocation::SetEnabled (bool enabled) |
| 92 | { |
| 93 | GetLocationOptions()->SetEnabled(enabled); |
| 94 | if (enabled) |
| 95 | { |
| 96 | ResolveBreakpointSite(); |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | ClearBreakpointSite(); |
| 101 | } |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 102 | SendBreakpointLocationChangedEvent (enabled ? eBreakpointEventTypeEnabled : eBreakpointEventTypeDisabled); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void |
| 106 | BreakpointLocation::SetThreadID (lldb::tid_t thread_id) |
| 107 | { |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 108 | if (thread_id != LLDB_INVALID_THREAD_ID) |
| 109 | GetLocationOptions()->SetThreadID(thread_id); |
| 110 | else |
| 111 | { |
| 112 | // If we're resetting this to an invalid thread id, then |
| 113 | // don't make an options pointer just to do that. |
| 114 | if (m_options_ap.get() != NULL) |
| 115 | m_options_ap->SetThreadID (thread_id); |
| 116 | } |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 117 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged); |
| 118 | } |
| 119 | |
| 120 | lldb::tid_t |
| 121 | BreakpointLocation::GetThreadID () |
| 122 | { |
| 123 | if (GetOptionsNoCreate()->GetThreadSpecNoCreate()) |
| 124 | return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetTID(); |
| 125 | else |
| 126 | return LLDB_INVALID_THREAD_ID; |
| 127 | } |
| 128 | |
| 129 | void |
| 130 | BreakpointLocation::SetThreadIndex (uint32_t index) |
| 131 | { |
| 132 | if (index != 0) |
| 133 | GetLocationOptions()->GetThreadSpec()->SetIndex(index); |
| 134 | else |
| 135 | { |
| 136 | // If we're resetting this to an invalid thread id, then |
| 137 | // don't make an options pointer just to do that. |
| 138 | if (m_options_ap.get() != NULL) |
| 139 | m_options_ap->GetThreadSpec()->SetIndex(index); |
| 140 | } |
| 141 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged); |
| 142 | |
| 143 | } |
| 144 | |
| 145 | uint32_t |
| 146 | BreakpointLocation::GetThreadIndex() const |
| 147 | { |
| 148 | if (GetOptionsNoCreate()->GetThreadSpecNoCreate()) |
| 149 | return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetIndex(); |
| 150 | else |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | void |
| 155 | BreakpointLocation::SetThreadName (const char *thread_name) |
| 156 | { |
| 157 | if (thread_name != NULL) |
| 158 | GetLocationOptions()->GetThreadSpec()->SetName(thread_name); |
| 159 | else |
| 160 | { |
| 161 | // If we're resetting this to an invalid thread id, then |
| 162 | // don't make an options pointer just to do that. |
| 163 | if (m_options_ap.get() != NULL) |
| 164 | m_options_ap->GetThreadSpec()->SetName(thread_name); |
| 165 | } |
| 166 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged); |
| 167 | } |
| 168 | |
| 169 | const char * |
| 170 | BreakpointLocation::GetThreadName () const |
| 171 | { |
| 172 | if (GetOptionsNoCreate()->GetThreadSpecNoCreate()) |
| 173 | return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetName(); |
| 174 | else |
| 175 | return NULL; |
| 176 | } |
| 177 | |
| 178 | void |
| 179 | BreakpointLocation::SetQueueName (const char *queue_name) |
| 180 | { |
| 181 | if (queue_name != NULL) |
| 182 | GetLocationOptions()->GetThreadSpec()->SetQueueName(queue_name); |
| 183 | else |
| 184 | { |
| 185 | // If we're resetting this to an invalid thread id, then |
| 186 | // don't make an options pointer just to do that. |
| 187 | if (m_options_ap.get() != NULL) |
| 188 | m_options_ap->GetThreadSpec()->SetQueueName(queue_name); |
| 189 | } |
| 190 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeThreadChanged); |
| 191 | } |
| 192 | |
| 193 | const char * |
| 194 | BreakpointLocation::GetQueueName () const |
| 195 | { |
| 196 | if (GetOptionsNoCreate()->GetThreadSpecNoCreate()) |
| 197 | return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetQueueName(); |
| 198 | else |
| 199 | return NULL; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | bool |
| 203 | BreakpointLocation::InvokeCallback (StoppointCallbackContext *context) |
| 204 | { |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 205 | if (m_options_ap.get() != NULL && m_options_ap->HasCallback()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 206 | return m_options_ap->InvokeCallback (context, m_owner.GetID(), GetID()); |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 207 | else |
| 208 | return m_owner.InvokeCallback (context, GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void |
| 212 | BreakpointLocation::SetCallback (BreakpointHitCallback callback, void *baton, |
| 213 | bool is_synchronous) |
| 214 | { |
| 215 | // The default "Baton" class will keep a copy of "baton" and won't free |
| 216 | // or delete it when it goes goes out of scope. |
| 217 | GetLocationOptions()->SetCallback(callback, BatonSP (new Baton(baton)), is_synchronous); |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 218 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeCommandChanged); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void |
| 222 | BreakpointLocation::SetCallback (BreakpointHitCallback callback, const BatonSP &baton_sp, |
| 223 | bool is_synchronous) |
| 224 | { |
| 225 | GetLocationOptions()->SetCallback (callback, baton_sp, is_synchronous); |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 226 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeCommandChanged); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 229 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 230 | void |
| 231 | BreakpointLocation::ClearCallback () |
| 232 | { |
| 233 | GetLocationOptions()->ClearCallback(); |
| 234 | } |
| 235 | |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 236 | void |
| 237 | BreakpointLocation::SetCondition (const char *condition) |
| 238 | { |
| 239 | GetLocationOptions()->SetCondition (condition); |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 240 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeConditionChanged); |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 243 | const char * |
Sean Callanan | 3dbf346 | 2013-04-19 07:09:15 +0000 | [diff] [blame] | 244 | BreakpointLocation::GetConditionText (size_t *hash) const |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 245 | { |
Sean Callanan | 3dbf346 | 2013-04-19 07:09:15 +0000 | [diff] [blame] | 246 | return GetOptionsNoCreate()->GetConditionText(hash); |
| 247 | } |
| 248 | |
| 249 | bool |
| 250 | BreakpointLocation::ConditionSaysStop (ExecutionContext &exe_ctx, Error &error) |
| 251 | { |
| 252 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
Sean Callanan | b4987e3 | 2013-06-06 20:18:50 +0000 | [diff] [blame] | 253 | |
| 254 | Mutex::Locker evaluation_locker(m_condition_mutex); |
Sean Callanan | 3dbf346 | 2013-04-19 07:09:15 +0000 | [diff] [blame] | 255 | |
| 256 | size_t condition_hash; |
| 257 | const char *condition_text = GetConditionText(&condition_hash); |
| 258 | |
| 259 | if (!condition_text) |
Sean Callanan | ec537a2 | 2013-05-10 21:58:45 +0000 | [diff] [blame] | 260 | { |
| 261 | m_user_expression_sp.reset(); |
Sean Callanan | 3dbf346 | 2013-04-19 07:09:15 +0000 | [diff] [blame] | 262 | return false; |
Sean Callanan | ec537a2 | 2013-05-10 21:58:45 +0000 | [diff] [blame] | 263 | } |
Sean Callanan | 3dbf346 | 2013-04-19 07:09:15 +0000 | [diff] [blame] | 264 | |
| 265 | if (condition_hash != m_condition_hash || |
| 266 | !m_user_expression_sp || |
| 267 | !m_user_expression_sp->MatchesContext(exe_ctx)) |
| 268 | { |
| 269 | m_user_expression_sp.reset(new ClangUserExpression(condition_text, |
| 270 | NULL, |
| 271 | lldb::eLanguageTypeUnknown, |
| 272 | ClangUserExpression::eResultTypeAny)); |
| 273 | |
| 274 | StreamString errors; |
| 275 | |
| 276 | if (!m_user_expression_sp->Parse(errors, |
| 277 | exe_ctx, |
| 278 | eExecutionPolicyOnlyWhenNeeded, |
| 279 | true)) |
| 280 | { |
| 281 | error.SetErrorStringWithFormat("Couldn't parse conditional expression:\n%s", |
| 282 | errors.GetData()); |
| 283 | m_user_expression_sp.reset(); |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | m_condition_hash = condition_hash; |
| 288 | } |
| 289 | |
| 290 | // We need to make sure the user sees any parse errors in their condition, so we'll hook the |
| 291 | // constructor errors up to the debugger's Async I/O. |
| 292 | |
| 293 | ValueObjectSP result_value_sp; |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame^] | 294 | |
| 295 | EvaluateExpressionOptions options; |
| 296 | options.SetUnwindOnError(true); |
| 297 | options.SetIgnoreBreakpoints(true); |
| 298 | options.SetRunOthers(true); |
Sean Callanan | 3dbf346 | 2013-04-19 07:09:15 +0000 | [diff] [blame] | 299 | |
| 300 | Error expr_error; |
| 301 | |
| 302 | StreamString execution_errors; |
| 303 | |
| 304 | ClangExpressionVariableSP result_variable_sp; |
| 305 | |
| 306 | ExecutionResults result_code = |
| 307 | m_user_expression_sp->Execute(execution_errors, |
| 308 | exe_ctx, |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame^] | 309 | options, |
Sean Callanan | 3dbf346 | 2013-04-19 07:09:15 +0000 | [diff] [blame] | 310 | m_user_expression_sp, |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame^] | 311 | result_variable_sp); |
Sean Callanan | 3dbf346 | 2013-04-19 07:09:15 +0000 | [diff] [blame] | 312 | |
| 313 | bool ret; |
| 314 | |
| 315 | if (result_code == eExecutionCompleted) |
| 316 | { |
Sean Callanan | 467441d5 | 2013-05-29 20:22:18 +0000 | [diff] [blame] | 317 | if (!result_variable_sp) |
| 318 | { |
| 319 | ret = false; |
| 320 | error.SetErrorString("Expression did not return a result"); |
Sean Callanan | 879425f | 2013-06-24 17:58:46 +0000 | [diff] [blame] | 321 | return false; |
Sean Callanan | 467441d5 | 2013-05-29 20:22:18 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Sean Callanan | 3dbf346 | 2013-04-19 07:09:15 +0000 | [diff] [blame] | 324 | result_value_sp = result_variable_sp->GetValueObject(); |
| 325 | |
| 326 | if (result_value_sp) |
| 327 | { |
| 328 | Scalar scalar_value; |
| 329 | if (result_value_sp->ResolveValue (scalar_value)) |
| 330 | { |
| 331 | if (scalar_value.ULongLong(1) == 0) |
| 332 | ret = false; |
| 333 | else |
| 334 | ret = true; |
| 335 | if (log) |
| 336 | log->Printf("Condition successfully evaluated, result is %s.\n", |
| 337 | ret ? "true" : "false"); |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | ret = false; |
| 342 | error.SetErrorString("Failed to get an integer result from the expression"); |
| 343 | } |
| 344 | } |
| 345 | else |
| 346 | { |
| 347 | ret = false; |
| 348 | error.SetErrorString("Failed to get any result from the expression"); |
| 349 | } |
| 350 | } |
| 351 | else |
| 352 | { |
| 353 | ret = false; |
| 354 | error.SetErrorStringWithFormat("Couldn't execute expression:\n%s", execution_errors.GetData()); |
| 355 | } |
| 356 | |
| 357 | return ret; |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 360 | uint32_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 361 | BreakpointLocation::GetIgnoreCount () |
| 362 | { |
Jim Ingham | 05407f6 | 2010-06-22 21:12:54 +0000 | [diff] [blame] | 363 | return GetOptionsNoCreate()->GetIgnoreCount(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | void |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 367 | BreakpointLocation::SetIgnoreCount (uint32_t n) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 368 | { |
| 369 | GetLocationOptions()->SetIgnoreCount(n); |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 370 | SendBreakpointLocationChangedEvent (eBreakpointEventTypeIgnoreChanged); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Jim Ingham | 0fd1b75 | 2012-06-26 22:27:55 +0000 | [diff] [blame] | 373 | void |
| 374 | BreakpointLocation::DecrementIgnoreCount() |
| 375 | { |
| 376 | if (m_options_ap.get() != NULL) |
| 377 | { |
| 378 | uint32_t loc_ignore = m_options_ap->GetIgnoreCount(); |
| 379 | if (loc_ignore != 0) |
| 380 | m_options_ap->SetIgnoreCount(loc_ignore - 1); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | bool |
| 385 | BreakpointLocation::IgnoreCountShouldStop() |
| 386 | { |
| 387 | if (m_options_ap.get() != NULL) |
| 388 | { |
| 389 | uint32_t loc_ignore = m_options_ap->GetIgnoreCount(); |
| 390 | if (loc_ignore != 0) |
| 391 | { |
| 392 | m_owner.DecrementIgnoreCount(); |
| 393 | DecrementIgnoreCount(); // Have to decrement our owners' ignore count, since it won't get a |
| 394 | // chance to. |
| 395 | return false; |
| 396 | } |
| 397 | } |
| 398 | return true; |
| 399 | } |
| 400 | |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 401 | const BreakpointOptions * |
Jim Ingham | 05407f6 | 2010-06-22 21:12:54 +0000 | [diff] [blame] | 402 | BreakpointLocation::GetOptionsNoCreate () const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 403 | { |
| 404 | if (m_options_ap.get() != NULL) |
| 405 | return m_options_ap.get(); |
| 406 | else |
| 407 | return m_owner.GetOptions (); |
| 408 | } |
| 409 | |
| 410 | BreakpointOptions * |
| 411 | BreakpointLocation::GetLocationOptions () |
| 412 | { |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 413 | // If we make the copy we don't copy the callbacks because that is potentially |
| 414 | // expensive and we don't want to do that for the simple case where someone is |
| 415 | // just disabling the location. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 416 | if (m_options_ap.get() == NULL) |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 417 | m_options_ap.reset(BreakpointOptions::CopyOptionsNoCallback(*m_owner.GetOptions ())); |
| 418 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 419 | return m_options_ap.get(); |
| 420 | } |
| 421 | |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 422 | bool |
| 423 | BreakpointLocation::ValidForThisThread (Thread *thread) |
| 424 | { |
Jim Ingham | 05407f6 | 2010-06-22 21:12:54 +0000 | [diff] [blame] | 425 | return thread->MatchesSpec(GetOptionsNoCreate()->GetThreadSpecNoCreate()); |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 428 | // RETURNS - true if we should stop at this breakpoint, false if we |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 429 | // should continue. Note, we don't check the thread spec for the breakpoint |
| 430 | // here, since if the breakpoint is not for this thread, then the event won't |
| 431 | // even get reported, so the check is redundant. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 432 | |
| 433 | bool |
| 434 | BreakpointLocation::ShouldStop (StoppointCallbackContext *context) |
| 435 | { |
| 436 | bool should_stop = true; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 437 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 438 | |
Johnny Chen | fab7a91 | 2012-01-23 23:03:59 +0000 | [diff] [blame] | 439 | IncrementHitCount(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 440 | |
| 441 | if (!IsEnabled()) |
| 442 | return false; |
| 443 | |
Jim Ingham | 0fd1b75 | 2012-06-26 22:27:55 +0000 | [diff] [blame] | 444 | if (!IgnoreCountShouldStop()) |
| 445 | return false; |
| 446 | |
| 447 | if (!m_owner.IgnoreCountShouldStop()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 448 | return false; |
| 449 | |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 450 | // We only run synchronous callbacks in ShouldStop: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 451 | context->is_synchronous = true; |
| 452 | should_stop = InvokeCallback (context); |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 453 | |
Jim Ingham | 5b52f0c | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 454 | if (log) |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 455 | { |
Jim Ingham | 5b52f0c | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 456 | StreamString s; |
| 457 | GetDescription (&s, lldb::eDescriptionLevelVerbose); |
| 458 | log->Printf ("Hit breakpoint location: %s, %s.\n", s.GetData(), should_stop ? "stopping" : "continuing"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 459 | } |
Jim Ingham | 5b52f0c | 2011-06-02 23:58:26 +0000 | [diff] [blame] | 460 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 461 | return should_stop; |
| 462 | } |
| 463 | |
| 464 | bool |
| 465 | BreakpointLocation::IsResolved () const |
| 466 | { |
| 467 | return m_bp_site_sp.get() != NULL; |
| 468 | } |
| 469 | |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 470 | lldb::BreakpointSiteSP |
| 471 | BreakpointLocation::GetBreakpointSite() const |
| 472 | { |
| 473 | return m_bp_site_sp; |
| 474 | } |
| 475 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 476 | bool |
| 477 | BreakpointLocation::ResolveBreakpointSite () |
| 478 | { |
| 479 | if (m_bp_site_sp) |
| 480 | return true; |
| 481 | |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 482 | Process *process = m_owner.GetTarget().GetProcessSP().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 483 | if (process == NULL) |
| 484 | return false; |
| 485 | |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 486 | lldb::break_id_t new_id = process->CreateBreakpointSite (shared_from_this(), m_owner.IsHardware()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 487 | |
Stephen Wilson | 50bd94f | 2010-07-17 00:56:13 +0000 | [diff] [blame] | 488 | if (new_id == LLDB_INVALID_BREAK_ID) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 489 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 490 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 491 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 492 | log->Warning ("Tried to add breakpoint site at 0x%" PRIx64 " but it was already present.\n", |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 493 | m_address.GetOpcodeLoadAddress (&m_owner.GetTarget())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 494 | return false; |
| 495 | } |
| 496 | |
| 497 | return true; |
| 498 | } |
| 499 | |
| 500 | bool |
| 501 | BreakpointLocation::SetBreakpointSite (BreakpointSiteSP& bp_site_sp) |
| 502 | { |
| 503 | m_bp_site_sp = bp_site_sp; |
| 504 | return true; |
| 505 | } |
| 506 | |
| 507 | bool |
| 508 | BreakpointLocation::ClearBreakpointSite () |
| 509 | { |
| 510 | if (m_bp_site_sp.get()) |
| 511 | { |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 512 | m_owner.GetTarget().GetProcessSP()->RemoveOwnerFromBreakpointSite (GetBreakpoint().GetID(), |
| 513 | GetID(), m_bp_site_sp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 514 | m_bp_site_sp.reset(); |
| 515 | return true; |
| 516 | } |
| 517 | return false; |
| 518 | } |
| 519 | |
| 520 | void |
| 521 | BreakpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 522 | { |
| 523 | SymbolContext sc; |
Jim Ingham | 1391cc7 | 2012-09-22 00:04:04 +0000 | [diff] [blame] | 524 | |
| 525 | // If the description level is "initial" then the breakpoint is printing out our initial state, |
| 526 | // and we should let it decide how it wants to print our label. |
| 527 | if (level != eDescriptionLevelInitial) |
| 528 | { |
| 529 | s->Indent(); |
| 530 | BreakpointID::GetCanonicalReference(s, m_owner.GetID(), GetID()); |
| 531 | } |
| 532 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 533 | if (level == lldb::eDescriptionLevelBrief) |
| 534 | return; |
| 535 | |
Jim Ingham | 1391cc7 | 2012-09-22 00:04:04 +0000 | [diff] [blame] | 536 | if (level != eDescriptionLevelInitial) |
| 537 | s->PutCString(": "); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 538 | |
| 539 | if (level == lldb::eDescriptionLevelVerbose) |
| 540 | s->IndentMore(); |
| 541 | |
| 542 | if (m_address.IsSectionOffset()) |
| 543 | { |
| 544 | m_address.CalculateSymbolContext(&sc); |
| 545 | |
Jim Ingham | 1391cc7 | 2012-09-22 00:04:04 +0000 | [diff] [blame] | 546 | if (level == lldb::eDescriptionLevelFull || level == eDescriptionLevelInitial) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 547 | { |
| 548 | s->PutCString("where = "); |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 549 | sc.DumpStopContext (s, m_owner.GetTarget().GetProcessSP().get(), m_address, false, true, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 550 | } |
| 551 | else |
| 552 | { |
| 553 | if (sc.module_sp) |
| 554 | { |
| 555 | s->EOL(); |
| 556 | s->Indent("module = "); |
| 557 | sc.module_sp->GetFileSpec().Dump (s); |
| 558 | } |
| 559 | |
| 560 | if (sc.comp_unit != NULL) |
| 561 | { |
| 562 | s->EOL(); |
| 563 | s->Indent("compile unit = "); |
Jim Ingham | 517b3b2 | 2010-10-27 22:58:34 +0000 | [diff] [blame] | 564 | static_cast<FileSpec*>(sc.comp_unit)->GetFilename().Dump (s); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 565 | |
| 566 | if (sc.function != NULL) |
| 567 | { |
| 568 | s->EOL(); |
| 569 | s->Indent("function = "); |
| 570 | s->PutCString (sc.function->GetMangled().GetName().AsCString("<unknown>")); |
| 571 | } |
| 572 | |
| 573 | if (sc.line_entry.line > 0) |
| 574 | { |
| 575 | s->EOL(); |
| 576 | s->Indent("location = "); |
Greg Clayton | 6dadd50 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 577 | sc.line_entry.DumpStopContext (s, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | } |
| 581 | else |
| 582 | { |
| 583 | // If we don't have a comp unit, see if we have a symbol we can print. |
| 584 | if (sc.symbol) |
| 585 | { |
| 586 | s->EOL(); |
| 587 | s->Indent("symbol = "); |
| 588 | s->PutCString(sc.symbol->GetMangled().GetName().AsCString("<unknown>")); |
| 589 | } |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | if (level == lldb::eDescriptionLevelVerbose) |
| 595 | { |
| 596 | s->EOL(); |
| 597 | s->Indent(); |
| 598 | } |
Jim Ingham | 1391cc7 | 2012-09-22 00:04:04 +0000 | [diff] [blame] | 599 | |
| 600 | if (m_address.IsSectionOffset() && (level == eDescriptionLevelFull || level == eDescriptionLevelInitial)) |
| 601 | s->Printf (", "); |
| 602 | s->Printf ("address = "); |
| 603 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 604 | ExecutionContextScope *exe_scope = NULL; |
| 605 | Target *target = &m_owner.GetTarget(); |
| 606 | if (target) |
| 607 | exe_scope = target->GetProcessSP().get(); |
| 608 | if (exe_scope == NULL) |
| 609 | exe_scope = target; |
| 610 | |
Jim Ingham | 1391cc7 | 2012-09-22 00:04:04 +0000 | [diff] [blame] | 611 | if (eDescriptionLevelInitial) |
| 612 | m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress); |
| 613 | else |
| 614 | m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 615 | |
| 616 | if (level == lldb::eDescriptionLevelVerbose) |
| 617 | { |
| 618 | s->EOL(); |
| 619 | s->Indent(); |
| 620 | s->Printf("resolved = %s\n", IsResolved() ? "true" : "false"); |
| 621 | |
| 622 | s->Indent(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 623 | s->Printf ("hit count = %-4u\n", GetHitCount()); |
| 624 | |
| 625 | if (m_options_ap.get()) |
| 626 | { |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 627 | s->Indent(); |
| 628 | m_options_ap->GetDescription (s, level); |
| 629 | s->EOL(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 630 | } |
| 631 | s->IndentLess(); |
| 632 | } |
Jim Ingham | 1391cc7 | 2012-09-22 00:04:04 +0000 | [diff] [blame] | 633 | else if (level != eDescriptionLevelInitial) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 634 | { |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 635 | s->Printf(", %sresolved, hit count = %u ", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 636 | (IsResolved() ? "" : "un"), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 637 | GetHitCount()); |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 638 | if (m_options_ap.get()) |
| 639 | { |
| 640 | m_options_ap->GetDescription (s, level); |
| 641 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | |
| 645 | void |
| 646 | BreakpointLocation::Dump(Stream *s) const |
| 647 | { |
| 648 | if (s == NULL) |
| 649 | return; |
| 650 | |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 651 | s->Printf("BreakpointLocation %u: tid = %4.4" PRIx64 " load addr = 0x%8.8" PRIx64 " state = %s type = %s breakpoint " |
Jim Ingham | 0136309 | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 652 | "hw_index = %i hit_count = %-4u ignore_count = %-4u", |
Johnny Chen | 9ec3c4f | 2012-01-26 00:08:14 +0000 | [diff] [blame] | 653 | GetID(), |
| 654 | GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetTID(), |
| 655 | (uint64_t) m_address.GetOpcodeLoadAddress (&m_owner.GetTarget()), |
Johnny Chen | 50df1f9 | 2012-01-30 22:48:10 +0000 | [diff] [blame] | 656 | (m_options_ap.get() ? m_options_ap->IsEnabled() : m_owner.IsEnabled()) ? "enabled " : "disabled", |
Johnny Chen | 9ec3c4f | 2012-01-26 00:08:14 +0000 | [diff] [blame] | 657 | IsHardware() ? "hardware" : "software", |
| 658 | GetHardwareIndex(), |
| 659 | GetHitCount(), |
| 660 | GetOptionsNoCreate()->GetIgnoreCount()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 661 | } |
Jim Ingham | e6bc6cb | 2012-02-08 05:23:15 +0000 | [diff] [blame] | 662 | |
| 663 | void |
| 664 | BreakpointLocation::SendBreakpointLocationChangedEvent (lldb::BreakpointEventType eventKind) |
| 665 | { |
| 666 | if (!m_being_created |
| 667 | && !m_owner.IsInternal() |
| 668 | && m_owner.GetTarget().EventTypeHasListeners(Target::eBroadcastBitBreakpointChanged)) |
| 669 | { |
| 670 | Breakpoint::BreakpointEventData *data = new Breakpoint::BreakpointEventData (eventKind, |
| 671 | m_owner.shared_from_this()); |
| 672 | data->GetBreakpointLocationCollection().Add (shared_from_this()); |
| 673 | m_owner.GetTarget().BroadcastEvent (Target::eBroadcastBitBreakpointChanged, data); |
| 674 | } |
| 675 | } |
| 676 | |