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