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