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" |
| 11 | |
| 12 | #include "lldb/lldb-private-log.h" |
| 13 | |
| 14 | #include "lldb/Breakpoint/StoppointCallbackContext.h" |
| 15 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 16 | #include "lldb/Core/Event.h" |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 17 | #include "lldb/Core/ConnectionFileDescriptor.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Debugger.h" |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 19 | #include "lldb/Core/InputReader.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Log.h" |
| 21 | #include "lldb/Core/PluginManager.h" |
| 22 | #include "lldb/Core/State.h" |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 23 | #include "lldb/Expression/ClangUserExpression.h" |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 24 | #include "lldb/Interpreter/CommandInterpreter.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Host/Host.h" |
| 26 | #include "lldb/Target/ABI.h" |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 27 | #include "lldb/Target/DynamicLoader.h" |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 28 | #include "lldb/Target/OperatingSystem.h" |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 29 | #include "lldb/Target/LanguageRuntime.h" |
| 30 | #include "lldb/Target/CPPLanguageRuntime.h" |
| 31 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 32 | #include "lldb/Target/Platform.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 34 | #include "lldb/Target/StopInfo.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | #include "lldb/Target/Target.h" |
| 36 | #include "lldb/Target/TargetList.h" |
| 37 | #include "lldb/Target/Thread.h" |
| 38 | #include "lldb/Target/ThreadPlan.h" |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 39 | #include "lldb/Target/ThreadPlanBase.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | |
| 41 | using namespace lldb; |
| 42 | using namespace lldb_private; |
| 43 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 44 | void |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 45 | ProcessInstanceInfo::Dump (Stream &s, Platform *platform) const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 46 | { |
| 47 | const char *cstr; |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 48 | if (m_pid != LLDB_INVALID_PROCESS_ID) |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 49 | s.Printf (" pid = %llu\n", m_pid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 50 | |
| 51 | if (m_parent_pid != LLDB_INVALID_PROCESS_ID) |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 52 | s.Printf (" parent = %llu\n", m_parent_pid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 53 | |
| 54 | if (m_executable) |
| 55 | { |
| 56 | s.Printf (" name = %s\n", m_executable.GetFilename().GetCString()); |
| 57 | s.PutCString (" file = "); |
| 58 | m_executable.Dump(&s); |
| 59 | s.EOL(); |
| 60 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 61 | const uint32_t argc = m_arguments.GetArgumentCount(); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 62 | if (argc > 0) |
| 63 | { |
| 64 | for (uint32_t i=0; i<argc; i++) |
| 65 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 66 | const char *arg = m_arguments.GetArgumentAtIndex(i); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 67 | if (i < 10) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 68 | s.Printf (" arg[%u] = %s\n", i, arg); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 69 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 70 | s.Printf ("arg[%u] = %s\n", i, arg); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 71 | } |
| 72 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 73 | |
| 74 | const uint32_t envc = m_environment.GetArgumentCount(); |
| 75 | if (envc > 0) |
| 76 | { |
| 77 | for (uint32_t i=0; i<envc; i++) |
| 78 | { |
| 79 | const char *env = m_environment.GetArgumentAtIndex(i); |
| 80 | if (i < 10) |
| 81 | s.Printf (" env[%u] = %s\n", i, env); |
| 82 | else |
| 83 | s.Printf ("env[%u] = %s\n", i, env); |
| 84 | } |
| 85 | } |
| 86 | |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 87 | if (m_arch.IsValid()) |
| 88 | s.Printf (" arch = %s\n", m_arch.GetTriple().str().c_str()); |
| 89 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 90 | if (m_uid != UINT32_MAX) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 91 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 92 | cstr = platform->GetUserName (m_uid); |
| 93 | s.Printf (" uid = %-5u (%s)\n", m_uid, cstr ? cstr : ""); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 94 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 95 | if (m_gid != UINT32_MAX) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 96 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 97 | cstr = platform->GetGroupName (m_gid); |
| 98 | s.Printf (" gid = %-5u (%s)\n", m_gid, cstr ? cstr : ""); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 99 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 100 | if (m_euid != UINT32_MAX) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 101 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 102 | cstr = platform->GetUserName (m_euid); |
| 103 | s.Printf (" euid = %-5u (%s)\n", m_euid, cstr ? cstr : ""); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 104 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 105 | if (m_egid != UINT32_MAX) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 106 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 107 | cstr = platform->GetGroupName (m_egid); |
| 108 | s.Printf (" egid = %-5u (%s)\n", m_egid, cstr ? cstr : ""); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | void |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 113 | ProcessInstanceInfo::DumpTableHeader (Stream &s, Platform *platform, bool show_args, bool verbose) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 114 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 115 | const char *label; |
| 116 | if (show_args || verbose) |
| 117 | label = "ARGUMENTS"; |
| 118 | else |
| 119 | label = "NAME"; |
| 120 | |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 121 | if (verbose) |
| 122 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 123 | 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] | 124 | s.PutCString ("====== ====== ========== ========== ========== ========== ======================== ============================\n"); |
| 125 | } |
| 126 | else |
| 127 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 128 | s.Printf ("PID PARENT USER ARCH %s\n", label); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 129 | s.PutCString ("====== ====== ========== ======= ============================\n"); |
| 130 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | void |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 134 | ProcessInstanceInfo::DumpAsTableRow (Stream &s, Platform *platform, bool show_args, bool verbose) const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 135 | { |
| 136 | if (m_pid != LLDB_INVALID_PROCESS_ID) |
| 137 | { |
| 138 | const char *cstr; |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 139 | s.Printf ("%-6llu %-6llu ", m_pid, m_parent_pid); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 140 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 141 | |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 142 | if (verbose) |
| 143 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 144 | cstr = platform->GetUserName (m_uid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 145 | if (cstr && cstr[0]) // Watch for empty string that indicates lookup failed |
| 146 | s.Printf ("%-10s ", cstr); |
| 147 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 148 | s.Printf ("%-10u ", m_uid); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 149 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 150 | cstr = platform->GetGroupName (m_gid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 151 | if (cstr && cstr[0]) // Watch for empty string that indicates lookup failed |
| 152 | s.Printf ("%-10s ", cstr); |
| 153 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 154 | s.Printf ("%-10u ", m_gid); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 155 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 156 | cstr = platform->GetUserName (m_euid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 157 | if (cstr && cstr[0]) // Watch for empty string that indicates lookup failed |
| 158 | s.Printf ("%-10s ", cstr); |
| 159 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 160 | s.Printf ("%-10u ", m_euid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 161 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 162 | cstr = platform->GetGroupName (m_egid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 163 | if (cstr && cstr[0]) // Watch for empty string that indicates lookup failed |
| 164 | s.Printf ("%-10s ", cstr); |
| 165 | else |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 166 | s.Printf ("%-10u ", m_egid); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 167 | s.Printf ("%-24s ", m_arch.IsValid() ? m_arch.GetTriple().str().c_str() : ""); |
| 168 | } |
| 169 | else |
| 170 | { |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 171 | s.Printf ("%-10s %-7d %s ", |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 172 | platform->GetUserName (m_euid), |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 173 | (int)m_arch.GetTriple().getArchName().size(), |
| 174 | m_arch.GetTriple().getArchName().data()); |
| 175 | } |
| 176 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 177 | if (verbose || show_args) |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 178 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 179 | const uint32_t argc = m_arguments.GetArgumentCount(); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 180 | if (argc > 0) |
| 181 | { |
| 182 | for (uint32_t i=0; i<argc; i++) |
| 183 | { |
| 184 | if (i > 0) |
| 185 | s.PutChar (' '); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 186 | s.PutCString (m_arguments.GetArgumentAtIndex(i)); |
Greg Clayton | 95bf0fd | 2011-04-01 00:29:43 +0000 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | } |
| 190 | else |
| 191 | { |
| 192 | s.PutCString (GetName()); |
| 193 | } |
| 194 | |
| 195 | s.EOL(); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 199 | |
| 200 | void |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 201 | ProcessInfo::SetArguments (char const **argv, |
| 202 | bool first_arg_is_executable, |
| 203 | bool first_arg_is_executable_and_argument) |
| 204 | { |
| 205 | m_arguments.SetArguments (argv); |
| 206 | |
| 207 | // Is the first argument the executable? |
| 208 | if (first_arg_is_executable) |
| 209 | { |
| 210 | const char *first_arg = m_arguments.GetArgumentAtIndex (0); |
| 211 | if (first_arg) |
| 212 | { |
| 213 | // Yes the first argument is an executable, set it as the executable |
| 214 | // in the launch options. Don't resolve the file path as the path |
| 215 | // could be a remote platform path |
| 216 | const bool resolve = false; |
| 217 | m_executable.SetFile(first_arg, resolve); |
| 218 | |
| 219 | // If argument zero is an executable and shouldn't be included |
| 220 | // in the arguments, remove it from the front of the arguments |
| 221 | if (first_arg_is_executable_and_argument == false) |
| 222 | m_arguments.DeleteArgumentAtIndex (0); |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | void |
| 227 | ProcessInfo::SetArguments (const Args& args, |
| 228 | bool first_arg_is_executable, |
| 229 | bool first_arg_is_executable_and_argument) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 230 | { |
| 231 | // Copy all arguments |
| 232 | m_arguments = args; |
| 233 | |
| 234 | // Is the first argument the executable? |
| 235 | if (first_arg_is_executable) |
| 236 | { |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 237 | const char *first_arg = m_arguments.GetArgumentAtIndex (0); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 238 | if (first_arg) |
| 239 | { |
| 240 | // Yes the first argument is an executable, set it as the executable |
| 241 | // in the launch options. Don't resolve the file path as the path |
| 242 | // could be a remote platform path |
| 243 | const bool resolve = false; |
| 244 | m_executable.SetFile(first_arg, resolve); |
| 245 | |
| 246 | // If argument zero is an executable and shouldn't be included |
| 247 | // in the arguments, remove it from the front of the arguments |
| 248 | if (first_arg_is_executable_and_argument == false) |
| 249 | m_arguments.DeleteArgumentAtIndex (0); |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 254 | void |
Greg Clayton | ee95ed5 | 2011-11-17 22:14:31 +0000 | [diff] [blame] | 255 | ProcessLaunchInfo::FinalizeFileActions (Target *target, bool default_to_use_pty) |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 256 | { |
| 257 | // If notthing was specified, then check the process for any default |
| 258 | // settings that were set with "settings set" |
| 259 | if (m_file_actions.empty()) |
| 260 | { |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 261 | if (m_flags.Test(eLaunchFlagDisableSTDIO)) |
| 262 | { |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 263 | AppendSuppressFileAction (STDIN_FILENO , true, false); |
| 264 | AppendSuppressFileAction (STDOUT_FILENO, false, true); |
| 265 | AppendSuppressFileAction (STDERR_FILENO, false, true); |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 266 | } |
| 267 | else |
| 268 | { |
| 269 | // Check for any values that might have gotten set with any of: |
| 270 | // (lldb) settings set target.input-path |
| 271 | // (lldb) settings set target.output-path |
| 272 | // (lldb) settings set target.error-path |
Greg Clayton | ee95ed5 | 2011-11-17 22:14:31 +0000 | [diff] [blame] | 273 | const char *in_path = NULL; |
| 274 | const char *out_path = NULL; |
| 275 | const char *err_path = NULL; |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 276 | if (target) |
| 277 | { |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 278 | in_path = target->GetStandardInputPath(); |
| 279 | out_path = target->GetStandardOutputPath(); |
| 280 | err_path = target->GetStandardErrorPath(); |
Greg Clayton | ee95ed5 | 2011-11-17 22:14:31 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | if (default_to_use_pty && (!in_path && !out_path && !err_path)) |
| 284 | { |
| 285 | if (m_pty.OpenFirstAvailableMaster (O_RDWR|O_NOCTTY, NULL, 0)) |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 286 | { |
Greg Clayton | ee95ed5 | 2011-11-17 22:14:31 +0000 | [diff] [blame] | 287 | in_path = out_path = err_path = m_pty.GetSlaveName (NULL, 0); |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
Greg Clayton | ee95ed5 | 2011-11-17 22:14:31 +0000 | [diff] [blame] | 291 | if (in_path) |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 292 | AppendOpenFileAction(STDIN_FILENO, in_path, true, false); |
| 293 | |
Greg Clayton | ee95ed5 | 2011-11-17 22:14:31 +0000 | [diff] [blame] | 294 | if (out_path) |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 295 | AppendOpenFileAction(STDOUT_FILENO, out_path, false, true); |
Greg Clayton | ee95ed5 | 2011-11-17 22:14:31 +0000 | [diff] [blame] | 296 | |
| 297 | if (err_path) |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 298 | AppendOpenFileAction(STDERR_FILENO, err_path, false, true); |
| 299 | |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 304 | |
| 305 | bool |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 306 | ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell (Error &error, |
| 307 | bool localhost, |
| 308 | bool will_debug, |
| 309 | bool first_arg_is_full_shell_command) |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 310 | { |
| 311 | error.Clear(); |
| 312 | |
| 313 | if (GetFlags().Test (eLaunchFlagLaunchInShell)) |
| 314 | { |
| 315 | const char *shell_executable = GetShell(); |
| 316 | if (shell_executable) |
| 317 | { |
| 318 | char shell_resolved_path[PATH_MAX]; |
| 319 | |
| 320 | if (localhost) |
| 321 | { |
| 322 | FileSpec shell_filespec (shell_executable, true); |
| 323 | |
| 324 | if (!shell_filespec.Exists()) |
| 325 | { |
| 326 | // Resolve the path in case we just got "bash", "sh" or "tcsh" |
| 327 | if (!shell_filespec.ResolveExecutableLocation ()) |
| 328 | { |
| 329 | error.SetErrorStringWithFormat("invalid shell path '%s'", shell_executable); |
| 330 | return false; |
| 331 | } |
| 332 | } |
| 333 | shell_filespec.GetPath (shell_resolved_path, sizeof(shell_resolved_path)); |
| 334 | shell_executable = shell_resolved_path; |
| 335 | } |
| 336 | |
| 337 | Args shell_arguments; |
| 338 | std::string safe_arg; |
| 339 | shell_arguments.AppendArgument (shell_executable); |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 340 | shell_arguments.AppendArgument ("-c"); |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 341 | |
| 342 | StreamString shell_command; |
| 343 | if (will_debug) |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 344 | { |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 345 | shell_command.PutCString ("exec"); |
| 346 | if (GetArchitecture().IsValid()) |
| 347 | { |
| 348 | shell_command.Printf(" /usr/bin/arch -arch %s", GetArchitecture().GetArchitectureName()); |
| 349 | // Set the resume count to 2: |
| 350 | // 1 - stop in shell |
| 351 | // 2 - stop in /usr/bin/arch |
| 352 | // 3 - then we will stop in our program |
| 353 | SetResumeCount(2); |
| 354 | } |
| 355 | else |
| 356 | { |
| 357 | // Set the resume count to 1: |
| 358 | // 1 - stop in shell |
| 359 | // 2 - then we will stop in our program |
| 360 | SetResumeCount(1); |
| 361 | } |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | const char **argv = GetArguments().GetConstArgumentVector (); |
| 365 | if (argv) |
| 366 | { |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 367 | if (first_arg_is_full_shell_command) |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 368 | { |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 369 | // There should only be one argument that is the shell command itself to be used as is |
| 370 | if (argv[0] && !argv[1]) |
| 371 | shell_command.Printf("%s", argv[0]); |
| 372 | else |
| 373 | return false; |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 374 | } |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 375 | else |
| 376 | { |
| 377 | for (size_t i=0; argv[i] != NULL; ++i) |
| 378 | { |
| 379 | const char *arg = Args::GetShellSafeArgument (argv[i], safe_arg); |
| 380 | shell_command.Printf(" %s", arg); |
| 381 | } |
| 382 | } |
| 383 | shell_arguments.AppendArgument (shell_command.GetString().c_str()); |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 384 | } |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 385 | else |
| 386 | { |
| 387 | return false; |
| 388 | } |
| 389 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 390 | m_executable.SetFile(shell_executable, false); |
| 391 | m_arguments = shell_arguments; |
| 392 | return true; |
| 393 | } |
| 394 | else |
| 395 | { |
| 396 | error.SetErrorString ("invalid shell path"); |
| 397 | } |
| 398 | } |
| 399 | else |
| 400 | { |
| 401 | error.SetErrorString ("not launching in shell"); |
| 402 | } |
| 403 | return false; |
| 404 | } |
| 405 | |
| 406 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 407 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 408 | ProcessLaunchInfo::FileAction::Open (int fd, const char *path, bool read, bool write) |
| 409 | { |
| 410 | if ((read || write) && fd >= 0 && path && path[0]) |
| 411 | { |
| 412 | m_action = eFileActionOpen; |
| 413 | m_fd = fd; |
| 414 | if (read && write) |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 415 | m_arg = O_NOCTTY | O_CREAT | O_RDWR; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 416 | else if (read) |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 417 | m_arg = O_NOCTTY | O_RDONLY; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 418 | else |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 419 | m_arg = O_NOCTTY | O_CREAT | O_WRONLY; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 420 | m_path.assign (path); |
| 421 | return true; |
| 422 | } |
| 423 | else |
| 424 | { |
| 425 | Clear(); |
| 426 | } |
| 427 | return false; |
| 428 | } |
| 429 | |
| 430 | bool |
| 431 | ProcessLaunchInfo::FileAction::Close (int fd) |
| 432 | { |
| 433 | Clear(); |
| 434 | if (fd >= 0) |
| 435 | { |
| 436 | m_action = eFileActionClose; |
| 437 | m_fd = fd; |
| 438 | } |
| 439 | return m_fd >= 0; |
| 440 | } |
| 441 | |
| 442 | |
| 443 | bool |
| 444 | ProcessLaunchInfo::FileAction::Duplicate (int fd, int dup_fd) |
| 445 | { |
| 446 | Clear(); |
| 447 | if (fd >= 0 && dup_fd >= 0) |
| 448 | { |
| 449 | m_action = eFileActionDuplicate; |
| 450 | m_fd = fd; |
| 451 | m_arg = dup_fd; |
| 452 | } |
| 453 | return m_fd >= 0; |
| 454 | } |
| 455 | |
| 456 | |
| 457 | |
| 458 | bool |
| 459 | ProcessLaunchInfo::FileAction::AddPosixSpawnFileAction (posix_spawn_file_actions_t *file_actions, |
| 460 | const FileAction *info, |
| 461 | Log *log, |
| 462 | Error& error) |
| 463 | { |
| 464 | if (info == NULL) |
| 465 | return false; |
| 466 | |
| 467 | switch (info->m_action) |
| 468 | { |
| 469 | case eFileActionNone: |
| 470 | error.Clear(); |
| 471 | break; |
| 472 | |
| 473 | case eFileActionClose: |
| 474 | if (info->m_fd == -1) |
| 475 | error.SetErrorString ("invalid fd for posix_spawn_file_actions_addclose(...)"); |
| 476 | else |
| 477 | { |
| 478 | error.SetError (::posix_spawn_file_actions_addclose (file_actions, info->m_fd), |
| 479 | eErrorTypePOSIX); |
| 480 | if (log && (error.Fail() || log)) |
| 481 | error.PutToLog(log, "posix_spawn_file_actions_addclose (action=%p, fd=%i)", |
| 482 | file_actions, info->m_fd); |
| 483 | } |
| 484 | break; |
| 485 | |
| 486 | case eFileActionDuplicate: |
| 487 | if (info->m_fd == -1) |
| 488 | error.SetErrorString ("invalid fd for posix_spawn_file_actions_adddup2(...)"); |
| 489 | else if (info->m_arg == -1) |
| 490 | error.SetErrorString ("invalid duplicate fd for posix_spawn_file_actions_adddup2(...)"); |
| 491 | else |
| 492 | { |
| 493 | error.SetError (::posix_spawn_file_actions_adddup2 (file_actions, info->m_fd, info->m_arg), |
| 494 | eErrorTypePOSIX); |
| 495 | if (log && (error.Fail() || log)) |
| 496 | error.PutToLog(log, "posix_spawn_file_actions_adddup2 (action=%p, fd=%i, dup_fd=%i)", |
| 497 | file_actions, info->m_fd, info->m_arg); |
| 498 | } |
| 499 | break; |
| 500 | |
| 501 | case eFileActionOpen: |
| 502 | if (info->m_fd == -1) |
| 503 | error.SetErrorString ("invalid fd in posix_spawn_file_actions_addopen(...)"); |
| 504 | else |
| 505 | { |
| 506 | int oflag = info->m_arg; |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 507 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 508 | mode_t mode = 0; |
| 509 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 510 | if (oflag & O_CREAT) |
| 511 | mode = 0640; |
| 512 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 513 | error.SetError (::posix_spawn_file_actions_addopen (file_actions, |
| 514 | info->m_fd, |
| 515 | info->m_path.c_str(), |
| 516 | oflag, |
| 517 | mode), |
| 518 | eErrorTypePOSIX); |
| 519 | if (error.Fail() || log) |
| 520 | error.PutToLog(log, |
| 521 | "posix_spawn_file_actions_addopen (action=%p, fd=%i, path='%s', oflag=%i, mode=%i)", |
| 522 | file_actions, info->m_fd, info->m_path.c_str(), oflag, mode); |
| 523 | } |
| 524 | break; |
| 525 | |
| 526 | default: |
| 527 | error.SetErrorStringWithFormat ("invalid file action: %i", info->m_action); |
| 528 | break; |
| 529 | } |
| 530 | return error.Success(); |
| 531 | } |
| 532 | |
| 533 | Error |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 534 | ProcessLaunchCommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 535 | { |
| 536 | Error error; |
| 537 | char short_option = (char) m_getopt_table[option_idx].val; |
| 538 | |
| 539 | switch (short_option) |
| 540 | { |
| 541 | case 's': // Stop at program entry point |
| 542 | launch_info.GetFlags().Set (eLaunchFlagStopAtEntry); |
| 543 | break; |
| 544 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 545 | case 'i': // STDIN for read only |
| 546 | { |
| 547 | ProcessLaunchInfo::FileAction action; |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 548 | if (action.Open (STDIN_FILENO, option_arg, true, false)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 549 | launch_info.AppendFileAction (action); |
| 550 | } |
| 551 | break; |
| 552 | |
| 553 | case 'o': // Open STDOUT for write only |
| 554 | { |
| 555 | ProcessLaunchInfo::FileAction action; |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 556 | if (action.Open (STDOUT_FILENO, option_arg, false, true)) |
| 557 | launch_info.AppendFileAction (action); |
| 558 | } |
| 559 | break; |
| 560 | |
| 561 | case 'e': // STDERR for write only |
| 562 | { |
| 563 | ProcessLaunchInfo::FileAction action; |
| 564 | if (action.Open (STDERR_FILENO, option_arg, false, true)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 565 | launch_info.AppendFileAction (action); |
| 566 | } |
| 567 | break; |
| 568 | |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 569 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 570 | case 'p': // Process plug-in name |
| 571 | launch_info.SetProcessPluginName (option_arg); |
| 572 | break; |
| 573 | |
| 574 | case 'n': // Disable STDIO |
| 575 | { |
| 576 | ProcessLaunchInfo::FileAction action; |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 577 | if (action.Open (STDIN_FILENO, "/dev/null", true, false)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 578 | launch_info.AppendFileAction (action); |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 579 | if (action.Open (STDOUT_FILENO, "/dev/null", false, true)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 580 | launch_info.AppendFileAction (action); |
Greg Clayton | 9845a8d | 2012-03-06 04:01:04 +0000 | [diff] [blame] | 581 | if (action.Open (STDERR_FILENO, "/dev/null", false, true)) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 582 | launch_info.AppendFileAction (action); |
| 583 | } |
| 584 | break; |
| 585 | |
| 586 | case 'w': |
| 587 | launch_info.SetWorkingDirectory (option_arg); |
| 588 | break; |
| 589 | |
| 590 | case 't': // Open process in new terminal window |
| 591 | launch_info.GetFlags().Set (eLaunchFlagLaunchInTTY); |
| 592 | break; |
| 593 | |
| 594 | case 'a': |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame^] | 595 | if (!launch_info.GetArchitecture().SetTriple (option_arg, m_interpreter.GetPlatform(true).get())) |
| 596 | launch_info.GetArchitecture().SetTriple (option_arg); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 597 | break; |
| 598 | |
| 599 | case 'A': |
| 600 | launch_info.GetFlags().Set (eLaunchFlagDisableASLR); |
| 601 | break; |
| 602 | |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 603 | case 'c': |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 604 | if (option_arg && option_arg[0]) |
| 605 | launch_info.SetShell (option_arg); |
| 606 | else |
| 607 | launch_info.SetShell ("/bin/bash"); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 608 | break; |
| 609 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 610 | case 'v': |
| 611 | launch_info.GetEnvironmentEntries().AppendArgument(option_arg); |
| 612 | break; |
| 613 | |
| 614 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 615 | error.SetErrorStringWithFormat("unrecognized short option character '%c'", short_option); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 616 | break; |
| 617 | |
| 618 | } |
| 619 | return error; |
| 620 | } |
| 621 | |
| 622 | OptionDefinition |
| 623 | ProcessLaunchCommandOptions::g_option_table[] = |
| 624 | { |
| 625 | { LLDB_OPT_SET_ALL, false, "stop-at-entry", 's', no_argument, NULL, 0, eArgTypeNone, "Stop at the entry point of the program when launching a process."}, |
| 626 | { LLDB_OPT_SET_ALL, false, "disable-aslr", 'A', no_argument, NULL, 0, eArgTypeNone, "Disable address space layout randomization when launching a process."}, |
| 627 | { LLDB_OPT_SET_ALL, false, "plugin", 'p', required_argument, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, |
| 628 | { LLDB_OPT_SET_ALL, false, "working-dir", 'w', required_argument, NULL, 0, eArgTypePath, "Set the current working directory to <path> when running the inferior."}, |
| 629 | { LLDB_OPT_SET_ALL, false, "arch", 'a', required_argument, NULL, 0, eArgTypeArchitecture, "Set the architecture for the process to launch when ambiguous."}, |
| 630 | { LLDB_OPT_SET_ALL, false, "environment", 'v', required_argument, NULL, 0, eArgTypeNone, "Specify an environment variable name/value stirng (--environement NAME=VALUE). Can be specified multiple times for subsequent environment entries."}, |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 631 | { LLDB_OPT_SET_ALL, false, "shell", 'c', optional_argument, NULL, 0, eArgTypePath, "Run the process in a shell (not supported on all platforms)."}, |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 632 | |
| 633 | { LLDB_OPT_SET_1 , false, "stdin", 'i', required_argument, NULL, 0, eArgTypePath, "Redirect stdin for the process to <path>."}, |
| 634 | { LLDB_OPT_SET_1 , false, "stdout", 'o', required_argument, NULL, 0, eArgTypePath, "Redirect stdout for the process to <path>."}, |
| 635 | { LLDB_OPT_SET_1 , false, "stderr", 'e', required_argument, NULL, 0, eArgTypePath, "Redirect stderr for the process to <path>."}, |
| 636 | |
| 637 | { LLDB_OPT_SET_2 , false, "tty", 't', no_argument, NULL, 0, eArgTypeNone, "Start the process in a terminal (not supported on all platforms)."}, |
| 638 | |
| 639 | { LLDB_OPT_SET_3 , false, "no-stdio", 'n', no_argument, NULL, 0, eArgTypeNone, "Do not set up for terminal I/O to go to running process."}, |
| 640 | |
| 641 | { 0 , false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
| 642 | }; |
| 643 | |
| 644 | |
| 645 | |
| 646 | bool |
| 647 | ProcessInstanceInfoMatch::NameMatches (const char *process_name) const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 648 | { |
| 649 | if (m_name_match_type == eNameMatchIgnore || process_name == NULL) |
| 650 | return true; |
| 651 | const char *match_name = m_match_info.GetName(); |
| 652 | if (!match_name) |
| 653 | return true; |
| 654 | |
| 655 | return lldb_private::NameMatches (process_name, m_name_match_type, match_name); |
| 656 | } |
| 657 | |
| 658 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 659 | ProcessInstanceInfoMatch::Matches (const ProcessInstanceInfo &proc_info) const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 660 | { |
| 661 | if (!NameMatches (proc_info.GetName())) |
| 662 | return false; |
| 663 | |
| 664 | if (m_match_info.ProcessIDIsValid() && |
| 665 | m_match_info.GetProcessID() != proc_info.GetProcessID()) |
| 666 | return false; |
| 667 | |
| 668 | if (m_match_info.ParentProcessIDIsValid() && |
| 669 | m_match_info.GetParentProcessID() != proc_info.GetParentProcessID()) |
| 670 | return false; |
| 671 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 672 | if (m_match_info.UserIDIsValid () && |
| 673 | m_match_info.GetUserID() != proc_info.GetUserID()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 674 | return false; |
| 675 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 676 | if (m_match_info.GroupIDIsValid () && |
| 677 | m_match_info.GetGroupID() != proc_info.GetGroupID()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 678 | return false; |
| 679 | |
| 680 | if (m_match_info.EffectiveUserIDIsValid () && |
| 681 | m_match_info.GetEffectiveUserID() != proc_info.GetEffectiveUserID()) |
| 682 | return false; |
| 683 | |
| 684 | if (m_match_info.EffectiveGroupIDIsValid () && |
| 685 | m_match_info.GetEffectiveGroupID() != proc_info.GetEffectiveGroupID()) |
| 686 | return false; |
| 687 | |
| 688 | if (m_match_info.GetArchitecture().IsValid() && |
| 689 | m_match_info.GetArchitecture() != proc_info.GetArchitecture()) |
| 690 | return false; |
| 691 | return true; |
| 692 | } |
| 693 | |
| 694 | bool |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 695 | ProcessInstanceInfoMatch::MatchAllProcesses () const |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 696 | { |
| 697 | if (m_name_match_type != eNameMatchIgnore) |
| 698 | return false; |
| 699 | |
| 700 | if (m_match_info.ProcessIDIsValid()) |
| 701 | return false; |
| 702 | |
| 703 | if (m_match_info.ParentProcessIDIsValid()) |
| 704 | return false; |
| 705 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 706 | if (m_match_info.UserIDIsValid ()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 707 | return false; |
| 708 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 709 | if (m_match_info.GroupIDIsValid ()) |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 710 | return false; |
| 711 | |
| 712 | if (m_match_info.EffectiveUserIDIsValid ()) |
| 713 | return false; |
| 714 | |
| 715 | if (m_match_info.EffectiveGroupIDIsValid ()) |
| 716 | return false; |
| 717 | |
| 718 | if (m_match_info.GetArchitecture().IsValid()) |
| 719 | return false; |
| 720 | |
| 721 | if (m_match_all_users) |
| 722 | return false; |
| 723 | |
| 724 | return true; |
| 725 | |
| 726 | } |
| 727 | |
| 728 | void |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 729 | ProcessInstanceInfoMatch::Clear() |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 730 | { |
| 731 | m_match_info.Clear(); |
| 732 | m_name_match_type = eNameMatchIgnore; |
| 733 | m_match_all_users = false; |
| 734 | } |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 735 | |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 736 | ProcessSP |
| 737 | 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] | 738 | { |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 739 | ProcessSP process_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 740 | ProcessCreateInstance create_callback = NULL; |
| 741 | if (plugin_name) |
| 742 | { |
| 743 | create_callback = PluginManager::GetProcessCreateCallbackForPluginName (plugin_name); |
| 744 | if (create_callback) |
| 745 | { |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 746 | process_sp = create_callback(target, listener, crash_file_path); |
| 747 | if (process_sp) |
| 748 | { |
| 749 | if (!process_sp->CanDebug(target, true)) |
| 750 | process_sp.reset(); |
| 751 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | else |
| 755 | { |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 756 | for (uint32_t idx = 0; (create_callback = PluginManager::GetProcessCreateCallbackAtIndex(idx)) != NULL; ++idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 757 | { |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 758 | process_sp = create_callback(target, listener, crash_file_path); |
| 759 | if (process_sp) |
| 760 | { |
| 761 | if (!process_sp->CanDebug(target, false)) |
| 762 | process_sp.reset(); |
| 763 | else |
| 764 | break; |
| 765 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 766 | } |
| 767 | } |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 768 | return process_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 771 | ConstString & |
| 772 | Process::GetStaticBroadcasterClass () |
| 773 | { |
| 774 | static ConstString class_name ("lldb.process"); |
| 775 | return class_name; |
| 776 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 777 | |
| 778 | //---------------------------------------------------------------------- |
| 779 | // Process constructor |
| 780 | //---------------------------------------------------------------------- |
| 781 | Process::Process(Target &target, Listener &listener) : |
| 782 | UserID (LLDB_INVALID_PROCESS_ID), |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 783 | Broadcaster (&(target.GetDebugger()), "lldb.process"), |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 784 | ProcessInstanceSettings (GetSettingsController()), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 785 | m_target (target), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 786 | m_public_state (eStateUnloaded), |
| 787 | m_private_state (eStateUnloaded), |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 788 | m_private_state_broadcaster (NULL, "lldb.process.internal_state_broadcaster"), |
| 789 | m_private_state_control_broadcaster (NULL, "lldb.process.internal_state_control_broadcaster"), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 790 | m_private_state_listener ("lldb.process.internal_state_listener"), |
| 791 | m_private_state_control_wait(), |
| 792 | m_private_state_thread (LLDB_INVALID_HOST_THREAD), |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 793 | m_mod_id (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 794 | m_thread_index_id (0), |
| 795 | m_exit_status (-1), |
| 796 | m_exit_string (), |
| 797 | m_thread_list (this), |
| 798 | m_notifications (), |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 799 | m_image_tokens (), |
| 800 | m_listener (listener), |
| 801 | m_breakpoint_site_list (), |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 802 | m_dynamic_checkers_ap (), |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 803 | m_unix_signals (), |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 804 | m_abi_sp (), |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 805 | m_process_input_reader (), |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 806 | m_stdio_communication ("process.stdio"), |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 807 | m_stdio_communication_mutex (Mutex::eMutexTypeRecursive), |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 808 | m_stdout_data (), |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 809 | m_stderr_data (), |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 810 | m_memory_cache (*this), |
| 811 | m_allocated_memory_cache (*this), |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 812 | m_should_detach (false), |
Sean Callanan | 9053945 | 2011-09-20 23:01:51 +0000 | [diff] [blame] | 813 | m_next_event_action_ap(), |
Bill Wendling | 7a4b007 | 2012-04-06 00:10:21 +0000 | [diff] [blame] | 814 | m_run_lock (), |
| 815 | m_can_jit(eCanJITDontKnow) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 816 | { |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 817 | UpdateInstanceName(); |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 818 | |
| 819 | CheckInWithManager (); |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 820 | |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 821 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 822 | if (log) |
| 823 | log->Printf ("%p Process::Process()", this); |
| 824 | |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 825 | SetEventName (eBroadcastBitStateChanged, "state-changed"); |
| 826 | SetEventName (eBroadcastBitInterrupt, "interrupt"); |
| 827 | SetEventName (eBroadcastBitSTDOUT, "stdout-available"); |
| 828 | SetEventName (eBroadcastBitSTDERR, "stderr-available"); |
| 829 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 830 | listener.StartListeningForEvents (this, |
| 831 | eBroadcastBitStateChanged | |
| 832 | eBroadcastBitInterrupt | |
| 833 | eBroadcastBitSTDOUT | |
| 834 | eBroadcastBitSTDERR); |
| 835 | |
| 836 | m_private_state_listener.StartListeningForEvents(&m_private_state_broadcaster, |
| 837 | eBroadcastBitStateChanged); |
| 838 | |
| 839 | m_private_state_listener.StartListeningForEvents(&m_private_state_control_broadcaster, |
| 840 | eBroadcastInternalStateControlStop | |
| 841 | eBroadcastInternalStateControlPause | |
| 842 | eBroadcastInternalStateControlResume); |
| 843 | } |
| 844 | |
| 845 | //---------------------------------------------------------------------- |
| 846 | // Destructor |
| 847 | //---------------------------------------------------------------------- |
| 848 | Process::~Process() |
| 849 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 850 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 851 | if (log) |
| 852 | log->Printf ("%p Process::~Process()", this); |
| 853 | StopPrivateStateThread(); |
| 854 | } |
| 855 | |
| 856 | void |
| 857 | Process::Finalize() |
| 858 | { |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 859 | switch (GetPrivateState()) |
| 860 | { |
| 861 | case eStateConnected: |
| 862 | case eStateAttaching: |
| 863 | case eStateLaunching: |
| 864 | case eStateStopped: |
| 865 | case eStateRunning: |
| 866 | case eStateStepping: |
| 867 | case eStateCrashed: |
| 868 | case eStateSuspended: |
| 869 | if (GetShouldDetach()) |
| 870 | Detach(); |
| 871 | else |
| 872 | Destroy(); |
| 873 | break; |
| 874 | |
| 875 | case eStateInvalid: |
| 876 | case eStateUnloaded: |
| 877 | case eStateDetached: |
| 878 | case eStateExited: |
| 879 | break; |
| 880 | } |
| 881 | |
Greg Clayton | 1ed54f5 | 2011-10-01 00:45:15 +0000 | [diff] [blame] | 882 | // Clear our broadcaster before we proceed with destroying |
| 883 | Broadcaster::Clear(); |
| 884 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 885 | // Do any cleanup needed prior to being destructed... Subclasses |
| 886 | // that override this method should call this superclass method as well. |
Jim Ingham | d0a3e12 | 2011-02-16 17:54:55 +0000 | [diff] [blame] | 887 | |
| 888 | // We need to destroy the loader before the derived Process class gets destroyed |
| 889 | // 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] | 890 | m_dynamic_checkers_ap.reset(); |
| 891 | m_abi_sp.reset(); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 892 | m_os_ap.reset(); |
Greg Clayton | 894f82f | 2012-01-20 23:08:34 +0000 | [diff] [blame] | 893 | m_dyld_ap.reset(); |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 894 | m_thread_list.Destroy(); |
Greg Clayton | 894f82f | 2012-01-20 23:08:34 +0000 | [diff] [blame] | 895 | std::vector<Notifications> empty_notifications; |
| 896 | m_notifications.swap(empty_notifications); |
| 897 | m_image_tokens.clear(); |
| 898 | m_memory_cache.Clear(); |
| 899 | m_allocated_memory_cache.Clear(); |
| 900 | m_language_runtimes.clear(); |
| 901 | m_next_event_action_ap.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | void |
| 905 | Process::RegisterNotificationCallbacks (const Notifications& callbacks) |
| 906 | { |
| 907 | m_notifications.push_back(callbacks); |
| 908 | if (callbacks.initialize != NULL) |
| 909 | callbacks.initialize (callbacks.baton, this); |
| 910 | } |
| 911 | |
| 912 | bool |
| 913 | Process::UnregisterNotificationCallbacks(const Notifications& callbacks) |
| 914 | { |
| 915 | std::vector<Notifications>::iterator pos, end = m_notifications.end(); |
| 916 | for (pos = m_notifications.begin(); pos != end; ++pos) |
| 917 | { |
| 918 | if (pos->baton == callbacks.baton && |
| 919 | pos->initialize == callbacks.initialize && |
| 920 | pos->process_state_changed == callbacks.process_state_changed) |
| 921 | { |
| 922 | m_notifications.erase(pos); |
| 923 | return true; |
| 924 | } |
| 925 | } |
| 926 | return false; |
| 927 | } |
| 928 | |
| 929 | void |
| 930 | Process::SynchronouslyNotifyStateChanged (StateType state) |
| 931 | { |
| 932 | std::vector<Notifications>::iterator notification_pos, notification_end = m_notifications.end(); |
| 933 | for (notification_pos = m_notifications.begin(); notification_pos != notification_end; ++notification_pos) |
| 934 | { |
| 935 | if (notification_pos->process_state_changed) |
| 936 | notification_pos->process_state_changed (notification_pos->baton, this, state); |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | // FIXME: We need to do some work on events before the general Listener sees them. |
| 941 | // For instance if we are continuing from a breakpoint, we need to ensure that we do |
| 942 | // the little "insert real insn, step & stop" trick. But we can't do that when the |
| 943 | // event is delivered by the broadcaster - since that is done on the thread that is |
| 944 | // waiting for new events, so if we needed more than one event for our handling, we would |
| 945 | // stall. So instead we do it when we fetch the event off of the queue. |
| 946 | // |
| 947 | |
| 948 | StateType |
| 949 | Process::GetNextEvent (EventSP &event_sp) |
| 950 | { |
| 951 | StateType state = eStateInvalid; |
| 952 | |
| 953 | if (m_listener.GetNextEventForBroadcaster (this, event_sp) && event_sp) |
| 954 | state = Process::ProcessEventData::GetStateFromEvent (event_sp.get()); |
| 955 | |
| 956 | return state; |
| 957 | } |
| 958 | |
| 959 | |
| 960 | StateType |
| 961 | Process::WaitForProcessToStop (const TimeValue *timeout) |
| 962 | { |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 963 | // We can't just wait for a "stopped" event, because the stopped event may have restarted the target. |
| 964 | // We have to actually check each event, and in the case of a stopped event check the restarted flag |
| 965 | // on the event. |
| 966 | EventSP event_sp; |
| 967 | StateType state = GetState(); |
| 968 | // If we are exited or detached, we won't ever get back to any |
| 969 | // other valid state... |
| 970 | if (state == eStateDetached || state == eStateExited) |
| 971 | return state; |
| 972 | |
| 973 | while (state != eStateInvalid) |
| 974 | { |
| 975 | state = WaitForStateChangedEvents (timeout, event_sp); |
| 976 | switch (state) |
| 977 | { |
| 978 | case eStateCrashed: |
| 979 | case eStateDetached: |
| 980 | case eStateExited: |
| 981 | case eStateUnloaded: |
| 982 | return state; |
| 983 | case eStateStopped: |
| 984 | if (Process::ProcessEventData::GetRestartedFromEvent(event_sp.get())) |
| 985 | continue; |
| 986 | else |
| 987 | return state; |
| 988 | default: |
| 989 | continue; |
| 990 | } |
| 991 | } |
| 992 | return state; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | |
| 996 | StateType |
| 997 | Process::WaitForState |
| 998 | ( |
| 999 | const TimeValue *timeout, |
| 1000 | const StateType *match_states, const uint32_t num_match_states |
| 1001 | ) |
| 1002 | { |
| 1003 | EventSP event_sp; |
| 1004 | uint32_t i; |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 1005 | StateType state = GetState(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1006 | while (state != eStateInvalid) |
| 1007 | { |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 1008 | // If we are exited or detached, we won't ever get back to any |
| 1009 | // other valid state... |
| 1010 | if (state == eStateDetached || state == eStateExited) |
| 1011 | return state; |
| 1012 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1013 | state = WaitForStateChangedEvents (timeout, event_sp); |
| 1014 | |
| 1015 | for (i=0; i<num_match_states; ++i) |
| 1016 | { |
| 1017 | if (match_states[i] == state) |
| 1018 | return state; |
| 1019 | } |
| 1020 | } |
| 1021 | return state; |
| 1022 | } |
| 1023 | |
Jim Ingham | 30f9b21 | 2010-10-11 23:53:14 +0000 | [diff] [blame] | 1024 | bool |
| 1025 | Process::HijackProcessEvents (Listener *listener) |
| 1026 | { |
| 1027 | if (listener != NULL) |
| 1028 | { |
| 1029 | return HijackBroadcaster(listener, eBroadcastBitStateChanged); |
| 1030 | } |
| 1031 | else |
| 1032 | return false; |
| 1033 | } |
| 1034 | |
| 1035 | void |
| 1036 | Process::RestoreProcessEvents () |
| 1037 | { |
| 1038 | RestoreBroadcaster(); |
| 1039 | } |
| 1040 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 1041 | bool |
| 1042 | Process::HijackPrivateProcessEvents (Listener *listener) |
| 1043 | { |
| 1044 | if (listener != NULL) |
| 1045 | { |
| 1046 | return m_private_state_broadcaster.HijackBroadcaster(listener, eBroadcastBitStateChanged); |
| 1047 | } |
| 1048 | else |
| 1049 | return false; |
| 1050 | } |
| 1051 | |
| 1052 | void |
| 1053 | Process::RestorePrivateProcessEvents () |
| 1054 | { |
| 1055 | m_private_state_broadcaster.RestoreBroadcaster(); |
| 1056 | } |
| 1057 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1058 | StateType |
| 1059 | Process::WaitForStateChangedEvents (const TimeValue *timeout, EventSP &event_sp) |
| 1060 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1061 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1062 | |
| 1063 | if (log) |
| 1064 | log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, timeout); |
| 1065 | |
| 1066 | StateType state = eStateInvalid; |
Greg Clayton | 3fcbed6 | 2010-10-19 03:25:40 +0000 | [diff] [blame] | 1067 | if (m_listener.WaitForEventForBroadcasterWithType (timeout, |
| 1068 | this, |
| 1069 | eBroadcastBitStateChanged, |
| 1070 | event_sp)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1071 | state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 1072 | |
| 1073 | if (log) |
| 1074 | log->Printf ("Process::%s (timeout = %p, event_sp) => %s", |
| 1075 | __FUNCTION__, |
| 1076 | timeout, |
| 1077 | StateAsCString(state)); |
| 1078 | return state; |
| 1079 | } |
| 1080 | |
| 1081 | Event * |
| 1082 | Process::PeekAtStateChangedEvents () |
| 1083 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1084 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1085 | |
| 1086 | if (log) |
| 1087 | log->Printf ("Process::%s...", __FUNCTION__); |
| 1088 | |
| 1089 | Event *event_ptr; |
Greg Clayton | 3fcbed6 | 2010-10-19 03:25:40 +0000 | [diff] [blame] | 1090 | event_ptr = m_listener.PeekAtNextEventForBroadcasterWithType (this, |
| 1091 | eBroadcastBitStateChanged); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1092 | if (log) |
| 1093 | { |
| 1094 | if (event_ptr) |
| 1095 | { |
| 1096 | log->Printf ("Process::%s (event_ptr) => %s", |
| 1097 | __FUNCTION__, |
| 1098 | StateAsCString(ProcessEventData::GetStateFromEvent (event_ptr))); |
| 1099 | } |
| 1100 | else |
| 1101 | { |
| 1102 | log->Printf ("Process::%s no events found", |
| 1103 | __FUNCTION__); |
| 1104 | } |
| 1105 | } |
| 1106 | return event_ptr; |
| 1107 | } |
| 1108 | |
| 1109 | StateType |
| 1110 | Process::WaitForStateChangedEventsPrivate (const TimeValue *timeout, EventSP &event_sp) |
| 1111 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1112 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1113 | |
| 1114 | if (log) |
| 1115 | log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, timeout); |
| 1116 | |
| 1117 | StateType state = eStateInvalid; |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1118 | if (m_private_state_listener.WaitForEventForBroadcasterWithType (timeout, |
| 1119 | &m_private_state_broadcaster, |
| 1120 | eBroadcastBitStateChanged, |
| 1121 | event_sp)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1122 | state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 1123 | |
| 1124 | // This is a bit of a hack, but when we wait here we could very well return |
| 1125 | // to the command-line, and that could disable the log, which would render the |
| 1126 | // log we got above invalid. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1127 | if (log) |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1128 | { |
| 1129 | if (state == eStateInvalid) |
| 1130 | log->Printf ("Process::%s (timeout = %p, event_sp) => TIMEOUT", __FUNCTION__, timeout); |
| 1131 | else |
| 1132 | log->Printf ("Process::%s (timeout = %p, event_sp) => %s", __FUNCTION__, timeout, StateAsCString(state)); |
| 1133 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1134 | return state; |
| 1135 | } |
| 1136 | |
| 1137 | bool |
| 1138 | Process::WaitForEventsPrivate (const TimeValue *timeout, EventSP &event_sp, bool control_only) |
| 1139 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1140 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1141 | |
| 1142 | if (log) |
| 1143 | log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, timeout); |
| 1144 | |
| 1145 | if (control_only) |
| 1146 | return m_private_state_listener.WaitForEventForBroadcaster(timeout, &m_private_state_control_broadcaster, event_sp); |
| 1147 | else |
| 1148 | return m_private_state_listener.WaitForEvent(timeout, event_sp); |
| 1149 | } |
| 1150 | |
| 1151 | bool |
| 1152 | Process::IsRunning () const |
| 1153 | { |
| 1154 | return StateIsRunningState (m_public_state.GetValue()); |
| 1155 | } |
| 1156 | |
| 1157 | int |
| 1158 | Process::GetExitStatus () |
| 1159 | { |
| 1160 | if (m_public_state.GetValue() == eStateExited) |
| 1161 | return m_exit_status; |
| 1162 | return -1; |
| 1163 | } |
| 1164 | |
Greg Clayton | 85851dd | 2010-12-04 00:10:17 +0000 | [diff] [blame] | 1165 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1166 | const char * |
| 1167 | Process::GetExitDescription () |
| 1168 | { |
| 1169 | if (m_public_state.GetValue() == eStateExited && !m_exit_string.empty()) |
| 1170 | return m_exit_string.c_str(); |
| 1171 | return NULL; |
| 1172 | } |
| 1173 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1174 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1175 | Process::SetExitStatus (int status, const char *cstr) |
| 1176 | { |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 1177 | LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS)); |
| 1178 | if (log) |
| 1179 | log->Printf("Process::SetExitStatus (status=%i (0x%8.8x), description=%s%s%s)", |
| 1180 | status, status, |
| 1181 | cstr ? "\"" : "", |
| 1182 | cstr ? cstr : "NULL", |
| 1183 | cstr ? "\"" : ""); |
| 1184 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1185 | // We were already in the exited state |
| 1186 | if (m_private_state.GetValue() == eStateExited) |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 1187 | { |
Greg Clayton | 385d603 | 2011-01-26 23:47:29 +0000 | [diff] [blame] | 1188 | if (log) |
| 1189 | 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] | 1190 | return false; |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 1191 | } |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1192 | |
| 1193 | m_exit_status = status; |
| 1194 | if (cstr) |
| 1195 | m_exit_string = cstr; |
| 1196 | else |
| 1197 | m_exit_string.clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1198 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1199 | DidExit (); |
Greg Clayton | 10177aa | 2010-12-08 05:08:21 +0000 | [diff] [blame] | 1200 | |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 1201 | SetPrivateState (eStateExited); |
| 1202 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | // This static callback can be used to watch for local child processes on |
| 1206 | // the current host. The the child process exits, the process will be |
| 1207 | // found in the global target list (we want to be completely sure that the |
| 1208 | // lldb_private::Process doesn't go away before we can deliver the signal. |
| 1209 | bool |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 1210 | Process::SetProcessExitStatus (void *callback_baton, |
| 1211 | lldb::pid_t pid, |
| 1212 | bool exited, |
| 1213 | int signo, // Zero for no signal |
| 1214 | int exit_status // Exit value of process if signal is zero |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1215 | ) |
| 1216 | { |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 1217 | LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 1218 | if (log) |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 1219 | log->Printf ("Process::SetProcessExitStatus (baton=%p, pid=%llu, exited=%i, signal=%i, exit_status=%i)\n", |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 1220 | callback_baton, |
| 1221 | pid, |
| 1222 | exited, |
| 1223 | signo, |
| 1224 | exit_status); |
| 1225 | |
| 1226 | if (exited) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1227 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1228 | TargetSP target_sp(Debugger::FindTargetWithProcessID (pid)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1229 | if (target_sp) |
| 1230 | { |
| 1231 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 1232 | if (process_sp) |
| 1233 | { |
| 1234 | const char *signal_cstr = NULL; |
| 1235 | if (signo) |
| 1236 | signal_cstr = process_sp->GetUnixSignals().GetSignalAsCString (signo); |
| 1237 | |
| 1238 | process_sp->SetExitStatus (exit_status, signal_cstr); |
| 1239 | } |
| 1240 | } |
| 1241 | return true; |
| 1242 | } |
| 1243 | return false; |
| 1244 | } |
| 1245 | |
| 1246 | |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1247 | void |
| 1248 | Process::UpdateThreadListIfNeeded () |
| 1249 | { |
| 1250 | const uint32_t stop_id = GetStopID(); |
| 1251 | if (m_thread_list.GetSize(false) == 0 || stop_id != m_thread_list.GetStopID()) |
| 1252 | { |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 1253 | const StateType state = GetPrivateState(); |
| 1254 | if (StateIsStoppedState (state, true)) |
| 1255 | { |
| 1256 | Mutex::Locker locker (m_thread_list.GetMutex ()); |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 1257 | // m_thread_list does have its own mutex, but we need to |
| 1258 | // hold onto the mutex between the call to UpdateThreadList(...) |
| 1259 | // and the os->UpdateThreadList(...) so it doesn't change on us |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 1260 | ThreadList new_thread_list(this); |
| 1261 | // Always update the thread list with the protocol specific |
Greg Clayton | 9fc1355 | 2012-04-10 00:18:59 +0000 | [diff] [blame] | 1262 | // thread list, but only update if "true" is returned |
| 1263 | if (UpdateThreadList (m_thread_list, new_thread_list)) |
| 1264 | { |
| 1265 | OperatingSystem *os = GetOperatingSystem (); |
| 1266 | if (os) |
| 1267 | os->UpdateThreadList (m_thread_list, new_thread_list); |
| 1268 | m_thread_list.Update (new_thread_list); |
| 1269 | m_thread_list.SetStopID (stop_id); |
| 1270 | } |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 1271 | } |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1272 | } |
| 1273 | } |
| 1274 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1275 | uint32_t |
| 1276 | Process::GetNextThreadIndexID () |
| 1277 | { |
| 1278 | return ++m_thread_index_id; |
| 1279 | } |
| 1280 | |
| 1281 | StateType |
| 1282 | Process::GetState() |
| 1283 | { |
| 1284 | // If any other threads access this we will need a mutex for it |
| 1285 | return m_public_state.GetValue (); |
| 1286 | } |
| 1287 | |
| 1288 | void |
| 1289 | Process::SetPublicState (StateType new_state) |
| 1290 | { |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 1291 | LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1292 | if (log) |
| 1293 | log->Printf("Process::SetPublicState (%s)", StateAsCString(new_state)); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1294 | const StateType old_state = m_public_state.GetValue(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1295 | m_public_state.SetValue (new_state); |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 1296 | |
| 1297 | // On the transition from Run to Stopped, we unlock the writer end of the |
| 1298 | // run lock. The lock gets locked in Resume, which is the public API |
| 1299 | // to tell the program to run. |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1300 | if (!IsHijackedForEvent(eBroadcastBitStateChanged)) |
| 1301 | { |
| 1302 | const bool old_state_is_stopped = StateIsStoppedState(old_state, false); |
| 1303 | const bool new_state_is_stopped = StateIsStoppedState(new_state, false); |
| 1304 | if (old_state_is_stopped != new_state_is_stopped) |
| 1305 | { |
| 1306 | if (new_state_is_stopped) |
| 1307 | { |
| 1308 | if (log) |
| 1309 | log->Printf("Process::SetPublicState (%s) -- unlocking run lock", StateAsCString(new_state)); |
| 1310 | m_run_lock.WriteUnlock(); |
| 1311 | } |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1312 | } |
| 1313 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1314 | } |
| 1315 | |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 1316 | Error |
| 1317 | Process::Resume () |
| 1318 | { |
| 1319 | LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS)); |
| 1320 | if (log) |
| 1321 | log->Printf("Process::Resume -- locking run lock"); |
| 1322 | if (!m_run_lock.WriteTryLock()) |
| 1323 | { |
| 1324 | Error error("Resume request failed - process still running."); |
| 1325 | if (log) |
| 1326 | log->Printf ("Process::Resume: -- WriteTryLock failed, not resuming."); |
| 1327 | return error; |
| 1328 | } |
| 1329 | return PrivateResume(); |
| 1330 | } |
| 1331 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1332 | StateType |
| 1333 | Process::GetPrivateState () |
| 1334 | { |
| 1335 | return m_private_state.GetValue(); |
| 1336 | } |
| 1337 | |
| 1338 | void |
| 1339 | Process::SetPrivateState (StateType new_state) |
| 1340 | { |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 1341 | LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STATE | LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1342 | bool state_changed = false; |
| 1343 | |
| 1344 | if (log) |
| 1345 | log->Printf("Process::SetPrivateState (%s)", StateAsCString(new_state)); |
| 1346 | |
| 1347 | Mutex::Locker locker(m_private_state.GetMutex()); |
| 1348 | |
| 1349 | const StateType old_state = m_private_state.GetValueNoLock (); |
| 1350 | state_changed = old_state != new_state; |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 1351 | // This code is left commented out in case we ever need to control |
| 1352 | // the private process state with another run lock. Right now it doesn't |
| 1353 | // seem like we need to do this, but if we ever do, we can uncomment and |
| 1354 | // use this code. |
| 1355 | // const bool old_state_is_stopped = StateIsStoppedState(old_state, false); |
| 1356 | // const bool new_state_is_stopped = StateIsStoppedState(new_state, false); |
| 1357 | // if (old_state_is_stopped != new_state_is_stopped) |
| 1358 | // { |
| 1359 | // if (new_state_is_stopped) |
| 1360 | // m_private_run_lock.WriteUnlock(); |
| 1361 | // else |
| 1362 | // m_private_run_lock.WriteLock(); |
| 1363 | // } |
| 1364 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1365 | if (state_changed) |
| 1366 | { |
| 1367 | m_private_state.SetValueNoLock (new_state); |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 1368 | if (StateIsStoppedState(new_state, false)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1369 | { |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1370 | m_mod_id.BumpStopID(); |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 1371 | m_memory_cache.Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1372 | if (log) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 1373 | 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] | 1374 | } |
| 1375 | // Use our target to get a shared pointer to ourselves... |
| 1376 | m_private_state_broadcaster.BroadcastEvent (eBroadcastBitStateChanged, new ProcessEventData (GetTarget().GetProcessSP(), new_state)); |
| 1377 | } |
| 1378 | else |
| 1379 | { |
| 1380 | if (log) |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 1381 | 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] | 1382 | } |
| 1383 | } |
| 1384 | |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 1385 | void |
| 1386 | Process::SetRunningUserExpression (bool on) |
| 1387 | { |
| 1388 | m_mod_id.SetRunningUserExpression (on); |
| 1389 | } |
| 1390 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1391 | addr_t |
| 1392 | Process::GetImageInfoAddress() |
| 1393 | { |
| 1394 | return LLDB_INVALID_ADDRESS; |
| 1395 | } |
| 1396 | |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1397 | //---------------------------------------------------------------------- |
| 1398 | // LoadImage |
| 1399 | // |
| 1400 | // This function provides a default implementation that works for most |
| 1401 | // unix variants. Any Process subclasses that need to do shared library |
| 1402 | // loading differently should override LoadImage and UnloadImage and |
| 1403 | // do what is needed. |
| 1404 | //---------------------------------------------------------------------- |
| 1405 | uint32_t |
| 1406 | Process::LoadImage (const FileSpec &image_spec, Error &error) |
| 1407 | { |
Greg Clayton | ac7a3db | 2012-04-18 00:05:19 +0000 | [diff] [blame] | 1408 | char path[PATH_MAX]; |
| 1409 | image_spec.GetPath(path, sizeof(path)); |
| 1410 | |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1411 | DynamicLoader *loader = GetDynamicLoader(); |
| 1412 | if (loader) |
| 1413 | { |
| 1414 | error = loader->CanLoadImage(); |
| 1415 | if (error.Fail()) |
| 1416 | return LLDB_INVALID_IMAGE_TOKEN; |
| 1417 | } |
| 1418 | |
| 1419 | if (error.Success()) |
| 1420 | { |
| 1421 | ThreadSP thread_sp(GetThreadList ().GetSelectedThread()); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1422 | |
| 1423 | if (thread_sp) |
| 1424 | { |
| 1425 | StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex (0)); |
| 1426 | |
| 1427 | if (frame_sp) |
| 1428 | { |
| 1429 | ExecutionContext exe_ctx; |
| 1430 | frame_sp->CalculateExecutionContext (exe_ctx); |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1431 | bool unwind_on_error = true; |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1432 | StreamString expr; |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1433 | expr.Printf("dlopen (\"%s\", 2)", path); |
| 1434 | const char *prefix = "extern \"C\" void* dlopen (const char *path, int mode);\n"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 1435 | lldb::ValueObjectSP result_valobj_sp; |
Sean Callanan | 20bb3aa | 2011-12-21 22:22:58 +0000 | [diff] [blame] | 1436 | ClangUserExpression::Evaluate (exe_ctx, eExecutionPolicyAlways, lldb::eLanguageTypeUnknown, ClangUserExpression::eResultTypeAny, unwind_on_error, expr.GetData(), prefix, result_valobj_sp); |
Johnny Chen | e92aa43 | 2011-09-09 00:01:43 +0000 | [diff] [blame] | 1437 | error = result_valobj_sp->GetError(); |
| 1438 | if (error.Success()) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1439 | { |
| 1440 | Scalar scalar; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1441 | if (result_valobj_sp->ResolveValue (scalar)) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1442 | { |
| 1443 | addr_t image_ptr = scalar.ULongLong(LLDB_INVALID_ADDRESS); |
| 1444 | if (image_ptr != 0 && image_ptr != LLDB_INVALID_ADDRESS) |
| 1445 | { |
| 1446 | uint32_t image_token = m_image_tokens.size(); |
| 1447 | m_image_tokens.push_back (image_ptr); |
| 1448 | return image_token; |
| 1449 | } |
| 1450 | } |
| 1451 | } |
| 1452 | } |
| 1453 | } |
| 1454 | } |
Greg Clayton | ac7a3db | 2012-04-18 00:05:19 +0000 | [diff] [blame] | 1455 | if (!error.AsCString()) |
| 1456 | error.SetErrorStringWithFormat("unable to load '%s'", path); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1457 | return LLDB_INVALID_IMAGE_TOKEN; |
| 1458 | } |
| 1459 | |
| 1460 | //---------------------------------------------------------------------- |
| 1461 | // UnloadImage |
| 1462 | // |
| 1463 | // This function provides a default implementation that works for most |
| 1464 | // unix variants. Any Process subclasses that need to do shared library |
| 1465 | // loading differently should override LoadImage and UnloadImage and |
| 1466 | // do what is needed. |
| 1467 | //---------------------------------------------------------------------- |
| 1468 | Error |
| 1469 | Process::UnloadImage (uint32_t image_token) |
| 1470 | { |
| 1471 | Error error; |
| 1472 | if (image_token < m_image_tokens.size()) |
| 1473 | { |
| 1474 | const addr_t image_addr = m_image_tokens[image_token]; |
| 1475 | if (image_addr == LLDB_INVALID_ADDRESS) |
| 1476 | { |
| 1477 | error.SetErrorString("image already unloaded"); |
| 1478 | } |
| 1479 | else |
| 1480 | { |
| 1481 | DynamicLoader *loader = GetDynamicLoader(); |
| 1482 | if (loader) |
| 1483 | error = loader->CanLoadImage(); |
| 1484 | |
| 1485 | if (error.Success()) |
| 1486 | { |
| 1487 | ThreadSP thread_sp(GetThreadList ().GetSelectedThread()); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1488 | |
| 1489 | if (thread_sp) |
| 1490 | { |
| 1491 | StackFrameSP frame_sp (thread_sp->GetStackFrameAtIndex (0)); |
| 1492 | |
| 1493 | if (frame_sp) |
| 1494 | { |
| 1495 | ExecutionContext exe_ctx; |
| 1496 | frame_sp->CalculateExecutionContext (exe_ctx); |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1497 | bool unwind_on_error = true; |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1498 | StreamString expr; |
| 1499 | expr.Printf("dlclose ((void *)0x%llx)", image_addr); |
| 1500 | const char *prefix = "extern \"C\" int dlclose(void* handle);\n"; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 1501 | lldb::ValueObjectSP result_valobj_sp; |
Sean Callanan | 20bb3aa | 2011-12-21 22:22:58 +0000 | [diff] [blame] | 1502 | ClangUserExpression::Evaluate (exe_ctx, eExecutionPolicyAlways, lldb::eLanguageTypeUnknown, ClangUserExpression::eResultTypeAny, unwind_on_error, expr.GetData(), prefix, result_valobj_sp); |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1503 | if (result_valobj_sp->GetError().Success()) |
| 1504 | { |
| 1505 | Scalar scalar; |
Jim Ingham | 6035b67 | 2011-03-31 00:19:25 +0000 | [diff] [blame] | 1506 | if (result_valobj_sp->ResolveValue (scalar)) |
Greg Clayton | 8f343b0 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1507 | { |
| 1508 | if (scalar.UInt(1)) |
| 1509 | { |
| 1510 | error.SetErrorStringWithFormat("expression failed: \"%s\"", expr.GetData()); |
| 1511 | } |
| 1512 | else |
| 1513 | { |
| 1514 | m_image_tokens[image_token] = LLDB_INVALID_ADDRESS; |
| 1515 | } |
| 1516 | } |
| 1517 | } |
| 1518 | else |
| 1519 | { |
| 1520 | error = result_valobj_sp->GetError(); |
| 1521 | } |
| 1522 | } |
| 1523 | } |
| 1524 | } |
| 1525 | } |
| 1526 | } |
| 1527 | else |
| 1528 | { |
| 1529 | error.SetErrorString("invalid image token"); |
| 1530 | } |
| 1531 | return error; |
| 1532 | } |
| 1533 | |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 1534 | const lldb::ABISP & |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1535 | Process::GetABI() |
| 1536 | { |
Greg Clayton | 31f1d2f | 2011-05-11 18:39:18 +0000 | [diff] [blame] | 1537 | if (!m_abi_sp) |
| 1538 | m_abi_sp = ABI::FindPlugin(m_target.GetArchitecture()); |
| 1539 | return m_abi_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1542 | LanguageRuntime * |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1543 | Process::GetLanguageRuntime(lldb::LanguageType language, bool retry_if_null) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1544 | { |
| 1545 | LanguageRuntimeCollection::iterator pos; |
| 1546 | pos = m_language_runtimes.find (language); |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1547 | if (pos == m_language_runtimes.end() || (retry_if_null && !(*pos).second)) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1548 | { |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1549 | lldb::LanguageRuntimeSP runtime_sp(LanguageRuntime::FindPlugin(this, language)); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1550 | |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1551 | m_language_runtimes[language] = runtime_sp; |
| 1552 | return runtime_sp.get(); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1553 | } |
| 1554 | else |
| 1555 | return (*pos).second.get(); |
| 1556 | } |
| 1557 | |
| 1558 | CPPLanguageRuntime * |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1559 | Process::GetCPPLanguageRuntime (bool retry_if_null) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1560 | { |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1561 | LanguageRuntime *runtime = GetLanguageRuntime(eLanguageTypeC_plus_plus, retry_if_null); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1562 | if (runtime != NULL && runtime->GetLanguageType() == eLanguageTypeC_plus_plus) |
| 1563 | return static_cast<CPPLanguageRuntime *> (runtime); |
| 1564 | return NULL; |
| 1565 | } |
| 1566 | |
| 1567 | ObjCLanguageRuntime * |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1568 | Process::GetObjCLanguageRuntime (bool retry_if_null) |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1569 | { |
Jim Ingham | ab17524 | 2012-03-10 00:22:19 +0000 | [diff] [blame] | 1570 | LanguageRuntime *runtime = GetLanguageRuntime(eLanguageTypeObjC, retry_if_null); |
Jim Ingham | 2277701 | 2010-09-23 02:01:19 +0000 | [diff] [blame] | 1571 | if (runtime != NULL && runtime->GetLanguageType() == eLanguageTypeObjC) |
| 1572 | return static_cast<ObjCLanguageRuntime *> (runtime); |
| 1573 | return NULL; |
| 1574 | } |
| 1575 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1576 | BreakpointSiteList & |
| 1577 | Process::GetBreakpointSiteList() |
| 1578 | { |
| 1579 | return m_breakpoint_site_list; |
| 1580 | } |
| 1581 | |
| 1582 | const BreakpointSiteList & |
| 1583 | Process::GetBreakpointSiteList() const |
| 1584 | { |
| 1585 | return m_breakpoint_site_list; |
| 1586 | } |
| 1587 | |
| 1588 | |
| 1589 | void |
| 1590 | Process::DisableAllBreakpointSites () |
| 1591 | { |
| 1592 | m_breakpoint_site_list.SetEnabledForAll (false); |
| 1593 | } |
| 1594 | |
| 1595 | Error |
| 1596 | Process::ClearBreakpointSiteByID (lldb::user_id_t break_id) |
| 1597 | { |
| 1598 | Error error (DisableBreakpointSiteByID (break_id)); |
| 1599 | |
| 1600 | if (error.Success()) |
| 1601 | m_breakpoint_site_list.Remove(break_id); |
| 1602 | |
| 1603 | return error; |
| 1604 | } |
| 1605 | |
| 1606 | Error |
| 1607 | Process::DisableBreakpointSiteByID (lldb::user_id_t break_id) |
| 1608 | { |
| 1609 | Error error; |
| 1610 | BreakpointSiteSP bp_site_sp = m_breakpoint_site_list.FindByID (break_id); |
| 1611 | if (bp_site_sp) |
| 1612 | { |
| 1613 | if (bp_site_sp->IsEnabled()) |
| 1614 | error = DisableBreakpoint (bp_site_sp.get()); |
| 1615 | } |
| 1616 | else |
| 1617 | { |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1618 | error.SetErrorStringWithFormat("invalid breakpoint site ID: %llu", break_id); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | return error; |
| 1622 | } |
| 1623 | |
| 1624 | Error |
| 1625 | Process::EnableBreakpointSiteByID (lldb::user_id_t break_id) |
| 1626 | { |
| 1627 | Error error; |
| 1628 | BreakpointSiteSP bp_site_sp = m_breakpoint_site_list.FindByID (break_id); |
| 1629 | if (bp_site_sp) |
| 1630 | { |
| 1631 | if (!bp_site_sp->IsEnabled()) |
| 1632 | error = EnableBreakpoint (bp_site_sp.get()); |
| 1633 | } |
| 1634 | else |
| 1635 | { |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1636 | error.SetErrorStringWithFormat("invalid breakpoint site ID: %llu", break_id); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1637 | } |
| 1638 | return error; |
| 1639 | } |
| 1640 | |
Stephen Wilson | 50bd94f | 2010-07-17 00:56:13 +0000 | [diff] [blame] | 1641 | lldb::break_id_t |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 1642 | Process::CreateBreakpointSite (const BreakpointLocationSP &owner, bool use_hardware) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1643 | { |
Greg Clayton | 92bb12c | 2011-05-19 18:17:41 +0000 | [diff] [blame] | 1644 | const addr_t load_addr = owner->GetAddress().GetOpcodeLoadAddress (&m_target); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1645 | if (load_addr != LLDB_INVALID_ADDRESS) |
| 1646 | { |
| 1647 | BreakpointSiteSP bp_site_sp; |
| 1648 | |
| 1649 | // Look up this breakpoint site. If it exists, then add this new owner, otherwise |
| 1650 | // create a new breakpoint site and add it. |
| 1651 | |
| 1652 | bp_site_sp = m_breakpoint_site_list.FindByAddress (load_addr); |
| 1653 | |
| 1654 | if (bp_site_sp) |
| 1655 | { |
| 1656 | bp_site_sp->AddOwner (owner); |
| 1657 | owner->SetBreakpointSite (bp_site_sp); |
| 1658 | return bp_site_sp->GetID(); |
| 1659 | } |
| 1660 | else |
| 1661 | { |
| 1662 | bp_site_sp.reset (new BreakpointSite (&m_breakpoint_site_list, owner, load_addr, LLDB_INVALID_THREAD_ID, use_hardware)); |
| 1663 | if (bp_site_sp) |
| 1664 | { |
| 1665 | if (EnableBreakpoint (bp_site_sp.get()).Success()) |
| 1666 | { |
| 1667 | owner->SetBreakpointSite (bp_site_sp); |
| 1668 | return m_breakpoint_site_list.Add (bp_site_sp); |
| 1669 | } |
| 1670 | } |
| 1671 | } |
| 1672 | } |
| 1673 | // We failed to enable the breakpoint |
| 1674 | return LLDB_INVALID_BREAK_ID; |
| 1675 | |
| 1676 | } |
| 1677 | |
| 1678 | void |
| 1679 | Process::RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id, lldb::user_id_t owner_loc_id, BreakpointSiteSP &bp_site_sp) |
| 1680 | { |
| 1681 | uint32_t num_owners = bp_site_sp->RemoveOwner (owner_id, owner_loc_id); |
| 1682 | if (num_owners == 0) |
| 1683 | { |
| 1684 | DisableBreakpoint(bp_site_sp.get()); |
| 1685 | m_breakpoint_site_list.RemoveByAddress(bp_site_sp->GetLoadAddress()); |
| 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | |
| 1690 | size_t |
| 1691 | Process::RemoveBreakpointOpcodesFromBuffer (addr_t bp_addr, size_t size, uint8_t *buf) const |
| 1692 | { |
| 1693 | size_t bytes_removed = 0; |
| 1694 | addr_t intersect_addr; |
| 1695 | size_t intersect_size; |
| 1696 | size_t opcode_offset; |
| 1697 | size_t idx; |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1698 | BreakpointSiteSP bp_sp; |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 1699 | BreakpointSiteList bp_sites_in_range; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1700 | |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 1701 | 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] | 1702 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1703 | for (idx = 0; (bp_sp = bp_sites_in_range.GetByIndex(idx)); ++idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1704 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1705 | if (bp_sp->GetType() == BreakpointSite::eSoftware) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1706 | { |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1707 | if (bp_sp->IntersectsRange(bp_addr, size, &intersect_addr, &intersect_size, &opcode_offset)) |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 1708 | { |
| 1709 | assert(bp_addr <= intersect_addr && intersect_addr < bp_addr + size); |
| 1710 | assert(bp_addr < intersect_addr + intersect_size && intersect_addr + intersect_size <= bp_addr + size); |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1711 | assert(opcode_offset + intersect_size <= bp_sp->GetByteSize()); |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 1712 | size_t buf_offset = intersect_addr - bp_addr; |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1713 | ::memcpy(buf + buf_offset, bp_sp->GetSavedOpcodeBytes() + opcode_offset, intersect_size); |
Jim Ingham | 20c7719 | 2011-06-29 19:42:28 +0000 | [diff] [blame] | 1714 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1715 | } |
| 1716 | } |
| 1717 | } |
| 1718 | return bytes_removed; |
| 1719 | } |
| 1720 | |
| 1721 | |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 1722 | |
| 1723 | size_t |
| 1724 | Process::GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site) |
| 1725 | { |
| 1726 | PlatformSP platform_sp (m_target.GetPlatform()); |
| 1727 | if (platform_sp) |
| 1728 | return platform_sp->GetSoftwareBreakpointTrapOpcode (m_target, bp_site); |
| 1729 | return 0; |
| 1730 | } |
| 1731 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1732 | Error |
| 1733 | Process::EnableSoftwareBreakpoint (BreakpointSite *bp_site) |
| 1734 | { |
| 1735 | Error error; |
| 1736 | assert (bp_site != NULL); |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1737 | LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1738 | const addr_t bp_addr = bp_site->GetLoadAddress(); |
| 1739 | if (log) |
| 1740 | log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%llx", bp_site->GetID(), (uint64_t)bp_addr); |
| 1741 | if (bp_site->IsEnabled()) |
| 1742 | { |
| 1743 | if (log) |
| 1744 | log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- already enabled", bp_site->GetID(), (uint64_t)bp_addr); |
| 1745 | return error; |
| 1746 | } |
| 1747 | |
| 1748 | if (bp_addr == LLDB_INVALID_ADDRESS) |
| 1749 | { |
| 1750 | error.SetErrorString("BreakpointSite contains an invalid load address."); |
| 1751 | return error; |
| 1752 | } |
| 1753 | // Ask the lldb::Process subclass to fill in the correct software breakpoint |
| 1754 | // trap for the breakpoint site |
| 1755 | const size_t bp_opcode_size = GetSoftwareBreakpointTrapOpcode(bp_site); |
| 1756 | |
| 1757 | if (bp_opcode_size == 0) |
| 1758 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 1759 | error.SetErrorStringWithFormat ("Process::GetSoftwareBreakpointTrapOpcode() returned zero, unable to get breakpoint trap for address 0x%llx", bp_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1760 | } |
| 1761 | else |
| 1762 | { |
| 1763 | const uint8_t * const bp_opcode_bytes = bp_site->GetTrapOpcodeBytes(); |
| 1764 | |
| 1765 | if (bp_opcode_bytes == NULL) |
| 1766 | { |
| 1767 | error.SetErrorString ("BreakpointSite doesn't contain a valid breakpoint trap opcode."); |
| 1768 | return error; |
| 1769 | } |
| 1770 | |
| 1771 | // Save the original opcode by reading it |
| 1772 | if (DoReadMemory(bp_addr, bp_site->GetSavedOpcodeBytes(), bp_opcode_size, error) == bp_opcode_size) |
| 1773 | { |
| 1774 | // Write a software breakpoint in place of the original opcode |
| 1775 | if (DoWriteMemory(bp_addr, bp_opcode_bytes, bp_opcode_size, error) == bp_opcode_size) |
| 1776 | { |
| 1777 | uint8_t verify_bp_opcode_bytes[64]; |
| 1778 | if (DoReadMemory(bp_addr, verify_bp_opcode_bytes, bp_opcode_size, error) == bp_opcode_size) |
| 1779 | { |
| 1780 | if (::memcmp(bp_opcode_bytes, verify_bp_opcode_bytes, bp_opcode_size) == 0) |
| 1781 | { |
| 1782 | bp_site->SetEnabled(true); |
| 1783 | bp_site->SetType (BreakpointSite::eSoftware); |
| 1784 | if (log) |
| 1785 | log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- SUCCESS", |
| 1786 | bp_site->GetID(), |
| 1787 | (uint64_t)bp_addr); |
| 1788 | } |
| 1789 | else |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 1790 | error.SetErrorString("failed to verify the breakpoint trap in memory."); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1791 | } |
| 1792 | else |
| 1793 | error.SetErrorString("Unable to read memory to verify breakpoint trap."); |
| 1794 | } |
| 1795 | else |
| 1796 | error.SetErrorString("Unable to write breakpoint trap to memory."); |
| 1797 | } |
| 1798 | else |
| 1799 | error.SetErrorString("Unable to read memory at breakpoint address."); |
| 1800 | } |
Stephen Wilson | 78a4feb | 2011-01-12 04:20:03 +0000 | [diff] [blame] | 1801 | if (log && error.Fail()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1802 | log->Printf ("Process::EnableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- FAILED: %s", |
| 1803 | bp_site->GetID(), |
| 1804 | (uint64_t)bp_addr, |
| 1805 | error.AsCString()); |
| 1806 | return error; |
| 1807 | } |
| 1808 | |
| 1809 | Error |
| 1810 | Process::DisableSoftwareBreakpoint (BreakpointSite *bp_site) |
| 1811 | { |
| 1812 | Error error; |
| 1813 | assert (bp_site != NULL); |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1814 | LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1815 | addr_t bp_addr = bp_site->GetLoadAddress(); |
| 1816 | lldb::user_id_t breakID = bp_site->GetID(); |
| 1817 | if (log) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1818 | log->Printf ("Process::DisableBreakpoint (breakID = %llu) addr = 0x%llx", breakID, (uint64_t)bp_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1819 | |
| 1820 | if (bp_site->IsHardware()) |
| 1821 | { |
| 1822 | error.SetErrorString("Breakpoint site is a hardware breakpoint."); |
| 1823 | } |
| 1824 | else if (bp_site->IsEnabled()) |
| 1825 | { |
| 1826 | const size_t break_op_size = bp_site->GetByteSize(); |
| 1827 | const uint8_t * const break_op = bp_site->GetTrapOpcodeBytes(); |
| 1828 | if (break_op_size > 0) |
| 1829 | { |
| 1830 | // Clear a software breakoint instruction |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1831 | uint8_t curr_break_op[8]; |
Stephen Wilson | 4ab4768 | 2010-07-20 18:41:11 +0000 | [diff] [blame] | 1832 | assert (break_op_size <= sizeof(curr_break_op)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1833 | bool break_op_found = false; |
| 1834 | |
| 1835 | // Read the breakpoint opcode |
| 1836 | if (DoReadMemory (bp_addr, curr_break_op, break_op_size, error) == break_op_size) |
| 1837 | { |
| 1838 | bool verify = false; |
| 1839 | // Make sure we have the a breakpoint opcode exists at this address |
| 1840 | if (::memcmp (curr_break_op, break_op, break_op_size) == 0) |
| 1841 | { |
| 1842 | break_op_found = true; |
| 1843 | // We found a valid breakpoint opcode at this address, now restore |
| 1844 | // the saved opcode. |
| 1845 | if (DoWriteMemory (bp_addr, bp_site->GetSavedOpcodeBytes(), break_op_size, error) == break_op_size) |
| 1846 | { |
| 1847 | verify = true; |
| 1848 | } |
| 1849 | else |
| 1850 | error.SetErrorString("Memory write failed when restoring original opcode."); |
| 1851 | } |
| 1852 | else |
| 1853 | { |
| 1854 | error.SetErrorString("Original breakpoint trap is no longer in memory."); |
| 1855 | // Set verify to true and so we can check if the original opcode has already been restored |
| 1856 | verify = true; |
| 1857 | } |
| 1858 | |
| 1859 | if (verify) |
| 1860 | { |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 1861 | uint8_t verify_opcode[8]; |
Stephen Wilson | 4ab4768 | 2010-07-20 18:41:11 +0000 | [diff] [blame] | 1862 | assert (break_op_size < sizeof(verify_opcode)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1863 | // Verify that our original opcode made it back to the inferior |
| 1864 | if (DoReadMemory (bp_addr, verify_opcode, break_op_size, error) == break_op_size) |
| 1865 | { |
| 1866 | // compare the memory we just read with the original opcode |
| 1867 | if (::memcmp (bp_site->GetSavedOpcodeBytes(), verify_opcode, break_op_size) == 0) |
| 1868 | { |
| 1869 | // SUCCESS |
| 1870 | bp_site->SetEnabled(false); |
| 1871 | if (log) |
| 1872 | log->Printf ("Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- SUCCESS", bp_site->GetID(), (uint64_t)bp_addr); |
| 1873 | return error; |
| 1874 | } |
| 1875 | else |
| 1876 | { |
| 1877 | if (break_op_found) |
| 1878 | error.SetErrorString("Failed to restore original opcode."); |
| 1879 | } |
| 1880 | } |
| 1881 | else |
| 1882 | error.SetErrorString("Failed to read memory to verify that breakpoint trap was restored."); |
| 1883 | } |
| 1884 | } |
| 1885 | else |
| 1886 | error.SetErrorString("Unable to read memory that should contain the breakpoint trap."); |
| 1887 | } |
| 1888 | } |
| 1889 | else |
| 1890 | { |
| 1891 | if (log) |
| 1892 | log->Printf ("Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- already disabled", bp_site->GetID(), (uint64_t)bp_addr); |
| 1893 | return error; |
| 1894 | } |
| 1895 | |
| 1896 | if (log) |
| 1897 | log->Printf ("Process::DisableSoftwareBreakpoint (site_id = %d) addr = 0x%llx -- FAILED: %s", |
| 1898 | bp_site->GetID(), |
| 1899 | (uint64_t)bp_addr, |
| 1900 | error.AsCString()); |
| 1901 | return error; |
| 1902 | |
| 1903 | } |
| 1904 | |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 1905 | // Comment out line below to disable memory caching |
| 1906 | #define ENABLE_MEMORY_CACHING |
| 1907 | // Uncomment to verify memory caching works after making changes to caching code |
| 1908 | //#define VERIFY_MEMORY_READS |
| 1909 | |
| 1910 | #if defined (ENABLE_MEMORY_CACHING) |
| 1911 | |
| 1912 | #if defined (VERIFY_MEMORY_READS) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1913 | |
| 1914 | size_t |
| 1915 | Process::ReadMemory (addr_t addr, void *buf, size_t size, Error &error) |
| 1916 | { |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 1917 | // Memory caching is enabled, with debug verification |
| 1918 | if (buf && size) |
| 1919 | { |
| 1920 | // Uncomment the line below to make sure memory caching is working. |
| 1921 | // I ran this through the test suite and got no assertions, so I am |
| 1922 | // pretty confident this is working well. If any changes are made to |
| 1923 | // memory caching, uncomment the line below and test your changes! |
| 1924 | |
| 1925 | // Verify all memory reads by using the cache first, then redundantly |
| 1926 | // reading the same memory from the inferior and comparing to make sure |
| 1927 | // everything is exactly the same. |
| 1928 | std::string verify_buf (size, '\0'); |
| 1929 | assert (verify_buf.size() == size); |
| 1930 | const size_t cache_bytes_read = m_memory_cache.Read (this, addr, buf, size, error); |
| 1931 | Error verify_error; |
| 1932 | const size_t verify_bytes_read = ReadMemoryFromInferior (addr, const_cast<char *>(verify_buf.data()), verify_buf.size(), verify_error); |
| 1933 | assert (cache_bytes_read == verify_bytes_read); |
| 1934 | assert (memcmp(buf, verify_buf.data(), verify_buf.size()) == 0); |
| 1935 | assert (verify_error.Success() == error.Success()); |
| 1936 | return cache_bytes_read; |
| 1937 | } |
| 1938 | return 0; |
| 1939 | } |
| 1940 | |
| 1941 | #else // #if defined (VERIFY_MEMORY_READS) |
| 1942 | |
| 1943 | size_t |
| 1944 | Process::ReadMemory (addr_t addr, void *buf, size_t size, Error &error) |
| 1945 | { |
| 1946 | // Memory caching enabled, no verification |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 1947 | return m_memory_cache.Read (addr, buf, size, error); |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | #endif // #else for #if defined (VERIFY_MEMORY_READS) |
| 1951 | |
| 1952 | #else // #if defined (ENABLE_MEMORY_CACHING) |
| 1953 | |
| 1954 | size_t |
| 1955 | Process::ReadMemory (addr_t addr, void *buf, size_t size, Error &error) |
| 1956 | { |
| 1957 | // Memory caching is disabled |
| 1958 | return ReadMemoryFromInferior (addr, buf, size, error); |
| 1959 | } |
| 1960 | |
| 1961 | #endif // #else for #if defined (ENABLE_MEMORY_CACHING) |
| 1962 | |
| 1963 | |
| 1964 | size_t |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1965 | 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] | 1966 | { |
| 1967 | size_t total_cstr_len = 0; |
| 1968 | if (dst && dst_max_len) |
| 1969 | { |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1970 | result_error.Clear(); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1971 | // NULL out everything just to be safe |
| 1972 | memset (dst, 0, dst_max_len); |
| 1973 | Error error; |
| 1974 | addr_t curr_addr = addr; |
| 1975 | const size_t cache_line_size = m_memory_cache.GetMemoryCacheLineSize(); |
| 1976 | size_t bytes_left = dst_max_len - 1; |
| 1977 | char *curr_dst = dst; |
| 1978 | |
| 1979 | while (bytes_left > 0) |
| 1980 | { |
| 1981 | addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size); |
| 1982 | addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left); |
| 1983 | size_t bytes_read = ReadMemory (curr_addr, curr_dst, bytes_to_read, error); |
| 1984 | |
| 1985 | if (bytes_read == 0) |
| 1986 | { |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 1987 | result_error = error; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1988 | dst[total_cstr_len] = '\0'; |
| 1989 | break; |
| 1990 | } |
| 1991 | const size_t len = strlen(curr_dst); |
| 1992 | |
| 1993 | total_cstr_len += len; |
| 1994 | |
| 1995 | if (len < bytes_to_read) |
| 1996 | break; |
| 1997 | |
| 1998 | curr_dst += bytes_read; |
| 1999 | curr_addr += bytes_read; |
| 2000 | bytes_left -= bytes_read; |
| 2001 | } |
| 2002 | } |
Greg Clayton | e91b795 | 2011-12-15 03:14:23 +0000 | [diff] [blame] | 2003 | else |
| 2004 | { |
| 2005 | if (dst == NULL) |
| 2006 | result_error.SetErrorString("invalid arguments"); |
| 2007 | else |
| 2008 | result_error.Clear(); |
| 2009 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2010 | return total_cstr_len; |
| 2011 | } |
| 2012 | |
| 2013 | size_t |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2014 | Process::ReadMemoryFromInferior (addr_t addr, void *buf, size_t size, Error &error) |
| 2015 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2016 | if (buf == NULL || size == 0) |
| 2017 | return 0; |
| 2018 | |
| 2019 | size_t bytes_read = 0; |
| 2020 | uint8_t *bytes = (uint8_t *)buf; |
| 2021 | |
| 2022 | while (bytes_read < size) |
| 2023 | { |
| 2024 | const size_t curr_size = size - bytes_read; |
| 2025 | const size_t curr_bytes_read = DoReadMemory (addr + bytes_read, |
| 2026 | bytes + bytes_read, |
| 2027 | curr_size, |
| 2028 | error); |
| 2029 | bytes_read += curr_bytes_read; |
| 2030 | if (curr_bytes_read == curr_size || curr_bytes_read == 0) |
| 2031 | break; |
| 2032 | } |
| 2033 | |
| 2034 | // Replace any software breakpoint opcodes that fall into this range back |
| 2035 | // into "buf" before we return |
| 2036 | if (bytes_read > 0) |
| 2037 | RemoveBreakpointOpcodesFromBuffer (addr, bytes_read, (uint8_t *)buf); |
| 2038 | return bytes_read; |
| 2039 | } |
| 2040 | |
Greg Clayton | 58a4c46 | 2010-12-16 20:01:20 +0000 | [diff] [blame] | 2041 | uint64_t |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2042 | 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] | 2043 | { |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2044 | Scalar scalar; |
| 2045 | if (ReadScalarIntegerFromMemory(vm_addr, integer_byte_size, false, scalar, error)) |
| 2046 | return scalar.ULongLong(fail_value); |
| 2047 | return fail_value; |
| 2048 | } |
| 2049 | |
| 2050 | addr_t |
| 2051 | Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error) |
| 2052 | { |
| 2053 | Scalar scalar; |
| 2054 | if (ReadScalarIntegerFromMemory(vm_addr, GetAddressByteSize(), false, scalar, error)) |
| 2055 | return scalar.ULongLong(LLDB_INVALID_ADDRESS); |
| 2056 | return LLDB_INVALID_ADDRESS; |
| 2057 | } |
| 2058 | |
| 2059 | |
| 2060 | bool |
| 2061 | Process::WritePointerToMemory (lldb::addr_t vm_addr, |
| 2062 | lldb::addr_t ptr_value, |
| 2063 | Error &error) |
| 2064 | { |
| 2065 | Scalar scalar; |
| 2066 | const uint32_t addr_byte_size = GetAddressByteSize(); |
| 2067 | if (addr_byte_size <= 4) |
| 2068 | scalar = (uint32_t)ptr_value; |
Greg Clayton | 58a4c46 | 2010-12-16 20:01:20 +0000 | [diff] [blame] | 2069 | else |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2070 | scalar = ptr_value; |
| 2071 | return WriteScalarToMemory(vm_addr, scalar, addr_byte_size, error) == addr_byte_size; |
Greg Clayton | 58a4c46 | 2010-12-16 20:01:20 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2074 | size_t |
| 2075 | Process::WriteMemoryPrivate (addr_t addr, const void *buf, size_t size, Error &error) |
| 2076 | { |
| 2077 | size_t bytes_written = 0; |
| 2078 | const uint8_t *bytes = (const uint8_t *)buf; |
| 2079 | |
| 2080 | while (bytes_written < size) |
| 2081 | { |
| 2082 | const size_t curr_size = size - bytes_written; |
| 2083 | const size_t curr_bytes_written = DoWriteMemory (addr + bytes_written, |
| 2084 | bytes + bytes_written, |
| 2085 | curr_size, |
| 2086 | error); |
| 2087 | bytes_written += curr_bytes_written; |
| 2088 | if (curr_bytes_written == curr_size || curr_bytes_written == 0) |
| 2089 | break; |
| 2090 | } |
| 2091 | return bytes_written; |
| 2092 | } |
| 2093 | |
| 2094 | size_t |
| 2095 | Process::WriteMemory (addr_t addr, const void *buf, size_t size, Error &error) |
| 2096 | { |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 2097 | #if defined (ENABLE_MEMORY_CACHING) |
| 2098 | m_memory_cache.Flush (addr, size); |
| 2099 | #endif |
| 2100 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2101 | if (buf == NULL || size == 0) |
| 2102 | return 0; |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2103 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 2104 | m_mod_id.BumpMemoryID(); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2105 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2106 | // We need to write any data that would go where any current software traps |
| 2107 | // (enabled software breakpoints) any software traps (breakpoints) that we |
| 2108 | // may have placed in our tasks memory. |
| 2109 | |
| 2110 | BreakpointSiteList::collection::const_iterator iter = m_breakpoint_site_list.GetMap()->lower_bound (addr); |
| 2111 | BreakpointSiteList::collection::const_iterator end = m_breakpoint_site_list.GetMap()->end(); |
| 2112 | |
| 2113 | if (iter == end || iter->second->GetLoadAddress() > addr + size) |
Greg Clayton | b4aaf2e | 2011-05-16 02:35:02 +0000 | [diff] [blame] | 2114 | return WriteMemoryPrivate (addr, buf, size, error); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2115 | |
| 2116 | BreakpointSiteList::collection::const_iterator pos; |
| 2117 | size_t bytes_written = 0; |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 2118 | addr_t intersect_addr = 0; |
| 2119 | size_t intersect_size = 0; |
| 2120 | size_t opcode_offset = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2121 | const uint8_t *ubuf = (const uint8_t *)buf; |
| 2122 | |
| 2123 | for (pos = iter; pos != end; ++pos) |
| 2124 | { |
| 2125 | BreakpointSiteSP bp; |
| 2126 | bp = pos->second; |
| 2127 | |
| 2128 | assert(bp->IntersectsRange(addr, size, &intersect_addr, &intersect_size, &opcode_offset)); |
| 2129 | assert(addr <= intersect_addr && intersect_addr < addr + size); |
| 2130 | assert(addr < intersect_addr + intersect_size && intersect_addr + intersect_size <= addr + size); |
| 2131 | assert(opcode_offset + intersect_size <= bp->GetByteSize()); |
| 2132 | |
| 2133 | // Check for bytes before this breakpoint |
| 2134 | const addr_t curr_addr = addr + bytes_written; |
| 2135 | if (intersect_addr > curr_addr) |
| 2136 | { |
| 2137 | // There are some bytes before this breakpoint that we need to |
| 2138 | // just write to memory |
| 2139 | size_t curr_size = intersect_addr - curr_addr; |
| 2140 | size_t curr_bytes_written = WriteMemoryPrivate (curr_addr, |
| 2141 | ubuf + bytes_written, |
| 2142 | curr_size, |
| 2143 | error); |
| 2144 | bytes_written += curr_bytes_written; |
| 2145 | if (curr_bytes_written != curr_size) |
| 2146 | { |
| 2147 | // We weren't able to write all of the requested bytes, we |
| 2148 | // are done looping and will return the number of bytes that |
| 2149 | // we have written so far. |
| 2150 | break; |
| 2151 | } |
| 2152 | } |
| 2153 | |
| 2154 | // Now write any bytes that would cover up any software breakpoints |
| 2155 | // directly into the breakpoint opcode buffer |
| 2156 | ::memcpy(bp->GetSavedOpcodeBytes() + opcode_offset, ubuf + bytes_written, intersect_size); |
| 2157 | bytes_written += intersect_size; |
| 2158 | } |
| 2159 | |
| 2160 | // Write any remaining bytes after the last breakpoint if we have any left |
| 2161 | if (bytes_written < size) |
| 2162 | bytes_written += WriteMemoryPrivate (addr + bytes_written, |
| 2163 | ubuf + bytes_written, |
| 2164 | size - bytes_written, |
| 2165 | error); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 2166 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2167 | return bytes_written; |
| 2168 | } |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2169 | |
| 2170 | size_t |
| 2171 | Process::WriteScalarToMemory (addr_t addr, const Scalar &scalar, uint32_t byte_size, Error &error) |
| 2172 | { |
| 2173 | if (byte_size == UINT32_MAX) |
| 2174 | byte_size = scalar.GetByteSize(); |
| 2175 | if (byte_size > 0) |
| 2176 | { |
| 2177 | uint8_t buf[32]; |
| 2178 | const size_t mem_size = scalar.GetAsMemoryData (buf, byte_size, GetByteOrder(), error); |
| 2179 | if (mem_size > 0) |
| 2180 | return WriteMemory(addr, buf, mem_size, error); |
| 2181 | else |
| 2182 | error.SetErrorString ("failed to get scalar as memory data"); |
| 2183 | } |
| 2184 | else |
| 2185 | { |
| 2186 | error.SetErrorString ("invalid scalar value"); |
| 2187 | } |
| 2188 | return 0; |
| 2189 | } |
| 2190 | |
| 2191 | size_t |
| 2192 | Process::ReadScalarIntegerFromMemory (addr_t addr, |
| 2193 | uint32_t byte_size, |
| 2194 | bool is_signed, |
| 2195 | Scalar &scalar, |
| 2196 | Error &error) |
| 2197 | { |
| 2198 | uint64_t uval; |
| 2199 | |
| 2200 | if (byte_size <= sizeof(uval)) |
| 2201 | { |
| 2202 | size_t bytes_read = ReadMemory (addr, &uval, byte_size, error); |
| 2203 | if (bytes_read == byte_size) |
| 2204 | { |
| 2205 | DataExtractor data (&uval, sizeof(uval), GetByteOrder(), GetAddressByteSize()); |
| 2206 | uint32_t offset = 0; |
| 2207 | if (byte_size <= 4) |
| 2208 | scalar = data.GetMaxU32 (&offset, byte_size); |
| 2209 | else |
| 2210 | scalar = data.GetMaxU64 (&offset, byte_size); |
| 2211 | |
| 2212 | if (is_signed) |
| 2213 | scalar.SignExtend(byte_size * 8); |
| 2214 | return bytes_read; |
| 2215 | } |
| 2216 | } |
| 2217 | else |
| 2218 | { |
| 2219 | error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size); |
| 2220 | } |
| 2221 | return 0; |
| 2222 | } |
| 2223 | |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2224 | #define USE_ALLOCATE_MEMORY_CACHE 1 |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2225 | addr_t |
| 2226 | Process::AllocateMemory(size_t size, uint32_t permissions, Error &error) |
| 2227 | { |
Jim Ingham | f72ce3a | 2011-06-20 17:32:44 +0000 | [diff] [blame] | 2228 | if (GetPrivateState() != eStateStopped) |
| 2229 | return LLDB_INVALID_ADDRESS; |
| 2230 | |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2231 | #if defined (USE_ALLOCATE_MEMORY_CACHE) |
| 2232 | return m_allocated_memory_cache.AllocateMemory(size, permissions, error); |
| 2233 | #else |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2234 | addr_t allocated_addr = DoAllocateMemory (size, permissions, error); |
| 2235 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 2236 | if (log) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 2237 | log->Printf("Process::AllocateMemory(size=%4zu, permissions=%s) => 0x%16.16llx (m_stop_id = %u m_memory_id = %u)", |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2238 | size, |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2239 | GetPermissionsAsCString (permissions), |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2240 | (uint64_t)allocated_addr, |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 2241 | m_mod_id.GetStopID(), |
| 2242 | m_mod_id.GetMemoryID()); |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2243 | return allocated_addr; |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2244 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
Sean Callanan | 9053945 | 2011-09-20 23:01:51 +0000 | [diff] [blame] | 2247 | bool |
| 2248 | Process::CanJIT () |
| 2249 | { |
Sean Callanan | a7b443a | 2012-02-14 22:50:38 +0000 | [diff] [blame] | 2250 | if (m_can_jit == eCanJITDontKnow) |
| 2251 | { |
| 2252 | Error err; |
| 2253 | |
| 2254 | uint64_t allocated_memory = AllocateMemory(8, |
| 2255 | ePermissionsReadable | ePermissionsWritable | ePermissionsExecutable, |
| 2256 | err); |
| 2257 | |
| 2258 | if (err.Success()) |
| 2259 | m_can_jit = eCanJITYes; |
| 2260 | else |
| 2261 | m_can_jit = eCanJITNo; |
| 2262 | |
| 2263 | DeallocateMemory (allocated_memory); |
| 2264 | } |
| 2265 | |
Sean Callanan | 9053945 | 2011-09-20 23:01:51 +0000 | [diff] [blame] | 2266 | return m_can_jit == eCanJITYes; |
| 2267 | } |
| 2268 | |
| 2269 | void |
| 2270 | Process::SetCanJIT (bool can_jit) |
| 2271 | { |
| 2272 | m_can_jit = (can_jit ? eCanJITYes : eCanJITNo); |
| 2273 | } |
| 2274 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2275 | Error |
| 2276 | Process::DeallocateMemory (addr_t ptr) |
| 2277 | { |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2278 | Error error; |
| 2279 | #if defined (USE_ALLOCATE_MEMORY_CACHE) |
| 2280 | if (!m_allocated_memory_cache.DeallocateMemory(ptr)) |
| 2281 | { |
| 2282 | error.SetErrorStringWithFormat ("deallocation of memory at 0x%llx failed.", (uint64_t)ptr); |
| 2283 | } |
| 2284 | #else |
| 2285 | error = DoDeallocateMemory (ptr); |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2286 | |
| 2287 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 2288 | if (log) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 2289 | log->Printf("Process::DeallocateMemory(addr=0x%16.16llx) => err = %s (m_stop_id = %u, m_memory_id = %u)", |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2290 | ptr, |
| 2291 | error.AsCString("SUCCESS"), |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 2292 | m_mod_id.GetStopID(), |
| 2293 | m_mod_id.GetMemoryID()); |
Greg Clayton | d495c53 | 2011-05-17 03:37:42 +0000 | [diff] [blame] | 2294 | #endif |
Greg Clayton | b2daec9 | 2011-01-23 19:58:49 +0000 | [diff] [blame] | 2295 | return error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 2298 | ModuleSP |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2299 | Process::ReadModuleFromMemory (const FileSpec& file_spec, |
| 2300 | lldb::addr_t header_addr, |
| 2301 | bool add_image_to_target, |
| 2302 | bool load_sections_in_target) |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 2303 | { |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 2304 | ModuleSP module_sp (new Module (file_spec, ArchSpec())); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 2305 | if (module_sp) |
| 2306 | { |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 2307 | Error error; |
| 2308 | ObjectFile *objfile = module_sp->GetMemoryObjectFile (shared_from_this(), header_addr, error); |
| 2309 | if (objfile) |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2310 | { |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 2311 | if (add_image_to_target) |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2312 | { |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 2313 | m_target.GetImages().Append(module_sp); |
| 2314 | if (load_sections_in_target) |
| 2315 | { |
| 2316 | bool changed = false; |
| 2317 | module_sp->SetLoadAddress (m_target, 0, changed); |
| 2318 | } |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2319 | } |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 2320 | return module_sp; |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2321 | } |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 2322 | } |
Greg Clayton | c7f09cc | 2012-02-24 21:55:59 +0000 | [diff] [blame] | 2323 | return ModuleSP(); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 2324 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2325 | |
| 2326 | Error |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 2327 | Process::EnableWatchpoint (Watchpoint *watchpoint) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2328 | { |
| 2329 | Error error; |
| 2330 | error.SetErrorString("watchpoints are not supported"); |
| 2331 | return error; |
| 2332 | } |
| 2333 | |
| 2334 | Error |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 2335 | Process::DisableWatchpoint (Watchpoint *watchpoint) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2336 | { |
| 2337 | Error error; |
| 2338 | error.SetErrorString("watchpoints are not supported"); |
| 2339 | return error; |
| 2340 | } |
| 2341 | |
| 2342 | StateType |
| 2343 | Process::WaitForProcessStopPrivate (const TimeValue *timeout, EventSP &event_sp) |
| 2344 | { |
| 2345 | StateType state; |
| 2346 | // Now wait for the process to launch and return control to us, and then |
| 2347 | // call DidLaunch: |
| 2348 | while (1) |
| 2349 | { |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 2350 | event_sp.reset(); |
| 2351 | state = WaitForStateChangedEventsPrivate (timeout, event_sp); |
| 2352 | |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 2353 | if (StateIsStoppedState(state, false)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2354 | break; |
Greg Clayton | 6779606a | 2011-01-22 23:43:18 +0000 | [diff] [blame] | 2355 | |
| 2356 | // If state is invalid, then we timed out |
| 2357 | if (state == eStateInvalid) |
| 2358 | break; |
| 2359 | |
| 2360 | if (event_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2361 | HandlePrivateEvent (event_sp); |
| 2362 | } |
| 2363 | return state; |
| 2364 | } |
| 2365 | |
| 2366 | Error |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 2367 | Process::Launch (const ProcessLaunchInfo &launch_info) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2368 | { |
| 2369 | Error error; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2370 | m_abi_sp.reset(); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 2371 | m_dyld_ap.reset(); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 2372 | m_os_ap.reset(); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 2373 | m_process_input_reader.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2374 | |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 2375 | Module *exe_module = m_target.GetExecutableModulePointer(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2376 | if (exe_module) |
| 2377 | { |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 2378 | char local_exec_file_path[PATH_MAX]; |
| 2379 | char platform_exec_file_path[PATH_MAX]; |
| 2380 | exe_module->GetFileSpec().GetPath(local_exec_file_path, sizeof(local_exec_file_path)); |
| 2381 | 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] | 2382 | if (exe_module->GetFileSpec().Exists()) |
| 2383 | { |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 2384 | if (PrivateStateThreadIsValid ()) |
| 2385 | PausePrivateStateThread (); |
| 2386 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2387 | error = WillLaunch (exe_module); |
| 2388 | if (error.Success()) |
| 2389 | { |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 2390 | SetPublicState (eStateLaunching); |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 2391 | m_should_detach = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2392 | |
| 2393 | // Now launch using these arguments. |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 2394 | error = DoLaunch (exe_module, launch_info); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2395 | |
| 2396 | if (error.Fail()) |
| 2397 | { |
| 2398 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
| 2399 | { |
| 2400 | SetID (LLDB_INVALID_PROCESS_ID); |
| 2401 | const char *error_string = error.AsCString(); |
| 2402 | if (error_string == NULL) |
| 2403 | error_string = "launch failed"; |
| 2404 | SetExitStatus (-1, error_string); |
| 2405 | } |
| 2406 | } |
| 2407 | else |
| 2408 | { |
| 2409 | EventSP event_sp; |
Greg Clayton | 1a38ea7 | 2011-06-22 01:42:17 +0000 | [diff] [blame] | 2410 | TimeValue timeout_time; |
| 2411 | timeout_time = TimeValue::Now(); |
| 2412 | timeout_time.OffsetWithSeconds(10); |
| 2413 | StateType state = WaitForProcessStopPrivate(&timeout_time, event_sp); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2414 | |
Greg Clayton | 1a38ea7 | 2011-06-22 01:42:17 +0000 | [diff] [blame] | 2415 | if (state == eStateInvalid || event_sp.get() == NULL) |
| 2416 | { |
| 2417 | // We were able to launch the process, but we failed to |
| 2418 | // catch the initial stop. |
| 2419 | SetExitStatus (0, "failed to catch stop after launch"); |
| 2420 | Destroy(); |
| 2421 | } |
| 2422 | else if (state == eStateStopped || state == eStateCrashed) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2423 | { |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 2424 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2425 | DidLaunch (); |
| 2426 | |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2427 | DynamicLoader *dyld = GetDynamicLoader (); |
| 2428 | if (dyld) |
| 2429 | dyld->DidLaunch(); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 2430 | |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 2431 | m_os_ap.reset (OperatingSystem::FindPlugin (this, NULL)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2432 | // This delays passing the stopped event to listeners till DidLaunch gets |
| 2433 | // a chance to complete... |
| 2434 | HandlePrivateEvent (event_sp); |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 2435 | |
| 2436 | if (PrivateStateThreadIsValid ()) |
| 2437 | ResumePrivateStateThread (); |
| 2438 | else |
| 2439 | StartPrivateStateThread (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2440 | } |
| 2441 | else if (state == eStateExited) |
| 2442 | { |
| 2443 | // We exited while trying to launch somehow. Don't call DidLaunch as that's |
| 2444 | // not likely to work, and return an invalid pid. |
| 2445 | HandlePrivateEvent (event_sp); |
| 2446 | } |
| 2447 | } |
| 2448 | } |
| 2449 | } |
| 2450 | else |
| 2451 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 2452 | error.SetErrorStringWithFormat("file doesn't exist: '%s'", local_exec_file_path); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2453 | } |
| 2454 | } |
| 2455 | return error; |
| 2456 | } |
| 2457 | |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 2458 | |
| 2459 | Error |
| 2460 | Process::LoadCore () |
| 2461 | { |
| 2462 | Error error = DoLoadCore(); |
| 2463 | if (error.Success()) |
| 2464 | { |
| 2465 | if (PrivateStateThreadIsValid ()) |
| 2466 | ResumePrivateStateThread (); |
| 2467 | else |
| 2468 | StartPrivateStateThread (); |
| 2469 | |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2470 | DynamicLoader *dyld = GetDynamicLoader (); |
| 2471 | if (dyld) |
| 2472 | dyld->DidAttach(); |
| 2473 | |
| 2474 | m_os_ap.reset (OperatingSystem::FindPlugin (this, NULL)); |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 2475 | // We successfully loaded a core file, now pretend we stopped so we can |
| 2476 | // show all of the threads in the core file and explore the crashed |
| 2477 | // state. |
| 2478 | SetPrivateState (eStateStopped); |
| 2479 | |
| 2480 | } |
| 2481 | return error; |
| 2482 | } |
| 2483 | |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2484 | DynamicLoader * |
| 2485 | Process::GetDynamicLoader () |
| 2486 | { |
| 2487 | if (m_dyld_ap.get() == NULL) |
| 2488 | m_dyld_ap.reset (DynamicLoader::FindPlugin(this, NULL)); |
| 2489 | return m_dyld_ap.get(); |
| 2490 | } |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 2491 | |
| 2492 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2493 | Process::NextEventAction::EventActionResult |
| 2494 | Process::AttachCompletionHandler::PerformAction (lldb::EventSP &event_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2495 | { |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2496 | StateType state = ProcessEventData::GetStateFromEvent (event_sp.get()); |
| 2497 | switch (state) |
Greg Clayton | 19388cf | 2010-10-18 01:45:30 +0000 | [diff] [blame] | 2498 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2499 | case eStateRunning: |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 2500 | case eStateConnected: |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2501 | return eEventActionRetry; |
| 2502 | |
| 2503 | case eStateStopped: |
| 2504 | case eStateCrashed: |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 2505 | { |
| 2506 | // During attach, prior to sending the eStateStopped event, |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 2507 | // lldb_private::Process subclasses must set the new process ID. |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 2508 | assert (m_process->GetID() != LLDB_INVALID_PROCESS_ID); |
| 2509 | if (m_exec_count > 0) |
| 2510 | { |
| 2511 | --m_exec_count; |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 2512 | m_process->PrivateResume (); |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 2513 | return eEventActionRetry; |
| 2514 | } |
| 2515 | else |
| 2516 | { |
| 2517 | m_process->CompleteAttach (); |
| 2518 | return eEventActionSuccess; |
| 2519 | } |
| 2520 | } |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2521 | break; |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 2522 | |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2523 | default: |
| 2524 | case eStateExited: |
| 2525 | case eStateInvalid: |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2526 | break; |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2527 | } |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 2528 | |
| 2529 | m_exit_string.assign ("No valid Process"); |
| 2530 | return eEventActionExit; |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2531 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2532 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2533 | Process::NextEventAction::EventActionResult |
| 2534 | Process::AttachCompletionHandler::HandleBeingInterrupted() |
| 2535 | { |
| 2536 | return eEventActionSuccess; |
| 2537 | } |
| 2538 | |
| 2539 | const char * |
| 2540 | Process::AttachCompletionHandler::GetExitString () |
| 2541 | { |
| 2542 | return m_exit_string.c_str(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | Error |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2546 | Process::Attach (ProcessAttachInfo &attach_info) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2547 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2548 | m_abi_sp.reset(); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 2549 | m_process_input_reader.reset(); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 2550 | m_dyld_ap.reset(); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 2551 | m_os_ap.reset(); |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 2552 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2553 | lldb::pid_t attach_pid = attach_info.GetProcessID(); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2554 | Error error; |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2555 | if (attach_pid == LLDB_INVALID_PROCESS_ID) |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 2556 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2557 | char process_name[PATH_MAX]; |
Jim Ingham | 4299fdb | 2011-09-15 01:10:17 +0000 | [diff] [blame] | 2558 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2559 | if (attach_info.GetExecutableFile().GetPath (process_name, sizeof(process_name))) |
Jim Ingham | 2ecb742 | 2010-08-17 21:54:19 +0000 | [diff] [blame] | 2560 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2561 | const bool wait_for_launch = attach_info.GetWaitForLaunch(); |
| 2562 | |
| 2563 | if (wait_for_launch) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2564 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2565 | error = WillAttachToProcessWithName(process_name, wait_for_launch); |
| 2566 | if (error.Success()) |
| 2567 | { |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 2568 | m_should_detach = true; |
| 2569 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2570 | SetPublicState (eStateAttaching); |
Han Ming Ong | 8464704 | 2012-02-25 01:07:38 +0000 | [diff] [blame] | 2571 | error = DoAttachToProcessWithName (process_name, wait_for_launch, attach_info); |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2572 | if (error.Fail()) |
| 2573 | { |
| 2574 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
| 2575 | { |
| 2576 | SetID (LLDB_INVALID_PROCESS_ID); |
| 2577 | if (error.AsCString() == NULL) |
| 2578 | error.SetErrorString("attach failed"); |
| 2579 | |
| 2580 | SetExitStatus(-1, error.AsCString()); |
| 2581 | } |
| 2582 | } |
| 2583 | else |
| 2584 | { |
| 2585 | SetNextEventAction(new Process::AttachCompletionHandler(this, attach_info.GetResumeCount())); |
| 2586 | StartPrivateStateThread(); |
| 2587 | } |
| 2588 | return error; |
| 2589 | } |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2590 | } |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2591 | else |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2592 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2593 | ProcessInstanceInfoList process_infos; |
| 2594 | PlatformSP platform_sp (m_target.GetPlatform ()); |
| 2595 | |
| 2596 | if (platform_sp) |
| 2597 | { |
| 2598 | ProcessInstanceInfoMatch match_info; |
| 2599 | match_info.GetProcessInfo() = attach_info; |
| 2600 | match_info.SetNameMatchType (eNameMatchEquals); |
| 2601 | platform_sp->FindProcesses (match_info, process_infos); |
| 2602 | const uint32_t num_matches = process_infos.GetSize(); |
| 2603 | if (num_matches == 1) |
| 2604 | { |
| 2605 | attach_pid = process_infos.GetProcessIDAtIndex(0); |
| 2606 | // Fall through and attach using the above process ID |
| 2607 | } |
| 2608 | else |
| 2609 | { |
| 2610 | match_info.GetProcessInfo().GetExecutableFile().GetPath (process_name, sizeof(process_name)); |
| 2611 | if (num_matches > 1) |
| 2612 | error.SetErrorStringWithFormat ("more than one process named %s", process_name); |
| 2613 | else |
| 2614 | error.SetErrorStringWithFormat ("could not find a process named %s", process_name); |
| 2615 | } |
| 2616 | } |
| 2617 | else |
| 2618 | { |
| 2619 | error.SetErrorString ("invalid platform, can't find processes by name"); |
| 2620 | return error; |
| 2621 | } |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2622 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2623 | } |
| 2624 | else |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2625 | { |
| 2626 | error.SetErrorString ("invalid process name"); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2627 | } |
| 2628 | } |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2629 | |
| 2630 | if (attach_pid != LLDB_INVALID_PROCESS_ID) |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2631 | { |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2632 | error = WillAttachToProcessWithID(attach_pid); |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2633 | if (error.Success()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2634 | { |
Greg Clayton | e24c4ac | 2011-11-17 04:46:02 +0000 | [diff] [blame] | 2635 | m_should_detach = true; |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2636 | SetPublicState (eStateAttaching); |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2637 | |
Han Ming Ong | 8464704 | 2012-02-25 01:07:38 +0000 | [diff] [blame] | 2638 | error = DoAttachToProcessWithID (attach_pid, attach_info); |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2639 | if (error.Success()) |
| 2640 | { |
| 2641 | |
| 2642 | SetNextEventAction(new Process::AttachCompletionHandler(this, attach_info.GetResumeCount())); |
| 2643 | StartPrivateStateThread(); |
| 2644 | } |
| 2645 | else |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 2646 | { |
| 2647 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
| 2648 | { |
| 2649 | SetID (LLDB_INVALID_PROCESS_ID); |
| 2650 | const char *error_string = error.AsCString(); |
| 2651 | if (error_string == NULL) |
| 2652 | error_string = "attach failed"; |
| 2653 | |
| 2654 | SetExitStatus(-1, error_string); |
| 2655 | } |
| 2656 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2657 | } |
| 2658 | } |
| 2659 | return error; |
| 2660 | } |
| 2661 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 2662 | //Error |
| 2663 | //Process::Attach (const char *process_name, bool wait_for_launch) |
| 2664 | //{ |
| 2665 | // m_abi_sp.reset(); |
| 2666 | // m_process_input_reader.reset(); |
| 2667 | // |
| 2668 | // // Find the process and its architecture. Make sure it matches the architecture |
| 2669 | // // of the current Target, and if not adjust it. |
| 2670 | // Error error; |
| 2671 | // |
| 2672 | // if (!wait_for_launch) |
| 2673 | // { |
| 2674 | // ProcessInstanceInfoList process_infos; |
| 2675 | // PlatformSP platform_sp (m_target.GetPlatform ()); |
| 2676 | // assert (platform_sp.get()); |
| 2677 | // |
| 2678 | // if (platform_sp) |
| 2679 | // { |
| 2680 | // ProcessInstanceInfoMatch match_info; |
| 2681 | // match_info.GetProcessInfo().SetName(process_name); |
| 2682 | // match_info.SetNameMatchType (eNameMatchEquals); |
| 2683 | // platform_sp->FindProcesses (match_info, process_infos); |
| 2684 | // if (process_infos.GetSize() > 1) |
| 2685 | // { |
| 2686 | // error.SetErrorStringWithFormat ("more than one process named %s", process_name); |
| 2687 | // } |
| 2688 | // else if (process_infos.GetSize() == 0) |
| 2689 | // { |
| 2690 | // error.SetErrorStringWithFormat ("could not find a process named %s", process_name); |
| 2691 | // } |
| 2692 | // } |
| 2693 | // else |
| 2694 | // { |
| 2695 | // error.SetErrorString ("invalid platform"); |
| 2696 | // } |
| 2697 | // } |
| 2698 | // |
| 2699 | // if (error.Success()) |
| 2700 | // { |
| 2701 | // m_dyld_ap.reset(); |
| 2702 | // m_os_ap.reset(); |
| 2703 | // |
| 2704 | // error = WillAttachToProcessWithName(process_name, wait_for_launch); |
| 2705 | // if (error.Success()) |
| 2706 | // { |
| 2707 | // SetPublicState (eStateAttaching); |
| 2708 | // error = DoAttachToProcessWithName (process_name, wait_for_launch); |
| 2709 | // if (error.Fail()) |
| 2710 | // { |
| 2711 | // if (GetID() != LLDB_INVALID_PROCESS_ID) |
| 2712 | // { |
| 2713 | // SetID (LLDB_INVALID_PROCESS_ID); |
| 2714 | // const char *error_string = error.AsCString(); |
| 2715 | // if (error_string == NULL) |
| 2716 | // error_string = "attach failed"; |
| 2717 | // |
| 2718 | // SetExitStatus(-1, error_string); |
| 2719 | // } |
| 2720 | // } |
| 2721 | // else |
| 2722 | // { |
| 2723 | // SetNextEventAction(new Process::AttachCompletionHandler(this, 0)); |
| 2724 | // StartPrivateStateThread(); |
| 2725 | // } |
| 2726 | // } |
| 2727 | // } |
| 2728 | // return error; |
| 2729 | //} |
| 2730 | |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 2731 | void |
| 2732 | Process::CompleteAttach () |
| 2733 | { |
| 2734 | // Let the process subclass figure out at much as it can about the process |
| 2735 | // before we go looking for a dynamic loader plug-in. |
| 2736 | DidAttach(); |
| 2737 | |
Jim Ingham | 4299fdb | 2011-09-15 01:10:17 +0000 | [diff] [blame] | 2738 | // We just attached. If we have a platform, ask it for the process architecture, and if it isn't |
| 2739 | // the same as the one we've already set, switch architectures. |
| 2740 | PlatformSP platform_sp (m_target.GetPlatform ()); |
| 2741 | assert (platform_sp.get()); |
| 2742 | if (platform_sp) |
| 2743 | { |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame^] | 2744 | const ArchSpec &target_arch = m_target.GetArchitecture(); |
| 2745 | if (target_arch.IsValid() && !platform_sp->IsCompatibleArchitecture (target_arch)) |
| 2746 | { |
| 2747 | ArchSpec platform_arch; |
| 2748 | platform_sp = platform_sp->GetPlatformForArchitecture (target_arch, &platform_arch); |
| 2749 | if (platform_sp) |
| 2750 | { |
| 2751 | m_target.SetPlatform (platform_sp); |
| 2752 | m_target.SetArchitecture(platform_arch); |
| 2753 | } |
| 2754 | } |
| 2755 | else |
| 2756 | { |
| 2757 | ProcessInstanceInfo process_info; |
| 2758 | platform_sp->GetProcessInfo (GetID(), process_info); |
| 2759 | const ArchSpec &process_arch = process_info.GetArchitecture(); |
| 2760 | if (process_arch.IsValid() && m_target.GetArchitecture() != process_arch) |
| 2761 | m_target.SetArchitecture (process_arch); |
| 2762 | } |
Jim Ingham | 4299fdb | 2011-09-15 01:10:17 +0000 | [diff] [blame] | 2763 | } |
| 2764 | |
| 2765 | // 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] | 2766 | // plug-in |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2767 | DynamicLoader *dyld = GetDynamicLoader (); |
| 2768 | if (dyld) |
| 2769 | dyld->DidAttach(); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 2770 | |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 2771 | m_os_ap.reset (OperatingSystem::FindPlugin (this, NULL)); |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 2772 | // Figure out which one is the executable, and set that in our target: |
| 2773 | ModuleList &modules = m_target.GetImages(); |
| 2774 | |
| 2775 | size_t num_modules = modules.GetSize(); |
| 2776 | for (int i = 0; i < num_modules; i++) |
| 2777 | { |
| 2778 | ModuleSP module_sp (modules.GetModuleAtIndex(i)); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 2779 | if (module_sp && module_sp->IsExecutable()) |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 2780 | { |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 2781 | if (m_target.GetExecutableModulePointer() != module_sp.get()) |
Greg Clayton | 93d3c833 | 2011-02-16 04:46:07 +0000 | [diff] [blame] | 2782 | m_target.SetExecutableModule (module_sp, false); |
| 2783 | break; |
| 2784 | } |
| 2785 | } |
| 2786 | } |
| 2787 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2788 | Error |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 2789 | Process::ConnectRemote (const char *remote_url) |
| 2790 | { |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 2791 | m_abi_sp.reset(); |
| 2792 | m_process_input_reader.reset(); |
| 2793 | |
| 2794 | // Find the process and its architecture. Make sure it matches the architecture |
| 2795 | // of the current Target, and if not adjust it. |
| 2796 | |
| 2797 | Error error (DoConnectRemote (remote_url)); |
| 2798 | if (error.Success()) |
| 2799 | { |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 2800 | if (GetID() != LLDB_INVALID_PROCESS_ID) |
| 2801 | { |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2802 | EventSP event_sp; |
| 2803 | StateType state = WaitForProcessStopPrivate(NULL, event_sp); |
| 2804 | |
| 2805 | if (state == eStateStopped || state == eStateCrashed) |
| 2806 | { |
| 2807 | // If we attached and actually have a process on the other end, then |
| 2808 | // this ended up being the equivalent of an attach. |
| 2809 | CompleteAttach (); |
| 2810 | |
| 2811 | // This delays passing the stopped event to listeners till |
| 2812 | // CompleteAttach gets a chance to complete... |
| 2813 | HandlePrivateEvent (event_sp); |
| 2814 | |
| 2815 | } |
Greg Clayton | 7133762 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 2816 | } |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 2817 | |
| 2818 | if (PrivateStateThreadIsValid ()) |
| 2819 | ResumePrivateStateThread (); |
| 2820 | else |
| 2821 | StartPrivateStateThread (); |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 2822 | } |
| 2823 | return error; |
| 2824 | } |
| 2825 | |
| 2826 | |
| 2827 | Error |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 2828 | Process::PrivateResume () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2829 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 2830 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2831 | if (log) |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 2832 | log->Printf("Process::Resume() m_stop_id = %u, public state: %s private state: %s", |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 2833 | m_mod_id.GetStopID(), |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 2834 | StateAsCString(m_public_state.GetValue()), |
| 2835 | StateAsCString(m_private_state.GetValue())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2836 | |
| 2837 | Error error (WillResume()); |
| 2838 | // Tell the process it is about to resume before the thread list |
| 2839 | if (error.Success()) |
| 2840 | { |
Johnny Chen | c4221e4 | 2010-12-02 20:53:05 +0000 | [diff] [blame] | 2841 | // 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] | 2842 | // can let all of our threads know that they are about to be |
| 2843 | // resumed. Threads will each be called with |
| 2844 | // Thread::WillResume(StateType) where StateType contains the state |
| 2845 | // that they are supposed to have when the process is resumed |
| 2846 | // (suspended/running/stepping). Threads should also check |
| 2847 | // their resume signal in lldb::Thread::GetResumeSignal() |
| 2848 | // to see if they are suppoed to start back up with a signal. |
| 2849 | if (m_thread_list.WillResume()) |
| 2850 | { |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 2851 | // Last thing, do the PreResumeActions. |
| 2852 | if (!RunPreResumeActions()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2853 | { |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 2854 | error.SetErrorStringWithFormat ("Process::Resume PreResumeActions failed, not resuming."); |
| 2855 | } |
| 2856 | else |
| 2857 | { |
| 2858 | m_mod_id.BumpResumeID(); |
| 2859 | error = DoResume(); |
| 2860 | if (error.Success()) |
| 2861 | { |
| 2862 | DidResume(); |
| 2863 | m_thread_list.DidResume(); |
| 2864 | if (log) |
| 2865 | log->Printf ("Process thinks the process has resumed."); |
| 2866 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2867 | } |
| 2868 | } |
| 2869 | else |
| 2870 | { |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 2871 | error.SetErrorStringWithFormat("Process::WillResume() thread list returned false after WillResume"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2872 | } |
| 2873 | } |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 2874 | else if (log) |
| 2875 | log->Printf ("Process::WillResume() got an error \"%s\".", error.AsCString("<unknown error>")); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2876 | return error; |
| 2877 | } |
| 2878 | |
| 2879 | Error |
| 2880 | Process::Halt () |
| 2881 | { |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2882 | // Pause our private state thread so we can ensure no one else eats |
| 2883 | // the stop event out from under us. |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 2884 | Listener halt_listener ("lldb.process.halt_listener"); |
| 2885 | HijackPrivateProcessEvents(&halt_listener); |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 2886 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2887 | EventSP event_sp; |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2888 | Error error (WillHalt()); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2889 | |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2890 | if (error.Success()) |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2891 | { |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2892 | |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2893 | bool caused_stop = false; |
| 2894 | |
| 2895 | // Ask the process subclass to actually halt our process |
| 2896 | error = DoHalt(caused_stop); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2897 | if (error.Success()) |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 2898 | { |
Greg Clayton | 513c26c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 2899 | if (m_public_state.GetValue() == eStateAttaching) |
| 2900 | { |
| 2901 | SetExitStatus(SIGKILL, "Cancelled async attach."); |
| 2902 | Destroy (); |
| 2903 | } |
| 2904 | else |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 2905 | { |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2906 | // If "caused_stop" is true, then DoHalt stopped the process. If |
| 2907 | // "caused_stop" is false, the process was already stopped. |
| 2908 | // If the DoHalt caused the process to stop, then we want to catch |
| 2909 | // this event and set the interrupted bool to true before we pass |
| 2910 | // this along so clients know that the process was interrupted by |
| 2911 | // a halt command. |
| 2912 | if (caused_stop) |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 2913 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 2914 | // Wait for 1 second for the process to stop. |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2915 | TimeValue timeout_time; |
| 2916 | timeout_time = TimeValue::Now(); |
| 2917 | timeout_time.OffsetWithSeconds(1); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 2918 | bool got_event = halt_listener.WaitForEvent (&timeout_time, event_sp); |
| 2919 | StateType state = ProcessEventData::GetStateFromEvent(event_sp.get()); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2920 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 2921 | if (!got_event || state == eStateInvalid) |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 2922 | { |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2923 | // We timeout out and didn't get a stop event... |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 2924 | error.SetErrorStringWithFormat ("Halt timed out. State = %s", StateAsCString(GetState())); |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 2925 | } |
| 2926 | else |
| 2927 | { |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 2928 | if (StateIsStoppedState (state, false)) |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2929 | { |
| 2930 | // We caused the process to interrupt itself, so mark this |
| 2931 | // as such in the stop event so clients can tell an interrupted |
| 2932 | // process from a natural stop |
| 2933 | ProcessEventData::SetInterruptedInEvent (event_sp.get(), true); |
| 2934 | } |
| 2935 | else |
| 2936 | { |
| 2937 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 2938 | if (log) |
| 2939 | log->Printf("Process::Halt() failed to stop, state is: %s", StateAsCString(state)); |
| 2940 | error.SetErrorString ("Did not get stopped event after halt."); |
| 2941 | } |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 2942 | } |
| 2943 | } |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2944 | DidHalt(); |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 2945 | } |
| 2946 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2947 | } |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2948 | // Resume our private state thread before we post the event (if any) |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 2949 | RestorePrivateProcessEvents(); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 2950 | |
| 2951 | // Post any event we might have consumed. If all goes well, we will have |
| 2952 | // stopped the process, intercepted the event and set the interrupted |
| 2953 | // bool in the event. Post it to the private event queue and that will end up |
| 2954 | // correctly setting the state. |
| 2955 | if (event_sp) |
| 2956 | m_private_state_broadcaster.BroadcastEvent(event_sp); |
| 2957 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2958 | return error; |
| 2959 | } |
| 2960 | |
| 2961 | Error |
| 2962 | Process::Detach () |
| 2963 | { |
| 2964 | Error error (WillDetach()); |
| 2965 | |
| 2966 | if (error.Success()) |
| 2967 | { |
| 2968 | DisableAllBreakpointSites(); |
| 2969 | error = DoDetach(); |
| 2970 | if (error.Success()) |
| 2971 | { |
| 2972 | DidDetach(); |
| 2973 | StopPrivateStateThread(); |
| 2974 | } |
| 2975 | } |
| 2976 | return error; |
| 2977 | } |
| 2978 | |
| 2979 | Error |
| 2980 | Process::Destroy () |
| 2981 | { |
| 2982 | Error error (WillDestroy()); |
| 2983 | if (error.Success()) |
| 2984 | { |
| 2985 | DisableAllBreakpointSites(); |
| 2986 | error = DoDestroy(); |
| 2987 | if (error.Success()) |
| 2988 | { |
| 2989 | DidDestroy(); |
| 2990 | StopPrivateStateThread(); |
| 2991 | } |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 2992 | m_stdio_communication.StopReadThread(); |
| 2993 | m_stdio_communication.Disconnect(); |
| 2994 | if (m_process_input_reader && m_process_input_reader->IsActive()) |
| 2995 | m_target.GetDebugger().PopInputReader (m_process_input_reader); |
| 2996 | if (m_process_input_reader) |
| 2997 | m_process_input_reader.reset(); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 2998 | |
| 2999 | // If we have been interrupted (to kill us) in the middle of running, we may not end up propagating |
| 3000 | // the last events through the event system, in which case we might strand the write lock. Unlock |
| 3001 | // it here so when we do to tear down the process we don't get an error destroying the lock. |
| 3002 | m_run_lock.WriteUnlock(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3003 | } |
| 3004 | return error; |
| 3005 | } |
| 3006 | |
| 3007 | Error |
| 3008 | Process::Signal (int signal) |
| 3009 | { |
| 3010 | Error error (WillSignal()); |
| 3011 | if (error.Success()) |
| 3012 | { |
| 3013 | error = DoSignal(signal); |
| 3014 | if (error.Success()) |
| 3015 | DidSignal(); |
| 3016 | } |
| 3017 | return error; |
| 3018 | } |
| 3019 | |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 3020 | lldb::ByteOrder |
| 3021 | Process::GetByteOrder () const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3022 | { |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 3023 | return m_target.GetArchitecture().GetByteOrder(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3024 | } |
| 3025 | |
| 3026 | uint32_t |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 3027 | Process::GetAddressByteSize () const |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3028 | { |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 3029 | return m_target.GetArchitecture().GetAddressByteSize(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3030 | } |
| 3031 | |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 3032 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3033 | bool |
| 3034 | Process::ShouldBroadcastEvent (Event *event_ptr) |
| 3035 | { |
| 3036 | const StateType state = Process::ProcessEventData::GetStateFromEvent (event_ptr); |
| 3037 | bool return_value = true; |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 3038 | LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3039 | |
| 3040 | switch (state) |
| 3041 | { |
Greg Clayton | b766a73 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 3042 | case eStateConnected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3043 | case eStateAttaching: |
| 3044 | case eStateLaunching: |
| 3045 | case eStateDetached: |
| 3046 | case eStateExited: |
| 3047 | case eStateUnloaded: |
| 3048 | // These events indicate changes in the state of the debugging session, always report them. |
| 3049 | return_value = true; |
| 3050 | break; |
| 3051 | case eStateInvalid: |
| 3052 | // We stopped for no apparent reason, don't report it. |
| 3053 | return_value = false; |
| 3054 | break; |
| 3055 | case eStateRunning: |
| 3056 | case eStateStepping: |
| 3057 | // If we've started the target running, we handle the cases where we |
| 3058 | // are already running and where there is a transition from stopped to |
| 3059 | // running differently. |
| 3060 | // running -> running: Automatically suppress extra running events |
| 3061 | // stopped -> running: Report except when there is one or more no votes |
| 3062 | // and no yes votes. |
| 3063 | SynchronouslyNotifyStateChanged (state); |
| 3064 | switch (m_public_state.GetValue()) |
| 3065 | { |
| 3066 | case eStateRunning: |
| 3067 | case eStateStepping: |
| 3068 | // We always suppress multiple runnings with no PUBLIC stop in between. |
| 3069 | return_value = false; |
| 3070 | break; |
| 3071 | default: |
| 3072 | // TODO: make this work correctly. For now always report |
| 3073 | // run if we aren't running so we don't miss any runnning |
| 3074 | // events. If I run the lldb/test/thread/a.out file and |
| 3075 | // break at main.cpp:58, run and hit the breakpoints on |
| 3076 | // multiple threads, then somehow during the stepping over |
| 3077 | // of all breakpoints no run gets reported. |
| 3078 | return_value = true; |
| 3079 | |
| 3080 | // This is a transition from stop to run. |
| 3081 | switch (m_thread_list.ShouldReportRun (event_ptr)) |
| 3082 | { |
| 3083 | case eVoteYes: |
| 3084 | case eVoteNoOpinion: |
| 3085 | return_value = true; |
| 3086 | break; |
| 3087 | case eVoteNo: |
| 3088 | return_value = false; |
| 3089 | break; |
| 3090 | } |
| 3091 | break; |
| 3092 | } |
| 3093 | break; |
| 3094 | case eStateStopped: |
| 3095 | case eStateCrashed: |
| 3096 | case eStateSuspended: |
| 3097 | { |
| 3098 | // We've stopped. First see if we're going to restart the target. |
| 3099 | // If we are going to stop, then we always broadcast the event. |
| 3100 | // 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] | 3101 | // If no thread has an opinion, we don't report it. |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3102 | if (ProcessEventData::GetInterruptedFromEvent (event_ptr)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3103 | { |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 3104 | if (log) |
| 3105 | log->Printf ("Process::ShouldBroadcastEvent (%p) stopped due to an interrupt, state: %s", event_ptr, StateAsCString(state)); |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3106 | return true; |
| 3107 | } |
| 3108 | else |
| 3109 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3110 | RefreshStateAfterStop (); |
| 3111 | |
| 3112 | if (m_thread_list.ShouldStop (event_ptr) == false) |
| 3113 | { |
| 3114 | switch (m_thread_list.ShouldReportStop (event_ptr)) |
| 3115 | { |
| 3116 | case eVoteYes: |
| 3117 | Process::ProcessEventData::SetRestartedInEvent (event_ptr, true); |
Johnny Chen | 3c23065 | 2010-10-14 00:54:32 +0000 | [diff] [blame] | 3118 | // Intentional fall-through here. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3119 | case eVoteNoOpinion: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3120 | case eVoteNo: |
| 3121 | return_value = false; |
| 3122 | break; |
| 3123 | } |
| 3124 | |
| 3125 | if (log) |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3126 | log->Printf ("Process::ShouldBroadcastEvent (%p) Restarting process from state: %s", event_ptr, StateAsCString(state)); |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 3127 | PrivateResume (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3128 | } |
| 3129 | else |
| 3130 | { |
| 3131 | return_value = true; |
| 3132 | SynchronouslyNotifyStateChanged (state); |
| 3133 | } |
| 3134 | } |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | if (log) |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 3139 | log->Printf ("Process::ShouldBroadcastEvent (%p) => %s - %s", event_ptr, StateAsCString(state), return_value ? "YES" : "NO"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3140 | return return_value; |
| 3141 | } |
| 3142 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3143 | |
| 3144 | bool |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 3145 | Process::StartPrivateStateThread (bool force) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3146 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 3147 | LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3148 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3149 | bool already_running = PrivateStateThreadIsValid (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3150 | if (log) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3151 | log->Printf ("Process::%s()%s ", __FUNCTION__, already_running ? " already running" : " starting private state thread"); |
| 3152 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 3153 | if (!force && already_running) |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3154 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3155 | |
| 3156 | // Create a thread that watches our internal state and controls which |
| 3157 | // events make it to clients (into the DCProcess event queue). |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 3158 | char thread_name[1024]; |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 3159 | if (already_running) |
| 3160 | snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state-override(pid=%llu)>", GetID()); |
| 3161 | else |
| 3162 | snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state(pid=%llu)>", GetID()); |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 3163 | |
| 3164 | // Create the private state thread, and start it running. |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 3165 | m_private_state_thread = Host::ThreadCreate (thread_name, Process::PrivateStateThread, this, NULL); |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 3166 | bool success = IS_VALID_LLDB_HOST_THREAD(m_private_state_thread); |
| 3167 | if (success) |
| 3168 | { |
| 3169 | ResumePrivateStateThread(); |
| 3170 | return true; |
| 3171 | } |
| 3172 | else |
| 3173 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | void |
| 3177 | Process::PausePrivateStateThread () |
| 3178 | { |
| 3179 | ControlPrivateStateThread (eBroadcastInternalStateControlPause); |
| 3180 | } |
| 3181 | |
| 3182 | void |
| 3183 | Process::ResumePrivateStateThread () |
| 3184 | { |
| 3185 | ControlPrivateStateThread (eBroadcastInternalStateControlResume); |
| 3186 | } |
| 3187 | |
| 3188 | void |
| 3189 | Process::StopPrivateStateThread () |
| 3190 | { |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3191 | if (PrivateStateThreadIsValid ()) |
| 3192 | ControlPrivateStateThread (eBroadcastInternalStateControlStop); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3193 | else |
| 3194 | { |
| 3195 | LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); |
| 3196 | if (log) |
| 3197 | printf ("Went to stop the private state thread, but it was already invalid."); |
| 3198 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | void |
| 3202 | Process::ControlPrivateStateThread (uint32_t signal) |
| 3203 | { |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3204 | LogSP log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3205 | |
| 3206 | assert (signal == eBroadcastInternalStateControlStop || |
| 3207 | signal == eBroadcastInternalStateControlPause || |
| 3208 | signal == eBroadcastInternalStateControlResume); |
| 3209 | |
| 3210 | if (log) |
Greg Clayton | 7ecb3a0 | 2011-01-22 17:43:17 +0000 | [diff] [blame] | 3211 | log->Printf ("Process::%s (signal = %d)", __FUNCTION__, signal); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3212 | |
Greg Clayton | 7ecb3a0 | 2011-01-22 17:43:17 +0000 | [diff] [blame] | 3213 | // Signal the private state thread. First we should copy this is case the |
| 3214 | // thread starts exiting since the private state thread will NULL this out |
| 3215 | // when it exits |
| 3216 | const lldb::thread_t private_state_thread = m_private_state_thread; |
Greg Clayton | 2da6d49 | 2011-02-08 01:34:25 +0000 | [diff] [blame] | 3217 | if (IS_VALID_LLDB_HOST_THREAD(private_state_thread)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3218 | { |
| 3219 | TimeValue timeout_time; |
| 3220 | bool timed_out; |
| 3221 | |
| 3222 | m_private_state_control_broadcaster.BroadcastEvent (signal, NULL); |
| 3223 | |
| 3224 | timeout_time = TimeValue::Now(); |
| 3225 | timeout_time.OffsetWithSeconds(2); |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3226 | if (log) |
| 3227 | log->Printf ("Sending control event of type: %d.", signal); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3228 | m_private_state_control_wait.WaitForValueEqualTo (true, &timeout_time, &timed_out); |
| 3229 | m_private_state_control_wait.SetValue (false, eBroadcastNever); |
| 3230 | |
| 3231 | if (signal == eBroadcastInternalStateControlStop) |
| 3232 | { |
| 3233 | if (timed_out) |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3234 | { |
| 3235 | Error error; |
| 3236 | Host::ThreadCancel (private_state_thread, &error); |
| 3237 | if (log) |
| 3238 | log->Printf ("Timed out responding to the control event, cancel got error: \"%s\".", error.AsCString()); |
| 3239 | } |
| 3240 | else |
| 3241 | { |
| 3242 | if (log) |
| 3243 | log->Printf ("The control event killed the private state thread without having to cancel."); |
| 3244 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3245 | |
| 3246 | thread_result_t result = NULL; |
Greg Clayton | 7ecb3a0 | 2011-01-22 17:43:17 +0000 | [diff] [blame] | 3247 | Host::ThreadJoin (private_state_thread, &result, NULL); |
Greg Clayton | 49182ed | 2010-07-22 18:34:21 +0000 | [diff] [blame] | 3248 | m_private_state_thread = LLDB_INVALID_HOST_THREAD; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3249 | } |
| 3250 | } |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3251 | else |
| 3252 | { |
| 3253 | if (log) |
| 3254 | log->Printf ("Private state thread already dead, no need to signal it to stop."); |
| 3255 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | void |
| 3259 | Process::HandlePrivateEvent (EventSP &event_sp) |
| 3260 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 3261 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3262 | |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 3263 | const StateType new_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3264 | |
| 3265 | // First check to see if anybody wants a shot at this event: |
Jim Ingham | 754ab98 | 2011-01-29 04:05:41 +0000 | [diff] [blame] | 3266 | if (m_next_event_action_ap.get() != NULL) |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3267 | { |
Jim Ingham | 754ab98 | 2011-01-29 04:05:41 +0000 | [diff] [blame] | 3268 | NextEventAction::EventActionResult action_result = m_next_event_action_ap->PerformAction(event_sp); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3269 | switch (action_result) |
| 3270 | { |
| 3271 | case NextEventAction::eEventActionSuccess: |
| 3272 | SetNextEventAction(NULL); |
| 3273 | break; |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 3274 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3275 | case NextEventAction::eEventActionRetry: |
| 3276 | break; |
Greg Clayton | c9ed478 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 3277 | |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3278 | case NextEventAction::eEventActionExit: |
Jim Ingham | 2a5fdd4 | 2011-01-29 01:57:31 +0000 | [diff] [blame] | 3279 | // Handle Exiting Here. If we already got an exited event, |
| 3280 | // we should just propagate it. Otherwise, swallow this event, |
| 3281 | // and set our state to exit so the next event will kill us. |
| 3282 | if (new_state != eStateExited) |
| 3283 | { |
| 3284 | // FIXME: should cons up an exited event, and discard this one. |
Jim Ingham | 754ab98 | 2011-01-29 04:05:41 +0000 | [diff] [blame] | 3285 | SetExitStatus(0, m_next_event_action_ap->GetExitString()); |
Jim Ingham | 2a5fdd4 | 2011-01-29 01:57:31 +0000 | [diff] [blame] | 3286 | SetNextEventAction(NULL); |
| 3287 | return; |
| 3288 | } |
| 3289 | SetNextEventAction(NULL); |
Jim Ingham | bb3a283 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 3290 | break; |
| 3291 | } |
| 3292 | } |
| 3293 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3294 | // See if we should broadcast this state to external clients? |
| 3295 | const bool should_broadcast = ShouldBroadcastEvent (event_sp.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3296 | |
| 3297 | if (should_broadcast) |
| 3298 | { |
| 3299 | if (log) |
| 3300 | { |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3301 | log->Printf ("Process::%s (pid = %llu) broadcasting new state %s (old state %s) to %s", |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 3302 | __FUNCTION__, |
| 3303 | GetID(), |
| 3304 | StateAsCString(new_state), |
| 3305 | StateAsCString (GetState ()), |
| 3306 | IsHijackedForEvent(eBroadcastBitStateChanged) ? "hijacked" : "public"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3307 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3308 | Process::ProcessEventData::SetUpdateStateOnRemoval(event_sp.get()); |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 3309 | if (StateIsRunningState (new_state)) |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 3310 | PushProcessInputReader (); |
| 3311 | else |
| 3312 | PopProcessInputReader (); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3313 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3314 | BroadcastEvent (event_sp); |
| 3315 | } |
| 3316 | else |
| 3317 | { |
| 3318 | if (log) |
| 3319 | { |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3320 | log->Printf ("Process::%s (pid = %llu) suppressing state %s (old state %s): should_broadcast == false", |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 3321 | __FUNCTION__, |
| 3322 | GetID(), |
| 3323 | StateAsCString(new_state), |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 3324 | StateAsCString (GetState ())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3325 | } |
| 3326 | } |
| 3327 | } |
| 3328 | |
| 3329 | void * |
| 3330 | Process::PrivateStateThread (void *arg) |
| 3331 | { |
| 3332 | Process *proc = static_cast<Process*> (arg); |
| 3333 | void *result = proc->RunPrivateStateThread (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3334 | return result; |
| 3335 | } |
| 3336 | |
| 3337 | void * |
| 3338 | Process::RunPrivateStateThread () |
| 3339 | { |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 3340 | bool control_only = true; |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3341 | m_private_state_control_wait.SetValue (false, eBroadcastNever); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3342 | |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 3343 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3344 | if (log) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3345 | log->Printf ("Process::%s (arg = %p, pid = %llu) thread starting...", __FUNCTION__, this, GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3346 | |
| 3347 | bool exit_now = false; |
| 3348 | while (!exit_now) |
| 3349 | { |
| 3350 | EventSP event_sp; |
| 3351 | WaitForEventsPrivate (NULL, event_sp, control_only); |
| 3352 | if (event_sp->BroadcasterIs(&m_private_state_control_broadcaster)) |
| 3353 | { |
Jim Ingham | b1e2e84 | 2012-04-12 18:49:31 +0000 | [diff] [blame] | 3354 | if (log) |
| 3355 | log->Printf ("Process::%s (arg = %p, pid = %llu) got a control event: %d", __FUNCTION__, this, GetID(), event_sp->GetType()); |
| 3356 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3357 | switch (event_sp->GetType()) |
| 3358 | { |
| 3359 | case eBroadcastInternalStateControlStop: |
| 3360 | exit_now = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3361 | break; // doing any internal state managment below |
| 3362 | |
| 3363 | case eBroadcastInternalStateControlPause: |
| 3364 | control_only = true; |
| 3365 | break; |
| 3366 | |
| 3367 | case eBroadcastInternalStateControlResume: |
| 3368 | control_only = false; |
| 3369 | break; |
| 3370 | } |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3371 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3372 | m_private_state_control_wait.SetValue (true, eBroadcastAlways); |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3373 | continue; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | |
| 3377 | const StateType internal_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 3378 | |
| 3379 | if (internal_state != eStateInvalid) |
| 3380 | { |
| 3381 | HandlePrivateEvent (event_sp); |
| 3382 | } |
| 3383 | |
Greg Clayton | 58d1c9a | 2010-10-18 04:14:23 +0000 | [diff] [blame] | 3384 | if (internal_state == eStateInvalid || |
| 3385 | internal_state == eStateExited || |
| 3386 | internal_state == eStateDetached ) |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3387 | { |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3388 | if (log) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3389 | log->Printf ("Process::%s (arg = %p, pid = %llu) about to exit with internal state %s...", __FUNCTION__, this, GetID(), StateAsCString(internal_state)); |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3390 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3391 | break; |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3392 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3393 | } |
| 3394 | |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 3395 | // Verify log is still enabled before attempting to write to it... |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3396 | if (log) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3397 | log->Printf ("Process::%s (arg = %p, pid = %llu) thread exiting...", __FUNCTION__, this, GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3398 | |
Greg Clayton | 6ed9594 | 2011-01-22 07:12:45 +0000 | [diff] [blame] | 3399 | m_private_state_control_wait.SetValue (true, eBroadcastAlways); |
| 3400 | m_private_state_thread = LLDB_INVALID_HOST_THREAD; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3401 | return NULL; |
| 3402 | } |
| 3403 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3404 | //------------------------------------------------------------------ |
| 3405 | // Process Event Data |
| 3406 | //------------------------------------------------------------------ |
| 3407 | |
| 3408 | Process::ProcessEventData::ProcessEventData () : |
| 3409 | EventData (), |
| 3410 | m_process_sp (), |
| 3411 | m_state (eStateInvalid), |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 3412 | m_restarted (false), |
Jim Ingham | a860469 | 2011-05-22 21:45:01 +0000 | [diff] [blame] | 3413 | m_update_state (0), |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3414 | m_interrupted (false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3415 | { |
| 3416 | } |
| 3417 | |
| 3418 | Process::ProcessEventData::ProcessEventData (const ProcessSP &process_sp, StateType state) : |
| 3419 | EventData (), |
| 3420 | m_process_sp (process_sp), |
| 3421 | m_state (state), |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 3422 | m_restarted (false), |
Jim Ingham | a860469 | 2011-05-22 21:45:01 +0000 | [diff] [blame] | 3423 | m_update_state (0), |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3424 | m_interrupted (false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3425 | { |
| 3426 | } |
| 3427 | |
| 3428 | Process::ProcessEventData::~ProcessEventData() |
| 3429 | { |
| 3430 | } |
| 3431 | |
| 3432 | const ConstString & |
| 3433 | Process::ProcessEventData::GetFlavorString () |
| 3434 | { |
| 3435 | static ConstString g_flavor ("Process::ProcessEventData"); |
| 3436 | return g_flavor; |
| 3437 | } |
| 3438 | |
| 3439 | const ConstString & |
| 3440 | Process::ProcessEventData::GetFlavor () const |
| 3441 | { |
| 3442 | return ProcessEventData::GetFlavorString (); |
| 3443 | } |
| 3444 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3445 | void |
| 3446 | Process::ProcessEventData::DoOnRemoval (Event *event_ptr) |
| 3447 | { |
| 3448 | // 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] | 3449 | // off of the private process event queue, and then any number of times, first when it gets pulled off of |
| 3450 | // the public event queue, then other times when we're pretending that this is where we stopped at the |
| 3451 | // end of expression evaluation. m_update_state is used to distinguish these |
| 3452 | // three cases; it is 0 when we're just pulling it off for private handling, |
| 3453 | // and > 1 for expression evaluation, and we don't want to do the breakpoint command handling then. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3454 | |
Jim Ingham | a860469 | 2011-05-22 21:45:01 +0000 | [diff] [blame] | 3455 | if (m_update_state != 1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3456 | return; |
| 3457 | |
| 3458 | m_process_sp->SetPublicState (m_state); |
| 3459 | |
| 3460 | // If we're stopped and haven't restarted, then do the breakpoint commands here: |
| 3461 | if (m_state == eStateStopped && ! m_restarted) |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 3462 | { |
| 3463 | ThreadList &curr_thread_list = m_process_sp->GetThreadList(); |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 3464 | uint32_t num_threads = curr_thread_list.GetSize(); |
| 3465 | uint32_t idx; |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 3466 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3467 | // The actions might change one of the thread's stop_info's opinions about whether we should |
| 3468 | // stop the process, so we need to query that as we go. |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 3469 | |
| 3470 | // One other complication here, is that we try to catch any case where the target has run (except for expressions) |
| 3471 | // and immediately exit, but if we get that wrong (which is possible) then the thread list might have changed, and |
| 3472 | // that would cause our iteration here to crash. We could make a copy of the thread list, but we'd really like |
| 3473 | // 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 |
| 3474 | // against this list & bag out if anything differs. |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 3475 | std::vector<uint32_t> thread_index_array(num_threads); |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 3476 | for (idx = 0; idx < num_threads; ++idx) |
| 3477 | thread_index_array[idx] = curr_thread_list.GetThreadAtIndex(idx)->GetIndexID(); |
| 3478 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3479 | bool still_should_stop = true; |
| 3480 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3481 | for (idx = 0; idx < num_threads; ++idx) |
| 3482 | { |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 3483 | curr_thread_list = m_process_sp->GetThreadList(); |
| 3484 | if (curr_thread_list.GetSize() != num_threads) |
| 3485 | { |
| 3486 | lldb::LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 87c665f | 2011-12-01 20:26:15 +0000 | [diff] [blame] | 3487 | if (log) |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 3488 | 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] | 3489 | break; |
| 3490 | } |
| 3491 | |
| 3492 | lldb::ThreadSP thread_sp = curr_thread_list.GetThreadAtIndex(idx); |
| 3493 | |
| 3494 | if (thread_sp->GetIndexID() != thread_index_array[idx]) |
| 3495 | { |
| 3496 | lldb::LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 87c665f | 2011-12-01 20:26:15 +0000 | [diff] [blame] | 3497 | if (log) |
Greg Clayton | 61e7a58 | 2011-12-01 23:28:38 +0000 | [diff] [blame] | 3498 | 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] | 3499 | idx, |
| 3500 | thread_index_array[idx], |
| 3501 | thread_sp->GetIndexID()); |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 3502 | break; |
| 3503 | } |
| 3504 | |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 3505 | StopInfoSP stop_info_sp = thread_sp->GetStopInfo (); |
| 3506 | if (stop_info_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3507 | { |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 3508 | stop_info_sp->PerformAction(event_ptr); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3509 | // The stop action might restart the target. If it does, then we want to mark that in the |
| 3510 | // event so that whoever is receiving it will know to wait for the running event and reflect |
| 3511 | // that state appropriately. |
| 3512 | // We also need to stop processing actions, since they aren't expecting the target to be running. |
Jim Ingham | 0faa43f | 2011-11-08 03:00:11 +0000 | [diff] [blame] | 3513 | |
| 3514 | // FIXME: we might have run. |
| 3515 | if (stop_info_sp->HasTargetRunSinceMe()) |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3516 | { |
| 3517 | SetRestarted (true); |
| 3518 | break; |
| 3519 | } |
| 3520 | else if (!stop_info_sp->ShouldStop(event_ptr)) |
| 3521 | { |
| 3522 | still_should_stop = false; |
| 3523 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3524 | } |
| 3525 | } |
Jim Ingham | 3ebcf7f | 2010-08-10 00:59:59 +0000 | [diff] [blame] | 3526 | |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3527 | |
| 3528 | if (m_process_sp->GetPrivateState() != eStateRunning) |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3529 | { |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3530 | if (!still_should_stop) |
| 3531 | { |
| 3532 | // We've been asked to continue, so do that here. |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3533 | SetRestarted(true); |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 3534 | // Use the public resume method here, since this is just |
| 3535 | // extending a public resume. |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 3536 | m_process_sp->Resume(); |
| 3537 | } |
| 3538 | else |
| 3539 | { |
| 3540 | // If we didn't restart, run the Stop Hooks here: |
| 3541 | // They might also restart the target, so watch for that. |
| 3542 | m_process_sp->GetTarget().RunStopHooks(); |
| 3543 | if (m_process_sp->GetPrivateState() == eStateRunning) |
| 3544 | SetRestarted(true); |
| 3545 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3546 | } |
| 3547 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3548 | } |
| 3549 | } |
| 3550 | |
| 3551 | void |
| 3552 | Process::ProcessEventData::Dump (Stream *s) const |
| 3553 | { |
| 3554 | if (m_process_sp) |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 3555 | s->Printf(" process = %p (pid = %llu), ", m_process_sp.get(), m_process_sp->GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3556 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 3557 | s->Printf("state = %s", StateAsCString(GetState())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | const Process::ProcessEventData * |
| 3561 | Process::ProcessEventData::GetEventDataFromEvent (const Event *event_ptr) |
| 3562 | { |
| 3563 | if (event_ptr) |
| 3564 | { |
| 3565 | const EventData *event_data = event_ptr->GetData(); |
| 3566 | if (event_data && event_data->GetFlavor() == ProcessEventData::GetFlavorString()) |
| 3567 | return static_cast <const ProcessEventData *> (event_ptr->GetData()); |
| 3568 | } |
| 3569 | return NULL; |
| 3570 | } |
| 3571 | |
| 3572 | ProcessSP |
| 3573 | Process::ProcessEventData::GetProcessFromEvent (const Event *event_ptr) |
| 3574 | { |
| 3575 | ProcessSP process_sp; |
| 3576 | const ProcessEventData *data = GetEventDataFromEvent (event_ptr); |
| 3577 | if (data) |
| 3578 | process_sp = data->GetProcessSP(); |
| 3579 | return process_sp; |
| 3580 | } |
| 3581 | |
| 3582 | StateType |
| 3583 | Process::ProcessEventData::GetStateFromEvent (const Event *event_ptr) |
| 3584 | { |
| 3585 | const ProcessEventData *data = GetEventDataFromEvent (event_ptr); |
| 3586 | if (data == NULL) |
| 3587 | return eStateInvalid; |
| 3588 | else |
| 3589 | return data->GetState(); |
| 3590 | } |
| 3591 | |
| 3592 | bool |
| 3593 | Process::ProcessEventData::GetRestartedFromEvent (const Event *event_ptr) |
| 3594 | { |
| 3595 | const ProcessEventData *data = GetEventDataFromEvent (event_ptr); |
| 3596 | if (data == NULL) |
| 3597 | return false; |
| 3598 | else |
| 3599 | return data->GetRestarted(); |
| 3600 | } |
| 3601 | |
| 3602 | void |
| 3603 | Process::ProcessEventData::SetRestartedInEvent (Event *event_ptr, bool new_value) |
| 3604 | { |
| 3605 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 3606 | if (data != NULL) |
| 3607 | data->SetRestarted(new_value); |
| 3608 | } |
| 3609 | |
| 3610 | bool |
Jim Ingham | 0d8bcc7 | 2010-11-17 02:32:00 +0000 | [diff] [blame] | 3611 | Process::ProcessEventData::GetInterruptedFromEvent (const Event *event_ptr) |
| 3612 | { |
| 3613 | const ProcessEventData *data = GetEventDataFromEvent (event_ptr); |
| 3614 | if (data == NULL) |
| 3615 | return false; |
| 3616 | else |
| 3617 | return data->GetInterrupted (); |
| 3618 | } |
| 3619 | |
| 3620 | void |
| 3621 | Process::ProcessEventData::SetInterruptedInEvent (Event *event_ptr, bool new_value) |
| 3622 | { |
| 3623 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 3624 | if (data != NULL) |
| 3625 | data->SetInterrupted(new_value); |
| 3626 | } |
| 3627 | |
| 3628 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3629 | Process::ProcessEventData::SetUpdateStateOnRemoval (Event *event_ptr) |
| 3630 | { |
| 3631 | ProcessEventData *data = const_cast<ProcessEventData *>(GetEventDataFromEvent (event_ptr)); |
| 3632 | if (data) |
| 3633 | { |
| 3634 | data->SetUpdateStateOnRemoval(); |
| 3635 | return true; |
| 3636 | } |
| 3637 | return false; |
| 3638 | } |
| 3639 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 3640 | lldb::TargetSP |
| 3641 | Process::CalculateTarget () |
| 3642 | { |
| 3643 | return m_target.shared_from_this(); |
| 3644 | } |
| 3645 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3646 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 3647 | Process::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3648 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 3649 | exe_ctx.SetTargetPtr (&m_target); |
| 3650 | exe_ctx.SetProcessPtr (this); |
| 3651 | exe_ctx.SetThreadPtr(NULL); |
| 3652 | exe_ctx.SetFramePtr (NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3653 | } |
| 3654 | |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 3655 | //uint32_t |
| 3656 | //Process::ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids) |
| 3657 | //{ |
| 3658 | // return 0; |
| 3659 | //} |
| 3660 | // |
| 3661 | //ArchSpec |
| 3662 | //Process::GetArchSpecForExistingProcess (lldb::pid_t pid) |
| 3663 | //{ |
| 3664 | // return Host::GetArchSpecForExistingProcess (pid); |
| 3665 | //} |
| 3666 | // |
| 3667 | //ArchSpec |
| 3668 | //Process::GetArchSpecForExistingProcess (const char *process_name) |
| 3669 | //{ |
| 3670 | // return Host::GetArchSpecForExistingProcess (process_name); |
| 3671 | //} |
| 3672 | // |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 3673 | void |
| 3674 | Process::AppendSTDOUT (const char * s, size_t len) |
| 3675 | { |
Greg Clayton | 3af9ea5 | 2010-11-18 05:57:03 +0000 | [diff] [blame] | 3676 | Mutex::Locker locker (m_stdio_communication_mutex); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 3677 | m_stdout_data.append (s, len); |
Greg Clayton | a9ff306 | 2010-12-05 19:16:56 +0000 | [diff] [blame] | 3678 | BroadcastEventIfUnique (eBroadcastBitSTDOUT, new ProcessEventData (GetTarget().GetProcessSP(), GetState())); |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 3679 | } |
| 3680 | |
| 3681 | void |
Greg Clayton | 93e8619 | 2011-11-13 04:45:22 +0000 | [diff] [blame] | 3682 | Process::AppendSTDERR (const char * s, size_t len) |
| 3683 | { |
| 3684 | Mutex::Locker locker (m_stdio_communication_mutex); |
| 3685 | m_stderr_data.append (s, len); |
| 3686 | BroadcastEventIfUnique (eBroadcastBitSTDERR, new ProcessEventData (GetTarget().GetProcessSP(), GetState())); |
| 3687 | } |
| 3688 | |
| 3689 | //------------------------------------------------------------------ |
| 3690 | // Process STDIO |
| 3691 | //------------------------------------------------------------------ |
| 3692 | |
| 3693 | size_t |
| 3694 | Process::GetSTDOUT (char *buf, size_t buf_size, Error &error) |
| 3695 | { |
| 3696 | Mutex::Locker locker(m_stdio_communication_mutex); |
| 3697 | size_t bytes_available = m_stdout_data.size(); |
| 3698 | if (bytes_available > 0) |
| 3699 | { |
| 3700 | LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 3701 | if (log) |
| 3702 | log->Printf ("Process::GetSTDOUT (buf = %p, size = %zu)", buf, buf_size); |
| 3703 | if (bytes_available > buf_size) |
| 3704 | { |
| 3705 | memcpy(buf, m_stdout_data.c_str(), buf_size); |
| 3706 | m_stdout_data.erase(0, buf_size); |
| 3707 | bytes_available = buf_size; |
| 3708 | } |
| 3709 | else |
| 3710 | { |
| 3711 | memcpy(buf, m_stdout_data.c_str(), bytes_available); |
| 3712 | m_stdout_data.clear(); |
| 3713 | } |
| 3714 | } |
| 3715 | return bytes_available; |
| 3716 | } |
| 3717 | |
| 3718 | |
| 3719 | size_t |
| 3720 | Process::GetSTDERR (char *buf, size_t buf_size, Error &error) |
| 3721 | { |
| 3722 | Mutex::Locker locker(m_stdio_communication_mutex); |
| 3723 | size_t bytes_available = m_stderr_data.size(); |
| 3724 | if (bytes_available > 0) |
| 3725 | { |
| 3726 | LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 3727 | if (log) |
| 3728 | log->Printf ("Process::GetSTDERR (buf = %p, size = %zu)", buf, buf_size); |
| 3729 | if (bytes_available > buf_size) |
| 3730 | { |
| 3731 | memcpy(buf, m_stderr_data.c_str(), buf_size); |
| 3732 | m_stderr_data.erase(0, buf_size); |
| 3733 | bytes_available = buf_size; |
| 3734 | } |
| 3735 | else |
| 3736 | { |
| 3737 | memcpy(buf, m_stderr_data.c_str(), bytes_available); |
| 3738 | m_stderr_data.clear(); |
| 3739 | } |
| 3740 | } |
| 3741 | return bytes_available; |
| 3742 | } |
| 3743 | |
| 3744 | void |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 3745 | Process::STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len) |
| 3746 | { |
| 3747 | Process *process = (Process *) baton; |
| 3748 | process->AppendSTDOUT (static_cast<const char *>(src), src_len); |
| 3749 | } |
| 3750 | |
| 3751 | size_t |
| 3752 | Process::ProcessInputReaderCallback (void *baton, |
| 3753 | InputReader &reader, |
| 3754 | lldb::InputReaderAction notification, |
| 3755 | const char *bytes, |
| 3756 | size_t bytes_len) |
| 3757 | { |
| 3758 | Process *process = (Process *) baton; |
| 3759 | |
| 3760 | switch (notification) |
| 3761 | { |
| 3762 | case eInputReaderActivate: |
| 3763 | break; |
| 3764 | |
| 3765 | case eInputReaderDeactivate: |
| 3766 | break; |
| 3767 | |
| 3768 | case eInputReaderReactivate: |
| 3769 | break; |
| 3770 | |
Caroline Tice | 969ed3d | 2011-05-02 20:41:46 +0000 | [diff] [blame] | 3771 | case eInputReaderAsynchronousOutputWritten: |
| 3772 | break; |
| 3773 | |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 3774 | case eInputReaderGotToken: |
| 3775 | { |
| 3776 | Error error; |
| 3777 | process->PutSTDIN (bytes, bytes_len, error); |
| 3778 | } |
| 3779 | break; |
| 3780 | |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 3781 | case eInputReaderInterrupt: |
| 3782 | process->Halt (); |
| 3783 | break; |
| 3784 | |
| 3785 | case eInputReaderEndOfFile: |
| 3786 | process->AppendSTDOUT ("^D", 2); |
| 3787 | break; |
| 3788 | |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 3789 | case eInputReaderDone: |
| 3790 | break; |
| 3791 | |
| 3792 | } |
| 3793 | |
| 3794 | return bytes_len; |
| 3795 | } |
| 3796 | |
| 3797 | void |
| 3798 | Process::ResetProcessInputReader () |
| 3799 | { |
| 3800 | m_process_input_reader.reset(); |
| 3801 | } |
| 3802 | |
| 3803 | void |
Greg Clayton | ee95ed5 | 2011-11-17 22:14:31 +0000 | [diff] [blame] | 3804 | Process::SetSTDIOFileDescriptor (int file_descriptor) |
Caroline Tice | ef5c6d0 | 2010-11-16 05:07:41 +0000 | [diff] [blame] | 3805 | { |
| 3806 | // First set up the Read Thread for reading/handling process I/O |
| 3807 | |
| 3808 | std::auto_ptr<ConnectionFileDescriptor> conn_ap (new ConnectionFileDescriptor (file_descriptor, true)); |
| 3809 | |
| 3810 | if (conn_ap.get()) |
| 3811 | { |
| 3812 | m_stdio_communication.SetConnection (conn_ap.release()); |
| 3813 | if (m_stdio_communication.IsConnected()) |
| 3814 | { |
| 3815 | m_stdio_communication.SetReadThreadBytesReceivedCallback (STDIOReadThreadBytesReceived, this); |
| 3816 | m_stdio_communication.StartReadThread(); |
| 3817 | |
| 3818 | // Now read thread is set up, set up input reader. |
| 3819 | |
| 3820 | if (!m_process_input_reader.get()) |
| 3821 | { |
| 3822 | m_process_input_reader.reset (new InputReader(m_target.GetDebugger())); |
| 3823 | Error err (m_process_input_reader->Initialize (Process::ProcessInputReaderCallback, |
| 3824 | this, |
| 3825 | eInputReaderGranularityByte, |
| 3826 | NULL, |
| 3827 | NULL, |
| 3828 | false)); |
| 3829 | |
| 3830 | if (err.Fail()) |
| 3831 | m_process_input_reader.reset(); |
| 3832 | } |
| 3833 | } |
| 3834 | } |
| 3835 | } |
| 3836 | |
| 3837 | void |
| 3838 | Process::PushProcessInputReader () |
| 3839 | { |
| 3840 | if (m_process_input_reader && !m_process_input_reader->IsActive()) |
| 3841 | m_target.GetDebugger().PushInputReader (m_process_input_reader); |
| 3842 | } |
| 3843 | |
| 3844 | void |
| 3845 | Process::PopProcessInputReader () |
| 3846 | { |
| 3847 | if (m_process_input_reader && m_process_input_reader->IsActive()) |
| 3848 | m_target.GetDebugger().PopInputReader (m_process_input_reader); |
| 3849 | } |
| 3850 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 3851 | // The process needs to know about installed plug-ins |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 3852 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 3853 | Process::SettingsInitialize () |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 3854 | { |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 3855 | static std::vector<OptionEnumValueElement> g_plugins; |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 3856 | |
| 3857 | int i=0; |
| 3858 | const char *name; |
| 3859 | OptionEnumValueElement option_enum; |
| 3860 | while ((name = PluginManager::GetProcessPluginNameAtIndex (i)) != NULL) |
| 3861 | { |
| 3862 | if (name) |
| 3863 | { |
| 3864 | option_enum.value = i; |
| 3865 | option_enum.string_value = name; |
| 3866 | option_enum.usage = PluginManager::GetProcessPluginDescriptionAtIndex (i); |
| 3867 | g_plugins.push_back (option_enum); |
| 3868 | } |
| 3869 | ++i; |
| 3870 | } |
| 3871 | option_enum.value = 0; |
| 3872 | option_enum.string_value = NULL; |
| 3873 | option_enum.usage = NULL; |
| 3874 | g_plugins.push_back (option_enum); |
| 3875 | |
| 3876 | for (i=0; (name = SettingsController::instance_settings_table[i].var_name); ++i) |
| 3877 | { |
| 3878 | if (::strcmp (name, "plugin") == 0) |
| 3879 | { |
| 3880 | SettingsController::instance_settings_table[i].enum_values = &g_plugins[0]; |
| 3881 | break; |
| 3882 | } |
| 3883 | } |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 3884 | UserSettingsControllerSP &usc = GetSettingsController(); |
| 3885 | usc.reset (new SettingsController); |
| 3886 | UserSettingsController::InitializeSettingsController (usc, |
| 3887 | SettingsController::global_settings_table, |
| 3888 | SettingsController::instance_settings_table); |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 3889 | |
| 3890 | // Now call SettingsInitialize() for each 'child' of Process settings |
| 3891 | Thread::SettingsInitialize (); |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 3892 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 3893 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 3894 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 3895 | Process::SettingsTerminate () |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 3896 | { |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 3897 | // Must call SettingsTerminate() on each 'child' of Process settings before terminating Process settings. |
| 3898 | |
| 3899 | Thread::SettingsTerminate (); |
| 3900 | |
| 3901 | // Now terminate Process Settings. |
| 3902 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 3903 | UserSettingsControllerSP &usc = GetSettingsController(); |
| 3904 | UserSettingsController::FinalizeSettingsController (usc); |
| 3905 | usc.reset(); |
| 3906 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 3907 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 3908 | UserSettingsControllerSP & |
| 3909 | Process::GetSettingsController () |
| 3910 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 3911 | static UserSettingsControllerSP g_settings_controller_sp; |
| 3912 | if (!g_settings_controller_sp) |
| 3913 | { |
| 3914 | g_settings_controller_sp.reset (new Process::SettingsController); |
| 3915 | // The first shared pointer to Process::SettingsController in |
| 3916 | // g_settings_controller_sp must be fully created above so that |
| 3917 | // the TargetInstanceSettings can use a weak_ptr to refer back |
| 3918 | // to the master setttings controller |
| 3919 | InstanceSettingsSP default_instance_settings_sp (new ProcessInstanceSettings (g_settings_controller_sp, |
| 3920 | false, |
| 3921 | InstanceSettings::GetDefaultName().AsCString())); |
| 3922 | g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp); |
| 3923 | } |
| 3924 | return g_settings_controller_sp; |
| 3925 | |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 3926 | } |
| 3927 | |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 3928 | void |
| 3929 | Process::UpdateInstanceName () |
| 3930 | { |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 3931 | Module *module = GetTarget().GetExecutableModulePointer(); |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3932 | if (module && module->GetFileSpec().GetFilename()) |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 3933 | { |
Greg Clayton | dbe5450 | 2010-11-19 03:46:01 +0000 | [diff] [blame] | 3934 | GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 3935 | module->GetFileSpec().GetFilename().AsCString()); |
Caroline Tice | 1559a46 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 3936 | } |
| 3937 | } |
| 3938 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 3939 | ExecutionResults |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 3940 | Process::RunThreadPlan (ExecutionContext &exe_ctx, |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 3941 | lldb::ThreadPlanSP &thread_plan_sp, |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 3942 | bool stop_others, |
| 3943 | bool try_all_threads, |
| 3944 | bool discard_on_error, |
| 3945 | uint32_t single_thread_timeout_usec, |
| 3946 | Stream &errors) |
| 3947 | { |
| 3948 | ExecutionResults return_value = eExecutionSetupError; |
| 3949 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 3950 | if (thread_plan_sp.get() == NULL) |
| 3951 | { |
| 3952 | errors.Printf("RunThreadPlan called with empty thread plan."); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 3953 | return eExecutionSetupError; |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 3954 | } |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 3955 | |
| 3956 | if (exe_ctx.GetProcessPtr() != this) |
| 3957 | { |
| 3958 | errors.Printf("RunThreadPlan called on wrong process."); |
| 3959 | return eExecutionSetupError; |
| 3960 | } |
| 3961 | |
| 3962 | Thread *thread = exe_ctx.GetThreadPtr(); |
| 3963 | if (thread == NULL) |
| 3964 | { |
| 3965 | errors.Printf("RunThreadPlan called with invalid thread."); |
| 3966 | return eExecutionSetupError; |
| 3967 | } |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 3968 | |
Jim Ingham | 17e5c4e | 2011-05-17 22:24:54 +0000 | [diff] [blame] | 3969 | // We rely on the thread plan we are running returning "PlanCompleted" if when it successfully completes. |
| 3970 | // For that to be true the plan can't be private - since private plans suppress themselves in the |
| 3971 | // GetCompletedPlan call. |
| 3972 | |
| 3973 | bool orig_plan_private = thread_plan_sp->GetPrivate(); |
| 3974 | thread_plan_sp->SetPrivate(false); |
| 3975 | |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 3976 | if (m_private_state.GetValue() != eStateStopped) |
| 3977 | { |
| 3978 | errors.Printf ("RunThreadPlan called while the private state was not stopped."); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 3979 | return eExecutionSetupError; |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 3980 | } |
| 3981 | |
Jim Ingham | 6624384 | 2011-08-13 00:56:10 +0000 | [diff] [blame] | 3982 | // 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] | 3983 | const uint32_t thread_idx_id = thread->GetIndexID(); |
| 3984 | StackID ctx_frame_id = thread->GetSelectedFrame()->GetStackID(); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 3985 | |
| 3986 | // N.B. Running the target may unset the currently selected thread and frame. We don't want to do that either, |
| 3987 | // so we should arrange to reset them as well. |
| 3988 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 3989 | lldb::ThreadSP selected_thread_sp = GetThreadList().GetSelectedThread(); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 3990 | |
Jim Ingham | 6624384 | 2011-08-13 00:56:10 +0000 | [diff] [blame] | 3991 | uint32_t selected_tid; |
| 3992 | StackID selected_stack_id; |
Greg Clayton | 762f713 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 3993 | if (selected_thread_sp) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 3994 | { |
| 3995 | selected_tid = selected_thread_sp->GetIndexID(); |
Jim Ingham | 6624384 | 2011-08-13 00:56:10 +0000 | [diff] [blame] | 3996 | selected_stack_id = selected_thread_sp->GetSelectedFrame()->GetStackID(); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 3997 | } |
| 3998 | else |
| 3999 | { |
| 4000 | selected_tid = LLDB_INVALID_THREAD_ID; |
| 4001 | } |
| 4002 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4003 | lldb::thread_t backup_private_state_thread = LLDB_INVALID_HOST_THREAD; |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4004 | lldb::StateType old_state; |
| 4005 | lldb::ThreadPlanSP stopper_base_plan_sp; |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4006 | |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4007 | lldb::LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS)); |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4008 | if (Host::GetCurrentThread() == m_private_state_thread) |
| 4009 | { |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4010 | // Yikes, we are running on the private state thread! So we can't wait for public events on this thread, since |
| 4011 | // we are the thread that is generating public events. |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4012 | // 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] | 4013 | // we are fielding public events here. |
| 4014 | if (log) |
| 4015 | log->Printf ("Running thread plan on private state thread, spinning up another state thread to handle the events."); |
| 4016 | |
| 4017 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4018 | backup_private_state_thread = m_private_state_thread; |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4019 | |
| 4020 | // One other bit of business: we want to run just this thread plan and anything it pushes, and then stop, |
| 4021 | // returning control here. |
| 4022 | // But in the normal course of things, the plan above us on the stack would be given a shot at the stop |
| 4023 | // event before deciding to stop, and we don't want that. So we insert a "stopper" base plan on the stack |
| 4024 | // before the plan we want to run. Since base plans always stop and return control to the user, that will |
| 4025 | // do just what we want. |
| 4026 | stopper_base_plan_sp.reset(new ThreadPlanBase (*thread)); |
| 4027 | thread->QueueThreadPlan (stopper_base_plan_sp, false); |
| 4028 | // Have to make sure our public state is stopped, since otherwise the reporting logic below doesn't work correctly. |
| 4029 | old_state = m_public_state.GetValue(); |
| 4030 | m_public_state.SetValueNoLock(eStateStopped); |
| 4031 | |
| 4032 | // Now spin up the private state thread: |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4033 | StartPrivateStateThread(true); |
| 4034 | } |
| 4035 | |
| 4036 | thread->QueueThreadPlan(thread_plan_sp, false); // This used to pass "true" does that make sense? |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4037 | |
Jim Ingham | 1e7a9ee | 2011-01-23 21:14:08 +0000 | [diff] [blame] | 4038 | Listener listener("lldb.process.listener.run-thread-plan"); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4039 | |
| 4040 | // This process event hijacker Hijacks the Public events and its destructor makes sure that the process events get |
| 4041 | // restored on exit to the function. |
| 4042 | |
| 4043 | ProcessEventHijacker run_thread_plan_hijacker (*this, &listener); |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 4044 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 4045 | if (log) |
| 4046 | { |
| 4047 | StreamString s; |
| 4048 | thread_plan_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4049 | log->Printf ("Process::RunThreadPlan(): Resuming thread %u - 0x%4.4llx to run thread plan \"%s\".", |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4050 | thread->GetIndexID(), |
| 4051 | thread->GetID(), |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4052 | s.GetData()); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 4053 | } |
| 4054 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4055 | bool got_event; |
| 4056 | lldb::EventSP event_sp; |
| 4057 | lldb::StateType stop_state = lldb::eStateInvalid; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4058 | |
| 4059 | TimeValue* timeout_ptr = NULL; |
| 4060 | TimeValue real_timeout; |
| 4061 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4062 | bool first_timeout = true; |
| 4063 | bool do_resume = true; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4064 | |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4065 | while (1) |
| 4066 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4067 | // We usually want to resume the process if we get to the top of the loop. |
| 4068 | // The only exception is if we get two running events with no intervening |
| 4069 | // stop, which can happen, we will just wait for then next stop event. |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4070 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4071 | if (do_resume) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4072 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4073 | // Do the initial resume and wait for the running event before going further. |
| 4074 | |
Jim Ingham | 3b8285d | 2012-04-19 01:40:33 +0000 | [diff] [blame] | 4075 | Error resume_error = PrivateResume (); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4076 | if (!resume_error.Success()) |
| 4077 | { |
| 4078 | errors.Printf("Error resuming inferior: \"%s\".\n", resume_error.AsCString()); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4079 | return_value = eExecutionSetupError; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4080 | break; |
| 4081 | } |
| 4082 | |
| 4083 | real_timeout = TimeValue::Now(); |
| 4084 | real_timeout.OffsetWithMicroSeconds(500000); |
| 4085 | timeout_ptr = &real_timeout; |
| 4086 | |
Sean Callanan | c1b312a | 2012-01-05 02:00:14 +0000 | [diff] [blame] | 4087 | got_event = listener.WaitForEvent(timeout_ptr, event_sp); |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4088 | if (!got_event) |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4089 | { |
| 4090 | if (log) |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4091 | log->PutCString("Process::RunThreadPlan(): didn't get any event after initial resume, exiting."); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4092 | |
| 4093 | errors.Printf("Didn't get any event after initial resume, exiting."); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4094 | return_value = eExecutionSetupError; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4095 | break; |
| 4096 | } |
| 4097 | |
| 4098 | stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 4099 | if (stop_state != eStateRunning) |
| 4100 | { |
| 4101 | if (log) |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4102 | log->Printf("Process::RunThreadPlan(): didn't get running event after initial resume, got %s instead.", StateAsCString(stop_state)); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4103 | |
| 4104 | errors.Printf("Didn't get running event after initial resume, got %s instead.", StateAsCString(stop_state)); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4105 | return_value = eExecutionSetupError; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4106 | break; |
| 4107 | } |
| 4108 | |
| 4109 | if (log) |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4110 | log->PutCString ("Process::RunThreadPlan(): resuming succeeded."); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4111 | // We need to call the function synchronously, so spin waiting for it to return. |
| 4112 | // If we get interrupted while executing, we're going to lose our context, and |
| 4113 | // won't be able to gather the result at this point. |
| 4114 | // We set the timeout AFTER the resume, since the resume takes some time and we |
| 4115 | // don't want to charge that to the timeout. |
| 4116 | |
| 4117 | if (single_thread_timeout_usec != 0) |
| 4118 | { |
| 4119 | real_timeout = TimeValue::Now(); |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4120 | real_timeout.OffsetWithMicroSeconds(single_thread_timeout_usec); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4121 | |
| 4122 | timeout_ptr = &real_timeout; |
| 4123 | } |
| 4124 | } |
| 4125 | else |
| 4126 | { |
| 4127 | if (log) |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4128 | log->PutCString ("Process::RunThreadPlan(): handled an extra running event."); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4129 | do_resume = true; |
| 4130 | } |
| 4131 | |
| 4132 | // Now wait for the process to stop again: |
| 4133 | stop_state = lldb::eStateInvalid; |
| 4134 | event_sp.reset(); |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4135 | |
| 4136 | if (log) |
| 4137 | { |
| 4138 | if (timeout_ptr) |
| 4139 | { |
| 4140 | StreamString s; |
| 4141 | s.Printf ("about to wait - timeout is:\n "); |
| 4142 | timeout_ptr->Dump (&s, 120); |
| 4143 | s.Printf ("\nNow is:\n "); |
| 4144 | TimeValue::Now().Dump (&s, 120); |
| 4145 | log->Printf ("Process::RunThreadPlan(): %s", s.GetData()); |
| 4146 | } |
| 4147 | else |
| 4148 | { |
| 4149 | log->Printf ("Process::RunThreadPlan(): about to wait forever."); |
| 4150 | } |
| 4151 | } |
| 4152 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4153 | got_event = listener.WaitForEvent (timeout_ptr, event_sp); |
| 4154 | |
| 4155 | if (got_event) |
| 4156 | { |
| 4157 | if (event_sp.get()) |
| 4158 | { |
| 4159 | bool keep_going = false; |
| 4160 | stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 4161 | if (log) |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4162 | log->Printf("Process::RunThreadPlan(): in while loop, got event: %s.", StateAsCString(stop_state)); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4163 | |
| 4164 | switch (stop_state) |
| 4165 | { |
| 4166 | case lldb::eStateStopped: |
Jim Ingham | 160f78c | 2011-05-17 01:10:11 +0000 | [diff] [blame] | 4167 | { |
Greg Clayton | 54e8ac5 | 2011-06-03 22:12:42 +0000 | [diff] [blame] | 4168 | // Yay, we're done. Now make sure that our thread plan actually completed. |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4169 | ThreadSP thread_sp = GetThreadList().FindThreadByIndexID (thread_idx_id); |
Greg Clayton | 54e8ac5 | 2011-06-03 22:12:42 +0000 | [diff] [blame] | 4170 | if (!thread_sp) |
Jim Ingham | 160f78c | 2011-05-17 01:10:11 +0000 | [diff] [blame] | 4171 | { |
Greg Clayton | 54e8ac5 | 2011-06-03 22:12:42 +0000 | [diff] [blame] | 4172 | // Ooh, our thread has vanished. Unlikely that this was successful execution... |
Jim Ingham | 160f78c | 2011-05-17 01:10:11 +0000 | [diff] [blame] | 4173 | if (log) |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4174 | log->Printf ("Process::RunThreadPlan(): execution completed but our thread (index-id=%u) has vanished.", thread_idx_id); |
Greg Clayton | 54e8ac5 | 2011-06-03 22:12:42 +0000 | [diff] [blame] | 4175 | return_value = eExecutionInterrupted; |
Jim Ingham | 160f78c | 2011-05-17 01:10:11 +0000 | [diff] [blame] | 4176 | } |
| 4177 | else |
| 4178 | { |
Greg Clayton | 54e8ac5 | 2011-06-03 22:12:42 +0000 | [diff] [blame] | 4179 | StopInfoSP stop_info_sp (thread_sp->GetStopInfo ()); |
| 4180 | StopReason stop_reason = eStopReasonInvalid; |
| 4181 | if (stop_info_sp) |
| 4182 | stop_reason = stop_info_sp->GetStopReason(); |
| 4183 | if (stop_reason == eStopReasonPlanComplete) |
| 4184 | { |
| 4185 | if (log) |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4186 | log->PutCString ("Process::RunThreadPlan(): execution completed successfully."); |
Greg Clayton | 54e8ac5 | 2011-06-03 22:12:42 +0000 | [diff] [blame] | 4187 | // Now mark this plan as private so it doesn't get reported as the stop reason |
| 4188 | // after this point. |
| 4189 | if (thread_plan_sp) |
| 4190 | thread_plan_sp->SetPrivate (orig_plan_private); |
| 4191 | return_value = eExecutionCompleted; |
| 4192 | } |
| 4193 | else |
| 4194 | { |
| 4195 | if (log) |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4196 | log->PutCString ("Process::RunThreadPlan(): thread plan didn't successfully complete."); |
Greg Clayton | 54e8ac5 | 2011-06-03 22:12:42 +0000 | [diff] [blame] | 4197 | |
| 4198 | return_value = eExecutionInterrupted; |
| 4199 | } |
Jim Ingham | 160f78c | 2011-05-17 01:10:11 +0000 | [diff] [blame] | 4200 | } |
Greg Clayton | 54e8ac5 | 2011-06-03 22:12:42 +0000 | [diff] [blame] | 4201 | } |
| 4202 | break; |
| 4203 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4204 | case lldb::eStateCrashed: |
| 4205 | if (log) |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4206 | log->PutCString ("Process::RunThreadPlan(): execution crashed."); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4207 | return_value = eExecutionInterrupted; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4208 | break; |
Greg Clayton | 54e8ac5 | 2011-06-03 22:12:42 +0000 | [diff] [blame] | 4209 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4210 | case lldb::eStateRunning: |
| 4211 | do_resume = false; |
| 4212 | keep_going = true; |
| 4213 | break; |
Greg Clayton | 54e8ac5 | 2011-06-03 22:12:42 +0000 | [diff] [blame] | 4214 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4215 | default: |
| 4216 | if (log) |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4217 | log->Printf("Process::RunThreadPlan(): execution stopped with unexpected state: %s.", StateAsCString(stop_state)); |
Jim Ingham | 160f78c | 2011-05-17 01:10:11 +0000 | [diff] [blame] | 4218 | |
| 4219 | errors.Printf ("Execution stopped with unexpected state."); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4220 | return_value = eExecutionInterrupted; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4221 | break; |
| 4222 | } |
| 4223 | if (keep_going) |
| 4224 | continue; |
| 4225 | else |
| 4226 | break; |
| 4227 | } |
| 4228 | else |
| 4229 | { |
| 4230 | if (log) |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4231 | log->PutCString ("Process::RunThreadPlan(): got_event was true, but the event pointer was null. How odd..."); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4232 | return_value = eExecutionInterrupted; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4233 | break; |
| 4234 | } |
| 4235 | } |
| 4236 | else |
| 4237 | { |
| 4238 | // If we didn't get an event that means we've timed out... |
| 4239 | // We will interrupt the process here. Depending on what we were asked to do we will |
| 4240 | // either exit, or try with all threads running for the same timeout. |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4241 | // Not really sure what to do if Halt fails here... |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4242 | |
Stephen Wilson | 78a4feb | 2011-01-12 04:20:03 +0000 | [diff] [blame] | 4243 | if (log) { |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4244 | if (try_all_threads) |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4245 | { |
| 4246 | if (first_timeout) |
| 4247 | log->Printf ("Process::RunThreadPlan(): Running function with timeout: %d timed out, " |
| 4248 | "trying with all threads enabled.", |
| 4249 | single_thread_timeout_usec); |
| 4250 | else |
| 4251 | log->Printf ("Process::RunThreadPlan(): Restarting function with all threads enabled " |
| 4252 | "and timeout: %d timed out.", |
| 4253 | single_thread_timeout_usec); |
| 4254 | } |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4255 | else |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4256 | log->Printf ("Process::RunThreadPlan(): Running function with timeout: %d timed out, " |
| 4257 | "halt and abandoning execution.", |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4258 | single_thread_timeout_usec); |
Stephen Wilson | 78a4feb | 2011-01-12 04:20:03 +0000 | [diff] [blame] | 4259 | } |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4260 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4261 | Error halt_error = Halt(); |
Jim Ingham | e22e88b | 2011-01-22 01:30:53 +0000 | [diff] [blame] | 4262 | if (halt_error.Success()) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4263 | { |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4264 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4265 | log->PutCString ("Process::RunThreadPlan(): Halt succeeded."); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4266 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4267 | // If halt succeeds, it always produces a stopped event. Wait for that: |
| 4268 | |
| 4269 | real_timeout = TimeValue::Now(); |
| 4270 | real_timeout.OffsetWithMicroSeconds(500000); |
| 4271 | |
| 4272 | got_event = listener.WaitForEvent(&real_timeout, event_sp); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4273 | |
| 4274 | if (got_event) |
| 4275 | { |
| 4276 | stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 4277 | if (log) |
| 4278 | { |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 4279 | log->Printf ("Process::RunThreadPlan(): Stopped with event: %s", StateAsCString(stop_state)); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4280 | if (stop_state == lldb::eStateStopped |
| 4281 | && Process::ProcessEventData::GetInterruptedFromEvent(event_sp.get())) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4282 | log->PutCString (" Event was the Halt interruption event."); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4283 | } |
| 4284 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4285 | if (stop_state == lldb::eStateStopped) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4286 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4287 | // Between the time we initiated the Halt and the time we delivered it, the process could have |
| 4288 | // already finished its job. Check that here: |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4289 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4290 | if (thread->IsThreadPlanDone (thread_plan_sp.get())) |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4291 | { |
| 4292 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4293 | log->PutCString ("Process::RunThreadPlan(): Even though we timed out, the call plan was done. " |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4294 | "Exiting wait loop."); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4295 | return_value = eExecutionCompleted; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4296 | break; |
| 4297 | } |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4298 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4299 | if (!try_all_threads) |
| 4300 | { |
| 4301 | if (log) |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4302 | log->PutCString ("Process::RunThreadPlan(): try_all_threads was false, we stopped so now we're quitting."); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4303 | return_value = eExecutionInterrupted; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4304 | break; |
| 4305 | } |
| 4306 | |
| 4307 | if (first_timeout) |
| 4308 | { |
| 4309 | // Set all the other threads to run, and return to the top of the loop, which will continue; |
| 4310 | first_timeout = false; |
| 4311 | thread_plan_sp->SetStopOthers (false); |
| 4312 | if (log) |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4313 | log->PutCString ("Process::RunThreadPlan(): about to resume."); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4314 | |
| 4315 | continue; |
| 4316 | } |
| 4317 | else |
| 4318 | { |
| 4319 | // Running all threads failed, so return Interrupted. |
| 4320 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4321 | log->PutCString("Process::RunThreadPlan(): running all threads timed out."); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4322 | return_value = eExecutionInterrupted; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4323 | break; |
| 4324 | } |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4325 | } |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4326 | } |
| 4327 | else |
| 4328 | { if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4329 | log->PutCString("Process::RunThreadPlan(): halt said it succeeded, but I got no event. " |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4330 | "I'm getting out of here passing Interrupted."); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4331 | return_value = eExecutionInterrupted; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4332 | break; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4333 | } |
| 4334 | } |
Jim Ingham | e22e88b | 2011-01-22 01:30:53 +0000 | [diff] [blame] | 4335 | else |
| 4336 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4337 | // This branch is to work around some problems with gdb-remote's Halt. It is a little racy, and can return |
| 4338 | // an error from halt, but if you wait a bit you'll get a stopped event anyway. |
Jim Ingham | e22e88b | 2011-01-22 01:30:53 +0000 | [diff] [blame] | 4339 | if (log) |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4340 | log->Printf ("Process::RunThreadPlan(): halt failed: error = \"%s\", I'm just going to wait a little longer and see if I get a stopped event.", |
| 4341 | halt_error.AsCString()); |
| 4342 | real_timeout = TimeValue::Now(); |
| 4343 | real_timeout.OffsetWithMicroSeconds(500000); |
| 4344 | timeout_ptr = &real_timeout; |
| 4345 | got_event = listener.WaitForEvent(&real_timeout, event_sp); |
| 4346 | if (!got_event || event_sp.get() == NULL) |
Jim Ingham | 1e7a9ee | 2011-01-23 21:14:08 +0000 | [diff] [blame] | 4347 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4348 | // This is not going anywhere, bag out. |
| 4349 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4350 | log->PutCString ("Process::RunThreadPlan(): halt failed: and waiting for the stopped event failed."); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4351 | return_value = eExecutionInterrupted; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4352 | break; |
Jim Ingham | 1e7a9ee | 2011-01-23 21:14:08 +0000 | [diff] [blame] | 4353 | } |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4354 | else |
| 4355 | { |
| 4356 | stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); |
| 4357 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4358 | log->PutCString ("Process::RunThreadPlan(): halt failed: but then I got a stopped event. Whatever..."); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4359 | if (stop_state == lldb::eStateStopped) |
| 4360 | { |
| 4361 | // Between the time we initiated the Halt and the time we delivered it, the process could have |
| 4362 | // already finished its job. Check that here: |
| 4363 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4364 | if (thread->IsThreadPlanDone (thread_plan_sp.get())) |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4365 | { |
| 4366 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4367 | log->PutCString ("Process::RunThreadPlan(): Even though we timed out, the call plan was done. " |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4368 | "Exiting wait loop."); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4369 | return_value = eExecutionCompleted; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4370 | break; |
| 4371 | } |
| 4372 | |
| 4373 | if (first_timeout) |
| 4374 | { |
| 4375 | // Set all the other threads to run, and return to the top of the loop, which will continue; |
| 4376 | first_timeout = false; |
| 4377 | thread_plan_sp->SetStopOthers (false); |
| 4378 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4379 | log->PutCString ("Process::RunThreadPlan(): About to resume."); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4380 | |
| 4381 | continue; |
| 4382 | } |
| 4383 | else |
| 4384 | { |
| 4385 | // Running all threads failed, so return Interrupted. |
| 4386 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4387 | log->PutCString ("Process::RunThreadPlan(): running all threads timed out."); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4388 | return_value = eExecutionInterrupted; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4389 | break; |
| 4390 | } |
| 4391 | } |
| 4392 | else |
| 4393 | { |
Sean Callanan | 39821ac | 2011-08-09 22:07:08 +0000 | [diff] [blame] | 4394 | if (log) |
| 4395 | log->Printf ("Process::RunThreadPlan(): halt failed, I waited and didn't get" |
| 4396 | " a stopped event, instead got %s.", StateAsCString(stop_state)); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4397 | return_value = eExecutionInterrupted; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4398 | break; |
| 4399 | } |
| 4400 | } |
Jim Ingham | e22e88b | 2011-01-22 01:30:53 +0000 | [diff] [blame] | 4401 | } |
| 4402 | |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4403 | } |
| 4404 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4405 | } // END WAIT LOOP |
| 4406 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4407 | // If we had to start up a temporary private state thread to run this thread plan, shut it down now. |
| 4408 | if (IS_VALID_LLDB_HOST_THREAD(backup_private_state_thread)) |
| 4409 | { |
| 4410 | StopPrivateStateThread(); |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4411 | Error error; |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4412 | m_private_state_thread = backup_private_state_thread; |
Jim Ingham | 076b304 | 2012-04-10 01:21:57 +0000 | [diff] [blame] | 4413 | if (stopper_base_plan_sp != NULL) |
| 4414 | { |
| 4415 | thread->DiscardThreadPlansUpToPlan(stopper_base_plan_sp); |
| 4416 | } |
| 4417 | m_public_state.SetValueNoLock(old_state); |
| 4418 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4419 | } |
| 4420 | |
| 4421 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4422 | // Now do some processing on the results of the run: |
| 4423 | if (return_value == eExecutionInterrupted) |
| 4424 | { |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4425 | if (log) |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4426 | { |
| 4427 | StreamString s; |
| 4428 | if (event_sp) |
| 4429 | event_sp->Dump (&s); |
| 4430 | else |
| 4431 | { |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4432 | log->PutCString ("Process::RunThreadPlan(): Stop event that interrupted us is NULL."); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4433 | } |
| 4434 | |
| 4435 | StreamString ts; |
| 4436 | |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4437 | const char *event_explanation = NULL; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4438 | |
| 4439 | do |
| 4440 | { |
| 4441 | const Process::ProcessEventData *event_data = Process::ProcessEventData::GetEventDataFromEvent (event_sp.get()); |
| 4442 | |
| 4443 | if (!event_data) |
| 4444 | { |
| 4445 | event_explanation = "<no event data>"; |
| 4446 | break; |
| 4447 | } |
| 4448 | |
| 4449 | Process *process = event_data->GetProcessSP().get(); |
| 4450 | |
| 4451 | if (!process) |
| 4452 | { |
| 4453 | event_explanation = "<no process>"; |
| 4454 | break; |
| 4455 | } |
| 4456 | |
| 4457 | ThreadList &thread_list = process->GetThreadList(); |
| 4458 | |
| 4459 | uint32_t num_threads = thread_list.GetSize(); |
| 4460 | uint32_t thread_index; |
| 4461 | |
| 4462 | ts.Printf("<%u threads> ", num_threads); |
| 4463 | |
| 4464 | for (thread_index = 0; |
| 4465 | thread_index < num_threads; |
| 4466 | ++thread_index) |
| 4467 | { |
| 4468 | Thread *thread = thread_list.GetThreadAtIndex(thread_index).get(); |
| 4469 | |
| 4470 | if (!thread) |
| 4471 | { |
| 4472 | ts.Printf("<?> "); |
| 4473 | continue; |
| 4474 | } |
| 4475 | |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4476 | ts.Printf("<0x%4.4llx ", thread->GetID()); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4477 | RegisterContext *register_context = thread->GetRegisterContext().get(); |
| 4478 | |
| 4479 | if (register_context) |
| 4480 | ts.Printf("[ip 0x%llx] ", register_context->GetPC()); |
| 4481 | else |
| 4482 | ts.Printf("[ip unknown] "); |
| 4483 | |
| 4484 | lldb::StopInfoSP stop_info_sp = thread->GetStopInfo(); |
| 4485 | if (stop_info_sp) |
| 4486 | { |
| 4487 | const char *stop_desc = stop_info_sp->GetDescription(); |
| 4488 | if (stop_desc) |
| 4489 | ts.PutCString (stop_desc); |
| 4490 | } |
| 4491 | ts.Printf(">"); |
| 4492 | } |
| 4493 | |
| 4494 | event_explanation = ts.GetData(); |
| 4495 | } while (0); |
| 4496 | |
| 4497 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4498 | { |
| 4499 | if (event_explanation) |
| 4500 | log->Printf("Process::RunThreadPlan(): execution interrupted: %s %s", s.GetData(), event_explanation); |
| 4501 | else |
| 4502 | log->Printf("Process::RunThreadPlan(): execution interrupted: %s", s.GetData()); |
| 4503 | } |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4504 | |
| 4505 | if (discard_on_error && thread_plan_sp) |
| 4506 | { |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4507 | if (log) |
| 4508 | log->Printf ("Process::RunThreadPlan: ExecutionInterrupted - discarding thread plans up to %p.", thread_plan_sp.get()); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4509 | thread->DiscardThreadPlansUpToPlan (thread_plan_sp); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4510 | thread_plan_sp->SetPrivate (orig_plan_private); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4511 | } |
Jim Ingham | e39f85c | 2012-04-13 23:09:49 +0000 | [diff] [blame] | 4512 | else |
| 4513 | { |
| 4514 | if (log) |
| 4515 | log->Printf ("Process::RunThreadPlan: ExecutionInterrupted - for plan: %p not discarding.", thread_plan_sp.get()); |
| 4516 | |
| 4517 | } |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4518 | } |
| 4519 | } |
| 4520 | else if (return_value == eExecutionSetupError) |
| 4521 | { |
| 4522 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4523 | log->PutCString("Process::RunThreadPlan(): execution set up error."); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4524 | |
| 4525 | if (discard_on_error && thread_plan_sp) |
| 4526 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4527 | thread->DiscardThreadPlansUpToPlan (thread_plan_sp); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4528 | thread_plan_sp->SetPrivate (orig_plan_private); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4529 | } |
| 4530 | } |
| 4531 | else |
| 4532 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4533 | if (thread->IsThreadPlanDone (thread_plan_sp.get())) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4534 | { |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 4535 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4536 | log->PutCString("Process::RunThreadPlan(): thread plan is done"); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4537 | return_value = eExecutionCompleted; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4538 | } |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4539 | else if (thread->WasThreadPlanDiscarded (thread_plan_sp.get())) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4540 | { |
Greg Clayton | 414f5d3 | 2011-01-25 02:58:48 +0000 | [diff] [blame] | 4541 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4542 | log->PutCString("Process::RunThreadPlan(): thread plan was discarded"); |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4543 | return_value = eExecutionDiscarded; |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4544 | } |
| 4545 | else |
| 4546 | { |
| 4547 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4548 | log->PutCString("Process::RunThreadPlan(): thread plan stopped in mid course"); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4549 | if (discard_on_error && thread_plan_sp) |
| 4550 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4551 | if (log) |
Jim Ingham | 20829ac | 2011-08-09 22:24:33 +0000 | [diff] [blame] | 4552 | log->PutCString("Process::RunThreadPlan(): discarding thread plan 'cause discard_on_error is set."); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4553 | thread->DiscardThreadPlansUpToPlan (thread_plan_sp); |
Jim Ingham | 4b53618 | 2011-08-09 02:12:22 +0000 | [diff] [blame] | 4554 | thread_plan_sp->SetPrivate (orig_plan_private); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4555 | } |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4556 | } |
| 4557 | } |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 4558 | |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4559 | // Thread we ran the function in may have gone away because we ran the target |
Jim Ingham | 6624384 | 2011-08-13 00:56:10 +0000 | [diff] [blame] | 4560 | // Check that it's still there, and if it is put it back in the context. Also restore the |
| 4561 | // frame in the context if it is still present. |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4562 | thread = GetThreadList().FindThreadByIndexID(thread_idx_id, true).get(); |
| 4563 | if (thread) |
Jim Ingham | 6624384 | 2011-08-13 00:56:10 +0000 | [diff] [blame] | 4564 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4565 | exe_ctx.SetFrameSP (thread->GetFrameWithStackID (ctx_frame_id)); |
Jim Ingham | 6624384 | 2011-08-13 00:56:10 +0000 | [diff] [blame] | 4566 | } |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4567 | |
| 4568 | // Also restore the current process'es selected frame & thread, since this function calling may |
| 4569 | // be done behind the user's back. |
| 4570 | |
| 4571 | if (selected_tid != LLDB_INVALID_THREAD_ID) |
| 4572 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4573 | if (GetThreadList().SetSelectedThreadByIndexID (selected_tid) && selected_stack_id.IsValid()) |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4574 | { |
| 4575 | // We were able to restore the selected thread, now restore the frame: |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4576 | StackFrameSP old_frame_sp = GetThreadList().GetSelectedThread()->GetFrameWithStackID(selected_stack_id); |
Jim Ingham | 6624384 | 2011-08-13 00:56:10 +0000 | [diff] [blame] | 4577 | if (old_frame_sp) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 4578 | GetThreadList().GetSelectedThread()->SetSelectedFrame(old_frame_sp.get()); |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4579 | } |
| 4580 | } |
| 4581 | |
| 4582 | return return_value; |
| 4583 | } |
| 4584 | |
| 4585 | const char * |
| 4586 | Process::ExecutionResultAsCString (ExecutionResults result) |
| 4587 | { |
| 4588 | const char *result_name; |
| 4589 | |
| 4590 | switch (result) |
| 4591 | { |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4592 | case eExecutionCompleted: |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4593 | result_name = "eExecutionCompleted"; |
| 4594 | break; |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4595 | case eExecutionDiscarded: |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4596 | result_name = "eExecutionDiscarded"; |
| 4597 | break; |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4598 | case eExecutionInterrupted: |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4599 | result_name = "eExecutionInterrupted"; |
| 4600 | break; |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4601 | case eExecutionSetupError: |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4602 | result_name = "eExecutionSetupError"; |
| 4603 | break; |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4604 | case eExecutionTimedOut: |
Jim Ingham | f48169b | 2010-11-30 02:22:11 +0000 | [diff] [blame] | 4605 | result_name = "eExecutionTimedOut"; |
| 4606 | break; |
| 4607 | } |
| 4608 | return result_name; |
| 4609 | } |
| 4610 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 4611 | void |
| 4612 | Process::GetStatus (Stream &strm) |
| 4613 | { |
| 4614 | const StateType state = GetState(); |
Greg Clayton | 2637f82 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 4615 | if (StateIsStoppedState(state, false)) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 4616 | { |
| 4617 | if (state == eStateExited) |
| 4618 | { |
| 4619 | int exit_status = GetExitStatus(); |
| 4620 | const char *exit_description = GetExitDescription(); |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4621 | strm.Printf ("Process %llu exited with status = %i (0x%8.8x) %s\n", |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 4622 | GetID(), |
| 4623 | exit_status, |
| 4624 | exit_status, |
| 4625 | exit_description ? exit_description : ""); |
| 4626 | } |
| 4627 | else |
| 4628 | { |
| 4629 | if (state == eStateConnected) |
| 4630 | strm.Printf ("Connected to remote target.\n"); |
| 4631 | else |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4632 | strm.Printf ("Process %llu %s\n", GetID(), StateAsCString (state)); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 4633 | } |
| 4634 | } |
| 4635 | else |
| 4636 | { |
Greg Clayton | 81c22f6 | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 4637 | strm.Printf ("Process %llu is running.\n", GetID()); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 4638 | } |
| 4639 | } |
| 4640 | |
| 4641 | size_t |
| 4642 | Process::GetThreadStatus (Stream &strm, |
| 4643 | bool only_threads_with_stop_reason, |
| 4644 | uint32_t start_frame, |
| 4645 | uint32_t num_frames, |
| 4646 | uint32_t num_frames_with_source) |
| 4647 | { |
| 4648 | size_t num_thread_infos_dumped = 0; |
| 4649 | |
| 4650 | const size_t num_threads = GetThreadList().GetSize(); |
| 4651 | for (uint32_t i = 0; i < num_threads; i++) |
| 4652 | { |
| 4653 | Thread *thread = GetThreadList().GetThreadAtIndex(i).get(); |
| 4654 | if (thread) |
| 4655 | { |
| 4656 | if (only_threads_with_stop_reason) |
| 4657 | { |
| 4658 | if (thread->GetStopInfo().get() == NULL) |
| 4659 | continue; |
| 4660 | } |
| 4661 | thread->GetStatus (strm, |
| 4662 | start_frame, |
| 4663 | num_frames, |
| 4664 | num_frames_with_source); |
| 4665 | ++num_thread_infos_dumped; |
| 4666 | } |
| 4667 | } |
| 4668 | return num_thread_infos_dumped; |
| 4669 | } |
| 4670 | |
Greg Clayton | a9f40ad | 2012-02-22 04:37:26 +0000 | [diff] [blame] | 4671 | void |
| 4672 | Process::AddInvalidMemoryRegion (const LoadRange ®ion) |
| 4673 | { |
| 4674 | m_memory_cache.AddInvalidRange(region.GetRangeBase(), region.GetByteSize()); |
| 4675 | } |
| 4676 | |
| 4677 | bool |
| 4678 | Process::RemoveInvalidMemoryRange (const LoadRange ®ion) |
| 4679 | { |
| 4680 | return m_memory_cache.RemoveInvalidRange(region.GetRangeBase(), region.GetByteSize()); |
| 4681 | } |
| 4682 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 4683 | void |
| 4684 | Process::AddPreResumeAction (PreResumeActionCallback callback, void *baton) |
| 4685 | { |
| 4686 | m_pre_resume_actions.push_back(PreResumeCallbackAndBaton (callback, baton)); |
| 4687 | } |
| 4688 | |
| 4689 | bool |
| 4690 | Process::RunPreResumeActions () |
| 4691 | { |
| 4692 | bool result = true; |
| 4693 | while (!m_pre_resume_actions.empty()) |
| 4694 | { |
| 4695 | struct PreResumeCallbackAndBaton action = m_pre_resume_actions.back(); |
| 4696 | m_pre_resume_actions.pop_back(); |
| 4697 | bool this_result = action.callback (action.baton); |
| 4698 | if (result == true) result = this_result; |
| 4699 | } |
| 4700 | return result; |
| 4701 | } |
| 4702 | |
| 4703 | void |
| 4704 | Process::ClearPreResumeActions () |
| 4705 | { |
| 4706 | m_pre_resume_actions.clear(); |
| 4707 | } |
Greg Clayton | a9f40ad | 2012-02-22 04:37:26 +0000 | [diff] [blame] | 4708 | |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4709 | //-------------------------------------------------------------- |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 4710 | // class Process::SettingsController |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4711 | //-------------------------------------------------------------- |
| 4712 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 4713 | Process::SettingsController::SettingsController () : |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 4714 | UserSettingsController ("process", Target::GetSettingsController()) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4715 | { |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4716 | } |
| 4717 | |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 4718 | Process::SettingsController::~SettingsController () |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4719 | { |
| 4720 | } |
| 4721 | |
| 4722 | lldb::InstanceSettingsSP |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 4723 | Process::SettingsController::CreateInstanceSettings (const char *instance_name) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4724 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 4725 | lldb::InstanceSettingsSP new_settings_sp (new ProcessInstanceSettings (GetSettingsController(), |
| 4726 | false, |
| 4727 | instance_name)); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4728 | return new_settings_sp; |
| 4729 | } |
| 4730 | |
| 4731 | //-------------------------------------------------------------- |
| 4732 | // class ProcessInstanceSettings |
| 4733 | //-------------------------------------------------------------- |
| 4734 | |
Greg Clayton | 85851dd | 2010-12-04 00:10:17 +0000 | [diff] [blame] | 4735 | ProcessInstanceSettings::ProcessInstanceSettings |
| 4736 | ( |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 4737 | const UserSettingsControllerSP &owner_sp, |
Greg Clayton | 85851dd | 2010-12-04 00:10:17 +0000 | [diff] [blame] | 4738 | bool live_instance, |
| 4739 | const char *name |
| 4740 | ) : |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 4741 | InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4742 | { |
Caroline Tice | f20e823 | 2010-09-09 18:26:37 +0000 | [diff] [blame] | 4743 | // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called |
| 4744 | // until the vtables for ProcessInstanceSettings are properly set up, i.e. AFTER all the initializers. |
| 4745 | // For this reason it has to be called here, rather than in the initializer or in the parent constructor. |
Caroline Tice | 9e41c15 | 2010-09-16 19:05:55 +0000 | [diff] [blame] | 4746 | // This is true for CreateInstanceName() too. |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 4747 | |
Caroline Tice | 9e41c15 | 2010-09-16 19:05:55 +0000 | [diff] [blame] | 4748 | if (GetInstanceName () == InstanceSettings::InvalidName()) |
| 4749 | { |
| 4750 | ChangeInstanceName (std::string (CreateInstanceName().AsCString())); |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 4751 | owner_sp->RegisterInstanceSettings (this); |
Caroline Tice | 9e41c15 | 2010-09-16 19:05:55 +0000 | [diff] [blame] | 4752 | } |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 4753 | |
Caroline Tice | f20e823 | 2010-09-09 18:26:37 +0000 | [diff] [blame] | 4754 | if (live_instance) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4755 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 4756 | const lldb::InstanceSettingsSP &pending_settings = owner_sp->FindPendingSettings (m_instance_name); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4757 | CopyInstanceSettings (pending_settings,false); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4758 | } |
| 4759 | } |
| 4760 | |
| 4761 | ProcessInstanceSettings::ProcessInstanceSettings (const ProcessInstanceSettings &rhs) : |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 4762 | InstanceSettings (Process::GetSettingsController(), CreateInstanceName().AsCString()) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4763 | { |
| 4764 | if (m_instance_name != InstanceSettings::GetDefaultName()) |
| 4765 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 4766 | UserSettingsControllerSP owner_sp (m_owner_wp.lock()); |
| 4767 | if (owner_sp) |
| 4768 | { |
| 4769 | CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false); |
| 4770 | owner_sp->RemovePendingSettings (m_instance_name); |
| 4771 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4772 | } |
| 4773 | } |
| 4774 | |
| 4775 | ProcessInstanceSettings::~ProcessInstanceSettings () |
| 4776 | { |
| 4777 | } |
| 4778 | |
| 4779 | ProcessInstanceSettings& |
| 4780 | ProcessInstanceSettings::operator= (const ProcessInstanceSettings &rhs) |
| 4781 | { |
| 4782 | if (this != &rhs) |
| 4783 | { |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4784 | } |
| 4785 | |
| 4786 | return *this; |
| 4787 | } |
| 4788 | |
| 4789 | |
| 4790 | void |
| 4791 | ProcessInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name, |
| 4792 | const char *index_value, |
| 4793 | const char *value, |
| 4794 | const ConstString &instance_name, |
| 4795 | const SettingEntry &entry, |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 4796 | VarSetOperationType op, |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4797 | Error &err, |
| 4798 | bool pending) |
| 4799 | { |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4800 | } |
| 4801 | |
| 4802 | void |
| 4803 | ProcessInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, |
| 4804 | bool pending) |
| 4805 | { |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 4806 | // if (new_settings.get() == NULL) |
| 4807 | // return; |
| 4808 | // |
| 4809 | // ProcessInstanceSettings *new_process_settings = (ProcessInstanceSettings *) new_settings.get(); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4810 | } |
| 4811 | |
Caroline Tice | 12cecd7 | 2010-09-20 21:37:42 +0000 | [diff] [blame] | 4812 | bool |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4813 | ProcessInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, |
| 4814 | const ConstString &var_name, |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 4815 | StringList &value, |
Caroline Tice | 12cecd7 | 2010-09-20 21:37:42 +0000 | [diff] [blame] | 4816 | Error *err) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4817 | { |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 4818 | if (err) |
| 4819 | err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); |
| 4820 | return false; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4821 | } |
| 4822 | |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4823 | const ConstString |
| 4824 | ProcessInstanceSettings::CreateInstanceName () |
| 4825 | { |
| 4826 | static int instance_count = 1; |
| 4827 | StreamString sstr; |
| 4828 | |
| 4829 | sstr.Printf ("process_%d", instance_count); |
| 4830 | ++instance_count; |
| 4831 | |
| 4832 | const ConstString ret_val (sstr.GetData()); |
| 4833 | return ret_val; |
| 4834 | } |
| 4835 | |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4836 | //-------------------------------------------------- |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 4837 | // SettingsController Variable Tables |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4838 | //-------------------------------------------------- |
| 4839 | |
| 4840 | SettingEntry |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 4841 | Process::SettingsController::global_settings_table[] = |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4842 | { |
| 4843 | //{ "var-name", var-type , "default", enum-table, init'd, hidden, "help-text"}, |
| 4844 | { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL } |
| 4845 | }; |
| 4846 | |
| 4847 | |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4848 | SettingEntry |
Greg Clayton | 1b65488 | 2010-09-19 02:33:57 +0000 | [diff] [blame] | 4849 | Process::SettingsController::instance_settings_table[] = |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4850 | { |
Greg Clayton | 85851dd | 2010-12-04 00:10:17 +0000 | [diff] [blame] | 4851 | //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"}, |
Greg Clayton | 85851dd | 2010-12-04 00:10:17 +0000 | [diff] [blame] | 4852 | { NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 4853 | }; |
| 4854 | |
| 4855 | |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 4856 | |
Greg Clayton | 1d88596 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 4857 | |