Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- Process.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 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "lldb/Target/Process.h" |
| 13 | |
| 14 | #include "lldb/lldb-private-log.h" |
| 15 | |
| 16 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
| 17 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 18 | #include "lldb/Core/Event.h" |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 19 | #include "lldb/Core/ConnectionFileDescriptor.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Debugger.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" |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 23 | #include "lldb/Symbol/Symbol.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Core/PluginManager.h" |
| 25 | #include "lldb/Core/State.h" |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 26 | #include "lldb/Core/StreamFile.h" |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 27 | #include "lldb/Expression/ClangUserExpression.h" |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 28 | #include "lldb/Interpreter/CommandInterpreter.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Host/Host.h" |
Greg Clayton | 100eb93 | 2014-07-02 21:10:39 +0000 | [diff] [blame] | 30 | #include "lldb/Host/Pipe.h" |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 31 | #include "lldb/Host/Terminal.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | #include "lldb/Target/ABI.h" |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 33 | #include "lldb/Target/DynamicLoader.h" |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 34 | #include "lldb/Target/JITLoader.h" |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 35 | #include "lldb/Target/OperatingSystem.h" |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 36 | #include "lldb/Target/LanguageRuntime.h" |
| 37 | #include "lldb/Target/CPPLanguageRuntime.h" |
| 38 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 39 | #include "lldb/Target/Platform.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 41 | #include "lldb/Target/StopInfo.h" |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 42 | #include "lldb/Target/SystemRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | #include "lldb/Target/Target.h" |
| 44 | #include "lldb/Target/TargetList.h" |
| 45 | #include "lldb/Target/Thread.h" |
| 46 | #include "lldb/Target/ThreadPlan.h" |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 47 | #include "lldb/Target/ThreadPlanBase.h" |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 48 | #include "Plugins/Process/Utility/InferiorCallPOSIX.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | |
Charles Davis | 510938e | 2013-08-27 05:04:57 +0000 | [diff] [blame] | 50 | #ifndef LLDB_DISABLE_POSIX |
| 51 | #include <spawn.h> |
| 52 | #endif |
| 53 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | using namespace lldb; |
| 55 | using namespace lldb_private; |
| 56 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 57 | |
| 58 | // Comment out line below to disable memory caching, overriding the process setting |
| 59 | // target.process.disable-memory-cache |
| 60 | #define ENABLE_MEMORY_CACHING |
| 61 | |
| 62 | #ifdef ENABLE_MEMORY_CACHING |
| 63 | #define DISABLE_MEM_CACHE_DEFAULT false |
| 64 | #else |
| 65 | #define DISABLE_MEM_CACHE_DEFAULT true |
| 66 | #endif |
| 67 | |
| 68 | class ProcessOptionValueProperties : public OptionValueProperties |
| 69 | { |
| 70 | public: |
| 71 | ProcessOptionValueProperties (const ConstString &name) : |
| 72 | OptionValueProperties (name) |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | // This constructor is used when creating ProcessOptionValueProperties when it |
| 77 | // is part of a new lldb_private::Process instance. It will copy all current |
| 78 | // global property values as needed |
| 79 | ProcessOptionValueProperties (ProcessProperties *global_properties) : |
| 80 | OptionValueProperties(*global_properties->GetValueProperties()) |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | virtual const Property * |
| 85 | GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const |
| 86 | { |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 87 | // When getting the value for a key from the process options, we will always |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 88 | // try and grab the setting from the current process if there is one. Else we just |
| 89 | // use the one from this instance. |
| 90 | if (exe_ctx) |
| 91 | { |
| 92 | Process *process = exe_ctx->GetProcessPtr(); |
| 93 | if (process) |
| 94 | { |
| 95 | ProcessOptionValueProperties *instance_properties = static_cast<ProcessOptionValueProperties *>(process->GetValueProperties().get()); |
| 96 | if (this != instance_properties) |
| 97 | return instance_properties->ProtectedGetPropertyAtIndex (idx); |
| 98 | } |
| 99 | } |
| 100 | return ProtectedGetPropertyAtIndex (idx); |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | static PropertyDefinition |
| 105 | g_properties[] = |
| 106 | { |
| 107 | { "disable-memory-cache" , OptionValue::eTypeBoolean, false, DISABLE_MEM_CACHE_DEFAULT, NULL, NULL, "Disable reading and caching of memory in fixed-size units." }, |
Jim Ingham | 8c3f276 | 2012-11-29 00:41:12 +0000 | [diff] [blame] | 108 | { "extra-startup-command", OptionValue::eTypeArray , false, OptionValue::eTypeString, NULL, NULL, "A list containing extra commands understood by the particular process plugin used. " |
| 109 | "For instance, to turn on debugserver logging set this to \"QSetLogging:bitmask=LOG_DEFAULT;\"" }, |
Jim Ingham | afc1b12 | 2013-01-31 19:48:57 +0000 | [diff] [blame] | 110 | { "ignore-breakpoints-in-expressions", OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, breakpoints will be ignored during expression evaluation." }, |
| 111 | { "unwind-on-error-in-expressions", OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, errors in expression evaluation will unwind the stack back to the state before the call." }, |
Greg Clayton | e1e835c | 2012-11-29 18:48:47 +0000 | [diff] [blame] | 112 | { "python-os-plugin-path", OptionValue::eTypeFileSpec, false, true, NULL, NULL, "A path to a python OS plug-in module file that contains a OperatingSystemPlugIn class." }, |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 113 | { "stop-on-sharedlibrary-events" , OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true, stop when a shared library is loaded or unloaded." }, |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 114 | { "detach-keeps-stopped" , OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true, detach will attempt to keep the process stopped." }, |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 115 | { NULL , OptionValue::eTypeInvalid, false, 0, NULL, NULL, NULL } |
| 116 | }; |
| 117 | |
| 118 | enum { |
| 119 | ePropertyDisableMemCache, |
Greg Clayton | c9d645d | 2012-10-18 22:40:37 +0000 | [diff] [blame] | 120 | ePropertyExtraStartCommand, |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 121 | ePropertyIgnoreBreakpointsInExpressions, |
| 122 | ePropertyUnwindOnErrorInExpressions, |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 123 | ePropertyPythonOSPluginPath, |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 124 | ePropertyStopOnSharedLibraryEvents, |
| 125 | ePropertyDetachKeepsStopped |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | ProcessProperties::ProcessProperties (bool is_global) : |
| 129 | Properties () |
| 130 | { |
| 131 | if (is_global) |
| 132 | { |
| 133 | m_collection_sp.reset (new ProcessOptionValueProperties(ConstString("process"))); |
| 134 | m_collection_sp->Initialize(g_properties); |
| 135 | m_collection_sp->AppendProperty(ConstString("thread"), |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 136 | ConstString("Settings specific to threads."), |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 137 | true, |
| 138 | Thread::GetGlobalProperties()->GetValueProperties()); |
| 139 | } |
| 140 | else |
| 141 | m_collection_sp.reset (new ProcessOptionValueProperties(Process::GetGlobalProperties().get())); |
| 142 | } |
| 143 | |
| 144 | ProcessProperties::~ProcessProperties() |
| 145 | { |
| 146 | } |
| 147 | |
| 148 | bool |
| 149 | ProcessProperties::GetDisableMemoryCache() const |
| 150 | { |
| 151 | const uint32_t idx = ePropertyDisableMemCache; |
| 152 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 153 | } |
| 154 | |
| 155 | Args |
| 156 | ProcessProperties::GetExtraStartupCommands () const |
| 157 | { |
| 158 | Args args; |
| 159 | const uint32_t idx = ePropertyExtraStartCommand; |
| 160 | m_collection_sp->GetPropertyAtIndexAsArgs(NULL, idx, args); |
| 161 | return args; |
| 162 | } |
| 163 | |
| 164 | void |
| 165 | ProcessProperties::SetExtraStartupCommands (const Args &args) |
| 166 | { |
| 167 | const uint32_t idx = ePropertyExtraStartCommand; |
| 168 | m_collection_sp->SetPropertyAtIndexFromArgs(NULL, idx, args); |
| 169 | } |
| 170 | |
Greg Clayton | c9d645d | 2012-10-18 22:40:37 +0000 | [diff] [blame] | 171 | FileSpec |
| 172 | ProcessProperties::GetPythonOSPluginPath () const |
| 173 | { |
| 174 | const uint32_t idx = ePropertyPythonOSPluginPath; |
| 175 | return m_collection_sp->GetPropertyAtIndexAsFileSpec(NULL, idx); |
| 176 | } |
| 177 | |
| 178 | void |
| 179 | ProcessProperties::SetPythonOSPluginPath (const FileSpec &file) |
| 180 | { |
| 181 | const uint32_t idx = ePropertyPythonOSPluginPath; |
| 182 | m_collection_sp->SetPropertyAtIndexAsFileSpec(NULL, idx, file); |
| 183 | } |
| 184 | |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 185 | |
| 186 | bool |
| 187 | ProcessProperties::GetIgnoreBreakpointsInExpressions () const |
| 188 | { |
| 189 | const uint32_t idx = ePropertyIgnoreBreakpointsInExpressions; |
| 190 | return m_collection_sp->GetPropertyAtIndexAsBoolean(NULL, idx, g_properties[idx].default_uint_value != 0); |
| 191 | } |
| 192 | |
| 193 | void |
| 194 | ProcessProperties::SetIgnoreBreakpointsInExpressions (bool ignore) |
| 195 | { |
| 196 | const uint32_t idx = ePropertyIgnoreBreakpointsInExpressions; |
| 197 | m_collection_sp->SetPropertyAtIndexAsBoolean(NULL, idx, ignore); |
| 198 | } |
| 199 | |
| 200 | bool |
| 201 | ProcessProperties::GetUnwindOnErrorInExpressions () const |
| 202 | { |
| 203 | const uint32_t idx = ePropertyUnwindOnErrorInExpressions; |
| 204 | return m_collection_sp->GetPropertyAtIndexAsBoolean(NULL, idx, g_properties[idx].default_uint_value != 0); |
| 205 | } |
| 206 | |
| 207 | void |
| 208 | ProcessProperties::SetUnwindOnErrorInExpressions (bool ignore) |
| 209 | { |
| 210 | const uint32_t idx = ePropertyUnwindOnErrorInExpressions; |
| 211 | m_collection_sp->SetPropertyAtIndexAsBoolean(NULL, idx, ignore); |
| 212 | } |
| 213 | |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 214 | bool |
| 215 | ProcessProperties::GetStopOnSharedLibraryEvents () const |
| 216 | { |
| 217 | const uint32_t idx = ePropertyStopOnSharedLibraryEvents; |
| 218 | return m_collection_sp->GetPropertyAtIndexAsBoolean(NULL, idx, g_properties[idx].default_uint_value != 0); |
| 219 | } |
| 220 | |
| 221 | void |
| 222 | ProcessProperties::SetStopOnSharedLibraryEvents (bool stop) |
| 223 | { |
| 224 | const uint32_t idx = ePropertyStopOnSharedLibraryEvents; |
| 225 | m_collection_sp->SetPropertyAtIndexAsBoolean(NULL, idx, stop); |
| 226 | } |
| 227 | |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 228 | bool |
| 229 | ProcessProperties::GetDetachKeepsStopped () const |
| 230 | { |
| 231 | const uint32_t idx = ePropertyDetachKeepsStopped; |
| 232 | return m_collection_sp->GetPropertyAtIndexAsBoolean(NULL, idx, g_properties[idx].default_uint_value != 0); |
| 233 | } |
| 234 | |
| 235 | void |
| 236 | ProcessProperties::SetDetachKeepsStopped (bool stop) |
| 237 | { |
| 238 | const uint32_t idx = ePropertyDetachKeepsStopped; |
| 239 | m_collection_sp->SetPropertyAtIndexAsBoolean(NULL, idx, stop); |
| 240 | } |
| 241 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 242 | void |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 243 | ProcessInstanceInfo::Dump (Stream &s, Platform *platform) const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 244 | { |
| 245 | const char *cstr; |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 246 | if (m_pid != LLDB_INVALID_PROCESS_ID) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 247 | s.Printf (" pid = %" PRIu64 "\n", m_pid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 248 | |
| 249 | if (m_parent_pid != LLDB_INVALID_PROCESS_ID) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 250 | s.Printf (" parent = %" PRIu64 "\n", m_parent_pid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 251 | |
| 252 | if (m_executable) |
| 253 | { |
| 254 | s.Printf (" name = %s\n", m_executable.GetFilename().GetCString()); |
| 255 | s.PutCString (" file = "); |
| 256 | m_executable.Dump(&s); |
| 257 | s.EOL(); |
| 258 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 259 | const uint32_t argc = m_arguments.GetArgumentCount(); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 260 | if (argc > 0) |
| 261 | { |
| 262 | for (uint32_t i=0; i<argc; i++) |
| 263 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 264 | const char *arg = m_arguments.GetArgumentAtIndex(i); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 265 | if (i < 10) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 266 | s.Printf (" arg[%u] = %s\n", i, arg); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 267 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 268 | s.Printf ("arg[%u] = %s\n", i, arg); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 269 | } |
| 270 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 271 | |
| 272 | const uint32_t envc = m_environment.GetArgumentCount(); |
| 273 | if (envc > 0) |
| 274 | { |
| 275 | for (uint32_t i=0; i<envc; i++) |
| 276 | { |
| 277 | const char *env = m_environment.GetArgumentAtIndex(i); |
| 278 | if (i < 10) |
| 279 | s.Printf (" env[%u] = %s\n", i, env); |
| 280 | else |
| 281 | s.Printf ("env[%u] = %s\n", i, env); |
| 282 | } |
| 283 | } |
| 284 | |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 285 | if (m_arch.IsValid()) |
| 286 | s.Printf (" arch = %s\n", m_arch.GetTriple().str().c_str()); |
| 287 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 288 | if (m_uid != UINT32_MAX) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 289 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 290 | cstr = platform->GetUserName (m_uid); |
| 291 | s.Printf (" uid = %-5u (%s)\n", m_uid, cstr ? cstr : ""); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 292 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 293 | if (m_gid != UINT32_MAX) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 294 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 295 | cstr = platform->GetGroupName (m_gid); |
| 296 | s.Printf (" gid = %-5u (%s)\n", m_gid, cstr ? cstr : ""); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 297 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 298 | if (m_euid != UINT32_MAX) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 299 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 300 | cstr = platform->GetUserName (m_euid); |
| 301 | s.Printf (" euid = %-5u (%s)\n", m_euid, cstr ? cstr : ""); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 302 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 303 | if (m_egid != UINT32_MAX) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 304 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 305 | cstr = platform->GetGroupName (m_egid); |
| 306 | s.Printf (" egid = %-5u (%s)\n", m_egid, cstr ? cstr : ""); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
| 310 | void |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 311 | ProcessInstanceInfo::DumpTableHeader (Stream &s, Platform *platform, bool show_args, bool verbose) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 312 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 313 | const char *label; |
| 314 | if (show_args || verbose) |
| 315 | label = "ARGUMENTS"; |
| 316 | else |
| 317 | label = "NAME"; |
| 318 | |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 319 | if (verbose) |
| 320 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 321 | s.Printf ("PID PARENT USER GROUP EFF USER EFF GROUP TRIPLE %s\n", label); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 322 | s.PutCString ("====== ====== ========== ========== ========== ========== ======================== ============================\n"); |
| 323 | } |
| 324 | else |
| 325 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 326 | s.Printf ("PID PARENT USER ARCH %s\n", label); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 327 | s.PutCString ("====== ====== ========== ======= ============================\n"); |
| 328 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | void |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 332 | ProcessInstanceInfo::DumpAsTableRow (Stream &s, Platform *platform, bool show_args, bool verbose) const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 333 | { |
| 334 | if (m_pid != LLDB_INVALID_PROCESS_ID) |
| 335 | { |
| 336 | const char *cstr; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 337 | s.Printf ("%-6" PRIu64 " %-6" PRIu64 " ", m_pid, m_parent_pid); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 338 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 339 | |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 340 | if (verbose) |
| 341 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 342 | cstr = platform->GetUserName (m_uid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 343 | if (cstr && cstr[0]) // Watch for empty string that indicates lookup failed |
| 344 | s.Printf ("%-10s ", cstr); |
| 345 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 346 | s.Printf ("%-10u ", m_uid); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 347 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 348 | cstr = platform->GetGroupName (m_gid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 349 | if (cstr && cstr[0]) // Watch for empty string that indicates lookup failed |
| 350 | s.Printf ("%-10s ", cstr); |
| 351 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 352 | s.Printf ("%-10u ", m_gid); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 353 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 354 | cstr = platform->GetUserName (m_euid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 355 | if (cstr && cstr[0]) // Watch for empty string that indicates lookup failed |
| 356 | s.Printf ("%-10s ", cstr); |
| 357 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 358 | s.Printf ("%-10u ", m_euid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 359 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 360 | cstr = platform->GetGroupName (m_egid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 361 | if (cstr && cstr[0]) // Watch for empty string that indicates lookup failed |
| 362 | s.Printf ("%-10s ", cstr); |
| 363 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 364 | s.Printf ("%-10u ", m_egid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 365 | s.Printf ("%-24s ", m_arch.IsValid() ? m_arch.GetTriple().str().c_str() : ""); |
| 366 | } |
| 367 | else |
| 368 | { |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 369 | s.Printf ("%-10s %-7d %s ", |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 370 | platform->GetUserName (m_euid), |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 371 | (int)m_arch.GetTriple().getArchName().size(), |
| 372 | m_arch.GetTriple().getArchName().data()); |
| 373 | } |
| 374 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 375 | if (verbose || show_args) |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 376 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 377 | const uint32_t argc = m_arguments.GetArgumentCount(); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 378 | if (argc > 0) |
| 379 | { |
| 380 | for (uint32_t i=0; i<argc; i++) |
| 381 | { |
| 382 | if (i > 0) |
| 383 | s.PutChar (' '); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 384 | s.PutCString (m_arguments.GetArgumentAtIndex(i)); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | s.PutCString (GetName()); |
| 391 | } |
| 392 | |
| 393 | s.EOL(); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 397 | Error |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 398 | ProcessLaunchCommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 399 | { |
| 400 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 401 | const int short_option = m_getopt_table[option_idx].val; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 402 | |
| 403 | switch (short_option) |
| 404 | { |
| 405 | case 's': // Stop at program entry point |
| 406 | launch_info.GetFlags().Set (eLaunchFlagStopAtEntry); |
| 407 | break; |
| 408 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 409 | case 'i': // STDIN for read only |
| 410 | { |
| 411 | ProcessLaunchInfo::FileAction action; |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 412 | if (action.Open (STDIN_FILENO, option_arg, true, false)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 413 | launch_info.AppendFileAction (action); |
| 414 | } |
| 415 | break; |
| 416 | |
| 417 | case 'o': // Open STDOUT for write only |
| 418 | { |
| 419 | ProcessLaunchInfo::FileAction action; |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 420 | if (action.Open (STDOUT_FILENO, option_arg, false, true)) |
| 421 | launch_info.AppendFileAction (action); |
| 422 | } |
| 423 | break; |
| 424 | |
| 425 | case 'e': // STDERR for write only |
| 426 | { |
| 427 | ProcessLaunchInfo::FileAction action; |
| 428 | if (action.Open (STDERR_FILENO, option_arg, false, true)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 429 | launch_info.AppendFileAction (action); |
| 430 | } |
| 431 | break; |
| 432 | |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 433 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 434 | case 'p': // Process plug-in name |
| 435 | launch_info.SetProcessPluginName (option_arg); |
| 436 | break; |
| 437 | |
| 438 | case 'n': // Disable STDIO |
| 439 | { |
| 440 | ProcessLaunchInfo::FileAction action; |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 441 | if (action.Open (STDIN_FILENO, "/dev/null", true, false)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 442 | launch_info.AppendFileAction (action); |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 443 | if (action.Open (STDOUT_FILENO, "/dev/null", false, true)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 444 | launch_info.AppendFileAction (action); |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 445 | if (action.Open (STDERR_FILENO, "/dev/null", false, true)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 446 | launch_info.AppendFileAction (action); |
| 447 | } |
| 448 | break; |
| 449 | |
| 450 | case 'w': |
| 451 | launch_info.SetWorkingDirectory (option_arg); |
| 452 | break; |
| 453 | |
| 454 | case 't': // Open process in new terminal window |
| 455 | launch_info.GetFlags().Set (eLaunchFlagLaunchInTTY); |
| 456 | break; |
| 457 | |
| 458 | case 'a': |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 459 | if (!launch_info.GetArchitecture().SetTriple (option_arg, m_interpreter.GetPlatform(true).get())) |
| 460 | launch_info.GetArchitecture().SetTriple (option_arg); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 461 | break; |
| 462 | |
| 463 | case 'A': |
| 464 | launch_info.GetFlags().Set (eLaunchFlagDisableASLR); |
| 465 | break; |
| 466 | |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 467 | case 'c': |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 468 | if (option_arg && option_arg[0]) |
| 469 | launch_info.SetShell (option_arg); |
| 470 | else |
Ed Maste | b8ca4a2 | 2013-09-03 23:04:53 +0000 | [diff] [blame] | 471 | launch_info.SetShell (LLDB_DEFAULT_SHELL); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 472 | break; |
| 473 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 474 | case 'v': |
| 475 | launch_info.GetEnvironmentEntries().AppendArgument(option_arg); |
| 476 | break; |
| 477 | |
| 478 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 479 | error.SetErrorStringWithFormat("unrecognized short option character '%c'", short_option); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 480 | break; |
| 481 | |
| 482 | } |
| 483 | return error; |
| 484 | } |
| 485 | |
| 486 | OptionDefinition |
| 487 | ProcessLaunchCommandOptions::g_option_table[] = |
| 488 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 489 | { LLDB_OPT_SET_ALL, false, "stop-at-entry", 's', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Stop at the entry point of the program when launching a process."}, |
| 490 | { LLDB_OPT_SET_ALL, false, "disable-aslr", 'A', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Disable address space layout randomization when launching a process."}, |
| 491 | { LLDB_OPT_SET_ALL, false, "plugin", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, |
| 492 | { LLDB_OPT_SET_ALL, false, "working-dir", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeDirectoryName, "Set the current working directory to <path> when running the inferior."}, |
| 493 | { LLDB_OPT_SET_ALL, false, "arch", 'a', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeArchitecture, "Set the architecture for the process to launch when ambiguous."}, |
| 494 | { LLDB_OPT_SET_ALL, false, "environment", 'v', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeNone, "Specify an environment variable name/value string (--environment NAME=VALUE). Can be specified multiple times for subsequent environment entries."}, |
| 495 | { LLDB_OPT_SET_ALL, false, "shell", 'c', OptionParser::eOptionalArgument, NULL, NULL, 0, eArgTypeFilename, "Run the process in a shell (not supported on all platforms)."}, |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 496 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 497 | { LLDB_OPT_SET_1 , false, "stdin", 'i', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeFilename, "Redirect stdin for the process to <filename>."}, |
| 498 | { LLDB_OPT_SET_1 , false, "stdout", 'o', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeFilename, "Redirect stdout for the process to <filename>."}, |
| 499 | { LLDB_OPT_SET_1 , false, "stderr", 'e', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeFilename, "Redirect stderr for the process to <filename>."}, |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 500 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 501 | { LLDB_OPT_SET_2 , false, "tty", 't', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Start the process in a terminal (not supported on all platforms)."}, |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 502 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 503 | { LLDB_OPT_SET_3 , false, "no-stdio", 'n', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Do not set up for terminal I/O to go to running process."}, |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 504 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 505 | { 0 , false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 506 | }; |
| 507 | |
| 508 | |
| 509 | |
| 510 | bool |
| 511 | ProcessInstanceInfoMatch::NameMatches (const char *process_name) const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 512 | { |
| 513 | if (m_name_match_type == eNameMatchIgnore || process_name == NULL) |
| 514 | return true; |
| 515 | const char *match_name = m_match_info.GetName(); |
| 516 | if (!match_name) |
| 517 | return true; |
| 518 | |
| 519 | return lldb_private::NameMatches (process_name, m_name_match_type, match_name); |
| 520 | } |
| 521 | |
| 522 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 523 | ProcessInstanceInfoMatch::Matches (const ProcessInstanceInfo &proc_info) const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 524 | { |
| 525 | if (!NameMatches (proc_info.GetName())) |
| 526 | return false; |
| 527 | |
| 528 | if (m_match_info.ProcessIDIsValid() && |
| 529 | m_match_info.GetProcessID() != proc_info.GetProcessID()) |
| 530 | return false; |
| 531 | |
| 532 | if (m_match_info.ParentProcessIDIsValid() && |
| 533 | m_match_info.GetParentProcessID() != proc_info.GetParentProcessID()) |
| 534 | return false; |
| 535 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 536 | if (m_match_info.UserIDIsValid () && |
| 537 | m_match_info.GetUserID() != proc_info.GetUserID()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 538 | return false; |
| 539 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 540 | if (m_match_info.GroupIDIsValid () && |
| 541 | m_match_info.GetGroupID() != proc_info.GetGroupID()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 542 | return false; |
| 543 | |
| 544 | if (m_match_info.EffectiveUserIDIsValid () && |
| 545 | m_match_info.GetEffectiveUserID() != proc_info.GetEffectiveUserID()) |
| 546 | return false; |
| 547 | |
| 548 | if (m_match_info.EffectiveGroupIDIsValid () && |
| 549 | m_match_info.GetEffectiveGroupID() != proc_info.GetEffectiveGroupID()) |
| 550 | return false; |
| 551 | |
| 552 | if (m_match_info.GetArchitecture().IsValid() && |
Sean Callanan | bf4b7be | 2012-12-13 22:07:14 +0000 | [diff] [blame] | 553 | !m_match_info.GetArchitecture().IsCompatibleMatch(proc_info.GetArchitecture())) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 554 | return false; |
| 555 | return true; |
| 556 | } |
| 557 | |
| 558 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 559 | ProcessInstanceInfoMatch::MatchAllProcesses () const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 560 | { |
| 561 | if (m_name_match_type != eNameMatchIgnore) |
| 562 | return false; |
| 563 | |
| 564 | if (m_match_info.ProcessIDIsValid()) |
| 565 | return false; |
| 566 | |
| 567 | if (m_match_info.ParentProcessIDIsValid()) |
| 568 | return false; |
| 569 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 570 | if (m_match_info.UserIDIsValid ()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 571 | return false; |
| 572 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 573 | if (m_match_info.GroupIDIsValid ()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 574 | return false; |
| 575 | |
| 576 | if (m_match_info.EffectiveUserIDIsValid ()) |
| 577 | return false; |
| 578 | |
| 579 | if (m_match_info.EffectiveGroupIDIsValid ()) |
| 580 | return false; |
| 581 | |
| 582 | if (m_match_info.GetArchitecture().IsValid()) |
| 583 | return false; |
| 584 | |
| 585 | if (m_match_all_users) |
| 586 | return false; |
| 587 | |
| 588 | return true; |
| 589 | |
| 590 | } |
| 591 | |
| 592 | void |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 593 | ProcessInstanceInfoMatch::Clear() |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 594 | { |
| 595 | m_match_info.Clear(); |
| 596 | m_name_match_type = eNameMatchIgnore; |
| 597 | m_match_all_users = false; |
| 598 | } |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 599 | |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 600 | ProcessSP |
| 601 | Process::FindPlugin (Target &target, const char *plugin_name, Listener &listener, const FileSpec *crash_file_path) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 602 | { |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 603 | static uint32_t g_process_unique_id = 0; |
| 604 | |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 605 | ProcessSP process_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 606 | ProcessCreateInstance create_callback = NULL; |
| 607 | if (plugin_name) |
| 608 | { |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 609 | ConstString const_plugin_name(plugin_name); |
| 610 | create_callback = PluginManager::GetProcessCreateCallbackForPluginName (const_plugin_name); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 611 | if (create_callback) |
| 612 | { |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 613 | process_sp = create_callback(target, listener, crash_file_path); |
| 614 | if (process_sp) |
| 615 | { |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 616 | if (process_sp->CanDebug(target, true)) |
| 617 | { |
| 618 | process_sp->m_process_unique_id = ++g_process_unique_id; |
| 619 | } |
| 620 | else |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 621 | process_sp.reset(); |
| 622 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | else |
| 626 | { |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 627 | for (uint32_t idx = 0; (create_callback = PluginManager::GetProcessCreateCallbackAtIndex(idx)) != NULL; ++idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 628 | { |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 629 | process_sp = create_callback(target, listener, crash_file_path); |
| 630 | if (process_sp) |
| 631 | { |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 632 | if (process_sp->CanDebug(target, false)) |
| 633 | { |
| 634 | process_sp->m_process_unique_id = ++g_process_unique_id; |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 635 | break; |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 636 | } |
| 637 | else |
| 638 | process_sp.reset(); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 639 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 640 | } |
| 641 | } |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 642 | return process_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 643 | } |
| 644 | |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 645 | ConstString & |
| 646 | Process::GetStaticBroadcasterClass () |
| 647 | { |
| 648 | static ConstString class_name ("lldb.process"); |
| 649 | return class_name; |
| 650 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 651 | |
| 652 | //---------------------------------------------------------------------- |
| 653 | // Process constructor |
| 654 | //---------------------------------------------------------------------- |
| 655 | Process::Process(Target &target, Listener &listener) : |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 656 | ProcessProperties (false), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 657 | UserID (LLDB_INVALID_PROCESS_ID), |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 658 | Broadcaster (&(target.GetDebugger()), "lldb.process"), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 659 | m_target (target), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 660 | m_public_state (eStateUnloaded), |
| 661 | m_private_state (eStateUnloaded), |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 662 | m_private_state_broadcaster (NULL, "lldb.process.internal_state_broadcaster"), |
| 663 | m_private_state_control_broadcaster (NULL, "lldb.process.internal_state_control_broadcaster"), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 664 | m_private_state_listener ("lldb.process.internal_state_listener"), |
| 665 | m_private_state_control_wait(), |
| 666 | m_private_state_thread (LLDB_INVALID_HOST_THREAD), |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 667 | m_mod_id (), |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 668 | m_process_unique_id(0), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 669 | m_thread_index_id (0), |
Han Ming Ong | c2c423e | 2013-01-08 22:10:01 +0000 | [diff] [blame] | 670 | m_thread_id_to_index_id_map (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 671 | m_exit_status (-1), |
| 672 | m_exit_string (), |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 673 | m_thread_mutex (Mutex::eMutexTypeRecursive), |
| 674 | m_thread_list_real (this), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 675 | m_thread_list (this), |
Jason Molenda | 864f1cc | 2013-11-11 05:20:44 +0000 | [diff] [blame] | 676 | m_extended_thread_list (this), |
Jason Molenda | 4ff1326 | 2013-11-20 00:31:38 +0000 | [diff] [blame] | 677 | m_extended_thread_stop_id (0), |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 678 | m_queue_list (this), |
| 679 | m_queue_list_stop_id (0), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 680 | m_notifications (), |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 681 | m_image_tokens (), |
| 682 | m_listener (listener), |
| 683 | m_breakpoint_site_list (), |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 684 | m_dynamic_checkers_ap (), |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 685 | m_unix_signals (), |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 686 | m_abi_sp (), |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 687 | m_process_input_reader (), |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 688 | m_stdio_communication ("process.stdio"), |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 689 | m_stdio_communication_mutex (Mutex::eMutexTypeRecursive), |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 690 | m_stdout_data (), |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 691 | m_stderr_data (), |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 692 | m_profile_data_comm_mutex (Mutex::eMutexTypeRecursive), |
| 693 | m_profile_data (), |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 694 | m_memory_cache (*this), |
| 695 | m_allocated_memory_cache (*this), |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 696 | m_should_detach (false), |
Sean Callanan | 9053945 | 2011-09-20 23:01:51 +0000 | [diff] [blame] | 697 | m_next_event_action_ap(), |
Greg Clayton | 9624985 | 2013-04-18 16:57:27 +0000 | [diff] [blame] | 698 | m_public_run_lock (), |
Greg Clayton | 9624985 | 2013-04-18 16:57:27 +0000 | [diff] [blame] | 699 | m_private_run_lock (), |
Jim Ingham | aacc318 | 2012-06-06 00:29:30 +0000 | [diff] [blame] | 700 | m_currently_handling_event(false), |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 701 | m_finalize_called(false), |
Greg Clayton | f9b57b9 | 2013-05-10 23:48:10 +0000 | [diff] [blame] | 702 | m_clear_thread_plans_on_stop (false), |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 703 | m_force_next_event_delivery(false), |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 704 | m_last_broadcast_state (eStateInvalid), |
Jason Molenda | 69b6b63 | 2013-03-05 03:33:59 +0000 | [diff] [blame] | 705 | m_destroy_in_process (false), |
| 706 | m_can_jit(eCanJITDontKnow) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 707 | { |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 708 | CheckInWithManager (); |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 709 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 710 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 711 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 712 | log->Printf ("%p Process::Process()", static_cast<void*>(this)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 713 | |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 714 | SetEventName (eBroadcastBitStateChanged, "state-changed"); |
| 715 | SetEventName (eBroadcastBitInterrupt, "interrupt"); |
| 716 | SetEventName (eBroadcastBitSTDOUT, "stdout-available"); |
| 717 | SetEventName (eBroadcastBitSTDERR, "stderr-available"); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 718 | SetEventName (eBroadcastBitProfileData, "profile-data-available"); |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 719 | |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 720 | m_private_state_control_broadcaster.SetEventName (eBroadcastInternalStateControlStop , "control-stop" ); |
| 721 | m_private_state_control_broadcaster.SetEventName (eBroadcastInternalStateControlPause , "control-pause" ); |
| 722 | m_private_state_control_broadcaster.SetEventName (eBroadcastInternalStateControlResume, "control-resume"); |
| 723 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 724 | listener.StartListeningForEvents (this, |
| 725 | eBroadcastBitStateChanged | |
| 726 | eBroadcastBitInterrupt | |
| 727 | eBroadcastBitSTDOUT | |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 728 | eBroadcastBitSTDERR | |
| 729 | eBroadcastBitProfileData); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 730 | |
| 731 | m_private_state_listener.StartListeningForEvents(&m_private_state_broadcaster, |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 732 | eBroadcastBitStateChanged | |
| 733 | eBroadcastBitInterrupt); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 734 | |
| 735 | m_private_state_listener.StartListeningForEvents(&m_private_state_control_broadcaster, |
| 736 | eBroadcastInternalStateControlStop | |
| 737 | eBroadcastInternalStateControlPause | |
| 738 | eBroadcastInternalStateControlResume); |
| 739 | } |
| 740 | |
| 741 | //---------------------------------------------------------------------- |
| 742 | // Destructor |
| 743 | //---------------------------------------------------------------------- |
| 744 | Process::~Process() |
| 745 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 746 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 747 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 748 | log->Printf ("%p Process::~Process()", static_cast<void*>(this)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 749 | StopPrivateStateThread(); |
| 750 | } |
| 751 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 752 | const ProcessPropertiesSP & |
| 753 | Process::GetGlobalProperties() |
| 754 | { |
| 755 | static ProcessPropertiesSP g_settings_sp; |
| 756 | if (!g_settings_sp) |
| 757 | g_settings_sp.reset (new ProcessProperties (true)); |
| 758 | return g_settings_sp; |
| 759 | } |
| 760 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 761 | void |
| 762 | Process::Finalize() |
| 763 | { |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 764 | switch (GetPrivateState()) |
| 765 | { |
| 766 | case eStateConnected: |
| 767 | case eStateAttaching: |
| 768 | case eStateLaunching: |
| 769 | case eStateStopped: |
| 770 | case eStateRunning: |
| 771 | case eStateStepping: |
| 772 | case eStateCrashed: |
| 773 | case eStateSuspended: |
| 774 | if (GetShouldDetach()) |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 775 | { |
| 776 | // FIXME: This will have to be a process setting: |
| 777 | bool keep_stopped = false; |
| 778 | Detach(keep_stopped); |
| 779 | } |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 780 | else |
| 781 | Destroy(); |
| 782 | break; |
| 783 | |
| 784 | case eStateInvalid: |
| 785 | case eStateUnloaded: |
| 786 | case eStateDetached: |
| 787 | case eStateExited: |
| 788 | break; |
| 789 | } |
| 790 | |
Greg Clayton | 1ed54f5 | 2011-10-01 00:45:15 +0000 | [diff] [blame] | 791 | // Clear our broadcaster before we proceed with destroying |
| 792 | Broadcaster::Clear(); |
| 793 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 794 | // Do any cleanup needed prior to being destructed... Subclasses |
| 795 | // that override this method should call this superclass method as well. |
Jim Ingham | d0a3e12 | 2011-02-16 17:54:55 +0000 | [diff] [blame] | 796 | |
| 797 | // We need to destroy the loader before the derived Process class gets destroyed |
| 798 | // since it is very likely that undoing the loader will require access to the real process. |
Greg Clayton | 894f82f | 2012-01-20 23:08:34 +0000 | [diff] [blame] | 799 | m_dynamic_checkers_ap.reset(); |
| 800 | m_abi_sp.reset(); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 801 | m_os_ap.reset(); |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 802 | m_system_runtime_ap.reset(); |
Greg Clayton | 894f82f | 2012-01-20 23:08:34 +0000 | [diff] [blame] | 803 | m_dyld_ap.reset(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 804 | m_jit_loaders_ap.reset(); |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 805 | m_thread_list_real.Destroy(); |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 806 | m_thread_list.Destroy(); |
Jason Molenda | 864f1cc | 2013-11-11 05:20:44 +0000 | [diff] [blame] | 807 | m_extended_thread_list.Destroy(); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 808 | m_queue_list.Clear(); |
| 809 | m_queue_list_stop_id = 0; |
Greg Clayton | 894f82f | 2012-01-20 23:08:34 +0000 | [diff] [blame] | 810 | std::vector<Notifications> empty_notifications; |
| 811 | m_notifications.swap(empty_notifications); |
| 812 | m_image_tokens.clear(); |
| 813 | m_memory_cache.Clear(); |
| 814 | m_allocated_memory_cache.Clear(); |
| 815 | m_language_runtimes.clear(); |
| 816 | m_next_event_action_ap.reset(); |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 817 | //#ifdef LLDB_CONFIGURATION_DEBUG |
| 818 | // StreamFile s(stdout, false); |
| 819 | // EventSP event_sp; |
| 820 | // while (m_private_state_listener.GetNextEvent(event_sp)) |
| 821 | // { |
| 822 | // event_sp->Dump (&s); |
| 823 | // s.EOL(); |
| 824 | // } |
| 825 | //#endif |
| 826 | // We have to be very careful here as the m_private_state_listener might |
| 827 | // contain events that have ProcessSP values in them which can keep this |
| 828 | // process around forever. These events need to be cleared out. |
| 829 | m_private_state_listener.Clear(); |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 830 | m_public_run_lock.TrySetRunning(); // This will do nothing if already locked |
| 831 | m_public_run_lock.SetStopped(); |
| 832 | m_private_run_lock.TrySetRunning(); // This will do nothing if already locked |
| 833 | m_private_run_lock.SetStopped(); |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 834 | m_finalize_called = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | void |
| 838 | Process::RegisterNotificationCallbacks (const Notifications& callbacks) |
| 839 | { |
| 840 | m_notifications.push_back(callbacks); |
| 841 | if (callbacks.initialize != NULL) |
| 842 | callbacks.initialize (callbacks.baton, this); |
| 843 | } |
| 844 | |
| 845 | bool |
| 846 | Process::UnregisterNotificationCallbacks(const Notifications& callbacks) |
| 847 | { |
| 848 | std::vector<Notifications>::iterator pos, end = m_notifications.end(); |
| 849 | for (pos = m_notifications.begin(); pos != end; ++pos) |
| 850 | { |
| 851 | if (pos->baton == callbacks.baton && |
| 852 | pos->initialize == callbacks.initialize && |
| 853 | pos->process_state_changed == callbacks.process_state_changed) |
| 854 | { |
| 855 | m_notifications.erase(pos); |
| 856 | return true; |
| 857 | } |
| 858 | } |
| 859 | return false; |
| 860 | } |
| 861 | |
| 862 | void |
| 863 | Process::SynchronouslyNotifyStateChanged (StateType state) |
| 864 | { |
| 865 | std::vector<Notifications>::iterator notification_pos, notification_end = m_notifications.end(); |
| 866 | for (notification_pos = m_notifications.begin(); notification_pos != notification_end; ++notification_pos) |
| 867 | { |
| 868 | if (notification_pos->process_state_changed) |
| 869 | notification_pos->process_state_changed (notification_pos->baton, this, state); |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | // FIXME: We need to do some work on events before the general Listener sees them. |
| 874 | // For instance if we are continuing from a breakpoint, we need to ensure that we do |
| 875 | // the little "insert real insn, step & stop" trick. But we can't do that when the |
| 876 | // event is delivered by the broadcaster - since that is done on the thread that is |
| 877 | // waiting for new events, so if we needed more than one event for our handling, we would |
| 878 | // stall. So instead we do it when we fetch the event off of the queue. |
| 879 | // |
| 880 | |
| 881 | StateType |
| 882 | Process::GetNextEvent (EventSP &event_sp) |
| 883 | { |
| 884 | StateType state = eStateInvalid; |
| 885 | |
| 886 | if (m_listener.GetNextEventForBroadcaster (this, event_sp) && event_sp) |
| 887 | state = Process::ProcessEventData::GetStateFromEvent (event_sp.get()); |
| 888 | |
| 889 | return state; |
| 890 | } |
| 891 | |
| 892 | |
| 893 | StateType |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 894 | Process::WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp_ptr, bool wait_always, Listener *hijack_listener) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 895 | { |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 896 | // We can't just wait for a "stopped" event, because the stopped event may have restarted the target. |
| 897 | // We have to actually check each event, and in the case of a stopped event check the restarted flag |
| 898 | // on the event. |
Greg Clayton | 85fb1b9 | 2012-09-11 02:33:37 +0000 | [diff] [blame] | 899 | if (event_sp_ptr) |
| 900 | event_sp_ptr->reset(); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 901 | StateType state = GetState(); |
| 902 | // If we are exited or detached, we won't ever get back to any |
| 903 | // other valid state... |
| 904 | if (state == eStateDetached || state == eStateExited) |
| 905 | return state; |
| 906 | |
Daniel Malea | 9e9919f | 2013-10-09 16:56:28 +0000 | [diff] [blame] | 907 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 908 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 909 | log->Printf ("Process::%s (timeout = %p)", __FUNCTION__, |
| 910 | static_cast<const void*>(timeout)); |
Daniel Malea | 9e9919f | 2013-10-09 16:56:28 +0000 | [diff] [blame] | 911 | |
| 912 | if (!wait_always && |
| 913 | StateIsStoppedState(state, true) && |
| 914 | StateIsStoppedState(GetPrivateState(), true)) { |
| 915 | if (log) |
| 916 | log->Printf("Process::%s returning without waiting for events; process private and public states are already 'stopped'.", |
| 917 | __FUNCTION__); |
| 918 | return state; |
| 919 | } |
| 920 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 921 | while (state != eStateInvalid) |
| 922 | { |
Greg Clayton | 85fb1b9 | 2012-09-11 02:33:37 +0000 | [diff] [blame] | 923 | EventSP event_sp; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 924 | state = WaitForStateChangedEvents (timeout, event_sp, hijack_listener); |
Greg Clayton | 85fb1b9 | 2012-09-11 02:33:37 +0000 | [diff] [blame] | 925 | if (event_sp_ptr && event_sp) |
| 926 | *event_sp_ptr = event_sp; |
| 927 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 928 | switch (state) |
| 929 | { |
| 930 | case eStateCrashed: |
| 931 | case eStateDetached: |
| 932 | case eStateExited: |
| 933 | case eStateUnloaded: |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 934 | // We need to toggle the run lock as this won't get done in |
| 935 | // SetPublicState() if the process is hijacked. |
| 936 | if (hijack_listener) |
| 937 | m_public_run_lock.SetStopped(); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 938 | return state; |
| 939 | case eStateStopped: |
| 940 | if (Process::ProcessEventData::GetRestartedFromEvent(event_sp.get())) |
| 941 | continue; |
| 942 | else |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 943 | { |
| 944 | // We need to toggle the run lock as this won't get done in |
| 945 | // SetPublicState() if the process is hijacked. |
| 946 | if (hijack_listener) |
| 947 | m_public_run_lock.SetStopped(); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 948 | return state; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 949 | } |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 950 | default: |
| 951 | continue; |
| 952 | } |
| 953 | } |
| 954 | return state; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | |
| 958 | StateType |
| 959 | Process::WaitForState |
| 960 | ( |
| 961 | const TimeValue *timeout, |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 962 | const StateType *match_states, |
| 963 | const uint32_t num_match_states |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 964 | ) |
| 965 | { |
| 966 | EventSP event_sp; |
| 967 | uint32_t i; |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 968 | StateType state = GetState(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 969 | while (state != eStateInvalid) |
| 970 | { |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 971 | // If we are exited or detached, we won't ever get back to any |
| 972 | // other valid state... |
| 973 | if (state == eStateDetached || state == eStateExited) |
| 974 | return state; |
| 975 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 976 | state = WaitForStateChangedEvents (timeout, event_sp, NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 977 | |
| 978 | for (i=0; i<num_match_states; ++i) |
| 979 | { |
| 980 | if (match_states[i] == state) |
| 981 | return state; |
| 982 | } |
| 983 | } |
| 984 | return state; |
| 985 | } |
| 986 | |
Jim Ingham | 30f9b21 | 2010-10-11 23:53:14 +0000 | [diff] [blame] | 987 | bool |
| 988 | Process::HijackProcessEvents (Listener *listener) |
| 989 | { |
| 990 | if (listener != NULL) |
| 991 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 992 | return HijackBroadcaster(listener, eBroadcastBitStateChanged | eBroadcastBitInterrupt); |
Jim Ingham | 30f9b21 | 2010-10-11 23:53:14 +0000 | [diff] [blame] | 993 | } |
| 994 | else |
| 995 | return false; |
| 996 | } |
| 997 | |
| 998 | void |
| 999 | Process::RestoreProcessEvents () |
| 1000 | { |
| 1001 | RestoreBroadcaster(); |
| 1002 | } |
| 1003 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 1004 | bool |
| 1005 | Process::HijackPrivateProcessEvents (Listener *listener) |
| 1006 | { |
| 1007 | if (listener != NULL) |
| 1008 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 1009 | return m_private_state_broadcaster.HijackBroadcaster(listener, eBroadcastBitStateChanged | eBroadcastBitInterrupt); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 1010 | } |
| 1011 | else |
| 1012 | return false; |
| 1013 | } |
| 1014 | |
| 1015 | void |
| 1016 | Process::RestorePrivateProcessEvents () |
| 1017 | { |
| 1018 | m_private_state_broadcaster.RestoreBroadcaster(); |
| 1019 | } |
| 1020 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1021 | StateType |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1022 | Process::WaitForStateChangedEvents (const TimeValue *timeout, EventSP &event_sp, Listener *hijack_listener) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1023 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1024 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1025 | |
| 1026 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1027 | log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, |
| 1028 | static_cast<const void*>(timeout)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1029 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1030 | Listener *listener = hijack_listener; |
| 1031 | if (listener == NULL) |
| 1032 | listener = &m_listener; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1033 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1034 | StateType state = eStateInvalid; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1035 | if (listener->WaitForEventForBroadcasterWithType (timeout, |
| 1036 | this, |
| 1037 | eBroadcastBitStateChanged | eBroadcastBitInterrupt, |
| 1038 | event_sp)) |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 1039 | { |
| 1040 | if (event_sp && event_sp->GetType() == eBroadcastBitStateChanged) |
| 1041 | state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 1042 | else if (log) |
| 1043 | log->Printf ("Process::%s got no event or was interrupted.", __FUNCTION__); |
| 1044 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1045 | |
| 1046 | if (log) |
| 1047 | log->Printf ("Process::%s (timeout = %p, event_sp) => %s", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1048 | __FUNCTION__, static_cast<const void*>(timeout), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1049 | StateAsCString(state)); |
| 1050 | return state; |
| 1051 | } |
| 1052 | |
| 1053 | Event * |
| 1054 | Process::PeekAtStateChangedEvents () |
| 1055 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1056 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1057 | |
| 1058 | if (log) |
| 1059 | log->Printf ("Process::%s...", __FUNCTION__); |
| 1060 | |
| 1061 | Event *event_ptr; |
Greg Clayton | 3fcbed6 | 2010-10-19 03:25:40 +0000 | [diff] [blame] | 1062 | event_ptr = m_listener.PeekAtNextEventForBroadcasterWithType (this, |
| 1063 | eBroadcastBitStateChanged); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1064 | if (log) |
| 1065 | { |
| 1066 | if (event_ptr) |
| 1067 | { |
| 1068 | log->Printf ("Process::%s (event_ptr) => %s", |
| 1069 | __FUNCTION__, |
| 1070 | StateAsCString(ProcessEventData::GetStateFromEvent (event_ptr))); |
| 1071 | } |
| 1072 | else |
| 1073 | { |
| 1074 | log->Printf ("Process::%s no events found", |
| 1075 | __FUNCTION__); |
| 1076 | } |
| 1077 | } |
| 1078 | return event_ptr; |
| 1079 | } |
| 1080 | |
| 1081 | StateType |
| 1082 | Process::WaitForStateChangedEventsPrivate (const TimeValue *timeout, EventSP &event_sp) |
| 1083 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1084 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1085 | |
| 1086 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1087 | log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, |
| 1088 | static_cast<const void*>(timeout)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1089 | |
| 1090 | StateType state = eStateInvalid; |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1091 | if (m_private_state_listener.WaitForEventForBroadcasterWithType (timeout, |
| 1092 | &m_private_state_broadcaster, |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 1093 | eBroadcastBitStateChanged | eBroadcastBitInterrupt, |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1094 | event_sp)) |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 1095 | if (event_sp && event_sp->GetType() == eBroadcastBitStateChanged) |
| 1096 | state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1097 | |
| 1098 | // This is a bit of a hack, but when we wait here we could very well return |
| 1099 | // to the command-line, and that could disable the log, which would render the |
| 1100 | // log we got above invalid. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1101 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1102 | log->Printf ("Process::%s (timeout = %p, event_sp) => %s", |
| 1103 | __FUNCTION__, static_cast<const void *>(timeout), |
| 1104 | state == eStateInvalid ? "TIMEOUT" : StateAsCString(state)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1105 | return state; |
| 1106 | } |
| 1107 | |
| 1108 | bool |
| 1109 | Process::WaitForEventsPrivate (const TimeValue *timeout, EventSP &event_sp, bool control_only) |
| 1110 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1111 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1112 | |
| 1113 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1114 | log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, |
| 1115 | static_cast<const void*>(timeout)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1116 | |
| 1117 | if (control_only) |
| 1118 | return m_private_state_listener.WaitForEventForBroadcaster(timeout, &m_private_state_control_broadcaster, event_sp); |
| 1119 | else |
| 1120 | return m_private_state_listener.WaitForEvent(timeout, event_sp); |
| 1121 | } |
| 1122 | |
| 1123 | bool |
| 1124 | Process::IsRunning () const |
| 1125 | { |
| 1126 | return StateIsRunningState (m_public_state.GetValue()); |
| 1127 | } |
| 1128 | |
| 1129 | int |
| 1130 | Process::GetExitStatus () |
| 1131 | { |
| 1132 | if (m_public_state.GetValue() == eStateExited) |
| 1133 | return m_exit_status; |
| 1134 | return -1; |
| 1135 | } |
| 1136 | |
Greg Clayton | 85851dd | 2010-12-04 00:10:17 +0000 | [diff] [blame] | 1137 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1138 | const char * |
| 1139 | Process::GetExitDescription () |
| 1140 | { |
| 1141 | if (m_public_state.GetValue() == eStateExited && !m_exit_string.empty()) |
| 1142 | return m_exit_string.c_str(); |
| 1143 | return NULL; |
| 1144 | } |
| 1145 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1146 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1147 | Process::SetExitStatus (int status, const char *cstr) |
| 1148 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1149 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS)); |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 1150 | if (log) |
| 1151 | log->Printf("Process::SetExitStatus (status=%i (0x%8.8x), description=%s%s%s)", |
| 1152 | status, status, |
| 1153 | cstr ? "\"" : "", |
| 1154 | cstr ? cstr : "NULL", |
| 1155 | cstr ? "\"" : ""); |
| 1156 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1157 | // We were already in the exited state |
| 1158 | if (m_private_state.GetValue() == eStateExited) |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 1159 | { |
Greg Clayton | 385d603 | 2011-01-26 23:47:29 +0000 | [diff] [blame] | 1160 | if (log) |
| 1161 | log->Printf("Process::SetExitStatus () ignoring exit status because state was already set to eStateExited"); |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1162 | return false; |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 1163 | } |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1164 | |
| 1165 | m_exit_status = status; |
| 1166 | if (cstr) |
| 1167 | m_exit_string = cstr; |
| 1168 | else |
| 1169 | m_exit_string.clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1170 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1171 | DidExit (); |
Greg Clayton | 10177aa | 2010-12-08 05:08:21 +0000 | [diff] [blame] | 1172 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1173 | SetPrivateState (eStateExited); |
| 1174 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | // This static callback can be used to watch for local child processes on |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 1178 | // the current host. The child process exits, the process will be |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1179 | // found in the global target list (we want to be completely sure that the |
| 1180 | // lldb_private::Process doesn't go away before we can deliver the signal. |
| 1181 | bool |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 1182 | Process::SetProcessExitStatus (void *callback_baton, |
| 1183 | lldb::pid_t pid, |
| 1184 | bool exited, |
| 1185 | int signo, // Zero for no signal |
| 1186 | int exit_status // Exit value of process if signal is zero |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1187 | ) |
| 1188 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1189 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 1190 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1191 | log->Printf ("Process::SetProcessExitStatus (baton=%p, pid=%" PRIu64 ", exited=%i, signal=%i, exit_status=%i)\n", |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 1192 | callback_baton, |
| 1193 | pid, |
| 1194 | exited, |
| 1195 | signo, |
| 1196 | exit_status); |
| 1197 | |
| 1198 | if (exited) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1199 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1200 | TargetSP target_sp(Debugger::FindTargetWithProcessID (pid)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1201 | if (target_sp) |
| 1202 | { |
| 1203 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 1204 | if (process_sp) |
| 1205 | { |
| 1206 | const char *signal_cstr = NULL; |
| 1207 | if (signo) |
| 1208 | signal_cstr = process_sp->GetUnixSignals().GetSignalAsCString (signo); |
| 1209 | |
| 1210 | process_sp->SetExitStatus (exit_status, signal_cstr); |
| 1211 | } |
| 1212 | } |
| 1213 | return true; |
| 1214 | } |
| 1215 | return false; |
| 1216 | } |
| 1217 | |
| 1218 | |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1219 | void |
| 1220 | Process::UpdateThreadListIfNeeded () |
| 1221 | { |
| 1222 | const uint32_t stop_id = GetStopID(); |
| 1223 | if (m_thread_list.GetSize(false) == 0 || stop_id != m_thread_list.GetStopID()) |
| 1224 | { |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 1225 | const StateType state = GetPrivateState(); |
| 1226 | if (StateIsStoppedState (state, true)) |
| 1227 | { |
| 1228 | Mutex::Locker locker (m_thread_list.GetMutex ()); |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 1229 | // m_thread_list does have its own mutex, but we need to |
| 1230 | // hold onto the mutex between the call to UpdateThreadList(...) |
| 1231 | // and the os->UpdateThreadList(...) so it doesn't change on us |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1232 | ThreadList &old_thread_list = m_thread_list; |
| 1233 | ThreadList real_thread_list(this); |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 1234 | ThreadList new_thread_list(this); |
| 1235 | // Always update the thread list with the protocol specific |
Greg Clayton | 9fc1355 | 2012-04-10 00:18:59 +0000 | [diff] [blame] | 1236 | // thread list, but only update if "true" is returned |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1237 | if (UpdateThreadList (m_thread_list_real, real_thread_list)) |
Greg Clayton | 9fc1355 | 2012-04-10 00:18:59 +0000 | [diff] [blame] | 1238 | { |
Jim Ingham | 0943792 | 2013-03-01 20:04:25 +0000 | [diff] [blame] | 1239 | // Don't call into the OperatingSystem to update the thread list if we are shutting down, since |
| 1240 | // that may call back into the SBAPI's, requiring the API lock which is already held by whoever is |
| 1241 | // shutting us down, causing a deadlock. |
| 1242 | if (!m_destroy_in_process) |
| 1243 | { |
| 1244 | OperatingSystem *os = GetOperatingSystem (); |
| 1245 | if (os) |
Greg Clayton | b3ae876 | 2013-04-12 20:07:46 +0000 | [diff] [blame] | 1246 | { |
| 1247 | // Clear any old backing threads where memory threads might have been |
| 1248 | // backed by actual threads from the lldb_private::Process subclass |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1249 | size_t num_old_threads = old_thread_list.GetSize(false); |
Greg Clayton | b3ae876 | 2013-04-12 20:07:46 +0000 | [diff] [blame] | 1250 | for (size_t i=0; i<num_old_threads; ++i) |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1251 | old_thread_list.GetThreadAtIndex(i, false)->ClearBackingThread(); |
Greg Clayton | b3ae876 | 2013-04-12 20:07:46 +0000 | [diff] [blame] | 1252 | |
| 1253 | // Now let the OperatingSystem plug-in update the thread list |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1254 | os->UpdateThreadList (old_thread_list, // Old list full of threads created by OS plug-in |
| 1255 | real_thread_list, // The actual thread list full of threads created by each lldb_private::Process subclass |
| 1256 | new_thread_list); // The new thread list that we will show to the user that gets filled in |
Greg Clayton | b3ae876 | 2013-04-12 20:07:46 +0000 | [diff] [blame] | 1257 | } |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1258 | else |
| 1259 | { |
| 1260 | // No OS plug-in, the new thread list is the same as the real thread list |
| 1261 | new_thread_list = real_thread_list; |
| 1262 | } |
Jim Ingham | 0943792 | 2013-03-01 20:04:25 +0000 | [diff] [blame] | 1263 | } |
Jim Ingham | 02ff8e0 | 2013-06-22 00:55:02 +0000 | [diff] [blame] | 1264 | |
| 1265 | m_thread_list_real.Update(real_thread_list); |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1266 | m_thread_list.Update (new_thread_list); |
| 1267 | m_thread_list.SetStopID (stop_id); |
Jason Molenda | a6e9130 | 2013-11-19 05:44:41 +0000 | [diff] [blame] | 1268 | |
Jason Molenda | 4ff1326 | 2013-11-20 00:31:38 +0000 | [diff] [blame] | 1269 | if (GetLastNaturalStopID () != m_extended_thread_stop_id) |
| 1270 | { |
| 1271 | // Clear any extended threads that we may have accumulated previously |
| 1272 | m_extended_thread_list.Clear(); |
| 1273 | m_extended_thread_stop_id = GetLastNaturalStopID (); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 1274 | |
| 1275 | m_queue_list.Clear(); |
| 1276 | m_queue_list_stop_id = GetLastNaturalStopID (); |
Jason Molenda | 4ff1326 | 2013-11-20 00:31:38 +0000 | [diff] [blame] | 1277 | } |
Greg Clayton | 9fc1355 | 2012-04-10 00:18:59 +0000 | [diff] [blame] | 1278 | } |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 1279 | } |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1280 | } |
| 1281 | } |
| 1282 | |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 1283 | void |
| 1284 | Process::UpdateQueueListIfNeeded () |
| 1285 | { |
| 1286 | if (m_system_runtime_ap.get()) |
| 1287 | { |
| 1288 | if (m_queue_list.GetSize() == 0 || m_queue_list_stop_id != GetLastNaturalStopID()) |
| 1289 | { |
| 1290 | const StateType state = GetPrivateState(); |
| 1291 | if (StateIsStoppedState (state, true)) |
| 1292 | { |
| 1293 | m_system_runtime_ap->PopulateQueueList (m_queue_list); |
| 1294 | m_queue_list_stop_id = GetLastNaturalStopID(); |
| 1295 | } |
| 1296 | } |
| 1297 | } |
| 1298 | } |
| 1299 | |
Greg Clayton | a4d8747 | 2013-01-18 23:41:08 +0000 | [diff] [blame] | 1300 | ThreadSP |
| 1301 | Process::CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context) |
| 1302 | { |
| 1303 | OperatingSystem *os = GetOperatingSystem (); |
| 1304 | if (os) |
| 1305 | return os->CreateThread(tid, context); |
| 1306 | return ThreadSP(); |
| 1307 | } |
| 1308 | |
Han Ming Ong | c2c423e | 2013-01-08 22:10:01 +0000 | [diff] [blame] | 1309 | uint32_t |
| 1310 | Process::GetNextThreadIndexID (uint64_t thread_id) |
| 1311 | { |
| 1312 | return AssignIndexIDToThread(thread_id); |
| 1313 | } |
| 1314 | |
| 1315 | bool |
| 1316 | Process::HasAssignedIndexIDToThread(uint64_t thread_id) |
| 1317 | { |
| 1318 | std::map<uint64_t, uint32_t>::iterator iterator = m_thread_id_to_index_id_map.find(thread_id); |
| 1319 | if (iterator == m_thread_id_to_index_id_map.end()) |
| 1320 | { |
| 1321 | return false; |
| 1322 | } |
| 1323 | else |
| 1324 | { |
| 1325 | return true; |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | uint32_t |
| 1330 | Process::AssignIndexIDToThread(uint64_t thread_id) |
| 1331 | { |
| 1332 | uint32_t result = 0; |
| 1333 | std::map<uint64_t, uint32_t>::iterator iterator = m_thread_id_to_index_id_map.find(thread_id); |
| 1334 | if (iterator == m_thread_id_to_index_id_map.end()) |
| 1335 | { |
| 1336 | result = ++m_thread_index_id; |
| 1337 | m_thread_id_to_index_id_map[thread_id] = result; |
| 1338 | } |
| 1339 | else |
| 1340 | { |
| 1341 | result = iterator->second; |
| 1342 | } |
| 1343 | |
| 1344 | return result; |
| 1345 | } |
| 1346 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1347 | StateType |
| 1348 | Process::GetState() |
| 1349 | { |
| 1350 | // If any other threads access this we will need a mutex for it |
| 1351 | return m_public_state.GetValue (); |
| 1352 | } |
| 1353 | |
| 1354 | void |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 1355 | Process::SetPublicState (StateType new_state, bool restarted) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1356 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1357 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1358 | if (log) |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 1359 | log->Printf("Process::SetPublicState (state = %s, restarted = %i)", StateAsCString(new_state), restarted); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1360 | const StateType old_state = m_public_state.GetValue(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1361 | m_public_state.SetValue (new_state); |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 1362 | |
| 1363 | // On the transition from Run to Stopped, we unlock the writer end of the |
| 1364 | // run lock. The lock gets locked in Resume, which is the public API |
| 1365 | // to tell the program to run. |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1366 | if (!IsHijackedForEvent(eBroadcastBitStateChanged)) |
| 1367 | { |
Sean Callanan | 8b0737f | 2012-06-02 01:16:20 +0000 | [diff] [blame] | 1368 | if (new_state == eStateDetached) |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1369 | { |
Sean Callanan | 8b0737f | 2012-06-02 01:16:20 +0000 | [diff] [blame] | 1370 | if (log) |
| 1371 | log->Printf("Process::SetPublicState (%s) -- unlocking run lock for detach", StateAsCString(new_state)); |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 1372 | m_public_run_lock.SetStopped(); |
Sean Callanan | 8b0737f | 2012-06-02 01:16:20 +0000 | [diff] [blame] | 1373 | } |
| 1374 | else |
| 1375 | { |
| 1376 | const bool old_state_is_stopped = StateIsStoppedState(old_state, false); |
| 1377 | const bool new_state_is_stopped = StateIsStoppedState(new_state, false); |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 1378 | if ((old_state_is_stopped != new_state_is_stopped)) |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1379 | { |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 1380 | if (new_state_is_stopped && !restarted) |
Sean Callanan | 8b0737f | 2012-06-02 01:16:20 +0000 | [diff] [blame] | 1381 | { |
| 1382 | if (log) |
| 1383 | log->Printf("Process::SetPublicState (%s) -- unlocking run lock", StateAsCString(new_state)); |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 1384 | m_public_run_lock.SetStopped(); |
Sean Callanan | 8b0737f | 2012-06-02 01:16:20 +0000 | [diff] [blame] | 1385 | } |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1386 | } |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1387 | } |
| 1388 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 1391 | Error |
| 1392 | Process::Resume () |
| 1393 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1394 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 1395 | if (log) |
| 1396 | log->Printf("Process::Resume -- locking run lock"); |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 1397 | if (!m_public_run_lock.TrySetRunning()) |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 1398 | { |
| 1399 | Error error("Resume request failed - process still running."); |
| 1400 | if (log) |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 1401 | log->Printf ("Process::Resume: -- TrySetRunning failed, not resuming."); |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 1402 | return error; |
| 1403 | } |
| 1404 | return PrivateResume(); |
| 1405 | } |
| 1406 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1407 | StateType |
| 1408 | Process::GetPrivateState () |
| 1409 | { |
| 1410 | return m_private_state.GetValue(); |
| 1411 | } |
| 1412 | |
| 1413 | void |
| 1414 | Process::SetPrivateState (StateType new_state) |
| 1415 | { |
Greg Clayton | fb8b37a | 2014-07-14 23:09:29 +0000 | [diff] [blame] | 1416 | if (m_finalize_called) |
| 1417 | return; |
| 1418 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1419 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1420 | bool state_changed = false; |
| 1421 | |
| 1422 | if (log) |
| 1423 | log->Printf("Process::SetPrivateState (%s)", StateAsCString(new_state)); |
| 1424 | |
Andrew Kaylor | 29d6574 | 2013-05-10 17:19:04 +0000 | [diff] [blame] | 1425 | Mutex::Locker thread_locker(m_thread_list.GetMutex()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1426 | Mutex::Locker locker(m_private_state.GetMutex()); |
| 1427 | |
| 1428 | const StateType old_state = m_private_state.GetValueNoLock (); |
| 1429 | state_changed = old_state != new_state; |
Ed Maste | c29693f | 2013-07-02 16:35:47 +0000 | [diff] [blame] | 1430 | |
Greg Clayton | aa49c83 | 2013-05-03 22:25:56 +0000 | [diff] [blame] | 1431 | const bool old_state_is_stopped = StateIsStoppedState(old_state, false); |
| 1432 | const bool new_state_is_stopped = StateIsStoppedState(new_state, false); |
| 1433 | if (old_state_is_stopped != new_state_is_stopped) |
| 1434 | { |
| 1435 | if (new_state_is_stopped) |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 1436 | m_private_run_lock.SetStopped(); |
Greg Clayton | aa49c83 | 2013-05-03 22:25:56 +0000 | [diff] [blame] | 1437 | else |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 1438 | m_private_run_lock.SetRunning(); |
Greg Clayton | aa49c83 | 2013-05-03 22:25:56 +0000 | [diff] [blame] | 1439 | } |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 1440 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1441 | if (state_changed) |
| 1442 | { |
| 1443 | m_private_state.SetValueNoLock (new_state); |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 1444 | if (StateIsStoppedState(new_state, false)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1445 | { |
Andrew Kaylor | 29d6574 | 2013-05-10 17:19:04 +0000 | [diff] [blame] | 1446 | // Note, this currently assumes that all threads in the list |
| 1447 | // stop when the process stops. In the future we will want to |
| 1448 | // support a debugging model where some threads continue to run |
| 1449 | // while others are stopped. When that happens we will either need |
| 1450 | // a way for the thread list to identify which threads are stopping |
| 1451 | // or create a special thread list containing only threads which |
| 1452 | // actually stopped. |
| 1453 | // |
| 1454 | // The process plugin is responsible for managing the actual |
| 1455 | // behavior of the threads and should have stopped any threads |
| 1456 | // that are going to stop before we get here. |
| 1457 | m_thread_list.DidStop(); |
| 1458 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1459 | m_mod_id.BumpStopID(); |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 1460 | m_memory_cache.Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1461 | if (log) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1462 | log->Printf("Process::SetPrivateState (%s) stop_id = %u", StateAsCString(new_state), m_mod_id.GetStopID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1463 | } |
| 1464 | // Use our target to get a shared pointer to ourselves... |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 1465 | if (m_finalize_called && PrivateStateThreadIsValid() == false) |
| 1466 | BroadcastEvent (eBroadcastBitStateChanged, new ProcessEventData (shared_from_this(), new_state)); |
| 1467 | else |
| 1468 | m_private_state_broadcaster.BroadcastEvent (eBroadcastBitStateChanged, new ProcessEventData (shared_from_this(), new_state)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1469 | } |
| 1470 | else |
| 1471 | { |
| 1472 | if (log) |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 1473 | log->Printf("Process::SetPrivateState (%s) state didn't change. Ignoring...", StateAsCString(new_state)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1474 | } |
| 1475 | } |
| 1476 | |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 1477 | void |
| 1478 | Process::SetRunningUserExpression (bool on) |
| 1479 | { |
| 1480 | m_mod_id.SetRunningUserExpression (on); |
| 1481 | } |
| 1482 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1483 | addr_t |
| 1484 | Process::GetImageInfoAddress() |
| 1485 | { |
| 1486 | return LLDB_INVALID_ADDRESS; |
| 1487 | } |
| 1488 | |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1489 | //---------------------------------------------------------------------- |
| 1490 | // LoadImage |
| 1491 | // |
| 1492 | // This function provides a default implementation that works for most |
| 1493 | // unix variants. Any Process subclasses that need to do shared library |
| 1494 | // loading differently should override LoadImage and UnloadImage and |
| 1495 | // do what is needed. |
| 1496 | //---------------------------------------------------------------------- |
| 1497 | uint32_t |
| 1498 | Process::LoadImage (const FileSpec &image_spec, Error &error) |
| 1499 | { |
Greg Clayton | ac7a3db | 2012-04-18 00:05:19 +0000 | [diff] [blame] | 1500 | char path[PATH_MAX]; |
| 1501 | image_spec.GetPath(path, sizeof(path)); |
| 1502 | |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1503 | DynamicLoader *loader = GetDynamicLoader(); |
| 1504 | if (loader) |
| 1505 | { |
| 1506 | error = loader->CanLoadImage(); |
| 1507 | if (error.Fail()) |
| 1508 | return LLDB_INVALID_IMAGE_TOKEN; |
| 1509 | } |
| 1510 | |
| 1511 | if (error.Success()) |
| 1512 | { |
| 1513 | ThreadSP thread_sp(GetThreadList ().GetSelectedThread()); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1514 | |
| 1515 | if (thread_sp) |
| 1516 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1517 | StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex (0)); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1518 | |
| 1519 | if (frame_sp) |
| 1520 | { |
| 1521 | ExecutionContext exe_ctx; |
| 1522 | frame_sp->CalculateExecutionContext (exe_ctx); |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1523 | EvaluateExpressionOptions expr_options; |
| 1524 | expr_options.SetUnwindOnError(true); |
| 1525 | expr_options.SetIgnoreBreakpoints(true); |
| 1526 | expr_options.SetExecutionPolicy(eExecutionPolicyAlways); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1527 | StreamString expr; |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1528 | expr.Printf("dlopen (\"%s\", 2)", path); |
| 1529 | const char *prefix = "extern \"C\" void* dlopen (const char *path, int mode);\n"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 1530 | lldb::ValueObjectSP result_valobj_sp; |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1531 | Error expr_error; |
Greg Clayton | 26ab83d | 2012-10-31 20:49:04 +0000 | [diff] [blame] | 1532 | ClangUserExpression::Evaluate (exe_ctx, |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1533 | expr_options, |
Greg Clayton | 26ab83d | 2012-10-31 20:49:04 +0000 | [diff] [blame] | 1534 | expr.GetData(), |
| 1535 | prefix, |
| 1536 | result_valobj_sp, |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1537 | expr_error); |
| 1538 | if (expr_error.Success()) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1539 | { |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1540 | error = result_valobj_sp->GetError(); |
| 1541 | if (error.Success()) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1542 | { |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1543 | Scalar scalar; |
| 1544 | if (result_valobj_sp->ResolveValue (scalar)) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1545 | { |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1546 | addr_t image_ptr = scalar.ULongLong(LLDB_INVALID_ADDRESS); |
| 1547 | if (image_ptr != 0 && image_ptr != LLDB_INVALID_ADDRESS) |
| 1548 | { |
| 1549 | uint32_t image_token = m_image_tokens.size(); |
| 1550 | m_image_tokens.push_back (image_ptr); |
| 1551 | return image_token; |
| 1552 | } |
Jim Ingham | 3ac7cf3 | 2014-07-17 18:55:25 +0000 | [diff] [blame^] | 1553 | else if (image_ptr == 0) |
| 1554 | { |
| 1555 | prefix = "extern \"C\" const char *dlerror(void);\n"; |
| 1556 | expr.Clear(); |
| 1557 | expr.PutCString("dlerror()"); |
| 1558 | ClangUserExpression::Evaluate (exe_ctx, |
| 1559 | expr_options, |
| 1560 | expr.GetData(), |
| 1561 | prefix, |
| 1562 | result_valobj_sp, |
| 1563 | expr_error); |
| 1564 | if (result_valobj_sp && error.Success()) |
| 1565 | { |
| 1566 | if (result_valobj_sp->IsCStringContainer(true)) |
| 1567 | { |
| 1568 | lldb::DataBufferSP buf_sp (new DataBufferHeap()); |
| 1569 | size_t num_chars = result_valobj_sp->ReadPointedString (buf_sp, error); |
| 1570 | if (error.Success() && num_chars > 0) |
| 1571 | { |
| 1572 | error.Clear(); |
| 1573 | error.SetErrorStringWithFormat("dlopen failed: %s", buf_sp->GetBytes()); |
| 1574 | } |
| 1575 | } |
| 1576 | } |
| 1577 | } |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1578 | } |
| 1579 | } |
| 1580 | } |
Jim Ingham | 6c9ed91 | 2014-04-03 01:26:14 +0000 | [diff] [blame] | 1581 | else |
| 1582 | error = expr_error; |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1583 | } |
| 1584 | } |
| 1585 | } |
Greg Clayton | ac7a3db | 2012-04-18 00:05:19 +0000 | [diff] [blame] | 1586 | if (!error.AsCString()) |
| 1587 | error.SetErrorStringWithFormat("unable to load '%s'", path); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1588 | return LLDB_INVALID_IMAGE_TOKEN; |
| 1589 | } |
| 1590 | |
| 1591 | //---------------------------------------------------------------------- |
| 1592 | // UnloadImage |
| 1593 | // |
| 1594 | // This function provides a default implementation that works for most |
| 1595 | // unix variants. Any Process subclasses that need to do shared library |
| 1596 | // loading differently should override LoadImage and UnloadImage and |
| 1597 | // do what is needed. |
| 1598 | //---------------------------------------------------------------------- |
| 1599 | Error |
| 1600 | Process::UnloadImage (uint32_t image_token) |
| 1601 | { |
| 1602 | Error error; |
| 1603 | if (image_token < m_image_tokens.size()) |
| 1604 | { |
| 1605 | const addr_t image_addr = m_image_tokens[image_token]; |
| 1606 | if (image_addr == LLDB_INVALID_ADDRESS) |
| 1607 | { |
| 1608 | error.SetErrorString("image already unloaded"); |
| 1609 | } |
| 1610 | else |
| 1611 | { |
| 1612 | DynamicLoader *loader = GetDynamicLoader(); |
| 1613 | if (loader) |
| 1614 | error = loader->CanLoadImage(); |
| 1615 | |
| 1616 | if (error.Success()) |
| 1617 | { |
| 1618 | ThreadSP thread_sp(GetThreadList ().GetSelectedThread()); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1619 | |
| 1620 | if (thread_sp) |
| 1621 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1622 | StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex (0)); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1623 | |
| 1624 | if (frame_sp) |
| 1625 | { |
| 1626 | ExecutionContext exe_ctx; |
| 1627 | frame_sp->CalculateExecutionContext (exe_ctx); |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1628 | EvaluateExpressionOptions expr_options; |
| 1629 | expr_options.SetUnwindOnError(true); |
| 1630 | expr_options.SetIgnoreBreakpoints(true); |
| 1631 | expr_options.SetExecutionPolicy(eExecutionPolicyAlways); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1632 | StreamString expr; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1633 | expr.Printf("dlclose ((void *)0x%" PRIx64 ")", image_addr); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1634 | const char *prefix = "extern \"C\" int dlclose(void* handle);\n"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 1635 | lldb::ValueObjectSP result_valobj_sp; |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1636 | Error expr_error; |
Greg Clayton | 26ab83d | 2012-10-31 20:49:04 +0000 | [diff] [blame] | 1637 | ClangUserExpression::Evaluate (exe_ctx, |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1638 | expr_options, |
Greg Clayton | 26ab83d | 2012-10-31 20:49:04 +0000 | [diff] [blame] | 1639 | expr.GetData(), |
| 1640 | prefix, |
| 1641 | result_valobj_sp, |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1642 | expr_error); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1643 | if (result_valobj_sp->GetError().Success()) |
| 1644 | { |
| 1645 | Scalar scalar; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1646 | if (result_valobj_sp->ResolveValue (scalar)) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1647 | { |
| 1648 | if (scalar.UInt(1)) |
| 1649 | { |
| 1650 | error.SetErrorStringWithFormat("expression failed: \"%s\"", expr.GetData()); |
| 1651 | } |
| 1652 | else |
| 1653 | { |
| 1654 | m_image_tokens[image_token] = LLDB_INVALID_ADDRESS; |
| 1655 | } |
| 1656 | } |
| 1657 | } |
| 1658 | else |
| 1659 | { |
| 1660 | error = result_valobj_sp->GetError(); |
| 1661 | } |
| 1662 | } |
| 1663 | } |
| 1664 | } |
| 1665 | } |
| 1666 | } |
| 1667 | else |
| 1668 | { |
| 1669 | error.SetErrorString("invalid image token"); |
| 1670 | } |
| 1671 | return error; |
| 1672 | } |
| 1673 | |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 1674 | const lldb::ABISP & |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1675 | Process::GetABI() |
| 1676 | { |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 1677 | if (!m_abi_sp) |
| 1678 | m_abi_sp = ABI::FindPlugin(m_target.GetArchitecture()); |
| 1679 | return m_abi_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1682 | LanguageRuntime * |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1683 | Process::GetLanguageRuntime(lldb::LanguageType language, bool retry_if_null) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1684 | { |
| 1685 | LanguageRuntimeCollection::iterator pos; |
| 1686 | pos = m_language_runtimes.find (language); |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1687 | if (pos == m_language_runtimes.end() || (retry_if_null && !(*pos).second)) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1688 | { |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1689 | lldb::LanguageRuntimeSP runtime_sp(LanguageRuntime::FindPlugin(this, language)); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1690 | |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1691 | m_language_runtimes[language] = runtime_sp; |
| 1692 | return runtime_sp.get(); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1693 | } |
| 1694 | else |
| 1695 | return (*pos).second.get(); |
| 1696 | } |
| 1697 | |
| 1698 | CPPLanguageRuntime * |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1699 | Process::GetCPPLanguageRuntime (bool retry_if_null) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1700 | { |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1701 | LanguageRuntime *runtime = GetLanguageRuntime(eLanguageTypeC_plus_plus, retry_if_null); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1702 | if (runtime != NULL && runtime->GetLanguageType() == eLanguageTypeC_plus_plus) |
| 1703 | return static_cast<CPPLanguageRuntime *> (runtime); |
| 1704 | return NULL; |
| 1705 | } |
| 1706 | |
| 1707 | ObjCLanguageRuntime * |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1708 | Process::GetObjCLanguageRuntime (bool retry_if_null) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1709 | { |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1710 | LanguageRuntime *runtime = GetLanguageRuntime(eLanguageTypeObjC, retry_if_null); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1711 | if (runtime != NULL && runtime->GetLanguageType() == eLanguageTypeObjC) |
| 1712 | return static_cast<ObjCLanguageRuntime *> (runtime); |
| 1713 | return NULL; |
| 1714 | } |
| 1715 | |
Enrico Granata | fd4c84e | 2012-05-21 16:51:35 +0000 | [diff] [blame] | 1716 | bool |
| 1717 | Process::IsPossibleDynamicValue (ValueObject& in_value) |
| 1718 | { |
| 1719 | if (in_value.IsDynamic()) |
| 1720 | return false; |
| 1721 | LanguageType known_type = in_value.GetObjectRuntimeLanguage(); |
| 1722 | |
| 1723 | if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC) |
| 1724 | { |
| 1725 | LanguageRuntime *runtime = GetLanguageRuntime (known_type); |
| 1726 | return runtime ? runtime->CouldHaveDynamicValue(in_value) : false; |
| 1727 | } |
| 1728 | |
| 1729 | LanguageRuntime *cpp_runtime = GetLanguageRuntime (eLanguageTypeC_plus_plus); |
| 1730 | if (cpp_runtime && cpp_runtime->CouldHaveDynamicValue(in_value)) |
| 1731 | return true; |
| 1732 | |
| 1733 | LanguageRuntime *objc_runtime = GetLanguageRuntime (eLanguageTypeObjC); |
| 1734 | return objc_runtime ? objc_runtime->CouldHaveDynamicValue(in_value) : false; |
| 1735 | } |
| 1736 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1737 | BreakpointSiteList & |
| 1738 | Process::GetBreakpointSiteList() |
| 1739 | { |
| 1740 | return m_breakpoint_site_list; |
| 1741 | } |
| 1742 | |
| 1743 | const BreakpointSiteList & |
| 1744 | Process::GetBreakpointSiteList() const |
| 1745 | { |
| 1746 | return m_breakpoint_site_list; |
| 1747 | } |
| 1748 | |
| 1749 | |
| 1750 | void |
| 1751 | Process::DisableAllBreakpointSites () |
| 1752 | { |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 1753 | m_breakpoint_site_list.ForEach([this](BreakpointSite *bp_site) -> void { |
| 1754 | // bp_site->SetEnabled(true); |
| 1755 | DisableBreakpointSite(bp_site); |
| 1756 | }); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | Error |
| 1760 | Process::ClearBreakpointSiteByID (lldb::user_id_t break_id) |
| 1761 | { |
| 1762 | Error error (DisableBreakpointSiteByID (break_id)); |
| 1763 | |
| 1764 | if (error.Success()) |
| 1765 | m_breakpoint_site_list.Remove(break_id); |
| 1766 | |
| 1767 | return error; |
| 1768 | } |
| 1769 | |
| 1770 | Error |
| 1771 | Process::DisableBreakpointSiteByID (lldb::user_id_t break_id) |
| 1772 | { |
| 1773 | Error error; |
| 1774 | BreakpointSiteSP bp_site_sp = m_breakpoint_site_list.FindByID (break_id); |
| 1775 | if (bp_site_sp) |
| 1776 | { |
| 1777 | if (bp_site_sp->IsEnabled()) |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 1778 | error = DisableBreakpointSite (bp_site_sp.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1779 | } |
| 1780 | else |
| 1781 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1782 | error.SetErrorStringWithFormat("invalid breakpoint site ID: %" PRIu64, break_id); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | return error; |
| 1786 | } |
| 1787 | |
| 1788 | Error |
| 1789 | Process::EnableBreakpointSiteByID (lldb::user_id_t break_id) |
| 1790 | { |
| 1791 | Error error; |
| 1792 | BreakpointSiteSP bp_site_sp = m_breakpoint_site_list.FindByID (break_id); |
| 1793 | if (bp_site_sp) |
| 1794 | { |
| 1795 | if (!bp_site_sp->IsEnabled()) |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 1796 | error = EnableBreakpointSite (bp_site_sp.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1797 | } |
| 1798 | else |
| 1799 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1800 | error.SetErrorStringWithFormat("invalid breakpoint site ID: %" PRIu64, break_id); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1801 | } |
| 1802 | return error; |
| 1803 | } |
| 1804 | |
Stephen Wilson | 50bd94f | 2010-07-17 00:56:13 +0000 | [diff] [blame] | 1805 | lldb::break_id_t |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 1806 | Process::CreateBreakpointSite (const BreakpointLocationSP &owner, bool use_hardware) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1807 | { |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 1808 | addr_t load_addr = LLDB_INVALID_ADDRESS; |
| 1809 | |
| 1810 | bool show_error = true; |
| 1811 | switch (GetState()) |
| 1812 | { |
| 1813 | case eStateInvalid: |
| 1814 | case eStateUnloaded: |
| 1815 | case eStateConnected: |
| 1816 | case eStateAttaching: |
| 1817 | case eStateLaunching: |
| 1818 | case eStateDetached: |
| 1819 | case eStateExited: |
| 1820 | show_error = false; |
| 1821 | break; |
| 1822 | |
| 1823 | case eStateStopped: |
| 1824 | case eStateRunning: |
| 1825 | case eStateStepping: |
| 1826 | case eStateCrashed: |
| 1827 | case eStateSuspended: |
| 1828 | show_error = IsAlive(); |
| 1829 | break; |
| 1830 | } |
| 1831 | |
| 1832 | // Reset the IsIndirect flag here, in case the location changes from |
| 1833 | // pointing to a indirect symbol to a regular symbol. |
| 1834 | owner->SetIsIndirect (false); |
| 1835 | |
| 1836 | if (owner->ShouldResolveIndirectFunctions()) |
| 1837 | { |
| 1838 | Symbol *symbol = owner->GetAddress().CalculateSymbolContextSymbol(); |
| 1839 | if (symbol && symbol->IsIndirect()) |
| 1840 | { |
| 1841 | Error error; |
| 1842 | load_addr = ResolveIndirectFunction (&symbol->GetAddress(), error); |
| 1843 | if (!error.Success() && show_error) |
| 1844 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1845 | m_target.GetDebugger().GetErrorFile()->Printf ("warning: failed to resolve indirect function at 0x%" PRIx64 " for breakpoint %i.%i: %s\n", |
| 1846 | symbol->GetAddress().GetLoadAddress(&m_target), |
| 1847 | owner->GetBreakpoint().GetID(), |
| 1848 | owner->GetID(), |
| 1849 | error.AsCString() ? error.AsCString() : "unkown error"); |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 1850 | return LLDB_INVALID_BREAK_ID; |
| 1851 | } |
| 1852 | Address resolved_address(load_addr); |
| 1853 | load_addr = resolved_address.GetOpcodeLoadAddress (&m_target); |
| 1854 | owner->SetIsIndirect(true); |
| 1855 | } |
| 1856 | else |
| 1857 | load_addr = owner->GetAddress().GetOpcodeLoadAddress (&m_target); |
| 1858 | } |
| 1859 | else |
| 1860 | load_addr = owner->GetAddress().GetOpcodeLoadAddress (&m_target); |
| 1861 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1862 | if (load_addr != LLDB_INVALID_ADDRESS) |
| 1863 | { |
| 1864 | BreakpointSiteSP bp_site_sp; |
| 1865 | |
| 1866 | // Look up this breakpoint site. If it exists, then add this new owner, otherwise |
| 1867 | // create a new breakpoint site and add it. |
| 1868 | |
| 1869 | bp_site_sp = m_breakpoint_site_list.FindByAddress (load_addr); |
| 1870 | |
| 1871 | if (bp_site_sp) |
| 1872 | { |
| 1873 | bp_site_sp->AddOwner (owner); |
| 1874 | owner->SetBreakpointSite (bp_site_sp); |
| 1875 | return bp_site_sp->GetID(); |
| 1876 | } |
| 1877 | else |
| 1878 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1879 | bp_site_sp.reset (new BreakpointSite (&m_breakpoint_site_list, owner, load_addr, use_hardware)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1880 | if (bp_site_sp) |
| 1881 | { |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1882 | Error error = EnableBreakpointSite (bp_site_sp.get()); |
| 1883 | if (error.Success()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1884 | { |
| 1885 | owner->SetBreakpointSite (bp_site_sp); |
| 1886 | return m_breakpoint_site_list.Add (bp_site_sp); |
| 1887 | } |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1888 | else |
| 1889 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1890 | if (show_error) |
| 1891 | { |
| 1892 | // Report error for setting breakpoint... |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1893 | m_target.GetDebugger().GetErrorFile()->Printf ("warning: failed to set breakpoint site at 0x%" PRIx64 " for breakpoint %i.%i: %s\n", |
| 1894 | load_addr, |
| 1895 | owner->GetBreakpoint().GetID(), |
| 1896 | owner->GetID(), |
| 1897 | error.AsCString() ? error.AsCString() : "unkown error"); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1898 | } |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1899 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1900 | } |
| 1901 | } |
| 1902 | } |
| 1903 | // We failed to enable the breakpoint |
| 1904 | return LLDB_INVALID_BREAK_ID; |
| 1905 | |
| 1906 | } |
| 1907 | |
| 1908 | void |
| 1909 | Process::RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id, lldb::user_id_t owner_loc_id, BreakpointSiteSP &bp_site_sp) |
| 1910 | { |
| 1911 | uint32_t num_owners = bp_site_sp->RemoveOwner (owner_id, owner_loc_id); |
| 1912 | if (num_owners == 0) |
| 1913 | { |
Jim Ingham | f1ff3bb | 2013-04-06 00:16:39 +0000 | [diff] [blame] | 1914 | // Don't try to disable the site if we don't have a live process anymore. |
| 1915 | if (IsAlive()) |
| 1916 | DisableBreakpointSite (bp_site_sp.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1917 | m_breakpoint_site_list.RemoveByAddress(bp_site_sp->GetLoadAddress()); |
| 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | |
| 1922 | size_t |
| 1923 | Process::RemoveBreakpointOpcodesFromBuffer (addr_t bp_addr, size_t size, uint8_t *buf) const |
| 1924 | { |
| 1925 | size_t bytes_removed = 0; |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 1926 | BreakpointSiteList bp_sites_in_range; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1927 | |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 1928 | if (m_breakpoint_site_list.FindInRange (bp_addr, bp_addr + size, bp_sites_in_range)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1929 | { |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 1930 | bp_sites_in_range.ForEach([bp_addr, size, buf, &bytes_removed](BreakpointSite *bp_site) -> void { |
| 1931 | if (bp_site->GetType() == BreakpointSite::eSoftware) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1932 | { |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 1933 | addr_t intersect_addr; |
| 1934 | size_t intersect_size; |
| 1935 | size_t opcode_offset; |
| 1936 | if (bp_site->IntersectsRange(bp_addr, size, &intersect_addr, &intersect_size, &opcode_offset)) |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 1937 | { |
| 1938 | assert(bp_addr <= intersect_addr && intersect_addr < bp_addr + size); |
| 1939 | assert(bp_addr < intersect_addr + intersect_size && intersect_addr + intersect_size <= bp_addr + size); |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 1940 | assert(opcode_offset + intersect_size <= bp_site->GetByteSize()); |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 1941 | size_t buf_offset = intersect_addr - bp_addr; |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 1942 | ::memcpy(buf + buf_offset, bp_site->GetSavedOpcodeBytes() + opcode_offset, intersect_size); |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 1943 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1944 | } |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 1945 | }); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1946 | } |
| 1947 | return bytes_removed; |
| 1948 | } |
| 1949 | |
| 1950 | |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1951 | |
| 1952 | size_t |
| 1953 | Process::GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site) |
| 1954 | { |
| 1955 | PlatformSP platform_sp (m_target.GetPlatform()); |
| 1956 | if (platform_sp) |
| 1957 | return platform_sp->GetSoftwareBreakpointTrapOpcode (m_target, bp_site); |
| 1958 | return 0; |
| 1959 | } |
| 1960 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1961 | Error |
| 1962 | Process::EnableSoftwareBreakpoint (BreakpointSite *bp_site) |
| 1963 | { |
| 1964 | Error error; |
| 1965 | assert (bp_site != NULL); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1966 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1967 | const addr_t bp_addr = bp_site->GetLoadAddress(); |
| 1968 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1969 | log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64, bp_site->GetID(), (uint64_t)bp_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1970 | if (bp_site->IsEnabled()) |
| 1971 | { |
| 1972 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1973 | log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64 " -- already enabled", bp_site->GetID(), (uint64_t)bp_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1974 | return error; |
| 1975 | } |
| 1976 | |
| 1977 | if (bp_addr == LLDB_INVALID_ADDRESS) |
| 1978 | { |
| 1979 | error.SetErrorString("BreakpointSite contains an invalid load address."); |
| 1980 | return error; |
| 1981 | } |
| 1982 | // Ask the lldb::Process subclass to fill in the correct software breakpoint |
| 1983 | // trap for the breakpoint site |
| 1984 | const size_t bp_opcode_size = GetSoftwareBreakpointTrapOpcode(bp_site); |
| 1985 | |
| 1986 | if (bp_opcode_size == 0) |
| 1987 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1988 | error.SetErrorStringWithFormat ("Process::GetSoftwareBreakpointTrapOpcode() returned zero, unable to get breakpoint trap for address 0x%" PRIx64, bp_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1989 | } |
| 1990 | else |
| 1991 | { |
| 1992 | const uint8_t * const bp_opcode_bytes = bp_site->GetTrapOpcodeBytes(); |
| 1993 | |
| 1994 | if (bp_opcode_bytes == NULL) |
| 1995 | { |
| 1996 | error.SetErrorString ("BreakpointSite doesn't contain a valid breakpoint trap opcode."); |
| 1997 | return error; |
| 1998 | } |
| 1999 | |
| 2000 | // Save the original opcode by reading it |
| 2001 | if (DoReadMemory(bp_addr, bp_site->GetSavedOpcodeBytes(), bp_opcode_size, error) == bp_opcode_size) |
| 2002 | { |
| 2003 | // Write a software breakpoint in place of the original opcode |
| 2004 | if (DoWriteMemory(bp_addr, bp_opcode_bytes, bp_opcode_size, error) == bp_opcode_size) |
| 2005 | { |
| 2006 | uint8_t verify_bp_opcode_bytes[64]; |
| 2007 | if (DoReadMemory(bp_addr, verify_bp_opcode_bytes, bp_opcode_size, error) == bp_opcode_size) |
| 2008 | { |
| 2009 | if (::memcmp(bp_opcode_bytes, verify_bp_opcode_bytes, bp_opcode_size) == 0) |
| 2010 | { |
| 2011 | bp_site->SetEnabled(true); |
| 2012 | bp_site->SetType (BreakpointSite::eSoftware); |
| 2013 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2014 | log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64 " -- SUCCESS", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2015 | bp_site->GetID(), |
| 2016 | (uint64_t)bp_addr); |
| 2017 | } |
| 2018 | else |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 2019 | error.SetErrorString("failed to verify the breakpoint trap in memory."); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2020 | } |
| 2021 | else |
| 2022 | error.SetErrorString("Unable to read memory to verify breakpoint trap."); |
| 2023 | } |
| 2024 | else |
| 2025 | error.SetErrorString("Unable to write breakpoint trap to memory."); |
| 2026 | } |
| 2027 | else |
| 2028 | error.SetErrorString("Unable to read memory at breakpoint address."); |
| 2029 | } |
Stephen Wilson | 78a4feb | 2011-01-12 04:20:03 +0000 | [diff] [blame] | 2030 | if (log && error.Fail()) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2031 | log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64 " -- FAILED: %s", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2032 | bp_site->GetID(), |
| 2033 | (uint64_t)bp_addr, |
| 2034 | error.AsCString()); |
| 2035 | return error; |
| 2036 | } |
| 2037 | |
| 2038 | Error |
| 2039 | Process::DisableSoftwareBreakpoint (BreakpointSite *bp_site) |
| 2040 | { |
| 2041 | Error error; |
| 2042 | assert (bp_site != NULL); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2043 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2044 | addr_t bp_addr = bp_site->GetLoadAddress(); |
| 2045 | lldb::user_id_t breakID = bp_site->GetID(); |
| 2046 | if (log) |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 2047 | log->Printf ("Process::DisableSoftwareBreakpoint (breakID = %" PRIu64 ") addr = 0x%" PRIx64, breakID, (uint64_t)bp_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2048 | |
| 2049 | if (bp_site->IsHardware()) |
| 2050 | { |
| 2051 | error.SetErrorString("Breakpoint site is a hardware breakpoint."); |
| 2052 | } |
| 2053 | else if (bp_site->IsEnabled()) |
| 2054 | { |
| 2055 | const size_t break_op_size = bp_site->GetByteSize(); |
| 2056 | const uint8_t * const break_op = bp_site->GetTrapOpcodeBytes(); |
| 2057 | if (break_op_size > 0) |
| 2058 | { |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 2059 | // Clear a software breakpoint instruction |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 2060 | uint8_t curr_break_op[8]; |
Stephen Wilson | 4ab4768 | 2010-07-20 18:41:11 +0000 | [diff] [blame] | 2061 | assert (break_op_size <= sizeof(curr_break_op)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2062 | bool break_op_found = false; |
| 2063 | |
| 2064 | // Read the breakpoint opcode |
| 2065 | if (DoReadMemory (bp_addr, curr_break_op, break_op_size, error) == break_op_size) |
| 2066 | { |
| 2067 | bool verify = false; |
| 2068 | // Make sure we have the a breakpoint opcode exists at this address |
| 2069 | if (::memcmp (curr_break_op, break_op, break_op_size) == 0) |
| 2070 | { |
| 2071 | break_op_found = true; |
| 2072 | // We found a valid breakpoint opcode at this address, now restore |
| 2073 | // the saved opcode. |
| 2074 | if (DoWriteMemory (bp_addr, bp_site->GetSavedOpcodeBytes(), break_op_size, error) == break_op_size) |
| 2075 | { |
| 2076 | verify = true; |
| 2077 | } |
| 2078 | else |
| 2079 | error.SetErrorString("Memory write failed when restoring original opcode."); |
| 2080 | } |
| 2081 | else |
| 2082 | { |
| 2083 | error.SetErrorString("Original breakpoint trap is no longer in memory."); |
| 2084 | // Set verify to true and so we can check if the original opcode has already been restored |
| 2085 | verify = true; |
| 2086 | } |
| 2087 | |
| 2088 | if (verify) |
| 2089 | { |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 2090 | uint8_t verify_opcode[8]; |
Stephen Wilson | 4ab4768 | 2010-07-20 18:41:11 +0000 | [diff] [blame] | 2091 | assert (break_op_size < sizeof(verify_opcode)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2092 | // Verify that our original opcode made it back to the inferior |
| 2093 | if (DoReadMemory (bp_addr, verify_opcode, break_op_size, error) == break_op_size) |
| 2094 | { |
| 2095 | // compare the memory we just read with the original opcode |
| 2096 | if (::memcmp (bp_site->GetSavedOpcodeBytes(), verify_opcode, break_op_size) == 0) |
| 2097 | { |
| 2098 | // SUCCESS |
| 2099 | bp_site->SetEnabled(false); |
| 2100 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2101 | log->Printf ("Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64 " -- SUCCESS", bp_site->GetID(), (uint64_t)bp_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2102 | return error; |
| 2103 | } |
| 2104 | else |
| 2105 | { |
| 2106 | if (break_op_found) |
| 2107 | error.SetErrorString("Failed to restore original opcode."); |
| 2108 | } |
| 2109 | } |
| 2110 | else |
| 2111 | error.SetErrorString("Failed to read memory to verify that breakpoint trap was restored."); |
| 2112 | } |
| 2113 | } |
| 2114 | else |
| 2115 | error.SetErrorString("Unable to read memory that should contain the breakpoint trap."); |
| 2116 | } |
| 2117 | } |
| 2118 | else |
| 2119 | { |
| 2120 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2121 | log->Printf ("Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64 " -- already disabled", bp_site->GetID(), (uint64_t)bp_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2122 | return error; |
| 2123 | } |
| 2124 | |
| 2125 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2126 | log->Printf ("Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64 " -- FAILED: %s", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2127 | bp_site->GetID(), |
| 2128 | (uint64_t)bp_addr, |
| 2129 | error.AsCString()); |
| 2130 | return error; |
| 2131 | |
| 2132 | } |
| 2133 | |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2134 | // Uncomment to verify memory caching works after making changes to caching code |
| 2135 | //#define VERIFY_MEMORY_READS |
| 2136 | |
Sean Callanan | 64c0cf2 | 2012-06-07 22:26:42 +0000 | [diff] [blame] | 2137 | size_t |
| 2138 | Process::ReadMemory (addr_t addr, void *buf, size_t size, Error &error) |
| 2139 | { |
Jason Molenda | a7b5afa | 2013-11-15 00:17:32 +0000 | [diff] [blame] | 2140 | error.Clear(); |
Sean Callanan | 64c0cf2 | 2012-06-07 22:26:42 +0000 | [diff] [blame] | 2141 | if (!GetDisableMemoryCache()) |
| 2142 | { |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2143 | #if defined (VERIFY_MEMORY_READS) |
Sean Callanan | 64c0cf2 | 2012-06-07 22:26:42 +0000 | [diff] [blame] | 2144 | // Memory caching is enabled, with debug verification |
| 2145 | |
| 2146 | if (buf && size) |
| 2147 | { |
| 2148 | // Uncomment the line below to make sure memory caching is working. |
| 2149 | // I ran this through the test suite and got no assertions, so I am |
| 2150 | // pretty confident this is working well. If any changes are made to |
| 2151 | // memory caching, uncomment the line below and test your changes! |
| 2152 | |
| 2153 | // Verify all memory reads by using the cache first, then redundantly |
| 2154 | // reading the same memory from the inferior and comparing to make sure |
| 2155 | // everything is exactly the same. |
| 2156 | std::string verify_buf (size, '\0'); |
| 2157 | assert (verify_buf.size() == size); |
| 2158 | const size_t cache_bytes_read = m_memory_cache.Read (this, addr, buf, size, error); |
| 2159 | Error verify_error; |
| 2160 | const size_t verify_bytes_read = ReadMemoryFromInferior (addr, const_cast<char *>(verify_buf.data()), verify_buf.size(), verify_error); |
| 2161 | assert (cache_bytes_read == verify_bytes_read); |
| 2162 | assert (memcmp(buf, verify_buf.data(), verify_buf.size()) == 0); |
| 2163 | assert (verify_error.Success() == error.Success()); |
| 2164 | return cache_bytes_read; |
| 2165 | } |
| 2166 | return 0; |
| 2167 | #else // !defined(VERIFY_MEMORY_READS) |
| 2168 | // Memory caching is enabled, without debug verification |
| 2169 | |
| 2170 | return m_memory_cache.Read (addr, buf, size, error); |
| 2171 | #endif // defined (VERIFY_MEMORY_READS) |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2172 | } |
Sean Callanan | 64c0cf2 | 2012-06-07 22:26:42 +0000 | [diff] [blame] | 2173 | else |
| 2174 | { |
| 2175 | // Memory caching is disabled |
| 2176 | |
| 2177 | return ReadMemoryFromInferior (addr, buf, size, error); |
| 2178 | } |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2179 | } |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2180 | |
Greg Clayton | 4c82d42 | 2012-05-18 23:20:01 +0000 | [diff] [blame] | 2181 | size_t |
| 2182 | Process::ReadCStringFromMemory (addr_t addr, std::string &out_str, Error &error) |
| 2183 | { |
Greg Clayton | de87c0f | 2012-05-19 00:18:00 +0000 | [diff] [blame] | 2184 | char buf[256]; |
Greg Clayton | 4c82d42 | 2012-05-18 23:20:01 +0000 | [diff] [blame] | 2185 | out_str.clear(); |
| 2186 | addr_t curr_addr = addr; |
| 2187 | while (1) |
| 2188 | { |
| 2189 | size_t length = ReadCStringFromMemory (curr_addr, buf, sizeof(buf), error); |
| 2190 | if (length == 0) |
| 2191 | break; |
| 2192 | out_str.append(buf, length); |
| 2193 | // If we got "length - 1" bytes, we didn't get the whole C string, we |
| 2194 | // need to read some more characters |
| 2195 | if (length == sizeof(buf) - 1) |
| 2196 | curr_addr += length; |
| 2197 | else |
| 2198 | break; |
| 2199 | } |
| 2200 | return out_str.size(); |
| 2201 | } |
| 2202 | |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2203 | |
| 2204 | size_t |
Ashok Thirumurthi | 6ac9d13 | 2013-04-19 15:58:38 +0000 | [diff] [blame] | 2205 | Process::ReadStringFromMemory (addr_t addr, char *dst, size_t max_bytes, Error &error, |
| 2206 | size_t type_width) |
| 2207 | { |
| 2208 | size_t total_bytes_read = 0; |
| 2209 | if (dst && max_bytes && type_width && max_bytes >= type_width) |
| 2210 | { |
| 2211 | // Ensure a null terminator independent of the number of bytes that is read. |
| 2212 | memset (dst, 0, max_bytes); |
| 2213 | size_t bytes_left = max_bytes - type_width; |
| 2214 | |
| 2215 | const char terminator[4] = {'\0', '\0', '\0', '\0'}; |
| 2216 | assert(sizeof(terminator) >= type_width && |
| 2217 | "Attempting to validate a string with more than 4 bytes per character!"); |
| 2218 | |
| 2219 | addr_t curr_addr = addr; |
| 2220 | const size_t cache_line_size = m_memory_cache.GetMemoryCacheLineSize(); |
| 2221 | char *curr_dst = dst; |
| 2222 | |
| 2223 | error.Clear(); |
| 2224 | while (bytes_left > 0 && error.Success()) |
| 2225 | { |
| 2226 | addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size); |
| 2227 | addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left); |
| 2228 | size_t bytes_read = ReadMemory (curr_addr, curr_dst, bytes_to_read, error); |
| 2229 | |
| 2230 | if (bytes_read == 0) |
| 2231 | break; |
| 2232 | |
| 2233 | // Search for a null terminator of correct size and alignment in bytes_read |
| 2234 | size_t aligned_start = total_bytes_read - total_bytes_read % type_width; |
| 2235 | for (size_t i = aligned_start; i + type_width <= total_bytes_read + bytes_read; i += type_width) |
| 2236 | if (::strncmp(&dst[i], terminator, type_width) == 0) |
| 2237 | { |
| 2238 | error.Clear(); |
| 2239 | return i; |
| 2240 | } |
| 2241 | |
| 2242 | total_bytes_read += bytes_read; |
| 2243 | curr_dst += bytes_read; |
| 2244 | curr_addr += bytes_read; |
| 2245 | bytes_left -= bytes_read; |
| 2246 | } |
| 2247 | } |
| 2248 | else |
| 2249 | { |
| 2250 | if (max_bytes) |
| 2251 | error.SetErrorString("invalid arguments"); |
| 2252 | } |
| 2253 | return total_bytes_read; |
| 2254 | } |
| 2255 | |
| 2256 | // Deprecated in favor of ReadStringFromMemory which has wchar support and correct code to find |
| 2257 | // null terminators. |
| 2258 | size_t |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 2259 | Process::ReadCStringFromMemory (addr_t addr, char *dst, size_t dst_max_len, Error &result_error) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2260 | { |
| 2261 | size_t total_cstr_len = 0; |
| 2262 | if (dst && dst_max_len) |
| 2263 | { |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 2264 | result_error.Clear(); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2265 | // NULL out everything just to be safe |
| 2266 | memset (dst, 0, dst_max_len); |
| 2267 | Error error; |
| 2268 | addr_t curr_addr = addr; |
| 2269 | const size_t cache_line_size = m_memory_cache.GetMemoryCacheLineSize(); |
| 2270 | size_t bytes_left = dst_max_len - 1; |
| 2271 | char *curr_dst = dst; |
| 2272 | |
| 2273 | while (bytes_left > 0) |
| 2274 | { |
| 2275 | addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size); |
| 2276 | addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left); |
| 2277 | size_t bytes_read = ReadMemory (curr_addr, curr_dst, bytes_to_read, error); |
| 2278 | |
| 2279 | if (bytes_read == 0) |
| 2280 | { |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 2281 | result_error = error; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2282 | dst[total_cstr_len] = '\0'; |
| 2283 | break; |
| 2284 | } |
| 2285 | const size_t len = strlen(curr_dst); |
| 2286 | |
| 2287 | total_cstr_len += len; |
| 2288 | |
| 2289 | if (len < bytes_to_read) |
| 2290 | break; |
| 2291 | |
| 2292 | curr_dst += bytes_read; |
| 2293 | curr_addr += bytes_read; |
| 2294 | bytes_left -= bytes_read; |
| 2295 | } |
| 2296 | } |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 2297 | else |
| 2298 | { |
| 2299 | if (dst == NULL) |
| 2300 | result_error.SetErrorString("invalid arguments"); |
| 2301 | else |
| 2302 | result_error.Clear(); |
| 2303 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2304 | return total_cstr_len; |
| 2305 | } |
| 2306 | |
| 2307 | size_t |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2308 | Process::ReadMemoryFromInferior (addr_t addr, void *buf, size_t size, Error &error) |
| 2309 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2310 | if (buf == NULL || size == 0) |
| 2311 | return 0; |
| 2312 | |
| 2313 | size_t bytes_read = 0; |
| 2314 | uint8_t *bytes = (uint8_t *)buf; |
| 2315 | |
| 2316 | while (bytes_read < size) |
| 2317 | { |
| 2318 | const size_t curr_size = size - bytes_read; |
| 2319 | const size_t curr_bytes_read = DoReadMemory (addr + bytes_read, |
| 2320 | bytes + bytes_read, |
| 2321 | curr_size, |
| 2322 | error); |
| 2323 | bytes_read += curr_bytes_read; |
| 2324 | if (curr_bytes_read == curr_size || curr_bytes_read == 0) |
| 2325 | break; |
| 2326 | } |
| 2327 | |
| 2328 | // Replace any software breakpoint opcodes that fall into this range back |
| 2329 | // into "buf" before we return |
| 2330 | if (bytes_read > 0) |
| 2331 | RemoveBreakpointOpcodesFromBuffer (addr, bytes_read, (uint8_t *)buf); |
| 2332 | return bytes_read; |
| 2333 | } |
| 2334 | |
Greg Clayton | 58a4c46 | 2010-12-16 20:01:20 +0000 | [diff] [blame] | 2335 | uint64_t |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2336 | Process::ReadUnsignedIntegerFromMemory (lldb::addr_t vm_addr, size_t integer_byte_size, uint64_t fail_value, Error &error) |
Greg Clayton | 58a4c46 | 2010-12-16 20:01:20 +0000 | [diff] [blame] | 2337 | { |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2338 | Scalar scalar; |
| 2339 | if (ReadScalarIntegerFromMemory(vm_addr, integer_byte_size, false, scalar, error)) |
| 2340 | return scalar.ULongLong(fail_value); |
| 2341 | return fail_value; |
| 2342 | } |
| 2343 | |
| 2344 | addr_t |
| 2345 | Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error) |
| 2346 | { |
| 2347 | Scalar scalar; |
| 2348 | if (ReadScalarIntegerFromMemory(vm_addr, GetAddressByteSize(), false, scalar, error)) |
| 2349 | return scalar.ULongLong(LLDB_INVALID_ADDRESS); |
| 2350 | return LLDB_INVALID_ADDRESS; |
| 2351 | } |
| 2352 | |
| 2353 | |
| 2354 | bool |
| 2355 | Process::WritePointerToMemory (lldb::addr_t vm_addr, |
| 2356 | lldb::addr_t ptr_value, |
| 2357 | Error &error) |
| 2358 | { |
| 2359 | Scalar scalar; |
| 2360 | const uint32_t addr_byte_size = GetAddressByteSize(); |
| 2361 | if (addr_byte_size <= 4) |
| 2362 | scalar = (uint32_t)ptr_value; |
Greg Clayton | 58a4c46 | 2010-12-16 20:01:20 +0000 | [diff] [blame] | 2363 | else |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2364 | scalar = ptr_value; |
| 2365 | return WriteScalarToMemory(vm_addr, scalar, addr_byte_size, error) == addr_byte_size; |
Greg Clayton | 58a4c46 | 2010-12-16 20:01:20 +0000 | [diff] [blame] | 2366 | } |
| 2367 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2368 | size_t |
| 2369 | Process::WriteMemoryPrivate (addr_t addr, const void *buf, size_t size, Error &error) |
| 2370 | { |
| 2371 | size_t bytes_written = 0; |
| 2372 | const uint8_t *bytes = (const uint8_t *)buf; |
| 2373 | |
| 2374 | while (bytes_written < size) |
| 2375 | { |
| 2376 | const size_t curr_size = size - bytes_written; |
| 2377 | const size_t curr_bytes_written = DoWriteMemory (addr + bytes_written, |
| 2378 | bytes + bytes_written, |
| 2379 | curr_size, |
| 2380 | error); |
| 2381 | bytes_written += curr_bytes_written; |
| 2382 | if (curr_bytes_written == curr_size || curr_bytes_written == 0) |
| 2383 | break; |
| 2384 | } |
| 2385 | return bytes_written; |
| 2386 | } |
| 2387 | |
| 2388 | size_t |
| 2389 | Process::WriteMemory (addr_t addr, const void *buf, size_t size, Error &error) |
| 2390 | { |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2391 | #if defined (ENABLE_MEMORY_CACHING) |
| 2392 | m_memory_cache.Flush (addr, size); |
| 2393 | #endif |
| 2394 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2395 | if (buf == NULL || size == 0) |
| 2396 | return 0; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2397 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 2398 | m_mod_id.BumpMemoryID(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2399 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2400 | // We need to write any data that would go where any current software traps |
| 2401 | // (enabled software breakpoints) any software traps (breakpoints) that we |
| 2402 | // may have placed in our tasks memory. |
| 2403 | |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2404 | BreakpointSiteList bp_sites_in_range; |
| 2405 | |
| 2406 | if (m_breakpoint_site_list.FindInRange (addr, addr + size, bp_sites_in_range)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2407 | { |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2408 | // No breakpoint sites overlap |
| 2409 | if (bp_sites_in_range.IsEmpty()) |
| 2410 | return WriteMemoryPrivate (addr, buf, size, error); |
| 2411 | else |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2412 | { |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2413 | const uint8_t *ubuf = (const uint8_t *)buf; |
| 2414 | uint64_t bytes_written = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2415 | |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2416 | bp_sites_in_range.ForEach([this, addr, size, &bytes_written, &ubuf, &error](BreakpointSite *bp) -> void { |
| 2417 | |
| 2418 | if (error.Success()) |
| 2419 | { |
| 2420 | addr_t intersect_addr; |
| 2421 | size_t intersect_size; |
| 2422 | size_t opcode_offset; |
| 2423 | const bool intersects = bp->IntersectsRange(addr, size, &intersect_addr, &intersect_size, &opcode_offset); |
| 2424 | assert(intersects); |
| 2425 | assert(addr <= intersect_addr && intersect_addr < addr + size); |
| 2426 | assert(addr < intersect_addr + intersect_size && intersect_addr + intersect_size <= addr + size); |
| 2427 | assert(opcode_offset + intersect_size <= bp->GetByteSize()); |
| 2428 | |
| 2429 | // Check for bytes before this breakpoint |
| 2430 | const addr_t curr_addr = addr + bytes_written; |
| 2431 | if (intersect_addr > curr_addr) |
| 2432 | { |
| 2433 | // There are some bytes before this breakpoint that we need to |
| 2434 | // just write to memory |
| 2435 | size_t curr_size = intersect_addr - curr_addr; |
| 2436 | size_t curr_bytes_written = WriteMemoryPrivate (curr_addr, |
| 2437 | ubuf + bytes_written, |
| 2438 | curr_size, |
| 2439 | error); |
| 2440 | bytes_written += curr_bytes_written; |
| 2441 | if (curr_bytes_written != curr_size) |
| 2442 | { |
| 2443 | // We weren't able to write all of the requested bytes, we |
| 2444 | // are done looping and will return the number of bytes that |
| 2445 | // we have written so far. |
| 2446 | if (error.Success()) |
| 2447 | error.SetErrorToGenericError(); |
| 2448 | } |
| 2449 | } |
| 2450 | // Now write any bytes that would cover up any software breakpoints |
| 2451 | // directly into the breakpoint opcode buffer |
| 2452 | ::memcpy(bp->GetSavedOpcodeBytes() + opcode_offset, ubuf + bytes_written, intersect_size); |
| 2453 | bytes_written += intersect_size; |
| 2454 | } |
| 2455 | }); |
| 2456 | |
| 2457 | if (bytes_written < size) |
| 2458 | bytes_written += WriteMemoryPrivate (addr + bytes_written, |
| 2459 | ubuf + bytes_written, |
| 2460 | size - bytes_written, |
| 2461 | error); |
| 2462 | } |
| 2463 | } |
| 2464 | else |
| 2465 | { |
| 2466 | return WriteMemoryPrivate (addr, buf, size, error); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | // Write any remaining bytes after the last breakpoint if we have any left |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2470 | return 0; //bytes_written; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2471 | } |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2472 | |
| 2473 | size_t |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2474 | Process::WriteScalarToMemory (addr_t addr, const Scalar &scalar, size_t byte_size, Error &error) |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2475 | { |
| 2476 | if (byte_size == UINT32_MAX) |
| 2477 | byte_size = scalar.GetByteSize(); |
| 2478 | if (byte_size > 0) |
| 2479 | { |
| 2480 | uint8_t buf[32]; |
| 2481 | const size_t mem_size = scalar.GetAsMemoryData (buf, byte_size, GetByteOrder(), error); |
| 2482 | if (mem_size > 0) |
| 2483 | return WriteMemory(addr, buf, mem_size, error); |
| 2484 | else |
| 2485 | error.SetErrorString ("failed to get scalar as memory data"); |
| 2486 | } |
| 2487 | else |
| 2488 | { |
| 2489 | error.SetErrorString ("invalid scalar value"); |
| 2490 | } |
| 2491 | return 0; |
| 2492 | } |
| 2493 | |
| 2494 | size_t |
| 2495 | Process::ReadScalarIntegerFromMemory (addr_t addr, |
| 2496 | uint32_t byte_size, |
| 2497 | bool is_signed, |
| 2498 | Scalar &scalar, |
| 2499 | Error &error) |
| 2500 | { |
Greg Clayton | 7060f89 | 2013-05-01 23:41:30 +0000 | [diff] [blame] | 2501 | uint64_t uval = 0; |
| 2502 | if (byte_size == 0) |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2503 | { |
Greg Clayton | 7060f89 | 2013-05-01 23:41:30 +0000 | [diff] [blame] | 2504 | error.SetErrorString ("byte size is zero"); |
| 2505 | } |
| 2506 | else if (byte_size & (byte_size - 1)) |
| 2507 | { |
| 2508 | error.SetErrorStringWithFormat ("byte size %u is not a power of 2", byte_size); |
| 2509 | } |
| 2510 | else if (byte_size <= sizeof(uval)) |
| 2511 | { |
| 2512 | const size_t bytes_read = ReadMemory (addr, &uval, byte_size, error); |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2513 | if (bytes_read == byte_size) |
| 2514 | { |
| 2515 | DataExtractor data (&uval, sizeof(uval), GetByteOrder(), GetAddressByteSize()); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2516 | lldb::offset_t offset = 0; |
Greg Clayton | 7060f89 | 2013-05-01 23:41:30 +0000 | [diff] [blame] | 2517 | if (byte_size <= 4) |
| 2518 | scalar = data.GetMaxU32 (&offset, byte_size); |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2519 | else |
Greg Clayton | 7060f89 | 2013-05-01 23:41:30 +0000 | [diff] [blame] | 2520 | scalar = data.GetMaxU64 (&offset, byte_size); |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2521 | if (is_signed) |
| 2522 | scalar.SignExtend(byte_size * 8); |
| 2523 | return bytes_read; |
| 2524 | } |
| 2525 | } |
| 2526 | else |
| 2527 | { |
| 2528 | error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size); |
| 2529 | } |
| 2530 | return 0; |
| 2531 | } |
| 2532 | |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2533 | #define USE_ALLOCATE_MEMORY_CACHE 1 |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2534 | addr_t |
| 2535 | Process::AllocateMemory(size_t size, uint32_t permissions, Error &error) |
| 2536 | { |
Jim Ingham | f72ce3a | 2011-06-20 17:32:44 +0000 | [diff] [blame] | 2537 | if (GetPrivateState() != eStateStopped) |
| 2538 | return LLDB_INVALID_ADDRESS; |
| 2539 | |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2540 | #if defined (USE_ALLOCATE_MEMORY_CACHE) |
| 2541 | return m_allocated_memory_cache.AllocateMemory(size, permissions, error); |
| 2542 | #else |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2543 | addr_t allocated_addr = DoAllocateMemory (size, permissions, error); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2544 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2545 | if (log) |
Greg Clayton | 4598907 | 2013-10-23 18:24:30 +0000 | [diff] [blame] | 2546 | log->Printf("Process::AllocateMemory(size=%" PRIu64 ", permissions=%s) => 0x%16.16" PRIx64 " (m_stop_id = %u m_memory_id = %u)", |
Deepak Panickal | d66b50c | 2013-10-22 12:27:43 +0000 | [diff] [blame] | 2547 | (uint64_t)size, |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2548 | GetPermissionsAsCString (permissions), |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2549 | (uint64_t)allocated_addr, |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 2550 | m_mod_id.GetStopID(), |
| 2551 | m_mod_id.GetMemoryID()); |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2552 | return allocated_addr; |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2553 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
Sean Callanan | 9053945 | 2011-09-20 23:01:51 +0000 | [diff] [blame] | 2556 | bool |
| 2557 | Process::CanJIT () |
| 2558 | { |
Sean Callanan | a7b443a | 2012-02-14 22:50:38 +0000 | [diff] [blame] | 2559 | if (m_can_jit == eCanJITDontKnow) |
| 2560 | { |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 2561 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Sean Callanan | a7b443a | 2012-02-14 22:50:38 +0000 | [diff] [blame] | 2562 | Error err; |
| 2563 | |
| 2564 | uint64_t allocated_memory = AllocateMemory(8, |
| 2565 | ePermissionsReadable | ePermissionsWritable | ePermissionsExecutable, |
| 2566 | err); |
| 2567 | |
| 2568 | if (err.Success()) |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 2569 | { |
Sean Callanan | a7b443a | 2012-02-14 22:50:38 +0000 | [diff] [blame] | 2570 | m_can_jit = eCanJITYes; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 2571 | if (log) |
| 2572 | log->Printf ("Process::%s pid %" PRIu64 " allocation test passed, CanJIT () is true", __FUNCTION__, GetID ()); |
| 2573 | } |
Sean Callanan | a7b443a | 2012-02-14 22:50:38 +0000 | [diff] [blame] | 2574 | else |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 2575 | { |
Sean Callanan | a7b443a | 2012-02-14 22:50:38 +0000 | [diff] [blame] | 2576 | m_can_jit = eCanJITNo; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 2577 | if (log) |
| 2578 | log->Printf ("Process::%s pid %" PRIu64 " allocation test failed, CanJIT () is false: %s", __FUNCTION__, GetID (), err.AsCString ()); |
| 2579 | } |
Sean Callanan | a7b443a | 2012-02-14 22:50:38 +0000 | [diff] [blame] | 2580 | |
| 2581 | DeallocateMemory (allocated_memory); |
| 2582 | } |
| 2583 | |
Sean Callanan | 9053945 | 2011-09-20 23:01:51 +0000 | [diff] [blame] | 2584 | return m_can_jit == eCanJITYes; |
| 2585 | } |
| 2586 | |
| 2587 | void |
| 2588 | Process::SetCanJIT (bool can_jit) |
| 2589 | { |
| 2590 | m_can_jit = (can_jit ? eCanJITYes : eCanJITNo); |
| 2591 | } |
| 2592 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2593 | Error |
| 2594 | Process::DeallocateMemory (addr_t ptr) |
| 2595 | { |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2596 | Error error; |
| 2597 | #if defined (USE_ALLOCATE_MEMORY_CACHE) |
| 2598 | if (!m_allocated_memory_cache.DeallocateMemory(ptr)) |
| 2599 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2600 | error.SetErrorStringWithFormat ("deallocation of memory at 0x%" PRIx64 " failed.", (uint64_t)ptr); |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2601 | } |
| 2602 | #else |
| 2603 | error = DoDeallocateMemory (ptr); |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2604 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2605 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2606 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2607 | log->Printf("Process::DeallocateMemory(addr=0x%16.16" PRIx64 ") => err = %s (m_stop_id = %u, m_memory_id = %u)", |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2608 | ptr, |
| 2609 | error.AsCString("SUCCESS"), |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 2610 | m_mod_id.GetStopID(), |
| 2611 | m_mod_id.GetMemoryID()); |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2612 | #endif |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2613 | return error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2614 | } |
| 2615 | |
Han Ming Ong | c811d38 | 2012-11-17 00:33:14 +0000 | [diff] [blame] | 2616 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 2617 | ModuleSP |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2618 | Process::ReadModuleFromMemory (const FileSpec& file_spec, |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 2619 | lldb::addr_t header_addr, |
| 2620 | size_t size_to_read) |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 2621 | { |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 2622 | ModuleSP module_sp (new Module (file_spec, ArchSpec())); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 2623 | if (module_sp) |
| 2624 | { |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 2625 | Error error; |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 2626 | ObjectFile *objfile = module_sp->GetMemoryObjectFile (shared_from_this(), header_addr, error, size_to_read); |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 2627 | if (objfile) |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 2628 | return module_sp; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 2629 | } |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 2630 | return ModuleSP(); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 2631 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2632 | |
| 2633 | Error |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 2634 | Process::EnableWatchpoint (Watchpoint *watchpoint, bool notify) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2635 | { |
| 2636 | Error error; |
| 2637 | error.SetErrorString("watchpoints are not supported"); |
| 2638 | return error; |
| 2639 | } |
| 2640 | |
| 2641 | Error |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 2642 | Process::DisableWatchpoint (Watchpoint *watchpoint, bool notify) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2643 | { |
| 2644 | Error error; |
| 2645 | error.SetErrorString("watchpoints are not supported"); |
| 2646 | return error; |
| 2647 | } |
| 2648 | |
| 2649 | StateType |
| 2650 | Process::WaitForProcessStopPrivate (const TimeValue *timeout, EventSP &event_sp) |
| 2651 | { |
| 2652 | StateType state; |
| 2653 | // Now wait for the process to launch and return control to us, and then |
| 2654 | // call DidLaunch: |
| 2655 | while (1) |
| 2656 | { |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 2657 | event_sp.reset(); |
| 2658 | state = WaitForStateChangedEventsPrivate (timeout, event_sp); |
| 2659 | |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 2660 | if (StateIsStoppedState(state, false)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2661 | break; |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 2662 | |
| 2663 | // If state is invalid, then we timed out |
| 2664 | if (state == eStateInvalid) |
| 2665 | break; |
| 2666 | |
| 2667 | if (event_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2668 | HandlePrivateEvent (event_sp); |
| 2669 | } |
| 2670 | return state; |
| 2671 | } |
| 2672 | |
| 2673 | Error |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 2674 | Process::Launch (ProcessLaunchInfo &launch_info) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2675 | { |
| 2676 | Error error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2677 | m_abi_sp.reset(); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 2678 | m_dyld_ap.reset(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 2679 | m_jit_loaders_ap.reset(); |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 2680 | m_system_runtime_ap.reset(); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 2681 | m_os_ap.reset(); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 2682 | m_process_input_reader.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2683 | |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 2684 | Module *exe_module = m_target.GetExecutableModulePointer(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2685 | if (exe_module) |
| 2686 | { |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 2687 | char local_exec_file_path[PATH_MAX]; |
| 2688 | char platform_exec_file_path[PATH_MAX]; |
| 2689 | exe_module->GetFileSpec().GetPath(local_exec_file_path, sizeof(local_exec_file_path)); |
| 2690 | exe_module->GetPlatformFileSpec().GetPath(platform_exec_file_path, sizeof(platform_exec_file_path)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2691 | if (exe_module->GetFileSpec().Exists()) |
| 2692 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 2693 | // Install anything that might need to be installed prior to launching. |
| 2694 | // For host systems, this will do nothing, but if we are connected to a |
| 2695 | // remote platform it will install any needed binaries |
| 2696 | error = GetTarget().Install(&launch_info); |
| 2697 | if (error.Fail()) |
| 2698 | return error; |
| 2699 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 2700 | if (PrivateStateThreadIsValid ()) |
| 2701 | PausePrivateStateThread (); |
| 2702 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2703 | error = WillLaunch (exe_module); |
| 2704 | if (error.Success()) |
| 2705 | { |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 2706 | const bool restarted = false; |
| 2707 | SetPublicState (eStateLaunching, restarted); |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 2708 | m_should_detach = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2709 | |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 2710 | if (m_public_run_lock.TrySetRunning()) |
Greg Clayton | 69fd4be | 2012-09-04 20:29:05 +0000 | [diff] [blame] | 2711 | { |
| 2712 | // Now launch using these arguments. |
| 2713 | error = DoLaunch (exe_module, launch_info); |
| 2714 | } |
| 2715 | else |
| 2716 | { |
| 2717 | // This shouldn't happen |
| 2718 | error.SetErrorString("failed to acquire process run lock"); |
| 2719 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2720 | |
| 2721 | if (error.Fail()) |
| 2722 | { |
| 2723 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
| 2724 | { |
| 2725 | SetID (LLDB_INVALID_PROCESS_ID); |
| 2726 | const char *error_string = error.AsCString(); |
| 2727 | if (error_string == NULL) |
| 2728 | error_string = "launch failed"; |
| 2729 | SetExitStatus (-1, error_string); |
| 2730 | } |
| 2731 | } |
| 2732 | else |
| 2733 | { |
| 2734 | EventSP event_sp; |
Greg Clayton | 1a38ea7 | 2011-06-22 01:42:17 +0000 | [diff] [blame] | 2735 | TimeValue timeout_time; |
| 2736 | timeout_time = TimeValue::Now(); |
| 2737 | timeout_time.OffsetWithSeconds(10); |
| 2738 | StateType state = WaitForProcessStopPrivate(&timeout_time, event_sp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2739 | |
Greg Clayton | 1a38ea7 | 2011-06-22 01:42:17 +0000 | [diff] [blame] | 2740 | if (state == eStateInvalid || event_sp.get() == NULL) |
| 2741 | { |
| 2742 | // We were able to launch the process, but we failed to |
| 2743 | // catch the initial stop. |
| 2744 | SetExitStatus (0, "failed to catch stop after launch"); |
| 2745 | Destroy(); |
| 2746 | } |
| 2747 | else if (state == eStateStopped || state == eStateCrashed) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2748 | { |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 2749 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2750 | DidLaunch (); |
| 2751 | |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2752 | DynamicLoader *dyld = GetDynamicLoader (); |
| 2753 | if (dyld) |
| 2754 | dyld->DidLaunch(); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 2755 | |
Andrew MacPherson | eb4d060 | 2014-03-13 09:37:02 +0000 | [diff] [blame] | 2756 | GetJITLoaders().DidLaunch(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 2757 | |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 2758 | SystemRuntime *system_runtime = GetSystemRuntime (); |
| 2759 | if (system_runtime) |
| 2760 | system_runtime->DidLaunch(); |
| 2761 | |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 2762 | m_os_ap.reset (OperatingSystem::FindPlugin (this, NULL)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2763 | // This delays passing the stopped event to listeners till DidLaunch gets |
| 2764 | // a chance to complete... |
| 2765 | HandlePrivateEvent (event_sp); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 2766 | |
| 2767 | if (PrivateStateThreadIsValid ()) |
| 2768 | ResumePrivateStateThread (); |
| 2769 | else |
| 2770 | StartPrivateStateThread (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2771 | } |
| 2772 | else if (state == eStateExited) |
| 2773 | { |
| 2774 | // We exited while trying to launch somehow. Don't call DidLaunch as that's |
| 2775 | // not likely to work, and return an invalid pid. |
| 2776 | HandlePrivateEvent (event_sp); |
| 2777 | } |
| 2778 | } |
| 2779 | } |
| 2780 | } |
| 2781 | else |
| 2782 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 2783 | error.SetErrorStringWithFormat("file doesn't exist: '%s'", local_exec_file_path); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2784 | } |
| 2785 | } |
| 2786 | return error; |
| 2787 | } |
| 2788 | |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 2789 | |
| 2790 | Error |
| 2791 | Process::LoadCore () |
| 2792 | { |
| 2793 | Error error = DoLoadCore(); |
| 2794 | if (error.Success()) |
| 2795 | { |
| 2796 | if (PrivateStateThreadIsValid ()) |
| 2797 | ResumePrivateStateThread (); |
| 2798 | else |
| 2799 | StartPrivateStateThread (); |
| 2800 | |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2801 | DynamicLoader *dyld = GetDynamicLoader (); |
| 2802 | if (dyld) |
| 2803 | dyld->DidAttach(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 2804 | |
Andrew MacPherson | eb4d060 | 2014-03-13 09:37:02 +0000 | [diff] [blame] | 2805 | GetJITLoaders().DidAttach(); |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2806 | |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 2807 | SystemRuntime *system_runtime = GetSystemRuntime (); |
| 2808 | if (system_runtime) |
| 2809 | system_runtime->DidAttach(); |
| 2810 | |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2811 | m_os_ap.reset (OperatingSystem::FindPlugin (this, NULL)); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 2812 | // We successfully loaded a core file, now pretend we stopped so we can |
| 2813 | // show all of the threads in the core file and explore the crashed |
| 2814 | // state. |
| 2815 | SetPrivateState (eStateStopped); |
| 2816 | |
| 2817 | } |
| 2818 | return error; |
| 2819 | } |
| 2820 | |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2821 | DynamicLoader * |
| 2822 | Process::GetDynamicLoader () |
| 2823 | { |
| 2824 | if (m_dyld_ap.get() == NULL) |
| 2825 | m_dyld_ap.reset (DynamicLoader::FindPlugin(this, NULL)); |
| 2826 | return m_dyld_ap.get(); |
| 2827 | } |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 2828 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 2829 | const lldb::DataBufferSP |
| 2830 | Process::GetAuxvData() |
| 2831 | { |
| 2832 | return DataBufferSP (); |
| 2833 | } |
| 2834 | |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 2835 | JITLoaderList & |
| 2836 | Process::GetJITLoaders () |
| 2837 | { |
| 2838 | if (!m_jit_loaders_ap) |
| 2839 | { |
| 2840 | m_jit_loaders_ap.reset(new JITLoaderList()); |
| 2841 | JITLoader::LoadPlugins(this, *m_jit_loaders_ap); |
| 2842 | } |
| 2843 | return *m_jit_loaders_ap; |
| 2844 | } |
| 2845 | |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 2846 | SystemRuntime * |
| 2847 | Process::GetSystemRuntime () |
| 2848 | { |
| 2849 | if (m_system_runtime_ap.get() == NULL) |
| 2850 | m_system_runtime_ap.reset (SystemRuntime::FindPlugin(this)); |
| 2851 | return m_system_runtime_ap.get(); |
| 2852 | } |
| 2853 | |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 2854 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2855 | Process::NextEventAction::EventActionResult |
| 2856 | Process::AttachCompletionHandler::PerformAction (lldb::EventSP &event_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2857 | { |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2858 | StateType state = ProcessEventData::GetStateFromEvent (event_sp.get()); |
| 2859 | switch (state) |
Greg Clayton | 19388cf | 2010-10-18 01:45:30 +0000 | [diff] [blame] | 2860 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2861 | case eStateRunning: |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 2862 | case eStateConnected: |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2863 | return eEventActionRetry; |
| 2864 | |
| 2865 | case eStateStopped: |
| 2866 | case eStateCrashed: |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 2867 | { |
| 2868 | // During attach, prior to sending the eStateStopped event, |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 2869 | // lldb_private::Process subclasses must set the new process ID. |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 2870 | assert (m_process->GetID() != LLDB_INVALID_PROCESS_ID); |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 2871 | // We don't want these events to be reported, so go set the ShouldReportStop here: |
| 2872 | m_process->GetThreadList().SetShouldReportStop (eVoteNo); |
| 2873 | |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 2874 | if (m_exec_count > 0) |
| 2875 | { |
| 2876 | --m_exec_count; |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 2877 | RequestResume(); |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 2878 | return eEventActionRetry; |
| 2879 | } |
| 2880 | else |
| 2881 | { |
| 2882 | m_process->CompleteAttach (); |
| 2883 | return eEventActionSuccess; |
| 2884 | } |
| 2885 | } |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2886 | break; |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 2887 | |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2888 | default: |
| 2889 | case eStateExited: |
| 2890 | case eStateInvalid: |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2891 | break; |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2892 | } |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 2893 | |
| 2894 | m_exit_string.assign ("No valid Process"); |
| 2895 | return eEventActionExit; |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2896 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2897 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2898 | Process::NextEventAction::EventActionResult |
| 2899 | Process::AttachCompletionHandler::HandleBeingInterrupted() |
| 2900 | { |
| 2901 | return eEventActionSuccess; |
| 2902 | } |
| 2903 | |
| 2904 | const char * |
| 2905 | Process::AttachCompletionHandler::GetExitString () |
| 2906 | { |
| 2907 | return m_exit_string.c_str(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2908 | } |
| 2909 | |
| 2910 | Error |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2911 | Process::Attach (ProcessAttachInfo &attach_info) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2912 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2913 | m_abi_sp.reset(); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 2914 | m_process_input_reader.reset(); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 2915 | m_dyld_ap.reset(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 2916 | m_jit_loaders_ap.reset(); |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 2917 | m_system_runtime_ap.reset(); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 2918 | m_os_ap.reset(); |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 2919 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2920 | lldb::pid_t attach_pid = attach_info.GetProcessID(); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2921 | Error error; |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2922 | if (attach_pid == LLDB_INVALID_PROCESS_ID) |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 2923 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2924 | char process_name[PATH_MAX]; |
Jim Ingham | 4299fdb | 2011-09-15 01:10:17 +0000 | [diff] [blame] | 2925 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2926 | if (attach_info.GetExecutableFile().GetPath (process_name, sizeof(process_name))) |
Jim Ingham | 2ecb742 | 2010-08-17 21:54:19 +0000 | [diff] [blame] | 2927 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2928 | const bool wait_for_launch = attach_info.GetWaitForLaunch(); |
| 2929 | |
| 2930 | if (wait_for_launch) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2931 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2932 | error = WillAttachToProcessWithName(process_name, wait_for_launch); |
| 2933 | if (error.Success()) |
| 2934 | { |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 2935 | if (m_public_run_lock.TrySetRunning()) |
Greg Clayton | 926cce7 | 2012-10-12 16:10:12 +0000 | [diff] [blame] | 2936 | { |
| 2937 | m_should_detach = true; |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 2938 | const bool restarted = false; |
| 2939 | SetPublicState (eStateAttaching, restarted); |
Greg Clayton | 926cce7 | 2012-10-12 16:10:12 +0000 | [diff] [blame] | 2940 | // Now attach using these arguments. |
Jean-Daniel Dupas | 9c517c0 | 2013-12-23 22:32:54 +0000 | [diff] [blame] | 2941 | error = DoAttachToProcessWithName (process_name, attach_info); |
Greg Clayton | 926cce7 | 2012-10-12 16:10:12 +0000 | [diff] [blame] | 2942 | } |
| 2943 | else |
| 2944 | { |
| 2945 | // This shouldn't happen |
| 2946 | error.SetErrorString("failed to acquire process run lock"); |
| 2947 | } |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 2948 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2949 | if (error.Fail()) |
| 2950 | { |
| 2951 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
| 2952 | { |
| 2953 | SetID (LLDB_INVALID_PROCESS_ID); |
| 2954 | if (error.AsCString() == NULL) |
| 2955 | error.SetErrorString("attach failed"); |
| 2956 | |
| 2957 | SetExitStatus(-1, error.AsCString()); |
| 2958 | } |
| 2959 | } |
| 2960 | else |
| 2961 | { |
| 2962 | SetNextEventAction(new Process::AttachCompletionHandler(this, attach_info.GetResumeCount())); |
| 2963 | StartPrivateStateThread(); |
| 2964 | } |
| 2965 | return error; |
| 2966 | } |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2967 | } |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2968 | else |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2969 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2970 | ProcessInstanceInfoList process_infos; |
| 2971 | PlatformSP platform_sp (m_target.GetPlatform ()); |
| 2972 | |
| 2973 | if (platform_sp) |
| 2974 | { |
| 2975 | ProcessInstanceInfoMatch match_info; |
| 2976 | match_info.GetProcessInfo() = attach_info; |
| 2977 | match_info.SetNameMatchType (eNameMatchEquals); |
| 2978 | platform_sp->FindProcesses (match_info, process_infos); |
| 2979 | const uint32_t num_matches = process_infos.GetSize(); |
| 2980 | if (num_matches == 1) |
| 2981 | { |
| 2982 | attach_pid = process_infos.GetProcessIDAtIndex(0); |
| 2983 | // Fall through and attach using the above process ID |
| 2984 | } |
| 2985 | else |
| 2986 | { |
| 2987 | match_info.GetProcessInfo().GetExecutableFile().GetPath (process_name, sizeof(process_name)); |
| 2988 | if (num_matches > 1) |
| 2989 | error.SetErrorStringWithFormat ("more than one process named %s", process_name); |
| 2990 | else |
| 2991 | error.SetErrorStringWithFormat ("could not find a process named %s", process_name); |
| 2992 | } |
| 2993 | } |
| 2994 | else |
| 2995 | { |
| 2996 | error.SetErrorString ("invalid platform, can't find processes by name"); |
| 2997 | return error; |
| 2998 | } |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2999 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3000 | } |
| 3001 | else |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3002 | { |
| 3003 | error.SetErrorString ("invalid process name"); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3004 | } |
| 3005 | } |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3006 | |
| 3007 | if (attach_pid != LLDB_INVALID_PROCESS_ID) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3008 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3009 | error = WillAttachToProcessWithID(attach_pid); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3010 | if (error.Success()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3011 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3012 | |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 3013 | if (m_public_run_lock.TrySetRunning()) |
Greg Clayton | 926cce7 | 2012-10-12 16:10:12 +0000 | [diff] [blame] | 3014 | { |
| 3015 | // Now attach using these arguments. |
| 3016 | m_should_detach = true; |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 3017 | const bool restarted = false; |
| 3018 | SetPublicState (eStateAttaching, restarted); |
Greg Clayton | 926cce7 | 2012-10-12 16:10:12 +0000 | [diff] [blame] | 3019 | error = DoAttachToProcessWithID (attach_pid, attach_info); |
| 3020 | } |
| 3021 | else |
| 3022 | { |
| 3023 | // This shouldn't happen |
| 3024 | error.SetErrorString("failed to acquire process run lock"); |
| 3025 | } |
| 3026 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3027 | if (error.Success()) |
| 3028 | { |
| 3029 | |
| 3030 | SetNextEventAction(new Process::AttachCompletionHandler(this, attach_info.GetResumeCount())); |
| 3031 | StartPrivateStateThread(); |
| 3032 | } |
| 3033 | else |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3034 | { |
| 3035 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
| 3036 | { |
| 3037 | SetID (LLDB_INVALID_PROCESS_ID); |
| 3038 | const char *error_string = error.AsCString(); |
| 3039 | if (error_string == NULL) |
| 3040 | error_string = "attach failed"; |
| 3041 | |
| 3042 | SetExitStatus(-1, error_string); |
| 3043 | } |
| 3044 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3045 | } |
| 3046 | } |
| 3047 | return error; |
| 3048 | } |
| 3049 | |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3050 | void |
| 3051 | Process::CompleteAttach () |
| 3052 | { |
| 3053 | // Let the process subclass figure out at much as it can about the process |
| 3054 | // before we go looking for a dynamic loader plug-in. |
| 3055 | DidAttach(); |
| 3056 | |
Jim Ingham | 4299fdb | 2011-09-15 01:10:17 +0000 | [diff] [blame] | 3057 | // We just attached. If we have a platform, ask it for the process architecture, and if it isn't |
| 3058 | // the same as the one we've already set, switch architectures. |
| 3059 | PlatformSP platform_sp (m_target.GetPlatform ()); |
| 3060 | assert (platform_sp.get()); |
| 3061 | if (platform_sp) |
| 3062 | { |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 3063 | const ArchSpec &target_arch = m_target.GetArchitecture(); |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 3064 | if (target_arch.IsValid() && !platform_sp->IsCompatibleArchitecture (target_arch, false, NULL)) |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 3065 | { |
| 3066 | ArchSpec platform_arch; |
| 3067 | platform_sp = platform_sp->GetPlatformForArchitecture (target_arch, &platform_arch); |
| 3068 | if (platform_sp) |
| 3069 | { |
| 3070 | m_target.SetPlatform (platform_sp); |
| 3071 | m_target.SetArchitecture(platform_arch); |
| 3072 | } |
| 3073 | } |
| 3074 | else |
| 3075 | { |
| 3076 | ProcessInstanceInfo process_info; |
| 3077 | platform_sp->GetProcessInfo (GetID(), process_info); |
| 3078 | const ArchSpec &process_arch = process_info.GetArchitecture(); |
Sean Callanan | bf4b7be | 2012-12-13 22:07:14 +0000 | [diff] [blame] | 3079 | if (process_arch.IsValid() && !m_target.GetArchitecture().IsExactMatch(process_arch)) |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 3080 | m_target.SetArchitecture (process_arch); |
| 3081 | } |
Jim Ingham | 4299fdb | 2011-09-15 01:10:17 +0000 | [diff] [blame] | 3082 | } |
| 3083 | |
| 3084 | // We have completed the attach, now it is time to find the dynamic loader |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3085 | // plug-in |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 3086 | DynamicLoader *dyld = GetDynamicLoader (); |
| 3087 | if (dyld) |
| 3088 | dyld->DidAttach(); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3089 | |
Andrew MacPherson | eb4d060 | 2014-03-13 09:37:02 +0000 | [diff] [blame] | 3090 | GetJITLoaders().DidAttach(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 3091 | |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 3092 | SystemRuntime *system_runtime = GetSystemRuntime (); |
| 3093 | if (system_runtime) |
| 3094 | system_runtime->DidAttach(); |
| 3095 | |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 3096 | m_os_ap.reset (OperatingSystem::FindPlugin (this, NULL)); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3097 | // Figure out which one is the executable, and set that in our target: |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 3098 | const ModuleList &target_modules = m_target.GetImages(); |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3099 | Mutex::Locker modules_locker(target_modules.GetMutex()); |
| 3100 | size_t num_modules = target_modules.GetSize(); |
| 3101 | ModuleSP new_executable_module_sp; |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3102 | |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 3103 | for (size_t i = 0; i < num_modules; i++) |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3104 | { |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3105 | ModuleSP module_sp (target_modules.GetModuleAtIndexUnlocked (i)); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3106 | if (module_sp && module_sp->IsExecutable()) |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3107 | { |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 3108 | if (m_target.GetExecutableModulePointer() != module_sp.get()) |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3109 | new_executable_module_sp = module_sp; |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3110 | break; |
| 3111 | } |
| 3112 | } |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3113 | if (new_executable_module_sp) |
| 3114 | m_target.SetExecutableModule (new_executable_module_sp, false); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3115 | } |
| 3116 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3117 | Error |
Jason Molenda | 4bd4e7e | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 3118 | Process::ConnectRemote (Stream *strm, const char *remote_url) |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 3119 | { |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 3120 | m_abi_sp.reset(); |
| 3121 | m_process_input_reader.reset(); |
| 3122 | |
| 3123 | // Find the process and its architecture. Make sure it matches the architecture |
| 3124 | // of the current Target, and if not adjust it. |
| 3125 | |
Jason Molenda | 4bd4e7e | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 3126 | Error error (DoConnectRemote (strm, remote_url)); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 3127 | if (error.Success()) |
| 3128 | { |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3129 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
| 3130 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 3131 | EventSP event_sp; |
| 3132 | StateType state = WaitForProcessStopPrivate(NULL, event_sp); |
| 3133 | |
| 3134 | if (state == eStateStopped || state == eStateCrashed) |
| 3135 | { |
| 3136 | // If we attached and actually have a process on the other end, then |
| 3137 | // this ended up being the equivalent of an attach. |
| 3138 | CompleteAttach (); |
| 3139 | |
| 3140 | // This delays passing the stopped event to listeners till |
| 3141 | // CompleteAttach gets a chance to complete... |
| 3142 | HandlePrivateEvent (event_sp); |
| 3143 | |
| 3144 | } |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3145 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 3146 | |
| 3147 | if (PrivateStateThreadIsValid ()) |
| 3148 | ResumePrivateStateThread (); |
| 3149 | else |
| 3150 | StartPrivateStateThread (); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 3151 | } |
| 3152 | return error; |
| 3153 | } |
| 3154 | |
| 3155 | |
| 3156 | Error |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 3157 | Process::PrivateResume () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3158 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3159 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS|LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3160 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3161 | log->Printf("Process::PrivateResume() m_stop_id = %u, public state: %s private state: %s", |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3162 | m_mod_id.GetStopID(), |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 3163 | StateAsCString(m_public_state.GetValue()), |
| 3164 | StateAsCString(m_private_state.GetValue())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3165 | |
| 3166 | Error error (WillResume()); |
| 3167 | // Tell the process it is about to resume before the thread list |
| 3168 | if (error.Success()) |
| 3169 | { |
Johnny Chen | c4221e4 | 2010-12-02 20:53:05 +0000 | [diff] [blame] | 3170 | // Now let the thread list know we are about to resume so it |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3171 | // can let all of our threads know that they are about to be |
| 3172 | // resumed. Threads will each be called with |
| 3173 | // Thread::WillResume(StateType) where StateType contains the state |
| 3174 | // that they are supposed to have when the process is resumed |
| 3175 | // (suspended/running/stepping). Threads should also check |
| 3176 | // their resume signal in lldb::Thread::GetResumeSignal() |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 3177 | // to see if they are supposed to start back up with a signal. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3178 | if (m_thread_list.WillResume()) |
| 3179 | { |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 3180 | // Last thing, do the PreResumeActions. |
| 3181 | if (!RunPreResumeActions()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3182 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3183 | error.SetErrorStringWithFormat ("Process::PrivateResume PreResumeActions failed, not resuming."); |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 3184 | } |
| 3185 | else |
| 3186 | { |
| 3187 | m_mod_id.BumpResumeID(); |
| 3188 | error = DoResume(); |
| 3189 | if (error.Success()) |
| 3190 | { |
| 3191 | DidResume(); |
| 3192 | m_thread_list.DidResume(); |
| 3193 | if (log) |
| 3194 | log->Printf ("Process thinks the process has resumed."); |
| 3195 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3196 | } |
| 3197 | } |
| 3198 | else |
| 3199 | { |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 3200 | // Somebody wanted to run without running. So generate a continue & a stopped event, |
| 3201 | // and let the world handle them. |
| 3202 | if (log) |
| 3203 | log->Printf ("Process::PrivateResume() asked to simulate a start & stop."); |
| 3204 | |
| 3205 | SetPrivateState(eStateRunning); |
| 3206 | SetPrivateState(eStateStopped); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3207 | } |
| 3208 | } |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 3209 | else if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3210 | log->Printf ("Process::PrivateResume() got an error \"%s\".", error.AsCString("<unknown error>")); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3211 | return error; |
| 3212 | } |
| 3213 | |
| 3214 | Error |
Greg Clayton | f9b57b9 | 2013-05-10 23:48:10 +0000 | [diff] [blame] | 3215 | Process::Halt (bool clear_thread_plans) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3216 | { |
Greg Clayton | f9b57b9 | 2013-05-10 23:48:10 +0000 | [diff] [blame] | 3217 | // Don't clear the m_clear_thread_plans_on_stop, only set it to true if |
| 3218 | // in case it was already set and some thread plan logic calls halt on its |
| 3219 | // own. |
| 3220 | m_clear_thread_plans_on_stop |= clear_thread_plans; |
| 3221 | |
Jim Ingham | aacc318 | 2012-06-06 00:29:30 +0000 | [diff] [blame] | 3222 | // First make sure we aren't in the middle of handling an event, or we might restart. This is pretty weak, since |
| 3223 | // we could just straightaway get another event. It just narrows the window... |
| 3224 | m_currently_handling_event.WaitForValueEqualTo(false); |
| 3225 | |
| 3226 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3227 | // Pause our private state thread so we can ensure no one else eats |
| 3228 | // the stop event out from under us. |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 3229 | Listener halt_listener ("lldb.process.halt_listener"); |
| 3230 | HijackPrivateProcessEvents(&halt_listener); |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 3231 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3232 | EventSP event_sp; |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3233 | Error error (WillHalt()); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3234 | |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3235 | if (error.Success()) |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3236 | { |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3237 | |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3238 | bool caused_stop = false; |
| 3239 | |
| 3240 | // Ask the process subclass to actually halt our process |
| 3241 | error = DoHalt(caused_stop); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3242 | if (error.Success()) |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3243 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3244 | if (m_public_state.GetValue() == eStateAttaching) |
| 3245 | { |
| 3246 | SetExitStatus(SIGKILL, "Cancelled async attach."); |
| 3247 | Destroy (); |
| 3248 | } |
| 3249 | else |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3250 | { |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3251 | // If "caused_stop" is true, then DoHalt stopped the process. If |
| 3252 | // "caused_stop" is false, the process was already stopped. |
| 3253 | // If the DoHalt caused the process to stop, then we want to catch |
| 3254 | // this event and set the interrupted bool to true before we pass |
| 3255 | // this along so clients know that the process was interrupted by |
| 3256 | // a halt command. |
| 3257 | if (caused_stop) |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 3258 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 3259 | // Wait for 1 second for the process to stop. |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3260 | TimeValue timeout_time; |
| 3261 | timeout_time = TimeValue::Now(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 3262 | timeout_time.OffsetWithSeconds(10); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 3263 | bool got_event = halt_listener.WaitForEvent (&timeout_time, event_sp); |
| 3264 | StateType state = ProcessEventData::GetStateFromEvent(event_sp.get()); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3265 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 3266 | if (!got_event || state == eStateInvalid) |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 3267 | { |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3268 | // We timeout out and didn't get a stop event... |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 3269 | error.SetErrorStringWithFormat ("Halt timed out. State = %s", StateAsCString(GetState())); |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 3270 | } |
| 3271 | else |
| 3272 | { |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 3273 | if (StateIsStoppedState (state, false)) |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3274 | { |
| 3275 | // We caused the process to interrupt itself, so mark this |
| 3276 | // as such in the stop event so clients can tell an interrupted |
| 3277 | // process from a natural stop |
| 3278 | ProcessEventData::SetInterruptedInEvent (event_sp.get(), true); |
| 3279 | } |
| 3280 | else |
| 3281 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3282 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3283 | if (log) |
| 3284 | log->Printf("Process::Halt() failed to stop, state is: %s", StateAsCString(state)); |
| 3285 | error.SetErrorString ("Did not get stopped event after halt."); |
| 3286 | } |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 3287 | } |
| 3288 | } |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3289 | DidHalt(); |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3290 | } |
| 3291 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3292 | } |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3293 | // Resume our private state thread before we post the event (if any) |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 3294 | RestorePrivateProcessEvents(); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3295 | |
| 3296 | // Post any event we might have consumed. If all goes well, we will have |
| 3297 | // stopped the process, intercepted the event and set the interrupted |
| 3298 | // bool in the event. Post it to the private event queue and that will end up |
| 3299 | // correctly setting the state. |
| 3300 | if (event_sp) |
| 3301 | m_private_state_broadcaster.BroadcastEvent(event_sp); |
| 3302 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3303 | return error; |
| 3304 | } |
| 3305 | |
| 3306 | Error |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 3307 | Process::HaltForDestroyOrDetach(lldb::EventSP &exit_event_sp) |
| 3308 | { |
| 3309 | Error error; |
| 3310 | if (m_public_state.GetValue() == eStateRunning) |
| 3311 | { |
| 3312 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 3313 | if (log) |
| 3314 | log->Printf("Process::Destroy() About to halt."); |
| 3315 | error = Halt(); |
| 3316 | if (error.Success()) |
| 3317 | { |
| 3318 | // Consume the halt event. |
| 3319 | TimeValue timeout (TimeValue::Now()); |
| 3320 | timeout.OffsetWithSeconds(1); |
| 3321 | StateType state = WaitForProcessToStop (&timeout, &exit_event_sp); |
| 3322 | |
| 3323 | // If the process exited while we were waiting for it to stop, put the exited event into |
| 3324 | // the shared pointer passed in and return. Our caller doesn't need to do anything else, since |
| 3325 | // they don't have a process anymore... |
| 3326 | |
| 3327 | if (state == eStateExited || m_private_state.GetValue() == eStateExited) |
| 3328 | { |
| 3329 | if (log) |
| 3330 | log->Printf("Process::HaltForDestroyOrDetach() Process exited while waiting to Halt."); |
| 3331 | return error; |
| 3332 | } |
| 3333 | else |
| 3334 | exit_event_sp.reset(); // It is ok to consume any non-exit stop events |
| 3335 | |
| 3336 | if (state != eStateStopped) |
| 3337 | { |
| 3338 | if (log) |
| 3339 | log->Printf("Process::HaltForDestroyOrDetach() Halt failed to stop, state is: %s", StateAsCString(state)); |
| 3340 | // If we really couldn't stop the process then we should just error out here, but if the |
| 3341 | // lower levels just bobbled sending the event and we really are stopped, then continue on. |
| 3342 | StateType private_state = m_private_state.GetValue(); |
| 3343 | if (private_state != eStateStopped) |
| 3344 | { |
| 3345 | return error; |
| 3346 | } |
| 3347 | } |
| 3348 | } |
| 3349 | else |
| 3350 | { |
| 3351 | if (log) |
| 3352 | log->Printf("Process::HaltForDestroyOrDetach() Halt got error: %s", error.AsCString()); |
| 3353 | } |
| 3354 | } |
| 3355 | return error; |
| 3356 | } |
| 3357 | |
| 3358 | Error |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 3359 | Process::Detach (bool keep_stopped) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3360 | { |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 3361 | EventSP exit_event_sp; |
| 3362 | Error error; |
| 3363 | m_destroy_in_process = true; |
| 3364 | |
| 3365 | error = WillDetach(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3366 | |
| 3367 | if (error.Success()) |
| 3368 | { |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 3369 | if (DetachRequiresHalt()) |
| 3370 | { |
| 3371 | error = HaltForDestroyOrDetach (exit_event_sp); |
| 3372 | if (!error.Success()) |
| 3373 | { |
| 3374 | m_destroy_in_process = false; |
| 3375 | return error; |
| 3376 | } |
| 3377 | else if (exit_event_sp) |
| 3378 | { |
| 3379 | // We shouldn't need to do anything else here. There's no process left to detach from... |
| 3380 | StopPrivateStateThread(); |
| 3381 | m_destroy_in_process = false; |
| 3382 | return error; |
| 3383 | } |
| 3384 | } |
| 3385 | |
Andrew MacPherson | c3826b5 | 2014-03-25 19:59:36 +0000 | [diff] [blame] | 3386 | m_thread_list.DiscardThreadPlans(); |
| 3387 | DisableAllBreakpointSites(); |
| 3388 | |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 3389 | error = DoDetach(keep_stopped); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3390 | if (error.Success()) |
| 3391 | { |
| 3392 | DidDetach(); |
| 3393 | StopPrivateStateThread(); |
| 3394 | } |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 3395 | else |
| 3396 | { |
| 3397 | return error; |
| 3398 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3399 | } |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 3400 | m_destroy_in_process = false; |
| 3401 | |
| 3402 | // If we exited when we were waiting for a process to stop, then |
| 3403 | // forward the event here so we don't lose the event |
| 3404 | if (exit_event_sp) |
| 3405 | { |
| 3406 | // Directly broadcast our exited event because we shut down our |
| 3407 | // private state thread above |
| 3408 | BroadcastEvent(exit_event_sp); |
| 3409 | } |
| 3410 | |
| 3411 | // If we have been interrupted (to kill us) in the middle of running, we may not end up propagating |
| 3412 | // the last events through the event system, in which case we might strand the write lock. Unlock |
| 3413 | // it here so when we do to tear down the process we don't get an error destroying the lock. |
| 3414 | |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 3415 | m_public_run_lock.SetStopped(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3416 | return error; |
| 3417 | } |
| 3418 | |
| 3419 | Error |
| 3420 | Process::Destroy () |
| 3421 | { |
Jim Ingham | 0943792 | 2013-03-01 20:04:25 +0000 | [diff] [blame] | 3422 | |
| 3423 | // Tell ourselves we are in the process of destroying the process, so that we don't do any unnecessary work |
| 3424 | // that might hinder the destruction. Remember to set this back to false when we are done. That way if the attempt |
| 3425 | // failed and the process stays around for some reason it won't be in a confused state. |
| 3426 | |
| 3427 | m_destroy_in_process = true; |
| 3428 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3429 | Error error (WillDestroy()); |
| 3430 | if (error.Success()) |
| 3431 | { |
Greg Clayton | 85fb1b9 | 2012-09-11 02:33:37 +0000 | [diff] [blame] | 3432 | EventSP exit_event_sp; |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 3433 | if (DestroyRequiresHalt()) |
Jim Ingham | 04e0a22 | 2012-05-23 15:46:31 +0000 | [diff] [blame] | 3434 | { |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 3435 | error = HaltForDestroyOrDetach(exit_event_sp); |
Jim Ingham | 04e0a22 | 2012-05-23 15:46:31 +0000 | [diff] [blame] | 3436 | } |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 3437 | |
Jim Ingham | aacc318 | 2012-06-06 00:29:30 +0000 | [diff] [blame] | 3438 | if (m_public_state.GetValue() != eStateRunning) |
| 3439 | { |
| 3440 | // Ditch all thread plans, and remove all our breakpoints: in case we have to restart the target to |
| 3441 | // kill it, we don't want it hitting a breakpoint... |
| 3442 | // Only do this if we've stopped, however, since if we didn't manage to halt it above, then |
| 3443 | // we're not going to have much luck doing this now. |
| 3444 | m_thread_list.DiscardThreadPlans(); |
| 3445 | DisableAllBreakpointSites(); |
| 3446 | } |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 3447 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3448 | error = DoDestroy(); |
| 3449 | if (error.Success()) |
| 3450 | { |
| 3451 | DidDestroy(); |
| 3452 | StopPrivateStateThread(); |
| 3453 | } |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 3454 | m_stdio_communication.StopReadThread(); |
| 3455 | m_stdio_communication.Disconnect(); |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3456 | |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 3457 | if (m_process_input_reader) |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3458 | { |
| 3459 | m_process_input_reader->SetIsDone(true); |
| 3460 | m_process_input_reader->Cancel(); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 3461 | m_process_input_reader.reset(); |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3462 | } |
| 3463 | |
Greg Clayton | 85fb1b9 | 2012-09-11 02:33:37 +0000 | [diff] [blame] | 3464 | // If we exited when we were waiting for a process to stop, then |
| 3465 | // forward the event here so we don't lose the event |
| 3466 | if (exit_event_sp) |
| 3467 | { |
| 3468 | // Directly broadcast our exited event because we shut down our |
| 3469 | // private state thread above |
| 3470 | BroadcastEvent(exit_event_sp); |
| 3471 | } |
| 3472 | |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3473 | // If we have been interrupted (to kill us) in the middle of running, we may not end up propagating |
| 3474 | // the last events through the event system, in which case we might strand the write lock. Unlock |
| 3475 | // it here so when we do to tear down the process we don't get an error destroying the lock. |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 3476 | m_public_run_lock.SetStopped(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3477 | } |
Jim Ingham | 0943792 | 2013-03-01 20:04:25 +0000 | [diff] [blame] | 3478 | |
| 3479 | m_destroy_in_process = false; |
| 3480 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3481 | return error; |
| 3482 | } |
| 3483 | |
| 3484 | Error |
| 3485 | Process::Signal (int signal) |
| 3486 | { |
| 3487 | Error error (WillSignal()); |
| 3488 | if (error.Success()) |
| 3489 | { |
| 3490 | error = DoSignal(signal); |
| 3491 | if (error.Success()) |
| 3492 | DidSignal(); |
| 3493 | } |
| 3494 | return error; |
| 3495 | } |
| 3496 | |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 3497 | lldb::ByteOrder |
| 3498 | Process::GetByteOrder () const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3499 | { |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 3500 | return m_target.GetArchitecture().GetByteOrder(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | uint32_t |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 3504 | Process::GetAddressByteSize () const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3505 | { |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 3506 | return m_target.GetArchitecture().GetAddressByteSize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3507 | } |
| 3508 | |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 3509 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3510 | bool |
| 3511 | Process::ShouldBroadcastEvent (Event *event_ptr) |
| 3512 | { |
| 3513 | const StateType state = Process::ProcessEventData::GetStateFromEvent (event_ptr); |
| 3514 | bool return_value = true; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3515 | Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EVENTS | LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3516 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3517 | switch (state) |
| 3518 | { |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 3519 | case eStateConnected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3520 | case eStateAttaching: |
| 3521 | case eStateLaunching: |
| 3522 | case eStateDetached: |
| 3523 | case eStateExited: |
| 3524 | case eStateUnloaded: |
| 3525 | // These events indicate changes in the state of the debugging session, always report them. |
| 3526 | return_value = true; |
| 3527 | break; |
| 3528 | case eStateInvalid: |
| 3529 | // We stopped for no apparent reason, don't report it. |
| 3530 | return_value = false; |
| 3531 | break; |
| 3532 | case eStateRunning: |
| 3533 | case eStateStepping: |
| 3534 | // If we've started the target running, we handle the cases where we |
| 3535 | // are already running and where there is a transition from stopped to |
| 3536 | // running differently. |
| 3537 | // running -> running: Automatically suppress extra running events |
| 3538 | // stopped -> running: Report except when there is one or more no votes |
| 3539 | // and no yes votes. |
| 3540 | SynchronouslyNotifyStateChanged (state); |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 3541 | if (m_force_next_event_delivery) |
| 3542 | return_value = true; |
| 3543 | else |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3544 | { |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 3545 | switch (m_last_broadcast_state) |
| 3546 | { |
| 3547 | case eStateRunning: |
| 3548 | case eStateStepping: |
| 3549 | // We always suppress multiple runnings with no PUBLIC stop in between. |
| 3550 | return_value = false; |
| 3551 | break; |
| 3552 | default: |
| 3553 | // TODO: make this work correctly. For now always report |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3554 | // run if we aren't running so we don't miss any running |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 3555 | // events. If I run the lldb/test/thread/a.out file and |
| 3556 | // break at main.cpp:58, run and hit the breakpoints on |
| 3557 | // multiple threads, then somehow during the stepping over |
| 3558 | // of all breakpoints no run gets reported. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3559 | |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 3560 | // This is a transition from stop to run. |
| 3561 | switch (m_thread_list.ShouldReportRun (event_ptr)) |
| 3562 | { |
| 3563 | case eVoteYes: |
| 3564 | case eVoteNoOpinion: |
| 3565 | return_value = true; |
| 3566 | break; |
| 3567 | case eVoteNo: |
| 3568 | return_value = false; |
| 3569 | break; |
| 3570 | } |
| 3571 | break; |
| 3572 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3573 | } |
| 3574 | break; |
| 3575 | case eStateStopped: |
| 3576 | case eStateCrashed: |
| 3577 | case eStateSuspended: |
| 3578 | { |
| 3579 | // We've stopped. First see if we're going to restart the target. |
| 3580 | // If we are going to stop, then we always broadcast the event. |
| 3581 | // If we aren't going to stop, let the thread plans decide if we're going to report this event. |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 3582 | // If no thread has an opinion, we don't report it. |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 3583 | |
Jim Ingham | cb4ca11 | 2012-05-16 01:32:14 +0000 | [diff] [blame] | 3584 | RefreshStateAfterStop (); |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3585 | if (ProcessEventData::GetInterruptedFromEvent (event_ptr)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3586 | { |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 3587 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3588 | log->Printf ("Process::ShouldBroadcastEvent (%p) stopped due to an interrupt, state: %s", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3589 | static_cast<void*>(event_ptr), |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3590 | StateAsCString(state)); |
Jim Ingham | 35878c4 | 2014-04-08 21:33:21 +0000 | [diff] [blame] | 3591 | // Even though we know we are going to stop, we should let the threads have a look at the stop, |
| 3592 | // so they can properly set their state. |
| 3593 | m_thread_list.ShouldStop (event_ptr); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3594 | return_value = true; |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3595 | } |
| 3596 | else |
| 3597 | { |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 3598 | bool was_restarted = ProcessEventData::GetRestartedFromEvent (event_ptr); |
| 3599 | bool should_resume = false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3600 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3601 | // It makes no sense to ask "ShouldStop" if we've already been restarted... |
| 3602 | // Asking the thread list is also not likely to go well, since we are running again. |
| 3603 | // So in that case just report the event. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3604 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3605 | if (!was_restarted) |
| 3606 | should_resume = m_thread_list.ShouldStop (event_ptr) == false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3607 | |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 3608 | if (was_restarted || should_resume || m_resume_requested) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3609 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3610 | Vote stop_vote = m_thread_list.ShouldReportStop (event_ptr); |
| 3611 | if (log) |
| 3612 | log->Printf ("Process::ShouldBroadcastEvent: should_stop: %i state: %s was_restarted: %i stop_vote: %d.", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3613 | should_resume, StateAsCString(state), |
| 3614 | was_restarted, stop_vote); |
| 3615 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3616 | switch (stop_vote) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3617 | { |
| 3618 | case eVoteYes: |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3619 | return_value = true; |
| 3620 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3621 | case eVoteNoOpinion: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3622 | case eVoteNo: |
| 3623 | return_value = false; |
| 3624 | break; |
| 3625 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3626 | |
Jim Ingham | cb95f34 | 2012-09-05 21:13:56 +0000 | [diff] [blame] | 3627 | if (!was_restarted) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3628 | { |
| 3629 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3630 | log->Printf ("Process::ShouldBroadcastEvent (%p) Restarting process from state: %s", |
| 3631 | static_cast<void*>(event_ptr), |
| 3632 | StateAsCString(state)); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3633 | ProcessEventData::SetRestartedInEvent(event_ptr, true); |
Jim Ingham | cb95f34 | 2012-09-05 21:13:56 +0000 | [diff] [blame] | 3634 | PrivateResume (); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3635 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3636 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3637 | } |
| 3638 | else |
| 3639 | { |
| 3640 | return_value = true; |
| 3641 | SynchronouslyNotifyStateChanged (state); |
| 3642 | } |
| 3643 | } |
| 3644 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3645 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3646 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3647 | |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 3648 | // Forcing the next event delivery is a one shot deal. So reset it here. |
| 3649 | m_force_next_event_delivery = false; |
| 3650 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3651 | // We do some coalescing of events (for instance two consecutive running events get coalesced.) |
| 3652 | // But we only coalesce against events we actually broadcast. So we use m_last_broadcast_state |
| 3653 | // to track that. NB - you can't use "m_public_state.GetValue()" for that purpose, as was originally done, |
| 3654 | // because the PublicState reflects the last event pulled off the queue, and there may be several |
| 3655 | // events stacked up on the queue unserviced. So the PublicState may not reflect the last broadcasted event |
| 3656 | // yet. m_last_broadcast_state gets updated here. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3657 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3658 | if (return_value) |
| 3659 | m_last_broadcast_state = state; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3660 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3661 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3662 | log->Printf ("Process::ShouldBroadcastEvent (%p) => new state: %s, last broadcast state: %s - %s", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3663 | static_cast<void*>(event_ptr), StateAsCString(state), |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3664 | StateAsCString(m_last_broadcast_state), |
| 3665 | return_value ? "YES" : "NO"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3666 | return return_value; |
| 3667 | } |
| 3668 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3669 | |
| 3670 | bool |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 3671 | Process::StartPrivateStateThread (bool force) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3672 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3673 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3674 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3675 | bool already_running = PrivateStateThreadIsValid (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3676 | if (log) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3677 | log->Printf ("Process::%s()%s ", __FUNCTION__, already_running ? " already running" : " starting private state thread"); |
| 3678 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 3679 | if (!force && already_running) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3680 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3681 | |
| 3682 | // Create a thread that watches our internal state and controls which |
| 3683 | // events make it to clients (into the DCProcess event queue). |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 3684 | char thread_name[1024]; |
Todd Fiala | 17096d7 | 2014-07-16 19:03:16 +0000 | [diff] [blame] | 3685 | |
| 3686 | if (Host::MAX_THREAD_NAME_LENGTH <= 16) |
| 3687 | { |
| 3688 | // On platforms with abbreviated thread name lengths, choose thread names that fit within the limit. |
| 3689 | if (already_running) |
| 3690 | snprintf(thread_name, sizeof(thread_name), "intern-state-OV"); |
| 3691 | else |
| 3692 | snprintf(thread_name, sizeof(thread_name), "intern-state"); |
| 3693 | } |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 3694 | else |
Todd Fiala | 17096d7 | 2014-07-16 19:03:16 +0000 | [diff] [blame] | 3695 | { |
| 3696 | if (already_running) |
| 3697 | snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state-override(pid=%" PRIu64 ")>", GetID()); |
| 3698 | else |
| 3699 | snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state(pid=%" PRIu64 ")>", GetID()); |
| 3700 | } |
| 3701 | |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 3702 | // Create the private state thread, and start it running. |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 3703 | m_private_state_thread = Host::ThreadCreate (thread_name, Process::PrivateStateThread, this, NULL); |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 3704 | bool success = IS_VALID_LLDB_HOST_THREAD(m_private_state_thread); |
| 3705 | if (success) |
| 3706 | { |
| 3707 | ResumePrivateStateThread(); |
| 3708 | return true; |
| 3709 | } |
| 3710 | else |
| 3711 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3712 | } |
| 3713 | |
| 3714 | void |
| 3715 | Process::PausePrivateStateThread () |
| 3716 | { |
| 3717 | ControlPrivateStateThread (eBroadcastInternalStateControlPause); |
| 3718 | } |
| 3719 | |
| 3720 | void |
| 3721 | Process::ResumePrivateStateThread () |
| 3722 | { |
| 3723 | ControlPrivateStateThread (eBroadcastInternalStateControlResume); |
| 3724 | } |
| 3725 | |
| 3726 | void |
| 3727 | Process::StopPrivateStateThread () |
| 3728 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3729 | if (PrivateStateThreadIsValid ()) |
| 3730 | ControlPrivateStateThread (eBroadcastInternalStateControlStop); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3731 | else |
| 3732 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3733 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3734 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3735 | log->Printf ("Went to stop the private state thread, but it was already invalid."); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3736 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | void |
| 3740 | Process::ControlPrivateStateThread (uint32_t signal) |
| 3741 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3742 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3743 | |
| 3744 | assert (signal == eBroadcastInternalStateControlStop || |
| 3745 | signal == eBroadcastInternalStateControlPause || |
| 3746 | signal == eBroadcastInternalStateControlResume); |
| 3747 | |
| 3748 | if (log) |
Greg Clayton | 7ecb3a0 | 2011-01-22 17:43:17 +0000 | [diff] [blame] | 3749 | log->Printf ("Process::%s (signal = %d)", __FUNCTION__, signal); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3750 | |
Greg Clayton | 7ecb3a0 | 2011-01-22 17:43:17 +0000 | [diff] [blame] | 3751 | // Signal the private state thread. First we should copy this is case the |
| 3752 | // thread starts exiting since the private state thread will NULL this out |
| 3753 | // when it exits |
| 3754 | const lldb::thread_t private_state_thread = m_private_state_thread; |
Greg Clayton | 2da6d49 | 2011-02-08 01:34:25 +0000 | [diff] [blame] | 3755 | if (IS_VALID_LLDB_HOST_THREAD(private_state_thread)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3756 | { |
| 3757 | TimeValue timeout_time; |
| 3758 | bool timed_out; |
| 3759 | |
| 3760 | m_private_state_control_broadcaster.BroadcastEvent (signal, NULL); |
| 3761 | |
| 3762 | timeout_time = TimeValue::Now(); |
| 3763 | timeout_time.OffsetWithSeconds(2); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3764 | if (log) |
| 3765 | log->Printf ("Sending control event of type: %d.", signal); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3766 | m_private_state_control_wait.WaitForValueEqualTo (true, &timeout_time, &timed_out); |
| 3767 | m_private_state_control_wait.SetValue (false, eBroadcastNever); |
| 3768 | |
| 3769 | if (signal == eBroadcastInternalStateControlStop) |
| 3770 | { |
| 3771 | if (timed_out) |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3772 | { |
| 3773 | Error error; |
| 3774 | Host::ThreadCancel (private_state_thread, &error); |
| 3775 | if (log) |
| 3776 | log->Printf ("Timed out responding to the control event, cancel got error: \"%s\".", error.AsCString()); |
| 3777 | } |
| 3778 | else |
| 3779 | { |
| 3780 | if (log) |
| 3781 | log->Printf ("The control event killed the private state thread without having to cancel."); |
| 3782 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3783 | |
| 3784 | thread_result_t result = NULL; |
Greg Clayton | 7ecb3a0 | 2011-01-22 17:43:17 +0000 | [diff] [blame] | 3785 | Host::ThreadJoin (private_state_thread, &result, NULL); |
Greg Clayton | 49182ed | 2010-07-22 18:34:21 +0000 | [diff] [blame] | 3786 | m_private_state_thread = LLDB_INVALID_HOST_THREAD; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3787 | } |
| 3788 | } |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3789 | else |
| 3790 | { |
| 3791 | if (log) |
| 3792 | log->Printf ("Private state thread already dead, no need to signal it to stop."); |
| 3793 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3794 | } |
| 3795 | |
| 3796 | void |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 3797 | Process::SendAsyncInterrupt () |
| 3798 | { |
| 3799 | if (PrivateStateThreadIsValid()) |
| 3800 | m_private_state_broadcaster.BroadcastEvent (Process::eBroadcastBitInterrupt, NULL); |
| 3801 | else |
| 3802 | BroadcastEvent (Process::eBroadcastBitInterrupt, NULL); |
| 3803 | } |
| 3804 | |
| 3805 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3806 | Process::HandlePrivateEvent (EventSP &event_sp) |
| 3807 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3808 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 3809 | m_resume_requested = false; |
| 3810 | |
Jim Ingham | aacc318 | 2012-06-06 00:29:30 +0000 | [diff] [blame] | 3811 | m_currently_handling_event.SetValue(true, eBroadcastNever); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3812 | |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 3813 | const StateType new_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3814 | |
| 3815 | // First check to see if anybody wants a shot at this event: |
Jim Ingham | 754ab98 | 2011-01-29 04:05:41 +0000 | [diff] [blame] | 3816 | if (m_next_event_action_ap.get() != NULL) |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3817 | { |
Jim Ingham | 754ab98 | 2011-01-29 04:05:41 +0000 | [diff] [blame] | 3818 | NextEventAction::EventActionResult action_result = m_next_event_action_ap->PerformAction(event_sp); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3819 | if (log) |
| 3820 | log->Printf ("Ran next event action, result was %d.", action_result); |
| 3821 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3822 | switch (action_result) |
| 3823 | { |
| 3824 | case NextEventAction::eEventActionSuccess: |
| 3825 | SetNextEventAction(NULL); |
| 3826 | break; |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 3827 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3828 | case NextEventAction::eEventActionRetry: |
| 3829 | break; |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 3830 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3831 | case NextEventAction::eEventActionExit: |
Jim Ingham | 2a5fdd4 | 2011-01-29 01:57:31 +0000 | [diff] [blame] | 3832 | // Handle Exiting Here. If we already got an exited event, |
| 3833 | // we should just propagate it. Otherwise, swallow this event, |
| 3834 | // and set our state to exit so the next event will kill us. |
| 3835 | if (new_state != eStateExited) |
| 3836 | { |
| 3837 | // FIXME: should cons up an exited event, and discard this one. |
Jim Ingham | 754ab98 | 2011-01-29 04:05:41 +0000 | [diff] [blame] | 3838 | SetExitStatus(0, m_next_event_action_ap->GetExitString()); |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 3839 | m_currently_handling_event.SetValue(false, eBroadcastAlways); |
Jim Ingham | 2a5fdd4 | 2011-01-29 01:57:31 +0000 | [diff] [blame] | 3840 | SetNextEventAction(NULL); |
| 3841 | return; |
| 3842 | } |
| 3843 | SetNextEventAction(NULL); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3844 | break; |
| 3845 | } |
| 3846 | } |
| 3847 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3848 | // See if we should broadcast this state to external clients? |
| 3849 | const bool should_broadcast = ShouldBroadcastEvent (event_sp.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3850 | |
| 3851 | if (should_broadcast) |
| 3852 | { |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3853 | const bool is_hijacked = IsHijackedForEvent(eBroadcastBitStateChanged); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3854 | if (log) |
| 3855 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3856 | log->Printf ("Process::%s (pid = %" PRIu64 ") broadcasting new state %s (old state %s) to %s", |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 3857 | __FUNCTION__, |
| 3858 | GetID(), |
| 3859 | StateAsCString(new_state), |
| 3860 | StateAsCString (GetState ()), |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3861 | is_hijacked ? "hijacked" : "public"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3862 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3863 | Process::ProcessEventData::SetUpdateStateOnRemoval(event_sp.get()); |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 3864 | if (StateIsRunningState (new_state)) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 3865 | { |
| 3866 | // Only push the input handler if we aren't fowarding events, |
| 3867 | // as this means the curses GUI is in use... |
| 3868 | if (!GetTarget().GetDebugger().IsForwardingEvents()) |
| 3869 | PushProcessIOHandler (); |
| 3870 | } |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 3871 | else if (StateIsStoppedState(new_state, false)) |
| 3872 | { |
| 3873 | if (!Process::ProcessEventData::GetRestartedFromEvent(event_sp.get())) |
| 3874 | { |
| 3875 | // If the lldb_private::Debugger is handling the events, we don't |
| 3876 | // want to pop the process IOHandler here, we want to do it when |
| 3877 | // we receive the stopped event so we can carefully control when |
| 3878 | // the process IOHandler is popped because when we stop we want to |
| 3879 | // display some text stating how and why we stopped, then maybe some |
| 3880 | // process/thread/frame info, and then we want the "(lldb) " prompt |
| 3881 | // to show up. If we pop the process IOHandler here, then we will |
| 3882 | // cause the command interpreter to become the top IOHandler after |
| 3883 | // the process pops off and it will update its prompt right away... |
| 3884 | // See the Debugger.cpp file where it calls the function as |
| 3885 | // "process_sp->PopProcessIOHandler()" to see where I am talking about. |
| 3886 | // Otherwise we end up getting overlapping "(lldb) " prompts and |
| 3887 | // garbled output. |
| 3888 | // |
| 3889 | // If we aren't handling the events in the debugger (which is indicated |
| 3890 | // by "m_target.GetDebugger().IsHandlingEvents()" returning false) or we |
| 3891 | // are hijacked, then we always pop the process IO handler manually. |
| 3892 | // Hijacking happens when the internal process state thread is running |
| 3893 | // thread plans, or when commands want to run in synchronous mode |
| 3894 | // and they call "process->WaitForProcessToStop()". An example of something |
| 3895 | // that will hijack the events is a simple expression: |
| 3896 | // |
| 3897 | // (lldb) expr (int)puts("hello") |
| 3898 | // |
| 3899 | // This will cause the internal process state thread to resume and halt |
| 3900 | // the process (and _it_ will hijack the eBroadcastBitStateChanged |
| 3901 | // events) and we do need the IO handler to be pushed and popped |
| 3902 | // correctly. |
| 3903 | |
| 3904 | if (is_hijacked || m_target.GetDebugger().IsHandlingEvents() == false) |
| 3905 | PopProcessIOHandler (); |
| 3906 | } |
| 3907 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3908 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3909 | BroadcastEvent (event_sp); |
| 3910 | } |
| 3911 | else |
| 3912 | { |
| 3913 | if (log) |
| 3914 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3915 | log->Printf ("Process::%s (pid = %" PRIu64 ") suppressing state %s (old state %s): should_broadcast == false", |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 3916 | __FUNCTION__, |
| 3917 | GetID(), |
| 3918 | StateAsCString(new_state), |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 3919 | StateAsCString (GetState ())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3920 | } |
| 3921 | } |
Jim Ingham | aacc318 | 2012-06-06 00:29:30 +0000 | [diff] [blame] | 3922 | m_currently_handling_event.SetValue(false, eBroadcastAlways); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3923 | } |
| 3924 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 3925 | thread_result_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3926 | Process::PrivateStateThread (void *arg) |
| 3927 | { |
| 3928 | Process *proc = static_cast<Process*> (arg); |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 3929 | thread_result_t result = proc->RunPrivateStateThread(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3930 | return result; |
| 3931 | } |
| 3932 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 3933 | thread_result_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3934 | Process::RunPrivateStateThread () |
| 3935 | { |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 3936 | bool control_only = true; |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3937 | m_private_state_control_wait.SetValue (false, eBroadcastNever); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3938 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3939 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3940 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3941 | log->Printf ("Process::%s (arg = %p, pid = %" PRIu64 ") thread starting...", |
| 3942 | __FUNCTION__, static_cast<void*>(this), GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3943 | |
| 3944 | bool exit_now = false; |
| 3945 | while (!exit_now) |
| 3946 | { |
| 3947 | EventSP event_sp; |
| 3948 | WaitForEventsPrivate (NULL, event_sp, control_only); |
| 3949 | if (event_sp->BroadcasterIs(&m_private_state_control_broadcaster)) |
| 3950 | { |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3951 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3952 | log->Printf ("Process::%s (arg = %p, pid = %" PRIu64 ") got a control event: %d", |
| 3953 | __FUNCTION__, static_cast<void*>(this), GetID(), |
| 3954 | event_sp->GetType()); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3955 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3956 | switch (event_sp->GetType()) |
| 3957 | { |
| 3958 | case eBroadcastInternalStateControlStop: |
| 3959 | exit_now = true; |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 3960 | break; // doing any internal state management below |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3961 | |
| 3962 | case eBroadcastInternalStateControlPause: |
| 3963 | control_only = true; |
| 3964 | break; |
| 3965 | |
| 3966 | case eBroadcastInternalStateControlResume: |
| 3967 | control_only = false; |
| 3968 | break; |
| 3969 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3970 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3971 | m_private_state_control_wait.SetValue (true, eBroadcastAlways); |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3972 | continue; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3973 | } |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 3974 | else if (event_sp->GetType() == eBroadcastBitInterrupt) |
| 3975 | { |
| 3976 | if (m_public_state.GetValue() == eStateAttaching) |
| 3977 | { |
| 3978 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3979 | log->Printf ("Process::%s (arg = %p, pid = %" PRIu64 ") woke up with an interrupt while attaching - forwarding interrupt.", |
| 3980 | __FUNCTION__, static_cast<void*>(this), |
| 3981 | GetID()); |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 3982 | BroadcastEvent (eBroadcastBitInterrupt, NULL); |
| 3983 | } |
| 3984 | else |
| 3985 | { |
| 3986 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 3987 | log->Printf ("Process::%s (arg = %p, pid = %" PRIu64 ") woke up with an interrupt - Halting.", |
| 3988 | __FUNCTION__, static_cast<void*>(this), |
| 3989 | GetID()); |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 3990 | Halt(); |
| 3991 | } |
| 3992 | continue; |
| 3993 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3994 | |
| 3995 | const StateType internal_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 3996 | |
| 3997 | if (internal_state != eStateInvalid) |
| 3998 | { |
Greg Clayton | f9b57b9 | 2013-05-10 23:48:10 +0000 | [diff] [blame] | 3999 | if (m_clear_thread_plans_on_stop && |
| 4000 | StateIsStoppedState(internal_state, true)) |
| 4001 | { |
| 4002 | m_clear_thread_plans_on_stop = false; |
| 4003 | m_thread_list.DiscardThreadPlans(); |
| 4004 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4005 | HandlePrivateEvent (event_sp); |
| 4006 | } |
| 4007 | |
Greg Clayton | 58d1c9a | 2010-10-18 04:14:23 +0000 | [diff] [blame] | 4008 | if (internal_state == eStateInvalid || |
| 4009 | internal_state == eStateExited || |
| 4010 | internal_state == eStateDetached ) |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4011 | { |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4012 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4013 | log->Printf ("Process::%s (arg = %p, pid = %" PRIu64 ") about to exit with internal state %s...", |
| 4014 | __FUNCTION__, static_cast<void*>(this), GetID(), |
| 4015 | StateAsCString(internal_state)); |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4016 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4017 | break; |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4018 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4019 | } |
| 4020 | |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 4021 | // Verify log is still enabled before attempting to write to it... |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4022 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4023 | log->Printf ("Process::%s (arg = %p, pid = %" PRIu64 ") thread exiting...", |
| 4024 | __FUNCTION__, static_cast<void*>(this), GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4025 | |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 4026 | m_public_run_lock.SetStopped(); |
Greg Clayton | 6ed9594 | 2011-01-22 07:12:45 +0000 | [diff] [blame] | 4027 | m_private_state_control_wait.SetValue (true, eBroadcastAlways); |
| 4028 | m_private_state_thread = LLDB_INVALID_HOST_THREAD; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4029 | return NULL; |
| 4030 | } |
| 4031 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4032 | //------------------------------------------------------------------ |
| 4033 | // Process Event Data |
| 4034 | //------------------------------------------------------------------ |
| 4035 | |
| 4036 | Process::ProcessEventData::ProcessEventData () : |
| 4037 | EventData (), |
| 4038 | m_process_sp (), |
| 4039 | m_state (eStateInvalid), |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 4040 | m_restarted (false), |
Jim Ingham | a860469 | 2011-05-22 21:45:01 +0000 | [diff] [blame] | 4041 | m_update_state (0), |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4042 | m_interrupted (false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4043 | { |
| 4044 | } |
| 4045 | |
| 4046 | Process::ProcessEventData::ProcessEventData (const ProcessSP &process_sp, StateType state) : |
| 4047 | EventData (), |
| 4048 | m_process_sp (process_sp), |
| 4049 | m_state (state), |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 4050 | m_restarted (false), |
Jim Ingham | a860469 | 2011-05-22 21:45:01 +0000 | [diff] [blame] | 4051 | m_update_state (0), |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4052 | m_interrupted (false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4053 | { |
| 4054 | } |
| 4055 | |
| 4056 | Process::ProcessEventData::~ProcessEventData() |
| 4057 | { |
| 4058 | } |
| 4059 | |
| 4060 | const ConstString & |
| 4061 | Process::ProcessEventData::GetFlavorString () |
| 4062 | { |
| 4063 | static ConstString g_flavor ("Process::ProcessEventData"); |
| 4064 | return g_flavor; |
| 4065 | } |
| 4066 | |
| 4067 | const ConstString & |
| 4068 | Process::ProcessEventData::GetFlavor () const |
| 4069 | { |
| 4070 | return ProcessEventData::GetFlavorString (); |
| 4071 | } |
| 4072 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4073 | void |
| 4074 | Process::ProcessEventData::DoOnRemoval (Event *event_ptr) |
| 4075 | { |
| 4076 | // This function gets called twice for each event, once when the event gets pulled |
Jim Ingham | a860469 | 2011-05-22 21:45:01 +0000 | [diff] [blame] | 4077 | // off of the private process event queue, and then any number of times, first when it gets pulled off of |
| 4078 | // the public event queue, then other times when we're pretending that this is where we stopped at the |
| 4079 | // end of expression evaluation. m_update_state is used to distinguish these |
| 4080 | // three cases; it is 0 when we're just pulling it off for private handling, |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 4081 | // and > 1 for expression evaluation, and we don't want to do the breakpoint command handling then. |
Jim Ingham | a860469 | 2011-05-22 21:45:01 +0000 | [diff] [blame] | 4082 | if (m_update_state != 1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4083 | return; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4084 | |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 4085 | m_process_sp->SetPublicState (m_state, Process::ProcessEventData::GetRestartedFromEvent(event_ptr)); |
Jim Ingham | 35878c4 | 2014-04-08 21:33:21 +0000 | [diff] [blame] | 4086 | |
| 4087 | // If this is a halt event, even if the halt stopped with some reason other than a plain interrupt (e.g. we had |
| 4088 | // already stopped for a breakpoint when the halt request came through) don't do the StopInfo actions, as they may |
| 4089 | // end up restarting the process. |
| 4090 | if (m_interrupted) |
| 4091 | return; |
| 4092 | |
| 4093 | // If we're stopped and haven't restarted, then do the StopInfo actions here: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4094 | if (m_state == eStateStopped && ! m_restarted) |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 4095 | { |
| 4096 | ThreadList &curr_thread_list = m_process_sp->GetThreadList(); |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 4097 | uint32_t num_threads = curr_thread_list.GetSize(); |
| 4098 | uint32_t idx; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 4099 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4100 | // The actions might change one of the thread's stop_info's opinions about whether we should |
| 4101 | // stop the process, so we need to query that as we go. |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 4102 | |
| 4103 | // One other complication here, is that we try to catch any case where the target has run (except for expressions) |
| 4104 | // and immediately exit, but if we get that wrong (which is possible) then the thread list might have changed, and |
| 4105 | // that would cause our iteration here to crash. We could make a copy of the thread list, but we'd really like |
| 4106 | // to also know if it has changed at all, so we make up a vector of the thread ID's and check what we get back |
| 4107 | // against this list & bag out if anything differs. |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 4108 | std::vector<uint32_t> thread_index_array(num_threads); |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 4109 | for (idx = 0; idx < num_threads; ++idx) |
| 4110 | thread_index_array[idx] = curr_thread_list.GetThreadAtIndex(idx)->GetIndexID(); |
| 4111 | |
Jim Ingham | c7078c2 | 2012-12-13 22:24:15 +0000 | [diff] [blame] | 4112 | // Use this to track whether we should continue from here. We will only continue the target running if |
| 4113 | // no thread says we should stop. Of course if some thread's PerformAction actually sets the target running, |
| 4114 | // then it doesn't matter what the other threads say... |
| 4115 | |
| 4116 | bool still_should_stop = false; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4117 | |
Jim Ingham | 0ad7e05 | 2013-04-25 02:04:59 +0000 | [diff] [blame] | 4118 | // Sometimes - for instance if we have a bug in the stub we are talking to, we stop but no thread has a |
| 4119 | // valid stop reason. In that case we should just stop, because we have no way of telling what the right |
| 4120 | // thing to do is, and it's better to let the user decide than continue behind their backs. |
| 4121 | |
| 4122 | bool does_anybody_have_an_opinion = false; |
| 4123 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4124 | for (idx = 0; idx < num_threads; ++idx) |
| 4125 | { |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 4126 | curr_thread_list = m_process_sp->GetThreadList(); |
| 4127 | if (curr_thread_list.GetSize() != num_threads) |
| 4128 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4129 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 87c665f | 2011-12-01 20:26:15 +0000 | [diff] [blame] | 4130 | if (log) |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 4131 | log->Printf("Number of threads changed from %u to %u while processing event.", num_threads, curr_thread_list.GetSize()); |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 4132 | break; |
| 4133 | } |
| 4134 | |
| 4135 | lldb::ThreadSP thread_sp = curr_thread_list.GetThreadAtIndex(idx); |
| 4136 | |
| 4137 | if (thread_sp->GetIndexID() != thread_index_array[idx]) |
| 4138 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4139 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 87c665f | 2011-12-01 20:26:15 +0000 | [diff] [blame] | 4140 | if (log) |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 4141 | log->Printf("The thread at position %u changed from %u to %u while processing event.", |
Jim Ingham | 87c665f | 2011-12-01 20:26:15 +0000 | [diff] [blame] | 4142 | idx, |
| 4143 | thread_index_array[idx], |
| 4144 | thread_sp->GetIndexID()); |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 4145 | break; |
| 4146 | } |
| 4147 | |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 4148 | StopInfoSP stop_info_sp = thread_sp->GetStopInfo (); |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 4149 | if (stop_info_sp && stop_info_sp->IsValid()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4150 | { |
Jim Ingham | 0ad7e05 | 2013-04-25 02:04:59 +0000 | [diff] [blame] | 4151 | does_anybody_have_an_opinion = true; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4152 | bool this_thread_wants_to_stop; |
| 4153 | if (stop_info_sp->GetOverrideShouldStop()) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4154 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4155 | this_thread_wants_to_stop = stop_info_sp->GetOverriddenShouldStopValue(); |
| 4156 | } |
| 4157 | else |
| 4158 | { |
| 4159 | stop_info_sp->PerformAction(event_ptr); |
| 4160 | // The stop action might restart the target. If it does, then we want to mark that in the |
| 4161 | // event so that whoever is receiving it will know to wait for the running event and reflect |
| 4162 | // that state appropriately. |
| 4163 | // We also need to stop processing actions, since they aren't expecting the target to be running. |
| 4164 | |
| 4165 | // FIXME: we might have run. |
| 4166 | if (stop_info_sp->HasTargetRunSinceMe()) |
| 4167 | { |
| 4168 | SetRestarted (true); |
| 4169 | break; |
| 4170 | } |
| 4171 | |
| 4172 | this_thread_wants_to_stop = stop_info_sp->ShouldStop(event_ptr); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4173 | } |
Jim Ingham | c7078c2 | 2012-12-13 22:24:15 +0000 | [diff] [blame] | 4174 | |
Jim Ingham | c7078c2 | 2012-12-13 22:24:15 +0000 | [diff] [blame] | 4175 | if (still_should_stop == false) |
| 4176 | still_should_stop = this_thread_wants_to_stop; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4177 | } |
| 4178 | } |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 4179 | |
Ashok Thirumurthi | cf7c55e | 2013-04-18 14:38:20 +0000 | [diff] [blame] | 4180 | |
Jim Ingham | a8ca6e2 | 2013-05-03 23:04:37 +0000 | [diff] [blame] | 4181 | if (!GetRestarted()) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4182 | { |
Jim Ingham | 0ad7e05 | 2013-04-25 02:04:59 +0000 | [diff] [blame] | 4183 | if (!still_should_stop && does_anybody_have_an_opinion) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4184 | { |
| 4185 | // We've been asked to continue, so do that here. |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4186 | SetRestarted(true); |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 4187 | // Use the public resume method here, since this is just |
| 4188 | // extending a public resume. |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4189 | m_process_sp->PrivateResume(); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4190 | } |
| 4191 | else |
| 4192 | { |
| 4193 | // If we didn't restart, run the Stop Hooks here: |
| 4194 | // They might also restart the target, so watch for that. |
| 4195 | m_process_sp->GetTarget().RunStopHooks(); |
| 4196 | if (m_process_sp->GetPrivateState() == eStateRunning) |
| 4197 | SetRestarted(true); |
| 4198 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4199 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4200 | } |
| 4201 | } |
| 4202 | |
| 4203 | void |
| 4204 | Process::ProcessEventData::Dump (Stream *s) const |
| 4205 | { |
| 4206 | if (m_process_sp) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4207 | s->Printf(" process = %p (pid = %" PRIu64 "), ", |
| 4208 | static_cast<void*>(m_process_sp.get()), m_process_sp->GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4209 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 4210 | s->Printf("state = %s", StateAsCString(GetState())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4211 | } |
| 4212 | |
| 4213 | const Process::ProcessEventData * |
| 4214 | Process::ProcessEventData::GetEventDataFromEvent (const Event *event_ptr) |
| 4215 | { |
| 4216 | if (event_ptr) |
| 4217 | { |
| 4218 | const EventData *event_data = event_ptr->GetData(); |
| 4219 | if (event_data && event_data->GetFlavor() == ProcessEventData::GetFlavorString()) |
| 4220 | return static_cast <const ProcessEventData *> (event_ptr->GetData()); |
| 4221 | } |
| 4222 | return NULL; |
| 4223 | } |
| 4224 | |
| 4225 | ProcessSP |
| 4226 | Process::ProcessEventData::GetProcessFromEvent (const Event *event_ptr) |
| 4227 | { |
| 4228 | ProcessSP process_sp; |
| 4229 | const ProcessEventData *data = GetEventDataFromEvent (event_ptr); |
| 4230 | if (data) |
| 4231 | process_sp = data->GetProcessSP(); |
| 4232 | return process_sp; |
| 4233 | } |
| 4234 | |
| 4235 | StateType |
| 4236 | Process::ProcessEventData::GetStateFromEvent (const Event *event_ptr) |
| 4237 | { |
| 4238 | const ProcessEventData *data = GetEventDataFromEvent (event_ptr); |
| 4239 | if (data == NULL) |
| 4240 | return eStateInvalid; |
| 4241 | else |
| 4242 | return data->GetState(); |
| 4243 | } |
| 4244 | |
| 4245 | bool |
| 4246 | Process::ProcessEventData::GetRestartedFromEvent (const Event *event_ptr) |
| 4247 | { |
| 4248 | const ProcessEventData *data = GetEventDataFromEvent (event_ptr); |
| 4249 | if (data == NULL) |
| 4250 | return false; |
| 4251 | else |
| 4252 | return data->GetRestarted(); |
| 4253 | } |
| 4254 | |
| 4255 | void |
| 4256 | Process::ProcessEventData::SetRestartedInEvent (Event *event_ptr, bool new_value) |
| 4257 | { |
| 4258 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 4259 | if (data != NULL) |
| 4260 | data->SetRestarted(new_value); |
| 4261 | } |
| 4262 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4263 | size_t |
| 4264 | Process::ProcessEventData::GetNumRestartedReasons(const Event *event_ptr) |
| 4265 | { |
| 4266 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 4267 | if (data != NULL) |
| 4268 | return data->GetNumRestartedReasons(); |
| 4269 | else |
| 4270 | return 0; |
| 4271 | } |
| 4272 | |
| 4273 | const char * |
| 4274 | Process::ProcessEventData::GetRestartedReasonAtIndex(const Event *event_ptr, size_t idx) |
| 4275 | { |
| 4276 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 4277 | if (data != NULL) |
| 4278 | return data->GetRestartedReasonAtIndex(idx); |
| 4279 | else |
| 4280 | return NULL; |
| 4281 | } |
| 4282 | |
| 4283 | void |
| 4284 | Process::ProcessEventData::AddRestartedReason (Event *event_ptr, const char *reason) |
| 4285 | { |
| 4286 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 4287 | if (data != NULL) |
| 4288 | data->AddRestartedReason(reason); |
| 4289 | } |
| 4290 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4291 | bool |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4292 | Process::ProcessEventData::GetInterruptedFromEvent (const Event *event_ptr) |
| 4293 | { |
| 4294 | const ProcessEventData *data = GetEventDataFromEvent (event_ptr); |
| 4295 | if (data == NULL) |
| 4296 | return false; |
| 4297 | else |
| 4298 | return data->GetInterrupted (); |
| 4299 | } |
| 4300 | |
| 4301 | void |
| 4302 | Process::ProcessEventData::SetInterruptedInEvent (Event *event_ptr, bool new_value) |
| 4303 | { |
| 4304 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 4305 | if (data != NULL) |
| 4306 | data->SetInterrupted(new_value); |
| 4307 | } |
| 4308 | |
| 4309 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4310 | Process::ProcessEventData::SetUpdateStateOnRemoval (Event *event_ptr) |
| 4311 | { |
| 4312 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 4313 | if (data) |
| 4314 | { |
| 4315 | data->SetUpdateStateOnRemoval(); |
| 4316 | return true; |
| 4317 | } |
| 4318 | return false; |
| 4319 | } |
| 4320 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 4321 | lldb::TargetSP |
| 4322 | Process::CalculateTarget () |
| 4323 | { |
| 4324 | return m_target.shared_from_this(); |
| 4325 | } |
| 4326 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4327 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 4328 | Process::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4329 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4330 | exe_ctx.SetTargetPtr (&m_target); |
| 4331 | exe_ctx.SetProcessPtr (this); |
| 4332 | exe_ctx.SetThreadPtr(NULL); |
| 4333 | exe_ctx.SetFramePtr (NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4334 | } |
| 4335 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 4336 | //uint32_t |
| 4337 | //Process::ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids) |
| 4338 | //{ |
| 4339 | // return 0; |
| 4340 | //} |
| 4341 | // |
| 4342 | //ArchSpec |
| 4343 | //Process::GetArchSpecForExistingProcess (lldb::pid_t pid) |
| 4344 | //{ |
| 4345 | // return Host::GetArchSpecForExistingProcess (pid); |
| 4346 | //} |
| 4347 | // |
| 4348 | //ArchSpec |
| 4349 | //Process::GetArchSpecForExistingProcess (const char *process_name) |
| 4350 | //{ |
| 4351 | // return Host::GetArchSpecForExistingProcess (process_name); |
| 4352 | //} |
| 4353 | // |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4354 | void |
| 4355 | Process::AppendSTDOUT (const char * s, size_t len) |
| 4356 | { |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 4357 | Mutex::Locker locker (m_stdio_communication_mutex); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4358 | m_stdout_data.append (s, len); |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 4359 | BroadcastEventIfUnique (eBroadcastBitSTDOUT, new ProcessEventData (shared_from_this(), GetState())); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4360 | } |
| 4361 | |
| 4362 | void |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 4363 | Process::AppendSTDERR (const char * s, size_t len) |
| 4364 | { |
| 4365 | Mutex::Locker locker (m_stdio_communication_mutex); |
| 4366 | m_stderr_data.append (s, len); |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 4367 | BroadcastEventIfUnique (eBroadcastBitSTDERR, new ProcessEventData (shared_from_this(), GetState())); |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 4370 | void |
Han Ming Ong | 91ed6b8 | 2013-06-24 18:15:05 +0000 | [diff] [blame] | 4371 | Process::BroadcastAsyncProfileData(const std::string &one_profile_data) |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 4372 | { |
| 4373 | Mutex::Locker locker (m_profile_data_comm_mutex); |
Han Ming Ong | 91ed6b8 | 2013-06-24 18:15:05 +0000 | [diff] [blame] | 4374 | m_profile_data.push_back(one_profile_data); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 4375 | BroadcastEventIfUnique (eBroadcastBitProfileData, new ProcessEventData (shared_from_this(), GetState())); |
| 4376 | } |
| 4377 | |
| 4378 | size_t |
| 4379 | Process::GetAsyncProfileData (char *buf, size_t buf_size, Error &error) |
| 4380 | { |
| 4381 | Mutex::Locker locker(m_profile_data_comm_mutex); |
Han Ming Ong | 929a94f | 2012-11-29 22:14:45 +0000 | [diff] [blame] | 4382 | if (m_profile_data.empty()) |
| 4383 | return 0; |
Han Ming Ong | 91ed6b8 | 2013-06-24 18:15:05 +0000 | [diff] [blame] | 4384 | |
| 4385 | std::string &one_profile_data = m_profile_data.front(); |
| 4386 | size_t bytes_available = one_profile_data.size(); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 4387 | if (bytes_available > 0) |
| 4388 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4389 | Log *log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 4390 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4391 | log->Printf ("Process::GetProfileData (buf = %p, size = %" PRIu64 ")", |
| 4392 | static_cast<void*>(buf), |
| 4393 | static_cast<uint64_t>(buf_size)); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 4394 | if (bytes_available > buf_size) |
| 4395 | { |
Han Ming Ong | 91ed6b8 | 2013-06-24 18:15:05 +0000 | [diff] [blame] | 4396 | memcpy(buf, one_profile_data.c_str(), buf_size); |
| 4397 | one_profile_data.erase(0, buf_size); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 4398 | bytes_available = buf_size; |
| 4399 | } |
| 4400 | else |
| 4401 | { |
Han Ming Ong | 91ed6b8 | 2013-06-24 18:15:05 +0000 | [diff] [blame] | 4402 | memcpy(buf, one_profile_data.c_str(), bytes_available); |
Han Ming Ong | 929a94f | 2012-11-29 22:14:45 +0000 | [diff] [blame] | 4403 | m_profile_data.erase(m_profile_data.begin()); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 4404 | } |
| 4405 | } |
| 4406 | return bytes_available; |
| 4407 | } |
| 4408 | |
| 4409 | |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 4410 | //------------------------------------------------------------------ |
| 4411 | // Process STDIO |
| 4412 | //------------------------------------------------------------------ |
| 4413 | |
| 4414 | size_t |
| 4415 | Process::GetSTDOUT (char *buf, size_t buf_size, Error &error) |
| 4416 | { |
| 4417 | Mutex::Locker locker(m_stdio_communication_mutex); |
| 4418 | size_t bytes_available = m_stdout_data.size(); |
| 4419 | if (bytes_available > 0) |
| 4420 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4421 | Log *log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 4422 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4423 | log->Printf ("Process::GetSTDOUT (buf = %p, size = %" PRIu64 ")", |
| 4424 | static_cast<void*>(buf), |
| 4425 | static_cast<uint64_t>(buf_size)); |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 4426 | if (bytes_available > buf_size) |
| 4427 | { |
| 4428 | memcpy(buf, m_stdout_data.c_str(), buf_size); |
| 4429 | m_stdout_data.erase(0, buf_size); |
| 4430 | bytes_available = buf_size; |
| 4431 | } |
| 4432 | else |
| 4433 | { |
| 4434 | memcpy(buf, m_stdout_data.c_str(), bytes_available); |
| 4435 | m_stdout_data.clear(); |
| 4436 | } |
| 4437 | } |
| 4438 | return bytes_available; |
| 4439 | } |
| 4440 | |
| 4441 | |
| 4442 | size_t |
| 4443 | Process::GetSTDERR (char *buf, size_t buf_size, Error &error) |
| 4444 | { |
| 4445 | Mutex::Locker locker(m_stdio_communication_mutex); |
| 4446 | size_t bytes_available = m_stderr_data.size(); |
| 4447 | if (bytes_available > 0) |
| 4448 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4449 | Log *log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 4450 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4451 | log->Printf ("Process::GetSTDERR (buf = %p, size = %" PRIu64 ")", |
| 4452 | static_cast<void*>(buf), |
| 4453 | static_cast<uint64_t>(buf_size)); |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 4454 | if (bytes_available > buf_size) |
| 4455 | { |
| 4456 | memcpy(buf, m_stderr_data.c_str(), buf_size); |
| 4457 | m_stderr_data.erase(0, buf_size); |
| 4458 | bytes_available = buf_size; |
| 4459 | } |
| 4460 | else |
| 4461 | { |
| 4462 | memcpy(buf, m_stderr_data.c_str(), bytes_available); |
| 4463 | m_stderr_data.clear(); |
| 4464 | } |
| 4465 | } |
| 4466 | return bytes_available; |
| 4467 | } |
| 4468 | |
| 4469 | void |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4470 | Process::STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len) |
| 4471 | { |
| 4472 | Process *process = (Process *) baton; |
| 4473 | process->AppendSTDOUT (static_cast<const char *>(src), src_len); |
| 4474 | } |
| 4475 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4476 | class IOHandlerProcessSTDIO : |
| 4477 | public IOHandler |
| 4478 | { |
| 4479 | public: |
| 4480 | IOHandlerProcessSTDIO (Process *process, |
| 4481 | int write_fd) : |
| 4482 | IOHandler(process->GetTarget().GetDebugger()), |
| 4483 | m_process (process), |
| 4484 | m_read_file (), |
| 4485 | m_write_file (write_fd, false), |
Greg Clayton | 100eb93 | 2014-07-02 21:10:39 +0000 | [diff] [blame] | 4486 | m_pipe () |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4487 | { |
| 4488 | m_read_file.SetDescriptor(GetInputFD(), false); |
| 4489 | } |
| 4490 | |
| 4491 | virtual |
| 4492 | ~IOHandlerProcessSTDIO () |
| 4493 | { |
| 4494 | |
| 4495 | } |
| 4496 | |
| 4497 | bool |
| 4498 | OpenPipes () |
| 4499 | { |
Greg Clayton | 100eb93 | 2014-07-02 21:10:39 +0000 | [diff] [blame] | 4500 | if (m_pipe.IsValid()) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4501 | return true; |
Greg Clayton | 100eb93 | 2014-07-02 21:10:39 +0000 | [diff] [blame] | 4502 | return m_pipe.Open(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4503 | } |
| 4504 | |
| 4505 | void |
| 4506 | ClosePipes() |
| 4507 | { |
Greg Clayton | 100eb93 | 2014-07-02 21:10:39 +0000 | [diff] [blame] | 4508 | m_pipe.Close(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4509 | } |
| 4510 | |
| 4511 | // Each IOHandler gets to run until it is done. It should read data |
| 4512 | // from the "in" and place output into "out" and "err and return |
| 4513 | // when done. |
| 4514 | virtual void |
| 4515 | Run () |
| 4516 | { |
| 4517 | if (m_read_file.IsValid() && m_write_file.IsValid()) |
| 4518 | { |
| 4519 | SetIsDone(false); |
| 4520 | if (OpenPipes()) |
| 4521 | { |
| 4522 | const int read_fd = m_read_file.GetDescriptor(); |
Greg Clayton | 100eb93 | 2014-07-02 21:10:39 +0000 | [diff] [blame] | 4523 | const int pipe_read_fd = m_pipe.GetReadFileDescriptor(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4524 | TerminalState terminal_state; |
| 4525 | terminal_state.Save (read_fd, false); |
| 4526 | Terminal terminal(read_fd); |
| 4527 | terminal.SetCanonical(false); |
| 4528 | terminal.SetEcho(false); |
Deepak Panickal | 914b8d9 | 2014-01-31 18:48:46 +0000 | [diff] [blame] | 4529 | // FD_ZERO, FD_SET are not supported on windows |
Hafiz Abid Qadeer | 6eff101 | 2014-03-12 10:45:23 +0000 | [diff] [blame] | 4530 | #ifndef _WIN32 |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4531 | while (!GetIsDone()) |
| 4532 | { |
| 4533 | fd_set read_fdset; |
| 4534 | FD_ZERO (&read_fdset); |
| 4535 | FD_SET (read_fd, &read_fdset); |
| 4536 | FD_SET (pipe_read_fd, &read_fdset); |
| 4537 | const int nfds = std::max<int>(read_fd, pipe_read_fd) + 1; |
| 4538 | int num_set_fds = select (nfds, &read_fdset, NULL, NULL, NULL); |
| 4539 | if (num_set_fds < 0) |
| 4540 | { |
| 4541 | const int select_errno = errno; |
| 4542 | |
| 4543 | if (select_errno != EINTR) |
| 4544 | SetIsDone(true); |
| 4545 | } |
| 4546 | else if (num_set_fds > 0) |
| 4547 | { |
| 4548 | char ch = 0; |
| 4549 | size_t n; |
| 4550 | if (FD_ISSET (read_fd, &read_fdset)) |
| 4551 | { |
| 4552 | n = 1; |
| 4553 | if (m_read_file.Read(&ch, n).Success() && n == 1) |
| 4554 | { |
| 4555 | if (m_write_file.Write(&ch, n).Fail() || n != 1) |
| 4556 | SetIsDone(true); |
| 4557 | } |
| 4558 | else |
| 4559 | SetIsDone(true); |
| 4560 | } |
| 4561 | if (FD_ISSET (pipe_read_fd, &read_fdset)) |
| 4562 | { |
| 4563 | // Consume the interrupt byte |
Greg Clayton | 100eb93 | 2014-07-02 21:10:39 +0000 | [diff] [blame] | 4564 | if (m_pipe.Read (&ch, 1) == 1) |
Greg Clayton | 19e1135 | 2014-02-26 22:47:33 +0000 | [diff] [blame] | 4565 | { |
Greg Clayton | 100eb93 | 2014-07-02 21:10:39 +0000 | [diff] [blame] | 4566 | switch (ch) |
| 4567 | { |
| 4568 | case 'q': |
| 4569 | SetIsDone(true); |
| 4570 | break; |
| 4571 | case 'i': |
| 4572 | if (StateIsRunningState(m_process->GetState())) |
| 4573 | m_process->Halt(); |
| 4574 | break; |
| 4575 | } |
Greg Clayton | 19e1135 | 2014-02-26 22:47:33 +0000 | [diff] [blame] | 4576 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4577 | } |
| 4578 | } |
| 4579 | } |
Deepak Panickal | 914b8d9 | 2014-01-31 18:48:46 +0000 | [diff] [blame] | 4580 | #endif |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4581 | terminal_state.Restore(); |
| 4582 | |
| 4583 | } |
| 4584 | else |
| 4585 | SetIsDone(true); |
| 4586 | } |
| 4587 | else |
| 4588 | SetIsDone(true); |
| 4589 | } |
| 4590 | |
| 4591 | // Hide any characters that have been displayed so far so async |
| 4592 | // output can be displayed. Refresh() will be called after the |
| 4593 | // output has been displayed. |
| 4594 | virtual void |
| 4595 | Hide () |
| 4596 | { |
| 4597 | |
| 4598 | } |
| 4599 | // Called when the async output has been received in order to update |
| 4600 | // the input reader (refresh the prompt and redisplay any current |
| 4601 | // line(s) that are being edited |
| 4602 | virtual void |
| 4603 | Refresh () |
| 4604 | { |
| 4605 | |
| 4606 | } |
Greg Clayton | e68f5d6 | 2014-02-24 22:50:57 +0000 | [diff] [blame] | 4607 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4608 | virtual void |
Greg Clayton | e68f5d6 | 2014-02-24 22:50:57 +0000 | [diff] [blame] | 4609 | Cancel () |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4610 | { |
Greg Clayton | 19e1135 | 2014-02-26 22:47:33 +0000 | [diff] [blame] | 4611 | char ch = 'q'; // Send 'q' for quit |
Greg Clayton | 100eb93 | 2014-07-02 21:10:39 +0000 | [diff] [blame] | 4612 | m_pipe.Write (&ch, 1); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4613 | } |
Greg Clayton | e68f5d6 | 2014-02-24 22:50:57 +0000 | [diff] [blame] | 4614 | |
Greg Clayton | f0066ad | 2014-05-02 00:45:31 +0000 | [diff] [blame] | 4615 | virtual bool |
Greg Clayton | e68f5d6 | 2014-02-24 22:50:57 +0000 | [diff] [blame] | 4616 | Interrupt () |
| 4617 | { |
Greg Clayton | 19e1135 | 2014-02-26 22:47:33 +0000 | [diff] [blame] | 4618 | // Do only things that are safe to do in an interrupt context (like in |
| 4619 | // a SIGINT handler), like write 1 byte to a file descriptor. This will |
| 4620 | // interrupt the IOHandlerProcessSTDIO::Run() and we can look at the byte |
| 4621 | // that was written to the pipe and then call m_process->Halt() from a |
| 4622 | // much safer location in code. |
Greg Clayton | 0fdd3ae | 2014-07-16 21:05:41 +0000 | [diff] [blame] | 4623 | if (m_active) |
| 4624 | { |
| 4625 | char ch = 'i'; // Send 'i' for interrupt |
| 4626 | return m_pipe.Write (&ch, 1) == 1; |
| 4627 | } |
| 4628 | else |
| 4629 | { |
| 4630 | // This IOHandler might be pushed on the stack, but not being run currently |
| 4631 | // so do the right thing if we aren't actively watching for STDIN by sending |
| 4632 | // the interrupt to the process. Otherwise the write to the pipe above would |
| 4633 | // do nothing. This can happen when the command interpreter is running and |
| 4634 | // gets a "expression ...". It will be on the IOHandler thread and sending |
| 4635 | // the input is complete to the delegate which will cause the expression to |
| 4636 | // run, which will push the process IO handler, but not run it. |
| 4637 | |
| 4638 | if (StateIsRunningState(m_process->GetState())) |
| 4639 | { |
| 4640 | m_process->SendAsyncInterrupt(); |
| 4641 | return true; |
| 4642 | } |
| 4643 | } |
| 4644 | return false; |
Greg Clayton | e68f5d6 | 2014-02-24 22:50:57 +0000 | [diff] [blame] | 4645 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4646 | |
| 4647 | virtual void |
| 4648 | GotEOF() |
| 4649 | { |
| 4650 | |
| 4651 | } |
| 4652 | |
| 4653 | protected: |
| 4654 | Process *m_process; |
| 4655 | File m_read_file; // Read from this file (usually actual STDIN for LLDB |
| 4656 | File m_write_file; // Write to this file (usually the master pty for getting io to debuggee) |
Greg Clayton | 100eb93 | 2014-07-02 21:10:39 +0000 | [diff] [blame] | 4657 | Pipe m_pipe; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4658 | }; |
| 4659 | |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4660 | void |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4661 | Process::SetSTDIOFileDescriptor (int fd) |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4662 | { |
| 4663 | // First set up the Read Thread for reading/handling process I/O |
| 4664 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4665 | std::unique_ptr<ConnectionFileDescriptor> conn_ap (new ConnectionFileDescriptor (fd, true)); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4666 | |
| 4667 | if (conn_ap.get()) |
| 4668 | { |
| 4669 | m_stdio_communication.SetConnection (conn_ap.release()); |
| 4670 | if (m_stdio_communication.IsConnected()) |
| 4671 | { |
| 4672 | m_stdio_communication.SetReadThreadBytesReceivedCallback (STDIOReadThreadBytesReceived, this); |
| 4673 | m_stdio_communication.StartReadThread(); |
| 4674 | |
| 4675 | // Now read thread is set up, set up input reader. |
| 4676 | |
| 4677 | if (!m_process_input_reader.get()) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4678 | m_process_input_reader.reset (new IOHandlerProcessSTDIO (this, fd)); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4679 | } |
| 4680 | } |
| 4681 | } |
| 4682 | |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 4683 | bool |
Greg Clayton | 6fea17e | 2014-03-03 19:15:20 +0000 | [diff] [blame] | 4684 | Process::ProcessIOHandlerIsActive () |
| 4685 | { |
| 4686 | IOHandlerSP io_handler_sp (m_process_input_reader); |
| 4687 | if (io_handler_sp) |
| 4688 | return m_target.GetDebugger().IsTopIOHandler (io_handler_sp); |
| 4689 | return false; |
| 4690 | } |
| 4691 | bool |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4692 | Process::PushProcessIOHandler () |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4693 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4694 | IOHandlerSP io_handler_sp (m_process_input_reader); |
| 4695 | if (io_handler_sp) |
| 4696 | { |
| 4697 | io_handler_sp->SetIsDone(false); |
| 4698 | m_target.GetDebugger().PushIOHandler (io_handler_sp); |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 4699 | return true; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4700 | } |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 4701 | return false; |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4702 | } |
| 4703 | |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 4704 | bool |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4705 | Process::PopProcessIOHandler () |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4706 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4707 | IOHandlerSP io_handler_sp (m_process_input_reader); |
| 4708 | if (io_handler_sp) |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 4709 | return m_target.GetDebugger().PopIOHandler (io_handler_sp); |
| 4710 | return false; |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4711 | } |
| 4712 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 4713 | // The process needs to know about installed plug-ins |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 4714 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 4715 | Process::SettingsInitialize () |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4716 | { |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 4717 | Thread::SettingsInitialize (); |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 4718 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4719 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 4720 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 4721 | Process::SettingsTerminate () |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 4722 | { |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 4723 | Thread::SettingsTerminate (); |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 4724 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4725 | |
Jim Ingham | 1624a2d | 2014-05-05 02:26:40 +0000 | [diff] [blame] | 4726 | ExpressionResults |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4727 | Process::RunThreadPlan (ExecutionContext &exe_ctx, |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4728 | lldb::ThreadPlanSP &thread_plan_sp, |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 4729 | const EvaluateExpressionOptions &options, |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4730 | Stream &errors) |
| 4731 | { |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 4732 | ExpressionResults return_value = eExpressionSetupError; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4733 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 4734 | if (thread_plan_sp.get() == NULL) |
| 4735 | { |
| 4736 | errors.Printf("RunThreadPlan called with empty thread plan."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 4737 | return eExpressionSetupError; |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 4738 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4739 | |
Jim Ingham | 7d7931d | 2013-03-28 00:05:34 +0000 | [diff] [blame] | 4740 | if (!thread_plan_sp->ValidatePlan(NULL)) |
| 4741 | { |
| 4742 | errors.Printf ("RunThreadPlan called with an invalid thread plan."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 4743 | return eExpressionSetupError; |
Jim Ingham | 7d7931d | 2013-03-28 00:05:34 +0000 | [diff] [blame] | 4744 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4745 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4746 | if (exe_ctx.GetProcessPtr() != this) |
| 4747 | { |
| 4748 | errors.Printf("RunThreadPlan called on wrong process."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 4749 | return eExpressionSetupError; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 4753 | if (thread == NULL) |
| 4754 | { |
| 4755 | errors.Printf("RunThreadPlan called with invalid thread."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 4756 | return eExpressionSetupError; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4757 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4758 | |
Jim Ingham | 17e5c4e | 2011-05-17 22:24:54 +0000 | [diff] [blame] | 4759 | // We rely on the thread plan we are running returning "PlanCompleted" if when it successfully completes. |
| 4760 | // For that to be true the plan can't be private - since private plans suppress themselves in the |
| 4761 | // GetCompletedPlan call. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4762 | |
Jim Ingham | 17e5c4e | 2011-05-17 22:24:54 +0000 | [diff] [blame] | 4763 | bool orig_plan_private = thread_plan_sp->GetPrivate(); |
| 4764 | thread_plan_sp->SetPrivate(false); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4765 | |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 4766 | if (m_private_state.GetValue() != eStateStopped) |
| 4767 | { |
| 4768 | errors.Printf ("RunThreadPlan called while the private state was not stopped."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 4769 | return eExpressionSetupError; |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 4770 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4771 | |
Jim Ingham | 6624384 | 2011-08-13 00:56:10 +0000 | [diff] [blame] | 4772 | // Save the thread & frame from the exe_ctx for restoration after we run |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4773 | const uint32_t thread_idx_id = thread->GetIndexID(); |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 4774 | StackFrameSP selected_frame_sp = thread->GetSelectedFrame(); |
Jim Ingham | 11b0e05 | 2013-02-19 23:22:45 +0000 | [diff] [blame] | 4775 | if (!selected_frame_sp) |
| 4776 | { |
| 4777 | thread->SetSelectedFrame(0); |
| 4778 | selected_frame_sp = thread->GetSelectedFrame(); |
| 4779 | if (!selected_frame_sp) |
| 4780 | { |
| 4781 | errors.Printf("RunThreadPlan called without a selected frame on thread %d", thread_idx_id); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 4782 | return eExpressionSetupError; |
Jim Ingham | 11b0e05 | 2013-02-19 23:22:45 +0000 | [diff] [blame] | 4783 | } |
| 4784 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4785 | |
Jim Ingham | 11b0e05 | 2013-02-19 23:22:45 +0000 | [diff] [blame] | 4786 | StackID ctx_frame_id = selected_frame_sp->GetStackID(); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4787 | |
| 4788 | // N.B. Running the target may unset the currently selected thread and frame. We don't want to do that either, |
| 4789 | // so we should arrange to reset them as well. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4790 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4791 | lldb::ThreadSP selected_thread_sp = GetThreadList().GetSelectedThread(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4792 | |
Jim Ingham | 6624384 | 2011-08-13 00:56:10 +0000 | [diff] [blame] | 4793 | uint32_t selected_tid; |
| 4794 | StackID selected_stack_id; |
Greg Clayton | 762f713 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 4795 | if (selected_thread_sp) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4796 | { |
| 4797 | selected_tid = selected_thread_sp->GetIndexID(); |
Jim Ingham | 6624384 | 2011-08-13 00:56:10 +0000 | [diff] [blame] | 4798 | selected_stack_id = selected_thread_sp->GetSelectedFrame()->GetStackID(); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4799 | } |
| 4800 | else |
| 4801 | { |
| 4802 | selected_tid = LLDB_INVALID_THREAD_ID; |
| 4803 | } |
| 4804 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4805 | lldb::thread_t backup_private_state_thread = LLDB_INVALID_HOST_THREAD; |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4806 | lldb::StateType old_state; |
| 4807 | lldb::ThreadPlanSP stopper_base_plan_sp; |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4808 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4809 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4810 | if (Host::GetCurrentThread() == m_private_state_thread) |
| 4811 | { |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4812 | // Yikes, we are running on the private state thread! So we can't wait for public events on this thread, since |
| 4813 | // we are the thread that is generating public events. |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4814 | // The simplest thing to do is to spin up a temporary thread to handle private state thread events while |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4815 | // we are fielding public events here. |
| 4816 | if (log) |
Jason Molenda | d251c9d | 2012-11-17 01:41:04 +0000 | [diff] [blame] | 4817 | log->Printf ("Running thread plan on private state thread, spinning up another state thread to handle the events."); |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4818 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4819 | backup_private_state_thread = m_private_state_thread; |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4820 | |
| 4821 | // One other bit of business: we want to run just this thread plan and anything it pushes, and then stop, |
| 4822 | // returning control here. |
| 4823 | // But in the normal course of things, the plan above us on the stack would be given a shot at the stop |
| 4824 | // event before deciding to stop, and we don't want that. So we insert a "stopper" base plan on the stack |
| 4825 | // before the plan we want to run. Since base plans always stop and return control to the user, that will |
| 4826 | // do just what we want. |
| 4827 | stopper_base_plan_sp.reset(new ThreadPlanBase (*thread)); |
| 4828 | thread->QueueThreadPlan (stopper_base_plan_sp, false); |
| 4829 | // Have to make sure our public state is stopped, since otherwise the reporting logic below doesn't work correctly. |
| 4830 | old_state = m_public_state.GetValue(); |
| 4831 | m_public_state.SetValueNoLock(eStateStopped); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4832 | |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4833 | // Now spin up the private state thread: |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4834 | StartPrivateStateThread(true); |
| 4835 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4836 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4837 | thread->QueueThreadPlan(thread_plan_sp, false); // This used to pass "true" does that make sense? |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4838 | |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 4839 | if (options.GetDebug()) |
| 4840 | { |
| 4841 | // In this case, we aren't actually going to run, we just want to stop right away. |
| 4842 | // Flush this thread so we will refetch the stacks and show the correct backtrace. |
| 4843 | // FIXME: To make this prettier we should invent some stop reason for this, but that |
| 4844 | // is only cosmetic, and this functionality is only of use to lldb developers who can |
| 4845 | // live with not pretty... |
| 4846 | thread->Flush(); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 4847 | return eExpressionStoppedForDebug; |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 4848 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4849 | |
Jim Ingham | 1e7a9ee | 2011-01-23 21:14:08 +0000 | [diff] [blame] | 4850 | Listener listener("lldb.process.listener.run-thread-plan"); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4851 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 4852 | lldb::EventSP event_to_broadcast_sp; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4853 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 4854 | { |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 4855 | // This process event hijacker Hijacks the Public events and its destructor makes sure that the process events get |
| 4856 | // restored on exit to the function. |
| 4857 | // |
| 4858 | // If the event needs to propagate beyond the hijacker (e.g., the process exits during execution), then the event |
| 4859 | // is put into event_to_broadcast_sp for rebroadcasting. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4860 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 4861 | ProcessEventHijacker run_thread_plan_hijacker (*this, &listener); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4862 | |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4863 | if (log) |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4864 | { |
| 4865 | StreamString s; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 4866 | thread_plan_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4867 | log->Printf ("Process::RunThreadPlan(): Resuming thread %u - 0x%4.4" PRIx64 " to run thread plan \"%s\".", |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 4868 | thread->GetIndexID(), |
| 4869 | thread->GetID(), |
| 4870 | s.GetData()); |
| 4871 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4872 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 4873 | bool got_event; |
| 4874 | lldb::EventSP event_sp; |
| 4875 | lldb::StateType stop_state = lldb::eStateInvalid; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4876 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 4877 | TimeValue* timeout_ptr = NULL; |
| 4878 | TimeValue real_timeout; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4879 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4880 | bool before_first_timeout = true; // This is set to false the first time that we have to halt the target. |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 4881 | bool do_resume = true; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 4882 | bool handle_running_event = true; |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 4883 | const uint64_t default_one_thread_timeout_usec = 250000; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4884 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4885 | // This is just for accounting: |
| 4886 | uint32_t num_resumes = 0; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4887 | |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 4888 | uint32_t timeout_usec = options.GetTimeoutUsec(); |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 4889 | uint32_t one_thread_timeout_usec; |
| 4890 | uint32_t all_threads_timeout_usec = 0; |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 4891 | |
| 4892 | // If we are going to run all threads the whole time, or if we are only going to run one thread, |
| 4893 | // then we don't need the first timeout. So we set the final timeout, and pretend we are after the |
| 4894 | // first timeout already. |
| 4895 | |
| 4896 | if (!options.GetStopOthers() || !options.GetTryAllThreads()) |
Jim Ingham | 286fb1e | 2014-02-28 02:52:06 +0000 | [diff] [blame] | 4897 | { |
| 4898 | before_first_timeout = false; |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 4899 | one_thread_timeout_usec = 0; |
| 4900 | all_threads_timeout_usec = timeout_usec; |
Jim Ingham | 286fb1e | 2014-02-28 02:52:06 +0000 | [diff] [blame] | 4901 | } |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 4902 | else |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4903 | { |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 4904 | uint32_t option_one_thread_timeout = options.GetOneThreadTimeoutUsec(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4905 | |
Jim Ingham | 914f4e7 | 2014-03-28 21:58:28 +0000 | [diff] [blame] | 4906 | // If the overall wait is forever, then we only need to set the one thread timeout: |
| 4907 | if (timeout_usec == 0) |
| 4908 | { |
Ed Maste | 801335c | 2014-03-31 19:28:14 +0000 | [diff] [blame] | 4909 | if (option_one_thread_timeout != 0) |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 4910 | one_thread_timeout_usec = option_one_thread_timeout; |
Jim Ingham | 914f4e7 | 2014-03-28 21:58:28 +0000 | [diff] [blame] | 4911 | else |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 4912 | one_thread_timeout_usec = default_one_thread_timeout_usec; |
Jim Ingham | 914f4e7 | 2014-03-28 21:58:28 +0000 | [diff] [blame] | 4913 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4914 | else |
| 4915 | { |
Jim Ingham | 914f4e7 | 2014-03-28 21:58:28 +0000 | [diff] [blame] | 4916 | // Otherwise, if the one thread timeout is set, make sure it isn't longer than the overall timeout, |
| 4917 | // and use it, otherwise use half the total timeout, bounded by the default_one_thread_timeout_usec. |
| 4918 | uint64_t computed_one_thread_timeout; |
| 4919 | if (option_one_thread_timeout != 0) |
| 4920 | { |
| 4921 | if (timeout_usec < option_one_thread_timeout) |
| 4922 | { |
| 4923 | errors.Printf("RunThreadPlan called without one thread timeout greater than total timeout"); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 4924 | return eExpressionSetupError; |
Jim Ingham | 914f4e7 | 2014-03-28 21:58:28 +0000 | [diff] [blame] | 4925 | } |
| 4926 | computed_one_thread_timeout = option_one_thread_timeout; |
| 4927 | } |
| 4928 | else |
| 4929 | { |
| 4930 | computed_one_thread_timeout = timeout_usec / 2; |
| 4931 | if (computed_one_thread_timeout > default_one_thread_timeout_usec) |
| 4932 | computed_one_thread_timeout = default_one_thread_timeout_usec; |
| 4933 | } |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 4934 | one_thread_timeout_usec = computed_one_thread_timeout; |
| 4935 | all_threads_timeout_usec = timeout_usec - one_thread_timeout_usec; |
| 4936 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4937 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4938 | } |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 4939 | |
| 4940 | if (log) |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 4941 | log->Printf ("Stop others: %u, try all: %u, before_first: %u, one thread: %" PRIu32 " - all threads: %" PRIu32 ".\n", |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 4942 | options.GetStopOthers(), |
| 4943 | options.GetTryAllThreads(), |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 4944 | before_first_timeout, |
| 4945 | one_thread_timeout_usec, |
| 4946 | all_threads_timeout_usec); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4947 | |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 4948 | // This isn't going to work if there are unfetched events on the queue. |
| 4949 | // Are there cases where we might want to run the remaining events here, and then try to |
| 4950 | // call the function? That's probably being too tricky for our own good. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4951 | |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 4952 | Event *other_events = listener.PeekAtNextEvent(); |
| 4953 | if (other_events != NULL) |
| 4954 | { |
| 4955 | errors.Printf("Calling RunThreadPlan with pending events on the queue."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 4956 | return eExpressionSetupError; |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 4957 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4958 | |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 4959 | // We also need to make sure that the next event is delivered. We might be calling a function as part of |
| 4960 | // a thread plan, in which case the last delivered event could be the running event, and we don't want |
| 4961 | // event coalescing to cause us to lose OUR running event... |
| 4962 | ForceNextEventDelivery(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4963 | |
Jim Ingham | 8559a35 | 2012-11-26 23:52:18 +0000 | [diff] [blame] | 4964 | // This while loop must exit out the bottom, there's cleanup that we need to do when we are done. |
| 4965 | // So don't call return anywhere within it. |
Jim Ingham | 35878c4 | 2014-04-08 21:33:21 +0000 | [diff] [blame] | 4966 | |
| 4967 | #ifdef LLDB_RUN_THREAD_HALT_WITH_EVENT |
| 4968 | // It's pretty much impossible to write test cases for things like: |
| 4969 | // One thread timeout expires, I go to halt, but the process already stopped |
| 4970 | // on the function call stop breakpoint. Turning on this define will make us not |
| 4971 | // fetch the first event till after the halt. So if you run a quick function, it will have |
| 4972 | // completed, and the completion event will be waiting, when you interrupt for halt. |
| 4973 | // The expression evaluation should still succeed. |
| 4974 | bool miss_first_event = true; |
| 4975 | #endif |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 4976 | TimeValue one_thread_timeout; |
| 4977 | TimeValue final_timeout; |
| 4978 | |
Jim Ingham | 35878c4 | 2014-04-08 21:33:21 +0000 | [diff] [blame] | 4979 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 4980 | while (1) |
| 4981 | { |
| 4982 | // We usually want to resume the process if we get to the top of the loop. |
| 4983 | // The only exception is if we get two running events with no intervening |
| 4984 | // stop, which can happen, we will just wait for then next stop event. |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4985 | if (log) |
| 4986 | log->Printf ("Top of while loop: do_resume: %i handle_running_event: %i before_first_timeout: %i.", |
| 4987 | do_resume, |
| 4988 | handle_running_event, |
| 4989 | before_first_timeout); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4990 | |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 4991 | if (do_resume || handle_running_event) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 4992 | { |
| 4993 | // Do the initial resume and wait for the running event before going further. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4994 | |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 4995 | if (do_resume) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 4996 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4997 | num_resumes++; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 4998 | Error resume_error = PrivateResume (); |
| 4999 | if (!resume_error.Success()) |
| 5000 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5001 | errors.Printf("Error resuming inferior the %d time: \"%s\".\n", |
| 5002 | num_resumes, |
| 5003 | resume_error.AsCString()); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5004 | return_value = eExpressionSetupError; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5005 | break; |
| 5006 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5007 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5008 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5009 | TimeValue resume_timeout = TimeValue::Now(); |
| 5010 | resume_timeout.OffsetWithMicroSeconds(500000); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5011 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5012 | got_event = listener.WaitForEvent(&resume_timeout, event_sp); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5013 | if (!got_event) |
| 5014 | { |
| 5015 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5016 | log->Printf ("Process::RunThreadPlan(): didn't get any event after resume %d, exiting.", |
| 5017 | num_resumes); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5018 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5019 | errors.Printf("Didn't get any event after resume %d, exiting.", num_resumes); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5020 | return_value = eExpressionSetupError; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5021 | break; |
| 5022 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5023 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5024 | stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5025 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5026 | if (stop_state != eStateRunning) |
| 5027 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5028 | bool restarted = false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5029 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5030 | if (stop_state == eStateStopped) |
| 5031 | { |
| 5032 | restarted = Process::ProcessEventData::GetRestartedFromEvent(event_sp.get()); |
| 5033 | if (log) |
| 5034 | log->Printf("Process::RunThreadPlan(): didn't get running event after " |
| 5035 | "resume %d, got %s instead (restarted: %i, do_resume: %i, handle_running_event: %i).", |
| 5036 | num_resumes, |
| 5037 | StateAsCString(stop_state), |
| 5038 | restarted, |
| 5039 | do_resume, |
| 5040 | handle_running_event); |
| 5041 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5042 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5043 | if (restarted) |
| 5044 | { |
| 5045 | // This is probably an overabundance of caution, I don't think I should ever get a stopped & restarted |
| 5046 | // event here. But if I do, the best thing is to Halt and then get out of here. |
| 5047 | Halt(); |
| 5048 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5049 | |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 5050 | errors.Printf("Didn't get running event after initial resume, got %s instead.", |
| 5051 | StateAsCString(stop_state)); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5052 | return_value = eExpressionSetupError; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5053 | break; |
| 5054 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5055 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5056 | if (log) |
| 5057 | log->PutCString ("Process::RunThreadPlan(): resuming succeeded."); |
| 5058 | // We need to call the function synchronously, so spin waiting for it to return. |
| 5059 | // If we get interrupted while executing, we're going to lose our context, and |
| 5060 | // won't be able to gather the result at this point. |
| 5061 | // We set the timeout AFTER the resume, since the resume takes some time and we |
| 5062 | // don't want to charge that to the timeout. |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5063 | } |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 5064 | else |
| 5065 | { |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5066 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5067 | log->PutCString ("Process::RunThreadPlan(): waiting for next event."); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 5068 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5069 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5070 | if (before_first_timeout) |
| 5071 | { |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5072 | if (options.GetTryAllThreads()) |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5073 | { |
| 5074 | one_thread_timeout = TimeValue::Now(); |
| 5075 | one_thread_timeout.OffsetWithMicroSeconds(one_thread_timeout_usec); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5076 | timeout_ptr = &one_thread_timeout; |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5077 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5078 | else |
| 5079 | { |
| 5080 | if (timeout_usec == 0) |
| 5081 | timeout_ptr = NULL; |
| 5082 | else |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5083 | { |
| 5084 | final_timeout = TimeValue::Now(); |
| 5085 | final_timeout.OffsetWithMicroSeconds (timeout_usec); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5086 | timeout_ptr = &final_timeout; |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5087 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5088 | } |
| 5089 | } |
| 5090 | else |
| 5091 | { |
| 5092 | if (timeout_usec == 0) |
| 5093 | timeout_ptr = NULL; |
| 5094 | else |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5095 | { |
| 5096 | final_timeout = TimeValue::Now(); |
| 5097 | final_timeout.OffsetWithMicroSeconds (all_threads_timeout_usec); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5098 | timeout_ptr = &final_timeout; |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5099 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5100 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5101 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5102 | do_resume = true; |
| 5103 | handle_running_event = true; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5104 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5105 | // Now wait for the process to stop again: |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5106 | event_sp.reset(); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 5107 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 5108 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 5109 | { |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5110 | if (timeout_ptr) |
| 5111 | { |
Matt Kopec | 676a487 | 2013-02-21 23:55:31 +0000 | [diff] [blame] | 5112 | log->Printf ("Process::RunThreadPlan(): about to wait - now is %" PRIu64 " - endpoint is %" PRIu64, |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5113 | TimeValue::Now().GetAsMicroSecondsSinceJan1_1970(), |
| 5114 | timeout_ptr->GetAsMicroSecondsSinceJan1_1970()); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5115 | } |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 5116 | else |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5117 | { |
| 5118 | log->Printf ("Process::RunThreadPlan(): about to wait forever."); |
| 5119 | } |
| 5120 | } |
Jim Ingham | 35878c4 | 2014-04-08 21:33:21 +0000 | [diff] [blame] | 5121 | |
| 5122 | #ifdef LLDB_RUN_THREAD_HALT_WITH_EVENT |
| 5123 | // See comment above... |
| 5124 | if (miss_first_event) |
| 5125 | { |
| 5126 | usleep(1000); |
| 5127 | miss_first_event = false; |
| 5128 | got_event = false; |
| 5129 | } |
| 5130 | else |
| 5131 | #endif |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5132 | got_event = listener.WaitForEvent (timeout_ptr, event_sp); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5133 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5134 | if (got_event) |
| 5135 | { |
| 5136 | if (event_sp.get()) |
| 5137 | { |
| 5138 | bool keep_going = false; |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5139 | if (event_sp->GetType() == eBroadcastBitInterrupt) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5140 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5141 | Halt(); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5142 | return_value = eExpressionInterrupted; |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5143 | errors.Printf ("Execution halted by user interrupt."); |
| 5144 | if (log) |
| 5145 | log->Printf ("Process::RunThreadPlan(): Got interrupted by eBroadcastBitInterrupted, exiting."); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5146 | break; |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5147 | } |
| 5148 | else |
| 5149 | { |
| 5150 | stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 5151 | if (log) |
| 5152 | log->Printf("Process::RunThreadPlan(): in while loop, got event: %s.", StateAsCString(stop_state)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5153 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5154 | switch (stop_state) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5155 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5156 | case lldb::eStateStopped: |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5157 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5158 | // We stopped, figure out what we are going to do now. |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5159 | ThreadSP thread_sp = GetThreadList().FindThreadByIndexID (thread_idx_id); |
| 5160 | if (!thread_sp) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5161 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5162 | // Ooh, our thread has vanished. Unlikely that this was successful execution... |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5163 | if (log) |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5164 | log->Printf ("Process::RunThreadPlan(): execution completed but our thread (index-id=%u) has vanished.", thread_idx_id); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5165 | return_value = eExpressionInterrupted; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5166 | } |
| 5167 | else |
| 5168 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5169 | // If we were restarted, we just need to go back up to fetch another event. |
| 5170 | if (Process::ProcessEventData::GetRestartedFromEvent(event_sp.get())) |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5171 | { |
| 5172 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5173 | { |
| 5174 | log->Printf ("Process::RunThreadPlan(): Got a stop and restart, so we'll continue waiting."); |
| 5175 | } |
| 5176 | keep_going = true; |
| 5177 | do_resume = false; |
| 5178 | handle_running_event = true; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5179 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5180 | } |
| 5181 | else |
| 5182 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5183 | StopInfoSP stop_info_sp (thread_sp->GetStopInfo ()); |
| 5184 | StopReason stop_reason = eStopReasonInvalid; |
| 5185 | if (stop_info_sp) |
| 5186 | stop_reason = stop_info_sp->GetStopReason(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5187 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5188 | // FIXME: We only check if the stop reason is plan complete, should we make sure that |
| 5189 | // it is OUR plan that is complete? |
| 5190 | if (stop_reason == eStopReasonPlanComplete) |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5191 | { |
| 5192 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5193 | log->PutCString ("Process::RunThreadPlan(): execution completed successfully."); |
| 5194 | // Now mark this plan as private so it doesn't get reported as the stop reason |
| 5195 | // after this point. |
| 5196 | if (thread_plan_sp) |
| 5197 | thread_plan_sp->SetPrivate (orig_plan_private); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5198 | return_value = eExpressionCompleted; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5199 | } |
| 5200 | else |
| 5201 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5202 | // Something restarted the target, so just wait for it to stop for real. |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5203 | if (stop_reason == eStopReasonBreakpoint) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5204 | { |
| 5205 | if (log) |
| 5206 | log->Printf ("Process::RunThreadPlan() stopped for breakpoint: %s.", stop_info_sp->GetDescription()); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5207 | return_value = eExpressionHitBreakpoint; |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5208 | if (!options.DoesIgnoreBreakpoints()) |
Sean Callanan | 4b388c9 | 2013-07-30 19:54:09 +0000 | [diff] [blame] | 5209 | { |
| 5210 | event_to_broadcast_sp = event_sp; |
| 5211 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5212 | } |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5213 | else |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5214 | { |
| 5215 | if (log) |
| 5216 | log->PutCString ("Process::RunThreadPlan(): thread plan didn't successfully complete."); |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5217 | if (!options.DoesUnwindOnError()) |
Sean Callanan | 4b388c9 | 2013-07-30 19:54:09 +0000 | [diff] [blame] | 5218 | event_to_broadcast_sp = event_sp; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5219 | return_value = eExpressionInterrupted; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5220 | } |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5221 | } |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5222 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5223 | } |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5224 | } |
| 5225 | break; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5226 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5227 | case lldb::eStateRunning: |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5228 | // This shouldn't really happen, but sometimes we do get two running events without an |
| 5229 | // intervening stop, and in that case we should just go back to waiting for the stop. |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5230 | do_resume = false; |
| 5231 | keep_going = true; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5232 | handle_running_event = false; |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5233 | break; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5234 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5235 | default: |
| 5236 | if (log) |
| 5237 | log->Printf("Process::RunThreadPlan(): execution stopped with unexpected state: %s.", StateAsCString(stop_state)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5238 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5239 | if (stop_state == eStateExited) |
| 5240 | event_to_broadcast_sp = event_sp; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5241 | |
Sean Callanan | bf154da | 2012-08-08 17:35:10 +0000 | [diff] [blame] | 5242 | errors.Printf ("Execution stopped with unexpected state.\n"); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5243 | return_value = eExpressionInterrupted; |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5244 | break; |
| 5245 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5246 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5247 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5248 | if (keep_going) |
| 5249 | continue; |
| 5250 | else |
| 5251 | break; |
| 5252 | } |
| 5253 | else |
| 5254 | { |
| 5255 | if (log) |
| 5256 | log->PutCString ("Process::RunThreadPlan(): got_event was true, but the event pointer was null. How odd..."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5257 | return_value = eExpressionInterrupted; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5258 | break; |
| 5259 | } |
| 5260 | } |
| 5261 | else |
| 5262 | { |
| 5263 | // If we didn't get an event that means we've timed out... |
| 5264 | // We will interrupt the process here. Depending on what we were asked to do we will |
| 5265 | // either exit, or try with all threads running for the same timeout. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5266 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5267 | if (log) { |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5268 | if (options.GetTryAllThreads()) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5269 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5270 | if (before_first_timeout) |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 5271 | { |
| 5272 | if (timeout_usec != 0) |
| 5273 | { |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 5274 | log->Printf ("Process::RunThreadPlan(): Running function with one thread timeout timed out, " |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5275 | "running for %" PRIu32 " usec with all threads enabled.", |
| 5276 | all_threads_timeout_usec); |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 5277 | } |
| 5278 | else |
| 5279 | { |
| 5280 | log->Printf ("Process::RunThreadPlan(): Running function with one thread timeout timed out, " |
Ed Maste | e61c7b0 | 2014-04-29 17:48:06 +0000 | [diff] [blame] | 5281 | "running forever with all threads enabled."); |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 5282 | } |
| 5283 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5284 | else |
| 5285 | log->Printf ("Process::RunThreadPlan(): Restarting function with all threads enabled " |
Jason Molenda | 6a8658a | 2013-10-27 02:32:23 +0000 | [diff] [blame] | 5286 | "and timeout: %u timed out, abandoning execution.", |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 5287 | timeout_usec); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5288 | } |
| 5289 | else |
Jason Molenda | 6a8658a | 2013-10-27 02:32:23 +0000 | [diff] [blame] | 5290 | log->Printf ("Process::RunThreadPlan(): Running function with timeout: %u timed out, " |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 5291 | "abandoning execution.", |
| 5292 | timeout_usec); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5293 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5294 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5295 | // It is possible that between the time we issued the Halt, and we get around to calling Halt the target |
| 5296 | // could have stopped. That's fine, Halt will figure that out and send the appropriate Stopped event. |
| 5297 | // BUT it is also possible that we stopped & restarted (e.g. hit a signal with "stop" set to false.) In |
| 5298 | // that case, we'll get the stopped & restarted event, and we should go back to waiting for the Halt's |
| 5299 | // stopped event. That's what this while loop does. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5300 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5301 | bool back_to_top = true; |
| 5302 | uint32_t try_halt_again = 0; |
| 5303 | bool do_halt = true; |
| 5304 | const uint32_t num_retries = 5; |
| 5305 | while (try_halt_again < num_retries) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5306 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5307 | Error halt_error; |
| 5308 | if (do_halt) |
| 5309 | { |
| 5310 | if (log) |
| 5311 | log->Printf ("Process::RunThreadPlan(): Running Halt."); |
| 5312 | halt_error = Halt(); |
| 5313 | } |
| 5314 | if (halt_error.Success()) |
| 5315 | { |
| 5316 | if (log) |
| 5317 | log->PutCString ("Process::RunThreadPlan(): Halt succeeded."); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5318 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5319 | real_timeout = TimeValue::Now(); |
| 5320 | real_timeout.OffsetWithMicroSeconds(500000); |
| 5321 | |
| 5322 | got_event = listener.WaitForEvent(&real_timeout, event_sp); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5323 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5324 | if (got_event) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5325 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5326 | stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 5327 | if (log) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5328 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5329 | log->Printf ("Process::RunThreadPlan(): Stopped with event: %s", StateAsCString(stop_state)); |
| 5330 | if (stop_state == lldb::eStateStopped |
| 5331 | && Process::ProcessEventData::GetInterruptedFromEvent(event_sp.get())) |
| 5332 | log->PutCString (" Event was the Halt interruption event."); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5333 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5334 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5335 | if (stop_state == lldb::eStateStopped) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5336 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5337 | // Between the time we initiated the Halt and the time we delivered it, the process could have |
| 5338 | // already finished its job. Check that here: |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5339 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5340 | if (thread->IsThreadPlanDone (thread_plan_sp.get())) |
| 5341 | { |
| 5342 | if (log) |
| 5343 | log->PutCString ("Process::RunThreadPlan(): Even though we timed out, the call plan was done. " |
| 5344 | "Exiting wait loop."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5345 | return_value = eExpressionCompleted; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5346 | back_to_top = false; |
| 5347 | break; |
| 5348 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5349 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5350 | if (Process::ProcessEventData::GetRestartedFromEvent(event_sp.get())) |
| 5351 | { |
| 5352 | if (log) |
| 5353 | log->PutCString ("Process::RunThreadPlan(): Went to halt but got a restarted event, there must be an un-restarted stopped event so try again... " |
| 5354 | "Exiting wait loop."); |
| 5355 | try_halt_again++; |
| 5356 | do_halt = false; |
| 5357 | continue; |
| 5358 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5359 | |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5360 | if (!options.GetTryAllThreads()) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5361 | { |
| 5362 | if (log) |
| 5363 | log->PutCString ("Process::RunThreadPlan(): try_all_threads was false, we stopped so now we're quitting."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5364 | return_value = eExpressionInterrupted; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5365 | back_to_top = false; |
| 5366 | break; |
| 5367 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5368 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5369 | if (before_first_timeout) |
| 5370 | { |
| 5371 | // Set all the other threads to run, and return to the top of the loop, which will continue; |
| 5372 | before_first_timeout = false; |
| 5373 | thread_plan_sp->SetStopOthers (false); |
| 5374 | if (log) |
| 5375 | log->PutCString ("Process::RunThreadPlan(): about to resume."); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5376 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5377 | back_to_top = true; |
| 5378 | break; |
| 5379 | } |
| 5380 | else |
| 5381 | { |
| 5382 | // Running all threads failed, so return Interrupted. |
| 5383 | if (log) |
| 5384 | log->PutCString("Process::RunThreadPlan(): running all threads timed out."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5385 | return_value = eExpressionInterrupted; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5386 | back_to_top = false; |
| 5387 | break; |
| 5388 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5389 | } |
| 5390 | } |
| 5391 | else |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5392 | { if (log) |
| 5393 | log->PutCString("Process::RunThreadPlan(): halt said it succeeded, but I got no event. " |
| 5394 | "I'm getting out of here passing Interrupted."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5395 | return_value = eExpressionInterrupted; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5396 | back_to_top = false; |
| 5397 | break; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5398 | } |
| 5399 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5400 | else |
| 5401 | { |
| 5402 | try_halt_again++; |
| 5403 | continue; |
| 5404 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5405 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5406 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5407 | if (!back_to_top || try_halt_again > num_retries) |
| 5408 | break; |
| 5409 | else |
| 5410 | continue; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5411 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5412 | } // END WAIT LOOP |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5413 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5414 | // If we had to start up a temporary private state thread to run this thread plan, shut it down now. |
| 5415 | if (IS_VALID_LLDB_HOST_THREAD(backup_private_state_thread)) |
| 5416 | { |
| 5417 | StopPrivateStateThread(); |
| 5418 | Error error; |
| 5419 | m_private_state_thread = backup_private_state_thread; |
Sean Callanan | 9a02851 | 2012-08-09 00:50:26 +0000 | [diff] [blame] | 5420 | if (stopper_base_plan_sp) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5421 | { |
| 5422 | thread->DiscardThreadPlansUpToPlan(stopper_base_plan_sp); |
| 5423 | } |
| 5424 | m_public_state.SetValueNoLock(old_state); |
| 5425 | |
| 5426 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5427 | |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5428 | // Restore the thread state if we are going to discard the plan execution. There are three cases where this |
| 5429 | // could happen: |
| 5430 | // 1) The execution successfully completed |
| 5431 | // 2) We hit a breakpoint, and ignore_breakpoints was true |
| 5432 | // 3) We got some other error, and discard_on_error was true |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5433 | bool should_unwind = (return_value == eExpressionInterrupted && options.DoesUnwindOnError()) |
| 5434 | || (return_value == eExpressionHitBreakpoint && options.DoesIgnoreBreakpoints()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5435 | |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5436 | if (return_value == eExpressionCompleted |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5437 | || should_unwind) |
Jim Ingham | 8559a35 | 2012-11-26 23:52:18 +0000 | [diff] [blame] | 5438 | { |
| 5439 | thread_plan_sp->RestoreThreadState(); |
| 5440 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5441 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5442 | // Now do some processing on the results of the run: |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5443 | if (return_value == eExpressionInterrupted || return_value == eExpressionHitBreakpoint) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5444 | { |
| 5445 | if (log) |
| 5446 | { |
| 5447 | StreamString s; |
| 5448 | if (event_sp) |
| 5449 | event_sp->Dump (&s); |
| 5450 | else |
| 5451 | { |
| 5452 | log->PutCString ("Process::RunThreadPlan(): Stop event that interrupted us is NULL."); |
| 5453 | } |
| 5454 | |
| 5455 | StreamString ts; |
| 5456 | |
| 5457 | const char *event_explanation = NULL; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5458 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5459 | do |
| 5460 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5461 | if (!event_sp) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5462 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5463 | event_explanation = "<no event>"; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5464 | break; |
| 5465 | } |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5466 | else if (event_sp->GetType() == eBroadcastBitInterrupt) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5467 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5468 | event_explanation = "<user interrupt>"; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5469 | break; |
| 5470 | } |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5471 | else |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5472 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5473 | const Process::ProcessEventData *event_data = Process::ProcessEventData::GetEventDataFromEvent (event_sp.get()); |
| 5474 | |
| 5475 | if (!event_data) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5476 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5477 | event_explanation = "<no event data>"; |
| 5478 | break; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5479 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5480 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5481 | Process *process = event_data->GetProcessSP().get(); |
| 5482 | |
| 5483 | if (!process) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5484 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5485 | event_explanation = "<no process>"; |
| 5486 | break; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5487 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5488 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5489 | ThreadList &thread_list = process->GetThreadList(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5490 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5491 | uint32_t num_threads = thread_list.GetSize(); |
| 5492 | uint32_t thread_index; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5493 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5494 | ts.Printf("<%u threads> ", num_threads); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5495 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5496 | for (thread_index = 0; |
| 5497 | thread_index < num_threads; |
| 5498 | ++thread_index) |
| 5499 | { |
| 5500 | Thread *thread = thread_list.GetThreadAtIndex(thread_index).get(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5501 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5502 | if (!thread) |
| 5503 | { |
| 5504 | ts.Printf("<?> "); |
| 5505 | continue; |
| 5506 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5507 | |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5508 | ts.Printf("<0x%4.4" PRIx64 " ", thread->GetID()); |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5509 | RegisterContext *register_context = thread->GetRegisterContext().get(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5510 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5511 | if (register_context) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5512 | ts.Printf("[ip 0x%" PRIx64 "] ", register_context->GetPC()); |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5513 | else |
| 5514 | ts.Printf("[ip unknown] "); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5515 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5516 | lldb::StopInfoSP stop_info_sp = thread->GetStopInfo(); |
| 5517 | if (stop_info_sp) |
| 5518 | { |
| 5519 | const char *stop_desc = stop_info_sp->GetDescription(); |
| 5520 | if (stop_desc) |
| 5521 | ts.PutCString (stop_desc); |
| 5522 | } |
| 5523 | ts.Printf(">"); |
| 5524 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5525 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5526 | event_explanation = ts.GetData(); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5527 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5528 | } while (0); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5529 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5530 | if (event_explanation) |
| 5531 | log->Printf("Process::RunThreadPlan(): execution interrupted: %s %s", s.GetData(), event_explanation); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5532 | else |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5533 | log->Printf("Process::RunThreadPlan(): execution interrupted: %s", s.GetData()); |
| 5534 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5535 | |
Jim Ingham | e4483cf | 2013-09-27 01:13:01 +0000 | [diff] [blame] | 5536 | if (should_unwind) |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5537 | { |
| 5538 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5539 | log->Printf ("Process::RunThreadPlan: ExecutionInterrupted - discarding thread plans up to %p.", |
| 5540 | static_cast<void*>(thread_plan_sp.get())); |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5541 | thread->DiscardThreadPlansUpToPlan (thread_plan_sp); |
| 5542 | thread_plan_sp->SetPrivate (orig_plan_private); |
| 5543 | } |
| 5544 | else |
| 5545 | { |
| 5546 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5547 | log->Printf ("Process::RunThreadPlan: ExecutionInterrupted - for plan: %p not discarding.", |
| 5548 | static_cast<void*>(thread_plan_sp.get())); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5549 | } |
| 5550 | } |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5551 | else if (return_value == eExpressionSetupError) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5552 | { |
| 5553 | if (log) |
| 5554 | log->PutCString("Process::RunThreadPlan(): execution set up error."); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5555 | |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5556 | if (options.DoesUnwindOnError()) |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 5557 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 5558 | thread->DiscardThreadPlansUpToPlan (thread_plan_sp); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 5559 | thread_plan_sp->SetPrivate (orig_plan_private); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 5560 | } |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5561 | } |
| 5562 | else |
| 5563 | { |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5564 | if (thread->IsThreadPlanDone (thread_plan_sp.get())) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5565 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 5566 | if (log) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5567 | log->PutCString("Process::RunThreadPlan(): thread plan is done"); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5568 | return_value = eExpressionCompleted; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5569 | } |
| 5570 | else if (thread->WasThreadPlanDiscarded (thread_plan_sp.get())) |
| 5571 | { |
| 5572 | if (log) |
| 5573 | log->PutCString("Process::RunThreadPlan(): thread plan was discarded"); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5574 | return_value = eExpressionDiscarded; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5575 | } |
| 5576 | else |
| 5577 | { |
| 5578 | if (log) |
| 5579 | log->PutCString("Process::RunThreadPlan(): thread plan stopped in mid course"); |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5580 | if (options.DoesUnwindOnError() && thread_plan_sp) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5581 | { |
| 5582 | if (log) |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5583 | log->PutCString("Process::RunThreadPlan(): discarding thread plan 'cause unwind_on_error is set."); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5584 | thread->DiscardThreadPlansUpToPlan (thread_plan_sp); |
| 5585 | thread_plan_sp->SetPrivate (orig_plan_private); |
| 5586 | } |
| 5587 | } |
| 5588 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5589 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5590 | // Thread we ran the function in may have gone away because we ran the target |
| 5591 | // Check that it's still there, and if it is put it back in the context. Also restore the |
| 5592 | // frame in the context if it is still present. |
| 5593 | thread = GetThreadList().FindThreadByIndexID(thread_idx_id, true).get(); |
| 5594 | if (thread) |
| 5595 | { |
| 5596 | exe_ctx.SetFrameSP (thread->GetFrameWithStackID (ctx_frame_id)); |
| 5597 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5598 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5599 | // Also restore the current process'es selected frame & thread, since this function calling may |
| 5600 | // be done behind the user's back. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5601 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5602 | if (selected_tid != LLDB_INVALID_THREAD_ID) |
| 5603 | { |
| 5604 | if (GetThreadList().SetSelectedThreadByIndexID (selected_tid) && selected_stack_id.IsValid()) |
| 5605 | { |
| 5606 | // We were able to restore the selected thread, now restore the frame: |
Daniel Malea | a012d3a | 2013-07-31 20:21:20 +0000 | [diff] [blame] | 5607 | Mutex::Locker lock(GetThreadList().GetMutex()); |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 5608 | StackFrameSP old_frame_sp = GetThreadList().GetSelectedThread()->GetFrameWithStackID(selected_stack_id); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5609 | if (old_frame_sp) |
| 5610 | GetThreadList().GetSelectedThread()->SetSelectedFrame(old_frame_sp.get()); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5611 | } |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5612 | } |
| 5613 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5614 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5615 | // If the process exited during the run of the thread plan, notify everyone. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5616 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5617 | if (event_to_broadcast_sp) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5618 | { |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5619 | if (log) |
| 5620 | log->PutCString("Process::RunThreadPlan(): rebroadcasting event."); |
| 5621 | BroadcastEvent(event_to_broadcast_sp); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5622 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5623 | |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5624 | return return_value; |
| 5625 | } |
| 5626 | |
| 5627 | const char * |
Jim Ingham | 1624a2d | 2014-05-05 02:26:40 +0000 | [diff] [blame] | 5628 | Process::ExecutionResultAsCString (ExpressionResults result) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5629 | { |
| 5630 | const char *result_name; |
| 5631 | |
| 5632 | switch (result) |
| 5633 | { |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5634 | case eExpressionCompleted: |
| 5635 | result_name = "eExpressionCompleted"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5636 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5637 | case eExpressionDiscarded: |
| 5638 | result_name = "eExpressionDiscarded"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5639 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5640 | case eExpressionInterrupted: |
| 5641 | result_name = "eExpressionInterrupted"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5642 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5643 | case eExpressionHitBreakpoint: |
| 5644 | result_name = "eExpressionHitBreakpoint"; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5645 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5646 | case eExpressionSetupError: |
| 5647 | result_name = "eExpressionSetupError"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5648 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5649 | case eExpressionParseError: |
| 5650 | result_name = "eExpressionParseError"; |
Jim Ingham | 1624a2d | 2014-05-05 02:26:40 +0000 | [diff] [blame] | 5651 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5652 | case eExpressionResultUnavailable: |
| 5653 | result_name = "eExpressionResultUnavailable"; |
Jim Ingham | 1624a2d | 2014-05-05 02:26:40 +0000 | [diff] [blame] | 5654 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5655 | case eExpressionTimedOut: |
| 5656 | result_name = "eExpressionTimedOut"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5657 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5658 | case eExpressionStoppedForDebug: |
| 5659 | result_name = "eExpressionStoppedForDebug"; |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5660 | break; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5661 | } |
| 5662 | return result_name; |
| 5663 | } |
| 5664 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5665 | void |
| 5666 | Process::GetStatus (Stream &strm) |
| 5667 | { |
| 5668 | const StateType state = GetState(); |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 5669 | if (StateIsStoppedState(state, false)) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5670 | { |
| 5671 | if (state == eStateExited) |
| 5672 | { |
| 5673 | int exit_status = GetExitStatus(); |
| 5674 | const char *exit_description = GetExitDescription(); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5675 | strm.Printf ("Process %" PRIu64 " exited with status = %i (0x%8.8x) %s\n", |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5676 | GetID(), |
| 5677 | exit_status, |
| 5678 | exit_status, |
| 5679 | exit_description ? exit_description : ""); |
| 5680 | } |
| 5681 | else |
| 5682 | { |
| 5683 | if (state == eStateConnected) |
| 5684 | strm.Printf ("Connected to remote target.\n"); |
| 5685 | else |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5686 | strm.Printf ("Process %" PRIu64 " %s\n", GetID(), StateAsCString (state)); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5687 | } |
| 5688 | } |
| 5689 | else |
| 5690 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5691 | strm.Printf ("Process %" PRIu64 " is running.\n", GetID()); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5692 | } |
| 5693 | } |
| 5694 | |
| 5695 | size_t |
| 5696 | Process::GetThreadStatus (Stream &strm, |
| 5697 | bool only_threads_with_stop_reason, |
| 5698 | uint32_t start_frame, |
| 5699 | uint32_t num_frames, |
| 5700 | uint32_t num_frames_with_source) |
| 5701 | { |
| 5702 | size_t num_thread_infos_dumped = 0; |
| 5703 | |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 5704 | // You can't hold the thread list lock while calling Thread::GetStatus. That very well might run code (e.g. if we need it |
| 5705 | // to get return values or arguments.) For that to work the process has to be able to acquire it. So instead copy the thread |
| 5706 | // ID's, and look them up one by one: |
| 5707 | |
| 5708 | uint32_t num_threads; |
| 5709 | std::vector<uint32_t> thread_index_array; |
| 5710 | //Scope for thread list locker; |
| 5711 | { |
| 5712 | Mutex::Locker locker (GetThreadList().GetMutex()); |
| 5713 | ThreadList &curr_thread_list = GetThreadList(); |
| 5714 | num_threads = curr_thread_list.GetSize(); |
| 5715 | uint32_t idx; |
| 5716 | thread_index_array.resize(num_threads); |
| 5717 | for (idx = 0; idx < num_threads; ++idx) |
| 5718 | thread_index_array[idx] = curr_thread_list.GetThreadAtIndex(idx)->GetID(); |
| 5719 | } |
| 5720 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5721 | for (uint32_t i = 0; i < num_threads; i++) |
| 5722 | { |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 5723 | ThreadSP thread_sp(GetThreadList().FindThreadByID(thread_index_array[i])); |
| 5724 | if (thread_sp) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5725 | { |
| 5726 | if (only_threads_with_stop_reason) |
| 5727 | { |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 5728 | StopInfoSP stop_info_sp = thread_sp->GetStopInfo(); |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 5729 | if (stop_info_sp.get() == NULL || !stop_info_sp->IsValid()) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5730 | continue; |
| 5731 | } |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 5732 | thread_sp->GetStatus (strm, |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5733 | start_frame, |
| 5734 | num_frames, |
| 5735 | num_frames_with_source); |
| 5736 | ++num_thread_infos_dumped; |
| 5737 | } |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 5738 | else |
| 5739 | { |
| 5740 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 5741 | if (log) |
| 5742 | log->Printf("Process::GetThreadStatus - thread 0x" PRIu64 " vanished while running Thread::GetStatus."); |
| 5743 | |
| 5744 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 5745 | } |
| 5746 | return num_thread_infos_dumped; |
| 5747 | } |
| 5748 | |
Greg Clayton | a9f40ad | 2012-02-22 04:37:26 +0000 | [diff] [blame] | 5749 | void |
| 5750 | Process::AddInvalidMemoryRegion (const LoadRange ®ion) |
| 5751 | { |
| 5752 | m_memory_cache.AddInvalidRange(region.GetRangeBase(), region.GetByteSize()); |
| 5753 | } |
| 5754 | |
| 5755 | bool |
| 5756 | Process::RemoveInvalidMemoryRange (const LoadRange ®ion) |
| 5757 | { |
| 5758 | return m_memory_cache.RemoveInvalidRange(region.GetRangeBase(), region.GetByteSize()); |
| 5759 | } |
| 5760 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 5761 | void |
| 5762 | Process::AddPreResumeAction (PreResumeActionCallback callback, void *baton) |
| 5763 | { |
| 5764 | m_pre_resume_actions.push_back(PreResumeCallbackAndBaton (callback, baton)); |
| 5765 | } |
| 5766 | |
| 5767 | bool |
| 5768 | Process::RunPreResumeActions () |
| 5769 | { |
| 5770 | bool result = true; |
| 5771 | while (!m_pre_resume_actions.empty()) |
| 5772 | { |
| 5773 | struct PreResumeCallbackAndBaton action = m_pre_resume_actions.back(); |
| 5774 | m_pre_resume_actions.pop_back(); |
| 5775 | bool this_result = action.callback (action.baton); |
| 5776 | if (result == true) result = this_result; |
| 5777 | } |
| 5778 | return result; |
| 5779 | } |
| 5780 | |
| 5781 | void |
| 5782 | Process::ClearPreResumeActions () |
| 5783 | { |
| 5784 | m_pre_resume_actions.clear(); |
| 5785 | } |
Greg Clayton | a9f40ad | 2012-02-22 04:37:26 +0000 | [diff] [blame] | 5786 | |
Greg Clayton | fa559e5 | 2012-05-18 02:38:05 +0000 | [diff] [blame] | 5787 | void |
| 5788 | Process::Flush () |
| 5789 | { |
| 5790 | m_thread_list.Flush(); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 5791 | m_extended_thread_list.Flush(); |
| 5792 | m_extended_thread_stop_id = 0; |
| 5793 | m_queue_list.Clear(); |
| 5794 | m_queue_list_stop_id = 0; |
Greg Clayton | fa559e5 | 2012-05-18 02:38:05 +0000 | [diff] [blame] | 5795 | } |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 5796 | |
| 5797 | void |
| 5798 | Process::DidExec () |
| 5799 | { |
| 5800 | Target &target = GetTarget(); |
| 5801 | target.CleanupProcess (); |
Greg Clayton | b35db63 | 2013-11-09 00:03:31 +0000 | [diff] [blame] | 5802 | target.ClearModules(false); |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 5803 | m_dynamic_checkers_ap.reset(); |
| 5804 | m_abi_sp.reset(); |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 5805 | m_system_runtime_ap.reset(); |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 5806 | m_os_ap.reset(); |
Greg Clayton | 15fc2be | 2013-05-21 01:00:52 +0000 | [diff] [blame] | 5807 | m_dyld_ap.reset(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 5808 | m_jit_loaders_ap.reset(); |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 5809 | m_image_tokens.clear(); |
| 5810 | m_allocated_memory_cache.Clear(); |
| 5811 | m_language_runtimes.clear(); |
Greg Clayton | 15fc2be | 2013-05-21 01:00:52 +0000 | [diff] [blame] | 5812 | m_thread_list.DiscardThreadPlans(); |
Greg Clayton | 15fc2be | 2013-05-21 01:00:52 +0000 | [diff] [blame] | 5813 | m_memory_cache.Clear(true); |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 5814 | DoDidExec(); |
| 5815 | CompleteAttach (); |
Greg Clayton | 095eeaa | 2013-11-05 23:28:00 +0000 | [diff] [blame] | 5816 | // Flush the process (threads and all stack frames) after running CompleteAttach() |
| 5817 | // in case the dynamic loader loaded things in new locations. |
| 5818 | Flush(); |
Greg Clayton | b35db63 | 2013-11-09 00:03:31 +0000 | [diff] [blame] | 5819 | |
| 5820 | // After we figure out what was loaded/unloaded in CompleteAttach, |
| 5821 | // we need to let the target know so it can do any cleanup it needs to. |
| 5822 | target.DidExec(); |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 5823 | } |
Greg Clayton | 095eeaa | 2013-11-05 23:28:00 +0000 | [diff] [blame] | 5824 | |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 5825 | addr_t |
| 5826 | Process::ResolveIndirectFunction(const Address *address, Error &error) |
| 5827 | { |
| 5828 | if (address == nullptr) |
| 5829 | { |
Jean-Daniel Dupas | ef37711f | 2014-02-08 20:22:05 +0000 | [diff] [blame] | 5830 | error.SetErrorString("Invalid address argument"); |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 5831 | return LLDB_INVALID_ADDRESS; |
| 5832 | } |
| 5833 | |
| 5834 | addr_t function_addr = LLDB_INVALID_ADDRESS; |
| 5835 | |
| 5836 | addr_t addr = address->GetLoadAddress(&GetTarget()); |
| 5837 | std::map<addr_t,addr_t>::const_iterator iter = m_resolved_indirect_addresses.find(addr); |
| 5838 | if (iter != m_resolved_indirect_addresses.end()) |
| 5839 | { |
| 5840 | function_addr = (*iter).second; |
| 5841 | } |
| 5842 | else |
| 5843 | { |
| 5844 | if (!InferiorCall(this, address, function_addr)) |
| 5845 | { |
| 5846 | Symbol *symbol = address->CalculateSymbolContextSymbol(); |
| 5847 | error.SetErrorStringWithFormat ("Unable to call resolver for indirect function %s", |
| 5848 | symbol ? symbol->GetName().AsCString() : "<UNKNOWN>"); |
| 5849 | function_addr = LLDB_INVALID_ADDRESS; |
| 5850 | } |
| 5851 | else |
| 5852 | { |
| 5853 | m_resolved_indirect_addresses.insert(std::pair<addr_t, addr_t>(addr, function_addr)); |
| 5854 | } |
| 5855 | } |
| 5856 | return function_addr; |
| 5857 | } |
| 5858 | |
Andrew MacPherson | eb4d060 | 2014-03-13 09:37:02 +0000 | [diff] [blame] | 5859 | void |
| 5860 | Process::ModulesDidLoad (ModuleList &module_list) |
| 5861 | { |
| 5862 | SystemRuntime *sys_runtime = GetSystemRuntime(); |
| 5863 | if (sys_runtime) |
| 5864 | { |
| 5865 | sys_runtime->ModulesDidLoad (module_list); |
| 5866 | } |
| 5867 | |
| 5868 | GetJITLoaders().ModulesDidLoad (module_list); |
| 5869 | } |