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