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