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