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