Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 1 | //===-- ThreadPlanCallFunction.cpp ------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/Target/ThreadPlanCallFunction.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 | [diff] [blame] | 15 | #include "llvm/Support/MachO.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 16 | // Project includes |
| 17 | #include "lldb/lldb-private-log.h" |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 | [diff] [blame] | 18 | #include "lldb/Breakpoint/Breakpoint.h" |
| 19 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 20 | #include "lldb/Core/Address.h" |
| 21 | #include "lldb/Core/Log.h" |
| 22 | #include "lldb/Core/Stream.h" |
Sean Callanan | f211510 | 2010-11-03 22:19:38 | [diff] [blame] | 23 | #include "lldb/Target/LanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 24 | #include "lldb/Target/Process.h" |
| 25 | #include "lldb/Target/RegisterContext.h" |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 | [diff] [blame] | 26 | #include "lldb/Target/StopInfo.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 27 | #include "lldb/Target/Target.h" |
| 28 | #include "lldb/Target/Thread.h" |
| 29 | #include "lldb/Target/ThreadPlanRunToAddress.h" |
| 30 | |
| 31 | using namespace lldb; |
| 32 | using namespace lldb_private; |
| 33 | |
| 34 | //---------------------------------------------------------------------- |
| 35 | // ThreadPlanCallFunction: Plan to call a single function |
| 36 | //---------------------------------------------------------------------- |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 | [diff] [blame^] | 37 | bool |
| 38 | ThreadPlanCallFunction::ConstructorSetup (Thread &thread, |
| 39 | bool discard_on_error, |
| 40 | ABI *& abi, |
| 41 | lldb::addr_t &start_load_addr, |
| 42 | lldb::addr_t &function_load_addr) |
| 43 | { |
| 44 | // Call function thread plans need to be master plans so that they can potentially stay on the stack when |
| 45 | // a breakpoint is hit during the function call. |
| 46 | SetIsMasterPlan (true); |
| 47 | SetOkayToDiscard (discard_on_error); |
| 48 | |
| 49 | ProcessSP process_sp (thread.GetProcess()); |
| 50 | if (!process_sp) |
| 51 | return false; |
| 52 | |
| 53 | abi = process_sp->GetABI().get(); |
| 54 | |
| 55 | if (!abi) |
| 56 | return false; |
| 57 | |
| 58 | TargetSP target_sp (thread.CalculateTarget()); |
| 59 | |
| 60 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
| 61 | |
| 62 | SetBreakpoints(); |
| 63 | |
| 64 | m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize(); |
| 65 | // If we can't read memory at the point of the process where we are planning to put our function, we're |
| 66 | // not going to get any further... |
| 67 | Error error; |
| 68 | process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error); |
| 69 | if (!error.Success()) |
| 70 | { |
| 71 | if (log) |
| 72 | log->Printf ("Trying to put the stack in unreadable memory at: 0x%llx.", m_function_sp); |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
| 77 | |
| 78 | if (exe_module == NULL) |
| 79 | { |
| 80 | if (log) |
| 81 | log->Printf ("Can't execute code without an executable module."); |
| 82 | return false; |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | ObjectFile *objectFile = exe_module->GetObjectFile(); |
| 87 | if (!objectFile) |
| 88 | { |
| 89 | if (log) |
| 90 | log->Printf ("Could not find object file for module \"%s\".", |
| 91 | exe_module->GetFileSpec().GetFilename().AsCString()); |
| 92 | return false; |
| 93 | } |
| 94 | m_start_addr = objectFile->GetEntryPointAddress(); |
| 95 | if (!m_start_addr.IsValid()) |
| 96 | { |
| 97 | if (log) |
| 98 | log->Printf ("Could not find entry point address for executable module \"%s\".", |
| 99 | exe_module->GetFileSpec().GetFilename().AsCString()); |
| 100 | return false; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | start_load_addr = m_start_addr.GetLoadAddress (target_sp.get()); |
| 105 | |
| 106 | // Checkpoint the thread state so we can restore it later. |
| 107 | if (log && log->GetVerbose()) |
| 108 | ReportRegisterState ("About to checkpoint thread before function call. Original register state was:"); |
| 109 | |
| 110 | if (!thread.CheckpointThreadState (m_stored_thread_state)) |
| 111 | { |
| 112 | if (log) |
| 113 | log->Printf ("Setting up ThreadPlanCallFunction, failed to checkpoint thread state."); |
| 114 | return false; |
| 115 | } |
| 116 | // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding... |
| 117 | thread.SetStopInfoToNothing(); |
| 118 | |
| 119 | function_load_addr = m_function_addr.GetLoadAddress (target_sp.get()); |
| 120 | |
| 121 | return true; |
| 122 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 123 | |
| 124 | ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread, |
| 125 | Address &function, |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 | [diff] [blame] | 126 | const ClangASTType &return_type, |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 127 | addr_t arg, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 128 | bool stop_other_threads, |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 | [diff] [blame] | 129 | bool discard_on_error, |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 130 | addr_t *this_arg, |
| 131 | addr_t *cmd_arg) : |
Jim Ingham | b01e742a | 2010-06-19 04:45:32 | [diff] [blame] | 132 | ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion), |
Benjamin Kramer | 1ee0d4f | 2010-07-16 12:32:33 | [diff] [blame] | 133 | m_valid (false), |
| 134 | m_stop_other_threads (stop_other_threads), |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 | [diff] [blame] | 135 | m_function_addr (function), |
Peter Collingbourne | 6b5f17a | 2011-06-03 20:41:09 | [diff] [blame] | 136 | m_function_sp (NULL), |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 | [diff] [blame] | 137 | m_return_type (return_type), |
Jim Ingham | ce553d8 | 2011-11-01 02:46:54 | [diff] [blame] | 138 | m_takedown_done (false), |
| 139 | m_stop_address (LLDB_INVALID_ADDRESS) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 140 | { |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 | [diff] [blame^] | 141 | lldb::addr_t start_load_addr; |
| 142 | ABI *abi; |
| 143 | lldb::addr_t function_load_addr; |
| 144 | if (!ConstructorSetup (thread, discard_on_error, abi, start_load_addr, function_load_addr)) |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 | [diff] [blame] | 145 | return; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 146 | |
Greg Clayton | fdeb156 | 2011-05-12 02:14:56 | [diff] [blame] | 147 | if (this_arg && cmd_arg) |
| 148 | { |
| 149 | if (!abi->PrepareTrivialCall (thread, |
| 150 | m_function_sp, |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 | [diff] [blame^] | 151 | function_load_addr, |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 152 | start_load_addr, |
Greg Clayton | fdeb156 | 2011-05-12 02:14:56 | [diff] [blame] | 153 | this_arg, |
| 154 | cmd_arg, |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 155 | &arg)) |
Greg Clayton | fdeb156 | 2011-05-12 02:14:56 | [diff] [blame] | 156 | return; |
| 157 | } |
| 158 | else if (this_arg) |
| 159 | { |
| 160 | if (!abi->PrepareTrivialCall (thread, |
| 161 | m_function_sp, |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 | [diff] [blame^] | 162 | function_load_addr, |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 163 | start_load_addr, |
Greg Clayton | fdeb156 | 2011-05-12 02:14:56 | [diff] [blame] | 164 | this_arg, |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 165 | &arg)) |
Greg Clayton | fdeb156 | 2011-05-12 02:14:56 | [diff] [blame] | 166 | return; |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | if (!abi->PrepareTrivialCall (thread, |
| 171 | m_function_sp, |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 | [diff] [blame^] | 172 | function_load_addr, |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 173 | start_load_addr, |
| 174 | &arg)) |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | ReportRegisterState ("Function call was set up. Register state was:"); |
| 179 | |
| 180 | m_valid = true; |
| 181 | } |
| 182 | |
| 183 | |
| 184 | ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread, |
| 185 | Address &function, |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 | [diff] [blame] | 186 | const ClangASTType &return_type, |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 187 | bool stop_other_threads, |
| 188 | bool discard_on_error, |
| 189 | addr_t *arg1_ptr, |
| 190 | addr_t *arg2_ptr, |
| 191 | addr_t *arg3_ptr, |
| 192 | addr_t *arg4_ptr, |
| 193 | addr_t *arg5_ptr, |
| 194 | addr_t *arg6_ptr) : |
| 195 | ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion), |
| 196 | m_valid (false), |
| 197 | m_stop_other_threads (stop_other_threads), |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 | [diff] [blame] | 198 | m_function_addr (function), |
Peter Collingbourne | 6b5f17a | 2011-06-03 20:41:09 | [diff] [blame] | 199 | m_function_sp(NULL), |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 | [diff] [blame] | 200 | m_return_type (return_type), |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 | [diff] [blame^] | 201 | m_takedown_done (false), |
| 202 | m_stop_address (LLDB_INVALID_ADDRESS) |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 203 | { |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 | [diff] [blame^] | 204 | lldb::addr_t start_load_addr; |
| 205 | ABI *abi; |
| 206 | lldb::addr_t function_load_addr; |
| 207 | if (!ConstructorSetup (thread, discard_on_error, abi, start_load_addr, function_load_addr)) |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 | [diff] [blame] | 208 | return; |
| 209 | |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 210 | if (!abi->PrepareTrivialCall (thread, |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 | [diff] [blame^] | 211 | m_function_sp, |
| 212 | function_load_addr, |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 213 | start_load_addr, |
| 214 | arg1_ptr, |
| 215 | arg2_ptr, |
| 216 | arg3_ptr, |
| 217 | arg4_ptr, |
| 218 | arg5_ptr, |
| 219 | arg6_ptr)) |
| 220 | { |
Greg Clayton | fdeb156 | 2011-05-12 02:14:56 | [diff] [blame] | 221 | return; |
| 222 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 223 | |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 | [diff] [blame] | 224 | ReportRegisterState ("Function call was set up. Register state was:"); |
| 225 | |
| 226 | m_valid = true; |
| 227 | } |
| 228 | |
| 229 | ThreadPlanCallFunction::~ThreadPlanCallFunction () |
| 230 | { |
Jim Ingham | 718583f | 2012-04-13 18:27:58 | [diff] [blame] | 231 | DoTakedown(); |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void |
| 235 | ThreadPlanCallFunction::ReportRegisterState (const char *message) |
| 236 | { |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 | [diff] [blame] | 237 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_VERBOSE)); |
Sean Callanan | ece9649 | 2010-11-08 03:49:50 | [diff] [blame] | 238 | if (log) |
| 239 | { |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 | [diff] [blame] | 240 | StreamString strm; |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 | [diff] [blame] | 241 | RegisterContext *reg_ctx = m_thread.GetRegisterContext().get(); |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 | [diff] [blame] | 242 | |
| 243 | log->PutCString(message); |
| 244 | |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 | [diff] [blame] | 245 | RegisterValue reg_value; |
| 246 | |
| 247 | for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount(); |
| 248 | reg_idx < num_registers; |
| 249 | ++reg_idx) |
Sean Callanan | ece9649 | 2010-11-08 03:49:50 | [diff] [blame] | 250 | { |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 | [diff] [blame] | 251 | const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx); |
| 252 | if (reg_ctx->ReadRegister(reg_info, reg_value)) |
| 253 | { |
| 254 | reg_value.Dump(&strm, reg_info, true, false, eFormatDefault); |
| 255 | strm.EOL(); |
| 256 | } |
Sean Callanan | ece9649 | 2010-11-08 03:49:50 | [diff] [blame] | 257 | } |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 | [diff] [blame] | 258 | log->PutCString(strm.GetData()); |
Sean Callanan | ece9649 | 2010-11-08 03:49:50 | [diff] [blame] | 259 | } |
Sean Callanan | 10af7c4 | 2010-11-04 01:51:38 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | void |
| 263 | ThreadPlanCallFunction::DoTakedown () |
| 264 | { |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 | [diff] [blame] | 265 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
| 266 | if (!m_takedown_done) |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 | [diff] [blame] | 267 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 | [diff] [blame] | 268 | ProcessSP process_sp (m_thread.GetProcess()); |
| 269 | const ABI *abi = process_sp ? process_sp->GetABI().get() : NULL; |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 | [diff] [blame] | 270 | if (abi && m_return_type.IsValid()) |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 | [diff] [blame] | 271 | { |
Sean Callanan | 6153c51 | 2012-04-10 18:16:59 | [diff] [blame] | 272 | const bool persistent = false; |
| 273 | m_return_valobj_sp = abi->GetReturnValueObject (m_thread, m_return_type, persistent); |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 | [diff] [blame] | 274 | } |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 | [diff] [blame] | 275 | |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 | [diff] [blame] | 276 | if (log) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 | [diff] [blame] | 277 | log->Printf ("DoTakedown called for thread 0x%4.4llx, m_valid: %d complete: %d.\n", m_thread.GetID(), m_valid, IsPlanComplete()); |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 | [diff] [blame] | 278 | m_takedown_done = true; |
Jim Ingham | ce553d8 | 2011-11-01 02:46:54 | [diff] [blame] | 279 | m_stop_address = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC(); |
Jim Ingham | 160f78c | 2011-05-17 01:10:11 | [diff] [blame] | 280 | m_real_stop_info_sp = GetPrivateStopReason(); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 | [diff] [blame] | 281 | m_thread.RestoreThreadStateFromCheckpoint(m_stored_thread_state); |
| 282 | SetPlanComplete(); |
| 283 | ClearBreakpoints(); |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 | [diff] [blame] | 284 | if (log && log->GetVerbose()) |
| 285 | ReportRegisterState ("Restoring thread state after function call. Restored register state:"); |
Jim Ingham | 2c36439 | 2011-01-26 19:13:09 | [diff] [blame] | 286 | |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 | [diff] [blame] | 287 | } |
| 288 | else |
| 289 | { |
| 290 | if (log) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 | [diff] [blame] | 291 | log->Printf ("DoTakedown called as no-op for thread 0x%4.4llx, m_valid: %d complete: %d.\n", m_thread.GetID(), m_valid, IsPlanComplete()); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 | [diff] [blame] | 292 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | void |
Jim Ingham | bda4e5eb | 2011-01-18 01:58:06 | [diff] [blame] | 296 | ThreadPlanCallFunction::WillPop () |
| 297 | { |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 | [diff] [blame] | 298 | DoTakedown(); |
Jim Ingham | bda4e5eb | 2011-01-18 01:58:06 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | void |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 302 | ThreadPlanCallFunction::GetDescription (Stream *s, DescriptionLevel level) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 303 | { |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 304 | if (level == eDescriptionLevelBrief) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 305 | { |
| 306 | s->Printf("Function call thread plan"); |
| 307 | } |
| 308 | else |
| 309 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 | [diff] [blame] | 310 | TargetSP target_sp (m_thread.CalculateTarget()); |
| 311 | s->Printf("Thread plan to call 0x%llx", m_function_addr.GetLoadAddress(target_sp.get())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
| 315 | bool |
| 316 | ThreadPlanCallFunction::ValidatePlan (Stream *error) |
| 317 | { |
| 318 | if (!m_valid) |
| 319 | return false; |
| 320 | |
| 321 | return true; |
| 322 | } |
| 323 | |
| 324 | bool |
| 325 | ThreadPlanCallFunction::PlanExplainsStop () |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 | [diff] [blame] | 326 | { |
Jim Ingham | 160f78c | 2011-05-17 01:10:11 | [diff] [blame] | 327 | m_real_stop_info_sp = GetPrivateStopReason(); |
| 328 | |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 | [diff] [blame] | 329 | // If our subplan knows why we stopped, even if it's done (which would forward the question to us) |
| 330 | // we answer yes. |
Enrico Granata | 20edcdb | 2011-07-19 18:03:25 | [diff] [blame] | 331 | if (m_subplan_sp.get() != NULL && m_subplan_sp->PlanExplainsStop()) |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 | [diff] [blame] | 332 | return true; |
Sean Callanan | 3e6fedc | 2010-10-19 22:24:06 | [diff] [blame] | 333 | |
Sean Callanan | c98aca6 | 2010-11-03 19:36:28 | [diff] [blame] | 334 | // Check if the breakpoint is one of ours. |
| 335 | |
| 336 | if (BreakpointsExplainStop()) |
| 337 | return true; |
| 338 | |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 | [diff] [blame] | 339 | // If we don't want to discard this plan, than any stop we don't understand should be propagated up the stack. |
| 340 | if (!OkayToDiscard()) |
| 341 | return false; |
| 342 | |
| 343 | // Otherwise, check the case where we stopped for an internal breakpoint, in that case, continue on. |
| 344 | // If it is not an internal breakpoint, consult OkayToDiscard. |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 | [diff] [blame] | 345 | |
Jim Ingham | 160f78c | 2011-05-17 01:10:11 | [diff] [blame] | 346 | if (m_real_stop_info_sp && m_real_stop_info_sp->GetStopReason() == eStopReasonBreakpoint) |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 | [diff] [blame] | 347 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 | [diff] [blame] | 348 | ProcessSP process_sp (m_thread.CalculateProcess()); |
Jim Ingham | 160f78c | 2011-05-17 01:10:11 | [diff] [blame] | 349 | uint64_t break_site_id = m_real_stop_info_sp->GetValue(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 | [diff] [blame] | 350 | BreakpointSiteSP bp_site_sp; |
| 351 | if (process_sp) |
| 352 | bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id); |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 | [diff] [blame] | 353 | if (bp_site_sp) |
| 354 | { |
| 355 | uint32_t num_owners = bp_site_sp->GetNumberOfOwners(); |
| 356 | bool is_internal = true; |
| 357 | for (uint32_t i = 0; i < num_owners; i++) |
| 358 | { |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 | [diff] [blame] | 359 | Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint(); |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 | [diff] [blame] | 360 | |
| 361 | if (!bp.IsInternal()) |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 | [diff] [blame] | 362 | { |
| 363 | is_internal = false; |
| 364 | break; |
| 365 | } |
| 366 | } |
| 367 | if (is_internal) |
| 368 | return false; |
| 369 | } |
| 370 | |
| 371 | return OkayToDiscard(); |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | // If the subplan is running, any crashes are attributable to us. |
Jim Ingham | 2c36439 | 2011-01-26 19:13:09 | [diff] [blame] | 376 | // If we want to discard the plan, then we say we explain the stop |
| 377 | // but if we are going to be discarded, let whoever is above us |
| 378 | // explain the stop. |
| 379 | return ((m_subplan_sp.get() != NULL) && !OkayToDiscard()); |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 | [diff] [blame] | 380 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | bool |
| 384 | ThreadPlanCallFunction::ShouldStop (Event *event_ptr) |
| 385 | { |
| 386 | if (PlanExplainsStop()) |
| 387 | { |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 | [diff] [blame] | 388 | ReportRegisterState ("Function completed. Register state was:"); |
Sean Callanan | 5300d37 | 2010-07-31 01:32:05 | [diff] [blame] | 389 | |
Sean Callanan | 10af7c4 | 2010-11-04 01:51:38 | [diff] [blame] | 390 | DoTakedown(); |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 | [diff] [blame] | 391 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 392 | return true; |
| 393 | } |
| 394 | else |
| 395 | { |
| 396 | return false; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | bool |
| 401 | ThreadPlanCallFunction::StopOthers () |
| 402 | { |
| 403 | return m_stop_other_threads; |
| 404 | } |
| 405 | |
| 406 | void |
| 407 | ThreadPlanCallFunction::SetStopOthers (bool new_value) |
| 408 | { |
| 409 | if (m_subplan_sp) |
| 410 | { |
| 411 | ThreadPlanRunToAddress *address_plan = static_cast<ThreadPlanRunToAddress *>(m_subplan_sp.get()); |
| 412 | address_plan->SetStopOthers(new_value); |
| 413 | } |
| 414 | m_stop_other_threads = new_value; |
| 415 | } |
| 416 | |
| 417 | StateType |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 | [diff] [blame] | 418 | ThreadPlanCallFunction::GetPlanRunState () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 419 | { |
| 420 | return eStateRunning; |
| 421 | } |
| 422 | |
| 423 | void |
| 424 | ThreadPlanCallFunction::DidPush () |
| 425 | { |
Sean Callanan | be3a1b1 | 2010-10-26 00:31:56 | [diff] [blame] | 426 | //#define SINGLE_STEP_EXPRESSIONS |
| 427 | |
| 428 | #ifndef SINGLE_STEP_EXPRESSIONS |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 429 | m_subplan_sp.reset(new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads)); |
| 430 | |
| 431 | m_thread.QueueThreadPlan(m_subplan_sp, false); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 | [diff] [blame] | 432 | m_subplan_sp->SetPrivate (true); |
Sean Callanan | be3a1b1 | 2010-10-26 00:31:56 | [diff] [blame] | 433 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | bool |
| 437 | ThreadPlanCallFunction::WillStop () |
| 438 | { |
| 439 | return true; |
| 440 | } |
| 441 | |
| 442 | bool |
| 443 | ThreadPlanCallFunction::MischiefManaged () |
| 444 | { |
| 445 | if (IsPlanComplete()) |
| 446 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 | [diff] [blame] | 447 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 | [diff] [blame] | 448 | |
| 449 | if (log) |
| 450 | log->Printf("Completed call function plan."); |
| 451 | |
| 452 | ThreadPlan::MischiefManaged (); |
| 453 | return true; |
| 454 | } |
| 455 | else |
| 456 | { |
| 457 | return false; |
| 458 | } |
| 459 | } |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 | [diff] [blame] | 460 | |
| 461 | void |
| 462 | ThreadPlanCallFunction::SetBreakpoints () |
| 463 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 | [diff] [blame] | 464 | ProcessSP process_sp (m_thread.CalculateProcess()); |
| 465 | if (process_sp) |
| 466 | { |
| 467 | m_cxx_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus); |
| 468 | m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC); |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 | [diff] [blame] | 469 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 | [diff] [blame] | 470 | if (m_cxx_language_runtime) |
| 471 | m_cxx_language_runtime->SetExceptionBreakpoints(); |
| 472 | if (m_objc_language_runtime) |
| 473 | m_objc_language_runtime->SetExceptionBreakpoints(); |
| 474 | } |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | void |
| 478 | ThreadPlanCallFunction::ClearBreakpoints () |
| 479 | { |
Sean Callanan | f211510 | 2010-11-03 22:19:38 | [diff] [blame] | 480 | if (m_cxx_language_runtime) |
| 481 | m_cxx_language_runtime->ClearExceptionBreakpoints(); |
| 482 | if (m_objc_language_runtime) |
| 483 | m_objc_language_runtime->ClearExceptionBreakpoints(); |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 | [diff] [blame] | 484 | } |
Sean Callanan | c98aca6 | 2010-11-03 19:36:28 | [diff] [blame] | 485 | |
| 486 | bool |
| 487 | ThreadPlanCallFunction::BreakpointsExplainStop() |
| 488 | { |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 | [diff] [blame] | 489 | StopInfoSP stop_info_sp = GetPrivateStopReason(); |
Sean Callanan | c98aca6 | 2010-11-03 19:36:28 | [diff] [blame] | 490 | |
Sean Callanan | f211510 | 2010-11-03 22:19:38 | [diff] [blame] | 491 | if (m_cxx_language_runtime && |
| 492 | m_cxx_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp)) |
| 493 | return true; |
Sean Callanan | c98aca6 | 2010-11-03 19:36:28 | [diff] [blame] | 494 | |
Sean Callanan | f211510 | 2010-11-03 22:19:38 | [diff] [blame] | 495 | if (m_objc_language_runtime && |
| 496 | m_objc_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp)) |
| 497 | return true; |
Sean Callanan | c98aca6 | 2010-11-03 19:36:28 | [diff] [blame] | 498 | |
| 499 | return false; |
| 500 | } |