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