Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1 | //===-- StopInfo.cpp --------------------------------------------*- C++ -*-===// |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 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 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | #include <string> |
| 13 | |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Greg Clayton | 4e78f60 | 2010-11-18 18:52:36 +0000 | [diff] [blame] | 16 | #include "lldb/Breakpoint/Breakpoint.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 17 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 18 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 19 | #include "lldb/Breakpoint/Watchpoint.h" |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Debugger.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Log.h" |
Zachary Turner | a78bd7f | 2015-03-03 23:11:11 +0000 | [diff] [blame] | 22 | #include "lldb/Core/ValueObject.h" |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 23 | #include "lldb/Expression/UserExpression.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Process.h" |
| 25 | #include "lldb/Target/StopInfo.h" |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Target.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 27 | #include "lldb/Target/Thread.h" |
| 28 | #include "lldb/Target/ThreadPlan.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 29 | #include "lldb/Target/UnixSignals.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 30 | #include "lldb/Utility/StreamString.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 31 | |
| 32 | using namespace lldb; |
| 33 | using namespace lldb_private; |
| 34 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 35 | StopInfo::StopInfo(Thread &thread, uint64_t value) |
| 36 | : m_thread_wp(thread.shared_from_this()), |
| 37 | m_stop_id(thread.GetProcess()->GetStopID()), |
| 38 | m_resume_id(thread.GetProcess()->GetResumeID()), m_value(value), |
| 39 | m_description(), m_override_should_notify(eLazyBoolCalculate), |
| 40 | m_override_should_stop(eLazyBoolCalculate), m_extended_info() {} |
| 41 | |
| 42 | bool StopInfo::IsValid() const { |
| 43 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 44 | if (thread_sp) |
| 45 | return thread_sp->GetProcess()->GetStopID() == m_stop_id; |
| 46 | return false; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 49 | void StopInfo::MakeStopInfoValid() { |
| 50 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 51 | if (thread_sp) { |
| 52 | m_stop_id = thread_sp->GetProcess()->GetStopID(); |
| 53 | m_resume_id = thread_sp->GetProcess()->GetResumeID(); |
| 54 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 57 | bool StopInfo::HasTargetRunSinceMe() { |
| 58 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 59 | |
| 60 | if (thread_sp) { |
| 61 | lldb::StateType ret_type = thread_sp->GetProcess()->GetPrivateState(); |
| 62 | if (ret_type == eStateRunning) { |
| 63 | return true; |
| 64 | } else if (ret_type == eStateStopped) { |
| 65 | // This is a little tricky. We want to count "run and stopped again |
| 66 | // before you could |
| 67 | // ask this question as a "TRUE" answer to HasTargetRunSinceMe. But we |
| 68 | // don't want to |
| 69 | // include any running of the target done for expressions. So we track |
| 70 | // both resumes, |
| 71 | // and resumes caused by expressions, and check if there are any resumes |
| 72 | // NOT caused |
| 73 | // by expressions. |
| 74 | |
| 75 | uint32_t curr_resume_id = thread_sp->GetProcess()->GetResumeID(); |
| 76 | uint32_t last_user_expression_id = |
| 77 | thread_sp->GetProcess()->GetLastUserExpressionResumeID(); |
| 78 | if (curr_resume_id == m_resume_id) { |
| 79 | return false; |
| 80 | } else if (curr_resume_id > last_user_expression_id) { |
| 81 | return true; |
| 82 | } |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 83 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | } |
| 85 | return false; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 88 | //---------------------------------------------------------------------- |
| 89 | // StopInfoBreakpoint |
| 90 | //---------------------------------------------------------------------- |
| 91 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 92 | namespace lldb_private { |
| 93 | class StopInfoBreakpoint : public StopInfo { |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 94 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 95 | StopInfoBreakpoint(Thread &thread, break_id_t break_id) |
| 96 | : StopInfo(thread, break_id), m_should_stop(false), |
| 97 | m_should_stop_is_valid(false), m_should_perform_action(true), |
| 98 | m_address(LLDB_INVALID_ADDRESS), m_break_id(LLDB_INVALID_BREAK_ID), |
| 99 | m_was_one_shot(false) { |
| 100 | StoreBPInfo(); |
| 101 | } |
| 102 | |
| 103 | StopInfoBreakpoint(Thread &thread, break_id_t break_id, bool should_stop) |
| 104 | : StopInfo(thread, break_id), m_should_stop(should_stop), |
| 105 | m_should_stop_is_valid(true), m_should_perform_action(true), |
| 106 | m_address(LLDB_INVALID_ADDRESS), m_break_id(LLDB_INVALID_BREAK_ID), |
| 107 | m_was_one_shot(false) { |
| 108 | StoreBPInfo(); |
| 109 | } |
| 110 | |
| 111 | ~StopInfoBreakpoint() override = default; |
| 112 | |
| 113 | void StoreBPInfo() { |
| 114 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 115 | if (thread_sp) { |
| 116 | BreakpointSiteSP bp_site_sp( |
| 117 | thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value)); |
| 118 | if (bp_site_sp) { |
| 119 | if (bp_site_sp->GetNumberOfOwners() == 1) { |
| 120 | BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(0); |
| 121 | if (bp_loc_sp) { |
| 122 | m_break_id = bp_loc_sp->GetBreakpoint().GetID(); |
| 123 | m_was_one_shot = bp_loc_sp->GetBreakpoint().IsOneShot(); |
| 124 | } |
| 125 | } |
| 126 | m_address = bp_site_sp->GetLoadAddress(); |
| 127 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 128 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 129 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 130 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 131 | bool IsValidForOperatingSystemThread(Thread &thread) override { |
| 132 | ProcessSP process_sp(thread.GetProcess()); |
| 133 | if (process_sp) { |
| 134 | BreakpointSiteSP bp_site_sp( |
| 135 | process_sp->GetBreakpointSiteList().FindByID(m_value)); |
| 136 | if (bp_site_sp) |
| 137 | return bp_site_sp->ValidForThisThread(&thread); |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 138 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 139 | return false; |
| 140 | } |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 141 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 142 | StopReason GetStopReason() const override { return eStopReasonBreakpoint; } |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 143 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 144 | bool ShouldStopSynchronous(Event *event_ptr) override { |
| 145 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 146 | if (thread_sp) { |
| 147 | if (!m_should_stop_is_valid) { |
| 148 | // Only check once if we should stop at a breakpoint |
| 149 | BreakpointSiteSP bp_site_sp( |
| 150 | thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value)); |
| 151 | if (bp_site_sp) { |
| 152 | ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0)); |
| 153 | StoppointCallbackContext context(event_ptr, exe_ctx, true); |
| 154 | bp_site_sp->BumpHitCounts(); |
| 155 | m_should_stop = bp_site_sp->ShouldStop(&context); |
| 156 | } else { |
| 157 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); |
| 158 | |
| 159 | if (log) |
| 160 | log->Printf( |
| 161 | "Process::%s could not find breakpoint site id: %" PRId64 "...", |
| 162 | __FUNCTION__, m_value); |
| 163 | |
| 164 | m_should_stop = true; |
| 165 | } |
| 166 | m_should_stop_is_valid = true; |
| 167 | } |
| 168 | return m_should_stop; |
| 169 | } |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | bool DoShouldNotify(Event *event_ptr) override { |
| 174 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 175 | if (thread_sp) { |
| 176 | BreakpointSiteSP bp_site_sp( |
| 177 | thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value)); |
| 178 | if (bp_site_sp) { |
| 179 | bool all_internal = true; |
| 180 | |
| 181 | for (uint32_t i = 0; i < bp_site_sp->GetNumberOfOwners(); i++) { |
| 182 | if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal()) { |
| 183 | all_internal = false; |
| 184 | break; |
| 185 | } |
| 186 | } |
| 187 | return !all_internal; |
| 188 | } |
| 189 | } |
| 190 | return true; |
| 191 | } |
| 192 | |
| 193 | const char *GetDescription() override { |
| 194 | if (m_description.empty()) { |
| 195 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 196 | if (thread_sp) { |
| 197 | BreakpointSiteSP bp_site_sp( |
| 198 | thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value)); |
| 199 | if (bp_site_sp) { |
| 200 | StreamString strm; |
| 201 | // If we have just hit an internal breakpoint, and it has a kind |
| 202 | // description, print that instead of the |
| 203 | // full breakpoint printing: |
| 204 | if (bp_site_sp->IsInternal()) { |
| 205 | size_t num_owners = bp_site_sp->GetNumberOfOwners(); |
| 206 | for (size_t idx = 0; idx < num_owners; idx++) { |
| 207 | const char *kind = bp_site_sp->GetOwnerAtIndex(idx) |
| 208 | ->GetBreakpoint() |
| 209 | .GetBreakpointKind(); |
| 210 | if (kind != nullptr) { |
| 211 | m_description.assign(kind); |
| 212 | return kind; |
| 213 | } |
Jim Ingham | ca36cd1 | 2012-10-05 19:16:31 +0000 | [diff] [blame] | 214 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 215 | } |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 216 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 217 | strm.Printf("breakpoint "); |
| 218 | bp_site_sp->GetDescription(&strm, eDescriptionLevelBrief); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 219 | m_description = strm.GetString(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 220 | } else { |
| 221 | StreamString strm; |
| 222 | if (m_break_id != LLDB_INVALID_BREAK_ID) { |
| 223 | BreakpointSP break_sp = |
| 224 | thread_sp->GetProcess()->GetTarget().GetBreakpointByID( |
| 225 | m_break_id); |
| 226 | if (break_sp) { |
| 227 | if (break_sp->IsInternal()) { |
| 228 | const char *kind = break_sp->GetBreakpointKind(); |
| 229 | if (kind) |
| 230 | strm.Printf("internal %s breakpoint(%d).", kind, m_break_id); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 231 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 232 | strm.Printf("internal breakpoint(%d).", m_break_id); |
| 233 | } else { |
| 234 | strm.Printf("breakpoint %d.", m_break_id); |
| 235 | } |
| 236 | } else { |
| 237 | if (m_was_one_shot) |
| 238 | strm.Printf("one-shot breakpoint %d", m_break_id); |
| 239 | else |
| 240 | strm.Printf("breakpoint %d which has been deleted.", |
| 241 | m_break_id); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 242 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 243 | } else if (m_address == LLDB_INVALID_ADDRESS) |
| 244 | strm.Printf("breakpoint site %" PRIi64 |
| 245 | " which has been deleted - unknown address", |
| 246 | m_value); |
| 247 | else |
| 248 | strm.Printf("breakpoint site %" PRIi64 |
| 249 | " which has been deleted - was at 0x%" PRIx64, |
| 250 | m_value, m_address); |
| 251 | |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 252 | m_description = strm.GetString(); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 253 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 254 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 255 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 256 | return m_description.c_str(); |
| 257 | } |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 258 | |
| 259 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 260 | bool ShouldStop(Event *event_ptr) override { |
| 261 | // This just reports the work done by PerformAction or the synchronous stop. |
| 262 | // It should |
| 263 | // only ever get called after they have had a chance to run. |
| 264 | assert(m_should_stop_is_valid); |
| 265 | return m_should_stop; |
| 266 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 267 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 268 | void PerformAction(Event *event_ptr) override { |
| 269 | if (!m_should_perform_action) |
| 270 | return; |
| 271 | m_should_perform_action = false; |
Boris Ulasevich | 86aaa8a | 2017-02-15 11:42:47 +0000 | [diff] [blame^] | 272 | bool internal_breakpoint = true; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 273 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 274 | ThreadSP thread_sp(m_thread_wp.lock()); |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 275 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 276 | if (thread_sp) { |
| 277 | Log *log = lldb_private::GetLogIfAnyCategoriesSet( |
| 278 | LIBLLDB_LOG_BREAKPOINTS | LIBLLDB_LOG_STEP); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 279 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 280 | if (!thread_sp->IsValid()) { |
| 281 | // This shouldn't ever happen, but just in case, don't do more harm. |
| 282 | if (log) { |
| 283 | log->Printf("PerformAction got called with an invalid thread."); |
| 284 | } |
| 285 | m_should_stop = true; |
| 286 | m_should_stop_is_valid = true; |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | BreakpointSiteSP bp_site_sp( |
| 291 | thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value)); |
| 292 | std::unordered_set<break_id_t> precondition_breakpoints; |
| 293 | |
| 294 | if (bp_site_sp) { |
| 295 | // Let's copy the owners list out of the site and store them in a local |
| 296 | // list. That way if |
| 297 | // one of the breakpoint actions changes the site, then we won't be |
| 298 | // operating on a bad list. |
| 299 | BreakpointLocationCollection site_locations; |
| 300 | size_t num_owners = bp_site_sp->CopyOwnersList(site_locations); |
| 301 | |
| 302 | if (num_owners == 0) { |
| 303 | m_should_stop = true; |
| 304 | } else { |
| 305 | // We go through each location, and test first its precondition - this |
| 306 | // overrides everything. Note, |
| 307 | // we only do this once per breakpoint - not once per location... |
| 308 | // Then check the condition. If the condition says to stop, |
| 309 | // then we run the callback for that location. If that callback says |
| 310 | // to stop as well, then |
| 311 | // we set m_should_stop to true; we are going to stop. |
| 312 | // But we still want to give all the breakpoints whose conditions say |
| 313 | // we are going to stop a |
| 314 | // chance to run their callbacks. |
| 315 | // Of course if any callback restarts the target by putting "continue" |
| 316 | // in the callback, then |
| 317 | // we're going to restart, without running the rest of the callbacks. |
| 318 | // And in this case we will |
| 319 | // end up not stopping even if another location said we should stop. |
| 320 | // But that's better than not |
| 321 | // running all the callbacks. |
| 322 | |
| 323 | m_should_stop = false; |
| 324 | |
| 325 | // We don't select threads as we go through them testing breakpoint |
| 326 | // conditions and running commands. |
| 327 | // So we need to set the thread for expression evaluation here: |
| 328 | ThreadList::ExpressionExecutionThreadPusher thread_pusher(thread_sp); |
| 329 | |
| 330 | ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0)); |
| 331 | Process *process = exe_ctx.GetProcessPtr(); |
| 332 | if (process->GetModIDRef().IsLastResumeForUserExpression()) { |
| 333 | // If we are in the middle of evaluating an expression, don't run |
| 334 | // asynchronous breakpoint commands or |
| 335 | // expressions. That could lead to infinite recursion if the |
| 336 | // command or condition re-calls the function |
| 337 | // with this breakpoint. |
| 338 | // TODO: We can keep a list of the breakpoints we've seen while |
| 339 | // running expressions in the nested |
| 340 | // PerformAction calls that can arise when the action runs a |
| 341 | // function that hits another breakpoint, |
| 342 | // and only stop running commands when we see the same breakpoint |
| 343 | // hit a second time. |
| 344 | |
| 345 | m_should_stop_is_valid = true; |
| 346 | if (log) |
| 347 | log->Printf("StopInfoBreakpoint::PerformAction - Hit a " |
| 348 | "breakpoint while running an expression," |
| 349 | " not running commands to avoid recursion."); |
| 350 | bool ignoring_breakpoints = |
| 351 | process->GetIgnoreBreakpointsInExpressions(); |
| 352 | if (ignoring_breakpoints) { |
| 353 | m_should_stop = false; |
| 354 | // Internal breakpoints will always stop. |
| 355 | for (size_t j = 0; j < num_owners; j++) { |
| 356 | lldb::BreakpointLocationSP bp_loc_sp = |
| 357 | bp_site_sp->GetOwnerAtIndex(j); |
| 358 | if (bp_loc_sp->GetBreakpoint().IsInternal()) { |
| 359 | m_should_stop = true; |
| 360 | break; |
Jason Molenda | 3f032ff | 2013-08-06 23:08:59 +0000 | [diff] [blame] | 361 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 362 | } |
| 363 | } else { |
| 364 | m_should_stop = true; |
Greg Clayton | 46c2b6e | 2013-04-29 23:30:46 +0000 | [diff] [blame] | 365 | } |
| 366 | if (log) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 367 | log->Printf("StopInfoBreakpoint::PerformAction - in expression, " |
| 368 | "continuing: %s.", |
| 369 | m_should_stop ? "true" : "false"); |
| 370 | process->GetTarget().GetDebugger().GetAsyncOutputStream()->Printf( |
| 371 | "Warning: hit breakpoint while " |
| 372 | "running function, skipping commands and conditions to prevent " |
| 373 | "recursion."); |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | StoppointCallbackContext context(event_ptr, exe_ctx, false); |
| 378 | |
| 379 | // For safety's sake let's also grab an extra reference to the |
| 380 | // breakpoint owners of the locations we're |
| 381 | // going to examine, since the locations are going to have to get back |
| 382 | // to their breakpoints, and the |
| 383 | // locations don't keep their owners alive. I'm just sticking the |
| 384 | // BreakpointSP's in a vector since |
| 385 | // I'm only using it to locally increment their retain counts. |
| 386 | |
| 387 | std::vector<lldb::BreakpointSP> location_owners; |
| 388 | |
| 389 | for (size_t j = 0; j < num_owners; j++) { |
| 390 | BreakpointLocationSP loc(site_locations.GetByIndex(j)); |
| 391 | location_owners.push_back(loc->GetBreakpoint().shared_from_this()); |
| 392 | } |
| 393 | |
| 394 | for (size_t j = 0; j < num_owners; j++) { |
| 395 | lldb::BreakpointLocationSP bp_loc_sp = site_locations.GetByIndex(j); |
| 396 | |
| 397 | // If another action disabled this breakpoint or its location, then |
| 398 | // don't run the actions. |
| 399 | if (!bp_loc_sp->IsEnabled() || |
| 400 | !bp_loc_sp->GetBreakpoint().IsEnabled()) |
| 401 | continue; |
| 402 | |
| 403 | // The breakpoint site may have many locations associated with it, |
| 404 | // not all of them valid for |
| 405 | // this thread. Skip the ones that aren't: |
| 406 | if (!bp_loc_sp->ValidForThisThread(thread_sp.get())) { |
| 407 | if (log) { |
| 408 | StreamString s; |
| 409 | bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief); |
| 410 | log->Printf("Breakpoint %s hit on thread 0x%llx but it was not " |
| 411 | "for this thread, continuing.", |
| 412 | s.GetData(), static_cast<unsigned long long>( |
| 413 | thread_sp->GetID())); |
| 414 | } |
| 415 | continue; |
| 416 | } |
| 417 | |
| 418 | // First run the precondition, but since the precondition is per |
| 419 | // breakpoint, only run it once |
| 420 | // per breakpoint. |
| 421 | std::pair<std::unordered_set<break_id_t>::iterator, bool> result = |
| 422 | precondition_breakpoints.insert( |
| 423 | bp_loc_sp->GetBreakpoint().GetID()); |
| 424 | if (!result.second) |
| 425 | continue; |
| 426 | |
| 427 | bool precondition_result = |
| 428 | bp_loc_sp->GetBreakpoint().EvaluatePrecondition(context); |
| 429 | if (!precondition_result) |
| 430 | continue; |
| 431 | |
| 432 | // Next run the condition for the breakpoint. If that says we |
| 433 | // should stop, then we'll run |
| 434 | // the callback for the breakpoint. If the callback says we |
| 435 | // shouldn't stop that will win. |
| 436 | |
| 437 | if (bp_loc_sp->GetConditionText() != nullptr) { |
| 438 | Error condition_error; |
| 439 | bool condition_says_stop = |
| 440 | bp_loc_sp->ConditionSaysStop(exe_ctx, condition_error); |
| 441 | |
| 442 | if (!condition_error.Success()) { |
| 443 | Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger(); |
| 444 | StreamSP error_sp = debugger.GetAsyncErrorStream(); |
| 445 | error_sp->Printf("Stopped due to an error evaluating condition " |
| 446 | "of breakpoint "); |
| 447 | bp_loc_sp->GetDescription(error_sp.get(), |
| 448 | eDescriptionLevelBrief); |
| 449 | error_sp->Printf(": \"%s\"", bp_loc_sp->GetConditionText()); |
| 450 | error_sp->EOL(); |
| 451 | const char *err_str = |
| 452 | condition_error.AsCString("<Unknown Error>"); |
| 453 | if (log) |
| 454 | log->Printf("Error evaluating condition: \"%s\"\n", err_str); |
| 455 | |
| 456 | error_sp->PutCString(err_str); |
| 457 | error_sp->EOL(); |
| 458 | error_sp->Flush(); |
| 459 | } else { |
| 460 | if (log) { |
| 461 | StreamString s; |
| 462 | bp_loc_sp->GetDescription(&s, eDescriptionLevelBrief); |
| 463 | log->Printf("Condition evaluated for breakpoint %s on thread " |
| 464 | "0x%llx conditon_says_stop: %i.", |
| 465 | s.GetData(), static_cast<unsigned long long>( |
| 466 | thread_sp->GetID()), |
| 467 | condition_says_stop); |
| 468 | } |
| 469 | if (!condition_says_stop) { |
| 470 | // We don't want to increment the hit count of breakpoints if |
| 471 | // the condition fails. |
| 472 | // We've already bumped it by the time we get here, so undo |
| 473 | // the bump: |
| 474 | bp_loc_sp->UndoBumpHitCount(); |
| 475 | continue; |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | bool callback_says_stop; |
| 481 | |
| 482 | // FIXME: For now the callbacks have to run in async mode - the |
| 483 | // first time we restart we need |
| 484 | // to get out of there. So set it here. |
| 485 | // When we figure out how to nest breakpoint hits then this will |
| 486 | // change. |
| 487 | |
| 488 | Debugger &debugger = thread_sp->CalculateTarget()->GetDebugger(); |
| 489 | bool old_async = debugger.GetAsyncExecution(); |
| 490 | debugger.SetAsyncExecution(true); |
| 491 | |
| 492 | callback_says_stop = bp_loc_sp->InvokeCallback(&context); |
| 493 | |
| 494 | debugger.SetAsyncExecution(old_async); |
| 495 | |
| 496 | if (callback_says_stop) |
| 497 | m_should_stop = true; |
| 498 | |
Boris Ulasevich | 86aaa8a | 2017-02-15 11:42:47 +0000 | [diff] [blame^] | 499 | if (m_should_stop && !bp_loc_sp->GetBreakpoint().IsInternal()) |
| 500 | internal_breakpoint = false; |
| 501 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 502 | // If we are going to stop for this breakpoint, then remove the |
| 503 | // breakpoint. |
| 504 | if (callback_says_stop && bp_loc_sp && |
| 505 | bp_loc_sp->GetBreakpoint().IsOneShot()) { |
| 506 | thread_sp->GetProcess()->GetTarget().RemoveBreakpointByID( |
| 507 | bp_loc_sp->GetBreakpoint().GetID()); |
| 508 | } |
| 509 | |
| 510 | // Also make sure that the callback hasn't continued the target. |
| 511 | // If it did, when we'll set m_should_start to false and get out of |
| 512 | // here. |
| 513 | if (HasTargetRunSinceMe()) { |
| 514 | m_should_stop = false; |
| 515 | break; |
| 516 | } |
| 517 | } |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 518 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 519 | // We've figured out what this stop wants to do, so mark it as valid so |
| 520 | // we don't compute it again. |
| 521 | m_should_stop_is_valid = true; |
| 522 | } else { |
| 523 | m_should_stop = true; |
| 524 | m_should_stop_is_valid = true; |
| 525 | Log *log_process( |
| 526 | lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); |
| 527 | |
| 528 | if (log_process) |
| 529 | log_process->Printf( |
| 530 | "Process::%s could not find breakpoint site id: %" PRId64 "...", |
| 531 | __FUNCTION__, m_value); |
| 532 | } |
Boris Ulasevich | 86aaa8a | 2017-02-15 11:42:47 +0000 | [diff] [blame^] | 533 | |
| 534 | if ((m_should_stop == false || internal_breakpoint) |
| 535 | && thread_sp->CompletedPlanOverridesBreakpoint()) { |
| 536 | |
| 537 | // Override should_stop decision when we have |
| 538 | // completed step plan additionally to the breakpoint |
| 539 | m_should_stop = true; |
| 540 | |
| 541 | // Here we clean the preset stop info so the next |
| 542 | // GetStopInfo call will find the appropriate stop info, |
| 543 | // which should be the stop info related to the completed plan |
| 544 | thread_sp->ResetStopInfo(); |
| 545 | } |
| 546 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 547 | if (log) |
| 548 | log->Printf("Process::%s returning from action with m_should_stop: %d.", |
| 549 | __FUNCTION__, m_should_stop); |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 550 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 551 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 552 | |
| 553 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 554 | bool m_should_stop; |
| 555 | bool m_should_stop_is_valid; |
| 556 | bool m_should_perform_action; // Since we are trying to preserve the "state" |
| 557 | // of the system even if we run functions |
| 558 | // etc. behind the users backs, we need to make sure we only REALLY perform |
| 559 | // the action once. |
| 560 | lldb::addr_t m_address; // We use this to capture the breakpoint site address |
| 561 | // when we create the StopInfo, |
| 562 | // in case somebody deletes it between the time the StopInfo is made and the |
| 563 | // description is asked for. |
| 564 | lldb::break_id_t m_break_id; |
| 565 | bool m_was_one_shot; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 566 | }; |
| 567 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 568 | //---------------------------------------------------------------------- |
| 569 | // StopInfoWatchpoint |
| 570 | //---------------------------------------------------------------------- |
| 571 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 572 | class StopInfoWatchpoint : public StopInfo { |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 573 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 574 | // Make sure watchpoint is properly disabled and subsequently enabled while |
| 575 | // performing watchpoint actions. |
| 576 | class WatchpointSentry { |
| 577 | public: |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 578 | WatchpointSentry(ProcessSP p_sp, WatchpointSP w_sp) : process_sp(p_sp), |
| 579 | watchpoint_sp(w_sp) { |
| 580 | if (process_sp && watchpoint_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 581 | const bool notify = false; |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 582 | watchpoint_sp->TurnOnEphemeralMode(); |
| 583 | process_sp->DisableWatchpoint(watchpoint_sp.get(), notify); |
| 584 | process_sp->AddPreResumeAction(SentryPreResumeAction, this); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 585 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 586 | } |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 587 | |
| 588 | void DoReenable() { |
| 589 | if (process_sp && watchpoint_sp) { |
| 590 | bool was_disabled = watchpoint_sp->IsDisabledDuringEphemeralMode(); |
| 591 | watchpoint_sp->TurnOffEphemeralMode(); |
| 592 | const bool notify = false; |
| 593 | if (was_disabled) { |
| 594 | process_sp->DisableWatchpoint(watchpoint_sp.get(), notify); |
| 595 | } else { |
| 596 | process_sp->EnableWatchpoint(watchpoint_sp.get(), notify); |
Pavel Labath | 2e8fe80 | 2016-10-21 10:52:11 +0000 | [diff] [blame] | 597 | } |
Pavel Labath | 2e8fe80 | 2016-10-21 10:52:11 +0000 | [diff] [blame] | 598 | } |
Jim Ingham | 94bd575 | 2016-10-21 00:06:38 +0000 | [diff] [blame] | 599 | } |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 600 | |
| 601 | ~WatchpointSentry() { |
| 602 | DoReenable(); |
| 603 | if (process_sp) |
| 604 | process_sp->ClearPreResumeAction(SentryPreResumeAction, this); |
| 605 | } |
| 606 | |
| 607 | static bool SentryPreResumeAction(void *sentry_void) { |
| 608 | WatchpointSentry *sentry = (WatchpointSentry *) sentry_void; |
| 609 | sentry->DoReenable(); |
| 610 | return true; |
| 611 | } |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 612 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 613 | private: |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 614 | ProcessSP process_sp; |
| 615 | WatchpointSP watchpoint_sp; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 616 | }; |
| 617 | |
| 618 | StopInfoWatchpoint(Thread &thread, break_id_t watch_id, |
| 619 | lldb::addr_t watch_hit_addr) |
| 620 | : StopInfo(thread, watch_id), m_should_stop(false), |
| 621 | m_should_stop_is_valid(false), m_watch_hit_addr(watch_hit_addr) {} |
| 622 | |
| 623 | ~StopInfoWatchpoint() override = default; |
| 624 | |
| 625 | StopReason GetStopReason() const override { return eStopReasonWatchpoint; } |
| 626 | |
| 627 | const char *GetDescription() override { |
| 628 | if (m_description.empty()) { |
| 629 | StreamString strm; |
| 630 | strm.Printf("watchpoint %" PRIi64, m_value); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 631 | m_description = strm.GetString(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 632 | } |
| 633 | return m_description.c_str(); |
| 634 | } |
| 635 | |
Jim Ingham | f57b435 | 2012-11-10 02:08:14 +0000 | [diff] [blame] | 636 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 637 | bool ShouldStopSynchronous(Event *event_ptr) override { |
| 638 | // ShouldStop() method is idempotent and should not affect hit count. |
| 639 | // See Process::RunPrivateStateThread()->Process()->HandlePrivateEvent() |
| 640 | // -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()-> |
| 641 | // Thread::ShouldStop()->ThreadPlanBase::ShouldStop()-> |
| 642 | // StopInfoWatchpoint::ShouldStop() and |
| 643 | // Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()-> |
| 644 | // StopInfoWatchpoint::PerformAction(). |
| 645 | if (m_should_stop_is_valid) |
| 646 | return m_should_stop; |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 647 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 648 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 649 | if (thread_sp) { |
| 650 | WatchpointSP wp_sp( |
| 651 | thread_sp->CalculateTarget()->GetWatchpointList().FindByID( |
| 652 | GetValue())); |
| 653 | if (wp_sp) { |
| 654 | // Check if we should stop at a watchpoint. |
| 655 | ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0)); |
| 656 | StoppointCallbackContext context(event_ptr, exe_ctx, true); |
| 657 | m_should_stop = wp_sp->ShouldStop(&context); |
| 658 | } else { |
| 659 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 660 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 661 | if (log) |
| 662 | log->Printf( |
| 663 | "Process::%s could not find watchpoint location id: %" PRId64 |
| 664 | "...", |
| 665 | __FUNCTION__, GetValue()); |
Johnny Chen | fd158f4 | 2011-09-21 22:47:15 +0000 | [diff] [blame] | 666 | |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 667 | m_should_stop = true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 668 | } |
Johnny Chen | 16dcf71 | 2011-10-17 18:58:00 +0000 | [diff] [blame] | 669 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 670 | m_should_stop_is_valid = true; |
| 671 | return m_should_stop; |
| 672 | } |
| 673 | |
| 674 | bool ShouldStop(Event *event_ptr) override { |
| 675 | // This just reports the work done by PerformAction or the synchronous stop. |
| 676 | // It should |
| 677 | // only ever get called after they have had a chance to run. |
| 678 | assert(m_should_stop_is_valid); |
| 679 | return m_should_stop; |
| 680 | } |
| 681 | |
| 682 | void PerformAction(Event *event_ptr) override { |
| 683 | Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS); |
| 684 | // We're going to calculate if we should stop or not in some way during the |
| 685 | // course of |
| 686 | // this code. Also by default we're going to stop, so set that here. |
| 687 | m_should_stop = true; |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 688 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 689 | |
| 690 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 691 | if (thread_sp) { |
| 692 | |
| 693 | WatchpointSP wp_sp( |
| 694 | thread_sp->CalculateTarget()->GetWatchpointList().FindByID( |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 695 | GetValue())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 696 | if (wp_sp) { |
| 697 | ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0)); |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 698 | ProcessSP process_sp = exe_ctx.GetProcessSP(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 699 | |
| 700 | { |
| 701 | // check if this process is running on an architecture where |
| 702 | // watchpoints trigger |
| 703 | // before the associated instruction runs. if so, disable the WP, |
| 704 | // single-step and then |
| 705 | // re-enable the watchpoint |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 706 | if (process_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 707 | uint32_t num; |
| 708 | bool wp_triggers_after; |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 709 | |
| 710 | if (process_sp->GetWatchpointSupportInfo(num, wp_triggers_after) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 711 | .Success()) { |
| 712 | if (!wp_triggers_after) { |
Nitesh Jain | 0546e84 | 2016-12-09 13:54:47 +0000 | [diff] [blame] | 713 | // We need to preserve the watch_index before watchpoint |
| 714 | // is disable. Since Watchpoint::SetEnabled will clear the |
| 715 | // watch index. |
| 716 | // This will fix TestWatchpointIter failure |
| 717 | Watchpoint *wp = wp_sp.get(); |
| 718 | uint32_t watch_index = wp->GetHardwareIndex(); |
| 719 | process_sp->DisableWatchpoint(wp, false); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 720 | StopInfoSP stored_stop_info_sp = thread_sp->GetStopInfo(); |
| 721 | assert(stored_stop_info_sp.get() == this); |
| 722 | |
| 723 | ThreadPlanSP new_plan_sp( |
| 724 | thread_sp->QueueThreadPlanForStepSingleInstruction( |
| 725 | false, // step-over |
| 726 | false, // abort_other_plans |
| 727 | true)); // stop_other_threads |
| 728 | new_plan_sp->SetIsMasterPlan(true); |
| 729 | new_plan_sp->SetOkayToDiscard(false); |
| 730 | new_plan_sp->SetPrivate(true); |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 731 | process_sp->GetThreadList().SetSelectedThreadByID( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 732 | thread_sp->GetID()); |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 733 | process_sp->ResumeSynchronous(nullptr); |
| 734 | process_sp->GetThreadList().SetSelectedThreadByID( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 735 | thread_sp->GetID()); |
| 736 | thread_sp->SetStopInfo(stored_stop_info_sp); |
Nitesh Jain | 0546e84 | 2016-12-09 13:54:47 +0000 | [diff] [blame] | 737 | process_sp->EnableWatchpoint(wp, false); |
| 738 | wp->SetHardwareIndex(watch_index); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 739 | } |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 744 | // This sentry object makes sure the current watchpoint is disabled |
| 745 | // while performing watchpoint actions, |
| 746 | // and it is then enabled after we are finished. |
| 747 | WatchpointSentry sentry(process_sp, wp_sp); |
| 748 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 749 | /* |
| 750 | * MIPS: Last 3bits of the watchpoint address are masked by the kernel. |
| 751 | * For example: |
| 752 | * 'n' is at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is |
| 753 | * set at 'm', then |
| 754 | * watch exception is generated even when 'n' is read/written. To handle |
| 755 | * this case, |
| 756 | * server emulates the instruction at PC and finds the base address of |
| 757 | * the load/store |
| 758 | * instruction and appends it in the description of the stop-info |
| 759 | * packet. If watchpoint |
| 760 | * is not set on this address by user then this do not stop. |
| 761 | */ |
| 762 | if (m_watch_hit_addr != LLDB_INVALID_ADDRESS) { |
| 763 | WatchpointSP wp_hit_sp = |
| 764 | thread_sp->CalculateTarget()->GetWatchpointList().FindByAddress( |
| 765 | m_watch_hit_addr); |
| 766 | if (!wp_hit_sp) { |
| 767 | m_should_stop = false; |
| 768 | wp_sp->IncrementFalseAlarmsAndReviseHitCount(); |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | // TODO: This condition should be checked in the synchronous part of the |
| 773 | // watchpoint code |
| 774 | // (Watchpoint::ShouldStop), so that we avoid pulling an event even if |
| 775 | // the watchpoint fails |
| 776 | // the ignore count condition. It is moved here temporarily, because for |
| 777 | // archs with |
| 778 | // watchpoint_exceptions_received=before, the code in the previous lines |
| 779 | // takes care of moving |
| 780 | // the inferior to next PC. We have to check the ignore count condition |
| 781 | // after this is done, |
| 782 | // otherwise we will hit same watchpoint multiple times until we pass |
| 783 | // ignore condition, but we |
| 784 | // won't actually be ignoring them. |
| 785 | if (wp_sp->GetHitCount() <= wp_sp->GetIgnoreCount()) |
| 786 | m_should_stop = false; |
| 787 | |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 788 | Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger(); |
| 789 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 790 | if (m_should_stop && wp_sp->GetConditionText() != nullptr) { |
| 791 | // We need to make sure the user sees any parse errors in their |
Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 792 | // condition, so we'll hook the constructor errors up to the |
| 793 | // debugger's Async I/O. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 794 | ExpressionResults result_code; |
| 795 | EvaluateExpressionOptions expr_options; |
| 796 | expr_options.SetUnwindOnError(true); |
| 797 | expr_options.SetIgnoreBreakpoints(true); |
| 798 | ValueObjectSP result_value_sp; |
| 799 | Error error; |
| 800 | result_code = UserExpression::Evaluate( |
Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 801 | exe_ctx, expr_options, wp_sp->GetConditionText(), |
| 802 | llvm::StringRef(), result_value_sp, error); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 803 | |
| 804 | if (result_code == eExpressionCompleted) { |
| 805 | if (result_value_sp) { |
| 806 | Scalar scalar_value; |
| 807 | if (result_value_sp->ResolveValue(scalar_value)) { |
| 808 | if (scalar_value.ULongLong(1) == 0) { |
| 809 | // We have been vetoed. This takes precedence over querying |
| 810 | // the watchpoint whether it should stop (aka ignore count and |
| 811 | // friends). See also StopInfoWatchpoint::ShouldStop() as |
Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 812 | // well as Process::ProcessEventData::DoOnRemoval(). |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 813 | m_should_stop = false; |
| 814 | } else |
| 815 | m_should_stop = true; |
| 816 | if (log) |
| 817 | log->Printf( |
| 818 | "Condition successfully evaluated, result is %s.\n", |
| 819 | m_should_stop ? "true" : "false"); |
| 820 | } else { |
| 821 | m_should_stop = true; |
| 822 | if (log) |
| 823 | log->Printf( |
| 824 | "Failed to get an integer result from the expression."); |
| 825 | } |
| 826 | } |
| 827 | } else { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 828 | StreamSP error_sp = debugger.GetAsyncErrorStream(); |
| 829 | error_sp->Printf( |
| 830 | "Stopped due to an error evaluating condition of watchpoint "); |
| 831 | wp_sp->GetDescription(error_sp.get(), eDescriptionLevelBrief); |
| 832 | error_sp->Printf(": \"%s\"", wp_sp->GetConditionText()); |
| 833 | error_sp->EOL(); |
| 834 | const char *err_str = error.AsCString("<Unknown Error>"); |
| 835 | if (log) |
| 836 | log->Printf("Error evaluating condition: \"%s\"\n", err_str); |
| 837 | |
| 838 | error_sp->PutCString(err_str); |
| 839 | error_sp->EOL(); |
| 840 | error_sp->Flush(); |
| 841 | // If the condition fails to be parsed or run, we should stop. |
| 842 | m_should_stop = true; |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | // If the condition says to stop, we run the callback to further decide |
| 847 | // whether to stop. |
| 848 | if (m_should_stop) { |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 849 | // FIXME: For now the callbacks have to run in async mode - the |
| 850 | // first time we restart we need |
| 851 | // to get out of there. So set it here. |
| 852 | // When we figure out how to nest watchpoint hits then this will |
| 853 | // change. |
| 854 | |
| 855 | bool old_async = debugger.GetAsyncExecution(); |
| 856 | debugger.SetAsyncExecution(true); |
| 857 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 858 | StoppointCallbackContext context(event_ptr, exe_ctx, false); |
| 859 | bool stop_requested = wp_sp->InvokeCallback(&context); |
Jim Ingham | 209a77d | 2016-10-25 20:34:32 +0000 | [diff] [blame] | 860 | |
| 861 | debugger.SetAsyncExecution(old_async); |
| 862 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 863 | // Also make sure that the callback hasn't continued the target. |
| 864 | // If it did, when we'll set m_should_stop to false and get out of |
| 865 | // here. |
| 866 | if (HasTargetRunSinceMe()) |
| 867 | m_should_stop = false; |
| 868 | |
| 869 | if (m_should_stop && !stop_requested) { |
| 870 | // We have been vetoed by the callback mechanism. |
| 871 | m_should_stop = false; |
| 872 | } |
| 873 | } |
| 874 | // Finally, if we are going to stop, print out the new & old values: |
| 875 | if (m_should_stop) { |
| 876 | wp_sp->CaptureWatchedValue(exe_ctx); |
| 877 | |
| 878 | Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger(); |
| 879 | StreamSP output_sp = debugger.GetAsyncOutputStream(); |
| 880 | wp_sp->DumpSnapshots(output_sp.get()); |
| 881 | output_sp->EOL(); |
| 882 | output_sp->Flush(); |
| 883 | } |
| 884 | |
| 885 | } else { |
| 886 | Log *log_process( |
| 887 | lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); |
| 888 | |
| 889 | if (log_process) |
| 890 | log_process->Printf( |
| 891 | "Process::%s could not find watchpoint id: %" PRId64 "...", |
| 892 | __FUNCTION__, m_value); |
| 893 | } |
| 894 | if (log) |
| 895 | log->Printf("Process::%s returning from action with m_should_stop: %d.", |
| 896 | __FUNCTION__, m_should_stop); |
| 897 | |
| 898 | m_should_stop_is_valid = true; |
| 899 | } |
| 900 | } |
| 901 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 902 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 903 | bool m_should_stop; |
| 904 | bool m_should_stop_is_valid; |
| 905 | lldb::addr_t m_watch_hit_addr; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 906 | }; |
| 907 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 908 | //---------------------------------------------------------------------- |
| 909 | // StopInfoUnixSignal |
| 910 | //---------------------------------------------------------------------- |
| 911 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 912 | class StopInfoUnixSignal : public StopInfo { |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 913 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 914 | StopInfoUnixSignal(Thread &thread, int signo, const char *description) |
| 915 | : StopInfo(thread, signo) { |
| 916 | SetDescription(description); |
| 917 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 918 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 919 | ~StopInfoUnixSignal() override = default; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 920 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 921 | StopReason GetStopReason() const override { return eStopReasonSignal; } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 922 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 923 | bool ShouldStopSynchronous(Event *event_ptr) override { |
| 924 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 925 | if (thread_sp) |
| 926 | return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value); |
| 927 | return false; |
| 928 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 929 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 930 | bool ShouldStop(Event *event_ptr) override { |
| 931 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 932 | if (thread_sp) |
| 933 | return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value); |
| 934 | return false; |
| 935 | } |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 936 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 937 | // If should stop returns false, check if we should notify of this event |
| 938 | bool DoShouldNotify(Event *event_ptr) override { |
| 939 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 940 | if (thread_sp) { |
| 941 | bool should_notify = |
| 942 | thread_sp->GetProcess()->GetUnixSignals()->GetShouldNotify(m_value); |
| 943 | if (should_notify) { |
| 944 | StreamString strm; |
| 945 | strm.Printf( |
| 946 | "thread %d received signal: %s", thread_sp->GetIndexID(), |
| 947 | thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsCString( |
| 948 | m_value)); |
| 949 | Process::ProcessEventData::AddRestartedReason(event_ptr, |
| 950 | strm.GetData()); |
| 951 | } |
| 952 | return should_notify; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 953 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 954 | return true; |
| 955 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 956 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 957 | void WillResume(lldb::StateType resume_state) override { |
| 958 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 959 | if (thread_sp) { |
| 960 | if (!thread_sp->GetProcess()->GetUnixSignals()->GetShouldSuppress( |
| 961 | m_value)) |
| 962 | thread_sp->SetResumeSignal(m_value); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 963 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 964 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 965 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 966 | const char *GetDescription() override { |
| 967 | if (m_description.empty()) { |
| 968 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 969 | if (thread_sp) { |
| 970 | StreamString strm; |
| 971 | const char *signal_name = |
| 972 | thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsCString( |
| 973 | m_value); |
| 974 | if (signal_name) |
| 975 | strm.Printf("signal %s", signal_name); |
| 976 | else |
| 977 | strm.Printf("signal %" PRIi64, m_value); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 978 | m_description = strm.GetString(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 979 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 980 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 981 | return m_description.c_str(); |
| 982 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 983 | }; |
| 984 | |
| 985 | //---------------------------------------------------------------------- |
| 986 | // StopInfoTrace |
| 987 | //---------------------------------------------------------------------- |
| 988 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 989 | class StopInfoTrace : public StopInfo { |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 990 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 991 | StopInfoTrace(Thread &thread) : StopInfo(thread, LLDB_INVALID_UID) {} |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 992 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 993 | ~StopInfoTrace() override = default; |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 994 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 995 | StopReason GetStopReason() const override { return eStopReasonTrace; } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 996 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 997 | const char *GetDescription() override { |
| 998 | if (m_description.empty()) |
| 999 | return "trace"; |
| 1000 | else |
| 1001 | return m_description.c_str(); |
| 1002 | } |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 1003 | }; |
| 1004 | |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 1005 | //---------------------------------------------------------------------- |
| 1006 | // StopInfoException |
| 1007 | //---------------------------------------------------------------------- |
| 1008 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1009 | class StopInfoException : public StopInfo { |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 1010 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1011 | StopInfoException(Thread &thread, const char *description) |
| 1012 | : StopInfo(thread, LLDB_INVALID_UID) { |
| 1013 | if (description) |
| 1014 | SetDescription(description); |
| 1015 | } |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1016 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1017 | ~StopInfoException() override = default; |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1018 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1019 | StopReason GetStopReason() const override { return eStopReasonException; } |
| 1020 | |
| 1021 | const char *GetDescription() override { |
| 1022 | if (m_description.empty()) |
| 1023 | return "exception"; |
| 1024 | else |
| 1025 | return m_description.c_str(); |
| 1026 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1027 | }; |
| 1028 | |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1029 | //---------------------------------------------------------------------- |
| 1030 | // StopInfoThreadPlan |
| 1031 | //---------------------------------------------------------------------- |
| 1032 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1033 | class StopInfoThreadPlan : public StopInfo { |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1034 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1035 | StopInfoThreadPlan(ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp, |
| 1036 | ExpressionVariableSP &expression_variable_sp) |
| 1037 | : StopInfo(plan_sp->GetThread(), LLDB_INVALID_UID), m_plan_sp(plan_sp), |
| 1038 | m_return_valobj_sp(return_valobj_sp), |
| 1039 | m_expression_variable_sp(expression_variable_sp) {} |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1040 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1041 | ~StopInfoThreadPlan() override = default; |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1042 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1043 | StopReason GetStopReason() const override { return eStopReasonPlanComplete; } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1044 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1045 | const char *GetDescription() override { |
| 1046 | if (m_description.empty()) { |
| 1047 | StreamString strm; |
| 1048 | m_plan_sp->GetDescription(&strm, eDescriptionLevelBrief); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1049 | m_description = strm.GetString(); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1050 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1051 | return m_description.c_str(); |
| 1052 | } |
| 1053 | |
| 1054 | ValueObjectSP GetReturnValueObject() { return m_return_valobj_sp; } |
| 1055 | |
| 1056 | ExpressionVariableSP GetExpressionVariable() { |
| 1057 | return m_expression_variable_sp; |
| 1058 | } |
| 1059 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 1060 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1061 | bool ShouldStop(Event *event_ptr) override { |
| 1062 | if (m_plan_sp) |
| 1063 | return m_plan_sp->ShouldStop(event_ptr); |
| 1064 | else |
| 1065 | return StopInfo::ShouldStop(event_ptr); |
| 1066 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1067 | |
| 1068 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1069 | ThreadPlanSP m_plan_sp; |
| 1070 | ValueObjectSP m_return_valobj_sp; |
| 1071 | ExpressionVariableSP m_expression_variable_sp; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1072 | }; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1073 | |
| 1074 | class StopInfoExec : public StopInfo { |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1075 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1076 | StopInfoExec(Thread &thread) |
| 1077 | : StopInfo(thread, LLDB_INVALID_UID), m_performed_action(false) {} |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1078 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1079 | ~StopInfoExec() override = default; |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1080 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1081 | StopReason GetStopReason() const override { return eStopReasonExec; } |
| 1082 | |
| 1083 | const char *GetDescription() override { return "exec"; } |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 1084 | |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1085 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1086 | void PerformAction(Event *event_ptr) override { |
| 1087 | // Only perform the action once |
| 1088 | if (m_performed_action) |
| 1089 | return; |
| 1090 | m_performed_action = true; |
| 1091 | ThreadSP thread_sp(m_thread_wp.lock()); |
| 1092 | if (thread_sp) |
| 1093 | thread_sp->GetProcess()->DidExec(); |
| 1094 | } |
| 1095 | |
| 1096 | bool m_performed_action; |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1097 | }; |
| 1098 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1099 | } // namespace lldb_private |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1100 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1101 | StopInfoSP StopInfo::CreateStopReasonWithBreakpointSiteID(Thread &thread, |
| 1102 | break_id_t break_id) { |
| 1103 | return StopInfoSP(new StopInfoBreakpoint(thread, break_id)); |
| 1104 | } |
| 1105 | |
| 1106 | StopInfoSP StopInfo::CreateStopReasonWithBreakpointSiteID(Thread &thread, |
| 1107 | break_id_t break_id, |
| 1108 | bool should_stop) { |
| 1109 | return StopInfoSP(new StopInfoBreakpoint(thread, break_id, should_stop)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | StopInfoSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1113 | StopInfo::CreateStopReasonWithWatchpointID(Thread &thread, break_id_t watch_id, |
| 1114 | lldb::addr_t watch_hit_addr) { |
| 1115 | return StopInfoSP(new StopInfoWatchpoint(thread, watch_id, watch_hit_addr)); |
Jim Ingham | 36f3b36 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1118 | StopInfoSP StopInfo::CreateStopReasonWithSignal(Thread &thread, int signo, |
| 1119 | const char *description) { |
| 1120 | return StopInfoSP(new StopInfoUnixSignal(thread, signo, description)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1123 | StopInfoSP StopInfo::CreateStopReasonToTrace(Thread &thread) { |
| 1124 | return StopInfoSP(new StopInfoTrace(thread)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1127 | StopInfoSP StopInfo::CreateStopReasonWithPlan( |
| 1128 | ThreadPlanSP &plan_sp, ValueObjectSP return_valobj_sp, |
| 1129 | ExpressionVariableSP expression_variable_sp) { |
| 1130 | return StopInfoSP(new StopInfoThreadPlan(plan_sp, return_valobj_sp, |
| 1131 | expression_variable_sp)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1134 | StopInfoSP StopInfo::CreateStopReasonWithException(Thread &thread, |
| 1135 | const char *description) { |
| 1136 | return StopInfoSP(new StopInfoException(thread, description)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 1137 | } |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 1138 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1139 | StopInfoSP StopInfo::CreateStopReasonWithExec(Thread &thread) { |
| 1140 | return StopInfoSP(new StopInfoExec(thread)); |
Greg Clayton | a658fd2 | 2011-06-04 01:26:29 +0000 | [diff] [blame] | 1141 | } |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1142 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1143 | ValueObjectSP StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp) { |
| 1144 | if (stop_info_sp && |
| 1145 | stop_info_sp->GetStopReason() == eStopReasonPlanComplete) { |
| 1146 | StopInfoThreadPlan *plan_stop_info = |
| 1147 | static_cast<StopInfoThreadPlan *>(stop_info_sp.get()); |
| 1148 | return plan_stop_info->GetReturnValueObject(); |
| 1149 | } else |
| 1150 | return ValueObjectSP(); |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1153 | ExpressionVariableSP StopInfo::GetExpressionVariable(StopInfoSP &stop_info_sp) { |
| 1154 | if (stop_info_sp && |
| 1155 | stop_info_sp->GetStopReason() == eStopReasonPlanComplete) { |
| 1156 | StopInfoThreadPlan *plan_stop_info = |
| 1157 | static_cast<StopInfoThreadPlan *>(stop_info_sp.get()); |
| 1158 | return plan_stop_info->GetExpressionVariable(); |
| 1159 | } else |
| 1160 | return ExpressionVariableSP(); |
Jim Ingham | 30fadaf | 2014-07-08 01:07:32 +0000 | [diff] [blame] | 1161 | } |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1162 | |
| 1163 | lldb::ValueObjectSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1164 | StopInfo::GetCrashingDereference(StopInfoSP &stop_info_sp, |
| 1165 | lldb::addr_t *crashing_address) { |
| 1166 | if (!stop_info_sp) { |
| 1167 | return ValueObjectSP(); |
| 1168 | } |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1169 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1170 | const char *description = stop_info_sp->GetDescription(); |
| 1171 | if (!description) { |
| 1172 | return ValueObjectSP(); |
| 1173 | } |
| 1174 | |
| 1175 | ThreadSP thread_sp = stop_info_sp->GetThread(); |
| 1176 | if (!thread_sp) { |
| 1177 | return ValueObjectSP(); |
| 1178 | } |
| 1179 | |
| 1180 | StackFrameSP frame_sp = thread_sp->GetSelectedFrame(); |
| 1181 | |
| 1182 | if (!frame_sp) { |
| 1183 | return ValueObjectSP(); |
| 1184 | } |
| 1185 | |
| 1186 | const char address_string[] = "address="; |
| 1187 | |
| 1188 | const char *address_loc = strstr(description, address_string); |
| 1189 | if (!address_loc) { |
| 1190 | return ValueObjectSP(); |
| 1191 | } |
| 1192 | |
| 1193 | address_loc += (sizeof(address_string) - 1); |
| 1194 | |
| 1195 | uint64_t address = strtoull(address_loc, 0, 0); |
| 1196 | if (crashing_address) { |
| 1197 | *crashing_address = address; |
| 1198 | } |
| 1199 | |
| 1200 | return frame_sp->GuessValueForAddress(address); |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1201 | } |