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