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" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 22 | #include "lldb/Core/Module.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Core/Stream.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 24 | #include "lldb/Symbol/ObjectFile.h" |
Sean Callanan | f211510 | 2010-11-03 22:19:38 +0000 | [diff] [blame] | 25 | #include "lldb/Target/LanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Process.h" |
| 27 | #include "lldb/Target/RegisterContext.h" |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 +0000 | [diff] [blame] | 28 | #include "lldb/Target/StopInfo.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Target/Target.h" |
| 30 | #include "lldb/Target/Thread.h" |
| 31 | #include "lldb/Target/ThreadPlanRunToAddress.h" |
| 32 | |
| 33 | using namespace lldb; |
| 34 | using namespace lldb_private; |
| 35 | |
| 36 | //---------------------------------------------------------------------- |
| 37 | // ThreadPlanCallFunction: Plan to call a single function |
| 38 | //---------------------------------------------------------------------- |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 39 | bool |
| 40 | ThreadPlanCallFunction::ConstructorSetup (Thread &thread, |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 41 | ABI *& abi, |
| 42 | lldb::addr_t &start_load_addr, |
| 43 | lldb::addr_t &function_load_addr) |
| 44 | { |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 45 | SetIsMasterPlan (true); |
Jim Ingham | 923886c | 2012-05-11 18:43:38 +0000 | [diff] [blame] | 46 | SetOkayToDiscard (false); |
Andrew Kaylor | 327c267 | 2012-12-07 17:56:31 +0000 | [diff] [blame] | 47 | SetPrivate (true); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 48 | |
| 49 | ProcessSP process_sp (thread.GetProcess()); |
| 50 | if (!process_sp) |
| 51 | return false; |
| 52 | |
| 53 | abi = process_sp->GetABI().get(); |
| 54 | |
| 55 | if (!abi) |
| 56 | return false; |
| 57 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 58 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 59 | |
| 60 | SetBreakpoints(); |
| 61 | |
| 62 | m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize(); |
| 63 | // If we can't read memory at the point of the process where we are planning to put our function, we're |
| 64 | // not going to get any further... |
| 65 | Error error; |
| 66 | process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error); |
| 67 | if (!error.Success()) |
| 68 | { |
Jim Ingham | ea06f3b | 2013-03-28 00:04:05 +0000 | [diff] [blame] | 69 | m_constructor_errors.Printf ("Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".", m_function_sp); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 70 | if (log) |
Jim Ingham | ea06f3b | 2013-03-28 00:04:05 +0000 | [diff] [blame] | 71 | log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData()); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 72 | return false; |
| 73 | } |
| 74 | |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 75 | Module *exe_module = GetTarget().GetExecutableModulePointer(); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 76 | |
| 77 | if (exe_module == NULL) |
| 78 | { |
Jim Ingham | ea06f3b | 2013-03-28 00:04:05 +0000 | [diff] [blame] | 79 | m_constructor_errors.Printf ("Can't execute code without an executable module."); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 80 | if (log) |
Jim Ingham | ea06f3b | 2013-03-28 00:04:05 +0000 | [diff] [blame] | 81 | log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData()); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 82 | return false; |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | ObjectFile *objectFile = exe_module->GetObjectFile(); |
| 87 | if (!objectFile) |
| 88 | { |
Jim Ingham | ea06f3b | 2013-03-28 00:04:05 +0000 | [diff] [blame] | 89 | m_constructor_errors.Printf ("Could not find object file for module \"%s\".", |
| 90 | exe_module->GetFileSpec().GetFilename().AsCString()); |
| 91 | |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 92 | if (log) |
Jim Ingham | ea06f3b | 2013-03-28 00:04:05 +0000 | [diff] [blame] | 93 | log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData()); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 94 | return false; |
| 95 | } |
Jim Ingham | ea06f3b | 2013-03-28 00:04:05 +0000 | [diff] [blame] | 96 | |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 97 | m_start_addr = objectFile->GetEntryPointAddress(); |
| 98 | if (!m_start_addr.IsValid()) |
| 99 | { |
Jim Ingham | ea06f3b | 2013-03-28 00:04:05 +0000 | [diff] [blame] | 100 | m_constructor_errors.Printf ("Could not find entry point address for executable module \"%s\".", |
| 101 | exe_module->GetFileSpec().GetFilename().AsCString()); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 102 | if (log) |
Jim Ingham | ea06f3b | 2013-03-28 00:04:05 +0000 | [diff] [blame] | 103 | log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData()); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 104 | return false; |
| 105 | } |
| 106 | } |
| 107 | |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 108 | start_load_addr = m_start_addr.GetLoadAddress (&GetTarget()); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 109 | |
| 110 | // Checkpoint the thread state so we can restore it later. |
| 111 | if (log && log->GetVerbose()) |
| 112 | ReportRegisterState ("About to checkpoint thread before function call. Original register state was:"); |
| 113 | |
| 114 | if (!thread.CheckpointThreadState (m_stored_thread_state)) |
| 115 | { |
Jim Ingham | ea06f3b | 2013-03-28 00:04:05 +0000 | [diff] [blame] | 116 | m_constructor_errors.Printf ("Setting up ThreadPlanCallFunction, failed to checkpoint thread state."); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 117 | if (log) |
Jim Ingham | ea06f3b | 2013-03-28 00:04:05 +0000 | [diff] [blame] | 118 | log->Printf ("ThreadPlanCallFunction(%p): %s.", this, m_constructor_errors.GetData()); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 119 | return false; |
| 120 | } |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 121 | function_load_addr = m_function_addr.GetLoadAddress (&GetTarget()); |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 122 | |
| 123 | return true; |
| 124 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 125 | |
| 126 | ThreadPlanCallFunction::ThreadPlanCallFunction (Thread &thread, |
Matt Kopec | 00049b8 | 2013-02-27 20:13:38 +0000 | [diff] [blame] | 127 | const Address &function, |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 +0000 | [diff] [blame] | 128 | const ClangASTType &return_type, |
Sean Callanan | a464f3d | 2013-11-08 01:14:26 +0000 | [diff] [blame^] | 129 | llvm::ArrayRef<addr_t> args, |
| 130 | const EvaluateExpressionOptions &options) : |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 131 | ThreadPlan (ThreadPlan::eKindCallFunction, "Call function plan", thread, eVoteNoOpinion, eVoteNoOpinion), |
Benjamin Kramer | 1ee0d4f | 2010-07-16 12:32:33 +0000 | [diff] [blame] | 132 | m_valid (false), |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 133 | m_stop_other_threads (options.GetStopOthers()), |
| 134 | m_unwind_on_error (options.DoesUnwindOnError()), |
| 135 | m_ignore_breakpoints (options.DoesIgnoreBreakpoints()), |
| 136 | m_debug_execution (options.GetDebug()), |
| 137 | m_trap_exceptions (options.GetTrapExceptions()), |
Jim Ingham | 16e0c68 | 2011-08-12 23:34:31 +0000 | [diff] [blame] | 138 | m_function_addr (function), |
Filipe Cabecinhas | b4cb0be | 2012-09-11 18:11:07 +0000 | [diff] [blame] | 139 | m_function_sp (0), |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 +0000 | [diff] [blame] | 140 | m_return_type (return_type), |
Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 141 | m_takedown_done (false), |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 142 | m_should_clear_objc_exception_bp(false), |
| 143 | m_should_clear_cxx_exception_bp (false), |
| 144 | m_stop_address (LLDB_INVALID_ADDRESS) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | { |
Jim Ingham | 0092c8e | 2012-04-13 20:38:13 +0000 | [diff] [blame] | 146 | lldb::addr_t start_load_addr; |
| 147 | ABI *abi; |
| 148 | lldb::addr_t function_load_addr; |
Jim Ingham | 923886c | 2012-05-11 18:43:38 +0000 | [diff] [blame] | 149 | if (!ConstructorSetup (thread, abi, start_load_addr, function_load_addr)) |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 150 | return; |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 151 | |
Sean Callanan | a464f3d | 2013-11-08 01:14:26 +0000 | [diff] [blame^] | 152 | if (!abi->PrepareTrivialCall(thread, |
| 153 | m_function_sp, |
| 154 | function_load_addr, |
| 155 | start_load_addr, |
| 156 | args)) |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 157 | return; |
| 158 | |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 +0000 | [diff] [blame] | 159 | ReportRegisterState ("Function call was set up. Register state was:"); |
| 160 | |
| 161 | m_valid = true; |
| 162 | } |
| 163 | |
| 164 | ThreadPlanCallFunction::~ThreadPlanCallFunction () |
| 165 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 166 | DoTakedown(PlanSucceeded()); |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | void |
| 170 | ThreadPlanCallFunction::ReportRegisterState (const char *message) |
| 171 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 172 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_VERBOSE)); |
Sean Callanan | ece9649 | 2010-11-08 03:49:50 +0000 | [diff] [blame] | 173 | if (log) |
| 174 | { |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 175 | StreamString strm; |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 176 | RegisterContext *reg_ctx = m_thread.GetRegisterContext().get(); |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 +0000 | [diff] [blame] | 177 | |
| 178 | log->PutCString(message); |
| 179 | |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 180 | RegisterValue reg_value; |
| 181 | |
| 182 | for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount(); |
| 183 | reg_idx < num_registers; |
| 184 | ++reg_idx) |
Sean Callanan | ece9649 | 2010-11-08 03:49:50 +0000 | [diff] [blame] | 185 | { |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 186 | const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx); |
| 187 | if (reg_ctx->ReadRegister(reg_info, reg_value)) |
| 188 | { |
| 189 | reg_value.Dump(&strm, reg_info, true, false, eFormatDefault); |
| 190 | strm.EOL(); |
| 191 | } |
Sean Callanan | ece9649 | 2010-11-08 03:49:50 +0000 | [diff] [blame] | 192 | } |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 193 | log->PutCString(strm.GetData()); |
Sean Callanan | ece9649 | 2010-11-08 03:49:50 +0000 | [diff] [blame] | 194 | } |
Sean Callanan | 10af7c4 | 2010-11-04 01:51:38 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | void |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 198 | ThreadPlanCallFunction::DoTakedown (bool success) |
Sean Callanan | 10af7c4 | 2010-11-04 01:51:38 +0000 | [diff] [blame] | 199 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 200 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 87d0e61 | 2012-04-13 23:11:52 +0000 | [diff] [blame] | 201 | |
| 202 | if (!m_valid) |
| 203 | { |
| 204 | //Don't call DoTakedown if we were never valid to begin with. |
| 205 | if (log) |
| 206 | log->Printf ("ThreadPlanCallFunction(%p): Log called on ThreadPlanCallFunction that was never valid.", this); |
| 207 | return; |
| 208 | } |
| 209 | |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 +0000 | [diff] [blame] | 210 | if (!m_takedown_done) |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 211 | { |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 212 | if (success) |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 213 | { |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 214 | ProcessSP process_sp (m_thread.GetProcess()); |
| 215 | const ABI *abi = process_sp ? process_sp->GetABI().get() : NULL; |
| 216 | if (abi && m_return_type.IsValid()) |
| 217 | { |
| 218 | const bool persistent = false; |
| 219 | m_return_valobj_sp = abi->GetReturnValueObject (m_thread, m_return_type, persistent); |
| 220 | } |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 221 | } |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 +0000 | [diff] [blame] | 222 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 223 | log->Printf ("ThreadPlanCallFunction(%p): DoTakedown called for thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n", this, m_thread.GetID(), m_valid, IsPlanComplete()); |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 +0000 | [diff] [blame] | 224 | m_takedown_done = true; |
Jim Ingham | ce553d8 | 2011-11-01 02:46:54 +0000 | [diff] [blame] | 225 | m_stop_address = m_thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC(); |
Jim Ingham | 60c4118 | 2013-06-04 01:40:51 +0000 | [diff] [blame] | 226 | m_real_stop_info_sp = GetPrivateStopInfo (); |
Jim Ingham | 8559a35 | 2012-11-26 23:52:18 +0000 | [diff] [blame] | 227 | m_thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state); |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 228 | SetPlanComplete(success); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 229 | ClearBreakpoints(); |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 +0000 | [diff] [blame] | 230 | if (log && log->GetVerbose()) |
| 231 | ReportRegisterState ("Restoring thread state after function call. Restored register state:"); |
Jim Ingham | 2c36439 | 2011-01-26 19:13:09 +0000 | [diff] [blame] | 232 | |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 +0000 | [diff] [blame] | 233 | } |
| 234 | else |
| 235 | { |
| 236 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 237 | log->Printf ("ThreadPlanCallFunction(%p): DoTakedown called as no-op for thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n", this, m_thread.GetID(), m_valid, IsPlanComplete()); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 238 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | void |
Jim Ingham | bda4e5eb | 2011-01-18 01:58:06 +0000 | [diff] [blame] | 242 | ThreadPlanCallFunction::WillPop () |
| 243 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 244 | DoTakedown(PlanSucceeded()); |
Jim Ingham | bda4e5eb | 2011-01-18 01:58:06 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | void |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 248 | ThreadPlanCallFunction::GetDescription (Stream *s, DescriptionLevel level) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 249 | { |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 250 | if (level == eDescriptionLevelBrief) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 251 | { |
| 252 | s->Printf("Function call thread plan"); |
| 253 | } |
| 254 | else |
| 255 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 256 | TargetSP target_sp (m_thread.CalculateTarget()); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 257 | s->Printf("Thread plan to call 0x%" PRIx64, m_function_addr.GetLoadAddress(target_sp.get())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
| 261 | bool |
| 262 | ThreadPlanCallFunction::ValidatePlan (Stream *error) |
| 263 | { |
| 264 | if (!m_valid) |
Jim Ingham | ea06f3b | 2013-03-28 00:04:05 +0000 | [diff] [blame] | 265 | { |
| 266 | if (error) |
| 267 | { |
| 268 | if (m_constructor_errors.GetSize() > 0) |
| 269 | error->PutCString (m_constructor_errors.GetData()); |
| 270 | else |
| 271 | error->PutCString ("Unknown error"); |
| 272 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 273 | return false; |
Jim Ingham | ea06f3b | 2013-03-28 00:04:05 +0000 | [diff] [blame] | 274 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 275 | |
| 276 | return true; |
| 277 | } |
| 278 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 279 | |
| 280 | Vote |
| 281 | ThreadPlanCallFunction::ShouldReportStop(Event *event_ptr) |
| 282 | { |
| 283 | if (m_takedown_done || IsPlanComplete()) |
| 284 | return eVoteYes; |
| 285 | else |
| 286 | return ThreadPlan::ShouldReportStop(event_ptr); |
| 287 | } |
| 288 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 289 | bool |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 290 | ThreadPlanCallFunction::DoPlanExplainsStop (Event *event_ptr) |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 +0000 | [diff] [blame] | 291 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 292 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP|LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 60c4118 | 2013-06-04 01:40:51 +0000 | [diff] [blame] | 293 | m_real_stop_info_sp = GetPrivateStopInfo (); |
Jim Ingham | 160f78c | 2011-05-17 01:10:11 +0000 | [diff] [blame] | 294 | |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 +0000 | [diff] [blame] | 295 | // If our subplan knows why we stopped, even if it's done (which would forward the question to us) |
| 296 | // we answer yes. |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 297 | if (m_subplan_sp.get() != NULL && m_subplan_sp->PlanExplainsStop(event_ptr)) |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 298 | { |
| 299 | SetPlanComplete(); |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 +0000 | [diff] [blame] | 300 | return true; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 301 | } |
Sean Callanan | 3e6fedc | 2010-10-19 22:24:06 +0000 | [diff] [blame] | 302 | |
Sean Callanan | c98aca6 | 2010-11-03 19:36:28 +0000 | [diff] [blame] | 303 | // Check if the breakpoint is one of ours. |
| 304 | |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 305 | StopReason stop_reason; |
| 306 | if (!m_real_stop_info_sp) |
| 307 | stop_reason = eStopReasonNone; |
| 308 | else |
| 309 | stop_reason = m_real_stop_info_sp->GetStopReason(); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 310 | if (log) |
| 311 | log->Printf ("ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - %s.", Thread::StopReasonAsCString(stop_reason)); |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 312 | |
| 313 | if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop()) |
Sean Callanan | c98aca6 | 2010-11-03 19:36:28 +0000 | [diff] [blame] | 314 | return true; |
| 315 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 316 | // We control breakpoints separately from other "stop reasons." So first, |
| 317 | // check the case where we stopped for an internal breakpoint, in that case, continue on. |
| 318 | // If it is not an internal breakpoint, consult m_ignore_breakpoints. |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 +0000 | [diff] [blame] | 319 | |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 320 | |
| 321 | if (stop_reason == eStopReasonBreakpoint) |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 +0000 | [diff] [blame] | 322 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 323 | ProcessSP process_sp (m_thread.CalculateProcess()); |
Jim Ingham | 160f78c | 2011-05-17 01:10:11 +0000 | [diff] [blame] | 324 | uint64_t break_site_id = m_real_stop_info_sp->GetValue(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 325 | BreakpointSiteSP bp_site_sp; |
| 326 | if (process_sp) |
| 327 | bp_site_sp = process_sp->GetBreakpointSiteList().FindByID(break_site_id); |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 +0000 | [diff] [blame] | 328 | if (bp_site_sp) |
| 329 | { |
| 330 | uint32_t num_owners = bp_site_sp->GetNumberOfOwners(); |
| 331 | bool is_internal = true; |
| 332 | for (uint32_t i = 0; i < num_owners; i++) |
| 333 | { |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 +0000 | [diff] [blame] | 334 | Breakpoint &bp = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint(); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 335 | if (log) |
| 336 | log->Printf ("ThreadPlanCallFunction::PlanExplainsStop: hit breakpoint %d while calling function", bp.GetID()); |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 +0000 | [diff] [blame] | 337 | |
| 338 | if (!bp.IsInternal()) |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 +0000 | [diff] [blame] | 339 | { |
| 340 | is_internal = false; |
| 341 | break; |
| 342 | } |
| 343 | } |
| 344 | if (is_internal) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 345 | { |
| 346 | if (log) |
| 347 | log->Printf ("ThreadPlanCallFunction::PlanExplainsStop hit an internal breakpoint, not stopping."); |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 +0000 | [diff] [blame] | 348 | return false; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 349 | } |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 +0000 | [diff] [blame] | 350 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 351 | |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 352 | if (m_ignore_breakpoints) |
Jim Ingham | 923886c | 2012-05-11 18:43:38 +0000 | [diff] [blame] | 353 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 354 | if (log) |
| 355 | log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are ignoring breakpoints, overriding breakpoint stop info ShouldStop, returning true"); |
| 356 | m_real_stop_info_sp->OverrideShouldStop(false); |
Jim Ingham | 923886c | 2012-05-11 18:43:38 +0000 | [diff] [blame] | 357 | return true; |
| 358 | } |
| 359 | else |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 360 | { |
| 361 | if (log) |
| 362 | log->Printf("ThreadPlanCallFunction::PlanExplainsStop: we are not ignoring breakpoints, overriding breakpoint stop info ShouldStop, returning true"); |
| 363 | m_real_stop_info_sp->OverrideShouldStop(true); |
Jim Ingham | 923886c | 2012-05-11 18:43:38 +0000 | [diff] [blame] | 364 | return false; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | else if (!m_unwind_on_error) |
| 368 | { |
| 369 | // If we don't want to discard this plan, than any stop we don't understand should be propagated up the stack. |
| 370 | return false; |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 +0000 | [diff] [blame] | 371 | } |
| 372 | else |
| 373 | { |
| 374 | // If the subplan is running, any crashes are attributable to us. |
Jim Ingham | 2c36439 | 2011-01-26 19:13:09 +0000 | [diff] [blame] | 375 | // If we want to discard the plan, then we say we explain the stop |
| 376 | // but if we are going to be discarded, let whoever is above us |
| 377 | // explain the stop. |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 378 | // But don't discard the plan if the stop would restart itself (for instance if it is a |
| 379 | // signal that is set not to stop. Check that here first. We just say we explain the stop |
| 380 | // but aren't done and everything will continue on from there. |
| 381 | |
| 382 | if (m_real_stop_info_sp->ShouldStopSynchronous(event_ptr)) |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 383 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 384 | SetPlanComplete(false); |
| 385 | if (m_subplan_sp) |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 386 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 387 | if (m_unwind_on_error) |
| 388 | return true; |
| 389 | else |
| 390 | return false; |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 391 | } |
| 392 | else |
| 393 | return false; |
| 394 | } |
| 395 | else |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 396 | return true; |
Jim Ingham | 40d871f | 2010-10-26 00:27:45 +0000 | [diff] [blame] | 397 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | bool |
| 401 | ThreadPlanCallFunction::ShouldStop (Event *event_ptr) |
| 402 | { |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 403 | // We do some computation in DoPlanExplainsStop that may or may not set the plan as complete. |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 404 | // We need to do that here to make sure our state is correct. |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 405 | DoPlanExplainsStop(event_ptr); |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 406 | |
| 407 | if (IsPlanComplete()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 408 | { |
Jim Ingham | 9da3683 | 2011-01-22 01:27:23 +0000 | [diff] [blame] | 409 | ReportRegisterState ("Function completed. Register state was:"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 410 | return true; |
| 411 | } |
| 412 | else |
| 413 | { |
| 414 | return false; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | bool |
| 419 | ThreadPlanCallFunction::StopOthers () |
| 420 | { |
| 421 | return m_stop_other_threads; |
| 422 | } |
| 423 | |
| 424 | void |
| 425 | ThreadPlanCallFunction::SetStopOthers (bool new_value) |
| 426 | { |
| 427 | if (m_subplan_sp) |
| 428 | { |
| 429 | ThreadPlanRunToAddress *address_plan = static_cast<ThreadPlanRunToAddress *>(m_subplan_sp.get()); |
| 430 | address_plan->SetStopOthers(new_value); |
| 431 | } |
| 432 | m_stop_other_threads = new_value; |
| 433 | } |
| 434 | |
| 435 | StateType |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 436 | ThreadPlanCallFunction::GetPlanRunState () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 437 | { |
| 438 | return eStateRunning; |
| 439 | } |
| 440 | |
| 441 | void |
| 442 | ThreadPlanCallFunction::DidPush () |
| 443 | { |
Sean Callanan | be3a1b1 | 2010-10-26 00:31:56 +0000 | [diff] [blame] | 444 | //#define SINGLE_STEP_EXPRESSIONS |
| 445 | |
Jim Ingham | 8559a35 | 2012-11-26 23:52:18 +0000 | [diff] [blame] | 446 | // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding... |
| 447 | // Wait till the plan is pushed so we aren't changing the stop info till we're about to run. |
| 448 | |
| 449 | GetThread().SetStopInfoToNothing(); |
| 450 | |
Sean Callanan | be3a1b1 | 2010-10-26 00:31:56 +0000 | [diff] [blame] | 451 | #ifndef SINGLE_STEP_EXPRESSIONS |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 452 | m_subplan_sp.reset(new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads)); |
| 453 | |
| 454 | m_thread.QueueThreadPlan(m_subplan_sp, false); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 455 | m_subplan_sp->SetPrivate (true); |
Sean Callanan | be3a1b1 | 2010-10-26 00:31:56 +0000 | [diff] [blame] | 456 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | bool |
| 460 | ThreadPlanCallFunction::WillStop () |
| 461 | { |
| 462 | return true; |
| 463 | } |
| 464 | |
| 465 | bool |
| 466 | ThreadPlanCallFunction::MischiefManaged () |
| 467 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 468 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 469 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 470 | if (IsPlanComplete()) |
| 471 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 472 | if (log) |
Jim Ingham | 87d0e61 | 2012-04-13 23:11:52 +0000 | [diff] [blame] | 473 | log->Printf("ThreadPlanCallFunction(%p): Completed call function plan.", this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 474 | |
| 475 | ThreadPlan::MischiefManaged (); |
| 476 | return true; |
| 477 | } |
| 478 | else |
| 479 | { |
| 480 | return false; |
| 481 | } |
| 482 | } |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 +0000 | [diff] [blame] | 483 | |
| 484 | void |
| 485 | ThreadPlanCallFunction::SetBreakpoints () |
| 486 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 487 | ProcessSP process_sp (m_thread.CalculateProcess()); |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 488 | if (m_trap_exceptions && process_sp) |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 489 | { |
| 490 | m_cxx_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeC_plus_plus); |
| 491 | m_objc_language_runtime = process_sp->GetLanguageRuntime(eLanguageTypeObjC); |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 +0000 | [diff] [blame] | 492 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 493 | if (m_cxx_language_runtime) |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 494 | { |
| 495 | m_should_clear_cxx_exception_bp = !m_cxx_language_runtime->ExceptionBreakpointsAreSet(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 496 | m_cxx_language_runtime->SetExceptionBreakpoints(); |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 497 | } |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 498 | if (m_objc_language_runtime) |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 499 | { |
| 500 | m_should_clear_objc_exception_bp = !m_objc_language_runtime->ExceptionBreakpointsAreSet(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 501 | m_objc_language_runtime->SetExceptionBreakpoints(); |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 502 | } |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 503 | } |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | void |
| 507 | ThreadPlanCallFunction::ClearBreakpoints () |
| 508 | { |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 509 | if (m_trap_exceptions) |
| 510 | { |
| 511 | if (m_cxx_language_runtime && m_should_clear_cxx_exception_bp) |
| 512 | m_cxx_language_runtime->ClearExceptionBreakpoints(); |
| 513 | if (m_objc_language_runtime && m_should_clear_objc_exception_bp) |
| 514 | m_objc_language_runtime->ClearExceptionBreakpoints(); |
| 515 | } |
Sean Callanan | 6db73ca | 2010-11-03 01:37:52 +0000 | [diff] [blame] | 516 | } |
Sean Callanan | c98aca6 | 2010-11-03 19:36:28 +0000 | [diff] [blame] | 517 | |
| 518 | bool |
| 519 | ThreadPlanCallFunction::BreakpointsExplainStop() |
| 520 | { |
Jim Ingham | 60c4118 | 2013-06-04 01:40:51 +0000 | [diff] [blame] | 521 | StopInfoSP stop_info_sp = GetPrivateStopInfo (); |
Sean Callanan | c98aca6 | 2010-11-03 19:36:28 +0000 | [diff] [blame] | 522 | |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 523 | if (m_trap_exceptions) |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 524 | { |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 525 | if ((m_cxx_language_runtime && |
| 526 | m_cxx_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp)) |
| 527 | ||(m_objc_language_runtime && |
| 528 | m_objc_language_runtime->ExceptionBreakpointsExplainStop(stop_info_sp))) |
| 529 | { |
| 530 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP)); |
| 531 | if (log) |
| 532 | log->Printf ("ThreadPlanCallFunction::BreakpointsExplainStop - Hit an exception breakpoint, setting plan complete."); |
| 533 | |
| 534 | SetPlanComplete(false); |
| 535 | |
| 536 | // If the user has set the ObjC language breakpoint, it would normally get priority over our internal |
| 537 | // catcher breakpoint, but in this case we can't let that happen, so force the ShouldStop here. |
| 538 | stop_info_sp->OverrideShouldStop (true); |
| 539 | return true; |
| 540 | } |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 541 | } |
Sean Callanan | c98aca6 | 2010-11-03 19:36:28 +0000 | [diff] [blame] | 542 | |
Sean Callanan | c98aca6 | 2010-11-03 19:36:28 +0000 | [diff] [blame] | 543 | return false; |
| 544 | } |
Jim Ingham | 8559a35 | 2012-11-26 23:52:18 +0000 | [diff] [blame] | 545 | |
| 546 | bool |
| 547 | ThreadPlanCallFunction::RestoreThreadState() |
| 548 | { |
| 549 | return GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state); |
| 550 | } |
| 551 | |