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