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 | |
| 10 | #include "lldb/Target/Process.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
| 12 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 13 | #include "lldb/Core/Event.h" |
| 14 | #include "lldb/Core/Debugger.h" |
| 15 | #include "lldb/Core/Log.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Module.h" |
Tamas Berghammer | 7cb18bf | 2015-03-24 11:15:23 +0000 | [diff] [blame] | 17 | #include "lldb/Core/ModuleSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Core/PluginManager.h" |
| 19 | #include "lldb/Core/State.h" |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 20 | #include "lldb/Core/StreamFile.h" |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 21 | #include "lldb/Expression/ClangUserExpression.h" |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 22 | #include "lldb/Expression/IRDynamicChecks.h" |
Zachary Turner | 93a66fc | 2014-10-06 21:22:36 +0000 | [diff] [blame] | 23 | #include "lldb/Host/ConnectionFileDescriptor.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Host/Host.h" |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 25 | #include "lldb/Host/HostInfo.h" |
Greg Clayton | 100eb93 | 2014-07-02 21:10:39 +0000 | [diff] [blame] | 26 | #include "lldb/Host/Pipe.h" |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 27 | #include "lldb/Host/Terminal.h" |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 28 | #include "lldb/Host/ThreadLauncher.h" |
Zachary Turner | 93a66fc | 2014-10-06 21:22:36 +0000 | [diff] [blame] | 29 | #include "lldb/Interpreter/CommandInterpreter.h" |
Zachary Turner | 633a29c | 2015-03-04 01:58:01 +0000 | [diff] [blame] | 30 | #include "lldb/Interpreter/OptionValueProperties.h" |
Jason Molenda | 484900b | 2015-08-10 07:55:25 +0000 | [diff] [blame] | 31 | #include "lldb/Symbol/Function.h" |
Zachary Turner | 93a66fc | 2014-10-06 21:22:36 +0000 | [diff] [blame] | 32 | #include "lldb/Symbol/Symbol.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | #include "lldb/Target/ABI.h" |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 34 | #include "lldb/Target/DynamicLoader.h" |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 35 | #include "lldb/Target/InstrumentationRuntime.h" |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 36 | #include "lldb/Target/JITLoader.h" |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 37 | #include "lldb/Target/JITLoaderList.h" |
Kuba Brecka | a51ea38 | 2014-09-06 01:33:13 +0000 | [diff] [blame] | 38 | #include "lldb/Target/MemoryHistory.h" |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 39 | #include "lldb/Target/MemoryRegionInfo.h" |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 40 | #include "lldb/Target/OperatingSystem.h" |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 41 | #include "lldb/Target/LanguageRuntime.h" |
| 42 | #include "lldb/Target/CPPLanguageRuntime.h" |
| 43 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 44 | #include "lldb/Target/Platform.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 46 | #include "lldb/Target/StopInfo.h" |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 47 | #include "lldb/Target/SystemRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | #include "lldb/Target/Target.h" |
| 49 | #include "lldb/Target/TargetList.h" |
| 50 | #include "lldb/Target/Thread.h" |
| 51 | #include "lldb/Target/ThreadPlan.h" |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 52 | #include "lldb/Target/ThreadPlanBase.h" |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 53 | #include "lldb/Target/UnixSignals.h" |
Zachary Turner | 5023257 | 2015-03-18 21:31:45 +0000 | [diff] [blame] | 54 | #include "lldb/Utility/NameMatches.h" |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 55 | #include "Plugins/Process/Utility/InferiorCallPOSIX.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | |
| 57 | using namespace lldb; |
| 58 | using namespace lldb_private; |
| 59 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 60 | |
| 61 | // Comment out line below to disable memory caching, overriding the process setting |
| 62 | // target.process.disable-memory-cache |
| 63 | #define ENABLE_MEMORY_CACHING |
| 64 | |
| 65 | #ifdef ENABLE_MEMORY_CACHING |
| 66 | #define DISABLE_MEM_CACHE_DEFAULT false |
| 67 | #else |
| 68 | #define DISABLE_MEM_CACHE_DEFAULT true |
| 69 | #endif |
| 70 | |
| 71 | class ProcessOptionValueProperties : public OptionValueProperties |
| 72 | { |
| 73 | public: |
| 74 | ProcessOptionValueProperties (const ConstString &name) : |
| 75 | OptionValueProperties (name) |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | // This constructor is used when creating ProcessOptionValueProperties when it |
| 80 | // is part of a new lldb_private::Process instance. It will copy all current |
| 81 | // global property values as needed |
| 82 | ProcessOptionValueProperties (ProcessProperties *global_properties) : |
| 83 | OptionValueProperties(*global_properties->GetValueProperties()) |
| 84 | { |
| 85 | } |
| 86 | |
| 87 | virtual const Property * |
| 88 | GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const |
| 89 | { |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 90 | // 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] | 91 | // try and grab the setting from the current process if there is one. Else we just |
| 92 | // use the one from this instance. |
| 93 | if (exe_ctx) |
| 94 | { |
| 95 | Process *process = exe_ctx->GetProcessPtr(); |
| 96 | if (process) |
| 97 | { |
| 98 | ProcessOptionValueProperties *instance_properties = static_cast<ProcessOptionValueProperties *>(process->GetValueProperties().get()); |
| 99 | if (this != instance_properties) |
| 100 | return instance_properties->ProtectedGetPropertyAtIndex (idx); |
| 101 | } |
| 102 | } |
| 103 | return ProtectedGetPropertyAtIndex (idx); |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | static PropertyDefinition |
| 108 | g_properties[] = |
| 109 | { |
| 110 | { "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] | 111 | { "extra-startup-command", OptionValue::eTypeArray , false, OptionValue::eTypeString, NULL, NULL, "A list containing extra commands understood by the particular process plugin used. " |
| 112 | "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] | 113 | { "ignore-breakpoints-in-expressions", OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, breakpoints will be ignored during expression evaluation." }, |
| 114 | { "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] | 115 | { "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] | 116 | { "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] | 117 | { "detach-keeps-stopped" , OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true, detach will attempt to keep the process stopped." }, |
Jason Molenda | f0340c9 | 2014-09-03 22:30:54 +0000 | [diff] [blame] | 118 | { "memory-cache-line-size" , OptionValue::eTypeUInt64, false, 512, NULL, NULL, "The memory cache line size" }, |
Jason Molenda | ef7d641 | 2015-08-06 03:27:10 +0000 | [diff] [blame] | 119 | { "optimization-warnings" , OptionValue::eTypeBoolean, false, true, NULL, NULL, "If true, warn when stopped in code that is optimized where stepping and variable availability may not behave as expected." }, |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 120 | { NULL , OptionValue::eTypeInvalid, false, 0, NULL, NULL, NULL } |
| 121 | }; |
| 122 | |
| 123 | enum { |
| 124 | ePropertyDisableMemCache, |
Greg Clayton | c9d645d | 2012-10-18 22:40:37 +0000 | [diff] [blame] | 125 | ePropertyExtraStartCommand, |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 126 | ePropertyIgnoreBreakpointsInExpressions, |
| 127 | ePropertyUnwindOnErrorInExpressions, |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 128 | ePropertyPythonOSPluginPath, |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 129 | ePropertyStopOnSharedLibraryEvents, |
Jason Molenda | f0340c9 | 2014-09-03 22:30:54 +0000 | [diff] [blame] | 130 | ePropertyDetachKeepsStopped, |
Jason Molenda | ef7d641 | 2015-08-06 03:27:10 +0000 | [diff] [blame] | 131 | ePropertyMemCacheLineSize, |
| 132 | ePropertyWarningOptimization |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 135 | ProcessProperties::ProcessProperties (lldb_private::Process *process) : |
| 136 | Properties (), |
| 137 | m_process (process) // Can be NULL for global ProcessProperties |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 138 | { |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 139 | if (process == NULL) |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 140 | { |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 141 | // Global process properties, set them up one time |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 142 | m_collection_sp.reset (new ProcessOptionValueProperties(ConstString("process"))); |
| 143 | m_collection_sp->Initialize(g_properties); |
| 144 | m_collection_sp->AppendProperty(ConstString("thread"), |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 145 | ConstString("Settings specific to threads."), |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 146 | true, |
| 147 | Thread::GetGlobalProperties()->GetValueProperties()); |
| 148 | } |
| 149 | else |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 150 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 151 | m_collection_sp.reset (new ProcessOptionValueProperties(Process::GetGlobalProperties().get())); |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 152 | m_collection_sp->SetValueChangedCallback(ePropertyPythonOSPluginPath, ProcessProperties::OptionValueChangedCallback, this); |
| 153 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | ProcessProperties::~ProcessProperties() |
| 157 | { |
| 158 | } |
| 159 | |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 160 | void |
| 161 | ProcessProperties::OptionValueChangedCallback (void *baton, OptionValue *option_value) |
| 162 | { |
| 163 | ProcessProperties *properties = (ProcessProperties *)baton; |
| 164 | if (properties->m_process) |
| 165 | properties->m_process->LoadOperatingSystemPlugin(true); |
| 166 | } |
| 167 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 168 | bool |
| 169 | ProcessProperties::GetDisableMemoryCache() const |
| 170 | { |
| 171 | const uint32_t idx = ePropertyDisableMemCache; |
| 172 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 173 | } |
| 174 | |
Jason Molenda | f0340c9 | 2014-09-03 22:30:54 +0000 | [diff] [blame] | 175 | uint64_t |
| 176 | ProcessProperties::GetMemoryCacheLineSize() const |
| 177 | { |
| 178 | const uint32_t idx = ePropertyMemCacheLineSize; |
| 179 | return m_collection_sp->GetPropertyAtIndexAsUInt64 (NULL, idx, g_properties[idx].default_uint_value); |
| 180 | } |
| 181 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 182 | Args |
| 183 | ProcessProperties::GetExtraStartupCommands () const |
| 184 | { |
| 185 | Args args; |
| 186 | const uint32_t idx = ePropertyExtraStartCommand; |
| 187 | m_collection_sp->GetPropertyAtIndexAsArgs(NULL, idx, args); |
| 188 | return args; |
| 189 | } |
| 190 | |
| 191 | void |
| 192 | ProcessProperties::SetExtraStartupCommands (const Args &args) |
| 193 | { |
| 194 | const uint32_t idx = ePropertyExtraStartCommand; |
| 195 | m_collection_sp->SetPropertyAtIndexFromArgs(NULL, idx, args); |
| 196 | } |
| 197 | |
Greg Clayton | c9d645d | 2012-10-18 22:40:37 +0000 | [diff] [blame] | 198 | FileSpec |
| 199 | ProcessProperties::GetPythonOSPluginPath () const |
| 200 | { |
| 201 | const uint32_t idx = ePropertyPythonOSPluginPath; |
| 202 | return m_collection_sp->GetPropertyAtIndexAsFileSpec(NULL, idx); |
| 203 | } |
| 204 | |
| 205 | void |
| 206 | ProcessProperties::SetPythonOSPluginPath (const FileSpec &file) |
| 207 | { |
| 208 | const uint32_t idx = ePropertyPythonOSPluginPath; |
| 209 | m_collection_sp->SetPropertyAtIndexAsFileSpec(NULL, idx, file); |
| 210 | } |
| 211 | |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 212 | |
| 213 | bool |
| 214 | ProcessProperties::GetIgnoreBreakpointsInExpressions () const |
| 215 | { |
| 216 | const uint32_t idx = ePropertyIgnoreBreakpointsInExpressions; |
| 217 | return m_collection_sp->GetPropertyAtIndexAsBoolean(NULL, idx, g_properties[idx].default_uint_value != 0); |
| 218 | } |
| 219 | |
| 220 | void |
| 221 | ProcessProperties::SetIgnoreBreakpointsInExpressions (bool ignore) |
| 222 | { |
| 223 | const uint32_t idx = ePropertyIgnoreBreakpointsInExpressions; |
| 224 | m_collection_sp->SetPropertyAtIndexAsBoolean(NULL, idx, ignore); |
| 225 | } |
| 226 | |
| 227 | bool |
| 228 | ProcessProperties::GetUnwindOnErrorInExpressions () const |
| 229 | { |
| 230 | const uint32_t idx = ePropertyUnwindOnErrorInExpressions; |
| 231 | return m_collection_sp->GetPropertyAtIndexAsBoolean(NULL, idx, g_properties[idx].default_uint_value != 0); |
| 232 | } |
| 233 | |
| 234 | void |
| 235 | ProcessProperties::SetUnwindOnErrorInExpressions (bool ignore) |
| 236 | { |
| 237 | const uint32_t idx = ePropertyUnwindOnErrorInExpressions; |
| 238 | m_collection_sp->SetPropertyAtIndexAsBoolean(NULL, idx, ignore); |
| 239 | } |
| 240 | |
Jim Ingham | 2995077 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 241 | bool |
| 242 | ProcessProperties::GetStopOnSharedLibraryEvents () const |
| 243 | { |
| 244 | const uint32_t idx = ePropertyStopOnSharedLibraryEvents; |
| 245 | return m_collection_sp->GetPropertyAtIndexAsBoolean(NULL, idx, g_properties[idx].default_uint_value != 0); |
| 246 | } |
| 247 | |
| 248 | void |
| 249 | ProcessProperties::SetStopOnSharedLibraryEvents (bool stop) |
| 250 | { |
| 251 | const uint32_t idx = ePropertyStopOnSharedLibraryEvents; |
| 252 | m_collection_sp->SetPropertyAtIndexAsBoolean(NULL, idx, stop); |
| 253 | } |
| 254 | |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 255 | bool |
| 256 | ProcessProperties::GetDetachKeepsStopped () const |
| 257 | { |
| 258 | const uint32_t idx = ePropertyDetachKeepsStopped; |
| 259 | return m_collection_sp->GetPropertyAtIndexAsBoolean(NULL, idx, g_properties[idx].default_uint_value != 0); |
| 260 | } |
| 261 | |
| 262 | void |
| 263 | ProcessProperties::SetDetachKeepsStopped (bool stop) |
| 264 | { |
| 265 | const uint32_t idx = ePropertyDetachKeepsStopped; |
| 266 | m_collection_sp->SetPropertyAtIndexAsBoolean(NULL, idx, stop); |
| 267 | } |
| 268 | |
Jason Molenda | ef7d641 | 2015-08-06 03:27:10 +0000 | [diff] [blame] | 269 | bool |
| 270 | ProcessProperties::GetWarningsOptimization () const |
| 271 | { |
| 272 | const uint32_t idx = ePropertyWarningOptimization; |
| 273 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 274 | } |
| 275 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 276 | void |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 277 | ProcessInstanceInfo::Dump (Stream &s, Platform *platform) const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 278 | { |
| 279 | const char *cstr; |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 280 | if (m_pid != LLDB_INVALID_PROCESS_ID) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 281 | s.Printf (" pid = %" PRIu64 "\n", m_pid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 282 | |
| 283 | if (m_parent_pid != LLDB_INVALID_PROCESS_ID) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 284 | s.Printf (" parent = %" PRIu64 "\n", m_parent_pid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 285 | |
| 286 | if (m_executable) |
| 287 | { |
| 288 | s.Printf (" name = %s\n", m_executable.GetFilename().GetCString()); |
| 289 | s.PutCString (" file = "); |
| 290 | m_executable.Dump(&s); |
| 291 | s.EOL(); |
| 292 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 293 | const uint32_t argc = m_arguments.GetArgumentCount(); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 294 | if (argc > 0) |
| 295 | { |
| 296 | for (uint32_t i=0; i<argc; i++) |
| 297 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 298 | const char *arg = m_arguments.GetArgumentAtIndex(i); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 299 | if (i < 10) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 300 | s.Printf (" arg[%u] = %s\n", i, arg); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 301 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 302 | s.Printf ("arg[%u] = %s\n", i, arg); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 303 | } |
| 304 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 305 | |
| 306 | const uint32_t envc = m_environment.GetArgumentCount(); |
| 307 | if (envc > 0) |
| 308 | { |
| 309 | for (uint32_t i=0; i<envc; i++) |
| 310 | { |
| 311 | const char *env = m_environment.GetArgumentAtIndex(i); |
| 312 | if (i < 10) |
| 313 | s.Printf (" env[%u] = %s\n", i, env); |
| 314 | else |
| 315 | s.Printf ("env[%u] = %s\n", i, env); |
| 316 | } |
| 317 | } |
| 318 | |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 319 | if (m_arch.IsValid()) |
| 320 | s.Printf (" arch = %s\n", m_arch.GetTriple().str().c_str()); |
| 321 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 322 | if (m_uid != UINT32_MAX) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 323 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 324 | cstr = platform->GetUserName (m_uid); |
| 325 | s.Printf (" uid = %-5u (%s)\n", m_uid, cstr ? cstr : ""); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 326 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 327 | if (m_gid != UINT32_MAX) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 328 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 329 | cstr = platform->GetGroupName (m_gid); |
| 330 | s.Printf (" gid = %-5u (%s)\n", m_gid, cstr ? cstr : ""); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 331 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 332 | if (m_euid != UINT32_MAX) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 333 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 334 | cstr = platform->GetUserName (m_euid); |
| 335 | s.Printf (" euid = %-5u (%s)\n", m_euid, cstr ? cstr : ""); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 336 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 337 | if (m_egid != UINT32_MAX) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 338 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 339 | cstr = platform->GetGroupName (m_egid); |
| 340 | s.Printf (" egid = %-5u (%s)\n", m_egid, cstr ? cstr : ""); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
| 344 | void |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 345 | ProcessInstanceInfo::DumpTableHeader (Stream &s, Platform *platform, bool show_args, bool verbose) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 346 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 347 | const char *label; |
| 348 | if (show_args || verbose) |
| 349 | label = "ARGUMENTS"; |
| 350 | else |
| 351 | label = "NAME"; |
| 352 | |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 353 | if (verbose) |
| 354 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 355 | 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] | 356 | s.PutCString ("====== ====== ========== ========== ========== ========== ======================== ============================\n"); |
| 357 | } |
| 358 | else |
| 359 | { |
Jim Ingham | 368ac22 | 2014-08-15 17:05:27 +0000 | [diff] [blame] | 360 | s.Printf ("PID PARENT USER TRIPLE %s\n", label); |
| 361 | s.PutCString ("====== ====== ========== ======================== ============================\n"); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 362 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 366 | ProcessInstanceInfo::DumpAsTableRow (Stream &s, Platform *platform, bool show_args, bool verbose) const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 367 | { |
| 368 | if (m_pid != LLDB_INVALID_PROCESS_ID) |
| 369 | { |
| 370 | const char *cstr; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 371 | s.Printf ("%-6" PRIu64 " %-6" PRIu64 " ", m_pid, m_parent_pid); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 372 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 373 | |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 374 | if (verbose) |
| 375 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 376 | cstr = platform->GetUserName (m_uid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 377 | if (cstr && cstr[0]) // Watch for empty string that indicates lookup failed |
| 378 | s.Printf ("%-10s ", cstr); |
| 379 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 380 | s.Printf ("%-10u ", m_uid); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 381 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 382 | cstr = platform->GetGroupName (m_gid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 383 | if (cstr && cstr[0]) // Watch for empty string that indicates lookup failed |
| 384 | s.Printf ("%-10s ", cstr); |
| 385 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 386 | s.Printf ("%-10u ", m_gid); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 387 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 388 | cstr = platform->GetUserName (m_euid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 389 | if (cstr && cstr[0]) // Watch for empty string that indicates lookup failed |
| 390 | s.Printf ("%-10s ", cstr); |
| 391 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 392 | s.Printf ("%-10u ", m_euid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 393 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 394 | cstr = platform->GetGroupName (m_egid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 395 | if (cstr && cstr[0]) // Watch for empty string that indicates lookup failed |
| 396 | s.Printf ("%-10s ", cstr); |
| 397 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 398 | s.Printf ("%-10u ", m_egid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 399 | s.Printf ("%-24s ", m_arch.IsValid() ? m_arch.GetTriple().str().c_str() : ""); |
| 400 | } |
| 401 | else |
| 402 | { |
Jim Ingham | 368ac22 | 2014-08-15 17:05:27 +0000 | [diff] [blame] | 403 | s.Printf ("%-10s %-24s ", |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 404 | platform->GetUserName (m_euid), |
Jim Ingham | 368ac22 | 2014-08-15 17:05:27 +0000 | [diff] [blame] | 405 | m_arch.IsValid() ? m_arch.GetTriple().str().c_str() : ""); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 408 | if (verbose || show_args) |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 409 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 410 | const uint32_t argc = m_arguments.GetArgumentCount(); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 411 | if (argc > 0) |
| 412 | { |
| 413 | for (uint32_t i=0; i<argc; i++) |
| 414 | { |
| 415 | if (i > 0) |
| 416 | s.PutChar (' '); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 417 | s.PutCString (m_arguments.GetArgumentAtIndex(i)); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | } |
| 421 | else |
| 422 | { |
| 423 | s.PutCString (GetName()); |
| 424 | } |
| 425 | |
| 426 | s.EOL(); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 430 | Error |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 431 | ProcessLaunchCommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 432 | { |
| 433 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 434 | const int short_option = m_getopt_table[option_idx].val; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 435 | |
| 436 | switch (short_option) |
| 437 | { |
| 438 | case 's': // Stop at program entry point |
| 439 | launch_info.GetFlags().Set (eLaunchFlagStopAtEntry); |
| 440 | break; |
| 441 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 442 | case 'i': // STDIN for read only |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 443 | { |
| 444 | FileAction action; |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 445 | if (action.Open(STDIN_FILENO, FileSpec{option_arg, false}, true, false)) |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 446 | launch_info.AppendFileAction (action); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 447 | break; |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 448 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 449 | |
| 450 | case 'o': // Open STDOUT for write only |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 451 | { |
| 452 | FileAction action; |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 453 | if (action.Open(STDOUT_FILENO, FileSpec{option_arg, false}, false, true)) |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 454 | launch_info.AppendFileAction (action); |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 455 | break; |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 456 | } |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 457 | |
| 458 | case 'e': // STDERR for write only |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 459 | { |
| 460 | FileAction action; |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 461 | if (action.Open(STDERR_FILENO, FileSpec{option_arg, false}, false, true)) |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 462 | launch_info.AppendFileAction (action); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 463 | break; |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 464 | } |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 465 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 466 | case 'p': // Process plug-in name |
| 467 | launch_info.SetProcessPluginName (option_arg); |
| 468 | break; |
| 469 | |
| 470 | case 'n': // Disable STDIO |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 471 | { |
| 472 | FileAction action; |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 473 | const FileSpec dev_null{"/dev/null", false}; |
| 474 | if (action.Open(STDIN_FILENO, dev_null, true, false)) |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 475 | launch_info.AppendFileAction (action); |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 476 | if (action.Open(STDOUT_FILENO, dev_null, false, true)) |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 477 | launch_info.AppendFileAction (action); |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 478 | if (action.Open(STDERR_FILENO, dev_null, false, true)) |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 479 | launch_info.AppendFileAction (action); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 480 | break; |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 481 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 482 | |
| 483 | case 'w': |
Chaoren Lin | d3173f3 | 2015-05-29 19:52:29 +0000 | [diff] [blame] | 484 | launch_info.SetWorkingDirectory(FileSpec{option_arg, false}); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 485 | break; |
| 486 | |
| 487 | case 't': // Open process in new terminal window |
| 488 | launch_info.GetFlags().Set (eLaunchFlagLaunchInTTY); |
| 489 | break; |
| 490 | |
| 491 | case 'a': |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 492 | if (!launch_info.GetArchitecture().SetTriple (option_arg, m_interpreter.GetPlatform(true).get())) |
| 493 | launch_info.GetArchitecture().SetTriple (option_arg); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 494 | break; |
| 495 | |
Todd Fiala | 5163792 | 2014-08-19 17:40:43 +0000 | [diff] [blame] | 496 | case 'A': // Disable ASLR. |
| 497 | { |
| 498 | bool success; |
| 499 | const bool disable_aslr_arg = Args::StringToBoolean (option_arg, true, &success); |
| 500 | if (success) |
| 501 | disable_aslr = disable_aslr_arg ? eLazyBoolYes : eLazyBoolNo; |
| 502 | else |
| 503 | error.SetErrorStringWithFormat ("Invalid boolean value for disable-aslr option: '%s'", option_arg ? option_arg : "<null>"); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 504 | break; |
Todd Fiala | 5163792 | 2014-08-19 17:40:43 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Enrico Granata | b38ef8c | 2015-02-20 22:20:30 +0000 | [diff] [blame] | 507 | case 'X': // shell expand args. |
Enrico Granata | d7a83a9 | 2015-02-10 03:06:24 +0000 | [diff] [blame] | 508 | { |
| 509 | bool success; |
Enrico Granata | b38ef8c | 2015-02-20 22:20:30 +0000 | [diff] [blame] | 510 | const bool expand_args = Args::StringToBoolean (option_arg, true, &success); |
Enrico Granata | d7a83a9 | 2015-02-10 03:06:24 +0000 | [diff] [blame] | 511 | if (success) |
Enrico Granata | b38ef8c | 2015-02-20 22:20:30 +0000 | [diff] [blame] | 512 | launch_info.SetShellExpandArguments(expand_args); |
Enrico Granata | d7a83a9 | 2015-02-10 03:06:24 +0000 | [diff] [blame] | 513 | else |
Enrico Granata | b38ef8c | 2015-02-20 22:20:30 +0000 | [diff] [blame] | 514 | error.SetErrorStringWithFormat ("Invalid boolean value for shell-expand-args option: '%s'", option_arg ? option_arg : "<null>"); |
Enrico Granata | d7a83a9 | 2015-02-10 03:06:24 +0000 | [diff] [blame] | 515 | break; |
| 516 | } |
| 517 | |
Todd Fiala | 5163792 | 2014-08-19 17:40:43 +0000 | [diff] [blame] | 518 | case 'c': |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 519 | if (option_arg && option_arg[0]) |
Zachary Turner | 10687b0 | 2014-10-20 17:46:43 +0000 | [diff] [blame] | 520 | launch_info.SetShell (FileSpec(option_arg, false)); |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 521 | else |
Zachary Turner | 10687b0 | 2014-10-20 17:46:43 +0000 | [diff] [blame] | 522 | launch_info.SetShell (HostInfo::GetDefaultShell()); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 523 | break; |
| 524 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 525 | case 'v': |
| 526 | launch_info.GetEnvironmentEntries().AppendArgument(option_arg); |
| 527 | break; |
| 528 | |
| 529 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 530 | error.SetErrorStringWithFormat("unrecognized short option character '%c'", short_option); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 531 | break; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 532 | } |
| 533 | return error; |
| 534 | } |
| 535 | |
| 536 | OptionDefinition |
| 537 | ProcessLaunchCommandOptions::g_option_table[] = |
| 538 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 539 | { 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."}, |
Todd Fiala | 5163792 | 2014-08-19 17:40:43 +0000 | [diff] [blame] | 540 | { LLDB_OPT_SET_ALL, false, "disable-aslr", 'A', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "Set whether to disable address space layout randomization when launching a process."}, |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 541 | { LLDB_OPT_SET_ALL, false, "plugin", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, |
| 542 | { 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."}, |
| 543 | { LLDB_OPT_SET_ALL, false, "arch", 'a', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeArchitecture, "Set the architecture for the process to launch when ambiguous."}, |
| 544 | { 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."}, |
Enrico Granata | d7a83a9 | 2015-02-10 03:06:24 +0000 | [diff] [blame] | 545 | { LLDB_OPT_SET_1|LLDB_OPT_SET_2|LLDB_OPT_SET_3, 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] | 546 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 547 | { LLDB_OPT_SET_1 , false, "stdin", 'i', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeFilename, "Redirect stdin for the process to <filename>."}, |
| 548 | { LLDB_OPT_SET_1 , false, "stdout", 'o', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeFilename, "Redirect stdout for the process to <filename>."}, |
| 549 | { 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] | 550 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 551 | { 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] | 552 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 553 | { 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."}, |
Enrico Granata | b38ef8c | 2015-02-20 22:20:30 +0000 | [diff] [blame] | 554 | { LLDB_OPT_SET_4, false, "shell-expand-args", 'X', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "Set whether to shell expand arguments to the process when launching."}, |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 555 | { 0 , false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 556 | }; |
| 557 | |
| 558 | |
| 559 | |
| 560 | bool |
| 561 | ProcessInstanceInfoMatch::NameMatches (const char *process_name) const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 562 | { |
| 563 | if (m_name_match_type == eNameMatchIgnore || process_name == NULL) |
| 564 | return true; |
| 565 | const char *match_name = m_match_info.GetName(); |
| 566 | if (!match_name) |
| 567 | return true; |
| 568 | |
| 569 | return lldb_private::NameMatches (process_name, m_name_match_type, match_name); |
| 570 | } |
| 571 | |
| 572 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 573 | ProcessInstanceInfoMatch::Matches (const ProcessInstanceInfo &proc_info) const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 574 | { |
| 575 | if (!NameMatches (proc_info.GetName())) |
| 576 | return false; |
| 577 | |
| 578 | if (m_match_info.ProcessIDIsValid() && |
| 579 | m_match_info.GetProcessID() != proc_info.GetProcessID()) |
| 580 | return false; |
| 581 | |
| 582 | if (m_match_info.ParentProcessIDIsValid() && |
| 583 | m_match_info.GetParentProcessID() != proc_info.GetParentProcessID()) |
| 584 | return false; |
| 585 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 586 | if (m_match_info.UserIDIsValid () && |
| 587 | m_match_info.GetUserID() != proc_info.GetUserID()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 588 | return false; |
| 589 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 590 | if (m_match_info.GroupIDIsValid () && |
| 591 | m_match_info.GetGroupID() != proc_info.GetGroupID()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 592 | return false; |
| 593 | |
| 594 | if (m_match_info.EffectiveUserIDIsValid () && |
| 595 | m_match_info.GetEffectiveUserID() != proc_info.GetEffectiveUserID()) |
| 596 | return false; |
| 597 | |
| 598 | if (m_match_info.EffectiveGroupIDIsValid () && |
| 599 | m_match_info.GetEffectiveGroupID() != proc_info.GetEffectiveGroupID()) |
| 600 | return false; |
| 601 | |
| 602 | if (m_match_info.GetArchitecture().IsValid() && |
Sean Callanan | bf4b7be | 2012-12-13 22:07:14 +0000 | [diff] [blame] | 603 | !m_match_info.GetArchitecture().IsCompatibleMatch(proc_info.GetArchitecture())) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 604 | return false; |
| 605 | return true; |
| 606 | } |
| 607 | |
| 608 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 609 | ProcessInstanceInfoMatch::MatchAllProcesses () const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 610 | { |
| 611 | if (m_name_match_type != eNameMatchIgnore) |
| 612 | return false; |
| 613 | |
| 614 | if (m_match_info.ProcessIDIsValid()) |
| 615 | return false; |
| 616 | |
| 617 | if (m_match_info.ParentProcessIDIsValid()) |
| 618 | return false; |
| 619 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 620 | if (m_match_info.UserIDIsValid ()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 621 | return false; |
| 622 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 623 | if (m_match_info.GroupIDIsValid ()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 624 | return false; |
| 625 | |
| 626 | if (m_match_info.EffectiveUserIDIsValid ()) |
| 627 | return false; |
| 628 | |
| 629 | if (m_match_info.EffectiveGroupIDIsValid ()) |
| 630 | return false; |
| 631 | |
| 632 | if (m_match_info.GetArchitecture().IsValid()) |
| 633 | return false; |
| 634 | |
| 635 | if (m_match_all_users) |
| 636 | return false; |
| 637 | |
| 638 | return true; |
| 639 | |
| 640 | } |
| 641 | |
| 642 | void |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 643 | ProcessInstanceInfoMatch::Clear() |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 644 | { |
| 645 | m_match_info.Clear(); |
| 646 | m_name_match_type = eNameMatchIgnore; |
| 647 | m_match_all_users = false; |
| 648 | } |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 649 | |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 650 | ProcessSP |
| 651 | 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] | 652 | { |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 653 | static uint32_t g_process_unique_id = 0; |
| 654 | |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 655 | ProcessSP process_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 656 | ProcessCreateInstance create_callback = NULL; |
| 657 | if (plugin_name) |
| 658 | { |
Greg Clayton | 57abc5d | 2013-05-10 21:47:16 +0000 | [diff] [blame] | 659 | ConstString const_plugin_name(plugin_name); |
| 660 | create_callback = PluginManager::GetProcessCreateCallbackForPluginName (const_plugin_name); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 661 | if (create_callback) |
| 662 | { |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 663 | process_sp = create_callback(target, listener, crash_file_path); |
| 664 | if (process_sp) |
| 665 | { |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 666 | if (process_sp->CanDebug(target, true)) |
| 667 | { |
| 668 | process_sp->m_process_unique_id = ++g_process_unique_id; |
| 669 | } |
| 670 | else |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 671 | process_sp.reset(); |
| 672 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | else |
| 676 | { |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 677 | for (uint32_t idx = 0; (create_callback = PluginManager::GetProcessCreateCallbackAtIndex(idx)) != NULL; ++idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 678 | { |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 679 | process_sp = create_callback(target, listener, crash_file_path); |
| 680 | if (process_sp) |
| 681 | { |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 682 | if (process_sp->CanDebug(target, false)) |
| 683 | { |
| 684 | process_sp->m_process_unique_id = ++g_process_unique_id; |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 685 | break; |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 686 | } |
| 687 | else |
| 688 | process_sp.reset(); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 689 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 690 | } |
| 691 | } |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 692 | return process_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 695 | ConstString & |
| 696 | Process::GetStaticBroadcasterClass () |
| 697 | { |
| 698 | static ConstString class_name ("lldb.process"); |
| 699 | return class_name; |
| 700 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 701 | |
| 702 | //---------------------------------------------------------------------- |
| 703 | // Process constructor |
| 704 | //---------------------------------------------------------------------- |
| 705 | Process::Process(Target &target, Listener &listener) : |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 706 | Process(target, listener, UnixSignals::Create(HostInfo::GetArchitecture())) |
Todd Fiala | 4ceced3 | 2014-08-29 17:35:57 +0000 | [diff] [blame] | 707 | { |
| 708 | // This constructor just delegates to the full Process constructor, |
| 709 | // defaulting to using the Host's UnixSignals. |
| 710 | } |
| 711 | |
| 712 | Process::Process(Target &target, Listener &listener, const UnixSignalsSP &unix_signals_sp) : |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 713 | ProcessProperties (this), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 714 | UserID (LLDB_INVALID_PROCESS_ID), |
Ilia K | 8a00a56 | 2015-03-17 16:54:52 +0000 | [diff] [blame] | 715 | Broadcaster (&(target.GetDebugger()), Process::GetStaticBroadcasterClass().AsCString()), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 716 | m_target (target), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 717 | m_public_state (eStateUnloaded), |
| 718 | m_private_state (eStateUnloaded), |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 719 | m_private_state_broadcaster (NULL, "lldb.process.internal_state_broadcaster"), |
| 720 | m_private_state_control_broadcaster (NULL, "lldb.process.internal_state_control_broadcaster"), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 721 | m_private_state_listener ("lldb.process.internal_state_listener"), |
| 722 | m_private_state_control_wait(), |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 723 | m_mod_id (), |
Greg Clayton | 949e822 | 2013-01-16 17:29:04 +0000 | [diff] [blame] | 724 | m_process_unique_id(0), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | m_thread_index_id (0), |
Han Ming Ong | c2c423e | 2013-01-08 22:10:01 +0000 | [diff] [blame] | 726 | m_thread_id_to_index_id_map (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 727 | m_exit_status (-1), |
| 728 | m_exit_string (), |
Todd Fiala | 7b0917a | 2014-09-15 20:07:33 +0000 | [diff] [blame] | 729 | m_exit_status_mutex(), |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 730 | m_thread_mutex (Mutex::eMutexTypeRecursive), |
| 731 | m_thread_list_real (this), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 732 | m_thread_list (this), |
Jason Molenda | 864f1cc | 2013-11-11 05:20:44 +0000 | [diff] [blame] | 733 | m_extended_thread_list (this), |
Jason Molenda | 4ff1326 | 2013-11-20 00:31:38 +0000 | [diff] [blame] | 734 | m_extended_thread_stop_id (0), |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 735 | m_queue_list (this), |
| 736 | m_queue_list_stop_id (0), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 737 | m_notifications (), |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 738 | m_image_tokens (), |
| 739 | m_listener (listener), |
| 740 | m_breakpoint_site_list (), |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 741 | m_dynamic_checkers_ap (), |
Todd Fiala | 4ceced3 | 2014-08-29 17:35:57 +0000 | [diff] [blame] | 742 | m_unix_signals_sp (unix_signals_sp), |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 743 | m_abi_sp (), |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 744 | m_process_input_reader (), |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 745 | m_stdio_communication ("process.stdio"), |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 746 | m_stdio_communication_mutex (Mutex::eMutexTypeRecursive), |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 747 | m_stdin_forward (false), |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 748 | m_stdout_data (), |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 749 | m_stderr_data (), |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 750 | m_profile_data_comm_mutex (Mutex::eMutexTypeRecursive), |
| 751 | m_profile_data (), |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 752 | m_iohandler_sync (0), |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 753 | m_memory_cache (*this), |
| 754 | m_allocated_memory_cache (*this), |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 755 | m_should_detach (false), |
Sean Callanan | 9053945 | 2011-09-20 23:01:51 +0000 | [diff] [blame] | 756 | m_next_event_action_ap(), |
Greg Clayton | 9624985 | 2013-04-18 16:57:27 +0000 | [diff] [blame] | 757 | m_public_run_lock (), |
Greg Clayton | 9624985 | 2013-04-18 16:57:27 +0000 | [diff] [blame] | 758 | m_private_run_lock (), |
Jim Ingham | aacc318 | 2012-06-06 00:29:30 +0000 | [diff] [blame] | 759 | m_currently_handling_event(false), |
Greg Clayton | a97c4d2 | 2014-12-09 23:31:02 +0000 | [diff] [blame] | 760 | m_stop_info_override_callback (NULL), |
Greg Clayton | c00ca31 | 2015-04-02 18:44:58 +0000 | [diff] [blame] | 761 | m_finalizing (false), |
| 762 | m_finalize_called (false), |
Greg Clayton | f9b57b9 | 2013-05-10 23:48:10 +0000 | [diff] [blame] | 763 | m_clear_thread_plans_on_stop (false), |
Greg Clayton | c00ca31 | 2015-04-02 18:44:58 +0000 | [diff] [blame] | 764 | m_force_next_event_delivery (false), |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 765 | m_last_broadcast_state (eStateInvalid), |
Jason Molenda | 69b6b63 | 2013-03-05 03:33:59 +0000 | [diff] [blame] | 766 | m_destroy_in_process (false), |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 767 | m_can_interpret_function_calls(false), |
Jason Molenda | ef7d641 | 2015-08-06 03:27:10 +0000 | [diff] [blame] | 768 | m_warnings_issued (), |
Jason Molenda | 69b6b63 | 2013-03-05 03:33:59 +0000 | [diff] [blame] | 769 | m_can_jit(eCanJITDontKnow) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 770 | { |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 771 | CheckInWithManager (); |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 772 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 773 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 774 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 775 | log->Printf ("%p Process::Process()", static_cast<void*>(this)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 776 | |
Todd Fiala | 4ceced3 | 2014-08-29 17:35:57 +0000 | [diff] [blame] | 777 | if (!m_unix_signals_sp) |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 778 | m_unix_signals_sp = std::make_shared<UnixSignals>(); |
Todd Fiala | 4ceced3 | 2014-08-29 17:35:57 +0000 | [diff] [blame] | 779 | |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 780 | SetEventName (eBroadcastBitStateChanged, "state-changed"); |
| 781 | SetEventName (eBroadcastBitInterrupt, "interrupt"); |
| 782 | SetEventName (eBroadcastBitSTDOUT, "stdout-available"); |
| 783 | SetEventName (eBroadcastBitSTDERR, "stderr-available"); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 784 | SetEventName (eBroadcastBitProfileData, "profile-data-available"); |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 785 | |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 786 | m_private_state_control_broadcaster.SetEventName (eBroadcastInternalStateControlStop , "control-stop" ); |
| 787 | m_private_state_control_broadcaster.SetEventName (eBroadcastInternalStateControlPause , "control-pause" ); |
| 788 | m_private_state_control_broadcaster.SetEventName (eBroadcastInternalStateControlResume, "control-resume"); |
| 789 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 790 | listener.StartListeningForEvents (this, |
| 791 | eBroadcastBitStateChanged | |
| 792 | eBroadcastBitInterrupt | |
| 793 | eBroadcastBitSTDOUT | |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 794 | eBroadcastBitSTDERR | |
| 795 | eBroadcastBitProfileData); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 796 | |
| 797 | m_private_state_listener.StartListeningForEvents(&m_private_state_broadcaster, |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 798 | eBroadcastBitStateChanged | |
| 799 | eBroadcastBitInterrupt); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 800 | |
| 801 | m_private_state_listener.StartListeningForEvents(&m_private_state_control_broadcaster, |
| 802 | eBroadcastInternalStateControlStop | |
| 803 | eBroadcastInternalStateControlPause | |
| 804 | eBroadcastInternalStateControlResume); |
Todd Fiala | 4ceced3 | 2014-08-29 17:35:57 +0000 | [diff] [blame] | 805 | // We need something valid here, even if just the default UnixSignalsSP. |
| 806 | assert (m_unix_signals_sp && "null m_unix_signals_sp after initialization"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | //---------------------------------------------------------------------- |
| 810 | // Destructor |
| 811 | //---------------------------------------------------------------------- |
| 812 | Process::~Process() |
| 813 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 814 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 815 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 816 | log->Printf ("%p Process::~Process()", static_cast<void*>(this)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 817 | StopPrivateStateThread(); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 818 | |
| 819 | // ThreadList::Clear() will try to acquire this process's mutex, so |
| 820 | // explicitly clear the thread list here to ensure that the mutex |
| 821 | // is not destroyed before the thread list. |
| 822 | m_thread_list.Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 823 | } |
| 824 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 825 | const ProcessPropertiesSP & |
| 826 | Process::GetGlobalProperties() |
| 827 | { |
| 828 | static ProcessPropertiesSP g_settings_sp; |
| 829 | if (!g_settings_sp) |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 830 | g_settings_sp.reset (new ProcessProperties (NULL)); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 831 | return g_settings_sp; |
| 832 | } |
| 833 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 834 | void |
| 835 | Process::Finalize() |
| 836 | { |
Greg Clayton | c00ca31 | 2015-04-02 18:44:58 +0000 | [diff] [blame] | 837 | m_finalizing = true; |
| 838 | |
Ilia K | c7efd56 | 2015-03-26 07:40:40 +0000 | [diff] [blame] | 839 | // Destroy this process if needed |
| 840 | switch (GetPrivateState()) |
| 841 | { |
| 842 | case eStateConnected: |
| 843 | case eStateAttaching: |
| 844 | case eStateLaunching: |
| 845 | case eStateStopped: |
| 846 | case eStateRunning: |
| 847 | case eStateStepping: |
| 848 | case eStateCrashed: |
| 849 | case eStateSuspended: |
Jason Molenda | ede3193 | 2015-04-17 05:01:58 +0000 | [diff] [blame] | 850 | Destroy(false); |
Ilia K | c7efd56 | 2015-03-26 07:40:40 +0000 | [diff] [blame] | 851 | break; |
| 852 | |
| 853 | case eStateInvalid: |
| 854 | case eStateUnloaded: |
| 855 | case eStateDetached: |
| 856 | case eStateExited: |
| 857 | break; |
| 858 | } |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 859 | |
Greg Clayton | 1ed54f5 | 2011-10-01 00:45:15 +0000 | [diff] [blame] | 860 | // Clear our broadcaster before we proceed with destroying |
| 861 | Broadcaster::Clear(); |
| 862 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 863 | // Do any cleanup needed prior to being destructed... Subclasses |
| 864 | // that override this method should call this superclass method as well. |
Jim Ingham | d0a3e12 | 2011-02-16 17:54:55 +0000 | [diff] [blame] | 865 | |
| 866 | // We need to destroy the loader before the derived Process class gets destroyed |
| 867 | // 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] | 868 | m_dynamic_checkers_ap.reset(); |
| 869 | m_abi_sp.reset(); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 870 | m_os_ap.reset(); |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 871 | m_system_runtime_ap.reset(); |
Greg Clayton | 894f82f | 2012-01-20 23:08:34 +0000 | [diff] [blame] | 872 | m_dyld_ap.reset(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 873 | m_jit_loaders_ap.reset(); |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 874 | m_thread_list_real.Destroy(); |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 875 | m_thread_list.Destroy(); |
Jason Molenda | 864f1cc | 2013-11-11 05:20:44 +0000 | [diff] [blame] | 876 | m_extended_thread_list.Destroy(); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 877 | m_queue_list.Clear(); |
| 878 | m_queue_list_stop_id = 0; |
Greg Clayton | 894f82f | 2012-01-20 23:08:34 +0000 | [diff] [blame] | 879 | std::vector<Notifications> empty_notifications; |
| 880 | m_notifications.swap(empty_notifications); |
| 881 | m_image_tokens.clear(); |
| 882 | m_memory_cache.Clear(); |
| 883 | m_allocated_memory_cache.Clear(); |
| 884 | m_language_runtimes.clear(); |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 885 | m_instrumentation_runtimes.clear(); |
Greg Clayton | 894f82f | 2012-01-20 23:08:34 +0000 | [diff] [blame] | 886 | m_next_event_action_ap.reset(); |
Greg Clayton | a97c4d2 | 2014-12-09 23:31:02 +0000 | [diff] [blame] | 887 | m_stop_info_override_callback = NULL; |
Greg Clayton | 08765fa | 2015-05-28 03:24:30 +0000 | [diff] [blame] | 888 | // Clear the last natural stop ID since it has a strong |
| 889 | // reference to this process |
| 890 | m_mod_id.SetStopEventForLastNaturalStopID(EventSP()); |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 891 | //#ifdef LLDB_CONFIGURATION_DEBUG |
| 892 | // StreamFile s(stdout, false); |
| 893 | // EventSP event_sp; |
| 894 | // while (m_private_state_listener.GetNextEvent(event_sp)) |
| 895 | // { |
| 896 | // event_sp->Dump (&s); |
| 897 | // s.EOL(); |
| 898 | // } |
| 899 | //#endif |
| 900 | // We have to be very careful here as the m_private_state_listener might |
| 901 | // contain events that have ProcessSP values in them which can keep this |
| 902 | // process around forever. These events need to be cleared out. |
| 903 | m_private_state_listener.Clear(); |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 904 | m_public_run_lock.TrySetRunning(); // This will do nothing if already locked |
| 905 | m_public_run_lock.SetStopped(); |
| 906 | m_private_run_lock.TrySetRunning(); // This will do nothing if already locked |
| 907 | m_private_run_lock.SetStopped(); |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 908 | m_finalize_called = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | void |
| 912 | Process::RegisterNotificationCallbacks (const Notifications& callbacks) |
| 913 | { |
| 914 | m_notifications.push_back(callbacks); |
| 915 | if (callbacks.initialize != NULL) |
| 916 | callbacks.initialize (callbacks.baton, this); |
| 917 | } |
| 918 | |
| 919 | bool |
| 920 | Process::UnregisterNotificationCallbacks(const Notifications& callbacks) |
| 921 | { |
| 922 | std::vector<Notifications>::iterator pos, end = m_notifications.end(); |
| 923 | for (pos = m_notifications.begin(); pos != end; ++pos) |
| 924 | { |
| 925 | if (pos->baton == callbacks.baton && |
| 926 | pos->initialize == callbacks.initialize && |
| 927 | pos->process_state_changed == callbacks.process_state_changed) |
| 928 | { |
| 929 | m_notifications.erase(pos); |
| 930 | return true; |
| 931 | } |
| 932 | } |
| 933 | return false; |
| 934 | } |
| 935 | |
| 936 | void |
| 937 | Process::SynchronouslyNotifyStateChanged (StateType state) |
| 938 | { |
| 939 | std::vector<Notifications>::iterator notification_pos, notification_end = m_notifications.end(); |
| 940 | for (notification_pos = m_notifications.begin(); notification_pos != notification_end; ++notification_pos) |
| 941 | { |
| 942 | if (notification_pos->process_state_changed) |
| 943 | notification_pos->process_state_changed (notification_pos->baton, this, state); |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | // FIXME: We need to do some work on events before the general Listener sees them. |
| 948 | // For instance if we are continuing from a breakpoint, we need to ensure that we do |
| 949 | // the little "insert real insn, step & stop" trick. But we can't do that when the |
| 950 | // event is delivered by the broadcaster - since that is done on the thread that is |
| 951 | // waiting for new events, so if we needed more than one event for our handling, we would |
| 952 | // stall. So instead we do it when we fetch the event off of the queue. |
| 953 | // |
| 954 | |
| 955 | StateType |
| 956 | Process::GetNextEvent (EventSP &event_sp) |
| 957 | { |
| 958 | StateType state = eStateInvalid; |
| 959 | |
| 960 | if (m_listener.GetNextEventForBroadcaster (this, event_sp) && event_sp) |
| 961 | state = Process::ProcessEventData::GetStateFromEvent (event_sp.get()); |
| 962 | |
| 963 | return state; |
| 964 | } |
| 965 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 966 | void |
| 967 | Process::SyncIOHandler (uint32_t iohandler_id, uint64_t timeout_msec) |
Todd Fiala | a3b89e2 | 2014-08-12 14:33:19 +0000 | [diff] [blame] | 968 | { |
Todd Fiala | a3b89e2 | 2014-08-12 14:33:19 +0000 | [diff] [blame] | 969 | // don't sync (potentially context switch) in case where there is no process IO |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 970 | if (! m_process_input_reader) |
| 971 | return; |
Todd Fiala | a3b89e2 | 2014-08-12 14:33:19 +0000 | [diff] [blame] | 972 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 973 | TimeValue timeout = TimeValue::Now(); |
| 974 | timeout.OffsetWithMicroSeconds(timeout_msec*1000); |
| 975 | uint32_t new_iohandler_id = 0; |
| 976 | m_iohandler_sync.WaitForValueNotEqualTo(iohandler_id, new_iohandler_id, &timeout); |
Todd Fiala | a3b89e2 | 2014-08-12 14:33:19 +0000 | [diff] [blame] | 977 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 978 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 979 | if (log) |
| 980 | log->Printf("Process::%s waited for m_iohandler_sync to change from %u, new value is %u", __FUNCTION__, iohandler_id, new_iohandler_id); |
Todd Fiala | a3b89e2 | 2014-08-12 14:33:19 +0000 | [diff] [blame] | 981 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 982 | |
| 983 | StateType |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 984 | Process::WaitForProcessToStop (const TimeValue *timeout, |
| 985 | EventSP *event_sp_ptr, |
| 986 | bool wait_always, |
| 987 | Listener *hijack_listener, |
| 988 | Stream *stream) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 989 | { |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 990 | // We can't just wait for a "stopped" event, because the stopped event may have restarted the target. |
| 991 | // We have to actually check each event, and in the case of a stopped event check the restarted flag |
| 992 | // on the event. |
Greg Clayton | 85fb1b9 | 2012-09-11 02:33:37 +0000 | [diff] [blame] | 993 | if (event_sp_ptr) |
| 994 | event_sp_ptr->reset(); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 995 | StateType state = GetState(); |
| 996 | // If we are exited or detached, we won't ever get back to any |
| 997 | // other valid state... |
| 998 | if (state == eStateDetached || state == eStateExited) |
| 999 | return state; |
| 1000 | |
Daniel Malea | 9e9919f | 2013-10-09 16:56:28 +0000 | [diff] [blame] | 1001 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 1002 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1003 | log->Printf ("Process::%s (timeout = %p)", __FUNCTION__, |
| 1004 | static_cast<const void*>(timeout)); |
Daniel Malea | 9e9919f | 2013-10-09 16:56:28 +0000 | [diff] [blame] | 1005 | |
| 1006 | if (!wait_always && |
| 1007 | StateIsStoppedState(state, true) && |
Jim Ingham | 5b4c5eb | 2015-04-22 17:48:24 +0000 | [diff] [blame] | 1008 | StateIsStoppedState(GetPrivateState(), true)) |
| 1009 | { |
Daniel Malea | 9e9919f | 2013-10-09 16:56:28 +0000 | [diff] [blame] | 1010 | if (log) |
| 1011 | log->Printf("Process::%s returning without waiting for events; process private and public states are already 'stopped'.", |
| 1012 | __FUNCTION__); |
Pavel Labath | 78521ef | 2015-03-06 10:52:47 +0000 | [diff] [blame] | 1013 | // We need to toggle the run lock as this won't get done in |
| 1014 | // SetPublicState() if the process is hijacked. |
| 1015 | if (hijack_listener) |
| 1016 | m_public_run_lock.SetStopped(); |
Daniel Malea | 9e9919f | 2013-10-09 16:56:28 +0000 | [diff] [blame] | 1017 | return state; |
| 1018 | } |
| 1019 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1020 | while (state != eStateInvalid) |
| 1021 | { |
Greg Clayton | 85fb1b9 | 2012-09-11 02:33:37 +0000 | [diff] [blame] | 1022 | EventSP event_sp; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1023 | state = WaitForStateChangedEvents (timeout, event_sp, hijack_listener); |
Greg Clayton | 85fb1b9 | 2012-09-11 02:33:37 +0000 | [diff] [blame] | 1024 | if (event_sp_ptr && event_sp) |
| 1025 | *event_sp_ptr = event_sp; |
| 1026 | |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1027 | bool pop_process_io_handler = hijack_listener != NULL; |
| 1028 | Process::HandleProcessStateChangedEvent (event_sp, stream, pop_process_io_handler); |
| 1029 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1030 | switch (state) |
| 1031 | { |
| 1032 | case eStateCrashed: |
| 1033 | case eStateDetached: |
| 1034 | case eStateExited: |
| 1035 | case eStateUnloaded: |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1036 | // We need to toggle the run lock as this won't get done in |
| 1037 | // SetPublicState() if the process is hijacked. |
| 1038 | if (hijack_listener) |
| 1039 | m_public_run_lock.SetStopped(); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1040 | return state; |
| 1041 | case eStateStopped: |
| 1042 | if (Process::ProcessEventData::GetRestartedFromEvent(event_sp.get())) |
| 1043 | continue; |
| 1044 | else |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1045 | { |
| 1046 | // We need to toggle the run lock as this won't get done in |
| 1047 | // SetPublicState() if the process is hijacked. |
| 1048 | if (hijack_listener) |
| 1049 | m_public_run_lock.SetStopped(); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1050 | return state; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1051 | } |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1052 | default: |
| 1053 | continue; |
| 1054 | } |
| 1055 | } |
| 1056 | return state; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1059 | bool |
| 1060 | Process::HandleProcessStateChangedEvent (const EventSP &event_sp, |
| 1061 | Stream *stream, |
| 1062 | bool &pop_process_io_handler) |
| 1063 | { |
| 1064 | const bool handle_pop = pop_process_io_handler == true; |
| 1065 | |
| 1066 | pop_process_io_handler = false; |
| 1067 | ProcessSP process_sp = Process::ProcessEventData::GetProcessFromEvent(event_sp.get()); |
| 1068 | |
| 1069 | if (!process_sp) |
| 1070 | return false; |
| 1071 | |
| 1072 | StateType event_state = Process::ProcessEventData::GetStateFromEvent (event_sp.get()); |
| 1073 | if (event_state == eStateInvalid) |
| 1074 | return false; |
| 1075 | |
| 1076 | switch (event_state) |
| 1077 | { |
| 1078 | case eStateInvalid: |
| 1079 | case eStateUnloaded: |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1080 | case eStateAttaching: |
| 1081 | case eStateLaunching: |
| 1082 | case eStateStepping: |
| 1083 | case eStateDetached: |
| 1084 | { |
| 1085 | if (stream) |
| 1086 | stream->Printf ("Process %" PRIu64 " %s\n", |
| 1087 | process_sp->GetID(), |
| 1088 | StateAsCString (event_state)); |
| 1089 | |
| 1090 | if (event_state == eStateDetached) |
| 1091 | pop_process_io_handler = true; |
| 1092 | } |
| 1093 | break; |
| 1094 | |
Stephane Sezer | f2ef94e | 2014-12-13 05:23:51 +0000 | [diff] [blame] | 1095 | case eStateConnected: |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1096 | case eStateRunning: |
| 1097 | // Don't be chatty when we run... |
| 1098 | break; |
| 1099 | |
| 1100 | case eStateExited: |
| 1101 | if (stream) |
| 1102 | process_sp->GetStatus(*stream); |
| 1103 | pop_process_io_handler = true; |
| 1104 | break; |
| 1105 | |
| 1106 | case eStateStopped: |
| 1107 | case eStateCrashed: |
| 1108 | case eStateSuspended: |
| 1109 | // Make sure the program hasn't been auto-restarted: |
| 1110 | if (Process::ProcessEventData::GetRestartedFromEvent (event_sp.get())) |
| 1111 | { |
| 1112 | if (stream) |
| 1113 | { |
| 1114 | size_t num_reasons = Process::ProcessEventData::GetNumRestartedReasons(event_sp.get()); |
| 1115 | if (num_reasons > 0) |
| 1116 | { |
| 1117 | // FIXME: Do we want to report this, or would that just be annoyingly chatty? |
| 1118 | if (num_reasons == 1) |
| 1119 | { |
| 1120 | const char *reason = Process::ProcessEventData::GetRestartedReasonAtIndex (event_sp.get(), 0); |
| 1121 | stream->Printf ("Process %" PRIu64 " stopped and restarted: %s\n", |
| 1122 | process_sp->GetID(), |
| 1123 | reason ? reason : "<UNKNOWN REASON>"); |
| 1124 | } |
| 1125 | else |
| 1126 | { |
| 1127 | stream->Printf ("Process %" PRIu64 " stopped and restarted, reasons:\n", |
| 1128 | process_sp->GetID()); |
| 1129 | |
| 1130 | |
| 1131 | for (size_t i = 0; i < num_reasons; i++) |
| 1132 | { |
| 1133 | const char *reason = Process::ProcessEventData::GetRestartedReasonAtIndex (event_sp.get(), i); |
| 1134 | stream->Printf("\t%s\n", reason ? reason : "<UNKNOWN REASON>"); |
| 1135 | } |
| 1136 | } |
| 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | else |
| 1141 | { |
| 1142 | // Lock the thread list so it doesn't change on us, this is the scope for the locker: |
| 1143 | { |
| 1144 | ThreadList &thread_list = process_sp->GetThreadList(); |
| 1145 | Mutex::Locker locker (thread_list.GetMutex()); |
| 1146 | |
| 1147 | ThreadSP curr_thread (thread_list.GetSelectedThread()); |
| 1148 | ThreadSP thread; |
| 1149 | StopReason curr_thread_stop_reason = eStopReasonInvalid; |
| 1150 | if (curr_thread) |
| 1151 | curr_thread_stop_reason = curr_thread->GetStopReason(); |
| 1152 | if (!curr_thread || |
| 1153 | !curr_thread->IsValid() || |
| 1154 | curr_thread_stop_reason == eStopReasonInvalid || |
| 1155 | curr_thread_stop_reason == eStopReasonNone) |
| 1156 | { |
| 1157 | // Prefer a thread that has just completed its plan over another thread as current thread. |
| 1158 | ThreadSP plan_thread; |
| 1159 | ThreadSP other_thread; |
Jim Ingham | ce400d9 | 2015-07-08 00:06:30 +0000 | [diff] [blame] | 1160 | |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1161 | const size_t num_threads = thread_list.GetSize(); |
| 1162 | size_t i; |
| 1163 | for (i = 0; i < num_threads; ++i) |
| 1164 | { |
| 1165 | thread = thread_list.GetThreadAtIndex(i); |
| 1166 | StopReason thread_stop_reason = thread->GetStopReason(); |
| 1167 | switch (thread_stop_reason) |
| 1168 | { |
| 1169 | case eStopReasonInvalid: |
| 1170 | case eStopReasonNone: |
| 1171 | break; |
| 1172 | |
Jim Ingham | ce400d9 | 2015-07-08 00:06:30 +0000 | [diff] [blame] | 1173 | case eStopReasonSignal: |
| 1174 | { |
| 1175 | // Don't select a signal thread if we weren't going to stop at that |
| 1176 | // signal. We have to have had another reason for stopping here, and |
| 1177 | // the user doesn't want to see this thread. |
| 1178 | uint64_t signo = thread->GetStopInfo()->GetValue(); |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 1179 | if (process_sp->GetUnixSignals()->GetShouldStop(signo)) |
Jim Ingham | ce400d9 | 2015-07-08 00:06:30 +0000 | [diff] [blame] | 1180 | { |
| 1181 | if (!other_thread) |
| 1182 | other_thread = thread; |
| 1183 | } |
| 1184 | break; |
| 1185 | } |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1186 | case eStopReasonTrace: |
| 1187 | case eStopReasonBreakpoint: |
| 1188 | case eStopReasonWatchpoint: |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1189 | case eStopReasonException: |
| 1190 | case eStopReasonExec: |
| 1191 | case eStopReasonThreadExiting: |
| 1192 | case eStopReasonInstrumentation: |
| 1193 | if (!other_thread) |
| 1194 | other_thread = thread; |
| 1195 | break; |
| 1196 | case eStopReasonPlanComplete: |
| 1197 | if (!plan_thread) |
| 1198 | plan_thread = thread; |
| 1199 | break; |
| 1200 | } |
| 1201 | } |
| 1202 | if (plan_thread) |
| 1203 | thread_list.SetSelectedThreadByID (plan_thread->GetID()); |
| 1204 | else if (other_thread) |
| 1205 | thread_list.SetSelectedThreadByID (other_thread->GetID()); |
| 1206 | else |
| 1207 | { |
| 1208 | if (curr_thread && curr_thread->IsValid()) |
| 1209 | thread = curr_thread; |
| 1210 | else |
| 1211 | thread = thread_list.GetThreadAtIndex(0); |
| 1212 | |
| 1213 | if (thread) |
| 1214 | thread_list.SetSelectedThreadByID (thread->GetID()); |
| 1215 | } |
| 1216 | } |
| 1217 | } |
| 1218 | // Drop the ThreadList mutex by here, since GetThreadStatus below might have to run code, |
| 1219 | // e.g. for Data formatters, and if we hold the ThreadList mutex, then the process is going to |
| 1220 | // have a hard time restarting the process. |
| 1221 | if (stream) |
| 1222 | { |
| 1223 | Debugger &debugger = process_sp->GetTarget().GetDebugger(); |
| 1224 | if (debugger.GetTargetList().GetSelectedTarget().get() == &process_sp->GetTarget()) |
| 1225 | { |
| 1226 | const bool only_threads_with_stop_reason = true; |
| 1227 | const uint32_t start_frame = 0; |
| 1228 | const uint32_t num_frames = 1; |
| 1229 | const uint32_t num_frames_with_source = 1; |
| 1230 | process_sp->GetStatus(*stream); |
| 1231 | process_sp->GetThreadStatus (*stream, |
| 1232 | only_threads_with_stop_reason, |
| 1233 | start_frame, |
| 1234 | num_frames, |
| 1235 | num_frames_with_source); |
| 1236 | } |
| 1237 | else |
| 1238 | { |
| 1239 | uint32_t target_idx = debugger.GetTargetList().GetIndexOfTarget(process_sp->GetTarget().shared_from_this()); |
| 1240 | if (target_idx != UINT32_MAX) |
| 1241 | stream->Printf ("Target %d: (", target_idx); |
| 1242 | else |
| 1243 | stream->Printf ("Target <unknown index>: ("); |
| 1244 | process_sp->GetTarget().Dump (stream, eDescriptionLevelBrief); |
| 1245 | stream->Printf (") stopped.\n"); |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | // Pop the process IO handler |
| 1250 | pop_process_io_handler = true; |
| 1251 | } |
| 1252 | break; |
| 1253 | } |
| 1254 | |
| 1255 | if (handle_pop && pop_process_io_handler) |
| 1256 | process_sp->PopProcessIOHandler(); |
| 1257 | |
| 1258 | return true; |
| 1259 | } |
| 1260 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1261 | |
| 1262 | StateType |
| 1263 | Process::WaitForState |
| 1264 | ( |
| 1265 | const TimeValue *timeout, |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1266 | const StateType *match_states, |
| 1267 | const uint32_t num_match_states |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1268 | ) |
| 1269 | { |
| 1270 | EventSP event_sp; |
| 1271 | uint32_t i; |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 1272 | StateType state = GetState(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1273 | while (state != eStateInvalid) |
| 1274 | { |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 1275 | // If we are exited or detached, we won't ever get back to any |
| 1276 | // other valid state... |
| 1277 | if (state == eStateDetached || state == eStateExited) |
| 1278 | return state; |
| 1279 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1280 | state = WaitForStateChangedEvents (timeout, event_sp, NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1281 | |
| 1282 | for (i=0; i<num_match_states; ++i) |
| 1283 | { |
| 1284 | if (match_states[i] == state) |
| 1285 | return state; |
| 1286 | } |
| 1287 | } |
| 1288 | return state; |
| 1289 | } |
| 1290 | |
Jim Ingham | 30f9b21 | 2010-10-11 23:53:14 +0000 | [diff] [blame] | 1291 | bool |
| 1292 | Process::HijackProcessEvents (Listener *listener) |
| 1293 | { |
| 1294 | if (listener != NULL) |
| 1295 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 1296 | return HijackBroadcaster(listener, eBroadcastBitStateChanged | eBroadcastBitInterrupt); |
Jim Ingham | 30f9b21 | 2010-10-11 23:53:14 +0000 | [diff] [blame] | 1297 | } |
| 1298 | else |
| 1299 | return false; |
| 1300 | } |
| 1301 | |
| 1302 | void |
| 1303 | Process::RestoreProcessEvents () |
| 1304 | { |
| 1305 | RestoreBroadcaster(); |
| 1306 | } |
| 1307 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 1308 | bool |
| 1309 | Process::HijackPrivateProcessEvents (Listener *listener) |
| 1310 | { |
| 1311 | if (listener != NULL) |
| 1312 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 1313 | return m_private_state_broadcaster.HijackBroadcaster(listener, eBroadcastBitStateChanged | eBroadcastBitInterrupt); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 1314 | } |
| 1315 | else |
| 1316 | return false; |
| 1317 | } |
| 1318 | |
| 1319 | void |
| 1320 | Process::RestorePrivateProcessEvents () |
| 1321 | { |
| 1322 | m_private_state_broadcaster.RestoreBroadcaster(); |
| 1323 | } |
| 1324 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1325 | StateType |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1326 | Process::WaitForStateChangedEvents (const TimeValue *timeout, EventSP &event_sp, Listener *hijack_listener) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1327 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1328 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1329 | |
| 1330 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1331 | log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, |
| 1332 | static_cast<const void*>(timeout)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1333 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1334 | Listener *listener = hijack_listener; |
| 1335 | if (listener == NULL) |
| 1336 | listener = &m_listener; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1337 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1338 | StateType state = eStateInvalid; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1339 | if (listener->WaitForEventForBroadcasterWithType (timeout, |
| 1340 | this, |
| 1341 | eBroadcastBitStateChanged | eBroadcastBitInterrupt, |
| 1342 | event_sp)) |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 1343 | { |
| 1344 | if (event_sp && event_sp->GetType() == eBroadcastBitStateChanged) |
| 1345 | state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 1346 | else if (log) |
| 1347 | log->Printf ("Process::%s got no event or was interrupted.", __FUNCTION__); |
| 1348 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1349 | |
| 1350 | if (log) |
| 1351 | log->Printf ("Process::%s (timeout = %p, event_sp) => %s", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1352 | __FUNCTION__, static_cast<const void*>(timeout), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1353 | StateAsCString(state)); |
| 1354 | return state; |
| 1355 | } |
| 1356 | |
| 1357 | Event * |
| 1358 | Process::PeekAtStateChangedEvents () |
| 1359 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1360 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1361 | |
| 1362 | if (log) |
| 1363 | log->Printf ("Process::%s...", __FUNCTION__); |
| 1364 | |
| 1365 | Event *event_ptr; |
Greg Clayton | 3fcbed6 | 2010-10-19 03:25:40 +0000 | [diff] [blame] | 1366 | event_ptr = m_listener.PeekAtNextEventForBroadcasterWithType (this, |
| 1367 | eBroadcastBitStateChanged); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1368 | if (log) |
| 1369 | { |
| 1370 | if (event_ptr) |
| 1371 | { |
| 1372 | log->Printf ("Process::%s (event_ptr) => %s", |
| 1373 | __FUNCTION__, |
| 1374 | StateAsCString(ProcessEventData::GetStateFromEvent (event_ptr))); |
| 1375 | } |
| 1376 | else |
| 1377 | { |
| 1378 | log->Printf ("Process::%s no events found", |
| 1379 | __FUNCTION__); |
| 1380 | } |
| 1381 | } |
| 1382 | return event_ptr; |
| 1383 | } |
| 1384 | |
| 1385 | StateType |
| 1386 | Process::WaitForStateChangedEventsPrivate (const TimeValue *timeout, EventSP &event_sp) |
| 1387 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1388 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1389 | |
| 1390 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1391 | log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, |
| 1392 | static_cast<const void*>(timeout)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1393 | |
| 1394 | StateType state = eStateInvalid; |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1395 | if (m_private_state_listener.WaitForEventForBroadcasterWithType (timeout, |
| 1396 | &m_private_state_broadcaster, |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 1397 | eBroadcastBitStateChanged | eBroadcastBitInterrupt, |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1398 | event_sp)) |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 1399 | if (event_sp && event_sp->GetType() == eBroadcastBitStateChanged) |
| 1400 | state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1401 | |
| 1402 | // This is a bit of a hack, but when we wait here we could very well return |
| 1403 | // to the command-line, and that could disable the log, which would render the |
| 1404 | // log we got above invalid. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1405 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1406 | log->Printf ("Process::%s (timeout = %p, event_sp) => %s", |
| 1407 | __FUNCTION__, static_cast<const void *>(timeout), |
| 1408 | state == eStateInvalid ? "TIMEOUT" : StateAsCString(state)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1409 | return state; |
| 1410 | } |
| 1411 | |
| 1412 | bool |
| 1413 | Process::WaitForEventsPrivate (const TimeValue *timeout, EventSP &event_sp, bool control_only) |
| 1414 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1415 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1416 | |
| 1417 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1418 | log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, |
| 1419 | static_cast<const void*>(timeout)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1420 | |
| 1421 | if (control_only) |
| 1422 | return m_private_state_listener.WaitForEventForBroadcaster(timeout, &m_private_state_control_broadcaster, event_sp); |
| 1423 | else |
| 1424 | return m_private_state_listener.WaitForEvent(timeout, event_sp); |
| 1425 | } |
| 1426 | |
| 1427 | bool |
| 1428 | Process::IsRunning () const |
| 1429 | { |
| 1430 | return StateIsRunningState (m_public_state.GetValue()); |
| 1431 | } |
| 1432 | |
| 1433 | int |
| 1434 | Process::GetExitStatus () |
| 1435 | { |
Todd Fiala | 7b0917a | 2014-09-15 20:07:33 +0000 | [diff] [blame] | 1436 | Mutex::Locker locker (m_exit_status_mutex); |
| 1437 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1438 | if (m_public_state.GetValue() == eStateExited) |
| 1439 | return m_exit_status; |
| 1440 | return -1; |
| 1441 | } |
| 1442 | |
Greg Clayton | 85851dd | 2010-12-04 00:10:17 +0000 | [diff] [blame] | 1443 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1444 | const char * |
| 1445 | Process::GetExitDescription () |
| 1446 | { |
Todd Fiala | 7b0917a | 2014-09-15 20:07:33 +0000 | [diff] [blame] | 1447 | Mutex::Locker locker (m_exit_status_mutex); |
| 1448 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1449 | if (m_public_state.GetValue() == eStateExited && !m_exit_string.empty()) |
| 1450 | return m_exit_string.c_str(); |
| 1451 | return NULL; |
| 1452 | } |
| 1453 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1454 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1455 | Process::SetExitStatus (int status, const char *cstr) |
| 1456 | { |
Greg Clayton | 81e2b6b | 2015-06-01 23:14:09 +0000 | [diff] [blame] | 1457 | // Use a mutex to protect setting the exit status. |
| 1458 | Mutex::Locker locker (m_exit_status_mutex); |
| 1459 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1460 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS)); |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 1461 | if (log) |
| 1462 | log->Printf("Process::SetExitStatus (status=%i (0x%8.8x), description=%s%s%s)", |
| 1463 | status, status, |
| 1464 | cstr ? "\"" : "", |
| 1465 | cstr ? cstr : "NULL", |
| 1466 | cstr ? "\"" : ""); |
| 1467 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1468 | // We were already in the exited state |
| 1469 | if (m_private_state.GetValue() == eStateExited) |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 1470 | { |
Greg Clayton | 385d603 | 2011-01-26 23:47:29 +0000 | [diff] [blame] | 1471 | if (log) |
| 1472 | 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] | 1473 | return false; |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 1474 | } |
Todd Fiala | 7b0917a | 2014-09-15 20:07:33 +0000 | [diff] [blame] | 1475 | |
Greg Clayton | 81e2b6b | 2015-06-01 23:14:09 +0000 | [diff] [blame] | 1476 | m_exit_status = status; |
| 1477 | if (cstr) |
| 1478 | m_exit_string = cstr; |
| 1479 | else |
| 1480 | m_exit_string.clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1481 | |
Greg Clayton | 5df78fa | 2015-05-23 03:54:53 +0000 | [diff] [blame] | 1482 | // When we exit, we no longer need to the communication channel |
Greg Clayton | 5df78fa | 2015-05-23 03:54:53 +0000 | [diff] [blame] | 1483 | m_stdio_communication.Disconnect(); |
Greg Clayton | 23d54f4 | 2015-06-03 00:34:01 +0000 | [diff] [blame] | 1484 | m_stdio_communication.StopReadThread(); |
Greg Clayton | 5df78fa | 2015-05-23 03:54:53 +0000 | [diff] [blame] | 1485 | m_stdin_forward = false; |
| 1486 | |
| 1487 | // And we don't need the input reader anymore as well |
| 1488 | if (m_process_input_reader) |
| 1489 | { |
| 1490 | m_process_input_reader->SetIsDone(true); |
| 1491 | m_process_input_reader->Cancel(); |
| 1492 | m_process_input_reader.reset(); |
| 1493 | } |
Greg Clayton | 10177aa | 2010-12-08 05:08:21 +0000 | [diff] [blame] | 1494 | |
Greg Clayton | 08765fa | 2015-05-28 03:24:30 +0000 | [diff] [blame] | 1495 | // Clear the last natural stop ID since it has a strong |
| 1496 | // reference to this process |
| 1497 | m_mod_id.SetStopEventForLastNaturalStopID(EventSP()); |
| 1498 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1499 | SetPrivateState (eStateExited); |
Greg Clayton | 5df78fa | 2015-05-23 03:54:53 +0000 | [diff] [blame] | 1500 | |
| 1501 | // Allow subclasses to do some cleanup |
| 1502 | DidExit (); |
| 1503 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1504 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | // 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] | 1508 | // the current host. The child process exits, the process will be |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1509 | // found in the global target list (we want to be completely sure that the |
| 1510 | // lldb_private::Process doesn't go away before we can deliver the signal. |
| 1511 | bool |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 1512 | Process::SetProcessExitStatus (void *callback_baton, |
| 1513 | lldb::pid_t pid, |
| 1514 | bool exited, |
| 1515 | int signo, // Zero for no signal |
| 1516 | int exit_status // Exit value of process if signal is zero |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1517 | ) |
| 1518 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1519 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 1520 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1521 | 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] | 1522 | callback_baton, |
| 1523 | pid, |
| 1524 | exited, |
| 1525 | signo, |
| 1526 | exit_status); |
| 1527 | |
| 1528 | if (exited) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1529 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1530 | TargetSP target_sp(Debugger::FindTargetWithProcessID (pid)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1531 | if (target_sp) |
| 1532 | { |
| 1533 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 1534 | if (process_sp) |
| 1535 | { |
| 1536 | const char *signal_cstr = NULL; |
| 1537 | if (signo) |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 1538 | signal_cstr = process_sp->GetUnixSignals()->GetSignalAsCString(signo); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1539 | |
| 1540 | process_sp->SetExitStatus (exit_status, signal_cstr); |
| 1541 | } |
| 1542 | } |
| 1543 | return true; |
| 1544 | } |
| 1545 | return false; |
| 1546 | } |
| 1547 | |
| 1548 | |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1549 | void |
| 1550 | Process::UpdateThreadListIfNeeded () |
| 1551 | { |
| 1552 | const uint32_t stop_id = GetStopID(); |
| 1553 | if (m_thread_list.GetSize(false) == 0 || stop_id != m_thread_list.GetStopID()) |
| 1554 | { |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 1555 | const StateType state = GetPrivateState(); |
| 1556 | if (StateIsStoppedState (state, true)) |
| 1557 | { |
| 1558 | Mutex::Locker locker (m_thread_list.GetMutex ()); |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 1559 | // m_thread_list does have its own mutex, but we need to |
| 1560 | // hold onto the mutex between the call to UpdateThreadList(...) |
| 1561 | // and the os->UpdateThreadList(...) so it doesn't change on us |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1562 | ThreadList &old_thread_list = m_thread_list; |
| 1563 | ThreadList real_thread_list(this); |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 1564 | ThreadList new_thread_list(this); |
| 1565 | // Always update the thread list with the protocol specific |
Greg Clayton | 9fc1355 | 2012-04-10 00:18:59 +0000 | [diff] [blame] | 1566 | // thread list, but only update if "true" is returned |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1567 | if (UpdateThreadList (m_thread_list_real, real_thread_list)) |
Greg Clayton | 9fc1355 | 2012-04-10 00:18:59 +0000 | [diff] [blame] | 1568 | { |
Jim Ingham | 0943792 | 2013-03-01 20:04:25 +0000 | [diff] [blame] | 1569 | // Don't call into the OperatingSystem to update the thread list if we are shutting down, since |
| 1570 | // that may call back into the SBAPI's, requiring the API lock which is already held by whoever is |
| 1571 | // shutting us down, causing a deadlock. |
| 1572 | if (!m_destroy_in_process) |
| 1573 | { |
| 1574 | OperatingSystem *os = GetOperatingSystem (); |
| 1575 | if (os) |
Greg Clayton | b3ae876 | 2013-04-12 20:07:46 +0000 | [diff] [blame] | 1576 | { |
| 1577 | // Clear any old backing threads where memory threads might have been |
| 1578 | // backed by actual threads from the lldb_private::Process subclass |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1579 | size_t num_old_threads = old_thread_list.GetSize(false); |
Greg Clayton | b3ae876 | 2013-04-12 20:07:46 +0000 | [diff] [blame] | 1580 | for (size_t i=0; i<num_old_threads; ++i) |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1581 | old_thread_list.GetThreadAtIndex(i, false)->ClearBackingThread(); |
Greg Clayton | b3ae876 | 2013-04-12 20:07:46 +0000 | [diff] [blame] | 1582 | |
Greg Clayton | 1548440 | 2015-05-15 18:40:24 +0000 | [diff] [blame] | 1583 | // Turn off dynamic types to ensure we don't run any expressions. Objective C |
| 1584 | // can run an expression to determine if a SBValue is a dynamic type or not |
| 1585 | // and we need to avoid this. OperatingSystem plug-ins can't run expressions |
| 1586 | // that require running code... |
| 1587 | |
| 1588 | Target &target = GetTarget(); |
| 1589 | const lldb::DynamicValueType saved_prefer_dynamic = target.GetPreferDynamicValue (); |
| 1590 | if (saved_prefer_dynamic != lldb::eNoDynamicValues) |
| 1591 | target.SetPreferDynamicValue(lldb::eNoDynamicValues); |
| 1592 | |
Greg Clayton | b3ae876 | 2013-04-12 20:07:46 +0000 | [diff] [blame] | 1593 | // Now let the OperatingSystem plug-in update the thread list |
Greg Clayton | 1548440 | 2015-05-15 18:40:24 +0000 | [diff] [blame] | 1594 | |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1595 | os->UpdateThreadList (old_thread_list, // Old list full of threads created by OS plug-in |
| 1596 | real_thread_list, // The actual thread list full of threads created by each lldb_private::Process subclass |
| 1597 | new_thread_list); // The new thread list that we will show to the user that gets filled in |
Greg Clayton | 1548440 | 2015-05-15 18:40:24 +0000 | [diff] [blame] | 1598 | |
| 1599 | if (saved_prefer_dynamic != lldb::eNoDynamicValues) |
| 1600 | target.SetPreferDynamicValue(saved_prefer_dynamic); |
Greg Clayton | b3ae876 | 2013-04-12 20:07:46 +0000 | [diff] [blame] | 1601 | } |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1602 | else |
| 1603 | { |
| 1604 | // No OS plug-in, the new thread list is the same as the real thread list |
| 1605 | new_thread_list = real_thread_list; |
| 1606 | } |
Jim Ingham | 0943792 | 2013-03-01 20:04:25 +0000 | [diff] [blame] | 1607 | } |
Jim Ingham | 02ff8e0 | 2013-06-22 00:55:02 +0000 | [diff] [blame] | 1608 | |
| 1609 | m_thread_list_real.Update(real_thread_list); |
Andrew Kaylor | ba4e61d | 2013-05-07 18:35:34 +0000 | [diff] [blame] | 1610 | m_thread_list.Update (new_thread_list); |
| 1611 | m_thread_list.SetStopID (stop_id); |
Jason Molenda | a6e9130 | 2013-11-19 05:44:41 +0000 | [diff] [blame] | 1612 | |
Jason Molenda | 4ff1326 | 2013-11-20 00:31:38 +0000 | [diff] [blame] | 1613 | if (GetLastNaturalStopID () != m_extended_thread_stop_id) |
| 1614 | { |
| 1615 | // Clear any extended threads that we may have accumulated previously |
| 1616 | m_extended_thread_list.Clear(); |
| 1617 | m_extended_thread_stop_id = GetLastNaturalStopID (); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 1618 | |
| 1619 | m_queue_list.Clear(); |
| 1620 | m_queue_list_stop_id = GetLastNaturalStopID (); |
Jason Molenda | 4ff1326 | 2013-11-20 00:31:38 +0000 | [diff] [blame] | 1621 | } |
Greg Clayton | 9fc1355 | 2012-04-10 00:18:59 +0000 | [diff] [blame] | 1622 | } |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 1623 | } |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1624 | } |
| 1625 | } |
| 1626 | |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 1627 | void |
| 1628 | Process::UpdateQueueListIfNeeded () |
| 1629 | { |
| 1630 | if (m_system_runtime_ap.get()) |
| 1631 | { |
| 1632 | if (m_queue_list.GetSize() == 0 || m_queue_list_stop_id != GetLastNaturalStopID()) |
| 1633 | { |
| 1634 | const StateType state = GetPrivateState(); |
| 1635 | if (StateIsStoppedState (state, true)) |
| 1636 | { |
| 1637 | m_system_runtime_ap->PopulateQueueList (m_queue_list); |
| 1638 | m_queue_list_stop_id = GetLastNaturalStopID(); |
| 1639 | } |
| 1640 | } |
| 1641 | } |
| 1642 | } |
| 1643 | |
Greg Clayton | a4d8747 | 2013-01-18 23:41:08 +0000 | [diff] [blame] | 1644 | ThreadSP |
| 1645 | Process::CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context) |
| 1646 | { |
| 1647 | OperatingSystem *os = GetOperatingSystem (); |
| 1648 | if (os) |
| 1649 | return os->CreateThread(tid, context); |
| 1650 | return ThreadSP(); |
| 1651 | } |
| 1652 | |
Han Ming Ong | c2c423e | 2013-01-08 22:10:01 +0000 | [diff] [blame] | 1653 | uint32_t |
| 1654 | Process::GetNextThreadIndexID (uint64_t thread_id) |
| 1655 | { |
| 1656 | return AssignIndexIDToThread(thread_id); |
| 1657 | } |
| 1658 | |
| 1659 | bool |
| 1660 | Process::HasAssignedIndexIDToThread(uint64_t thread_id) |
| 1661 | { |
| 1662 | std::map<uint64_t, uint32_t>::iterator iterator = m_thread_id_to_index_id_map.find(thread_id); |
| 1663 | if (iterator == m_thread_id_to_index_id_map.end()) |
| 1664 | { |
| 1665 | return false; |
| 1666 | } |
| 1667 | else |
| 1668 | { |
| 1669 | return true; |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | uint32_t |
| 1674 | Process::AssignIndexIDToThread(uint64_t thread_id) |
| 1675 | { |
| 1676 | uint32_t result = 0; |
| 1677 | std::map<uint64_t, uint32_t>::iterator iterator = m_thread_id_to_index_id_map.find(thread_id); |
| 1678 | if (iterator == m_thread_id_to_index_id_map.end()) |
| 1679 | { |
| 1680 | result = ++m_thread_index_id; |
| 1681 | m_thread_id_to_index_id_map[thread_id] = result; |
| 1682 | } |
| 1683 | else |
| 1684 | { |
| 1685 | result = iterator->second; |
| 1686 | } |
| 1687 | |
| 1688 | return result; |
| 1689 | } |
| 1690 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1691 | StateType |
| 1692 | Process::GetState() |
| 1693 | { |
| 1694 | // If any other threads access this we will need a mutex for it |
| 1695 | return m_public_state.GetValue (); |
| 1696 | } |
| 1697 | |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1698 | bool |
| 1699 | Process::StateChangedIsExternallyHijacked() |
| 1700 | { |
| 1701 | if (IsHijackedForEvent(eBroadcastBitStateChanged)) |
| 1702 | { |
| 1703 | if (strcmp(m_hijacking_listeners.back()->GetName(), "lldb.Process.ResumeSynchronous.hijack")) |
| 1704 | return true; |
| 1705 | } |
| 1706 | return false; |
| 1707 | } |
| 1708 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1709 | void |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 1710 | Process::SetPublicState (StateType new_state, bool restarted) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1711 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1712 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1713 | if (log) |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 1714 | log->Printf("Process::SetPublicState (state = %s, restarted = %i)", StateAsCString(new_state), restarted); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1715 | const StateType old_state = m_public_state.GetValue(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1716 | m_public_state.SetValue (new_state); |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 1717 | |
| 1718 | // On the transition from Run to Stopped, we unlock the writer end of the |
| 1719 | // run lock. The lock gets locked in Resume, which is the public API |
| 1720 | // to tell the program to run. |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1721 | if (!StateChangedIsExternallyHijacked()) |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1722 | { |
Sean Callanan | 8b0737f | 2012-06-02 01:16:20 +0000 | [diff] [blame] | 1723 | if (new_state == eStateDetached) |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1724 | { |
Sean Callanan | 8b0737f | 2012-06-02 01:16:20 +0000 | [diff] [blame] | 1725 | if (log) |
| 1726 | 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] | 1727 | m_public_run_lock.SetStopped(); |
Sean Callanan | 8b0737f | 2012-06-02 01:16:20 +0000 | [diff] [blame] | 1728 | } |
| 1729 | else |
| 1730 | { |
| 1731 | const bool old_state_is_stopped = StateIsStoppedState(old_state, false); |
| 1732 | const bool new_state_is_stopped = StateIsStoppedState(new_state, false); |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 1733 | if ((old_state_is_stopped != new_state_is_stopped)) |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1734 | { |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 1735 | if (new_state_is_stopped && !restarted) |
Sean Callanan | 8b0737f | 2012-06-02 01:16:20 +0000 | [diff] [blame] | 1736 | { |
| 1737 | if (log) |
| 1738 | log->Printf("Process::SetPublicState (%s) -- unlocking run lock", StateAsCString(new_state)); |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 1739 | m_public_run_lock.SetStopped(); |
Sean Callanan | 8b0737f | 2012-06-02 01:16:20 +0000 | [diff] [blame] | 1740 | } |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1741 | } |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1742 | } |
| 1743 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1744 | } |
| 1745 | |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 1746 | Error |
| 1747 | Process::Resume () |
| 1748 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1749 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 1750 | if (log) |
| 1751 | log->Printf("Process::Resume -- locking run lock"); |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 1752 | if (!m_public_run_lock.TrySetRunning()) |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 1753 | { |
| 1754 | Error error("Resume request failed - process still running."); |
| 1755 | if (log) |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 1756 | log->Printf ("Process::Resume: -- TrySetRunning failed, not resuming."); |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 1757 | return error; |
| 1758 | } |
| 1759 | return PrivateResume(); |
| 1760 | } |
| 1761 | |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1762 | Error |
| 1763 | Process::ResumeSynchronous (Stream *stream) |
| 1764 | { |
| 1765 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS)); |
| 1766 | if (log) |
| 1767 | log->Printf("Process::ResumeSynchronous -- locking run lock"); |
| 1768 | if (!m_public_run_lock.TrySetRunning()) |
| 1769 | { |
| 1770 | Error error("Resume request failed - process still running."); |
| 1771 | if (log) |
| 1772 | log->Printf ("Process::Resume: -- TrySetRunning failed, not resuming."); |
| 1773 | return error; |
| 1774 | } |
| 1775 | |
| 1776 | ListenerSP listener_sp (new Listener("lldb.Process.ResumeSynchronous.hijack")); |
| 1777 | HijackProcessEvents(listener_sp.get()); |
| 1778 | |
| 1779 | Error error = PrivateResume(); |
Ilia K | d8c1475 | 2015-04-30 13:10:32 +0000 | [diff] [blame] | 1780 | if (error.Success()) |
| 1781 | { |
| 1782 | StateType state = WaitForProcessToStop (NULL, NULL, true, listener_sp.get(), stream); |
| 1783 | const bool must_be_alive = false; // eStateExited is ok, so this must be false |
| 1784 | if (!StateIsStoppedState(state, must_be_alive)) |
| 1785 | error.SetErrorStringWithFormat("process not in stopped state after synchronous resume: %s", StateAsCString(state)); |
| 1786 | } |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1787 | |
| 1788 | // Undo the hijacking of process events... |
| 1789 | RestoreProcessEvents(); |
| 1790 | |
Greg Clayton | dc6224e | 2014-10-21 01:00:42 +0000 | [diff] [blame] | 1791 | return error; |
| 1792 | } |
| 1793 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1794 | StateType |
| 1795 | Process::GetPrivateState () |
| 1796 | { |
| 1797 | return m_private_state.GetValue(); |
| 1798 | } |
| 1799 | |
| 1800 | void |
| 1801 | Process::SetPrivateState (StateType new_state) |
| 1802 | { |
Greg Clayton | fb8b37a | 2014-07-14 23:09:29 +0000 | [diff] [blame] | 1803 | if (m_finalize_called) |
| 1804 | return; |
| 1805 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1806 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1807 | bool state_changed = false; |
| 1808 | |
| 1809 | if (log) |
| 1810 | log->Printf("Process::SetPrivateState (%s)", StateAsCString(new_state)); |
| 1811 | |
Andrew Kaylor | 29d6574 | 2013-05-10 17:19:04 +0000 | [diff] [blame] | 1812 | Mutex::Locker thread_locker(m_thread_list.GetMutex()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1813 | Mutex::Locker locker(m_private_state.GetMutex()); |
| 1814 | |
| 1815 | const StateType old_state = m_private_state.GetValueNoLock (); |
| 1816 | state_changed = old_state != new_state; |
Ed Maste | c29693f | 2013-07-02 16:35:47 +0000 | [diff] [blame] | 1817 | |
Greg Clayton | aa49c83 | 2013-05-03 22:25:56 +0000 | [diff] [blame] | 1818 | const bool old_state_is_stopped = StateIsStoppedState(old_state, false); |
| 1819 | const bool new_state_is_stopped = StateIsStoppedState(new_state, false); |
| 1820 | if (old_state_is_stopped != new_state_is_stopped) |
| 1821 | { |
| 1822 | if (new_state_is_stopped) |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 1823 | m_private_run_lock.SetStopped(); |
Greg Clayton | aa49c83 | 2013-05-03 22:25:56 +0000 | [diff] [blame] | 1824 | else |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 1825 | m_private_run_lock.SetRunning(); |
Greg Clayton | aa49c83 | 2013-05-03 22:25:56 +0000 | [diff] [blame] | 1826 | } |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 1827 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1828 | if (state_changed) |
| 1829 | { |
| 1830 | m_private_state.SetValueNoLock (new_state); |
Ilia K | 38810f4 | 2015-05-20 10:15:47 +0000 | [diff] [blame] | 1831 | EventSP event_sp (new Event (eBroadcastBitStateChanged, new ProcessEventData (shared_from_this(), new_state))); |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 1832 | if (StateIsStoppedState(new_state, false)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1833 | { |
Andrew Kaylor | 29d6574 | 2013-05-10 17:19:04 +0000 | [diff] [blame] | 1834 | // Note, this currently assumes that all threads in the list |
| 1835 | // stop when the process stops. In the future we will want to |
| 1836 | // support a debugging model where some threads continue to run |
| 1837 | // while others are stopped. When that happens we will either need |
| 1838 | // a way for the thread list to identify which threads are stopping |
| 1839 | // or create a special thread list containing only threads which |
| 1840 | // actually stopped. |
| 1841 | // |
| 1842 | // The process plugin is responsible for managing the actual |
| 1843 | // behavior of the threads and should have stopped any threads |
| 1844 | // that are going to stop before we get here. |
| 1845 | m_thread_list.DidStop(); |
| 1846 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1847 | m_mod_id.BumpStopID(); |
Ilia K | 38810f4 | 2015-05-20 10:15:47 +0000 | [diff] [blame] | 1848 | if (!m_mod_id.IsLastResumeForUserExpression()) |
| 1849 | m_mod_id.SetStopEventForLastNaturalStopID(event_sp); |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 1850 | m_memory_cache.Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1851 | if (log) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1852 | 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] | 1853 | } |
Ilia K | 38810f4 | 2015-05-20 10:15:47 +0000 | [diff] [blame] | 1854 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1855 | // Use our target to get a shared pointer to ourselves... |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 1856 | if (m_finalize_called && PrivateStateThreadIsValid() == false) |
Ilia K | 38810f4 | 2015-05-20 10:15:47 +0000 | [diff] [blame] | 1857 | BroadcastEvent (event_sp); |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 1858 | else |
Ilia K | 38810f4 | 2015-05-20 10:15:47 +0000 | [diff] [blame] | 1859 | m_private_state_broadcaster.BroadcastEvent (event_sp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1860 | } |
| 1861 | else |
| 1862 | { |
| 1863 | if (log) |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 1864 | 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] | 1865 | } |
| 1866 | } |
| 1867 | |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 1868 | void |
| 1869 | Process::SetRunningUserExpression (bool on) |
| 1870 | { |
| 1871 | m_mod_id.SetRunningUserExpression (on); |
| 1872 | } |
| 1873 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1874 | addr_t |
| 1875 | Process::GetImageInfoAddress() |
| 1876 | { |
| 1877 | return LLDB_INVALID_ADDRESS; |
| 1878 | } |
| 1879 | |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1880 | //---------------------------------------------------------------------- |
| 1881 | // LoadImage |
| 1882 | // |
| 1883 | // This function provides a default implementation that works for most |
| 1884 | // unix variants. Any Process subclasses that need to do shared library |
| 1885 | // loading differently should override LoadImage and UnloadImage and |
| 1886 | // do what is needed. |
| 1887 | //---------------------------------------------------------------------- |
| 1888 | uint32_t |
| 1889 | Process::LoadImage (const FileSpec &image_spec, Error &error) |
| 1890 | { |
Greg Clayton | c00ca31 | 2015-04-02 18:44:58 +0000 | [diff] [blame] | 1891 | if (m_finalizing) |
| 1892 | { |
| 1893 | error.SetErrorString("process is tearing itself down"); |
| 1894 | return LLDB_INVALID_IMAGE_TOKEN; |
| 1895 | } |
| 1896 | |
Greg Clayton | ac7a3db | 2012-04-18 00:05:19 +0000 | [diff] [blame] | 1897 | char path[PATH_MAX]; |
| 1898 | image_spec.GetPath(path, sizeof(path)); |
| 1899 | |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1900 | DynamicLoader *loader = GetDynamicLoader(); |
| 1901 | if (loader) |
| 1902 | { |
| 1903 | error = loader->CanLoadImage(); |
| 1904 | if (error.Fail()) |
| 1905 | return LLDB_INVALID_IMAGE_TOKEN; |
| 1906 | } |
| 1907 | |
| 1908 | if (error.Success()) |
| 1909 | { |
| 1910 | ThreadSP thread_sp(GetThreadList ().GetSelectedThread()); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1911 | |
| 1912 | if (thread_sp) |
| 1913 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1914 | StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex (0)); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1915 | |
| 1916 | if (frame_sp) |
| 1917 | { |
| 1918 | ExecutionContext exe_ctx; |
| 1919 | frame_sp->CalculateExecutionContext (exe_ctx); |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1920 | EvaluateExpressionOptions expr_options; |
| 1921 | expr_options.SetUnwindOnError(true); |
| 1922 | expr_options.SetIgnoreBreakpoints(true); |
| 1923 | expr_options.SetExecutionPolicy(eExecutionPolicyAlways); |
Jim Ingham | 4ac0443 | 2014-07-19 01:09:16 +0000 | [diff] [blame] | 1924 | expr_options.SetResultIsInternal(true); |
| 1925 | |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1926 | StreamString expr; |
Jim Ingham | 6971b86 | 2014-07-19 00:37:06 +0000 | [diff] [blame] | 1927 | expr.Printf(R"( |
| 1928 | struct __lldb_dlopen_result { void *image_ptr; const char *error_str; } the_result; |
| 1929 | the_result.image_ptr = dlopen ("%s", 2); |
| 1930 | if (the_result.image_ptr == (void *) 0x0) |
| 1931 | { |
| 1932 | the_result.error_str = dlerror(); |
| 1933 | } |
| 1934 | else |
| 1935 | { |
| 1936 | the_result.error_str = (const char *) 0x0; |
| 1937 | } |
| 1938 | the_result; |
| 1939 | )", |
| 1940 | path); |
| 1941 | const char *prefix = R"( |
| 1942 | extern "C" void* dlopen (const char *path, int mode); |
| 1943 | extern "C" const char *dlerror (void); |
| 1944 | )"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 1945 | lldb::ValueObjectSP result_valobj_sp; |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1946 | Error expr_error; |
Greg Clayton | 26ab83d | 2012-10-31 20:49:04 +0000 | [diff] [blame] | 1947 | ClangUserExpression::Evaluate (exe_ctx, |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1948 | expr_options, |
Greg Clayton | 26ab83d | 2012-10-31 20:49:04 +0000 | [diff] [blame] | 1949 | expr.GetData(), |
| 1950 | prefix, |
| 1951 | result_valobj_sp, |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1952 | expr_error); |
| 1953 | if (expr_error.Success()) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1954 | { |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1955 | error = result_valobj_sp->GetError(); |
| 1956 | if (error.Success()) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1957 | { |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1958 | Scalar scalar; |
Jim Ingham | 6971b86 | 2014-07-19 00:37:06 +0000 | [diff] [blame] | 1959 | ValueObjectSP image_ptr_sp = result_valobj_sp->GetChildAtIndex(0, true); |
| 1960 | if (image_ptr_sp && image_ptr_sp->ResolveValue (scalar)) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1961 | { |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 1962 | addr_t image_ptr = scalar.ULongLong(LLDB_INVALID_ADDRESS); |
| 1963 | if (image_ptr != 0 && image_ptr != LLDB_INVALID_ADDRESS) |
| 1964 | { |
| 1965 | uint32_t image_token = m_image_tokens.size(); |
| 1966 | m_image_tokens.push_back (image_ptr); |
| 1967 | return image_token; |
| 1968 | } |
Jim Ingham | 3ac7cf3 | 2014-07-17 18:55:25 +0000 | [diff] [blame] | 1969 | else if (image_ptr == 0) |
| 1970 | { |
Jim Ingham | 6971b86 | 2014-07-19 00:37:06 +0000 | [diff] [blame] | 1971 | ValueObjectSP error_str_sp = result_valobj_sp->GetChildAtIndex(1, true); |
| 1972 | if (error_str_sp) |
Jim Ingham | 3ac7cf3 | 2014-07-17 18:55:25 +0000 | [diff] [blame] | 1973 | { |
Jim Ingham | 6971b86 | 2014-07-19 00:37:06 +0000 | [diff] [blame] | 1974 | if (error_str_sp->IsCStringContainer(true)) |
Jim Ingham | 3ac7cf3 | 2014-07-17 18:55:25 +0000 | [diff] [blame] | 1975 | { |
Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1976 | DataBufferSP buffer_sp(new DataBufferHeap(10240,0)); |
| 1977 | size_t num_chars = error_str_sp->ReadPointedString (buffer_sp, error, 10240); |
Jim Ingham | 3ac7cf3 | 2014-07-17 18:55:25 +0000 | [diff] [blame] | 1978 | if (error.Success() && num_chars > 0) |
| 1979 | { |
| 1980 | error.Clear(); |
Enrico Granata | 2206b48 | 2014-10-30 18:27:31 +0000 | [diff] [blame] | 1981 | error.SetErrorStringWithFormat("dlopen error: %s", buffer_sp->GetBytes()); |
| 1982 | } |
| 1983 | else |
| 1984 | { |
| 1985 | error.Clear(); |
| 1986 | error.SetErrorStringWithFormat("dlopen failed for unknown reasons."); |
Jim Ingham | 3ac7cf3 | 2014-07-17 18:55:25 +0000 | [diff] [blame] | 1987 | } |
| 1988 | } |
| 1989 | } |
| 1990 | } |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1991 | } |
| 1992 | } |
| 1993 | } |
Jim Ingham | 6c9ed91 | 2014-04-03 01:26:14 +0000 | [diff] [blame] | 1994 | else |
| 1995 | error = expr_error; |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1996 | } |
| 1997 | } |
| 1998 | } |
Greg Clayton | ac7a3db | 2012-04-18 00:05:19 +0000 | [diff] [blame] | 1999 | if (!error.AsCString()) |
| 2000 | error.SetErrorStringWithFormat("unable to load '%s'", path); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 2001 | return LLDB_INVALID_IMAGE_TOKEN; |
| 2002 | } |
| 2003 | |
| 2004 | //---------------------------------------------------------------------- |
| 2005 | // UnloadImage |
| 2006 | // |
| 2007 | // This function provides a default implementation that works for most |
| 2008 | // unix variants. Any Process subclasses that need to do shared library |
| 2009 | // loading differently should override LoadImage and UnloadImage and |
| 2010 | // do what is needed. |
| 2011 | //---------------------------------------------------------------------- |
| 2012 | Error |
| 2013 | Process::UnloadImage (uint32_t image_token) |
| 2014 | { |
| 2015 | Error error; |
Greg Clayton | c00ca31 | 2015-04-02 18:44:58 +0000 | [diff] [blame] | 2016 | |
| 2017 | if (m_finalizing) |
| 2018 | { |
| 2019 | error.SetErrorString("process is tearing itself down"); |
| 2020 | return error; |
| 2021 | } |
| 2022 | |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 2023 | if (image_token < m_image_tokens.size()) |
| 2024 | { |
| 2025 | const addr_t image_addr = m_image_tokens[image_token]; |
| 2026 | if (image_addr == LLDB_INVALID_ADDRESS) |
| 2027 | { |
| 2028 | error.SetErrorString("image already unloaded"); |
| 2029 | } |
| 2030 | else |
| 2031 | { |
| 2032 | DynamicLoader *loader = GetDynamicLoader(); |
| 2033 | if (loader) |
| 2034 | error = loader->CanLoadImage(); |
| 2035 | |
| 2036 | if (error.Success()) |
| 2037 | { |
| 2038 | ThreadSP thread_sp(GetThreadList ().GetSelectedThread()); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 2039 | |
| 2040 | if (thread_sp) |
| 2041 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 2042 | StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex (0)); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 2043 | |
| 2044 | if (frame_sp) |
| 2045 | { |
| 2046 | ExecutionContext exe_ctx; |
| 2047 | frame_sp->CalculateExecutionContext (exe_ctx); |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 2048 | EvaluateExpressionOptions expr_options; |
| 2049 | expr_options.SetUnwindOnError(true); |
| 2050 | expr_options.SetIgnoreBreakpoints(true); |
| 2051 | expr_options.SetExecutionPolicy(eExecutionPolicyAlways); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 2052 | StreamString expr; |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2053 | expr.Printf("dlclose ((void *)0x%" PRIx64 ")", image_addr); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 2054 | const char *prefix = "extern \"C\" int dlclose(void* handle);\n"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 2055 | lldb::ValueObjectSP result_valobj_sp; |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 2056 | Error expr_error; |
Greg Clayton | 26ab83d | 2012-10-31 20:49:04 +0000 | [diff] [blame] | 2057 | ClangUserExpression::Evaluate (exe_ctx, |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 2058 | expr_options, |
Greg Clayton | 26ab83d | 2012-10-31 20:49:04 +0000 | [diff] [blame] | 2059 | expr.GetData(), |
| 2060 | prefix, |
| 2061 | result_valobj_sp, |
Greg Clayton | 62afb9f | 2013-11-04 19:35:17 +0000 | [diff] [blame] | 2062 | expr_error); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 2063 | if (result_valobj_sp->GetError().Success()) |
| 2064 | { |
| 2065 | Scalar scalar; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 2066 | if (result_valobj_sp->ResolveValue (scalar)) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 2067 | { |
| 2068 | if (scalar.UInt(1)) |
| 2069 | { |
| 2070 | error.SetErrorStringWithFormat("expression failed: \"%s\"", expr.GetData()); |
| 2071 | } |
| 2072 | else |
| 2073 | { |
| 2074 | m_image_tokens[image_token] = LLDB_INVALID_ADDRESS; |
| 2075 | } |
| 2076 | } |
| 2077 | } |
| 2078 | else |
| 2079 | { |
| 2080 | error = result_valobj_sp->GetError(); |
| 2081 | } |
| 2082 | } |
| 2083 | } |
| 2084 | } |
| 2085 | } |
| 2086 | } |
| 2087 | else |
| 2088 | { |
| 2089 | error.SetErrorString("invalid image token"); |
| 2090 | } |
| 2091 | return error; |
| 2092 | } |
| 2093 | |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 2094 | const lldb::ABISP & |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2095 | Process::GetABI() |
| 2096 | { |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 2097 | if (!m_abi_sp) |
| 2098 | m_abi_sp = ABI::FindPlugin(m_target.GetArchitecture()); |
| 2099 | return m_abi_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2100 | } |
| 2101 | |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 2102 | LanguageRuntime * |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 2103 | Process::GetLanguageRuntime(lldb::LanguageType language, bool retry_if_null) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 2104 | { |
Greg Clayton | c00ca31 | 2015-04-02 18:44:58 +0000 | [diff] [blame] | 2105 | if (m_finalizing) |
| 2106 | return nullptr; |
| 2107 | |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 2108 | LanguageRuntimeCollection::iterator pos; |
| 2109 | pos = m_language_runtimes.find (language); |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 2110 | if (pos == m_language_runtimes.end() || (retry_if_null && !(*pos).second)) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 2111 | { |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 2112 | lldb::LanguageRuntimeSP runtime_sp(LanguageRuntime::FindPlugin(this, language)); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 2113 | |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 2114 | m_language_runtimes[language] = runtime_sp; |
| 2115 | return runtime_sp.get(); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 2116 | } |
| 2117 | else |
| 2118 | return (*pos).second.get(); |
| 2119 | } |
| 2120 | |
| 2121 | CPPLanguageRuntime * |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 2122 | Process::GetCPPLanguageRuntime (bool retry_if_null) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 2123 | { |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 2124 | LanguageRuntime *runtime = GetLanguageRuntime(eLanguageTypeC_plus_plus, retry_if_null); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 2125 | if (runtime != NULL && runtime->GetLanguageType() == eLanguageTypeC_plus_plus) |
| 2126 | return static_cast<CPPLanguageRuntime *> (runtime); |
| 2127 | return NULL; |
| 2128 | } |
| 2129 | |
| 2130 | ObjCLanguageRuntime * |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 2131 | Process::GetObjCLanguageRuntime (bool retry_if_null) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 2132 | { |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 2133 | LanguageRuntime *runtime = GetLanguageRuntime(eLanguageTypeObjC, retry_if_null); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 2134 | if (runtime != NULL && runtime->GetLanguageType() == eLanguageTypeObjC) |
| 2135 | return static_cast<ObjCLanguageRuntime *> (runtime); |
| 2136 | return NULL; |
| 2137 | } |
| 2138 | |
Enrico Granata | fd4c84e | 2012-05-21 16:51:35 +0000 | [diff] [blame] | 2139 | bool |
| 2140 | Process::IsPossibleDynamicValue (ValueObject& in_value) |
| 2141 | { |
Greg Clayton | c00ca31 | 2015-04-02 18:44:58 +0000 | [diff] [blame] | 2142 | if (m_finalizing) |
| 2143 | return false; |
| 2144 | |
Enrico Granata | fd4c84e | 2012-05-21 16:51:35 +0000 | [diff] [blame] | 2145 | if (in_value.IsDynamic()) |
| 2146 | return false; |
| 2147 | LanguageType known_type = in_value.GetObjectRuntimeLanguage(); |
| 2148 | |
| 2149 | if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC) |
| 2150 | { |
| 2151 | LanguageRuntime *runtime = GetLanguageRuntime (known_type); |
| 2152 | return runtime ? runtime->CouldHaveDynamicValue(in_value) : false; |
| 2153 | } |
| 2154 | |
| 2155 | LanguageRuntime *cpp_runtime = GetLanguageRuntime (eLanguageTypeC_plus_plus); |
| 2156 | if (cpp_runtime && cpp_runtime->CouldHaveDynamicValue(in_value)) |
| 2157 | return true; |
| 2158 | |
| 2159 | LanguageRuntime *objc_runtime = GetLanguageRuntime (eLanguageTypeObjC); |
| 2160 | return objc_runtime ? objc_runtime->CouldHaveDynamicValue(in_value) : false; |
| 2161 | } |
| 2162 | |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 2163 | void |
| 2164 | Process::SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers) |
| 2165 | { |
| 2166 | m_dynamic_checkers_ap.reset(dynamic_checkers); |
| 2167 | } |
| 2168 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2169 | BreakpointSiteList & |
| 2170 | Process::GetBreakpointSiteList() |
| 2171 | { |
| 2172 | return m_breakpoint_site_list; |
| 2173 | } |
| 2174 | |
| 2175 | const BreakpointSiteList & |
| 2176 | Process::GetBreakpointSiteList() const |
| 2177 | { |
| 2178 | return m_breakpoint_site_list; |
| 2179 | } |
| 2180 | |
| 2181 | |
| 2182 | void |
| 2183 | Process::DisableAllBreakpointSites () |
| 2184 | { |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2185 | m_breakpoint_site_list.ForEach([this](BreakpointSite *bp_site) -> void { |
| 2186 | // bp_site->SetEnabled(true); |
| 2187 | DisableBreakpointSite(bp_site); |
| 2188 | }); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | Error |
| 2192 | Process::ClearBreakpointSiteByID (lldb::user_id_t break_id) |
| 2193 | { |
| 2194 | Error error (DisableBreakpointSiteByID (break_id)); |
| 2195 | |
| 2196 | if (error.Success()) |
| 2197 | m_breakpoint_site_list.Remove(break_id); |
| 2198 | |
| 2199 | return error; |
| 2200 | } |
| 2201 | |
| 2202 | Error |
| 2203 | Process::DisableBreakpointSiteByID (lldb::user_id_t break_id) |
| 2204 | { |
| 2205 | Error error; |
| 2206 | BreakpointSiteSP bp_site_sp = m_breakpoint_site_list.FindByID (break_id); |
| 2207 | if (bp_site_sp) |
| 2208 | { |
| 2209 | if (bp_site_sp->IsEnabled()) |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 2210 | error = DisableBreakpointSite (bp_site_sp.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2211 | } |
| 2212 | else |
| 2213 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2214 | error.SetErrorStringWithFormat("invalid breakpoint site ID: %" PRIu64, break_id); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | return error; |
| 2218 | } |
| 2219 | |
| 2220 | Error |
| 2221 | Process::EnableBreakpointSiteByID (lldb::user_id_t break_id) |
| 2222 | { |
| 2223 | Error error; |
| 2224 | BreakpointSiteSP bp_site_sp = m_breakpoint_site_list.FindByID (break_id); |
| 2225 | if (bp_site_sp) |
| 2226 | { |
| 2227 | if (!bp_site_sp->IsEnabled()) |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 2228 | error = EnableBreakpointSite (bp_site_sp.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2229 | } |
| 2230 | else |
| 2231 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2232 | error.SetErrorStringWithFormat("invalid breakpoint site ID: %" PRIu64, break_id); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2233 | } |
| 2234 | return error; |
| 2235 | } |
| 2236 | |
Stephen Wilson | 50bd94f | 2010-07-17 00:56:13 +0000 | [diff] [blame] | 2237 | lldb::break_id_t |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 2238 | Process::CreateBreakpointSite (const BreakpointLocationSP &owner, bool use_hardware) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2239 | { |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 2240 | addr_t load_addr = LLDB_INVALID_ADDRESS; |
| 2241 | |
| 2242 | bool show_error = true; |
| 2243 | switch (GetState()) |
| 2244 | { |
| 2245 | case eStateInvalid: |
| 2246 | case eStateUnloaded: |
| 2247 | case eStateConnected: |
| 2248 | case eStateAttaching: |
| 2249 | case eStateLaunching: |
| 2250 | case eStateDetached: |
| 2251 | case eStateExited: |
| 2252 | show_error = false; |
| 2253 | break; |
| 2254 | |
| 2255 | case eStateStopped: |
| 2256 | case eStateRunning: |
| 2257 | case eStateStepping: |
| 2258 | case eStateCrashed: |
| 2259 | case eStateSuspended: |
| 2260 | show_error = IsAlive(); |
| 2261 | break; |
| 2262 | } |
| 2263 | |
| 2264 | // Reset the IsIndirect flag here, in case the location changes from |
| 2265 | // pointing to a indirect symbol to a regular symbol. |
| 2266 | owner->SetIsIndirect (false); |
| 2267 | |
| 2268 | if (owner->ShouldResolveIndirectFunctions()) |
| 2269 | { |
| 2270 | Symbol *symbol = owner->GetAddress().CalculateSymbolContextSymbol(); |
| 2271 | if (symbol && symbol->IsIndirect()) |
| 2272 | { |
| 2273 | Error error; |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2274 | Address symbol_address = symbol->GetAddress(); |
| 2275 | load_addr = ResolveIndirectFunction (&symbol_address, error); |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 2276 | if (!error.Success() && show_error) |
| 2277 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 2278 | m_target.GetDebugger().GetErrorFile()->Printf ("warning: failed to resolve indirect function at 0x%" PRIx64 " for breakpoint %i.%i: %s\n", |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 2279 | symbol->GetLoadAddress(&m_target), |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 2280 | owner->GetBreakpoint().GetID(), |
| 2281 | owner->GetID(), |
Sylvestre Ledru | f610289 | 2014-08-11 18:06:28 +0000 | [diff] [blame] | 2282 | error.AsCString() ? error.AsCString() : "unknown error"); |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 2283 | return LLDB_INVALID_BREAK_ID; |
| 2284 | } |
| 2285 | Address resolved_address(load_addr); |
| 2286 | load_addr = resolved_address.GetOpcodeLoadAddress (&m_target); |
| 2287 | owner->SetIsIndirect(true); |
| 2288 | } |
| 2289 | else |
| 2290 | load_addr = owner->GetAddress().GetOpcodeLoadAddress (&m_target); |
| 2291 | } |
| 2292 | else |
| 2293 | load_addr = owner->GetAddress().GetOpcodeLoadAddress (&m_target); |
| 2294 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2295 | if (load_addr != LLDB_INVALID_ADDRESS) |
| 2296 | { |
| 2297 | BreakpointSiteSP bp_site_sp; |
| 2298 | |
| 2299 | // Look up this breakpoint site. If it exists, then add this new owner, otherwise |
| 2300 | // create a new breakpoint site and add it. |
| 2301 | |
| 2302 | bp_site_sp = m_breakpoint_site_list.FindByAddress (load_addr); |
| 2303 | |
| 2304 | if (bp_site_sp) |
| 2305 | { |
| 2306 | bp_site_sp->AddOwner (owner); |
| 2307 | owner->SetBreakpointSite (bp_site_sp); |
| 2308 | return bp_site_sp->GetID(); |
| 2309 | } |
| 2310 | else |
| 2311 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2312 | 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] | 2313 | if (bp_site_sp) |
| 2314 | { |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 2315 | Error error = EnableBreakpointSite (bp_site_sp.get()); |
| 2316 | if (error.Success()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2317 | { |
| 2318 | owner->SetBreakpointSite (bp_site_sp); |
| 2319 | return m_breakpoint_site_list.Add (bp_site_sp); |
| 2320 | } |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 2321 | else |
| 2322 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 2323 | if (show_error) |
| 2324 | { |
| 2325 | // Report error for setting breakpoint... |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 2326 | m_target.GetDebugger().GetErrorFile()->Printf ("warning: failed to set breakpoint site at 0x%" PRIx64 " for breakpoint %i.%i: %s\n", |
| 2327 | load_addr, |
| 2328 | owner->GetBreakpoint().GetID(), |
| 2329 | owner->GetID(), |
Sylvestre Ledru | f610289 | 2014-08-11 18:06:28 +0000 | [diff] [blame] | 2330 | error.AsCString() ? error.AsCString() : "unknown error"); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 2331 | } |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 2332 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2333 | } |
| 2334 | } |
| 2335 | } |
| 2336 | // We failed to enable the breakpoint |
| 2337 | return LLDB_INVALID_BREAK_ID; |
| 2338 | |
| 2339 | } |
| 2340 | |
| 2341 | void |
| 2342 | Process::RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id, lldb::user_id_t owner_loc_id, BreakpointSiteSP &bp_site_sp) |
| 2343 | { |
| 2344 | uint32_t num_owners = bp_site_sp->RemoveOwner (owner_id, owner_loc_id); |
| 2345 | if (num_owners == 0) |
| 2346 | { |
Jim Ingham | f1ff3bb | 2013-04-06 00:16:39 +0000 | [diff] [blame] | 2347 | // Don't try to disable the site if we don't have a live process anymore. |
| 2348 | if (IsAlive()) |
| 2349 | DisableBreakpointSite (bp_site_sp.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2350 | m_breakpoint_site_list.RemoveByAddress(bp_site_sp->GetLoadAddress()); |
| 2351 | } |
| 2352 | } |
| 2353 | |
| 2354 | |
| 2355 | size_t |
| 2356 | Process::RemoveBreakpointOpcodesFromBuffer (addr_t bp_addr, size_t size, uint8_t *buf) const |
| 2357 | { |
| 2358 | size_t bytes_removed = 0; |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 2359 | BreakpointSiteList bp_sites_in_range; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2360 | |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 2361 | 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] | 2362 | { |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2363 | bp_sites_in_range.ForEach([bp_addr, size, buf, &bytes_removed](BreakpointSite *bp_site) -> void { |
| 2364 | if (bp_site->GetType() == BreakpointSite::eSoftware) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2365 | { |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2366 | addr_t intersect_addr; |
| 2367 | size_t intersect_size; |
| 2368 | size_t opcode_offset; |
| 2369 | 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] | 2370 | { |
| 2371 | assert(bp_addr <= intersect_addr && intersect_addr < bp_addr + size); |
| 2372 | 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] | 2373 | assert(opcode_offset + intersect_size <= bp_site->GetByteSize()); |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 2374 | size_t buf_offset = intersect_addr - bp_addr; |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2375 | ::memcpy(buf + buf_offset, bp_site->GetSavedOpcodeBytes() + opcode_offset, intersect_size); |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 2376 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2377 | } |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2378 | }); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2379 | } |
| 2380 | return bytes_removed; |
| 2381 | } |
| 2382 | |
| 2383 | |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 2384 | |
| 2385 | size_t |
| 2386 | Process::GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site) |
| 2387 | { |
| 2388 | PlatformSP platform_sp (m_target.GetPlatform()); |
| 2389 | if (platform_sp) |
| 2390 | return platform_sp->GetSoftwareBreakpointTrapOpcode (m_target, bp_site); |
| 2391 | return 0; |
| 2392 | } |
| 2393 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2394 | Error |
| 2395 | Process::EnableSoftwareBreakpoint (BreakpointSite *bp_site) |
| 2396 | { |
| 2397 | Error error; |
| 2398 | assert (bp_site != NULL); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2399 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2400 | const addr_t bp_addr = bp_site->GetLoadAddress(); |
| 2401 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2402 | 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] | 2403 | if (bp_site->IsEnabled()) |
| 2404 | { |
| 2405 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2406 | 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] | 2407 | return error; |
| 2408 | } |
| 2409 | |
| 2410 | if (bp_addr == LLDB_INVALID_ADDRESS) |
| 2411 | { |
| 2412 | error.SetErrorString("BreakpointSite contains an invalid load address."); |
| 2413 | return error; |
| 2414 | } |
| 2415 | // Ask the lldb::Process subclass to fill in the correct software breakpoint |
| 2416 | // trap for the breakpoint site |
| 2417 | const size_t bp_opcode_size = GetSoftwareBreakpointTrapOpcode(bp_site); |
| 2418 | |
| 2419 | if (bp_opcode_size == 0) |
| 2420 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2421 | 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] | 2422 | } |
| 2423 | else |
| 2424 | { |
| 2425 | const uint8_t * const bp_opcode_bytes = bp_site->GetTrapOpcodeBytes(); |
| 2426 | |
| 2427 | if (bp_opcode_bytes == NULL) |
| 2428 | { |
| 2429 | error.SetErrorString ("BreakpointSite doesn't contain a valid breakpoint trap opcode."); |
| 2430 | return error; |
| 2431 | } |
| 2432 | |
| 2433 | // Save the original opcode by reading it |
| 2434 | if (DoReadMemory(bp_addr, bp_site->GetSavedOpcodeBytes(), bp_opcode_size, error) == bp_opcode_size) |
| 2435 | { |
| 2436 | // Write a software breakpoint in place of the original opcode |
| 2437 | if (DoWriteMemory(bp_addr, bp_opcode_bytes, bp_opcode_size, error) == bp_opcode_size) |
| 2438 | { |
| 2439 | uint8_t verify_bp_opcode_bytes[64]; |
| 2440 | if (DoReadMemory(bp_addr, verify_bp_opcode_bytes, bp_opcode_size, error) == bp_opcode_size) |
| 2441 | { |
| 2442 | if (::memcmp(bp_opcode_bytes, verify_bp_opcode_bytes, bp_opcode_size) == 0) |
| 2443 | { |
| 2444 | bp_site->SetEnabled(true); |
| 2445 | bp_site->SetType (BreakpointSite::eSoftware); |
| 2446 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2447 | log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64 " -- SUCCESS", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2448 | bp_site->GetID(), |
| 2449 | (uint64_t)bp_addr); |
| 2450 | } |
| 2451 | else |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 2452 | error.SetErrorString("failed to verify the breakpoint trap in memory."); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2453 | } |
| 2454 | else |
| 2455 | error.SetErrorString("Unable to read memory to verify breakpoint trap."); |
| 2456 | } |
| 2457 | else |
| 2458 | error.SetErrorString("Unable to write breakpoint trap to memory."); |
| 2459 | } |
| 2460 | else |
| 2461 | error.SetErrorString("Unable to read memory at breakpoint address."); |
| 2462 | } |
Stephen Wilson | 78a4feb | 2011-01-12 04:20:03 +0000 | [diff] [blame] | 2463 | if (log && error.Fail()) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2464 | log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64 " -- FAILED: %s", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2465 | bp_site->GetID(), |
| 2466 | (uint64_t)bp_addr, |
| 2467 | error.AsCString()); |
| 2468 | return error; |
| 2469 | } |
| 2470 | |
| 2471 | Error |
| 2472 | Process::DisableSoftwareBreakpoint (BreakpointSite *bp_site) |
| 2473 | { |
| 2474 | Error error; |
| 2475 | assert (bp_site != NULL); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2476 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2477 | addr_t bp_addr = bp_site->GetLoadAddress(); |
| 2478 | lldb::user_id_t breakID = bp_site->GetID(); |
| 2479 | if (log) |
Jim Ingham | 299c0c1 | 2013-02-15 02:06:30 +0000 | [diff] [blame] | 2480 | 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] | 2481 | |
| 2482 | if (bp_site->IsHardware()) |
| 2483 | { |
| 2484 | error.SetErrorString("Breakpoint site is a hardware breakpoint."); |
| 2485 | } |
| 2486 | else if (bp_site->IsEnabled()) |
| 2487 | { |
| 2488 | const size_t break_op_size = bp_site->GetByteSize(); |
| 2489 | const uint8_t * const break_op = bp_site->GetTrapOpcodeBytes(); |
| 2490 | if (break_op_size > 0) |
| 2491 | { |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 2492 | // Clear a software breakpoint instruction |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 2493 | uint8_t curr_break_op[8]; |
Stephen Wilson | 4ab4768 | 2010-07-20 18:41:11 +0000 | [diff] [blame] | 2494 | assert (break_op_size <= sizeof(curr_break_op)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2495 | bool break_op_found = false; |
| 2496 | |
| 2497 | // Read the breakpoint opcode |
| 2498 | if (DoReadMemory (bp_addr, curr_break_op, break_op_size, error) == break_op_size) |
| 2499 | { |
| 2500 | bool verify = false; |
Bruce Mitchener | 58ef391 | 2015-06-18 05:27:05 +0000 | [diff] [blame] | 2501 | // Make sure the breakpoint opcode exists at this address |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2502 | if (::memcmp (curr_break_op, break_op, break_op_size) == 0) |
| 2503 | { |
| 2504 | break_op_found = true; |
| 2505 | // We found a valid breakpoint opcode at this address, now restore |
| 2506 | // the saved opcode. |
| 2507 | if (DoWriteMemory (bp_addr, bp_site->GetSavedOpcodeBytes(), break_op_size, error) == break_op_size) |
| 2508 | { |
| 2509 | verify = true; |
| 2510 | } |
| 2511 | else |
| 2512 | error.SetErrorString("Memory write failed when restoring original opcode."); |
| 2513 | } |
| 2514 | else |
| 2515 | { |
| 2516 | error.SetErrorString("Original breakpoint trap is no longer in memory."); |
| 2517 | // Set verify to true and so we can check if the original opcode has already been restored |
| 2518 | verify = true; |
| 2519 | } |
| 2520 | |
| 2521 | if (verify) |
| 2522 | { |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 2523 | uint8_t verify_opcode[8]; |
Stephen Wilson | 4ab4768 | 2010-07-20 18:41:11 +0000 | [diff] [blame] | 2524 | assert (break_op_size < sizeof(verify_opcode)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2525 | // Verify that our original opcode made it back to the inferior |
| 2526 | if (DoReadMemory (bp_addr, verify_opcode, break_op_size, error) == break_op_size) |
| 2527 | { |
| 2528 | // compare the memory we just read with the original opcode |
| 2529 | if (::memcmp (bp_site->GetSavedOpcodeBytes(), verify_opcode, break_op_size) == 0) |
| 2530 | { |
| 2531 | // SUCCESS |
| 2532 | bp_site->SetEnabled(false); |
| 2533 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2534 | 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] | 2535 | return error; |
| 2536 | } |
| 2537 | else |
| 2538 | { |
| 2539 | if (break_op_found) |
| 2540 | error.SetErrorString("Failed to restore original opcode."); |
| 2541 | } |
| 2542 | } |
| 2543 | else |
| 2544 | error.SetErrorString("Failed to read memory to verify that breakpoint trap was restored."); |
| 2545 | } |
| 2546 | } |
| 2547 | else |
| 2548 | error.SetErrorString("Unable to read memory that should contain the breakpoint trap."); |
| 2549 | } |
| 2550 | } |
| 2551 | else |
| 2552 | { |
| 2553 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2554 | 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] | 2555 | return error; |
| 2556 | } |
| 2557 | |
| 2558 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 2559 | log->Printf ("Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%" PRIx64 " -- FAILED: %s", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2560 | bp_site->GetID(), |
| 2561 | (uint64_t)bp_addr, |
| 2562 | error.AsCString()); |
| 2563 | return error; |
| 2564 | |
| 2565 | } |
| 2566 | |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2567 | // Uncomment to verify memory caching works after making changes to caching code |
| 2568 | //#define VERIFY_MEMORY_READS |
| 2569 | |
Sean Callanan | 64c0cf2 | 2012-06-07 22:26:42 +0000 | [diff] [blame] | 2570 | size_t |
| 2571 | Process::ReadMemory (addr_t addr, void *buf, size_t size, Error &error) |
| 2572 | { |
Jason Molenda | a7b5afa | 2013-11-15 00:17:32 +0000 | [diff] [blame] | 2573 | error.Clear(); |
Sean Callanan | 64c0cf2 | 2012-06-07 22:26:42 +0000 | [diff] [blame] | 2574 | if (!GetDisableMemoryCache()) |
| 2575 | { |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2576 | #if defined (VERIFY_MEMORY_READS) |
Sean Callanan | 64c0cf2 | 2012-06-07 22:26:42 +0000 | [diff] [blame] | 2577 | // Memory caching is enabled, with debug verification |
| 2578 | |
| 2579 | if (buf && size) |
| 2580 | { |
| 2581 | // Uncomment the line below to make sure memory caching is working. |
| 2582 | // I ran this through the test suite and got no assertions, so I am |
| 2583 | // pretty confident this is working well. If any changes are made to |
| 2584 | // memory caching, uncomment the line below and test your changes! |
| 2585 | |
| 2586 | // Verify all memory reads by using the cache first, then redundantly |
| 2587 | // reading the same memory from the inferior and comparing to make sure |
| 2588 | // everything is exactly the same. |
| 2589 | std::string verify_buf (size, '\0'); |
| 2590 | assert (verify_buf.size() == size); |
| 2591 | const size_t cache_bytes_read = m_memory_cache.Read (this, addr, buf, size, error); |
| 2592 | Error verify_error; |
| 2593 | const size_t verify_bytes_read = ReadMemoryFromInferior (addr, const_cast<char *>(verify_buf.data()), verify_buf.size(), verify_error); |
| 2594 | assert (cache_bytes_read == verify_bytes_read); |
| 2595 | assert (memcmp(buf, verify_buf.data(), verify_buf.size()) == 0); |
| 2596 | assert (verify_error.Success() == error.Success()); |
| 2597 | return cache_bytes_read; |
| 2598 | } |
| 2599 | return 0; |
| 2600 | #else // !defined(VERIFY_MEMORY_READS) |
| 2601 | // Memory caching is enabled, without debug verification |
| 2602 | |
| 2603 | return m_memory_cache.Read (addr, buf, size, error); |
| 2604 | #endif // defined (VERIFY_MEMORY_READS) |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2605 | } |
Sean Callanan | 64c0cf2 | 2012-06-07 22:26:42 +0000 | [diff] [blame] | 2606 | else |
| 2607 | { |
| 2608 | // Memory caching is disabled |
| 2609 | |
| 2610 | return ReadMemoryFromInferior (addr, buf, size, error); |
| 2611 | } |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2612 | } |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2613 | |
Greg Clayton | 4c82d42 | 2012-05-18 23:20:01 +0000 | [diff] [blame] | 2614 | size_t |
| 2615 | Process::ReadCStringFromMemory (addr_t addr, std::string &out_str, Error &error) |
| 2616 | { |
Greg Clayton | de87c0f | 2012-05-19 00:18:00 +0000 | [diff] [blame] | 2617 | char buf[256]; |
Greg Clayton | 4c82d42 | 2012-05-18 23:20:01 +0000 | [diff] [blame] | 2618 | out_str.clear(); |
| 2619 | addr_t curr_addr = addr; |
| 2620 | while (1) |
| 2621 | { |
| 2622 | size_t length = ReadCStringFromMemory (curr_addr, buf, sizeof(buf), error); |
| 2623 | if (length == 0) |
| 2624 | break; |
| 2625 | out_str.append(buf, length); |
| 2626 | // If we got "length - 1" bytes, we didn't get the whole C string, we |
| 2627 | // need to read some more characters |
| 2628 | if (length == sizeof(buf) - 1) |
| 2629 | curr_addr += length; |
| 2630 | else |
| 2631 | break; |
| 2632 | } |
| 2633 | return out_str.size(); |
| 2634 | } |
| 2635 | |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2636 | |
| 2637 | size_t |
Ashok Thirumurthi | 6ac9d13 | 2013-04-19 15:58:38 +0000 | [diff] [blame] | 2638 | Process::ReadStringFromMemory (addr_t addr, char *dst, size_t max_bytes, Error &error, |
| 2639 | size_t type_width) |
| 2640 | { |
| 2641 | size_t total_bytes_read = 0; |
| 2642 | if (dst && max_bytes && type_width && max_bytes >= type_width) |
| 2643 | { |
| 2644 | // Ensure a null terminator independent of the number of bytes that is read. |
| 2645 | memset (dst, 0, max_bytes); |
| 2646 | size_t bytes_left = max_bytes - type_width; |
| 2647 | |
| 2648 | const char terminator[4] = {'\0', '\0', '\0', '\0'}; |
| 2649 | assert(sizeof(terminator) >= type_width && |
| 2650 | "Attempting to validate a string with more than 4 bytes per character!"); |
| 2651 | |
| 2652 | addr_t curr_addr = addr; |
| 2653 | const size_t cache_line_size = m_memory_cache.GetMemoryCacheLineSize(); |
| 2654 | char *curr_dst = dst; |
| 2655 | |
| 2656 | error.Clear(); |
| 2657 | while (bytes_left > 0 && error.Success()) |
| 2658 | { |
| 2659 | addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size); |
| 2660 | addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left); |
| 2661 | size_t bytes_read = ReadMemory (curr_addr, curr_dst, bytes_to_read, error); |
| 2662 | |
| 2663 | if (bytes_read == 0) |
| 2664 | break; |
| 2665 | |
| 2666 | // Search for a null terminator of correct size and alignment in bytes_read |
| 2667 | size_t aligned_start = total_bytes_read - total_bytes_read % type_width; |
| 2668 | for (size_t i = aligned_start; i + type_width <= total_bytes_read + bytes_read; i += type_width) |
| 2669 | if (::strncmp(&dst[i], terminator, type_width) == 0) |
| 2670 | { |
| 2671 | error.Clear(); |
| 2672 | return i; |
| 2673 | } |
| 2674 | |
| 2675 | total_bytes_read += bytes_read; |
| 2676 | curr_dst += bytes_read; |
| 2677 | curr_addr += bytes_read; |
| 2678 | bytes_left -= bytes_read; |
| 2679 | } |
| 2680 | } |
| 2681 | else |
| 2682 | { |
| 2683 | if (max_bytes) |
| 2684 | error.SetErrorString("invalid arguments"); |
| 2685 | } |
| 2686 | return total_bytes_read; |
| 2687 | } |
| 2688 | |
| 2689 | // Deprecated in favor of ReadStringFromMemory which has wchar support and correct code to find |
| 2690 | // null terminators. |
| 2691 | size_t |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 2692 | 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] | 2693 | { |
| 2694 | size_t total_cstr_len = 0; |
| 2695 | if (dst && dst_max_len) |
| 2696 | { |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 2697 | result_error.Clear(); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2698 | // NULL out everything just to be safe |
| 2699 | memset (dst, 0, dst_max_len); |
| 2700 | Error error; |
| 2701 | addr_t curr_addr = addr; |
| 2702 | const size_t cache_line_size = m_memory_cache.GetMemoryCacheLineSize(); |
| 2703 | size_t bytes_left = dst_max_len - 1; |
| 2704 | char *curr_dst = dst; |
| 2705 | |
| 2706 | while (bytes_left > 0) |
| 2707 | { |
| 2708 | addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size); |
| 2709 | addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left); |
| 2710 | size_t bytes_read = ReadMemory (curr_addr, curr_dst, bytes_to_read, error); |
| 2711 | |
| 2712 | if (bytes_read == 0) |
| 2713 | { |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 2714 | result_error = error; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2715 | dst[total_cstr_len] = '\0'; |
| 2716 | break; |
| 2717 | } |
| 2718 | const size_t len = strlen(curr_dst); |
| 2719 | |
| 2720 | total_cstr_len += len; |
| 2721 | |
| 2722 | if (len < bytes_to_read) |
| 2723 | break; |
| 2724 | |
| 2725 | curr_dst += bytes_read; |
| 2726 | curr_addr += bytes_read; |
| 2727 | bytes_left -= bytes_read; |
| 2728 | } |
| 2729 | } |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 2730 | else |
| 2731 | { |
| 2732 | if (dst == NULL) |
| 2733 | result_error.SetErrorString("invalid arguments"); |
| 2734 | else |
| 2735 | result_error.Clear(); |
| 2736 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2737 | return total_cstr_len; |
| 2738 | } |
| 2739 | |
| 2740 | size_t |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2741 | Process::ReadMemoryFromInferior (addr_t addr, void *buf, size_t size, Error &error) |
| 2742 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2743 | if (buf == NULL || size == 0) |
| 2744 | return 0; |
| 2745 | |
| 2746 | size_t bytes_read = 0; |
| 2747 | uint8_t *bytes = (uint8_t *)buf; |
| 2748 | |
| 2749 | while (bytes_read < size) |
| 2750 | { |
| 2751 | const size_t curr_size = size - bytes_read; |
| 2752 | const size_t curr_bytes_read = DoReadMemory (addr + bytes_read, |
| 2753 | bytes + bytes_read, |
| 2754 | curr_size, |
| 2755 | error); |
| 2756 | bytes_read += curr_bytes_read; |
| 2757 | if (curr_bytes_read == curr_size || curr_bytes_read == 0) |
| 2758 | break; |
| 2759 | } |
| 2760 | |
| 2761 | // Replace any software breakpoint opcodes that fall into this range back |
| 2762 | // into "buf" before we return |
| 2763 | if (bytes_read > 0) |
| 2764 | RemoveBreakpointOpcodesFromBuffer (addr, bytes_read, (uint8_t *)buf); |
| 2765 | return bytes_read; |
| 2766 | } |
| 2767 | |
Greg Clayton | 58a4c46 | 2010-12-16 20:01:20 +0000 | [diff] [blame] | 2768 | uint64_t |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2769 | 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] | 2770 | { |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2771 | Scalar scalar; |
| 2772 | if (ReadScalarIntegerFromMemory(vm_addr, integer_byte_size, false, scalar, error)) |
| 2773 | return scalar.ULongLong(fail_value); |
| 2774 | return fail_value; |
| 2775 | } |
| 2776 | |
| 2777 | addr_t |
| 2778 | Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error) |
| 2779 | { |
| 2780 | Scalar scalar; |
| 2781 | if (ReadScalarIntegerFromMemory(vm_addr, GetAddressByteSize(), false, scalar, error)) |
| 2782 | return scalar.ULongLong(LLDB_INVALID_ADDRESS); |
| 2783 | return LLDB_INVALID_ADDRESS; |
| 2784 | } |
| 2785 | |
| 2786 | |
| 2787 | bool |
| 2788 | Process::WritePointerToMemory (lldb::addr_t vm_addr, |
| 2789 | lldb::addr_t ptr_value, |
| 2790 | Error &error) |
| 2791 | { |
| 2792 | Scalar scalar; |
| 2793 | const uint32_t addr_byte_size = GetAddressByteSize(); |
| 2794 | if (addr_byte_size <= 4) |
| 2795 | scalar = (uint32_t)ptr_value; |
Greg Clayton | 58a4c46 | 2010-12-16 20:01:20 +0000 | [diff] [blame] | 2796 | else |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2797 | scalar = ptr_value; |
| 2798 | return WriteScalarToMemory(vm_addr, scalar, addr_byte_size, error) == addr_byte_size; |
Greg Clayton | 58a4c46 | 2010-12-16 20:01:20 +0000 | [diff] [blame] | 2799 | } |
| 2800 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2801 | size_t |
| 2802 | Process::WriteMemoryPrivate (addr_t addr, const void *buf, size_t size, Error &error) |
| 2803 | { |
| 2804 | size_t bytes_written = 0; |
| 2805 | const uint8_t *bytes = (const uint8_t *)buf; |
| 2806 | |
| 2807 | while (bytes_written < size) |
| 2808 | { |
| 2809 | const size_t curr_size = size - bytes_written; |
| 2810 | const size_t curr_bytes_written = DoWriteMemory (addr + bytes_written, |
| 2811 | bytes + bytes_written, |
| 2812 | curr_size, |
| 2813 | error); |
| 2814 | bytes_written += curr_bytes_written; |
| 2815 | if (curr_bytes_written == curr_size || curr_bytes_written == 0) |
| 2816 | break; |
| 2817 | } |
| 2818 | return bytes_written; |
| 2819 | } |
| 2820 | |
| 2821 | size_t |
| 2822 | Process::WriteMemory (addr_t addr, const void *buf, size_t size, Error &error) |
| 2823 | { |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2824 | #if defined (ENABLE_MEMORY_CACHING) |
| 2825 | m_memory_cache.Flush (addr, size); |
| 2826 | #endif |
| 2827 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2828 | if (buf == NULL || size == 0) |
| 2829 | return 0; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2830 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 2831 | m_mod_id.BumpMemoryID(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2832 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2833 | // We need to write any data that would go where any current software traps |
| 2834 | // (enabled software breakpoints) any software traps (breakpoints) that we |
| 2835 | // may have placed in our tasks memory. |
| 2836 | |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2837 | BreakpointSiteList bp_sites_in_range; |
| 2838 | |
| 2839 | 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] | 2840 | { |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2841 | // No breakpoint sites overlap |
| 2842 | if (bp_sites_in_range.IsEmpty()) |
| 2843 | return WriteMemoryPrivate (addr, buf, size, error); |
| 2844 | else |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2845 | { |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2846 | const uint8_t *ubuf = (const uint8_t *)buf; |
| 2847 | uint64_t bytes_written = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2848 | |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2849 | bp_sites_in_range.ForEach([this, addr, size, &bytes_written, &ubuf, &error](BreakpointSite *bp) -> void { |
| 2850 | |
| 2851 | if (error.Success()) |
| 2852 | { |
| 2853 | addr_t intersect_addr; |
| 2854 | size_t intersect_size; |
| 2855 | size_t opcode_offset; |
| 2856 | const bool intersects = bp->IntersectsRange(addr, size, &intersect_addr, &intersect_size, &opcode_offset); |
Bruce Mitchener | 8a67bf7 | 2015-07-24 00:23:29 +0000 | [diff] [blame] | 2857 | UNUSED_IF_ASSERT_DISABLED(intersects); |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2858 | assert(intersects); |
| 2859 | assert(addr <= intersect_addr && intersect_addr < addr + size); |
| 2860 | assert(addr < intersect_addr + intersect_size && intersect_addr + intersect_size <= addr + size); |
| 2861 | assert(opcode_offset + intersect_size <= bp->GetByteSize()); |
| 2862 | |
| 2863 | // Check for bytes before this breakpoint |
| 2864 | const addr_t curr_addr = addr + bytes_written; |
| 2865 | if (intersect_addr > curr_addr) |
| 2866 | { |
| 2867 | // There are some bytes before this breakpoint that we need to |
| 2868 | // just write to memory |
| 2869 | size_t curr_size = intersect_addr - curr_addr; |
| 2870 | size_t curr_bytes_written = WriteMemoryPrivate (curr_addr, |
| 2871 | ubuf + bytes_written, |
| 2872 | curr_size, |
| 2873 | error); |
| 2874 | bytes_written += curr_bytes_written; |
| 2875 | if (curr_bytes_written != curr_size) |
| 2876 | { |
| 2877 | // We weren't able to write all of the requested bytes, we |
| 2878 | // are done looping and will return the number of bytes that |
| 2879 | // we have written so far. |
| 2880 | if (error.Success()) |
| 2881 | error.SetErrorToGenericError(); |
| 2882 | } |
| 2883 | } |
| 2884 | // Now write any bytes that would cover up any software breakpoints |
| 2885 | // directly into the breakpoint opcode buffer |
| 2886 | ::memcpy(bp->GetSavedOpcodeBytes() + opcode_offset, ubuf + bytes_written, intersect_size); |
| 2887 | bytes_written += intersect_size; |
| 2888 | } |
| 2889 | }); |
| 2890 | |
| 2891 | if (bytes_written < size) |
Jason Molenda | 8b5f2cf | 2014-10-16 07:49:27 +0000 | [diff] [blame] | 2892 | WriteMemoryPrivate (addr + bytes_written, |
| 2893 | ubuf + bytes_written, |
| 2894 | size - bytes_written, |
| 2895 | error); |
Greg Clayton | d8cf1a1 | 2013-06-12 00:46:38 +0000 | [diff] [blame] | 2896 | } |
| 2897 | } |
| 2898 | else |
| 2899 | { |
| 2900 | return WriteMemoryPrivate (addr, buf, size, error); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | // 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] | 2904 | return 0; //bytes_written; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2905 | } |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2906 | |
| 2907 | size_t |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2908 | 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] | 2909 | { |
| 2910 | if (byte_size == UINT32_MAX) |
| 2911 | byte_size = scalar.GetByteSize(); |
| 2912 | if (byte_size > 0) |
| 2913 | { |
| 2914 | uint8_t buf[32]; |
| 2915 | const size_t mem_size = scalar.GetAsMemoryData (buf, byte_size, GetByteOrder(), error); |
| 2916 | if (mem_size > 0) |
| 2917 | return WriteMemory(addr, buf, mem_size, error); |
| 2918 | else |
| 2919 | error.SetErrorString ("failed to get scalar as memory data"); |
| 2920 | } |
| 2921 | else |
| 2922 | { |
| 2923 | error.SetErrorString ("invalid scalar value"); |
| 2924 | } |
| 2925 | return 0; |
| 2926 | } |
| 2927 | |
| 2928 | size_t |
| 2929 | Process::ReadScalarIntegerFromMemory (addr_t addr, |
| 2930 | uint32_t byte_size, |
| 2931 | bool is_signed, |
| 2932 | Scalar &scalar, |
| 2933 | Error &error) |
| 2934 | { |
Greg Clayton | 7060f89 | 2013-05-01 23:41:30 +0000 | [diff] [blame] | 2935 | uint64_t uval = 0; |
| 2936 | if (byte_size == 0) |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2937 | { |
Greg Clayton | 7060f89 | 2013-05-01 23:41:30 +0000 | [diff] [blame] | 2938 | error.SetErrorString ("byte size is zero"); |
| 2939 | } |
| 2940 | else if (byte_size & (byte_size - 1)) |
| 2941 | { |
| 2942 | error.SetErrorStringWithFormat ("byte size %u is not a power of 2", byte_size); |
| 2943 | } |
| 2944 | else if (byte_size <= sizeof(uval)) |
| 2945 | { |
| 2946 | const size_t bytes_read = ReadMemory (addr, &uval, byte_size, error); |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2947 | if (bytes_read == byte_size) |
| 2948 | { |
| 2949 | DataExtractor data (&uval, sizeof(uval), GetByteOrder(), GetAddressByteSize()); |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 2950 | lldb::offset_t offset = 0; |
Greg Clayton | 7060f89 | 2013-05-01 23:41:30 +0000 | [diff] [blame] | 2951 | if (byte_size <= 4) |
| 2952 | scalar = data.GetMaxU32 (&offset, byte_size); |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2953 | else |
Greg Clayton | 7060f89 | 2013-05-01 23:41:30 +0000 | [diff] [blame] | 2954 | scalar = data.GetMaxU64 (&offset, byte_size); |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2955 | if (is_signed) |
| 2956 | scalar.SignExtend(byte_size * 8); |
| 2957 | return bytes_read; |
| 2958 | } |
| 2959 | } |
| 2960 | else |
| 2961 | { |
| 2962 | error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size); |
| 2963 | } |
| 2964 | return 0; |
| 2965 | } |
| 2966 | |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2967 | #define USE_ALLOCATE_MEMORY_CACHE 1 |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2968 | addr_t |
| 2969 | Process::AllocateMemory(size_t size, uint32_t permissions, Error &error) |
| 2970 | { |
Jim Ingham | f72ce3a | 2011-06-20 17:32:44 +0000 | [diff] [blame] | 2971 | if (GetPrivateState() != eStateStopped) |
| 2972 | return LLDB_INVALID_ADDRESS; |
| 2973 | |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2974 | #if defined (USE_ALLOCATE_MEMORY_CACHE) |
| 2975 | return m_allocated_memory_cache.AllocateMemory(size, permissions, error); |
| 2976 | #else |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2977 | addr_t allocated_addr = DoAllocateMemory (size, permissions, error); |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2978 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2979 | if (log) |
Greg Clayton | 4598907 | 2013-10-23 18:24:30 +0000 | [diff] [blame] | 2980 | 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] | 2981 | (uint64_t)size, |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2982 | GetPermissionsAsCString (permissions), |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2983 | (uint64_t)allocated_addr, |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 2984 | m_mod_id.GetStopID(), |
| 2985 | m_mod_id.GetMemoryID()); |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2986 | return allocated_addr; |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2987 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2988 | } |
| 2989 | |
Sean Callanan | 9053945 | 2011-09-20 23:01:51 +0000 | [diff] [blame] | 2990 | bool |
| 2991 | Process::CanJIT () |
| 2992 | { |
Sean Callanan | a7b443a | 2012-02-14 22:50:38 +0000 | [diff] [blame] | 2993 | if (m_can_jit == eCanJITDontKnow) |
| 2994 | { |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 2995 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Sean Callanan | a7b443a | 2012-02-14 22:50:38 +0000 | [diff] [blame] | 2996 | Error err; |
| 2997 | |
| 2998 | uint64_t allocated_memory = AllocateMemory(8, |
| 2999 | ePermissionsReadable | ePermissionsWritable | ePermissionsExecutable, |
| 3000 | err); |
| 3001 | |
| 3002 | if (err.Success()) |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 3003 | { |
Sean Callanan | a7b443a | 2012-02-14 22:50:38 +0000 | [diff] [blame] | 3004 | m_can_jit = eCanJITYes; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 3005 | if (log) |
| 3006 | log->Printf ("Process::%s pid %" PRIu64 " allocation test passed, CanJIT () is true", __FUNCTION__, GetID ()); |
| 3007 | } |
Sean Callanan | a7b443a | 2012-02-14 22:50:38 +0000 | [diff] [blame] | 3008 | else |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 3009 | { |
Sean Callanan | a7b443a | 2012-02-14 22:50:38 +0000 | [diff] [blame] | 3010 | m_can_jit = eCanJITNo; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 3011 | if (log) |
| 3012 | log->Printf ("Process::%s pid %" PRIu64 " allocation test failed, CanJIT () is false: %s", __FUNCTION__, GetID (), err.AsCString ()); |
| 3013 | } |
Sean Callanan | a7b443a | 2012-02-14 22:50:38 +0000 | [diff] [blame] | 3014 | |
| 3015 | DeallocateMemory (allocated_memory); |
| 3016 | } |
| 3017 | |
Sean Callanan | 9053945 | 2011-09-20 23:01:51 +0000 | [diff] [blame] | 3018 | return m_can_jit == eCanJITYes; |
| 3019 | } |
| 3020 | |
| 3021 | void |
| 3022 | Process::SetCanJIT (bool can_jit) |
| 3023 | { |
| 3024 | m_can_jit = (can_jit ? eCanJITYes : eCanJITNo); |
| 3025 | } |
| 3026 | |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 3027 | void |
| 3028 | Process::SetCanRunCode (bool can_run_code) |
| 3029 | { |
| 3030 | SetCanJIT(can_run_code); |
| 3031 | m_can_interpret_function_calls = can_run_code; |
| 3032 | } |
| 3033 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3034 | Error |
| 3035 | Process::DeallocateMemory (addr_t ptr) |
| 3036 | { |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 3037 | Error error; |
| 3038 | #if defined (USE_ALLOCATE_MEMORY_CACHE) |
| 3039 | if (!m_allocated_memory_cache.DeallocateMemory(ptr)) |
| 3040 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3041 | error.SetErrorStringWithFormat ("deallocation of memory at 0x%" PRIx64 " failed.", (uint64_t)ptr); |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 3042 | } |
| 3043 | #else |
| 3044 | error = DoDeallocateMemory (ptr); |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 3045 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3046 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 3047 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 3048 | 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] | 3049 | ptr, |
| 3050 | error.AsCString("SUCCESS"), |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3051 | m_mod_id.GetStopID(), |
| 3052 | m_mod_id.GetMemoryID()); |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 3053 | #endif |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 3054 | return error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3055 | } |
| 3056 | |
Han Ming Ong | c811d38 | 2012-11-17 00:33:14 +0000 | [diff] [blame] | 3057 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3058 | ModuleSP |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 3059 | Process::ReadModuleFromMemory (const FileSpec& file_spec, |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 3060 | lldb::addr_t header_addr, |
| 3061 | size_t size_to_read) |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3062 | { |
Jason Molenda | 08a3258 | 2015-07-25 02:39:42 +0000 | [diff] [blame] | 3063 | Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); |
| 3064 | if (log) |
| 3065 | { |
| 3066 | log->Printf ("Process::ReadModuleFromMemory reading %s binary from memory", file_spec.GetPath().c_str()); |
| 3067 | } |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 3068 | ModuleSP module_sp (new Module (file_spec, ArchSpec())); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3069 | if (module_sp) |
| 3070 | { |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 3071 | Error error; |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 3072 | 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] | 3073 | if (objfile) |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 3074 | return module_sp; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3075 | } |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 3076 | return ModuleSP(); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 3077 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3078 | |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 3079 | bool |
| 3080 | Process::GetLoadAddressPermissions (lldb::addr_t load_addr, uint32_t &permissions) |
| 3081 | { |
| 3082 | MemoryRegionInfo range_info; |
| 3083 | permissions = 0; |
| 3084 | Error error (GetMemoryRegionInfo (load_addr, range_info)); |
| 3085 | if (!error.Success()) |
| 3086 | return false; |
| 3087 | if (range_info.GetReadable() == MemoryRegionInfo::eDontKnow |
| 3088 | || range_info.GetWritable() == MemoryRegionInfo::eDontKnow |
| 3089 | || range_info.GetExecutable() == MemoryRegionInfo::eDontKnow) |
| 3090 | { |
| 3091 | return false; |
| 3092 | } |
| 3093 | |
| 3094 | if (range_info.GetReadable() == MemoryRegionInfo::eYes) |
| 3095 | permissions |= lldb::ePermissionsReadable; |
| 3096 | |
| 3097 | if (range_info.GetWritable() == MemoryRegionInfo::eYes) |
| 3098 | permissions |= lldb::ePermissionsWritable; |
| 3099 | |
| 3100 | if (range_info.GetExecutable() == MemoryRegionInfo::eYes) |
| 3101 | permissions |= lldb::ePermissionsExecutable; |
| 3102 | |
| 3103 | return true; |
| 3104 | } |
| 3105 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3106 | Error |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3107 | Process::EnableWatchpoint (Watchpoint *watchpoint, bool notify) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3108 | { |
| 3109 | Error error; |
| 3110 | error.SetErrorString("watchpoints are not supported"); |
| 3111 | return error; |
| 3112 | } |
| 3113 | |
| 3114 | Error |
Jim Ingham | 1b5792e | 2012-12-18 02:03:49 +0000 | [diff] [blame] | 3115 | Process::DisableWatchpoint (Watchpoint *watchpoint, bool notify) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3116 | { |
| 3117 | Error error; |
| 3118 | error.SetErrorString("watchpoints are not supported"); |
| 3119 | return error; |
| 3120 | } |
| 3121 | |
| 3122 | StateType |
| 3123 | Process::WaitForProcessStopPrivate (const TimeValue *timeout, EventSP &event_sp) |
| 3124 | { |
| 3125 | StateType state; |
| 3126 | // Now wait for the process to launch and return control to us, and then |
| 3127 | // call DidLaunch: |
| 3128 | while (1) |
| 3129 | { |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 3130 | event_sp.reset(); |
| 3131 | state = WaitForStateChangedEventsPrivate (timeout, event_sp); |
| 3132 | |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 3133 | if (StateIsStoppedState(state, false)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3134 | break; |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 3135 | |
| 3136 | // If state is invalid, then we timed out |
| 3137 | if (state == eStateInvalid) |
| 3138 | break; |
| 3139 | |
| 3140 | if (event_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3141 | HandlePrivateEvent (event_sp); |
| 3142 | } |
| 3143 | return state; |
| 3144 | } |
| 3145 | |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 3146 | void |
| 3147 | Process::LoadOperatingSystemPlugin(bool flush) |
| 3148 | { |
| 3149 | if (flush) |
| 3150 | m_thread_list.Clear(); |
| 3151 | m_os_ap.reset (OperatingSystem::FindPlugin (this, NULL)); |
| 3152 | if (flush) |
| 3153 | Flush(); |
| 3154 | } |
| 3155 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3156 | Error |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3157 | Process::Launch (ProcessLaunchInfo &launch_info) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3158 | { |
| 3159 | Error error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3160 | m_abi_sp.reset(); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3161 | m_dyld_ap.reset(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 3162 | m_jit_loaders_ap.reset(); |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 3163 | m_system_runtime_ap.reset(); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 3164 | m_os_ap.reset(); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 3165 | m_process_input_reader.reset(); |
Greg Clayton | a97c4d2 | 2014-12-09 23:31:02 +0000 | [diff] [blame] | 3166 | m_stop_info_override_callback = NULL; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3167 | |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 3168 | Module *exe_module = m_target.GetExecutableModulePointer(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3169 | if (exe_module) |
| 3170 | { |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 3171 | char local_exec_file_path[PATH_MAX]; |
| 3172 | char platform_exec_file_path[PATH_MAX]; |
| 3173 | exe_module->GetFileSpec().GetPath(local_exec_file_path, sizeof(local_exec_file_path)); |
| 3174 | 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] | 3175 | if (exe_module->GetFileSpec().Exists()) |
| 3176 | { |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3177 | // Install anything that might need to be installed prior to launching. |
| 3178 | // For host systems, this will do nothing, but if we are connected to a |
| 3179 | // remote platform it will install any needed binaries |
| 3180 | error = GetTarget().Install(&launch_info); |
| 3181 | if (error.Fail()) |
| 3182 | return error; |
| 3183 | |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3184 | if (PrivateStateThreadIsValid ()) |
| 3185 | PausePrivateStateThread (); |
| 3186 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3187 | error = WillLaunch (exe_module); |
| 3188 | if (error.Success()) |
| 3189 | { |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 3190 | const bool restarted = false; |
| 3191 | SetPublicState (eStateLaunching, restarted); |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 3192 | m_should_detach = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3193 | |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 3194 | if (m_public_run_lock.TrySetRunning()) |
Greg Clayton | 69fd4be | 2012-09-04 20:29:05 +0000 | [diff] [blame] | 3195 | { |
| 3196 | // Now launch using these arguments. |
| 3197 | error = DoLaunch (exe_module, launch_info); |
| 3198 | } |
| 3199 | else |
| 3200 | { |
| 3201 | // This shouldn't happen |
| 3202 | error.SetErrorString("failed to acquire process run lock"); |
| 3203 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3204 | |
| 3205 | if (error.Fail()) |
| 3206 | { |
| 3207 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
| 3208 | { |
| 3209 | SetID (LLDB_INVALID_PROCESS_ID); |
| 3210 | const char *error_string = error.AsCString(); |
| 3211 | if (error_string == NULL) |
| 3212 | error_string = "launch failed"; |
| 3213 | SetExitStatus (-1, error_string); |
| 3214 | } |
| 3215 | } |
| 3216 | else |
| 3217 | { |
| 3218 | EventSP event_sp; |
Greg Clayton | 1a38ea7 | 2011-06-22 01:42:17 +0000 | [diff] [blame] | 3219 | TimeValue timeout_time; |
| 3220 | timeout_time = TimeValue::Now(); |
| 3221 | timeout_time.OffsetWithSeconds(10); |
| 3222 | StateType state = WaitForProcessStopPrivate(&timeout_time, event_sp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3223 | |
Greg Clayton | 1a38ea7 | 2011-06-22 01:42:17 +0000 | [diff] [blame] | 3224 | if (state == eStateInvalid || event_sp.get() == NULL) |
| 3225 | { |
| 3226 | // We were able to launch the process, but we failed to |
| 3227 | // catch the initial stop. |
Tamas Berghammer | 04e6314 | 2015-02-23 10:59:54 +0000 | [diff] [blame] | 3228 | error.SetErrorString ("failed to catch stop after launch"); |
Greg Clayton | 1a38ea7 | 2011-06-22 01:42:17 +0000 | [diff] [blame] | 3229 | SetExitStatus (0, "failed to catch stop after launch"); |
Jason Molenda | ede3193 | 2015-04-17 05:01:58 +0000 | [diff] [blame] | 3230 | Destroy(false); |
Greg Clayton | 1a38ea7 | 2011-06-22 01:42:17 +0000 | [diff] [blame] | 3231 | } |
| 3232 | else if (state == eStateStopped || state == eStateCrashed) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3233 | { |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3234 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3235 | DidLaunch (); |
| 3236 | |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 3237 | DynamicLoader *dyld = GetDynamicLoader (); |
| 3238 | if (dyld) |
| 3239 | dyld->DidLaunch(); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3240 | |
Andrew MacPherson | eb4d060 | 2014-03-13 09:37:02 +0000 | [diff] [blame] | 3241 | GetJITLoaders().DidLaunch(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 3242 | |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 3243 | SystemRuntime *system_runtime = GetSystemRuntime (); |
| 3244 | if (system_runtime) |
| 3245 | system_runtime->DidLaunch(); |
| 3246 | |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 3247 | LoadOperatingSystemPlugin(false); |
Todd Fiala | f72fa67 | 2014-10-07 16:05:21 +0000 | [diff] [blame] | 3248 | |
| 3249 | // Note, the stop event was consumed above, but not handled. This was done |
| 3250 | // to give DidLaunch a chance to run. The target is either stopped or crashed. |
| 3251 | // Directly set the state. This is done to prevent a stop message with a bunch |
| 3252 | // of spurious output on thread status, as well as not pop a ProcessIOHandler. |
| 3253 | SetPublicState(state, false); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3254 | |
| 3255 | if (PrivateStateThreadIsValid ()) |
| 3256 | ResumePrivateStateThread (); |
| 3257 | else |
| 3258 | StartPrivateStateThread (); |
Greg Clayton | a97c4d2 | 2014-12-09 23:31:02 +0000 | [diff] [blame] | 3259 | |
| 3260 | m_stop_info_override_callback = GetTarget().GetArchitecture().GetStopInfoOverrideCallback(); |
Ilia K | 6af632f | 2015-02-06 18:15:05 +0000 | [diff] [blame] | 3261 | |
| 3262 | // Target was stopped at entry as was intended. Need to notify the listeners |
| 3263 | // about it. |
Ilia K | 333fc18 | 2015-02-11 11:24:20 +0000 | [diff] [blame] | 3264 | if (state == eStateStopped && launch_info.GetFlags().Test(eLaunchFlagStopAtEntry)) |
Ilia K | 6af632f | 2015-02-06 18:15:05 +0000 | [diff] [blame] | 3265 | HandlePrivateEvent(event_sp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3266 | } |
| 3267 | else if (state == eStateExited) |
| 3268 | { |
| 3269 | // We exited while trying to launch somehow. Don't call DidLaunch as that's |
| 3270 | // not likely to work, and return an invalid pid. |
| 3271 | HandlePrivateEvent (event_sp); |
| 3272 | } |
| 3273 | } |
| 3274 | } |
| 3275 | } |
| 3276 | else |
| 3277 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 3278 | error.SetErrorStringWithFormat("file doesn't exist: '%s'", local_exec_file_path); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3279 | } |
| 3280 | } |
| 3281 | return error; |
| 3282 | } |
| 3283 | |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 3284 | |
| 3285 | Error |
| 3286 | Process::LoadCore () |
| 3287 | { |
| 3288 | Error error = DoLoadCore(); |
| 3289 | if (error.Success()) |
| 3290 | { |
Greg Clayton | 35824e3 | 2015-02-20 20:59:47 +0000 | [diff] [blame] | 3291 | Listener listener ("lldb.process.load_core_listener"); |
Greg Clayton | 338d0bd | 2015-02-20 21:51:06 +0000 | [diff] [blame] | 3292 | HijackProcessEvents(&listener); |
Greg Clayton | 35824e3 | 2015-02-20 20:59:47 +0000 | [diff] [blame] | 3293 | |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 3294 | if (PrivateStateThreadIsValid ()) |
| 3295 | ResumePrivateStateThread (); |
| 3296 | else |
| 3297 | StartPrivateStateThread (); |
| 3298 | |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 3299 | DynamicLoader *dyld = GetDynamicLoader (); |
| 3300 | if (dyld) |
| 3301 | dyld->DidAttach(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 3302 | |
Andrew MacPherson | eb4d060 | 2014-03-13 09:37:02 +0000 | [diff] [blame] | 3303 | GetJITLoaders().DidAttach(); |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 3304 | |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 3305 | SystemRuntime *system_runtime = GetSystemRuntime (); |
| 3306 | if (system_runtime) |
| 3307 | system_runtime->DidAttach(); |
| 3308 | |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 3309 | m_os_ap.reset (OperatingSystem::FindPlugin (this, NULL)); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 3310 | // We successfully loaded a core file, now pretend we stopped so we can |
| 3311 | // show all of the threads in the core file and explore the crashed |
| 3312 | // state. |
| 3313 | SetPrivateState (eStateStopped); |
Greg Clayton | 35824e3 | 2015-02-20 20:59:47 +0000 | [diff] [blame] | 3314 | |
| 3315 | // Wait indefinitely for a stopped event since we just posted one above... |
| 3316 | lldb::EventSP event_sp; |
| 3317 | listener.WaitForEvent (NULL, event_sp); |
| 3318 | StateType state = ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 3319 | |
| 3320 | if (!StateIsStoppedState (state, false)) |
| 3321 | { |
| 3322 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 3323 | if (log) |
| 3324 | log->Printf("Process::Halt() failed to stop, state is: %s", StateAsCString(state)); |
| 3325 | error.SetErrorString ("Did not get stopped event after loading the core file."); |
| 3326 | } |
Greg Clayton | 338d0bd | 2015-02-20 21:51:06 +0000 | [diff] [blame] | 3327 | RestoreProcessEvents (); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 3328 | } |
| 3329 | return error; |
| 3330 | } |
| 3331 | |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 3332 | DynamicLoader * |
| 3333 | Process::GetDynamicLoader () |
| 3334 | { |
| 3335 | if (m_dyld_ap.get() == NULL) |
| 3336 | m_dyld_ap.reset (DynamicLoader::FindPlugin(this, NULL)); |
| 3337 | return m_dyld_ap.get(); |
| 3338 | } |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 3339 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 3340 | const lldb::DataBufferSP |
| 3341 | Process::GetAuxvData() |
| 3342 | { |
| 3343 | return DataBufferSP (); |
| 3344 | } |
| 3345 | |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 3346 | JITLoaderList & |
| 3347 | Process::GetJITLoaders () |
| 3348 | { |
| 3349 | if (!m_jit_loaders_ap) |
| 3350 | { |
| 3351 | m_jit_loaders_ap.reset(new JITLoaderList()); |
| 3352 | JITLoader::LoadPlugins(this, *m_jit_loaders_ap); |
| 3353 | } |
| 3354 | return *m_jit_loaders_ap; |
| 3355 | } |
| 3356 | |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 3357 | SystemRuntime * |
| 3358 | Process::GetSystemRuntime () |
| 3359 | { |
| 3360 | if (m_system_runtime_ap.get() == NULL) |
| 3361 | m_system_runtime_ap.reset (SystemRuntime::FindPlugin(this)); |
| 3362 | return m_system_runtime_ap.get(); |
| 3363 | } |
| 3364 | |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3365 | Process::AttachCompletionHandler::AttachCompletionHandler (Process *process, uint32_t exec_count) : |
| 3366 | NextEventAction (process), |
| 3367 | m_exec_count (exec_count) |
| 3368 | { |
| 3369 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 3370 | if (log) |
| 3371 | log->Printf ("Process::AttachCompletionHandler::%s process=%p, exec_count=%" PRIu32, __FUNCTION__, static_cast<void*>(process), exec_count); |
| 3372 | } |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 3373 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3374 | Process::NextEventAction::EventActionResult |
| 3375 | Process::AttachCompletionHandler::PerformAction (lldb::EventSP &event_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3376 | { |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3377 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 3378 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3379 | StateType state = ProcessEventData::GetStateFromEvent (event_sp.get()); |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3380 | if (log) |
| 3381 | log->Printf ("Process::AttachCompletionHandler::%s called with state %s (%d)", __FUNCTION__, StateAsCString(state), static_cast<int> (state)); |
| 3382 | |
| 3383 | switch (state) |
Greg Clayton | 19388cf | 2010-10-18 01:45:30 +0000 | [diff] [blame] | 3384 | { |
Zachary Turner | c62733b | 2015-05-20 18:31:17 +0000 | [diff] [blame] | 3385 | case eStateAttaching: |
| 3386 | return eEventActionSuccess; |
| 3387 | |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3388 | case eStateRunning: |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3389 | case eStateConnected: |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3390 | return eEventActionRetry; |
| 3391 | |
| 3392 | case eStateStopped: |
| 3393 | case eStateCrashed: |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 3394 | { |
| 3395 | // During attach, prior to sending the eStateStopped event, |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3396 | // lldb_private::Process subclasses must set the new process ID. |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 3397 | assert (m_process->GetID() != LLDB_INVALID_PROCESS_ID); |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 3398 | // We don't want these events to be reported, so go set the ShouldReportStop here: |
| 3399 | m_process->GetThreadList().SetShouldReportStop (eVoteNo); |
| 3400 | |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 3401 | if (m_exec_count > 0) |
| 3402 | { |
| 3403 | --m_exec_count; |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3404 | |
| 3405 | if (log) |
| 3406 | log->Printf ("Process::AttachCompletionHandler::%s state %s: reduced remaining exec count to %" PRIu32 ", requesting resume", __FUNCTION__, StateAsCString(state), m_exec_count); |
| 3407 | |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 3408 | RequestResume(); |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 3409 | return eEventActionRetry; |
| 3410 | } |
| 3411 | else |
| 3412 | { |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3413 | if (log) |
| 3414 | log->Printf ("Process::AttachCompletionHandler::%s state %s: no more execs expected to start, continuing with attach", __FUNCTION__, StateAsCString(state)); |
| 3415 | |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 3416 | m_process->CompleteAttach (); |
| 3417 | return eEventActionSuccess; |
| 3418 | } |
| 3419 | } |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3420 | break; |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 3421 | |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3422 | default: |
| 3423 | case eStateExited: |
| 3424 | case eStateInvalid: |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3425 | break; |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3426 | } |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 3427 | |
| 3428 | m_exit_string.assign ("No valid Process"); |
| 3429 | return eEventActionExit; |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3430 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3431 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3432 | Process::NextEventAction::EventActionResult |
| 3433 | Process::AttachCompletionHandler::HandleBeingInterrupted() |
| 3434 | { |
| 3435 | return eEventActionSuccess; |
| 3436 | } |
| 3437 | |
| 3438 | const char * |
| 3439 | Process::AttachCompletionHandler::GetExitString () |
| 3440 | { |
| 3441 | return m_exit_string.c_str(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3442 | } |
| 3443 | |
Greg Clayton | 8012cad | 2014-11-17 19:39:20 +0000 | [diff] [blame] | 3444 | Listener & |
| 3445 | ProcessAttachInfo::GetListenerForProcess (Debugger &debugger) |
| 3446 | { |
| 3447 | if (m_listener_sp) |
| 3448 | return *m_listener_sp; |
| 3449 | else |
| 3450 | return debugger.GetListener(); |
| 3451 | } |
| 3452 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3453 | Error |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3454 | Process::Attach (ProcessAttachInfo &attach_info) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3455 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3456 | m_abi_sp.reset(); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 3457 | m_process_input_reader.reset(); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3458 | m_dyld_ap.reset(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 3459 | m_jit_loaders_ap.reset(); |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 3460 | m_system_runtime_ap.reset(); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 3461 | m_os_ap.reset(); |
Greg Clayton | a97c4d2 | 2014-12-09 23:31:02 +0000 | [diff] [blame] | 3462 | m_stop_info_override_callback = NULL; |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 3463 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3464 | lldb::pid_t attach_pid = attach_info.GetProcessID(); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3465 | Error error; |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3466 | if (attach_pid == LLDB_INVALID_PROCESS_ID) |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 3467 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3468 | char process_name[PATH_MAX]; |
Jim Ingham | 4299fdb | 2011-09-15 01:10:17 +0000 | [diff] [blame] | 3469 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3470 | if (attach_info.GetExecutableFile().GetPath (process_name, sizeof(process_name))) |
Jim Ingham | 2ecb742 | 2010-08-17 21:54:19 +0000 | [diff] [blame] | 3471 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3472 | const bool wait_for_launch = attach_info.GetWaitForLaunch(); |
| 3473 | |
| 3474 | if (wait_for_launch) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3475 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3476 | error = WillAttachToProcessWithName(process_name, wait_for_launch); |
| 3477 | if (error.Success()) |
| 3478 | { |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 3479 | if (m_public_run_lock.TrySetRunning()) |
Greg Clayton | 926cce7 | 2012-10-12 16:10:12 +0000 | [diff] [blame] | 3480 | { |
| 3481 | m_should_detach = true; |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 3482 | const bool restarted = false; |
| 3483 | SetPublicState (eStateAttaching, restarted); |
Greg Clayton | 926cce7 | 2012-10-12 16:10:12 +0000 | [diff] [blame] | 3484 | // Now attach using these arguments. |
Jean-Daniel Dupas | 9c517c0 | 2013-12-23 22:32:54 +0000 | [diff] [blame] | 3485 | error = DoAttachToProcessWithName (process_name, attach_info); |
Greg Clayton | 926cce7 | 2012-10-12 16:10:12 +0000 | [diff] [blame] | 3486 | } |
| 3487 | else |
| 3488 | { |
| 3489 | // This shouldn't happen |
| 3490 | error.SetErrorString("failed to acquire process run lock"); |
| 3491 | } |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 3492 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3493 | if (error.Fail()) |
| 3494 | { |
| 3495 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
| 3496 | { |
| 3497 | SetID (LLDB_INVALID_PROCESS_ID); |
| 3498 | if (error.AsCString() == NULL) |
| 3499 | error.SetErrorString("attach failed"); |
| 3500 | |
| 3501 | SetExitStatus(-1, error.AsCString()); |
| 3502 | } |
| 3503 | } |
| 3504 | else |
| 3505 | { |
| 3506 | SetNextEventAction(new Process::AttachCompletionHandler(this, attach_info.GetResumeCount())); |
| 3507 | StartPrivateStateThread(); |
| 3508 | } |
| 3509 | return error; |
| 3510 | } |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3511 | } |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3512 | else |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3513 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3514 | ProcessInstanceInfoList process_infos; |
| 3515 | PlatformSP platform_sp (m_target.GetPlatform ()); |
| 3516 | |
| 3517 | if (platform_sp) |
| 3518 | { |
| 3519 | ProcessInstanceInfoMatch match_info; |
| 3520 | match_info.GetProcessInfo() = attach_info; |
| 3521 | match_info.SetNameMatchType (eNameMatchEquals); |
| 3522 | platform_sp->FindProcesses (match_info, process_infos); |
| 3523 | const uint32_t num_matches = process_infos.GetSize(); |
| 3524 | if (num_matches == 1) |
| 3525 | { |
| 3526 | attach_pid = process_infos.GetProcessIDAtIndex(0); |
| 3527 | // Fall through and attach using the above process ID |
| 3528 | } |
| 3529 | else |
| 3530 | { |
| 3531 | match_info.GetProcessInfo().GetExecutableFile().GetPath (process_name, sizeof(process_name)); |
| 3532 | if (num_matches > 1) |
Jim Ingham | 368ac22 | 2014-08-15 17:05:27 +0000 | [diff] [blame] | 3533 | { |
| 3534 | StreamString s; |
| 3535 | ProcessInstanceInfo::DumpTableHeader (s, platform_sp.get(), true, false); |
| 3536 | for (size_t i = 0; i < num_matches; i++) |
| 3537 | { |
| 3538 | process_infos.GetProcessInfoAtIndex(i).DumpAsTableRow(s, platform_sp.get(), true, false); |
| 3539 | } |
| 3540 | error.SetErrorStringWithFormat ("more than one process named %s:\n%s", |
| 3541 | process_name, |
| 3542 | s.GetData()); |
| 3543 | } |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3544 | else |
| 3545 | error.SetErrorStringWithFormat ("could not find a process named %s", process_name); |
| 3546 | } |
| 3547 | } |
| 3548 | else |
| 3549 | { |
| 3550 | error.SetErrorString ("invalid platform, can't find processes by name"); |
| 3551 | return error; |
| 3552 | } |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3553 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3554 | } |
| 3555 | else |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3556 | { |
| 3557 | error.SetErrorString ("invalid process name"); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3558 | } |
| 3559 | } |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3560 | |
| 3561 | if (attach_pid != LLDB_INVALID_PROCESS_ID) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3562 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3563 | error = WillAttachToProcessWithID(attach_pid); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3564 | if (error.Success()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3565 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3566 | |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 3567 | if (m_public_run_lock.TrySetRunning()) |
Greg Clayton | 926cce7 | 2012-10-12 16:10:12 +0000 | [diff] [blame] | 3568 | { |
| 3569 | // Now attach using these arguments. |
| 3570 | m_should_detach = true; |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 3571 | const bool restarted = false; |
| 3572 | SetPublicState (eStateAttaching, restarted); |
Greg Clayton | 926cce7 | 2012-10-12 16:10:12 +0000 | [diff] [blame] | 3573 | error = DoAttachToProcessWithID (attach_pid, attach_info); |
| 3574 | } |
| 3575 | else |
| 3576 | { |
| 3577 | // This shouldn't happen |
| 3578 | error.SetErrorString("failed to acquire process run lock"); |
| 3579 | } |
| 3580 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 3581 | if (error.Success()) |
| 3582 | { |
| 3583 | |
| 3584 | SetNextEventAction(new Process::AttachCompletionHandler(this, attach_info.GetResumeCount())); |
| 3585 | StartPrivateStateThread(); |
| 3586 | } |
| 3587 | else |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3588 | { |
| 3589 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3590 | SetID (LLDB_INVALID_PROCESS_ID); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3591 | |
Oleksiy Vyalov | 5d06474 | 2014-11-19 18:27:45 +0000 | [diff] [blame] | 3592 | const char *error_string = error.AsCString(); |
| 3593 | if (error_string == NULL) |
| 3594 | error_string = "attach failed"; |
| 3595 | |
| 3596 | SetExitStatus(-1, error_string); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3597 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3598 | } |
| 3599 | } |
| 3600 | return error; |
| 3601 | } |
| 3602 | |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3603 | void |
| 3604 | Process::CompleteAttach () |
| 3605 | { |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3606 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 3607 | if (log) |
| 3608 | log->Printf ("Process::%s()", __FUNCTION__); |
| 3609 | |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3610 | // Let the process subclass figure out at much as it can about the process |
| 3611 | // before we go looking for a dynamic loader plug-in. |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 3612 | ArchSpec process_arch; |
| 3613 | DidAttach(process_arch); |
| 3614 | |
| 3615 | if (process_arch.IsValid()) |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3616 | { |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 3617 | m_target.SetArchitecture(process_arch); |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3618 | if (log) |
| 3619 | { |
| 3620 | const char *triple_str = process_arch.GetTriple().getTriple().c_str (); |
| 3621 | log->Printf ("Process::%s replacing process architecture with DidAttach() architecture: %s", |
| 3622 | __FUNCTION__, |
| 3623 | triple_str ? triple_str : "<null>"); |
| 3624 | } |
| 3625 | } |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3626 | |
Jim Ingham | 4299fdb | 2011-09-15 01:10:17 +0000 | [diff] [blame] | 3627 | // We just attached. If we have a platform, ask it for the process architecture, and if it isn't |
| 3628 | // the same as the one we've already set, switch architectures. |
| 3629 | PlatformSP platform_sp (m_target.GetPlatform ()); |
| 3630 | assert (platform_sp.get()); |
| 3631 | if (platform_sp) |
| 3632 | { |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 3633 | const ArchSpec &target_arch = m_target.GetArchitecture(); |
Greg Clayton | 1e0c884 | 2013-01-11 20:49:54 +0000 | [diff] [blame] | 3634 | if (target_arch.IsValid() && !platform_sp->IsCompatibleArchitecture (target_arch, false, NULL)) |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 3635 | { |
| 3636 | ArchSpec platform_arch; |
| 3637 | platform_sp = platform_sp->GetPlatformForArchitecture (target_arch, &platform_arch); |
| 3638 | if (platform_sp) |
| 3639 | { |
| 3640 | m_target.SetPlatform (platform_sp); |
| 3641 | m_target.SetArchitecture(platform_arch); |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3642 | if (log) |
| 3643 | log->Printf ("Process::%s switching platform to %s and architecture to %s based on info from attach", __FUNCTION__, platform_sp->GetName().AsCString (""), platform_arch.GetTriple().getTriple().c_str ()); |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 3644 | } |
| 3645 | } |
Jim Ingham | bb006ce | 2014-08-02 00:33:35 +0000 | [diff] [blame] | 3646 | else if (!process_arch.IsValid()) |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 3647 | { |
| 3648 | ProcessInstanceInfo process_info; |
| 3649 | platform_sp->GetProcessInfo (GetID(), process_info); |
| 3650 | const ArchSpec &process_arch = process_info.GetArchitecture(); |
Sean Callanan | bf4b7be | 2012-12-13 22:07:14 +0000 | [diff] [blame] | 3651 | if (process_arch.IsValid() && !m_target.GetArchitecture().IsExactMatch(process_arch)) |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3652 | { |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 3653 | m_target.SetArchitecture (process_arch); |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3654 | if (log) |
| 3655 | log->Printf ("Process::%s switching architecture to %s based on info the platform retrieved for pid %" PRIu64, __FUNCTION__, process_arch.GetTriple().getTriple().c_str (), GetID ()); |
| 3656 | } |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 3657 | } |
Jim Ingham | 4299fdb | 2011-09-15 01:10:17 +0000 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | // 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] | 3661 | // plug-in |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 3662 | DynamicLoader *dyld = GetDynamicLoader (); |
| 3663 | if (dyld) |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3664 | { |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 3665 | dyld->DidAttach(); |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3666 | if (log) |
| 3667 | { |
| 3668 | ModuleSP exe_module_sp = m_target.GetExecutableModule (); |
| 3669 | log->Printf ("Process::%s after DynamicLoader::DidAttach(), target executable is %s (using %s plugin)", |
| 3670 | __FUNCTION__, |
| 3671 | exe_module_sp ? exe_module_sp->GetFileSpec().GetPath().c_str () : "<none>", |
| 3672 | dyld->GetPluginName().AsCString ("<unnamed>")); |
| 3673 | } |
| 3674 | } |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3675 | |
Andrew MacPherson | eb4d060 | 2014-03-13 09:37:02 +0000 | [diff] [blame] | 3676 | GetJITLoaders().DidAttach(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 3677 | |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 3678 | SystemRuntime *system_runtime = GetSystemRuntime (); |
| 3679 | if (system_runtime) |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3680 | { |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 3681 | system_runtime->DidAttach(); |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3682 | if (log) |
| 3683 | { |
| 3684 | ModuleSP exe_module_sp = m_target.GetExecutableModule (); |
| 3685 | log->Printf ("Process::%s after SystemRuntime::DidAttach(), target executable is %s (using %s plugin)", |
| 3686 | __FUNCTION__, |
| 3687 | exe_module_sp ? exe_module_sp->GetFileSpec().GetPath().c_str () : "<none>", |
| 3688 | system_runtime->GetPluginName().AsCString("<unnamed>")); |
| 3689 | } |
| 3690 | } |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 3691 | |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 3692 | m_os_ap.reset (OperatingSystem::FindPlugin (this, NULL)); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3693 | // 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] | 3694 | const ModuleList &target_modules = m_target.GetImages(); |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3695 | Mutex::Locker modules_locker(target_modules.GetMutex()); |
| 3696 | size_t num_modules = target_modules.GetSize(); |
| 3697 | ModuleSP new_executable_module_sp; |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3698 | |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 3699 | for (size_t i = 0; i < num_modules; i++) |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3700 | { |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3701 | ModuleSP module_sp (target_modules.GetModuleAtIndexUnlocked (i)); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3702 | if (module_sp && module_sp->IsExecutable()) |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3703 | { |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 3704 | if (m_target.GetExecutableModulePointer() != module_sp.get()) |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3705 | new_executable_module_sp = module_sp; |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3706 | break; |
| 3707 | } |
| 3708 | } |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3709 | if (new_executable_module_sp) |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3710 | { |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 3711 | m_target.SetExecutableModule (new_executable_module_sp, false); |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 3712 | if (log) |
| 3713 | { |
| 3714 | ModuleSP exe_module_sp = m_target.GetExecutableModule (); |
| 3715 | log->Printf ("Process::%s after looping through modules, target executable is %s", |
| 3716 | __FUNCTION__, |
| 3717 | exe_module_sp ? exe_module_sp->GetFileSpec().GetPath().c_str () : "<none>"); |
| 3718 | } |
| 3719 | } |
Greg Clayton | a97c4d2 | 2014-12-09 23:31:02 +0000 | [diff] [blame] | 3720 | |
| 3721 | m_stop_info_override_callback = process_arch.GetStopInfoOverrideCallback(); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 3722 | } |
| 3723 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3724 | Error |
Jason Molenda | 4bd4e7e | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 3725 | Process::ConnectRemote (Stream *strm, const char *remote_url) |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 3726 | { |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 3727 | m_abi_sp.reset(); |
| 3728 | m_process_input_reader.reset(); |
| 3729 | |
| 3730 | // Find the process and its architecture. Make sure it matches the architecture |
| 3731 | // of the current Target, and if not adjust it. |
| 3732 | |
Jason Molenda | 4bd4e7e | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 3733 | Error error (DoConnectRemote (strm, remote_url)); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 3734 | if (error.Success()) |
| 3735 | { |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3736 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
| 3737 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 3738 | EventSP event_sp; |
| 3739 | StateType state = WaitForProcessStopPrivate(NULL, event_sp); |
| 3740 | |
| 3741 | if (state == eStateStopped || state == eStateCrashed) |
| 3742 | { |
| 3743 | // If we attached and actually have a process on the other end, then |
| 3744 | // this ended up being the equivalent of an attach. |
| 3745 | CompleteAttach (); |
| 3746 | |
| 3747 | // This delays passing the stopped event to listeners till |
| 3748 | // CompleteAttach gets a chance to complete... |
| 3749 | HandlePrivateEvent (event_sp); |
| 3750 | |
| 3751 | } |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 3752 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 3753 | |
| 3754 | if (PrivateStateThreadIsValid ()) |
| 3755 | ResumePrivateStateThread (); |
| 3756 | else |
| 3757 | StartPrivateStateThread (); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 3758 | } |
| 3759 | return error; |
| 3760 | } |
| 3761 | |
| 3762 | |
| 3763 | Error |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 3764 | Process::PrivateResume () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3765 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3766 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS|LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3767 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3768 | 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] | 3769 | m_mod_id.GetStopID(), |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 3770 | StateAsCString(m_public_state.GetValue()), |
| 3771 | StateAsCString(m_private_state.GetValue())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3772 | |
| 3773 | Error error (WillResume()); |
| 3774 | // Tell the process it is about to resume before the thread list |
| 3775 | if (error.Success()) |
| 3776 | { |
Johnny Chen | c4221e4 | 2010-12-02 20:53:05 +0000 | [diff] [blame] | 3777 | // 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] | 3778 | // can let all of our threads know that they are about to be |
| 3779 | // resumed. Threads will each be called with |
| 3780 | // Thread::WillResume(StateType) where StateType contains the state |
| 3781 | // that they are supposed to have when the process is resumed |
| 3782 | // (suspended/running/stepping). Threads should also check |
| 3783 | // their resume signal in lldb::Thread::GetResumeSignal() |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 3784 | // 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] | 3785 | if (m_thread_list.WillResume()) |
| 3786 | { |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 3787 | // Last thing, do the PreResumeActions. |
| 3788 | if (!RunPreResumeActions()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3789 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3790 | error.SetErrorStringWithFormat ("Process::PrivateResume PreResumeActions failed, not resuming."); |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 3791 | } |
| 3792 | else |
| 3793 | { |
| 3794 | m_mod_id.BumpResumeID(); |
| 3795 | error = DoResume(); |
| 3796 | if (error.Success()) |
| 3797 | { |
| 3798 | DidResume(); |
| 3799 | m_thread_list.DidResume(); |
| 3800 | if (log) |
| 3801 | log->Printf ("Process thinks the process has resumed."); |
| 3802 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3803 | } |
| 3804 | } |
| 3805 | else |
| 3806 | { |
Jim Ingham | d5ac1ab | 2015-01-19 23:51:51 +0000 | [diff] [blame] | 3807 | // Somebody wanted to run without running (e.g. we were faking a step from one frame of a set of inlined |
| 3808 | // frames that share the same PC to another.) So generate a continue & a stopped event, |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 3809 | // and let the world handle them. |
| 3810 | if (log) |
| 3811 | log->Printf ("Process::PrivateResume() asked to simulate a start & stop."); |
| 3812 | |
| 3813 | SetPrivateState(eStateRunning); |
| 3814 | SetPrivateState(eStateStopped); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3815 | } |
| 3816 | } |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 3817 | else if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 3818 | log->Printf ("Process::PrivateResume() got an error \"%s\".", error.AsCString("<unknown error>")); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3819 | return error; |
| 3820 | } |
| 3821 | |
| 3822 | Error |
Greg Clayton | f9b57b9 | 2013-05-10 23:48:10 +0000 | [diff] [blame] | 3823 | Process::Halt (bool clear_thread_plans) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3824 | { |
Greg Clayton | f9b57b9 | 2013-05-10 23:48:10 +0000 | [diff] [blame] | 3825 | // Don't clear the m_clear_thread_plans_on_stop, only set it to true if |
| 3826 | // in case it was already set and some thread plan logic calls halt on its |
| 3827 | // own. |
| 3828 | m_clear_thread_plans_on_stop |= clear_thread_plans; |
| 3829 | |
Jim Ingham | aacc318 | 2012-06-06 00:29:30 +0000 | [diff] [blame] | 3830 | // First make sure we aren't in the middle of handling an event, or we might restart. This is pretty weak, since |
| 3831 | // we could just straightaway get another event. It just narrows the window... |
| 3832 | m_currently_handling_event.WaitForValueEqualTo(false); |
| 3833 | |
| 3834 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3835 | // Pause our private state thread so we can ensure no one else eats |
| 3836 | // the stop event out from under us. |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 3837 | Listener halt_listener ("lldb.process.halt_listener"); |
| 3838 | HijackPrivateProcessEvents(&halt_listener); |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 3839 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3840 | EventSP event_sp; |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3841 | Error error (WillHalt()); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3842 | |
Greg Clayton | 06357c9 | 2014-07-30 17:38:47 +0000 | [diff] [blame] | 3843 | bool restored_process_events = false; |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3844 | if (error.Success()) |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3845 | { |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3846 | |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3847 | bool caused_stop = false; |
| 3848 | |
| 3849 | // Ask the process subclass to actually halt our process |
| 3850 | error = DoHalt(caused_stop); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3851 | if (error.Success()) |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3852 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3853 | if (m_public_state.GetValue() == eStateAttaching) |
| 3854 | { |
Greg Clayton | 06357c9 | 2014-07-30 17:38:47 +0000 | [diff] [blame] | 3855 | // Don't hijack and eat the eStateExited as the code that was doing |
| 3856 | // the attach will be waiting for this event... |
| 3857 | RestorePrivateProcessEvents(); |
| 3858 | restored_process_events = true; |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3859 | SetExitStatus(SIGKILL, "Cancelled async attach."); |
Jason Molenda | ede3193 | 2015-04-17 05:01:58 +0000 | [diff] [blame] | 3860 | Destroy (false); |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 3861 | } |
| 3862 | else |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3863 | { |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3864 | // If "caused_stop" is true, then DoHalt stopped the process. If |
| 3865 | // "caused_stop" is false, the process was already stopped. |
| 3866 | // If the DoHalt caused the process to stop, then we want to catch |
| 3867 | // this event and set the interrupted bool to true before we pass |
| 3868 | // this along so clients know that the process was interrupted by |
| 3869 | // a halt command. |
| 3870 | if (caused_stop) |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 3871 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 3872 | // Wait for 1 second for the process to stop. |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3873 | TimeValue timeout_time; |
| 3874 | timeout_time = TimeValue::Now(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 3875 | timeout_time.OffsetWithSeconds(10); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 3876 | bool got_event = halt_listener.WaitForEvent (&timeout_time, event_sp); |
| 3877 | StateType state = ProcessEventData::GetStateFromEvent(event_sp.get()); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3878 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 3879 | if (!got_event || state == eStateInvalid) |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 3880 | { |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3881 | // We timeout out and didn't get a stop event... |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 3882 | error.SetErrorStringWithFormat ("Halt timed out. State = %s", StateAsCString(GetState())); |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 3883 | } |
| 3884 | else |
| 3885 | { |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 3886 | if (StateIsStoppedState (state, false)) |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3887 | { |
| 3888 | // We caused the process to interrupt itself, so mark this |
| 3889 | // as such in the stop event so clients can tell an interrupted |
| 3890 | // process from a natural stop |
| 3891 | ProcessEventData::SetInterruptedInEvent (event_sp.get(), true); |
| 3892 | } |
| 3893 | else |
| 3894 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 3895 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3896 | if (log) |
| 3897 | log->Printf("Process::Halt() failed to stop, state is: %s", StateAsCString(state)); |
| 3898 | error.SetErrorString ("Did not get stopped event after halt."); |
| 3899 | } |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 3900 | } |
| 3901 | } |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3902 | DidHalt(); |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3903 | } |
| 3904 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3905 | } |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3906 | // Resume our private state thread before we post the event (if any) |
Greg Clayton | 06357c9 | 2014-07-30 17:38:47 +0000 | [diff] [blame] | 3907 | if (!restored_process_events) |
| 3908 | RestorePrivateProcessEvents(); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3909 | |
| 3910 | // Post any event we might have consumed. If all goes well, we will have |
| 3911 | // stopped the process, intercepted the event and set the interrupted |
| 3912 | // bool in the event. Post it to the private event queue and that will end up |
| 3913 | // correctly setting the state. |
| 3914 | if (event_sp) |
| 3915 | m_private_state_broadcaster.BroadcastEvent(event_sp); |
| 3916 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3917 | return error; |
| 3918 | } |
| 3919 | |
| 3920 | Error |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 3921 | Process::HaltForDestroyOrDetach(lldb::EventSP &exit_event_sp) |
| 3922 | { |
| 3923 | Error error; |
| 3924 | if (m_public_state.GetValue() == eStateRunning) |
| 3925 | { |
| 3926 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 3927 | if (log) |
| 3928 | log->Printf("Process::Destroy() About to halt."); |
| 3929 | error = Halt(); |
| 3930 | if (error.Success()) |
| 3931 | { |
| 3932 | // Consume the halt event. |
| 3933 | TimeValue timeout (TimeValue::Now()); |
| 3934 | timeout.OffsetWithSeconds(1); |
| 3935 | StateType state = WaitForProcessToStop (&timeout, &exit_event_sp); |
| 3936 | |
| 3937 | // If the process exited while we were waiting for it to stop, put the exited event into |
| 3938 | // the shared pointer passed in and return. Our caller doesn't need to do anything else, since |
| 3939 | // they don't have a process anymore... |
| 3940 | |
| 3941 | if (state == eStateExited || m_private_state.GetValue() == eStateExited) |
| 3942 | { |
| 3943 | if (log) |
| 3944 | log->Printf("Process::HaltForDestroyOrDetach() Process exited while waiting to Halt."); |
| 3945 | return error; |
| 3946 | } |
| 3947 | else |
| 3948 | exit_event_sp.reset(); // It is ok to consume any non-exit stop events |
| 3949 | |
| 3950 | if (state != eStateStopped) |
| 3951 | { |
| 3952 | if (log) |
| 3953 | log->Printf("Process::HaltForDestroyOrDetach() Halt failed to stop, state is: %s", StateAsCString(state)); |
| 3954 | // If we really couldn't stop the process then we should just error out here, but if the |
| 3955 | // lower levels just bobbled sending the event and we really are stopped, then continue on. |
| 3956 | StateType private_state = m_private_state.GetValue(); |
| 3957 | if (private_state != eStateStopped) |
| 3958 | { |
| 3959 | return error; |
| 3960 | } |
| 3961 | } |
| 3962 | } |
| 3963 | else |
| 3964 | { |
| 3965 | if (log) |
| 3966 | log->Printf("Process::HaltForDestroyOrDetach() Halt got error: %s", error.AsCString()); |
| 3967 | } |
| 3968 | } |
| 3969 | return error; |
| 3970 | } |
| 3971 | |
| 3972 | Error |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 3973 | Process::Detach (bool keep_stopped) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3974 | { |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 3975 | EventSP exit_event_sp; |
| 3976 | Error error; |
| 3977 | m_destroy_in_process = true; |
| 3978 | |
| 3979 | error = WillDetach(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3980 | |
| 3981 | if (error.Success()) |
| 3982 | { |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 3983 | if (DetachRequiresHalt()) |
| 3984 | { |
| 3985 | error = HaltForDestroyOrDetach (exit_event_sp); |
| 3986 | if (!error.Success()) |
| 3987 | { |
| 3988 | m_destroy_in_process = false; |
| 3989 | return error; |
| 3990 | } |
| 3991 | else if (exit_event_sp) |
| 3992 | { |
| 3993 | // We shouldn't need to do anything else here. There's no process left to detach from... |
| 3994 | StopPrivateStateThread(); |
| 3995 | m_destroy_in_process = false; |
| 3996 | return error; |
| 3997 | } |
| 3998 | } |
| 3999 | |
Andrew MacPherson | c3826b5 | 2014-03-25 19:59:36 +0000 | [diff] [blame] | 4000 | m_thread_list.DiscardThreadPlans(); |
| 4001 | DisableAllBreakpointSites(); |
| 4002 | |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 4003 | error = DoDetach(keep_stopped); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4004 | if (error.Success()) |
| 4005 | { |
| 4006 | DidDetach(); |
| 4007 | StopPrivateStateThread(); |
| 4008 | } |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 4009 | else |
| 4010 | { |
| 4011 | return error; |
| 4012 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4013 | } |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 4014 | m_destroy_in_process = false; |
| 4015 | |
| 4016 | // If we exited when we were waiting for a process to stop, then |
| 4017 | // forward the event here so we don't lose the event |
| 4018 | if (exit_event_sp) |
| 4019 | { |
| 4020 | // Directly broadcast our exited event because we shut down our |
| 4021 | // private state thread above |
| 4022 | BroadcastEvent(exit_event_sp); |
| 4023 | } |
| 4024 | |
| 4025 | // If we have been interrupted (to kill us) in the middle of running, we may not end up propagating |
| 4026 | // the last events through the event system, in which case we might strand the write lock. Unlock |
| 4027 | // it here so when we do to tear down the process we don't get an error destroying the lock. |
| 4028 | |
Ed Maste | 64fad60 | 2013-07-29 20:58:06 +0000 | [diff] [blame] | 4029 | m_public_run_lock.SetStopped(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4030 | return error; |
| 4031 | } |
| 4032 | |
| 4033 | Error |
Jason Molenda | ede3193 | 2015-04-17 05:01:58 +0000 | [diff] [blame] | 4034 | Process::Destroy (bool force_kill) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4035 | { |
Jim Ingham | 0943792 | 2013-03-01 20:04:25 +0000 | [diff] [blame] | 4036 | |
| 4037 | // Tell ourselves we are in the process of destroying the process, so that we don't do any unnecessary work |
| 4038 | // that might hinder the destruction. Remember to set this back to false when we are done. That way if the attempt |
| 4039 | // failed and the process stays around for some reason it won't be in a confused state. |
Jason Molenda | ede3193 | 2015-04-17 05:01:58 +0000 | [diff] [blame] | 4040 | |
| 4041 | if (force_kill) |
| 4042 | m_should_detach = false; |
Jim Ingham | 0943792 | 2013-03-01 20:04:25 +0000 | [diff] [blame] | 4043 | |
Ilia K | fcc89a0 | 2015-03-26 07:08:47 +0000 | [diff] [blame] | 4044 | if (GetShouldDetach()) |
| 4045 | { |
| 4046 | // FIXME: This will have to be a process setting: |
| 4047 | bool keep_stopped = false; |
| 4048 | Detach(keep_stopped); |
| 4049 | } |
| 4050 | |
Jim Ingham | 0943792 | 2013-03-01 20:04:25 +0000 | [diff] [blame] | 4051 | m_destroy_in_process = true; |
| 4052 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4053 | Error error (WillDestroy()); |
| 4054 | if (error.Success()) |
| 4055 | { |
Greg Clayton | 85fb1b9 | 2012-09-11 02:33:37 +0000 | [diff] [blame] | 4056 | EventSP exit_event_sp; |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 4057 | if (DestroyRequiresHalt()) |
Jim Ingham | 04e0a22 | 2012-05-23 15:46:31 +0000 | [diff] [blame] | 4058 | { |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 4059 | error = HaltForDestroyOrDetach(exit_event_sp); |
Jim Ingham | 04e0a22 | 2012-05-23 15:46:31 +0000 | [diff] [blame] | 4060 | } |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 4061 | |
Jim Ingham | aacc318 | 2012-06-06 00:29:30 +0000 | [diff] [blame] | 4062 | if (m_public_state.GetValue() != eStateRunning) |
| 4063 | { |
| 4064 | // Ditch all thread plans, and remove all our breakpoints: in case we have to restart the target to |
| 4065 | // kill it, we don't want it hitting a breakpoint... |
| 4066 | // Only do this if we've stopped, however, since if we didn't manage to halt it above, then |
| 4067 | // we're not going to have much luck doing this now. |
| 4068 | m_thread_list.DiscardThreadPlans(); |
| 4069 | DisableAllBreakpointSites(); |
| 4070 | } |
Jim Ingham | 8af3b9c | 2013-03-29 01:18:12 +0000 | [diff] [blame] | 4071 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4072 | error = DoDestroy(); |
| 4073 | if (error.Success()) |
| 4074 | { |
| 4075 | DidDestroy(); |
| 4076 | StopPrivateStateThread(); |
| 4077 | } |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4078 | m_stdio_communication.Disconnect(); |
Greg Clayton | 23d54f4 | 2015-06-03 00:34:01 +0000 | [diff] [blame] | 4079 | m_stdio_communication.StopReadThread(); |
Vince Harron | df3f00f | 2015-02-10 21:09:04 +0000 | [diff] [blame] | 4080 | m_stdin_forward = false; |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 4081 | |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4082 | if (m_process_input_reader) |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 4083 | { |
| 4084 | m_process_input_reader->SetIsDone(true); |
| 4085 | m_process_input_reader->Cancel(); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 4086 | m_process_input_reader.reset(); |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 4087 | } |
| 4088 | |
Greg Clayton | 85fb1b9 | 2012-09-11 02:33:37 +0000 | [diff] [blame] | 4089 | // If we exited when we were waiting for a process to stop, then |
| 4090 | // forward the event here so we don't lose the event |
| 4091 | if (exit_event_sp) |
| 4092 | { |
| 4093 | // Directly broadcast our exited event because we shut down our |
| 4094 | // private state thread above |
| 4095 | BroadcastEvent(exit_event_sp); |
| 4096 | } |
| 4097 | |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 4098 | // If we have been interrupted (to kill us) in the middle of running, we may not end up propagating |
| 4099 | // the last events through the event system, in which case we might strand the write lock. Unlock |
| 4100 | // 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] | 4101 | m_public_run_lock.SetStopped(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4102 | } |
Jim Ingham | 0943792 | 2013-03-01 20:04:25 +0000 | [diff] [blame] | 4103 | |
| 4104 | m_destroy_in_process = false; |
| 4105 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4106 | return error; |
| 4107 | } |
| 4108 | |
| 4109 | Error |
| 4110 | Process::Signal (int signal) |
| 4111 | { |
| 4112 | Error error (WillSignal()); |
| 4113 | if (error.Success()) |
| 4114 | { |
| 4115 | error = DoSignal(signal); |
| 4116 | if (error.Success()) |
| 4117 | DidSignal(); |
| 4118 | } |
| 4119 | return error; |
| 4120 | } |
| 4121 | |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 4122 | void |
Chaoren Lin | c963a22 | 2015-09-01 16:58:45 +0000 | [diff] [blame^] | 4123 | Process::SetUnixSignals(UnixSignalsSP &&signals_sp) |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 4124 | { |
| 4125 | assert (signals_sp && "null signals_sp"); |
| 4126 | m_unix_signals_sp = signals_sp; |
| 4127 | } |
| 4128 | |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 4129 | const lldb::UnixSignalsSP & |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 4130 | Process::GetUnixSignals () |
| 4131 | { |
| 4132 | assert (m_unix_signals_sp && "null m_unix_signals_sp"); |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 4133 | return m_unix_signals_sp; |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 4134 | } |
| 4135 | |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 4136 | lldb::ByteOrder |
| 4137 | Process::GetByteOrder () const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4138 | { |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 4139 | return m_target.GetArchitecture().GetByteOrder(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | uint32_t |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 4143 | Process::GetAddressByteSize () const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4144 | { |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 4145 | return m_target.GetArchitecture().GetAddressByteSize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4146 | } |
| 4147 | |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 4148 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4149 | bool |
| 4150 | Process::ShouldBroadcastEvent (Event *event_ptr) |
| 4151 | { |
| 4152 | const StateType state = Process::ProcessEventData::GetStateFromEvent (event_ptr); |
| 4153 | bool return_value = true; |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4154 | Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EVENTS | LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4155 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4156 | switch (state) |
| 4157 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4158 | case eStateDetached: |
| 4159 | case eStateExited: |
| 4160 | case eStateUnloaded: |
Pavel Labath | 3f5df53 | 2015-03-12 10:12:41 +0000 | [diff] [blame] | 4161 | m_stdio_communication.SynchronizeWithReadThread(); |
| 4162 | // fall-through |
| 4163 | case eStateConnected: |
| 4164 | case eStateAttaching: |
| 4165 | case eStateLaunching: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4166 | // These events indicate changes in the state of the debugging session, always report them. |
| 4167 | return_value = true; |
| 4168 | break; |
| 4169 | case eStateInvalid: |
| 4170 | // We stopped for no apparent reason, don't report it. |
| 4171 | return_value = false; |
| 4172 | break; |
| 4173 | case eStateRunning: |
| 4174 | case eStateStepping: |
| 4175 | // If we've started the target running, we handle the cases where we |
| 4176 | // are already running and where there is a transition from stopped to |
| 4177 | // running differently. |
| 4178 | // running -> running: Automatically suppress extra running events |
| 4179 | // stopped -> running: Report except when there is one or more no votes |
| 4180 | // and no yes votes. |
| 4181 | SynchronouslyNotifyStateChanged (state); |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 4182 | if (m_force_next_event_delivery) |
| 4183 | return_value = true; |
| 4184 | else |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4185 | { |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 4186 | switch (m_last_broadcast_state) |
| 4187 | { |
| 4188 | case eStateRunning: |
| 4189 | case eStateStepping: |
| 4190 | // We always suppress multiple runnings with no PUBLIC stop in between. |
| 4191 | return_value = false; |
| 4192 | break; |
| 4193 | default: |
| 4194 | // TODO: make this work correctly. For now always report |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 4195 | // 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] | 4196 | // events. If I run the lldb/test/thread/a.out file and |
| 4197 | // break at main.cpp:58, run and hit the breakpoints on |
| 4198 | // multiple threads, then somehow during the stepping over |
| 4199 | // of all breakpoints no run gets reported. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4200 | |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 4201 | // This is a transition from stop to run. |
| 4202 | switch (m_thread_list.ShouldReportRun (event_ptr)) |
| 4203 | { |
| 4204 | case eVoteYes: |
| 4205 | case eVoteNoOpinion: |
| 4206 | return_value = true; |
| 4207 | break; |
| 4208 | case eVoteNo: |
| 4209 | return_value = false; |
| 4210 | break; |
| 4211 | } |
| 4212 | break; |
| 4213 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4214 | } |
| 4215 | break; |
| 4216 | case eStateStopped: |
| 4217 | case eStateCrashed: |
| 4218 | case eStateSuspended: |
| 4219 | { |
| 4220 | // We've stopped. First see if we're going to restart the target. |
| 4221 | // If we are going to stop, then we always broadcast the event. |
| 4222 | // 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] | 4223 | // If no thread has an opinion, we don't report it. |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 4224 | |
Pavel Labath | 3f5df53 | 2015-03-12 10:12:41 +0000 | [diff] [blame] | 4225 | m_stdio_communication.SynchronizeWithReadThread(); |
Jim Ingham | cb4ca11 | 2012-05-16 01:32:14 +0000 | [diff] [blame] | 4226 | RefreshStateAfterStop (); |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4227 | if (ProcessEventData::GetInterruptedFromEvent (event_ptr)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4228 | { |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 4229 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4230 | log->Printf ("Process::ShouldBroadcastEvent (%p) stopped due to an interrupt, state: %s", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4231 | static_cast<void*>(event_ptr), |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4232 | StateAsCString(state)); |
Jim Ingham | 35878c4 | 2014-04-08 21:33:21 +0000 | [diff] [blame] | 4233 | // Even though we know we are going to stop, we should let the threads have a look at the stop, |
| 4234 | // so they can properly set their state. |
| 4235 | m_thread_list.ShouldStop (event_ptr); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4236 | return_value = true; |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4237 | } |
| 4238 | else |
| 4239 | { |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 4240 | bool was_restarted = ProcessEventData::GetRestartedFromEvent (event_ptr); |
| 4241 | bool should_resume = false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4242 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4243 | // It makes no sense to ask "ShouldStop" if we've already been restarted... |
| 4244 | // Asking the thread list is also not likely to go well, since we are running again. |
| 4245 | // So in that case just report the event. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4246 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4247 | if (!was_restarted) |
| 4248 | should_resume = m_thread_list.ShouldStop (event_ptr) == false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4249 | |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 4250 | if (was_restarted || should_resume || m_resume_requested) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4251 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4252 | Vote stop_vote = m_thread_list.ShouldReportStop (event_ptr); |
| 4253 | if (log) |
| 4254 | 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] | 4255 | should_resume, StateAsCString(state), |
| 4256 | was_restarted, stop_vote); |
| 4257 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4258 | switch (stop_vote) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4259 | { |
| 4260 | case eVoteYes: |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4261 | return_value = true; |
| 4262 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4263 | case eVoteNoOpinion: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4264 | case eVoteNo: |
| 4265 | return_value = false; |
| 4266 | break; |
| 4267 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4268 | |
Jim Ingham | cb95f34 | 2012-09-05 21:13:56 +0000 | [diff] [blame] | 4269 | if (!was_restarted) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4270 | { |
| 4271 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4272 | log->Printf ("Process::ShouldBroadcastEvent (%p) Restarting process from state: %s", |
| 4273 | static_cast<void*>(event_ptr), |
| 4274 | StateAsCString(state)); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4275 | ProcessEventData::SetRestartedInEvent(event_ptr, true); |
Jim Ingham | cb95f34 | 2012-09-05 21:13:56 +0000 | [diff] [blame] | 4276 | PrivateResume (); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4277 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4278 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4279 | } |
| 4280 | else |
| 4281 | { |
| 4282 | return_value = true; |
| 4283 | SynchronouslyNotifyStateChanged (state); |
| 4284 | } |
| 4285 | } |
| 4286 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4287 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4288 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4289 | |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 4290 | // Forcing the next event delivery is a one shot deal. So reset it here. |
| 4291 | m_force_next_event_delivery = false; |
| 4292 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4293 | // We do some coalescing of events (for instance two consecutive running events get coalesced.) |
| 4294 | // But we only coalesce against events we actually broadcast. So we use m_last_broadcast_state |
| 4295 | // to track that. NB - you can't use "m_public_state.GetValue()" for that purpose, as was originally done, |
| 4296 | // because the PublicState reflects the last event pulled off the queue, and there may be several |
| 4297 | // events stacked up on the queue unserviced. So the PublicState may not reflect the last broadcasted event |
| 4298 | // yet. m_last_broadcast_state gets updated here. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4299 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4300 | if (return_value) |
| 4301 | m_last_broadcast_state = state; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4302 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4303 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4304 | 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] | 4305 | static_cast<void*>(event_ptr), StateAsCString(state), |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4306 | StateAsCString(m_last_broadcast_state), |
| 4307 | return_value ? "YES" : "NO"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4308 | return return_value; |
| 4309 | } |
| 4310 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4311 | |
| 4312 | bool |
Jim Ingham | 60c915e | 2015-06-23 21:02:45 +0000 | [diff] [blame] | 4313 | Process::StartPrivateStateThread (bool is_secondary_thread) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4314 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4315 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4316 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 4317 | bool already_running = PrivateStateThreadIsValid (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4318 | if (log) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 4319 | log->Printf ("Process::%s()%s ", __FUNCTION__, already_running ? " already running" : " starting private state thread"); |
| 4320 | |
Jim Ingham | 60c915e | 2015-06-23 21:02:45 +0000 | [diff] [blame] | 4321 | if (!is_secondary_thread && already_running) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 4322 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4323 | |
| 4324 | // Create a thread that watches our internal state and controls which |
| 4325 | // events make it to clients (into the DCProcess event queue). |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 4326 | char thread_name[1024]; |
Todd Fiala | 17096d7 | 2014-07-16 19:03:16 +0000 | [diff] [blame] | 4327 | |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 4328 | if (HostInfo::GetMaxThreadNameLength() <= 30) |
Todd Fiala | 17096d7 | 2014-07-16 19:03:16 +0000 | [diff] [blame] | 4329 | { |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 4330 | // On platforms with abbreviated thread name lengths, choose thread names that fit within the limit. |
| 4331 | if (already_running) |
| 4332 | snprintf(thread_name, sizeof(thread_name), "intern-state-OV"); |
| 4333 | else |
| 4334 | snprintf(thread_name, sizeof(thread_name), "intern-state"); |
Todd Fiala | 17096d7 | 2014-07-16 19:03:16 +0000 | [diff] [blame] | 4335 | } |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4336 | else |
Todd Fiala | 17096d7 | 2014-07-16 19:03:16 +0000 | [diff] [blame] | 4337 | { |
| 4338 | if (already_running) |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 4339 | snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state-override(pid=%" PRIu64 ")>", GetID()); |
Todd Fiala | 17096d7 | 2014-07-16 19:03:16 +0000 | [diff] [blame] | 4340 | else |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 4341 | snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state(pid=%" PRIu64 ")>", GetID()); |
Todd Fiala | 17096d7 | 2014-07-16 19:03:16 +0000 | [diff] [blame] | 4342 | } |
| 4343 | |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4344 | // Create the private state thread, and start it running. |
Jim Ingham | 60c915e | 2015-06-23 21:02:45 +0000 | [diff] [blame] | 4345 | PrivateStateThreadArgs args = {this, is_secondary_thread}; |
| 4346 | m_private_state_thread = ThreadLauncher::LaunchThread(thread_name, Process::PrivateStateThread, (void *) &args, NULL); |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 4347 | if (m_private_state_thread.IsJoinable()) |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4348 | { |
| 4349 | ResumePrivateStateThread(); |
| 4350 | return true; |
| 4351 | } |
| 4352 | else |
| 4353 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | void |
| 4357 | Process::PausePrivateStateThread () |
| 4358 | { |
| 4359 | ControlPrivateStateThread (eBroadcastInternalStateControlPause); |
| 4360 | } |
| 4361 | |
| 4362 | void |
| 4363 | Process::ResumePrivateStateThread () |
| 4364 | { |
| 4365 | ControlPrivateStateThread (eBroadcastInternalStateControlResume); |
| 4366 | } |
| 4367 | |
| 4368 | void |
| 4369 | Process::StopPrivateStateThread () |
| 4370 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 4371 | if (PrivateStateThreadIsValid ()) |
| 4372 | ControlPrivateStateThread (eBroadcastInternalStateControlStop); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 4373 | else |
| 4374 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4375 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 4376 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4377 | 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] | 4378 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4379 | } |
| 4380 | |
| 4381 | void |
| 4382 | Process::ControlPrivateStateThread (uint32_t signal) |
| 4383 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4384 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4385 | |
| 4386 | assert (signal == eBroadcastInternalStateControlStop || |
| 4387 | signal == eBroadcastInternalStateControlPause || |
| 4388 | signal == eBroadcastInternalStateControlResume); |
| 4389 | |
| 4390 | if (log) |
Greg Clayton | 7ecb3a0 | 2011-01-22 17:43:17 +0000 | [diff] [blame] | 4391 | log->Printf ("Process::%s (signal = %d)", __FUNCTION__, signal); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4392 | |
Greg Clayton | 7ecb3a0 | 2011-01-22 17:43:17 +0000 | [diff] [blame] | 4393 | // Signal the private state thread. First we should copy this is case the |
| 4394 | // thread starts exiting since the private state thread will NULL this out |
| 4395 | // when it exits |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 4396 | HostThread private_state_thread(m_private_state_thread); |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 4397 | if (private_state_thread.IsJoinable()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4398 | { |
| 4399 | TimeValue timeout_time; |
| 4400 | bool timed_out; |
| 4401 | |
| 4402 | m_private_state_control_broadcaster.BroadcastEvent (signal, NULL); |
| 4403 | |
| 4404 | timeout_time = TimeValue::Now(); |
| 4405 | timeout_time.OffsetWithSeconds(2); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 4406 | if (log) |
| 4407 | log->Printf ("Sending control event of type: %d.", signal); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4408 | m_private_state_control_wait.WaitForValueEqualTo (true, &timeout_time, &timed_out); |
| 4409 | m_private_state_control_wait.SetValue (false, eBroadcastNever); |
| 4410 | |
| 4411 | if (signal == eBroadcastInternalStateControlStop) |
| 4412 | { |
| 4413 | if (timed_out) |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 4414 | { |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 4415 | Error error = private_state_thread.Cancel(); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 4416 | if (log) |
| 4417 | log->Printf ("Timed out responding to the control event, cancel got error: \"%s\".", error.AsCString()); |
| 4418 | } |
| 4419 | else |
| 4420 | { |
| 4421 | if (log) |
| 4422 | log->Printf ("The control event killed the private state thread without having to cancel."); |
| 4423 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4424 | |
| 4425 | thread_result_t result = NULL; |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 4426 | private_state_thread.Join(&result); |
| 4427 | m_private_state_thread.Reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4428 | } |
| 4429 | } |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 4430 | else |
| 4431 | { |
| 4432 | if (log) |
| 4433 | log->Printf ("Private state thread already dead, no need to signal it to stop."); |
| 4434 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | void |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 4438 | Process::SendAsyncInterrupt () |
| 4439 | { |
| 4440 | if (PrivateStateThreadIsValid()) |
| 4441 | m_private_state_broadcaster.BroadcastEvent (Process::eBroadcastBitInterrupt, NULL); |
| 4442 | else |
| 4443 | BroadcastEvent (Process::eBroadcastBitInterrupt, NULL); |
| 4444 | } |
| 4445 | |
| 4446 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4447 | Process::HandlePrivateEvent (EventSP &event_sp) |
| 4448 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4449 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 4450 | m_resume_requested = false; |
| 4451 | |
Jim Ingham | aacc318 | 2012-06-06 00:29:30 +0000 | [diff] [blame] | 4452 | m_currently_handling_event.SetValue(true, eBroadcastNever); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 4453 | |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 4454 | const StateType new_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 4455 | |
| 4456 | // First check to see if anybody wants a shot at this event: |
Jim Ingham | 754ab98 | 2011-01-29 04:05:41 +0000 | [diff] [blame] | 4457 | if (m_next_event_action_ap.get() != NULL) |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 4458 | { |
Jim Ingham | 754ab98 | 2011-01-29 04:05:41 +0000 | [diff] [blame] | 4459 | NextEventAction::EventActionResult action_result = m_next_event_action_ap->PerformAction(event_sp); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4460 | if (log) |
| 4461 | log->Printf ("Ran next event action, result was %d.", action_result); |
| 4462 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 4463 | switch (action_result) |
| 4464 | { |
| 4465 | case NextEventAction::eEventActionSuccess: |
| 4466 | SetNextEventAction(NULL); |
| 4467 | break; |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 4468 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 4469 | case NextEventAction::eEventActionRetry: |
| 4470 | break; |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 4471 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 4472 | case NextEventAction::eEventActionExit: |
Jim Ingham | 2a5fdd4 | 2011-01-29 01:57:31 +0000 | [diff] [blame] | 4473 | // Handle Exiting Here. If we already got an exited event, |
| 4474 | // we should just propagate it. Otherwise, swallow this event, |
| 4475 | // and set our state to exit so the next event will kill us. |
| 4476 | if (new_state != eStateExited) |
| 4477 | { |
| 4478 | // FIXME: should cons up an exited event, and discard this one. |
Jim Ingham | 754ab98 | 2011-01-29 04:05:41 +0000 | [diff] [blame] | 4479 | SetExitStatus(0, m_next_event_action_ap->GetExitString()); |
Jim Ingham | 221d51c | 2013-05-08 00:35:16 +0000 | [diff] [blame] | 4480 | m_currently_handling_event.SetValue(false, eBroadcastAlways); |
Jim Ingham | 2a5fdd4 | 2011-01-29 01:57:31 +0000 | [diff] [blame] | 4481 | SetNextEventAction(NULL); |
| 4482 | return; |
| 4483 | } |
| 4484 | SetNextEventAction(NULL); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 4485 | break; |
| 4486 | } |
| 4487 | } |
| 4488 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4489 | // See if we should broadcast this state to external clients? |
| 4490 | const bool should_broadcast = ShouldBroadcastEvent (event_sp.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4491 | |
| 4492 | if (should_broadcast) |
| 4493 | { |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 4494 | const bool is_hijacked = IsHijackedForEvent(eBroadcastBitStateChanged); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4495 | if (log) |
| 4496 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4497 | 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] | 4498 | __FUNCTION__, |
| 4499 | GetID(), |
| 4500 | StateAsCString(new_state), |
| 4501 | StateAsCString (GetState ()), |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 4502 | is_hijacked ? "hijacked" : "public"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4503 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4504 | Process::ProcessEventData::SetUpdateStateOnRemoval(event_sp.get()); |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 4505 | if (StateIsRunningState (new_state)) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4506 | { |
| 4507 | // Only push the input handler if we aren't fowarding events, |
| 4508 | // as this means the curses GUI is in use... |
Todd Fiala | f72fa67 | 2014-10-07 16:05:21 +0000 | [diff] [blame] | 4509 | // Or don't push it if we are launching since it will come up stopped. |
Zachary Turner | c62733b | 2015-05-20 18:31:17 +0000 | [diff] [blame] | 4510 | if (!GetTarget().GetDebugger().IsForwardingEvents() && new_state != eStateLaunching && |
| 4511 | new_state != eStateAttaching) |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 4512 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4513 | PushProcessIOHandler (); |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 4514 | m_iohandler_sync.SetValue(m_iohandler_sync.GetValue()+1, eBroadcastAlways); |
| 4515 | if (log) |
| 4516 | log->Printf("Process::%s updated m_iohandler_sync to %d", __FUNCTION__, m_iohandler_sync.GetValue()); |
| 4517 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 4518 | } |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 4519 | else if (StateIsStoppedState(new_state, false)) |
| 4520 | { |
| 4521 | if (!Process::ProcessEventData::GetRestartedFromEvent(event_sp.get())) |
| 4522 | { |
| 4523 | // If the lldb_private::Debugger is handling the events, we don't |
| 4524 | // want to pop the process IOHandler here, we want to do it when |
| 4525 | // we receive the stopped event so we can carefully control when |
| 4526 | // the process IOHandler is popped because when we stop we want to |
| 4527 | // display some text stating how and why we stopped, then maybe some |
| 4528 | // process/thread/frame info, and then we want the "(lldb) " prompt |
| 4529 | // to show up. If we pop the process IOHandler here, then we will |
| 4530 | // cause the command interpreter to become the top IOHandler after |
| 4531 | // the process pops off and it will update its prompt right away... |
| 4532 | // See the Debugger.cpp file where it calls the function as |
| 4533 | // "process_sp->PopProcessIOHandler()" to see where I am talking about. |
| 4534 | // Otherwise we end up getting overlapping "(lldb) " prompts and |
| 4535 | // garbled output. |
| 4536 | // |
| 4537 | // If we aren't handling the events in the debugger (which is indicated |
| 4538 | // by "m_target.GetDebugger().IsHandlingEvents()" returning false) or we |
| 4539 | // are hijacked, then we always pop the process IO handler manually. |
| 4540 | // Hijacking happens when the internal process state thread is running |
| 4541 | // thread plans, or when commands want to run in synchronous mode |
| 4542 | // and they call "process->WaitForProcessToStop()". An example of something |
| 4543 | // that will hijack the events is a simple expression: |
| 4544 | // |
| 4545 | // (lldb) expr (int)puts("hello") |
| 4546 | // |
| 4547 | // This will cause the internal process state thread to resume and halt |
| 4548 | // the process (and _it_ will hijack the eBroadcastBitStateChanged |
| 4549 | // events) and we do need the IO handler to be pushed and popped |
| 4550 | // correctly. |
| 4551 | |
| 4552 | if (is_hijacked || m_target.GetDebugger().IsHandlingEvents() == false) |
| 4553 | PopProcessIOHandler (); |
| 4554 | } |
| 4555 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4556 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4557 | BroadcastEvent (event_sp); |
| 4558 | } |
| 4559 | else |
| 4560 | { |
| 4561 | if (log) |
| 4562 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 4563 | 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] | 4564 | __FUNCTION__, |
| 4565 | GetID(), |
| 4566 | StateAsCString(new_state), |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 4567 | StateAsCString (GetState ())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4568 | } |
| 4569 | } |
Jim Ingham | aacc318 | 2012-06-06 00:29:30 +0000 | [diff] [blame] | 4570 | m_currently_handling_event.SetValue(false, eBroadcastAlways); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4571 | } |
| 4572 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 4573 | thread_result_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4574 | Process::PrivateStateThread (void *arg) |
| 4575 | { |
Jim Ingham | 60c915e | 2015-06-23 21:02:45 +0000 | [diff] [blame] | 4576 | PrivateStateThreadArgs *real_args = static_cast<PrivateStateThreadArgs *> (arg); |
| 4577 | thread_result_t result = real_args->process->RunPrivateStateThread(real_args->is_secondary_thread); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4578 | return result; |
| 4579 | } |
| 4580 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 4581 | thread_result_t |
Jim Ingham | 60c915e | 2015-06-23 21:02:45 +0000 | [diff] [blame] | 4582 | Process::RunPrivateStateThread (bool is_secondary_thread) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4583 | { |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4584 | bool control_only = true; |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 4585 | m_private_state_control_wait.SetValue (false, eBroadcastNever); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4586 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4587 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4588 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4589 | log->Printf ("Process::%s (arg = %p, pid = %" PRIu64 ") thread starting...", |
| 4590 | __FUNCTION__, static_cast<void*>(this), GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4591 | |
| 4592 | bool exit_now = false; |
| 4593 | while (!exit_now) |
| 4594 | { |
| 4595 | EventSP event_sp; |
| 4596 | WaitForEventsPrivate (NULL, event_sp, control_only); |
| 4597 | if (event_sp->BroadcasterIs(&m_private_state_control_broadcaster)) |
| 4598 | { |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 4599 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4600 | log->Printf ("Process::%s (arg = %p, pid = %" PRIu64 ") got a control event: %d", |
| 4601 | __FUNCTION__, static_cast<void*>(this), GetID(), |
| 4602 | event_sp->GetType()); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 4603 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4604 | switch (event_sp->GetType()) |
| 4605 | { |
| 4606 | case eBroadcastInternalStateControlStop: |
| 4607 | exit_now = true; |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 4608 | break; // doing any internal state management below |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4609 | |
| 4610 | case eBroadcastInternalStateControlPause: |
| 4611 | control_only = true; |
| 4612 | break; |
| 4613 | |
| 4614 | case eBroadcastInternalStateControlResume: |
| 4615 | control_only = false; |
| 4616 | break; |
| 4617 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4618 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4619 | m_private_state_control_wait.SetValue (true, eBroadcastAlways); |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4620 | continue; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4621 | } |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 4622 | else if (event_sp->GetType() == eBroadcastBitInterrupt) |
| 4623 | { |
| 4624 | if (m_public_state.GetValue() == eStateAttaching) |
| 4625 | { |
| 4626 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4627 | log->Printf ("Process::%s (arg = %p, pid = %" PRIu64 ") woke up with an interrupt while attaching - forwarding interrupt.", |
| 4628 | __FUNCTION__, static_cast<void*>(this), |
| 4629 | GetID()); |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 4630 | BroadcastEvent (eBroadcastBitInterrupt, NULL); |
| 4631 | } |
| 4632 | else |
| 4633 | { |
| 4634 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4635 | log->Printf ("Process::%s (arg = %p, pid = %" PRIu64 ") woke up with an interrupt - Halting.", |
| 4636 | __FUNCTION__, static_cast<void*>(this), |
| 4637 | GetID()); |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 4638 | Halt(); |
| 4639 | } |
| 4640 | continue; |
| 4641 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4642 | |
| 4643 | const StateType internal_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 4644 | |
| 4645 | if (internal_state != eStateInvalid) |
| 4646 | { |
Greg Clayton | f9b57b9 | 2013-05-10 23:48:10 +0000 | [diff] [blame] | 4647 | if (m_clear_thread_plans_on_stop && |
| 4648 | StateIsStoppedState(internal_state, true)) |
| 4649 | { |
| 4650 | m_clear_thread_plans_on_stop = false; |
| 4651 | m_thread_list.DiscardThreadPlans(); |
| 4652 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4653 | HandlePrivateEvent (event_sp); |
| 4654 | } |
| 4655 | |
Greg Clayton | 58d1c9a | 2010-10-18 04:14:23 +0000 | [diff] [blame] | 4656 | if (internal_state == eStateInvalid || |
| 4657 | internal_state == eStateExited || |
| 4658 | internal_state == eStateDetached ) |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4659 | { |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4660 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4661 | log->Printf ("Process::%s (arg = %p, pid = %" PRIu64 ") about to exit with internal state %s...", |
| 4662 | __FUNCTION__, static_cast<void*>(this), GetID(), |
| 4663 | StateAsCString(internal_state)); |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4664 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4665 | break; |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4666 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4667 | } |
| 4668 | |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 4669 | // Verify log is still enabled before attempting to write to it... |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4670 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4671 | log->Printf ("Process::%s (arg = %p, pid = %" PRIu64 ") thread exiting...", |
| 4672 | __FUNCTION__, static_cast<void*>(this), GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4673 | |
Jim Ingham | 60c915e | 2015-06-23 21:02:45 +0000 | [diff] [blame] | 4674 | // If we are a secondary thread, then the primary thread we are working for will have already |
| 4675 | // acquired the public_run_lock, and isn't done with what it was doing yet, so don't |
| 4676 | // try to change it on the way out. |
| 4677 | if (!is_secondary_thread) |
| 4678 | m_public_run_lock.SetStopped(); |
Greg Clayton | 6ed9594 | 2011-01-22 07:12:45 +0000 | [diff] [blame] | 4679 | m_private_state_control_wait.SetValue (true, eBroadcastAlways); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 4680 | m_private_state_thread.Reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4681 | return NULL; |
| 4682 | } |
| 4683 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4684 | //------------------------------------------------------------------ |
| 4685 | // Process Event Data |
| 4686 | //------------------------------------------------------------------ |
| 4687 | |
| 4688 | Process::ProcessEventData::ProcessEventData () : |
| 4689 | EventData (), |
Greg Clayton | aeb3b8b | 2015-05-29 03:20:37 +0000 | [diff] [blame] | 4690 | m_process_wp (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4691 | m_state (eStateInvalid), |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 4692 | m_restarted (false), |
Jim Ingham | a860469 | 2011-05-22 21:45:01 +0000 | [diff] [blame] | 4693 | m_update_state (0), |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4694 | m_interrupted (false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4695 | { |
| 4696 | } |
| 4697 | |
| 4698 | Process::ProcessEventData::ProcessEventData (const ProcessSP &process_sp, StateType state) : |
| 4699 | EventData (), |
Greg Clayton | aeb3b8b | 2015-05-29 03:20:37 +0000 | [diff] [blame] | 4700 | m_process_wp (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4701 | m_state (state), |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 4702 | m_restarted (false), |
Jim Ingham | a860469 | 2011-05-22 21:45:01 +0000 | [diff] [blame] | 4703 | m_update_state (0), |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4704 | m_interrupted (false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4705 | { |
Greg Clayton | aeb3b8b | 2015-05-29 03:20:37 +0000 | [diff] [blame] | 4706 | if (process_sp) |
| 4707 | m_process_wp = process_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
| 4710 | Process::ProcessEventData::~ProcessEventData() |
| 4711 | { |
| 4712 | } |
| 4713 | |
| 4714 | const ConstString & |
| 4715 | Process::ProcessEventData::GetFlavorString () |
| 4716 | { |
| 4717 | static ConstString g_flavor ("Process::ProcessEventData"); |
| 4718 | return g_flavor; |
| 4719 | } |
| 4720 | |
| 4721 | const ConstString & |
| 4722 | Process::ProcessEventData::GetFlavor () const |
| 4723 | { |
| 4724 | return ProcessEventData::GetFlavorString (); |
| 4725 | } |
| 4726 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4727 | void |
| 4728 | Process::ProcessEventData::DoOnRemoval (Event *event_ptr) |
| 4729 | { |
Greg Clayton | aeb3b8b | 2015-05-29 03:20:37 +0000 | [diff] [blame] | 4730 | ProcessSP process_sp(m_process_wp.lock()); |
| 4731 | |
| 4732 | if (!process_sp) |
| 4733 | return; |
| 4734 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4735 | // 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] | 4736 | // off of the private process event queue, and then any number of times, first when it gets pulled off of |
| 4737 | // the public event queue, then other times when we're pretending that this is where we stopped at the |
| 4738 | // end of expression evaluation. m_update_state is used to distinguish these |
| 4739 | // 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] | 4740 | // 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] | 4741 | if (m_update_state != 1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4742 | return; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4743 | |
Greg Clayton | aeb3b8b | 2015-05-29 03:20:37 +0000 | [diff] [blame] | 4744 | process_sp->SetPublicState (m_state, Process::ProcessEventData::GetRestartedFromEvent(event_ptr)); |
Jim Ingham | 35878c4 | 2014-04-08 21:33:21 +0000 | [diff] [blame] | 4745 | |
| 4746 | // If this is a halt event, even if the halt stopped with some reason other than a plain interrupt (e.g. we had |
| 4747 | // already stopped for a breakpoint when the halt request came through) don't do the StopInfo actions, as they may |
| 4748 | // end up restarting the process. |
| 4749 | if (m_interrupted) |
| 4750 | return; |
| 4751 | |
| 4752 | // 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] | 4753 | if (m_state == eStateStopped && ! m_restarted) |
Greg Clayton | 2e30907 | 2015-07-17 23:42:28 +0000 | [diff] [blame] | 4754 | { |
| 4755 | // Let process subclasses know we are about to do a public stop and |
| 4756 | // do anything they might need to in order to speed up register and |
| 4757 | // memory accesses. |
| 4758 | process_sp->WillPublicStop(); |
| 4759 | |
Greg Clayton | aeb3b8b | 2015-05-29 03:20:37 +0000 | [diff] [blame] | 4760 | ThreadList &curr_thread_list = process_sp->GetThreadList(); |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 4761 | uint32_t num_threads = curr_thread_list.GetSize(); |
| 4762 | uint32_t idx; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 4763 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4764 | // The actions might change one of the thread's stop_info's opinions about whether we should |
| 4765 | // stop the process, so we need to query that as we go. |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 4766 | |
| 4767 | // One other complication here, is that we try to catch any case where the target has run (except for expressions) |
| 4768 | // and immediately exit, but if we get that wrong (which is possible) then the thread list might have changed, and |
| 4769 | // that would cause our iteration here to crash. We could make a copy of the thread list, but we'd really like |
| 4770 | // 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 |
| 4771 | // against this list & bag out if anything differs. |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 4772 | std::vector<uint32_t> thread_index_array(num_threads); |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 4773 | for (idx = 0; idx < num_threads; ++idx) |
| 4774 | thread_index_array[idx] = curr_thread_list.GetThreadAtIndex(idx)->GetIndexID(); |
| 4775 | |
Jim Ingham | c7078c2 | 2012-12-13 22:24:15 +0000 | [diff] [blame] | 4776 | // Use this to track whether we should continue from here. We will only continue the target running if |
| 4777 | // no thread says we should stop. Of course if some thread's PerformAction actually sets the target running, |
| 4778 | // then it doesn't matter what the other threads say... |
| 4779 | |
| 4780 | bool still_should_stop = false; |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4781 | |
Jim Ingham | 0ad7e05 | 2013-04-25 02:04:59 +0000 | [diff] [blame] | 4782 | // Sometimes - for instance if we have a bug in the stub we are talking to, we stop but no thread has a |
| 4783 | // valid stop reason. In that case we should just stop, because we have no way of telling what the right |
| 4784 | // thing to do is, and it's better to let the user decide than continue behind their backs. |
| 4785 | |
| 4786 | bool does_anybody_have_an_opinion = false; |
| 4787 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4788 | for (idx = 0; idx < num_threads; ++idx) |
| 4789 | { |
Greg Clayton | aeb3b8b | 2015-05-29 03:20:37 +0000 | [diff] [blame] | 4790 | curr_thread_list = process_sp->GetThreadList(); |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 4791 | if (curr_thread_list.GetSize() != num_threads) |
| 4792 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4793 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 87c665f | 2011-12-01 20:26:15 +0000 | [diff] [blame] | 4794 | if (log) |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 4795 | 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] | 4796 | break; |
| 4797 | } |
| 4798 | |
| 4799 | lldb::ThreadSP thread_sp = curr_thread_list.GetThreadAtIndex(idx); |
| 4800 | |
| 4801 | if (thread_sp->GetIndexID() != thread_index_array[idx]) |
| 4802 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 4803 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 87c665f | 2011-12-01 20:26:15 +0000 | [diff] [blame] | 4804 | if (log) |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 4805 | 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] | 4806 | idx, |
| 4807 | thread_index_array[idx], |
| 4808 | thread_sp->GetIndexID()); |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 4809 | break; |
| 4810 | } |
| 4811 | |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 4812 | StopInfoSP stop_info_sp = thread_sp->GetStopInfo (); |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 4813 | if (stop_info_sp && stop_info_sp->IsValid()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4814 | { |
Jim Ingham | 0ad7e05 | 2013-04-25 02:04:59 +0000 | [diff] [blame] | 4815 | does_anybody_have_an_opinion = true; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4816 | bool this_thread_wants_to_stop; |
| 4817 | if (stop_info_sp->GetOverrideShouldStop()) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4818 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4819 | this_thread_wants_to_stop = stop_info_sp->GetOverriddenShouldStopValue(); |
| 4820 | } |
| 4821 | else |
| 4822 | { |
| 4823 | stop_info_sp->PerformAction(event_ptr); |
| 4824 | // The stop action might restart the target. If it does, then we want to mark that in the |
| 4825 | // event so that whoever is receiving it will know to wait for the running event and reflect |
| 4826 | // that state appropriately. |
| 4827 | // We also need to stop processing actions, since they aren't expecting the target to be running. |
| 4828 | |
| 4829 | // FIXME: we might have run. |
| 4830 | if (stop_info_sp->HasTargetRunSinceMe()) |
| 4831 | { |
| 4832 | SetRestarted (true); |
| 4833 | break; |
| 4834 | } |
| 4835 | |
| 4836 | this_thread_wants_to_stop = stop_info_sp->ShouldStop(event_ptr); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4837 | } |
Jim Ingham | c7078c2 | 2012-12-13 22:24:15 +0000 | [diff] [blame] | 4838 | |
Jim Ingham | c7078c2 | 2012-12-13 22:24:15 +0000 | [diff] [blame] | 4839 | if (still_should_stop == false) |
| 4840 | still_should_stop = this_thread_wants_to_stop; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4841 | } |
| 4842 | } |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 4843 | |
Ashok Thirumurthi | cf7c55e | 2013-04-18 14:38:20 +0000 | [diff] [blame] | 4844 | |
Jim Ingham | a8ca6e2 | 2013-05-03 23:04:37 +0000 | [diff] [blame] | 4845 | if (!GetRestarted()) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4846 | { |
Jim Ingham | 0ad7e05 | 2013-04-25 02:04:59 +0000 | [diff] [blame] | 4847 | if (!still_should_stop && does_anybody_have_an_opinion) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4848 | { |
| 4849 | // We've been asked to continue, so do that here. |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4850 | SetRestarted(true); |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 4851 | // Use the public resume method here, since this is just |
| 4852 | // extending a public resume. |
Greg Clayton | aeb3b8b | 2015-05-29 03:20:37 +0000 | [diff] [blame] | 4853 | process_sp->PrivateResume(); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4854 | } |
| 4855 | else |
| 4856 | { |
| 4857 | // If we didn't restart, run the Stop Hooks here: |
| 4858 | // They might also restart the target, so watch for that. |
Greg Clayton | aeb3b8b | 2015-05-29 03:20:37 +0000 | [diff] [blame] | 4859 | process_sp->GetTarget().RunStopHooks(); |
| 4860 | if (process_sp->GetPrivateState() == eStateRunning) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4861 | SetRestarted(true); |
| 4862 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 4863 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4864 | } |
| 4865 | } |
| 4866 | |
| 4867 | void |
| 4868 | Process::ProcessEventData::Dump (Stream *s) const |
| 4869 | { |
Greg Clayton | aeb3b8b | 2015-05-29 03:20:37 +0000 | [diff] [blame] | 4870 | ProcessSP process_sp(m_process_wp.lock()); |
| 4871 | |
| 4872 | if (process_sp) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 4873 | s->Printf(" process = %p (pid = %" PRIu64 "), ", |
Greg Clayton | aeb3b8b | 2015-05-29 03:20:37 +0000 | [diff] [blame] | 4874 | static_cast<void*>(process_sp.get()), process_sp->GetID()); |
| 4875 | else |
| 4876 | s->PutCString(" process = NULL, "); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4877 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 4878 | s->Printf("state = %s", StateAsCString(GetState())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | const Process::ProcessEventData * |
| 4882 | Process::ProcessEventData::GetEventDataFromEvent (const Event *event_ptr) |
| 4883 | { |
| 4884 | if (event_ptr) |
| 4885 | { |
| 4886 | const EventData *event_data = event_ptr->GetData(); |
| 4887 | if (event_data && event_data->GetFlavor() == ProcessEventData::GetFlavorString()) |
| 4888 | return static_cast <const ProcessEventData *> (event_ptr->GetData()); |
| 4889 | } |
| 4890 | return NULL; |
| 4891 | } |
| 4892 | |
| 4893 | ProcessSP |
| 4894 | Process::ProcessEventData::GetProcessFromEvent (const Event *event_ptr) |
| 4895 | { |
| 4896 | ProcessSP process_sp; |
| 4897 | const ProcessEventData *data = GetEventDataFromEvent (event_ptr); |
| 4898 | if (data) |
| 4899 | process_sp = data->GetProcessSP(); |
| 4900 | return process_sp; |
| 4901 | } |
| 4902 | |
| 4903 | StateType |
| 4904 | Process::ProcessEventData::GetStateFromEvent (const Event *event_ptr) |
| 4905 | { |
| 4906 | const ProcessEventData *data = GetEventDataFromEvent (event_ptr); |
| 4907 | if (data == NULL) |
| 4908 | return eStateInvalid; |
| 4909 | else |
| 4910 | return data->GetState(); |
| 4911 | } |
| 4912 | |
| 4913 | bool |
| 4914 | Process::ProcessEventData::GetRestartedFromEvent (const Event *event_ptr) |
| 4915 | { |
| 4916 | const ProcessEventData *data = GetEventDataFromEvent (event_ptr); |
| 4917 | if (data == NULL) |
| 4918 | return false; |
| 4919 | else |
| 4920 | return data->GetRestarted(); |
| 4921 | } |
| 4922 | |
| 4923 | void |
| 4924 | Process::ProcessEventData::SetRestartedInEvent (Event *event_ptr, bool new_value) |
| 4925 | { |
| 4926 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 4927 | if (data != NULL) |
| 4928 | data->SetRestarted(new_value); |
| 4929 | } |
| 4930 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 4931 | size_t |
| 4932 | Process::ProcessEventData::GetNumRestartedReasons(const Event *event_ptr) |
| 4933 | { |
| 4934 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 4935 | if (data != NULL) |
| 4936 | return data->GetNumRestartedReasons(); |
| 4937 | else |
| 4938 | return 0; |
| 4939 | } |
| 4940 | |
| 4941 | const char * |
| 4942 | Process::ProcessEventData::GetRestartedReasonAtIndex(const Event *event_ptr, size_t idx) |
| 4943 | { |
| 4944 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 4945 | if (data != NULL) |
| 4946 | return data->GetRestartedReasonAtIndex(idx); |
| 4947 | else |
| 4948 | return NULL; |
| 4949 | } |
| 4950 | |
| 4951 | void |
| 4952 | Process::ProcessEventData::AddRestartedReason (Event *event_ptr, const char *reason) |
| 4953 | { |
| 4954 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 4955 | if (data != NULL) |
| 4956 | data->AddRestartedReason(reason); |
| 4957 | } |
| 4958 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4959 | bool |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 4960 | Process::ProcessEventData::GetInterruptedFromEvent (const Event *event_ptr) |
| 4961 | { |
| 4962 | const ProcessEventData *data = GetEventDataFromEvent (event_ptr); |
| 4963 | if (data == NULL) |
| 4964 | return false; |
| 4965 | else |
| 4966 | return data->GetInterrupted (); |
| 4967 | } |
| 4968 | |
| 4969 | void |
| 4970 | Process::ProcessEventData::SetInterruptedInEvent (Event *event_ptr, bool new_value) |
| 4971 | { |
| 4972 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 4973 | if (data != NULL) |
| 4974 | data->SetInterrupted(new_value); |
| 4975 | } |
| 4976 | |
| 4977 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4978 | Process::ProcessEventData::SetUpdateStateOnRemoval (Event *event_ptr) |
| 4979 | { |
| 4980 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 4981 | if (data) |
| 4982 | { |
| 4983 | data->SetUpdateStateOnRemoval(); |
| 4984 | return true; |
| 4985 | } |
| 4986 | return false; |
| 4987 | } |
| 4988 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 4989 | lldb::TargetSP |
| 4990 | Process::CalculateTarget () |
| 4991 | { |
| 4992 | return m_target.shared_from_this(); |
| 4993 | } |
| 4994 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4995 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 4996 | Process::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4997 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4998 | exe_ctx.SetTargetPtr (&m_target); |
| 4999 | exe_ctx.SetProcessPtr (this); |
| 5000 | exe_ctx.SetThreadPtr(NULL); |
| 5001 | exe_ctx.SetFramePtr (NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5002 | } |
| 5003 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 5004 | //uint32_t |
| 5005 | //Process::ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids) |
| 5006 | //{ |
| 5007 | // return 0; |
| 5008 | //} |
| 5009 | // |
| 5010 | //ArchSpec |
| 5011 | //Process::GetArchSpecForExistingProcess (lldb::pid_t pid) |
| 5012 | //{ |
| 5013 | // return Host::GetArchSpecForExistingProcess (pid); |
| 5014 | //} |
| 5015 | // |
| 5016 | //ArchSpec |
| 5017 | //Process::GetArchSpecForExistingProcess (const char *process_name) |
| 5018 | //{ |
| 5019 | // return Host::GetArchSpecForExistingProcess (process_name); |
| 5020 | //} |
| 5021 | // |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 5022 | void |
| 5023 | Process::AppendSTDOUT (const char * s, size_t len) |
| 5024 | { |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 5025 | Mutex::Locker locker (m_stdio_communication_mutex); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 5026 | m_stdout_data.append (s, len); |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 5027 | BroadcastEventIfUnique (eBroadcastBitSTDOUT, new ProcessEventData (shared_from_this(), GetState())); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 5028 | } |
| 5029 | |
| 5030 | void |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 5031 | Process::AppendSTDERR (const char * s, size_t len) |
| 5032 | { |
| 5033 | Mutex::Locker locker (m_stdio_communication_mutex); |
| 5034 | m_stderr_data.append (s, len); |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 5035 | BroadcastEventIfUnique (eBroadcastBitSTDERR, new ProcessEventData (shared_from_this(), GetState())); |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 5036 | } |
| 5037 | |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 5038 | void |
Han Ming Ong | 91ed6b8 | 2013-06-24 18:15:05 +0000 | [diff] [blame] | 5039 | Process::BroadcastAsyncProfileData(const std::string &one_profile_data) |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 5040 | { |
| 5041 | Mutex::Locker locker (m_profile_data_comm_mutex); |
Han Ming Ong | 91ed6b8 | 2013-06-24 18:15:05 +0000 | [diff] [blame] | 5042 | m_profile_data.push_back(one_profile_data); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 5043 | BroadcastEventIfUnique (eBroadcastBitProfileData, new ProcessEventData (shared_from_this(), GetState())); |
| 5044 | } |
| 5045 | |
| 5046 | size_t |
| 5047 | Process::GetAsyncProfileData (char *buf, size_t buf_size, Error &error) |
| 5048 | { |
| 5049 | Mutex::Locker locker(m_profile_data_comm_mutex); |
Han Ming Ong | 929a94f | 2012-11-29 22:14:45 +0000 | [diff] [blame] | 5050 | if (m_profile_data.empty()) |
| 5051 | return 0; |
Han Ming Ong | 91ed6b8 | 2013-06-24 18:15:05 +0000 | [diff] [blame] | 5052 | |
| 5053 | std::string &one_profile_data = m_profile_data.front(); |
| 5054 | size_t bytes_available = one_profile_data.size(); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 5055 | if (bytes_available > 0) |
| 5056 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5057 | Log *log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 5058 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5059 | log->Printf ("Process::GetProfileData (buf = %p, size = %" PRIu64 ")", |
| 5060 | static_cast<void*>(buf), |
| 5061 | static_cast<uint64_t>(buf_size)); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 5062 | if (bytes_available > buf_size) |
| 5063 | { |
Han Ming Ong | 91ed6b8 | 2013-06-24 18:15:05 +0000 | [diff] [blame] | 5064 | memcpy(buf, one_profile_data.c_str(), buf_size); |
| 5065 | one_profile_data.erase(0, buf_size); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 5066 | bytes_available = buf_size; |
| 5067 | } |
| 5068 | else |
| 5069 | { |
Han Ming Ong | 91ed6b8 | 2013-06-24 18:15:05 +0000 | [diff] [blame] | 5070 | memcpy(buf, one_profile_data.c_str(), bytes_available); |
Han Ming Ong | 929a94f | 2012-11-29 22:14:45 +0000 | [diff] [blame] | 5071 | m_profile_data.erase(m_profile_data.begin()); |
Han Ming Ong | ab3b8b2 | 2012-11-17 00:21:04 +0000 | [diff] [blame] | 5072 | } |
| 5073 | } |
| 5074 | return bytes_available; |
| 5075 | } |
| 5076 | |
| 5077 | |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 5078 | //------------------------------------------------------------------ |
| 5079 | // Process STDIO |
| 5080 | //------------------------------------------------------------------ |
| 5081 | |
| 5082 | size_t |
| 5083 | Process::GetSTDOUT (char *buf, size_t buf_size, Error &error) |
| 5084 | { |
| 5085 | Mutex::Locker locker(m_stdio_communication_mutex); |
| 5086 | size_t bytes_available = m_stdout_data.size(); |
| 5087 | if (bytes_available > 0) |
| 5088 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5089 | Log *log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 5090 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5091 | log->Printf ("Process::GetSTDOUT (buf = %p, size = %" PRIu64 ")", |
| 5092 | static_cast<void*>(buf), |
| 5093 | static_cast<uint64_t>(buf_size)); |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 5094 | if (bytes_available > buf_size) |
| 5095 | { |
| 5096 | memcpy(buf, m_stdout_data.c_str(), buf_size); |
| 5097 | m_stdout_data.erase(0, buf_size); |
| 5098 | bytes_available = buf_size; |
| 5099 | } |
| 5100 | else |
| 5101 | { |
| 5102 | memcpy(buf, m_stdout_data.c_str(), bytes_available); |
| 5103 | m_stdout_data.clear(); |
| 5104 | } |
| 5105 | } |
| 5106 | return bytes_available; |
| 5107 | } |
| 5108 | |
| 5109 | |
| 5110 | size_t |
| 5111 | Process::GetSTDERR (char *buf, size_t buf_size, Error &error) |
| 5112 | { |
| 5113 | Mutex::Locker locker(m_stdio_communication_mutex); |
| 5114 | size_t bytes_available = m_stderr_data.size(); |
| 5115 | if (bytes_available > 0) |
| 5116 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5117 | Log *log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 5118 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5119 | log->Printf ("Process::GetSTDERR (buf = %p, size = %" PRIu64 ")", |
| 5120 | static_cast<void*>(buf), |
| 5121 | static_cast<uint64_t>(buf_size)); |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 5122 | if (bytes_available > buf_size) |
| 5123 | { |
| 5124 | memcpy(buf, m_stderr_data.c_str(), buf_size); |
| 5125 | m_stderr_data.erase(0, buf_size); |
| 5126 | bytes_available = buf_size; |
| 5127 | } |
| 5128 | else |
| 5129 | { |
| 5130 | memcpy(buf, m_stderr_data.c_str(), bytes_available); |
| 5131 | m_stderr_data.clear(); |
| 5132 | } |
| 5133 | } |
| 5134 | return bytes_available; |
| 5135 | } |
| 5136 | |
| 5137 | void |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 5138 | Process::STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len) |
| 5139 | { |
| 5140 | Process *process = (Process *) baton; |
| 5141 | process->AppendSTDOUT (static_cast<const char *>(src), src_len); |
| 5142 | } |
| 5143 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5144 | class IOHandlerProcessSTDIO : |
| 5145 | public IOHandler |
| 5146 | { |
| 5147 | public: |
| 5148 | IOHandlerProcessSTDIO (Process *process, |
| 5149 | int write_fd) : |
Kate Stone | e30f11d | 2014-11-17 19:06:59 +0000 | [diff] [blame] | 5150 | IOHandler(process->GetTarget().GetDebugger(), IOHandler::Type::ProcessIO), |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5151 | m_process (process), |
| 5152 | m_read_file (), |
| 5153 | m_write_file (write_fd, false), |
Greg Clayton | 100eb93 | 2014-07-02 21:10:39 +0000 | [diff] [blame] | 5154 | m_pipe () |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5155 | { |
Pavel Labath | fb7d5b8 | 2015-05-28 13:41:08 +0000 | [diff] [blame] | 5156 | m_pipe.CreateNew(false); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5157 | m_read_file.SetDescriptor(GetInputFD(), false); |
| 5158 | } |
| 5159 | |
| 5160 | virtual |
| 5161 | ~IOHandlerProcessSTDIO () |
| 5162 | { |
| 5163 | |
| 5164 | } |
| 5165 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5166 | // Each IOHandler gets to run until it is done. It should read data |
| 5167 | // from the "in" and place output into "out" and "err and return |
| 5168 | // when done. |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 5169 | void |
| 5170 | Run () override |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5171 | { |
Pavel Labath | fb7d5b8 | 2015-05-28 13:41:08 +0000 | [diff] [blame] | 5172 | if (!m_read_file.IsValid() || !m_write_file.IsValid() || !m_pipe.CanRead() || !m_pipe.CanWrite()) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5173 | { |
Pavel Labath | fb7d5b8 | 2015-05-28 13:41:08 +0000 | [diff] [blame] | 5174 | SetIsDone(true); |
| 5175 | return; |
| 5176 | } |
| 5177 | |
| 5178 | SetIsDone(false); |
| 5179 | const int read_fd = m_read_file.GetDescriptor(); |
| 5180 | TerminalState terminal_state; |
| 5181 | terminal_state.Save (read_fd, false); |
| 5182 | Terminal terminal(read_fd); |
| 5183 | terminal.SetCanonical(false); |
| 5184 | terminal.SetEcho(false); |
Deepak Panickal | 914b8d9 | 2014-01-31 18:48:46 +0000 | [diff] [blame] | 5185 | // FD_ZERO, FD_SET are not supported on windows |
Hafiz Abid Qadeer | 6eff101 | 2014-03-12 10:45:23 +0000 | [diff] [blame] | 5186 | #ifndef _WIN32 |
Pavel Labath | fb7d5b8 | 2015-05-28 13:41:08 +0000 | [diff] [blame] | 5187 | const int pipe_read_fd = m_pipe.GetReadFileDescriptor(); |
| 5188 | while (!GetIsDone()) |
| 5189 | { |
| 5190 | fd_set read_fdset; |
| 5191 | FD_ZERO (&read_fdset); |
| 5192 | FD_SET (read_fd, &read_fdset); |
| 5193 | FD_SET (pipe_read_fd, &read_fdset); |
| 5194 | const int nfds = std::max<int>(read_fd, pipe_read_fd) + 1; |
| 5195 | int num_set_fds = select (nfds, &read_fdset, NULL, NULL, NULL); |
| 5196 | if (num_set_fds < 0) |
| 5197 | { |
| 5198 | const int select_errno = errno; |
| 5199 | |
| 5200 | if (select_errno != EINTR) |
| 5201 | SetIsDone(true); |
| 5202 | } |
| 5203 | else if (num_set_fds > 0) |
| 5204 | { |
| 5205 | char ch = 0; |
| 5206 | size_t n; |
| 5207 | if (FD_ISSET (read_fd, &read_fdset)) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5208 | { |
Pavel Labath | fb7d5b8 | 2015-05-28 13:41:08 +0000 | [diff] [blame] | 5209 | n = 1; |
| 5210 | if (m_read_file.Read(&ch, n).Success() && n == 1) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5211 | { |
Pavel Labath | fb7d5b8 | 2015-05-28 13:41:08 +0000 | [diff] [blame] | 5212 | if (m_write_file.Write(&ch, n).Fail() || n != 1) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5213 | SetIsDone(true); |
| 5214 | } |
Pavel Labath | fb7d5b8 | 2015-05-28 13:41:08 +0000 | [diff] [blame] | 5215 | else |
| 5216 | SetIsDone(true); |
| 5217 | } |
| 5218 | if (FD_ISSET (pipe_read_fd, &read_fdset)) |
| 5219 | { |
| 5220 | size_t bytes_read; |
| 5221 | // Consume the interrupt byte |
| 5222 | Error error = m_pipe.Read(&ch, 1, bytes_read); |
| 5223 | if (error.Success()) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5224 | { |
Pavel Labath | fb7d5b8 | 2015-05-28 13:41:08 +0000 | [diff] [blame] | 5225 | switch (ch) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5226 | { |
Pavel Labath | fb7d5b8 | 2015-05-28 13:41:08 +0000 | [diff] [blame] | 5227 | case 'q': |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5228 | SetIsDone(true); |
Pavel Labath | fb7d5b8 | 2015-05-28 13:41:08 +0000 | [diff] [blame] | 5229 | break; |
| 5230 | case 'i': |
| 5231 | if (StateIsRunningState(m_process->GetState())) |
| 5232 | m_process->Halt(); |
| 5233 | break; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5234 | } |
| 5235 | } |
| 5236 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5237 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5238 | } |
Pavel Labath | fb7d5b8 | 2015-05-28 13:41:08 +0000 | [diff] [blame] | 5239 | #endif |
| 5240 | terminal_state.Restore(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5241 | } |
| 5242 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 5243 | void |
| 5244 | Cancel () override |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5245 | { |
Greg Clayton | 19e1135 | 2014-02-26 22:47:33 +0000 | [diff] [blame] | 5246 | char ch = 'q'; // Send 'q' for quit |
Zachary Turner | 0b9d3ee | 2014-12-17 18:02:19 +0000 | [diff] [blame] | 5247 | size_t bytes_written = 0; |
| 5248 | m_pipe.Write(&ch, 1, bytes_written); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5249 | } |
Greg Clayton | e68f5d6 | 2014-02-24 22:50:57 +0000 | [diff] [blame] | 5250 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 5251 | bool |
| 5252 | Interrupt () override |
Greg Clayton | e68f5d6 | 2014-02-24 22:50:57 +0000 | [diff] [blame] | 5253 | { |
Greg Clayton | 19e1135 | 2014-02-26 22:47:33 +0000 | [diff] [blame] | 5254 | // Do only things that are safe to do in an interrupt context (like in |
| 5255 | // a SIGINT handler), like write 1 byte to a file descriptor. This will |
| 5256 | // interrupt the IOHandlerProcessSTDIO::Run() and we can look at the byte |
| 5257 | // that was written to the pipe and then call m_process->Halt() from a |
| 5258 | // much safer location in code. |
Greg Clayton | 0fdd3ae | 2014-07-16 21:05:41 +0000 | [diff] [blame] | 5259 | if (m_active) |
| 5260 | { |
| 5261 | char ch = 'i'; // Send 'i' for interrupt |
Zachary Turner | 0b9d3ee | 2014-12-17 18:02:19 +0000 | [diff] [blame] | 5262 | size_t bytes_written = 0; |
| 5263 | Error result = m_pipe.Write(&ch, 1, bytes_written); |
| 5264 | return result.Success(); |
Greg Clayton | 0fdd3ae | 2014-07-16 21:05:41 +0000 | [diff] [blame] | 5265 | } |
| 5266 | else |
| 5267 | { |
| 5268 | // This IOHandler might be pushed on the stack, but not being run currently |
| 5269 | // so do the right thing if we aren't actively watching for STDIN by sending |
| 5270 | // the interrupt to the process. Otherwise the write to the pipe above would |
| 5271 | // do nothing. This can happen when the command interpreter is running and |
| 5272 | // gets a "expression ...". It will be on the IOHandler thread and sending |
| 5273 | // the input is complete to the delegate which will cause the expression to |
| 5274 | // run, which will push the process IO handler, but not run it. |
| 5275 | |
| 5276 | if (StateIsRunningState(m_process->GetState())) |
| 5277 | { |
| 5278 | m_process->SendAsyncInterrupt(); |
| 5279 | return true; |
| 5280 | } |
| 5281 | } |
| 5282 | return false; |
Greg Clayton | e68f5d6 | 2014-02-24 22:50:57 +0000 | [diff] [blame] | 5283 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5284 | |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 5285 | void |
| 5286 | GotEOF() override |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5287 | { |
| 5288 | |
| 5289 | } |
| 5290 | |
| 5291 | protected: |
| 5292 | Process *m_process; |
| 5293 | File m_read_file; // Read from this file (usually actual STDIN for LLDB |
| 5294 | 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] | 5295 | Pipe m_pipe; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5296 | }; |
| 5297 | |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 5298 | void |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5299 | Process::SetSTDIOFileDescriptor (int fd) |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 5300 | { |
| 5301 | // First set up the Read Thread for reading/handling process I/O |
| 5302 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5303 | std::unique_ptr<ConnectionFileDescriptor> conn_ap (new ConnectionFileDescriptor (fd, true)); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 5304 | |
| 5305 | if (conn_ap.get()) |
| 5306 | { |
| 5307 | m_stdio_communication.SetConnection (conn_ap.release()); |
| 5308 | if (m_stdio_communication.IsConnected()) |
| 5309 | { |
| 5310 | m_stdio_communication.SetReadThreadBytesReceivedCallback (STDIOReadThreadBytesReceived, this); |
| 5311 | m_stdio_communication.StartReadThread(); |
| 5312 | |
| 5313 | // Now read thread is set up, set up input reader. |
| 5314 | |
| 5315 | if (!m_process_input_reader.get()) |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5316 | m_process_input_reader.reset (new IOHandlerProcessSTDIO (this, fd)); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 5317 | } |
| 5318 | } |
| 5319 | } |
| 5320 | |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 5321 | bool |
Greg Clayton | 6fea17e | 2014-03-03 19:15:20 +0000 | [diff] [blame] | 5322 | Process::ProcessIOHandlerIsActive () |
| 5323 | { |
| 5324 | IOHandlerSP io_handler_sp (m_process_input_reader); |
| 5325 | if (io_handler_sp) |
| 5326 | return m_target.GetDebugger().IsTopIOHandler (io_handler_sp); |
| 5327 | return false; |
| 5328 | } |
| 5329 | bool |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5330 | Process::PushProcessIOHandler () |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 5331 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5332 | IOHandlerSP io_handler_sp (m_process_input_reader); |
| 5333 | if (io_handler_sp) |
| 5334 | { |
Pavel Labath | 4446487 | 2015-05-27 12:40:32 +0000 | [diff] [blame] | 5335 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 5336 | if (log) |
| 5337 | log->Printf("Process::%s pushing IO handler", __FUNCTION__); |
| 5338 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5339 | io_handler_sp->SetIsDone(false); |
| 5340 | m_target.GetDebugger().PushIOHandler (io_handler_sp); |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 5341 | return true; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5342 | } |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 5343 | return false; |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 5344 | } |
| 5345 | |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 5346 | bool |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5347 | Process::PopProcessIOHandler () |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 5348 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 5349 | IOHandlerSP io_handler_sp (m_process_input_reader); |
| 5350 | if (io_handler_sp) |
Greg Clayton | b4874f1 | 2014-02-28 18:22:24 +0000 | [diff] [blame] | 5351 | return m_target.GetDebugger().PopIOHandler (io_handler_sp); |
| 5352 | return false; |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 5353 | } |
| 5354 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 5355 | // The process needs to know about installed plug-ins |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 5356 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 5357 | Process::SettingsInitialize () |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 5358 | { |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 5359 | Thread::SettingsInitialize (); |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 5360 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 5361 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 5362 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 5363 | Process::SettingsTerminate () |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 5364 | { |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 5365 | Thread::SettingsTerminate (); |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 5366 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 5367 | |
Jim Ingham | 1624a2d | 2014-05-05 02:26:40 +0000 | [diff] [blame] | 5368 | ExpressionResults |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5369 | Process::RunThreadPlan (ExecutionContext &exe_ctx, |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 5370 | lldb::ThreadPlanSP &thread_plan_sp, |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5371 | const EvaluateExpressionOptions &options, |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5372 | Stream &errors) |
| 5373 | { |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5374 | ExpressionResults return_value = eExpressionSetupError; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5375 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 5376 | if (thread_plan_sp.get() == NULL) |
| 5377 | { |
| 5378 | errors.Printf("RunThreadPlan called with empty thread plan."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5379 | return eExpressionSetupError; |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 5380 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5381 | |
Jim Ingham | 7d7931d | 2013-03-28 00:05:34 +0000 | [diff] [blame] | 5382 | if (!thread_plan_sp->ValidatePlan(NULL)) |
| 5383 | { |
| 5384 | errors.Printf ("RunThreadPlan called with an invalid thread plan."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5385 | return eExpressionSetupError; |
Jim Ingham | 7d7931d | 2013-03-28 00:05:34 +0000 | [diff] [blame] | 5386 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5387 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 5388 | if (exe_ctx.GetProcessPtr() != this) |
| 5389 | { |
| 5390 | errors.Printf("RunThreadPlan called on wrong process."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5391 | return eExpressionSetupError; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 5392 | } |
| 5393 | |
| 5394 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 5395 | if (thread == NULL) |
| 5396 | { |
| 5397 | errors.Printf("RunThreadPlan called with invalid thread."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5398 | return eExpressionSetupError; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 5399 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5400 | |
Jim Ingham | 17e5c4e | 2011-05-17 22:24:54 +0000 | [diff] [blame] | 5401 | // We rely on the thread plan we are running returning "PlanCompleted" if when it successfully completes. |
| 5402 | // For that to be true the plan can't be private - since private plans suppress themselves in the |
| 5403 | // GetCompletedPlan call. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5404 | |
Jim Ingham | 17e5c4e | 2011-05-17 22:24:54 +0000 | [diff] [blame] | 5405 | bool orig_plan_private = thread_plan_sp->GetPrivate(); |
| 5406 | thread_plan_sp->SetPrivate(false); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5407 | |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 5408 | if (m_private_state.GetValue() != eStateStopped) |
| 5409 | { |
| 5410 | errors.Printf ("RunThreadPlan called while the private state was not stopped."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5411 | return eExpressionSetupError; |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 5412 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5413 | |
Jim Ingham | 6624384 | 2011-08-13 00:56:10 +0000 | [diff] [blame] | 5414 | // 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] | 5415 | const uint32_t thread_idx_id = thread->GetIndexID(); |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 5416 | StackFrameSP selected_frame_sp = thread->GetSelectedFrame(); |
Jim Ingham | 11b0e05 | 2013-02-19 23:22:45 +0000 | [diff] [blame] | 5417 | if (!selected_frame_sp) |
| 5418 | { |
| 5419 | thread->SetSelectedFrame(0); |
| 5420 | selected_frame_sp = thread->GetSelectedFrame(); |
| 5421 | if (!selected_frame_sp) |
| 5422 | { |
| 5423 | 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] | 5424 | return eExpressionSetupError; |
Jim Ingham | 11b0e05 | 2013-02-19 23:22:45 +0000 | [diff] [blame] | 5425 | } |
| 5426 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5427 | |
Jim Ingham | 11b0e05 | 2013-02-19 23:22:45 +0000 | [diff] [blame] | 5428 | StackID ctx_frame_id = selected_frame_sp->GetStackID(); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5429 | |
| 5430 | // N.B. Running the target may unset the currently selected thread and frame. We don't want to do that either, |
| 5431 | // so we should arrange to reset them as well. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5432 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 5433 | lldb::ThreadSP selected_thread_sp = GetThreadList().GetSelectedThread(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5434 | |
Jim Ingham | 6624384 | 2011-08-13 00:56:10 +0000 | [diff] [blame] | 5435 | uint32_t selected_tid; |
| 5436 | StackID selected_stack_id; |
Greg Clayton | 762f713 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 5437 | if (selected_thread_sp) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5438 | { |
| 5439 | selected_tid = selected_thread_sp->GetIndexID(); |
Jim Ingham | 6624384 | 2011-08-13 00:56:10 +0000 | [diff] [blame] | 5440 | selected_stack_id = selected_thread_sp->GetSelectedFrame()->GetStackID(); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5441 | } |
| 5442 | else |
| 5443 | { |
| 5444 | selected_tid = LLDB_INVALID_THREAD_ID; |
| 5445 | } |
| 5446 | |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 5447 | HostThread backup_private_state_thread; |
Jason Molenda | 76513fd | 2014-10-15 23:39:31 +0000 | [diff] [blame] | 5448 | lldb::StateType old_state = eStateInvalid; |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 5449 | lldb::ThreadPlanSP stopper_base_plan_sp; |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 5450 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 5451 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS)); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 5452 | if (m_private_state_thread.EqualsThread(Host::GetCurrentThread())) |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 5453 | { |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 5454 | // Yikes, we are running on the private state thread! So we can't wait for public events on this thread, since |
| 5455 | // we are the thread that is generating public events. |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 5456 | // 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] | 5457 | // we are fielding public events here. |
| 5458 | if (log) |
Jason Molenda | d251c9d | 2012-11-17 01:41:04 +0000 | [diff] [blame] | 5459 | 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] | 5460 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 5461 | backup_private_state_thread = m_private_state_thread; |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 5462 | |
| 5463 | // One other bit of business: we want to run just this thread plan and anything it pushes, and then stop, |
| 5464 | // returning control here. |
| 5465 | // But in the normal course of things, the plan above us on the stack would be given a shot at the stop |
| 5466 | // event before deciding to stop, and we don't want that. So we insert a "stopper" base plan on the stack |
| 5467 | // before the plan we want to run. Since base plans always stop and return control to the user, that will |
| 5468 | // do just what we want. |
| 5469 | stopper_base_plan_sp.reset(new ThreadPlanBase (*thread)); |
| 5470 | thread->QueueThreadPlan (stopper_base_plan_sp, false); |
| 5471 | // Have to make sure our public state is stopped, since otherwise the reporting logic below doesn't work correctly. |
| 5472 | old_state = m_public_state.GetValue(); |
| 5473 | m_public_state.SetValueNoLock(eStateStopped); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5474 | |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 5475 | // Now spin up the private state thread: |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 5476 | StartPrivateStateThread(true); |
| 5477 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5478 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 5479 | 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] | 5480 | |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5481 | if (options.GetDebug()) |
| 5482 | { |
| 5483 | // In this case, we aren't actually going to run, we just want to stop right away. |
| 5484 | // Flush this thread so we will refetch the stacks and show the correct backtrace. |
| 5485 | // FIXME: To make this prettier we should invent some stop reason for this, but that |
| 5486 | // is only cosmetic, and this functionality is only of use to lldb developers who can |
| 5487 | // live with not pretty... |
| 5488 | thread->Flush(); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5489 | return eExpressionStoppedForDebug; |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5490 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5491 | |
Jim Ingham | 1e7a9ee | 2011-01-23 21:14:08 +0000 | [diff] [blame] | 5492 | Listener listener("lldb.process.listener.run-thread-plan"); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5493 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5494 | lldb::EventSP event_to_broadcast_sp; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5495 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 5496 | { |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5497 | // This process event hijacker Hijacks the Public events and its destructor makes sure that the process events get |
| 5498 | // restored on exit to the function. |
| 5499 | // |
| 5500 | // If the event needs to propagate beyond the hijacker (e.g., the process exits during execution), then the event |
| 5501 | // is put into event_to_broadcast_sp for rebroadcasting. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5502 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5503 | ProcessEventHijacker run_thread_plan_hijacker (*this, &listener); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5504 | |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 5505 | if (log) |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 5506 | { |
| 5507 | StreamString s; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5508 | thread_plan_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 5509 | 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] | 5510 | thread->GetIndexID(), |
| 5511 | thread->GetID(), |
| 5512 | s.GetData()); |
| 5513 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5514 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5515 | bool got_event; |
| 5516 | lldb::EventSP event_sp; |
| 5517 | lldb::StateType stop_state = lldb::eStateInvalid; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5518 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5519 | TimeValue* timeout_ptr = NULL; |
| 5520 | TimeValue real_timeout; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5521 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5522 | 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] | 5523 | bool do_resume = true; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5524 | bool handle_running_event = true; |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 5525 | const uint64_t default_one_thread_timeout_usec = 250000; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5526 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5527 | // This is just for accounting: |
| 5528 | uint32_t num_resumes = 0; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5529 | |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5530 | uint32_t timeout_usec = options.GetTimeoutUsec(); |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5531 | uint32_t one_thread_timeout_usec; |
| 5532 | uint32_t all_threads_timeout_usec = 0; |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 5533 | |
| 5534 | // If we are going to run all threads the whole time, or if we are only going to run one thread, |
| 5535 | // then we don't need the first timeout. So we set the final timeout, and pretend we are after the |
| 5536 | // first timeout already. |
| 5537 | |
| 5538 | if (!options.GetStopOthers() || !options.GetTryAllThreads()) |
Jim Ingham | 286fb1e | 2014-02-28 02:52:06 +0000 | [diff] [blame] | 5539 | { |
| 5540 | before_first_timeout = false; |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5541 | one_thread_timeout_usec = 0; |
| 5542 | all_threads_timeout_usec = timeout_usec; |
Jim Ingham | 286fb1e | 2014-02-28 02:52:06 +0000 | [diff] [blame] | 5543 | } |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 5544 | else |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5545 | { |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5546 | uint32_t option_one_thread_timeout = options.GetOneThreadTimeoutUsec(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5547 | |
Jim Ingham | 914f4e7 | 2014-03-28 21:58:28 +0000 | [diff] [blame] | 5548 | // If the overall wait is forever, then we only need to set the one thread timeout: |
| 5549 | if (timeout_usec == 0) |
| 5550 | { |
Ed Maste | 801335c | 2014-03-31 19:28:14 +0000 | [diff] [blame] | 5551 | if (option_one_thread_timeout != 0) |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5552 | one_thread_timeout_usec = option_one_thread_timeout; |
Jim Ingham | 914f4e7 | 2014-03-28 21:58:28 +0000 | [diff] [blame] | 5553 | else |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5554 | one_thread_timeout_usec = default_one_thread_timeout_usec; |
Jim Ingham | 914f4e7 | 2014-03-28 21:58:28 +0000 | [diff] [blame] | 5555 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5556 | else |
| 5557 | { |
Jim Ingham | 914f4e7 | 2014-03-28 21:58:28 +0000 | [diff] [blame] | 5558 | // Otherwise, if the one thread timeout is set, make sure it isn't longer than the overall timeout, |
| 5559 | // and use it, otherwise use half the total timeout, bounded by the default_one_thread_timeout_usec. |
| 5560 | uint64_t computed_one_thread_timeout; |
| 5561 | if (option_one_thread_timeout != 0) |
| 5562 | { |
| 5563 | if (timeout_usec < option_one_thread_timeout) |
| 5564 | { |
| 5565 | errors.Printf("RunThreadPlan called without one thread timeout greater than total timeout"); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5566 | return eExpressionSetupError; |
Jim Ingham | 914f4e7 | 2014-03-28 21:58:28 +0000 | [diff] [blame] | 5567 | } |
| 5568 | computed_one_thread_timeout = option_one_thread_timeout; |
| 5569 | } |
| 5570 | else |
| 5571 | { |
| 5572 | computed_one_thread_timeout = timeout_usec / 2; |
| 5573 | if (computed_one_thread_timeout > default_one_thread_timeout_usec) |
| 5574 | computed_one_thread_timeout = default_one_thread_timeout_usec; |
| 5575 | } |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5576 | one_thread_timeout_usec = computed_one_thread_timeout; |
| 5577 | all_threads_timeout_usec = timeout_usec - one_thread_timeout_usec; |
| 5578 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5579 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5580 | } |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 5581 | |
| 5582 | if (log) |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5583 | 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] | 5584 | options.GetStopOthers(), |
| 5585 | options.GetTryAllThreads(), |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5586 | before_first_timeout, |
| 5587 | one_thread_timeout_usec, |
| 5588 | all_threads_timeout_usec); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5589 | |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 5590 | // This isn't going to work if there are unfetched events on the queue. |
| 5591 | // Are there cases where we might want to run the remaining events here, and then try to |
| 5592 | // 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] | 5593 | |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 5594 | Event *other_events = listener.PeekAtNextEvent(); |
| 5595 | if (other_events != NULL) |
| 5596 | { |
| 5597 | errors.Printf("Calling RunThreadPlan with pending events on the queue."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5598 | return eExpressionSetupError; |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 5599 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5600 | |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 5601 | // We also need to make sure that the next event is delivered. We might be calling a function as part of |
| 5602 | // a thread plan, in which case the last delivered event could be the running event, and we don't want |
| 5603 | // event coalescing to cause us to lose OUR running event... |
| 5604 | ForceNextEventDelivery(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5605 | |
Jim Ingham | 8559a35 | 2012-11-26 23:52:18 +0000 | [diff] [blame] | 5606 | // This while loop must exit out the bottom, there's cleanup that we need to do when we are done. |
| 5607 | // So don't call return anywhere within it. |
Jim Ingham | 35878c4 | 2014-04-08 21:33:21 +0000 | [diff] [blame] | 5608 | |
| 5609 | #ifdef LLDB_RUN_THREAD_HALT_WITH_EVENT |
| 5610 | // It's pretty much impossible to write test cases for things like: |
| 5611 | // One thread timeout expires, I go to halt, but the process already stopped |
| 5612 | // on the function call stop breakpoint. Turning on this define will make us not |
| 5613 | // fetch the first event till after the halt. So if you run a quick function, it will have |
| 5614 | // completed, and the completion event will be waiting, when you interrupt for halt. |
| 5615 | // The expression evaluation should still succeed. |
| 5616 | bool miss_first_event = true; |
| 5617 | #endif |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5618 | TimeValue one_thread_timeout; |
| 5619 | TimeValue final_timeout; |
| 5620 | |
Jim Ingham | 35878c4 | 2014-04-08 21:33:21 +0000 | [diff] [blame] | 5621 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5622 | while (1) |
| 5623 | { |
| 5624 | // We usually want to resume the process if we get to the top of the loop. |
| 5625 | // The only exception is if we get two running events with no intervening |
| 5626 | // 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] | 5627 | if (log) |
| 5628 | log->Printf ("Top of while loop: do_resume: %i handle_running_event: %i before_first_timeout: %i.", |
| 5629 | do_resume, |
| 5630 | handle_running_event, |
| 5631 | before_first_timeout); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5632 | |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5633 | if (do_resume || handle_running_event) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5634 | { |
| 5635 | // 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] | 5636 | |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5637 | if (do_resume) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5638 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5639 | num_resumes++; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5640 | Error resume_error = PrivateResume (); |
| 5641 | if (!resume_error.Success()) |
| 5642 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5643 | errors.Printf("Error resuming inferior the %d time: \"%s\".\n", |
| 5644 | num_resumes, |
| 5645 | resume_error.AsCString()); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5646 | return_value = eExpressionSetupError; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5647 | break; |
| 5648 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5649 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5650 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5651 | TimeValue resume_timeout = TimeValue::Now(); |
| 5652 | resume_timeout.OffsetWithMicroSeconds(500000); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5653 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5654 | got_event = listener.WaitForEvent(&resume_timeout, event_sp); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5655 | if (!got_event) |
| 5656 | { |
| 5657 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5658 | log->Printf ("Process::RunThreadPlan(): didn't get any event after resume %d, exiting.", |
| 5659 | num_resumes); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5660 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5661 | 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] | 5662 | return_value = eExpressionSetupError; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5663 | break; |
| 5664 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5665 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5666 | stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5667 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5668 | if (stop_state != eStateRunning) |
| 5669 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5670 | bool restarted = false; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5671 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5672 | if (stop_state == eStateStopped) |
| 5673 | { |
| 5674 | restarted = Process::ProcessEventData::GetRestartedFromEvent(event_sp.get()); |
| 5675 | if (log) |
| 5676 | log->Printf("Process::RunThreadPlan(): didn't get running event after " |
| 5677 | "resume %d, got %s instead (restarted: %i, do_resume: %i, handle_running_event: %i).", |
| 5678 | num_resumes, |
| 5679 | StateAsCString(stop_state), |
| 5680 | restarted, |
| 5681 | do_resume, |
| 5682 | handle_running_event); |
| 5683 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5684 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5685 | if (restarted) |
| 5686 | { |
| 5687 | // This is probably an overabundance of caution, I don't think I should ever get a stopped & restarted |
| 5688 | // event here. But if I do, the best thing is to Halt and then get out of here. |
| 5689 | Halt(); |
| 5690 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5691 | |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 5692 | errors.Printf("Didn't get running event after initial resume, got %s instead.", |
| 5693 | StateAsCString(stop_state)); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5694 | return_value = eExpressionSetupError; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5695 | break; |
| 5696 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5697 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5698 | if (log) |
| 5699 | log->PutCString ("Process::RunThreadPlan(): resuming succeeded."); |
| 5700 | // We need to call the function synchronously, so spin waiting for it to return. |
| 5701 | // If we get interrupted while executing, we're going to lose our context, and |
| 5702 | // won't be able to gather the result at this point. |
| 5703 | // We set the timeout AFTER the resume, since the resume takes some time and we |
| 5704 | // don't want to charge that to the timeout. |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5705 | } |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 5706 | else |
| 5707 | { |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5708 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5709 | log->PutCString ("Process::RunThreadPlan(): waiting for next event."); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 5710 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5711 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5712 | if (before_first_timeout) |
| 5713 | { |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5714 | if (options.GetTryAllThreads()) |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5715 | { |
| 5716 | one_thread_timeout = TimeValue::Now(); |
| 5717 | one_thread_timeout.OffsetWithMicroSeconds(one_thread_timeout_usec); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5718 | timeout_ptr = &one_thread_timeout; |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5719 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5720 | else |
| 5721 | { |
| 5722 | if (timeout_usec == 0) |
| 5723 | timeout_ptr = NULL; |
| 5724 | else |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5725 | { |
| 5726 | final_timeout = TimeValue::Now(); |
| 5727 | final_timeout.OffsetWithMicroSeconds (timeout_usec); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5728 | timeout_ptr = &final_timeout; |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5729 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5730 | } |
| 5731 | } |
| 5732 | else |
| 5733 | { |
| 5734 | if (timeout_usec == 0) |
| 5735 | timeout_ptr = NULL; |
| 5736 | else |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5737 | { |
| 5738 | final_timeout = TimeValue::Now(); |
| 5739 | final_timeout.OffsetWithMicroSeconds (all_threads_timeout_usec); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5740 | timeout_ptr = &final_timeout; |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5741 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5742 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5743 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5744 | do_resume = true; |
| 5745 | handle_running_event = true; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5746 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5747 | // Now wait for the process to stop again: |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5748 | event_sp.reset(); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 5749 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 5750 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 5751 | { |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5752 | if (timeout_ptr) |
| 5753 | { |
Matt Kopec | 676a487 | 2013-02-21 23:55:31 +0000 | [diff] [blame] | 5754 | 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] | 5755 | TimeValue::Now().GetAsMicroSecondsSinceJan1_1970(), |
| 5756 | timeout_ptr->GetAsMicroSecondsSinceJan1_1970()); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5757 | } |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 5758 | else |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5759 | { |
| 5760 | log->Printf ("Process::RunThreadPlan(): about to wait forever."); |
| 5761 | } |
| 5762 | } |
Jim Ingham | 35878c4 | 2014-04-08 21:33:21 +0000 | [diff] [blame] | 5763 | |
| 5764 | #ifdef LLDB_RUN_THREAD_HALT_WITH_EVENT |
| 5765 | // See comment above... |
| 5766 | if (miss_first_event) |
| 5767 | { |
| 5768 | usleep(1000); |
| 5769 | miss_first_event = false; |
| 5770 | got_event = false; |
| 5771 | } |
| 5772 | else |
| 5773 | #endif |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5774 | got_event = listener.WaitForEvent (timeout_ptr, event_sp); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5775 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5776 | if (got_event) |
| 5777 | { |
| 5778 | if (event_sp.get()) |
| 5779 | { |
| 5780 | bool keep_going = false; |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5781 | if (event_sp->GetType() == eBroadcastBitInterrupt) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5782 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5783 | Halt(); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5784 | return_value = eExpressionInterrupted; |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5785 | errors.Printf ("Execution halted by user interrupt."); |
| 5786 | if (log) |
| 5787 | log->Printf ("Process::RunThreadPlan(): Got interrupted by eBroadcastBitInterrupted, exiting."); |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5788 | break; |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5789 | } |
| 5790 | else |
| 5791 | { |
| 5792 | stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 5793 | if (log) |
| 5794 | 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] | 5795 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5796 | switch (stop_state) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5797 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5798 | case lldb::eStateStopped: |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5799 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5800 | // We stopped, figure out what we are going to do now. |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5801 | ThreadSP thread_sp = GetThreadList().FindThreadByIndexID (thread_idx_id); |
| 5802 | if (!thread_sp) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5803 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5804 | // Ooh, our thread has vanished. Unlikely that this was successful execution... |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5805 | if (log) |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5806 | 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] | 5807 | return_value = eExpressionInterrupted; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5808 | } |
| 5809 | else |
| 5810 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5811 | // If we were restarted, we just need to go back up to fetch another event. |
| 5812 | if (Process::ProcessEventData::GetRestartedFromEvent(event_sp.get())) |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5813 | { |
| 5814 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5815 | { |
| 5816 | log->Printf ("Process::RunThreadPlan(): Got a stop and restart, so we'll continue waiting."); |
| 5817 | } |
| 5818 | keep_going = true; |
| 5819 | do_resume = false; |
| 5820 | handle_running_event = true; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5821 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5822 | } |
| 5823 | else |
| 5824 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5825 | StopInfoSP stop_info_sp (thread_sp->GetStopInfo ()); |
| 5826 | StopReason stop_reason = eStopReasonInvalid; |
| 5827 | if (stop_info_sp) |
| 5828 | stop_reason = stop_info_sp->GetStopReason(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5829 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5830 | // FIXME: We only check if the stop reason is plan complete, should we make sure that |
| 5831 | // it is OUR plan that is complete? |
| 5832 | if (stop_reason == eStopReasonPlanComplete) |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5833 | { |
| 5834 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5835 | log->PutCString ("Process::RunThreadPlan(): execution completed successfully."); |
| 5836 | // Now mark this plan as private so it doesn't get reported as the stop reason |
| 5837 | // after this point. |
| 5838 | if (thread_plan_sp) |
| 5839 | thread_plan_sp->SetPrivate (orig_plan_private); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5840 | return_value = eExpressionCompleted; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5841 | } |
| 5842 | else |
| 5843 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5844 | // 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] | 5845 | if (stop_reason == eStopReasonBreakpoint) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5846 | { |
| 5847 | if (log) |
| 5848 | log->Printf ("Process::RunThreadPlan() stopped for breakpoint: %s.", stop_info_sp->GetDescription()); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5849 | return_value = eExpressionHitBreakpoint; |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5850 | if (!options.DoesIgnoreBreakpoints()) |
Sean Callanan | 4b388c9 | 2013-07-30 19:54:09 +0000 | [diff] [blame] | 5851 | { |
| 5852 | event_to_broadcast_sp = event_sp; |
| 5853 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5854 | } |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5855 | else |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5856 | { |
| 5857 | if (log) |
| 5858 | log->PutCString ("Process::RunThreadPlan(): thread plan didn't successfully complete."); |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5859 | if (!options.DoesUnwindOnError()) |
Sean Callanan | 4b388c9 | 2013-07-30 19:54:09 +0000 | [diff] [blame] | 5860 | event_to_broadcast_sp = event_sp; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5861 | return_value = eExpressionInterrupted; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5862 | } |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5863 | } |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5864 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5865 | } |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5866 | } |
| 5867 | break; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5868 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5869 | case lldb::eStateRunning: |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5870 | // This shouldn't really happen, but sometimes we do get two running events without an |
| 5871 | // 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] | 5872 | do_resume = false; |
| 5873 | keep_going = true; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 5874 | handle_running_event = false; |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5875 | break; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5876 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5877 | default: |
| 5878 | if (log) |
| 5879 | 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] | 5880 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5881 | if (stop_state == eStateExited) |
| 5882 | event_to_broadcast_sp = event_sp; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5883 | |
Sean Callanan | bf154da | 2012-08-08 17:35:10 +0000 | [diff] [blame] | 5884 | errors.Printf ("Execution stopped with unexpected state.\n"); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5885 | return_value = eExpressionInterrupted; |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 5886 | break; |
| 5887 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5888 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5889 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5890 | if (keep_going) |
| 5891 | continue; |
| 5892 | else |
| 5893 | break; |
| 5894 | } |
| 5895 | else |
| 5896 | { |
| 5897 | if (log) |
| 5898 | 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] | 5899 | return_value = eExpressionInterrupted; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5900 | break; |
| 5901 | } |
| 5902 | } |
| 5903 | else |
| 5904 | { |
| 5905 | // If we didn't get an event that means we've timed out... |
| 5906 | // We will interrupt the process here. Depending on what we were asked to do we will |
| 5907 | // either exit, or try with all threads running for the same timeout. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5908 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5909 | if (log) { |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 5910 | if (options.GetTryAllThreads()) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5911 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5912 | if (before_first_timeout) |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 5913 | { |
| 5914 | if (timeout_usec != 0) |
| 5915 | { |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 5916 | log->Printf ("Process::RunThreadPlan(): Running function with one thread timeout timed out, " |
Jim Ingham | fd95f89 | 2014-04-22 01:41:52 +0000 | [diff] [blame] | 5917 | "running for %" PRIu32 " usec with all threads enabled.", |
| 5918 | all_threads_timeout_usec); |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 5919 | } |
| 5920 | else |
| 5921 | { |
| 5922 | log->Printf ("Process::RunThreadPlan(): Running function with one thread timeout timed out, " |
Ed Maste | e61c7b0 | 2014-04-29 17:48:06 +0000 | [diff] [blame] | 5923 | "running forever with all threads enabled."); |
Jim Ingham | fe1c342 | 2014-04-16 02:24:48 +0000 | [diff] [blame] | 5924 | } |
| 5925 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5926 | else |
| 5927 | log->Printf ("Process::RunThreadPlan(): Restarting function with all threads enabled " |
Jason Molenda | 6a8658a | 2013-10-27 02:32:23 +0000 | [diff] [blame] | 5928 | "and timeout: %u timed out, abandoning execution.", |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 5929 | timeout_usec); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5930 | } |
| 5931 | else |
Jason Molenda | 6a8658a | 2013-10-27 02:32:23 +0000 | [diff] [blame] | 5932 | log->Printf ("Process::RunThreadPlan(): Running function with timeout: %u timed out, " |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 5933 | "abandoning execution.", |
| 5934 | timeout_usec); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5935 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5936 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5937 | // It is possible that between the time we issued the Halt, and we get around to calling Halt the target |
| 5938 | // could have stopped. That's fine, Halt will figure that out and send the appropriate Stopped event. |
| 5939 | // BUT it is also possible that we stopped & restarted (e.g. hit a signal with "stop" set to false.) In |
| 5940 | // that case, we'll get the stopped & restarted event, and we should go back to waiting for the Halt's |
| 5941 | // stopped event. That's what this while loop does. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5942 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5943 | bool back_to_top = true; |
| 5944 | uint32_t try_halt_again = 0; |
| 5945 | bool do_halt = true; |
| 5946 | const uint32_t num_retries = 5; |
| 5947 | while (try_halt_again < num_retries) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5948 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5949 | Error halt_error; |
| 5950 | if (do_halt) |
| 5951 | { |
| 5952 | if (log) |
| 5953 | log->Printf ("Process::RunThreadPlan(): Running Halt."); |
| 5954 | halt_error = Halt(); |
| 5955 | } |
| 5956 | if (halt_error.Success()) |
| 5957 | { |
| 5958 | if (log) |
| 5959 | log->PutCString ("Process::RunThreadPlan(): Halt succeeded."); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5960 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5961 | real_timeout = TimeValue::Now(); |
| 5962 | real_timeout.OffsetWithMicroSeconds(500000); |
| 5963 | |
| 5964 | got_event = listener.WaitForEvent(&real_timeout, event_sp); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5965 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5966 | if (got_event) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5967 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5968 | stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 5969 | if (log) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5970 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5971 | log->Printf ("Process::RunThreadPlan(): Stopped with event: %s", StateAsCString(stop_state)); |
| 5972 | if (stop_state == lldb::eStateStopped |
| 5973 | && Process::ProcessEventData::GetInterruptedFromEvent(event_sp.get())) |
| 5974 | log->PutCString (" Event was the Halt interruption event."); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5975 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5976 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5977 | if (stop_state == lldb::eStateStopped) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 5978 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5979 | // Between the time we initiated the Halt and the time we delivered it, the process could have |
| 5980 | // already finished its job. Check that here: |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5981 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5982 | if (thread->IsThreadPlanDone (thread_plan_sp.get())) |
| 5983 | { |
| 5984 | if (log) |
| 5985 | log->PutCString ("Process::RunThreadPlan(): Even though we timed out, the call plan was done. " |
| 5986 | "Exiting wait loop."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 5987 | return_value = eExpressionCompleted; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5988 | back_to_top = false; |
| 5989 | break; |
| 5990 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 5991 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 5992 | if (Process::ProcessEventData::GetRestartedFromEvent(event_sp.get())) |
| 5993 | { |
| 5994 | if (log) |
| 5995 | log->PutCString ("Process::RunThreadPlan(): Went to halt but got a restarted event, there must be an un-restarted stopped event so try again... " |
| 5996 | "Exiting wait loop."); |
| 5997 | try_halt_again++; |
| 5998 | do_halt = false; |
| 5999 | continue; |
| 6000 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6001 | |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 6002 | if (!options.GetTryAllThreads()) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 6003 | { |
| 6004 | if (log) |
| 6005 | 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] | 6006 | return_value = eExpressionInterrupted; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 6007 | back_to_top = false; |
| 6008 | break; |
| 6009 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6010 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 6011 | if (before_first_timeout) |
| 6012 | { |
| 6013 | // Set all the other threads to run, and return to the top of the loop, which will continue; |
| 6014 | before_first_timeout = false; |
| 6015 | thread_plan_sp->SetStopOthers (false); |
| 6016 | if (log) |
| 6017 | log->PutCString ("Process::RunThreadPlan(): about to resume."); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6018 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 6019 | back_to_top = true; |
| 6020 | break; |
| 6021 | } |
| 6022 | else |
| 6023 | { |
| 6024 | // Running all threads failed, so return Interrupted. |
| 6025 | if (log) |
| 6026 | log->PutCString("Process::RunThreadPlan(): running all threads timed out."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6027 | return_value = eExpressionInterrupted; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 6028 | back_to_top = false; |
| 6029 | break; |
| 6030 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6031 | } |
| 6032 | } |
| 6033 | else |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 6034 | { if (log) |
| 6035 | log->PutCString("Process::RunThreadPlan(): halt said it succeeded, but I got no event. " |
| 6036 | "I'm getting out of here passing Interrupted."); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6037 | return_value = eExpressionInterrupted; |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 6038 | back_to_top = false; |
| 6039 | break; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6040 | } |
| 6041 | } |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 6042 | else |
| 6043 | { |
| 6044 | try_halt_again++; |
| 6045 | continue; |
| 6046 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6047 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6048 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 6049 | if (!back_to_top || try_halt_again > num_retries) |
| 6050 | break; |
| 6051 | else |
| 6052 | continue; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6053 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6054 | } // END WAIT LOOP |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6055 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6056 | // If we had to start up a temporary private state thread to run this thread plan, shut it down now. |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 6057 | if (backup_private_state_thread.IsJoinable()) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6058 | { |
| 6059 | StopPrivateStateThread(); |
| 6060 | Error error; |
| 6061 | m_private_state_thread = backup_private_state_thread; |
Sean Callanan | 9a02851 | 2012-08-09 00:50:26 +0000 | [diff] [blame] | 6062 | if (stopper_base_plan_sp) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6063 | { |
| 6064 | thread->DiscardThreadPlansUpToPlan(stopper_base_plan_sp); |
| 6065 | } |
Jason Molenda | 76513fd | 2014-10-15 23:39:31 +0000 | [diff] [blame] | 6066 | if (old_state != eStateInvalid) |
| 6067 | m_public_state.SetValueNoLock(old_state); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6068 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6069 | |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 6070 | // Restore the thread state if we are going to discard the plan execution. There are three cases where this |
| 6071 | // could happen: |
| 6072 | // 1) The execution successfully completed |
| 6073 | // 2) We hit a breakpoint, and ignore_breakpoints was true |
| 6074 | // 3) We got some other error, and discard_on_error was true |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6075 | bool should_unwind = (return_value == eExpressionInterrupted && options.DoesUnwindOnError()) |
| 6076 | || (return_value == eExpressionHitBreakpoint && options.DoesIgnoreBreakpoints()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6077 | |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6078 | if (return_value == eExpressionCompleted |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 6079 | || should_unwind) |
Jim Ingham | 8559a35 | 2012-11-26 23:52:18 +0000 | [diff] [blame] | 6080 | { |
| 6081 | thread_plan_sp->RestoreThreadState(); |
| 6082 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6083 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6084 | // Now do some processing on the results of the run: |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6085 | if (return_value == eExpressionInterrupted || return_value == eExpressionHitBreakpoint) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6086 | { |
| 6087 | if (log) |
| 6088 | { |
| 6089 | StreamString s; |
| 6090 | if (event_sp) |
| 6091 | event_sp->Dump (&s); |
| 6092 | else |
| 6093 | { |
| 6094 | log->PutCString ("Process::RunThreadPlan(): Stop event that interrupted us is NULL."); |
| 6095 | } |
| 6096 | |
| 6097 | StreamString ts; |
| 6098 | |
| 6099 | const char *event_explanation = NULL; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6100 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6101 | do |
| 6102 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6103 | if (!event_sp) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6104 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6105 | event_explanation = "<no event>"; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6106 | break; |
| 6107 | } |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6108 | else if (event_sp->GetType() == eBroadcastBitInterrupt) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6109 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6110 | event_explanation = "<user interrupt>"; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6111 | break; |
| 6112 | } |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6113 | else |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6114 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6115 | const Process::ProcessEventData *event_data = Process::ProcessEventData::GetEventDataFromEvent (event_sp.get()); |
| 6116 | |
| 6117 | if (!event_data) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6118 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6119 | event_explanation = "<no event data>"; |
| 6120 | break; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6121 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6122 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6123 | Process *process = event_data->GetProcessSP().get(); |
| 6124 | |
| 6125 | if (!process) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6126 | { |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6127 | event_explanation = "<no process>"; |
| 6128 | break; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6129 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6130 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6131 | ThreadList &thread_list = process->GetThreadList(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6132 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6133 | uint32_t num_threads = thread_list.GetSize(); |
| 6134 | uint32_t thread_index; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6135 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6136 | ts.Printf("<%u threads> ", num_threads); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6137 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6138 | for (thread_index = 0; |
| 6139 | thread_index < num_threads; |
| 6140 | ++thread_index) |
| 6141 | { |
| 6142 | Thread *thread = thread_list.GetThreadAtIndex(thread_index).get(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6143 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6144 | if (!thread) |
| 6145 | { |
| 6146 | ts.Printf("<?> "); |
| 6147 | continue; |
| 6148 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6149 | |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6150 | ts.Printf("<0x%4.4" PRIx64 " ", thread->GetID()); |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6151 | RegisterContext *register_context = thread->GetRegisterContext().get(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6152 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6153 | if (register_context) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6154 | ts.Printf("[ip 0x%" PRIx64 "] ", register_context->GetPC()); |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6155 | else |
| 6156 | ts.Printf("[ip unknown] "); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6157 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6158 | lldb::StopInfoSP stop_info_sp = thread->GetStopInfo(); |
| 6159 | if (stop_info_sp) |
| 6160 | { |
| 6161 | const char *stop_desc = stop_info_sp->GetDescription(); |
| 6162 | if (stop_desc) |
| 6163 | ts.PutCString (stop_desc); |
| 6164 | } |
| 6165 | ts.Printf(">"); |
| 6166 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6167 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6168 | event_explanation = ts.GetData(); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6169 | } |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6170 | } while (0); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6171 | |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6172 | if (event_explanation) |
| 6173 | log->Printf("Process::RunThreadPlan(): execution interrupted: %s %s", s.GetData(), event_explanation); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6174 | else |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6175 | log->Printf("Process::RunThreadPlan(): execution interrupted: %s", s.GetData()); |
| 6176 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6177 | |
Jim Ingham | e4483cf | 2013-09-27 01:13:01 +0000 | [diff] [blame] | 6178 | if (should_unwind) |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6179 | { |
| 6180 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6181 | log->Printf ("Process::RunThreadPlan: ExecutionInterrupted - discarding thread plans up to %p.", |
| 6182 | static_cast<void*>(thread_plan_sp.get())); |
Jim Ingham | cfc0935 | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 6183 | thread->DiscardThreadPlansUpToPlan (thread_plan_sp); |
| 6184 | thread_plan_sp->SetPrivate (orig_plan_private); |
| 6185 | } |
| 6186 | else |
| 6187 | { |
| 6188 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6189 | log->Printf ("Process::RunThreadPlan: ExecutionInterrupted - for plan: %p not discarding.", |
| 6190 | static_cast<void*>(thread_plan_sp.get())); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6191 | } |
| 6192 | } |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6193 | else if (return_value == eExpressionSetupError) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6194 | { |
| 6195 | if (log) |
| 6196 | log->PutCString("Process::RunThreadPlan(): execution set up error."); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6197 | |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 6198 | if (options.DoesUnwindOnError()) |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 6199 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 6200 | thread->DiscardThreadPlansUpToPlan (thread_plan_sp); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 6201 | thread_plan_sp->SetPrivate (orig_plan_private); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 6202 | } |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6203 | } |
| 6204 | else |
| 6205 | { |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6206 | if (thread->IsThreadPlanDone (thread_plan_sp.get())) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6207 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 6208 | if (log) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6209 | log->PutCString("Process::RunThreadPlan(): thread plan is done"); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6210 | return_value = eExpressionCompleted; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6211 | } |
| 6212 | else if (thread->WasThreadPlanDiscarded (thread_plan_sp.get())) |
| 6213 | { |
| 6214 | if (log) |
| 6215 | log->PutCString("Process::RunThreadPlan(): thread plan was discarded"); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6216 | return_value = eExpressionDiscarded; |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6217 | } |
| 6218 | else |
| 6219 | { |
| 6220 | if (log) |
| 6221 | log->PutCString("Process::RunThreadPlan(): thread plan stopped in mid course"); |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 6222 | if (options.DoesUnwindOnError() && thread_plan_sp) |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6223 | { |
| 6224 | if (log) |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 6225 | 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] | 6226 | thread->DiscardThreadPlansUpToPlan (thread_plan_sp); |
| 6227 | thread_plan_sp->SetPrivate (orig_plan_private); |
| 6228 | } |
| 6229 | } |
| 6230 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6231 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6232 | // Thread we ran the function in may have gone away because we ran the target |
| 6233 | // Check that it's still there, and if it is put it back in the context. Also restore the |
| 6234 | // frame in the context if it is still present. |
| 6235 | thread = GetThreadList().FindThreadByIndexID(thread_idx_id, true).get(); |
| 6236 | if (thread) |
| 6237 | { |
| 6238 | exe_ctx.SetFrameSP (thread->GetFrameWithStackID (ctx_frame_id)); |
| 6239 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6240 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6241 | // Also restore the current process'es selected frame & thread, since this function calling may |
| 6242 | // be done behind the user's back. |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6243 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6244 | if (selected_tid != LLDB_INVALID_THREAD_ID) |
| 6245 | { |
| 6246 | if (GetThreadList().SetSelectedThreadByIndexID (selected_tid) && selected_stack_id.IsValid()) |
| 6247 | { |
| 6248 | // We were able to restore the selected thread, now restore the frame: |
Daniel Malea | a012d3a | 2013-07-31 20:21:20 +0000 | [diff] [blame] | 6249 | Mutex::Locker lock(GetThreadList().GetMutex()); |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 6250 | StackFrameSP old_frame_sp = GetThreadList().GetSelectedThread()->GetFrameWithStackID(selected_stack_id); |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6251 | if (old_frame_sp) |
| 6252 | GetThreadList().GetSelectedThread()->SetSelectedFrame(old_frame_sp.get()); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6253 | } |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6254 | } |
| 6255 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6256 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6257 | // 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] | 6258 | |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6259 | if (event_to_broadcast_sp) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6260 | { |
Sean Callanan | a46ec45 | 2012-07-11 21:31:24 +0000 | [diff] [blame] | 6261 | if (log) |
| 6262 | log->PutCString("Process::RunThreadPlan(): rebroadcasting event."); |
| 6263 | BroadcastEvent(event_to_broadcast_sp); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6264 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 6265 | |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6266 | return return_value; |
| 6267 | } |
| 6268 | |
| 6269 | const char * |
Jim Ingham | 1624a2d | 2014-05-05 02:26:40 +0000 | [diff] [blame] | 6270 | Process::ExecutionResultAsCString (ExpressionResults result) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6271 | { |
| 6272 | const char *result_name; |
| 6273 | |
| 6274 | switch (result) |
| 6275 | { |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6276 | case eExpressionCompleted: |
| 6277 | result_name = "eExpressionCompleted"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6278 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6279 | case eExpressionDiscarded: |
| 6280 | result_name = "eExpressionDiscarded"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6281 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6282 | case eExpressionInterrupted: |
| 6283 | result_name = "eExpressionInterrupted"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6284 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6285 | case eExpressionHitBreakpoint: |
| 6286 | result_name = "eExpressionHitBreakpoint"; |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 6287 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6288 | case eExpressionSetupError: |
| 6289 | result_name = "eExpressionSetupError"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6290 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6291 | case eExpressionParseError: |
| 6292 | result_name = "eExpressionParseError"; |
Jim Ingham | 1624a2d | 2014-05-05 02:26:40 +0000 | [diff] [blame] | 6293 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6294 | case eExpressionResultUnavailable: |
| 6295 | result_name = "eExpressionResultUnavailable"; |
Jim Ingham | 1624a2d | 2014-05-05 02:26:40 +0000 | [diff] [blame] | 6296 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6297 | case eExpressionTimedOut: |
| 6298 | result_name = "eExpressionTimedOut"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6299 | break; |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 6300 | case eExpressionStoppedForDebug: |
| 6301 | result_name = "eExpressionStoppedForDebug"; |
Jim Ingham | 6fbc48b | 2013-11-07 00:11:47 +0000 | [diff] [blame] | 6302 | break; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 6303 | } |
| 6304 | return result_name; |
| 6305 | } |
| 6306 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 6307 | void |
| 6308 | Process::GetStatus (Stream &strm) |
| 6309 | { |
| 6310 | const StateType state = GetState(); |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 6311 | if (StateIsStoppedState(state, false)) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 6312 | { |
| 6313 | if (state == eStateExited) |
| 6314 | { |
| 6315 | int exit_status = GetExitStatus(); |
| 6316 | const char *exit_description = GetExitDescription(); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6317 | 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] | 6318 | GetID(), |
| 6319 | exit_status, |
| 6320 | exit_status, |
| 6321 | exit_description ? exit_description : ""); |
| 6322 | } |
| 6323 | else |
| 6324 | { |
| 6325 | if (state == eStateConnected) |
| 6326 | strm.Printf ("Connected to remote target.\n"); |
| 6327 | else |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6328 | strm.Printf ("Process %" PRIu64 " %s\n", GetID(), StateAsCString (state)); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 6329 | } |
| 6330 | } |
| 6331 | else |
| 6332 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 6333 | strm.Printf ("Process %" PRIu64 " is running.\n", GetID()); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 6334 | } |
| 6335 | } |
| 6336 | |
| 6337 | size_t |
| 6338 | Process::GetThreadStatus (Stream &strm, |
| 6339 | bool only_threads_with_stop_reason, |
| 6340 | uint32_t start_frame, |
| 6341 | uint32_t num_frames, |
| 6342 | uint32_t num_frames_with_source) |
| 6343 | { |
| 6344 | size_t num_thread_infos_dumped = 0; |
| 6345 | |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 6346 | // You can't hold the thread list lock while calling Thread::GetStatus. That very well might run code (e.g. if we need it |
| 6347 | // to get return values or arguments.) For that to work the process has to be able to acquire it. So instead copy the thread |
| 6348 | // ID's, and look them up one by one: |
| 6349 | |
| 6350 | uint32_t num_threads; |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 6351 | std::vector<lldb::tid_t> thread_id_array; |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 6352 | //Scope for thread list locker; |
| 6353 | { |
| 6354 | Mutex::Locker locker (GetThreadList().GetMutex()); |
| 6355 | ThreadList &curr_thread_list = GetThreadList(); |
| 6356 | num_threads = curr_thread_list.GetSize(); |
| 6357 | uint32_t idx; |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 6358 | thread_id_array.resize(num_threads); |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 6359 | for (idx = 0; idx < num_threads; ++idx) |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 6360 | thread_id_array[idx] = curr_thread_list.GetThreadAtIndex(idx)->GetID(); |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 6361 | } |
| 6362 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 6363 | for (uint32_t i = 0; i < num_threads; i++) |
| 6364 | { |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 6365 | ThreadSP thread_sp(GetThreadList().FindThreadByID(thread_id_array[i])); |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 6366 | if (thread_sp) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 6367 | { |
| 6368 | if (only_threads_with_stop_reason) |
| 6369 | { |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 6370 | StopInfoSP stop_info_sp = thread_sp->GetStopInfo(); |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 6371 | if (stop_info_sp.get() == NULL || !stop_info_sp->IsValid()) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 6372 | continue; |
| 6373 | } |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 6374 | thread_sp->GetStatus (strm, |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 6375 | start_frame, |
| 6376 | num_frames, |
| 6377 | num_frames_with_source); |
| 6378 | ++num_thread_infos_dumped; |
| 6379 | } |
Jim Ingham | 4a65fb1 | 2014-03-07 11:20:03 +0000 | [diff] [blame] | 6380 | else |
| 6381 | { |
| 6382 | Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 6383 | if (log) |
| 6384 | log->Printf("Process::GetThreadStatus - thread 0x" PRIu64 " vanished while running Thread::GetStatus."); |
| 6385 | |
| 6386 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 6387 | } |
| 6388 | return num_thread_infos_dumped; |
| 6389 | } |
| 6390 | |
Greg Clayton | a9f40ad | 2012-02-22 04:37:26 +0000 | [diff] [blame] | 6391 | void |
| 6392 | Process::AddInvalidMemoryRegion (const LoadRange ®ion) |
| 6393 | { |
| 6394 | m_memory_cache.AddInvalidRange(region.GetRangeBase(), region.GetByteSize()); |
| 6395 | } |
| 6396 | |
| 6397 | bool |
| 6398 | Process::RemoveInvalidMemoryRange (const LoadRange ®ion) |
| 6399 | { |
| 6400 | return m_memory_cache.RemoveInvalidRange(region.GetRangeBase(), region.GetByteSize()); |
| 6401 | } |
| 6402 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 6403 | void |
| 6404 | Process::AddPreResumeAction (PreResumeActionCallback callback, void *baton) |
| 6405 | { |
| 6406 | m_pre_resume_actions.push_back(PreResumeCallbackAndBaton (callback, baton)); |
| 6407 | } |
| 6408 | |
| 6409 | bool |
| 6410 | Process::RunPreResumeActions () |
| 6411 | { |
| 6412 | bool result = true; |
| 6413 | while (!m_pre_resume_actions.empty()) |
| 6414 | { |
| 6415 | struct PreResumeCallbackAndBaton action = m_pre_resume_actions.back(); |
| 6416 | m_pre_resume_actions.pop_back(); |
| 6417 | bool this_result = action.callback (action.baton); |
Jason Molenda | 5571093 | 2014-11-17 20:10:15 +0000 | [diff] [blame] | 6418 | if (result == true) |
| 6419 | result = this_result; |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 6420 | } |
| 6421 | return result; |
| 6422 | } |
| 6423 | |
| 6424 | void |
| 6425 | Process::ClearPreResumeActions () |
| 6426 | { |
| 6427 | m_pre_resume_actions.clear(); |
| 6428 | } |
Greg Clayton | a9f40ad | 2012-02-22 04:37:26 +0000 | [diff] [blame] | 6429 | |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 6430 | ProcessRunLock & |
| 6431 | Process::GetRunLock() |
| 6432 | { |
| 6433 | if (m_private_state_thread.EqualsThread(Host::GetCurrentThread())) |
| 6434 | return m_private_run_lock; |
| 6435 | else |
| 6436 | return m_public_run_lock; |
| 6437 | } |
| 6438 | |
Greg Clayton | fa559e5 | 2012-05-18 02:38:05 +0000 | [diff] [blame] | 6439 | void |
| 6440 | Process::Flush () |
| 6441 | { |
| 6442 | m_thread_list.Flush(); |
Jason Molenda | 5e8dce4 | 2013-12-13 00:29:16 +0000 | [diff] [blame] | 6443 | m_extended_thread_list.Flush(); |
| 6444 | m_extended_thread_stop_id = 0; |
| 6445 | m_queue_list.Clear(); |
| 6446 | m_queue_list_stop_id = 0; |
Greg Clayton | fa559e5 | 2012-05-18 02:38:05 +0000 | [diff] [blame] | 6447 | } |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 6448 | |
| 6449 | void |
| 6450 | Process::DidExec () |
| 6451 | { |
Todd Fiala | 76e0fc9 | 2014-08-27 22:58:26 +0000 | [diff] [blame] | 6452 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 6453 | if (log) |
| 6454 | log->Printf ("Process::%s()", __FUNCTION__); |
| 6455 | |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 6456 | Target &target = GetTarget(); |
| 6457 | target.CleanupProcess (); |
Greg Clayton | b35db63 | 2013-11-09 00:03:31 +0000 | [diff] [blame] | 6458 | target.ClearModules(false); |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 6459 | m_dynamic_checkers_ap.reset(); |
| 6460 | m_abi_sp.reset(); |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 6461 | m_system_runtime_ap.reset(); |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 6462 | m_os_ap.reset(); |
Greg Clayton | 15fc2be | 2013-05-21 01:00:52 +0000 | [diff] [blame] | 6463 | m_dyld_ap.reset(); |
Andrew MacPherson | 17220c1 | 2014-03-05 10:12:43 +0000 | [diff] [blame] | 6464 | m_jit_loaders_ap.reset(); |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 6465 | m_image_tokens.clear(); |
| 6466 | m_allocated_memory_cache.Clear(); |
| 6467 | m_language_runtimes.clear(); |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 6468 | m_instrumentation_runtimes.clear(); |
Greg Clayton | 15fc2be | 2013-05-21 01:00:52 +0000 | [diff] [blame] | 6469 | m_thread_list.DiscardThreadPlans(); |
Greg Clayton | 15fc2be | 2013-05-21 01:00:52 +0000 | [diff] [blame] | 6470 | m_memory_cache.Clear(true); |
Greg Clayton | a97c4d2 | 2014-12-09 23:31:02 +0000 | [diff] [blame] | 6471 | m_stop_info_override_callback = NULL; |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 6472 | DoDidExec(); |
| 6473 | CompleteAttach (); |
Greg Clayton | 095eeaa | 2013-11-05 23:28:00 +0000 | [diff] [blame] | 6474 | // Flush the process (threads and all stack frames) after running CompleteAttach() |
| 6475 | // in case the dynamic loader loaded things in new locations. |
| 6476 | Flush(); |
Greg Clayton | b35db63 | 2013-11-09 00:03:31 +0000 | [diff] [blame] | 6477 | |
| 6478 | // After we figure out what was loaded/unloaded in CompleteAttach, |
| 6479 | // we need to let the target know so it can do any cleanup it needs to. |
| 6480 | target.DidExec(); |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 6481 | } |
Greg Clayton | 095eeaa | 2013-11-05 23:28:00 +0000 | [diff] [blame] | 6482 | |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 6483 | addr_t |
| 6484 | Process::ResolveIndirectFunction(const Address *address, Error &error) |
| 6485 | { |
| 6486 | if (address == nullptr) |
| 6487 | { |
Jean-Daniel Dupas | ef37711f | 2014-02-08 20:22:05 +0000 | [diff] [blame] | 6488 | error.SetErrorString("Invalid address argument"); |
Jim Ingham | 1460e4b | 2014-01-10 23:46:59 +0000 | [diff] [blame] | 6489 | return LLDB_INVALID_ADDRESS; |
| 6490 | } |
| 6491 | |
| 6492 | addr_t function_addr = LLDB_INVALID_ADDRESS; |
| 6493 | |
| 6494 | addr_t addr = address->GetLoadAddress(&GetTarget()); |
| 6495 | std::map<addr_t,addr_t>::const_iterator iter = m_resolved_indirect_addresses.find(addr); |
| 6496 | if (iter != m_resolved_indirect_addresses.end()) |
| 6497 | { |
| 6498 | function_addr = (*iter).second; |
| 6499 | } |
| 6500 | else |
| 6501 | { |
| 6502 | if (!InferiorCall(this, address, function_addr)) |
| 6503 | { |
| 6504 | Symbol *symbol = address->CalculateSymbolContextSymbol(); |
| 6505 | error.SetErrorStringWithFormat ("Unable to call resolver for indirect function %s", |
| 6506 | symbol ? symbol->GetName().AsCString() : "<UNKNOWN>"); |
| 6507 | function_addr = LLDB_INVALID_ADDRESS; |
| 6508 | } |
| 6509 | else |
| 6510 | { |
| 6511 | m_resolved_indirect_addresses.insert(std::pair<addr_t, addr_t>(addr, function_addr)); |
| 6512 | } |
| 6513 | } |
| 6514 | return function_addr; |
| 6515 | } |
| 6516 | |
Andrew MacPherson | eb4d060 | 2014-03-13 09:37:02 +0000 | [diff] [blame] | 6517 | void |
| 6518 | Process::ModulesDidLoad (ModuleList &module_list) |
| 6519 | { |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 6520 | SystemRuntime *sys_runtime = GetSystemRuntime(); |
| 6521 | if (sys_runtime) |
| 6522 | { |
| 6523 | sys_runtime->ModulesDidLoad (module_list); |
| 6524 | } |
Andrew MacPherson | eb4d060 | 2014-03-13 09:37:02 +0000 | [diff] [blame] | 6525 | |
Kuba Brecka | afdf842 | 2014-10-10 23:43:03 +0000 | [diff] [blame] | 6526 | GetJITLoaders().ModulesDidLoad (module_list); |
| 6527 | |
| 6528 | // Give runtimes a chance to be created. |
| 6529 | InstrumentationRuntime::ModulesDidLoad(module_list, this, m_instrumentation_runtimes); |
| 6530 | |
| 6531 | // Tell runtimes about new modules. |
| 6532 | for (auto pos = m_instrumentation_runtimes.begin(); pos != m_instrumentation_runtimes.end(); ++pos) |
| 6533 | { |
| 6534 | InstrumentationRuntimeSP runtime = pos->second; |
| 6535 | runtime->ModulesDidLoad(module_list); |
| 6536 | } |
| 6537 | |
Greg Clayton | 35ca64b | 2015-04-16 17:13:34 +0000 | [diff] [blame] | 6538 | // Let any language runtimes we have already created know |
| 6539 | // about the modules that loaded. |
| 6540 | |
| 6541 | // Iterate over a copy of this language runtime list in case |
| 6542 | // the language runtime ModulesDidLoad somehow causes the language |
| 6543 | // riuntime to be unloaded. |
| 6544 | LanguageRuntimeCollection language_runtimes(m_language_runtimes); |
| 6545 | for (const auto &pair: language_runtimes) |
| 6546 | { |
| 6547 | // We must check language_runtime_sp to make sure it is not |
| 6548 | // NULL as we might cache the fact that we didn't have a |
| 6549 | // language runtime for a language. |
| 6550 | LanguageRuntimeSP language_runtime_sp = pair.second; |
| 6551 | if (language_runtime_sp) |
| 6552 | language_runtime_sp->ModulesDidLoad(module_list); |
| 6553 | } |
Andrew MacPherson | eb4d060 | 2014-03-13 09:37:02 +0000 | [diff] [blame] | 6554 | } |
Kuba Brecka | a51ea38 | 2014-09-06 01:33:13 +0000 | [diff] [blame] | 6555 | |
Jason Molenda | ef7d641 | 2015-08-06 03:27:10 +0000 | [diff] [blame] | 6556 | void |
| 6557 | Process::PrintWarning (uint64_t warning_type, void *repeat_key, const char *fmt, ...) |
| 6558 | { |
| 6559 | bool print_warning = true; |
| 6560 | |
| 6561 | StreamSP stream_sp = GetTarget().GetDebugger().GetAsyncOutputStream(); |
| 6562 | if (stream_sp.get() == nullptr) |
| 6563 | return; |
| 6564 | if (warning_type == eWarningsOptimization |
| 6565 | && GetWarningsOptimization() == false) |
| 6566 | { |
| 6567 | return; |
| 6568 | } |
| 6569 | |
| 6570 | if (repeat_key != nullptr) |
| 6571 | { |
| 6572 | WarningsCollection::iterator it = m_warnings_issued.find (warning_type); |
| 6573 | if (it == m_warnings_issued.end()) |
| 6574 | { |
| 6575 | m_warnings_issued[warning_type] = WarningsPointerSet(); |
| 6576 | m_warnings_issued[warning_type].insert (repeat_key); |
| 6577 | } |
| 6578 | else |
| 6579 | { |
| 6580 | if (it->second.find (repeat_key) != it->second.end()) |
| 6581 | { |
| 6582 | print_warning = false; |
| 6583 | } |
| 6584 | else |
| 6585 | { |
| 6586 | it->second.insert (repeat_key); |
| 6587 | } |
| 6588 | } |
| 6589 | } |
| 6590 | |
| 6591 | if (print_warning) |
| 6592 | { |
| 6593 | va_list args; |
| 6594 | va_start (args, fmt); |
| 6595 | stream_sp->PrintfVarArg (fmt, args); |
| 6596 | va_end (args); |
| 6597 | } |
| 6598 | } |
| 6599 | |
Jason Molenda | 484900b | 2015-08-10 07:55:25 +0000 | [diff] [blame] | 6600 | void |
| 6601 | Process::PrintWarningOptimization (const SymbolContext &sc) |
| 6602 | { |
| 6603 | if (GetWarningsOptimization() == true |
| 6604 | && sc.module_sp.get() |
| 6605 | && sc.module_sp->GetFileSpec().GetFilename().IsEmpty() == false |
| 6606 | && sc.function |
| 6607 | && sc.function->GetIsOptimized() == true) |
| 6608 | { |
| 6609 | PrintWarning (Process::Warnings::eWarningsOptimization, sc.module_sp.get(), "%s was compiled with optimization - stepping may behave oddly; variables may not be available.\n", sc.module_sp->GetFileSpec().GetFilename().GetCString()); |
| 6610 | } |
| 6611 | } |
| 6612 | |
Kuba Brecka | a51ea38 | 2014-09-06 01:33:13 +0000 | [diff] [blame] | 6613 | ThreadCollectionSP |
| 6614 | Process::GetHistoryThreads(lldb::addr_t addr) |
| 6615 | { |
| 6616 | ThreadCollectionSP threads; |
Greg Clayton | 35ca64b | 2015-04-16 17:13:34 +0000 | [diff] [blame] | 6617 | |
Kuba Brecka | a51ea38 | 2014-09-06 01:33:13 +0000 | [diff] [blame] | 6618 | const MemoryHistorySP &memory_history = MemoryHistory::FindPlugin(shared_from_this()); |
| 6619 | |
| 6620 | if (! memory_history.get()) { |
| 6621 | return threads; |
| 6622 | } |
| 6623 | |
| 6624 | threads.reset(new ThreadCollection(memory_history->GetHistoryThreads(addr))); |
| 6625 | |
| 6626 | return threads; |
| 6627 | } |
Kuba Brecka | 6392754 | 2014-10-11 01:59:32 +0000 | [diff] [blame] | 6628 | |
| 6629 | InstrumentationRuntimeSP |
| 6630 | Process::GetInstrumentationRuntime(lldb::InstrumentationRuntimeType type) |
| 6631 | { |
| 6632 | InstrumentationRuntimeCollection::iterator pos; |
| 6633 | pos = m_instrumentation_runtimes.find (type); |
| 6634 | if (pos == m_instrumentation_runtimes.end()) |
| 6635 | { |
| 6636 | return InstrumentationRuntimeSP(); |
| 6637 | } |
| 6638 | else |
| 6639 | return (*pos).second; |
| 6640 | } |
Tamas Berghammer | 7cb18bf | 2015-03-24 11:15:23 +0000 | [diff] [blame] | 6641 | |
| 6642 | bool |
| 6643 | Process::GetModuleSpec(const FileSpec& module_file_spec, |
| 6644 | const ArchSpec& arch, |
| 6645 | ModuleSpec& module_spec) |
| 6646 | { |
| 6647 | module_spec.Clear(); |
| 6648 | return false; |
| 6649 | } |