Process.h revision d168690e51f9020b926d3d0d57dc9a2cfb2095a8
1c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)//===-- Process.h -----------------------------------------------*- C++ -*-===// 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The LLVM Compiler Infrastructure 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// 5c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// This file is distributed under the University of Illinois Open Source 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// License. See LICENSE.TXT for details. 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//===----------------------------------------------------------------------===// 9c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef liblldb_Process_h_ 115e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#define liblldb_Process_h_ 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// C Includes 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// C++ Includes 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <list> 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Other libraries and framework includes 18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Project includes 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/lldb-private.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/Interpreter/Args.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/Interpreter/Options.h" 22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "lldb/Core/Broadcaster.h" 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/Core/Error.h" 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/Core/Event.h" 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/Core/StringList.h" 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/Core/ThreadSafeValue.h" 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/Core/PluginInterface.h" 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/Core/UserSettingsController.h" 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/Breakpoint/BreakpointSiteList.h" 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/Expression/ClangPersistentVariables.h" 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/Expression/IRDynamicChecks.h" 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/Target/ExecutionContextScope.h" 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "lldb/Target/ThreadList.h" 34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "lldb/Target/UnixSignals.h" 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace lldb_private { 37c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef enum ProcessPlugins 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles){ 41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) eMacosx, 42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) eRemoteDebugger 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} ProcessPlugins; 44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class ProcessInstanceSettings : public InstanceSettings 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles){ 48a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)public: 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ProcessInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL); 51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ProcessInstanceSettings (const ProcessInstanceSettings &rhs); 537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ~ProcessInstanceSettings (); 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 57c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ProcessInstanceSettings& 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) operator= (const ProcessInstanceSettings &rhs); 59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void 62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) UpdateInstanceSettingsVariable (const ConstString &var_name, 63a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const char *index_value, 64a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const char *value, 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const ConstString &instance_name, 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const SettingEntry &entry, 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) lldb::VarSetOperationType op, 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Error &err, 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool pending); 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetInstanceSettingsValue (const SettingEntry &entry, 73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const ConstString &var_name, 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StringList &value, 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Error *err); 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const Args & 79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GetRunArguments () const 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 81f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return m_run_args; 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 83c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetRunArguments (const Args &args) 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) m_run_args = args; 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 90f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) size_t 91558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch GetEnvironmentAsArgs (Args &env) const 92558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch { 93558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch dictionary::const_iterator pos, end = m_env_vars.end(); 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (pos = m_env_vars.begin(); pos != end; ++pos) 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string env_var_equal_value (pos->first); 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) env_var_equal_value.append(1, '='); 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) env_var_equal_value.append (pos->second); 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) env.AppendArgument (env_var_equal_value.c_str()); 100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return env.GetArgumentCount(); 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const char * 105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GetStandardInputPath () const 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (m_input_path.empty()) 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return NULL; 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return m_input_path.c_str(); 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetStandardInputPath (const char *path) 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (path && path[0]) 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) m_input_path.assign (path); 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Make sure we deallocate memory in string... 120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string tmp; 121c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) tmp.swap (m_input_path); 122c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 123558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch } 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const char * 126558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch GetStandardOutputPath () const 127558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch { 128558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch if (m_output_path.empty()) 129558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch return NULL; 130558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch return m_output_path.c_str(); 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void 134 SetStandardOutputPath (const char *path) 135 { 136 if (path && path[0]) 137 m_output_path.assign (path); 138 else 139 { 140 // Make sure we deallocate memory in string... 141 std::string tmp; 142 tmp.swap (m_output_path); 143 } 144 } 145 146 const char * 147 GetStandardErrorPath () const 148 { 149 if (m_error_path.empty()) 150 return NULL; 151 return m_error_path.c_str(); 152 } 153 154 void 155 SetStandardErrorPath (const char *path) 156 { 157 if (path && path[0]) 158 m_error_path.assign (path); 159 else 160 { 161 // Make sure we deallocate memory in string... 162 std::string tmp; 163 tmp.swap (m_error_path); 164 } 165 } 166 167 bool 168 GetDisableASLR () const 169 { 170 return m_disable_aslr; 171 } 172 173 void 174 SetDisableASLR (bool b) 175 { 176 m_disable_aslr = b; 177 } 178 179protected: 180 181 void 182 CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, 183 bool pending); 184 185 const ConstString 186 CreateInstanceName (); 187 188 static const ConstString & 189 RunArgsVarName (); 190 191 static const ConstString & 192 EnvVarsVarName (); 193 194 static const ConstString & 195 InputPathVarName (); 196 197 static const ConstString & 198 OutputPathVarName (); 199 200 static const ConstString & 201 ErrorPathVarName (); 202 203 static const ConstString & 204 PluginVarName (); 205 206 static const ConstString & 207 DisableASLRVarName(); 208 209 210private: 211 212 typedef std::map<std::string, std::string> dictionary; 213 Args m_run_args; 214 dictionary m_env_vars; 215 std::string m_input_path; 216 std::string m_output_path; 217 std::string m_error_path; 218 ProcessPlugins m_plugin; 219 bool m_disable_aslr; 220}; 221 222 223//---------------------------------------------------------------------- 224/// @class Process Process.h "lldb/Target/Process.h" 225/// @brief A plug-in interface definition class for debugging a process. 226//---------------------------------------------------------------------- 227class Process : 228 public UserID, 229 public Broadcaster, 230 public ExecutionContextScope, 231 public PluginInterface, 232 public ProcessInstanceSettings 233{ 234friend class ThreadList; 235friend class ClangFunction; // For WaitForStateChangeEventsPrivate 236 237public: 238 239 //------------------------------------------------------------------ 240 /// Broadcaster event bits definitions. 241 //------------------------------------------------------------------ 242 enum 243 { 244 eBroadcastBitStateChanged = (1 << 0), 245 eBroadcastBitInterrupt = (1 << 1), 246 eBroadcastBitSTDOUT = (1 << 2), 247 eBroadcastBitSTDERR = (1 << 3) 248 }; 249 250 enum 251 { 252 eBroadcastInternalStateControlStop = (1<<0), 253 eBroadcastInternalStateControlPause = (1<<1), 254 eBroadcastInternalStateControlResume = (1<<2) 255 }; 256 257 //------------------------------------------------------------------ 258 /// A notification structure that can be used by clients to listen 259 /// for changes in a process's lifetime. 260 /// 261 /// @see RegisterNotificationCallbacks (const Notifications&) 262 /// @see UnregisterNotificationCallbacks (const Notifications&) 263 //------------------------------------------------------------------ 264#ifndef SWIG 265 typedef struct 266 { 267 void *baton; 268 void (*initialize)(void *baton, Process *process); 269 void (*process_state_changed) (void *baton, Process *process, lldb::StateType state); 270 } Notifications; 271 272 class ProcessEventData : 273 public EventData 274 { 275 public: 276 ProcessEventData (); 277 ProcessEventData (const lldb::ProcessSP &process, lldb::StateType state); 278 279 virtual ~ProcessEventData(); 280 281 static const ConstString & 282 GetFlavorString (); 283 284 virtual const ConstString & 285 GetFlavor () const; 286 287 const lldb::ProcessSP & 288 GetProcessSP() const; 289 290 lldb::StateType 291 GetState() const; 292 293 bool 294 GetRestarted () const; 295 296 virtual void 297 Dump (Stream *s) const; 298 299 virtual void 300 DoOnRemoval (Event *event_ptr); 301 302 static const Process::ProcessEventData * 303 GetEventDataFromEvent (const Event *event_ptr); 304 305 static lldb::ProcessSP 306 GetProcessFromEvent (const Event *event_ptr); 307 308 static lldb::StateType 309 GetStateFromEvent (const Event *event_ptr); 310 311 static bool 312 GetRestartedFromEvent (const Event *event_ptr); 313 314 static void 315 SetRestartedInEvent (Event *event_ptr, bool new_value); 316 317 static bool 318 SetUpdateStateOnRemoval (Event *event_ptr); 319 320 private: 321 322 void 323 SetUpdateStateOnRemoval(); 324 325 void 326 SetRestarted (bool new_value); 327 328 lldb::ProcessSP m_process_sp; 329 lldb::StateType m_state; 330 bool m_restarted; // For "eStateStopped" events, this is true if the target was automatically restarted. 331 bool m_update_state; 332 DISALLOW_COPY_AND_ASSIGN (ProcessEventData); 333 334 }; 335 336 class SettingsController : public UserSettingsController 337 { 338 public: 339 340 SettingsController (); 341 342 virtual 343 ~SettingsController (); 344 345 static SettingEntry global_settings_table[]; 346 static SettingEntry instance_settings_table[]; 347 348 protected: 349 350 lldb::InstanceSettingsSP 351 CreateInstanceSettings (const char *instance_name); 352 353 static lldb::OptionEnumValueElement g_plugins[]; 354 355 private: 356 357 // Class-wide settings. 358 359 DISALLOW_COPY_AND_ASSIGN (SettingsController); 360 }; 361 362#endif 363 364 static lldb::UserSettingsControllerSP 365 GetSettingsController (bool finish = false); 366 367 void 368 UpdateInstanceName (); 369 370 //------------------------------------------------------------------ 371 /// Construct with a shared pointer to a target, and the Process listener. 372 //------------------------------------------------------------------ 373 Process(Target &target, Listener &listener); 374 375 //------------------------------------------------------------------ 376 /// Destructor. 377 /// 378 /// The destructor is virtual since this class is designed to be 379 /// inherited from by the plug-in instance. 380 //------------------------------------------------------------------ 381 virtual 382 ~Process(); 383 384 //------------------------------------------------------------------ 385 /// Find a Process plug-in that can debug \a module using the 386 /// currently selected architecture. 387 /// 388 /// Scans all loaded plug-in interfaces that implement versions of 389 /// the Process plug-in interface and returns the first instance 390 /// that can debug the file. 391 /// 392 /// @param[in] module_sp 393 /// The module shared pointer that this process will debug. 394 /// 395 /// @param[in] plugin_name 396 /// If NULL, select the best plug-in for the binary. If non-NULL 397 /// then look for a plugin whose PluginInfo's name matches 398 /// this string. 399 /// 400 /// @see Process::CanDebug () 401 //------------------------------------------------------------------ 402 static Process* 403 FindPlugin (Target &target, const char *plugin_name, Listener &listener); 404 405 406 407 //------------------------------------------------------------------ 408 /// Static function that can be used with the \b host function 409 /// Host::StartMonitoringChildProcess (). 410 /// 411 /// This function can be used by lldb_private::Process subclasses 412 /// when they want to watch for a local process and have its exit 413 /// status automatically set when the host child process exits. 414 /// Subclasses should call Host::StartMonitoringChildProcess () 415 /// with: 416 /// callback = Process::SetHostProcessExitStatus 417 /// callback_baton = NULL 418 /// pid = Process::GetID() 419 /// monitor_signals = false 420 //------------------------------------------------------------------ 421 static bool 422 SetProcessExitStatus (void *callback_baton, // The callback baton which should be set to NULL 423 lldb::pid_t pid, // The process ID we want to monitor 424 int signo, // Zero for no signal 425 int status); // Exit value of process if signal is zero 426 427 //------------------------------------------------------------------ 428 /// Check if a plug-in instance can debug the file in \a module. 429 /// 430 /// Each plug-in is given a chance to say whether it can debug 431 /// the file in \a module. If the Process plug-in instance can 432 /// debug a file on the current system, it should return \b true. 433 /// 434 /// @return 435 /// Returns \b true if this Process plug-in instance can 436 /// debug the executable, \b false otherwise. 437 //------------------------------------------------------------------ 438 virtual bool 439 CanDebug (Target &target) = 0; 440 441 442 //------------------------------------------------------------------ 443 /// This object is about to be destroyed, do any necessary cleanup. 444 /// 445 /// Subclasses that override this method should always call this 446 /// superclass method. 447 //------------------------------------------------------------------ 448 virtual void 449 Finalize(); 450 451 //------------------------------------------------------------------ 452 /// Launch a new process. 453 /// 454 /// Launch a new process by spawning a new process using the 455 /// target object's executable module's file as the file to launch. 456 /// Arguments are given in \a argv, and the environment variables 457 /// are in \a envp. Standard input and output files can be 458 /// optionally re-directed to \a stdin_path, \a stdout_path, and 459 /// \a stderr_path. 460 /// 461 /// This function is not meant to be overridden by Process 462 /// subclasses. It will first call Process::WillLaunch (Module *) 463 /// and if that returns \b true, Process::DoLaunch (Module*, 464 /// char const *[],char const *[],const char *,const char *, 465 /// const char *) will be called to actually do the launching. If 466 /// DoLaunch returns \b true, then Process::DidLaunch() will be 467 /// called. 468 /// 469 /// @param[in] argv 470 /// The argument array. 471 /// 472 /// @param[in] envp 473 /// The environment array. 474 /// 475 /// @param[in] launch_flags 476 /// Flags to modify the launch (@see lldb::LaunchFlags) 477 /// 478 /// @param[in] stdin_path 479 /// The path to use when re-directing the STDIN of the new 480 /// process. If all stdXX_path arguments are NULL, a pseudo 481 /// terminal will be used. 482 /// 483 /// @param[in] stdout_path 484 /// The path to use when re-directing the STDOUT of the new 485 /// process. If all stdXX_path arguments are NULL, a pseudo 486 /// terminal will be used. 487 /// 488 /// @param[in] stderr_path 489 /// The path to use when re-directing the STDERR of the new 490 /// process. If all stdXX_path arguments are NULL, a pseudo 491 /// terminal will be used. 492 /// 493 /// @return 494 /// An error object. Call GetID() to get the process ID if 495 /// the error object is success. 496 //------------------------------------------------------------------ 497 virtual Error 498 Launch (char const *argv[], 499 char const *envp[], 500 uint32_t launch_flags, 501 const char *stdin_path, 502 const char *stdout_path, 503 const char *stderr_path); 504 505 //------------------------------------------------------------------ 506 /// Attach to an existing process using a process ID. 507 /// 508 /// This function is not meant to be overridden by Process 509 /// subclasses. It will first call Process::WillAttach (lldb::pid_t) 510 /// and if that returns \b true, Process::DoAttach (lldb::pid_t) will 511 /// be called to actually do the attach. If DoAttach returns \b 512 /// true, then Process::DidAttach() will be called. 513 /// 514 /// @param[in] pid 515 /// The process ID that we should attempt to attach to. 516 /// 517 /// @return 518 /// Returns \a pid if attaching was successful, or 519 /// LLDB_INVALID_PROCESS_ID if attaching fails. 520 //------------------------------------------------------------------ 521 virtual Error 522 Attach (lldb::pid_t pid); 523 524 //------------------------------------------------------------------ 525 /// Attach to an existing process by process name. 526 /// 527 /// This function is not meant to be overridden by Process 528 /// subclasses. It will first call 529 /// Process::WillAttach (const char *) and if that returns \b 530 /// true, Process::DoAttach (const char *) will be called to 531 /// actually do the attach. If DoAttach returns \b true, then 532 /// Process::DidAttach() will be called. 533 /// 534 /// @param[in] process_name 535 /// A process name to match against the current process list. 536 /// 537 /// @return 538 /// Returns \a pid if attaching was successful, or 539 /// LLDB_INVALID_PROCESS_ID if attaching fails. 540 //------------------------------------------------------------------ 541 virtual Error 542 Attach (const char *process_name, bool wait_for_launch); 543 544 //------------------------------------------------------------------ 545 /// List the processes matching the given partial name. 546 /// 547 /// FIXME: Is it too heavyweight to create an entire process object to do this? 548 /// The problem is for remote processes we're going to have to set up the same transport 549 /// to get this data as to actually attach. So we need to factor out transport 550 /// and process before we can do this separately from the process. 551 /// 552 /// @param[in] name 553 /// A partial name to match against the current process list. 554 /// 555 /// @param[out] matches 556 /// The list of process names matching \a name. 557 /// 558 /// @param[in] pids 559 /// A vector filled with the pids that correspond to the names in \a matches. 560 /// 561 /// @return 562 /// Returns the number of matching processes. 563 //------------------------------------------------------------------ 564 565 virtual uint32_t 566 ListProcessesMatchingName (const char *name, StringList &matches, std::vector<lldb::pid_t> &pids); 567 568 //------------------------------------------------------------------ 569 /// Find the architecture of a process by pid. 570 /// 571 /// FIXME: See comment for ListProcessesMatchingName. 572 /// 573 /// @param[in] pid 574 /// A pid to inspect. 575 /// 576 /// @return 577 /// Returns the architecture of the process or an invalid architecture if the process can't be found. 578 //------------------------------------------------------------------ 579 virtual ArchSpec 580 GetArchSpecForExistingProcess (lldb::pid_t pid); 581 582 //------------------------------------------------------------------ 583 /// Find the architecture of a process by name. 584 /// 585 /// FIXME: See comment for ListProcessesMatchingName. 586 /// 587 /// @param[in] process_name 588 /// The process name to inspect. 589 /// 590 /// @return 591 /// Returns the architecture of the process or an invalid architecture if the process can't be found. 592 //------------------------------------------------------------------ 593 virtual ArchSpec 594 GetArchSpecForExistingProcess (const char *process_name); 595 596 uint32_t 597 GetAddressByteSize(); 598 599 //------------------------------------------------------------------ 600 /// Get the image information address for the current process. 601 /// 602 /// Some runtimes have system functions that can help dynamic 603 /// loaders locate the dynamic loader information needed to observe 604 /// shared libraries being loaded or unloaded. This function is 605 /// in the Process interface (as opposed to the DynamicLoader 606 /// interface) to ensure that remote debugging can take advantage of 607 /// this functionality. 608 /// 609 /// @return 610 /// The address of the dynamic loader information, or 611 /// LLDB_INVALID_ADDRESS if this is not supported by this 612 /// interface. 613 //------------------------------------------------------------------ 614 virtual lldb::addr_t 615 GetImageInfoAddress (); 616 617 //------------------------------------------------------------------ 618 /// Register for process and thread notifications. 619 /// 620 /// Clients can register nofication callbacks by filling out a 621 /// Process::Notifications structure and calling this function. 622 /// 623 /// @param[in] callbacks 624 /// A structure that contains the notification baton and 625 /// callback functions. 626 /// 627 /// @see Process::Notifications 628 //------------------------------------------------------------------ 629#ifndef SWIG 630 void 631 RegisterNotificationCallbacks (const Process::Notifications& callbacks); 632#endif 633 //------------------------------------------------------------------ 634 /// Unregister for process and thread notifications. 635 /// 636 /// Clients can unregister nofication callbacks by passing a copy of 637 /// the original baton and callbacks in \a callbacks. 638 /// 639 /// @param[in] callbacks 640 /// A structure that contains the notification baton and 641 /// callback functions. 642 /// 643 /// @return 644 /// Returns \b true if the notification callbacks were 645 /// successfully removed from the process, \b false otherwise. 646 /// 647 /// @see Process::Notifications 648 //------------------------------------------------------------------ 649#ifndef SWIG 650 bool 651 UnregisterNotificationCallbacks (const Process::Notifications& callbacks); 652#endif 653 //================================================================== 654 // Built in Process Control functions 655 //================================================================== 656 //------------------------------------------------------------------ 657 /// Resumes all of a process's threads as configured using the 658 /// Thread run control functions. 659 /// 660 /// Threads for a process should be updated with one of the run 661 /// control actions (resume, step, or suspend) that they should take 662 /// when the process is resumed. If no run control action is given 663 /// to a thread it will be resumed by default. 664 /// 665 /// This function is not meant to be overridden by Process 666 /// subclasses. This function will take care of disabling any 667 /// breakpoints that threads may be stopped at, single stepping, and 668 /// re-enabling breakpoints, and enabling the basic flow control 669 /// that the plug-in instances need not worry about. 670 /// 671 /// @return 672 /// Returns an error object. 673 /// 674 /// @see Thread:Resume() 675 /// @see Thread:Step() 676 /// @see Thread:Suspend() 677 //------------------------------------------------------------------ 678 virtual Error 679 Resume (); 680 681 //------------------------------------------------------------------ 682 /// Halts a running process. 683 /// 684 /// This function is not meant to be overridden by Process 685 /// subclasses. 686 /// 687 /// @return 688 /// Returns an error object. 689 //------------------------------------------------------------------ 690 virtual Error 691 Halt (); 692 693 //------------------------------------------------------------------ 694 /// Detaches from a running or stopped process. 695 /// 696 /// This function is not meant to be overridden by Process 697 /// subclasses. 698 /// 699 /// @return 700 /// Returns an error object. 701 //------------------------------------------------------------------ 702 virtual Error 703 Detach (); 704 705 //------------------------------------------------------------------ 706 /// Kills the process and shuts down all threads that were spawned 707 /// to track and monitor the process. 708 /// 709 /// This function is not meant to be overridden by Process 710 /// subclasses. 711 /// 712 /// @return 713 /// Returns an error object. 714 //------------------------------------------------------------------ 715 virtual Error 716 Destroy(); 717 718 //------------------------------------------------------------------ 719 /// Sends a process a UNIX signal \a signal. 720 /// 721 /// This function is not meant to be overridden by Process 722 /// subclasses. 723 /// 724 /// @return 725 /// Returns an error object. 726 //------------------------------------------------------------------ 727 virtual Error 728 Signal (int signal); 729 730 virtual UnixSignals & 731 GetUnixSignals (); 732 733 734 //================================================================== 735 // Plug-in Process Control Overrides 736 //================================================================== 737 738 //------------------------------------------------------------------ 739 /// Called before attaching to a process. 740 /// 741 /// Allow Process plug-ins to execute some code before attaching a 742 /// process. 743 /// 744 /// @return 745 /// Returns an error object. 746 //------------------------------------------------------------------ 747 virtual Error 748 WillAttachToProcessWithID (lldb::pid_t pid) 749 { 750 return Error(); 751 } 752 753 //------------------------------------------------------------------ 754 /// Called before attaching to a process. 755 /// 756 /// Allow Process plug-ins to execute some code before attaching a 757 /// process. 758 /// 759 /// @return 760 /// Returns an error object. 761 //------------------------------------------------------------------ 762 virtual Error 763 WillAttachToProcessWithName (const char *process_name, bool wait_for_launch) 764 { 765 return Error(); 766 } 767 768 //------------------------------------------------------------------ 769 /// Attach to an existing process using a process ID. 770 /// 771 /// @param[in] pid 772 /// The process ID that we should attempt to attach to. 773 /// 774 /// @return 775 /// Returns \a pid if attaching was successful, or 776 /// LLDB_INVALID_PROCESS_ID if attaching fails. 777 //------------------------------------------------------------------ 778 virtual Error 779 DoAttachToProcessWithID (lldb::pid_t pid) = 0; 780 781 //------------------------------------------------------------------ 782 /// Attach to an existing process using a partial process name. 783 /// 784 /// @param[in] process_name 785 /// The name of the process to attach to. 786 /// 787 /// @param[in] wait_for_launch 788 /// If \b true, wait for the process to be launched and attach 789 /// as soon as possible after it does launch. If \b false, then 790 /// search for a matching process the currently exists. 791 /// 792 /// @return 793 /// Returns \a pid if attaching was successful, or 794 /// LLDB_INVALID_PROCESS_ID if attaching fails. 795 //------------------------------------------------------------------ 796 virtual Error 797 DoAttachToProcessWithName (const char *process_name, bool wait_for_launch) 798 { 799 Error error; 800 error.SetErrorString("attach by name is not supported"); 801 return error; 802 } 803 804 //------------------------------------------------------------------ 805 /// Called after attaching a process. 806 /// 807 /// Allow Process plug-ins to execute some code after attaching to 808 /// a process. 809 //------------------------------------------------------------------ 810 virtual void 811 DidAttach () {} 812 813 814 //------------------------------------------------------------------ 815 /// Called before launching to a process. 816 /// 817 /// Allow Process plug-ins to execute some code before launching a 818 /// process. 819 /// 820 /// @return 821 /// Returns an error object. 822 //------------------------------------------------------------------ 823 virtual Error 824 WillLaunch (Module* module) 825 { 826 return Error(); 827 } 828 829 //------------------------------------------------------------------ 830 /// Launch a new process. 831 /// 832 /// Launch a new process by spawning a new process using \a module's 833 /// file as the file to launch. Arguments are given in \a argv, 834 /// and the environment variables are in \a envp. Standard input 835 /// and output files can be optionally re-directed to \a stdin_path, 836 /// \a stdout_path, and \a stderr_path. 837 /// 838 /// @param[in] module 839 /// The module from which to extract the file specification and 840 /// launch. 841 /// 842 /// @param[in] argv 843 /// The argument array. 844 /// 845 /// @param[in] envp 846 /// The environment array. 847 /// 848 /// @param[in] launch_flags 849 /// Flags to modify the launch (@see lldb::LaunchFlags) 850 /// 851 /// @param[in] stdin_path 852 /// The path to use when re-directing the STDIN of the new 853 /// process. If all stdXX_path arguments are NULL, a pseudo 854 /// terminal will be used. 855 /// 856 /// @param[in] stdout_path 857 /// The path to use when re-directing the STDOUT of the new 858 /// process. If all stdXX_path arguments are NULL, a pseudo 859 /// terminal will be used. 860 /// 861 /// @param[in] stderr_path 862 /// The path to use when re-directing the STDERR of the new 863 /// process. If all stdXX_path arguments are NULL, a pseudo 864 /// terminal will be used. 865 /// 866 /// @return 867 /// A new valid process ID, or LLDB_INVALID_PROCESS_ID if 868 /// launching fails. 869 //------------------------------------------------------------------ 870 virtual Error 871 DoLaunch (Module* module, 872 char const *argv[], 873 char const *envp[], 874 uint32_t launch_flags, 875 const char *stdin_path, 876 const char *stdout_path, 877 const char *stderr_path) = 0; 878 879 //------------------------------------------------------------------ 880 /// Called after launching a process. 881 /// 882 /// Allow Process plug-ins to execute some code after launching 883 /// a process. 884 //------------------------------------------------------------------ 885 virtual void 886 DidLaunch () {} 887 888 889 890 //------------------------------------------------------------------ 891 /// Called before resuming to a process. 892 /// 893 /// Allow Process plug-ins to execute some code before resuming a 894 /// process. 895 /// 896 /// @return 897 /// Returns an error object. 898 //------------------------------------------------------------------ 899 virtual Error 900 WillResume () { return Error(); } 901 902 //------------------------------------------------------------------ 903 /// Resumes all of a process's threads as configured using the 904 /// Thread run control functions. 905 /// 906 /// Threads for a process should be updated with one of the run 907 /// control actions (resume, step, or suspend) that they should take 908 /// when the process is resumed. If no run control action is given 909 /// to a thread it will be resumed by default. 910 /// 911 /// @return 912 /// Returns \b true if the process successfully resumes using 913 /// the thread run control actions, \b false otherwise. 914 /// 915 /// @see Thread:Resume() 916 /// @see Thread:Step() 917 /// @see Thread:Suspend() 918 //------------------------------------------------------------------ 919 virtual Error 920 DoResume () = 0; 921 922 //------------------------------------------------------------------ 923 /// Called after resuming a process. 924 /// 925 /// Allow Process plug-ins to execute some code after resuming 926 /// a process. 927 //------------------------------------------------------------------ 928 virtual void 929 DidResume () {} 930 931 932 //------------------------------------------------------------------ 933 /// Called before halting to a process. 934 /// 935 /// Allow Process plug-ins to execute some code before halting a 936 /// process. 937 /// 938 /// @return 939 /// Returns an error object. 940 //------------------------------------------------------------------ 941 virtual Error 942 WillHalt () { return Error(); } 943 944 //------------------------------------------------------------------ 945 /// Halts a running process. 946 /// 947 /// @return 948 /// Returns \b true if the process successfully halts, \b false 949 /// otherwise. 950 //------------------------------------------------------------------ 951 virtual Error 952 DoHalt () = 0; 953 954 //------------------------------------------------------------------ 955 /// Called after halting a process. 956 /// 957 /// Allow Process plug-ins to execute some code after halting 958 /// a process. 959 //------------------------------------------------------------------ 960 virtual void 961 DidHalt () {} 962 963 //------------------------------------------------------------------ 964 /// Called before detaching from a process. 965 /// 966 /// Allow Process plug-ins to execute some code before detaching 967 /// from a process. 968 /// 969 /// @return 970 /// Returns an error object. 971 //------------------------------------------------------------------ 972 virtual Error 973 WillDetach () 974 { 975 return Error(); 976 } 977 978 //------------------------------------------------------------------ 979 /// Detaches from a running or stopped process. 980 /// 981 /// @return 982 /// Returns \b true if the process successfully detaches, \b 983 /// false otherwise. 984 //------------------------------------------------------------------ 985 virtual Error 986 DoDetach () = 0; 987 988 //------------------------------------------------------------------ 989 /// Called after detaching from a process. 990 /// 991 /// Allow Process plug-ins to execute some code after detaching 992 /// from a process. 993 //------------------------------------------------------------------ 994 virtual void 995 DidDetach () {} 996 997 //------------------------------------------------------------------ 998 /// Called before sending a signal to a process. 999 /// 1000 /// Allow Process plug-ins to execute some code before sending a 1001 /// signal to a process. 1002 /// 1003 /// @return 1004 /// Returns no error if it is safe to proceed with a call to 1005 /// Process::DoSignal(int), otherwise an error describing what 1006 /// prevents the signal from being sent. 1007 //------------------------------------------------------------------ 1008 virtual Error 1009 WillSignal () { return Error(); } 1010 1011 //------------------------------------------------------------------ 1012 /// Sends a process a UNIX signal \a signal. 1013 /// 1014 /// @return 1015 /// Returns an error object. 1016 //------------------------------------------------------------------ 1017 virtual Error 1018 DoSignal (int signal) = 0; 1019 1020 1021 1022 virtual Error 1023 WillDestroy () { return Error(); } 1024 1025 virtual Error 1026 DoDestroy () = 0; 1027 1028 virtual void 1029 DidDestroy () { } 1030 1031 1032 //------------------------------------------------------------------ 1033 /// Called after sending a signal to a process. 1034 /// 1035 /// Allow Process plug-ins to execute some code after sending a 1036 /// signal to a process. 1037 //------------------------------------------------------------------ 1038 virtual void 1039 DidSignal () {} 1040 1041 1042 //------------------------------------------------------------------ 1043 /// Currently called as part of ShouldStop. 1044 /// FIXME: Should really happen when the target stops before the 1045 /// event is taken from the queue... 1046 /// 1047 /// This callback is called as the event 1048 /// is about to be queued up to allow Process plug-ins to execute 1049 /// some code prior to clients being notified that a process was 1050 /// stopped. Common operations include updating the thread list, 1051 /// invalidating any thread state (registers, stack, etc) prior to 1052 /// letting the notification go out. 1053 /// 1054 //------------------------------------------------------------------ 1055 virtual void 1056 RefreshStateAfterStop () = 0; 1057 1058 //------------------------------------------------------------------ 1059 /// Get the target object pointer for this module. 1060 /// 1061 /// @return 1062 /// A Target object pointer to the target that owns this 1063 /// module. 1064 //------------------------------------------------------------------ 1065 Target & 1066 GetTarget (); 1067 1068 //------------------------------------------------------------------ 1069 /// Get the const target object pointer for this module. 1070 /// 1071 /// @return 1072 /// A const Target object pointer to the target that owns this 1073 /// module. 1074 //------------------------------------------------------------------ 1075 const Target & 1076 GetTarget () const; 1077 1078 //------------------------------------------------------------------ 1079 /// Get accessor for the current process state. 1080 /// 1081 /// @return 1082 /// The current state of the process. 1083 /// 1084 /// @see lldb::StateType 1085 //------------------------------------------------------------------ 1086 lldb::StateType 1087 GetState (); 1088 1089protected: 1090 friend class CommandObjectProcessLaunch; 1091 friend class ProcessEventData; 1092 friend class CommandObjectBreakpointCommand; 1093 1094 void 1095 SetState (lldb::EventSP &event_sp); 1096 1097 lldb::StateType 1098 GetPrivateState (); 1099 1100public: 1101 //------------------------------------------------------------------ 1102 /// Get the exit status for a process. 1103 /// 1104 /// @return 1105 /// The process's return code, or -1 if the current process 1106 /// state is not eStateExited. 1107 //------------------------------------------------------------------ 1108 int 1109 GetExitStatus (); 1110 1111 //------------------------------------------------------------------ 1112 /// Get a textual description of what the process exited. 1113 /// 1114 /// @return 1115 /// The textual description of why the process exited, or NULL 1116 /// if there is no description available. 1117 //------------------------------------------------------------------ 1118 const char * 1119 GetExitDescription (); 1120 1121 1122 virtual void 1123 DidExit () 1124 { 1125 } 1126 1127 //------------------------------------------------------------------ 1128 /// Get the number of times this process has posted a stop event. 1129 /// 1130 /// @return 1131 /// The number of times this process has stopped while being 1132 /// debugged. 1133 //------------------------------------------------------------------ 1134 uint32_t 1135 GetStopID () const; 1136 1137 //------------------------------------------------------------------ 1138 /// Set accessor for the process exit status (return code). 1139 /// 1140 /// Sometimes a child exits and the exit can be detected by global 1141 /// functions (signal handler for SIGCHLD for example). This 1142 /// accessor allows the exit status to be set from an external 1143 /// source. 1144 /// 1145 /// Setting this will cause a eStateExited event to be posted to 1146 /// the process event queue. 1147 /// 1148 /// @param[in] exit_status 1149 /// The value for the process's return code. 1150 /// 1151 /// @see lldb::StateType 1152 //------------------------------------------------------------------ 1153 virtual void 1154 SetExitStatus (int exit_status, const char *cstr); 1155 1156 //------------------------------------------------------------------ 1157 /// Check if a process is still alive. 1158 /// 1159 /// @return 1160 /// Returns \b true if the process is still valid, \b false 1161 /// otherwise. 1162 //------------------------------------------------------------------ 1163 virtual bool 1164 IsAlive () = 0; 1165 1166 //------------------------------------------------------------------ 1167 /// Actually do the reading of memory from a process. 1168 /// 1169 /// Subclasses must override this function and can return fewer 1170 /// bytes than requested when memory requests are too large. This 1171 /// class will break up the memory requests and keep advancing the 1172 /// arguments along as needed. 1173 /// 1174 /// @param[in] vm_addr 1175 /// A virtual load address that indicates where to start reading 1176 /// memory from. 1177 /// 1178 /// @param[in] size 1179 /// The number of bytes to read. 1180 /// 1181 /// @param[out] buf 1182 /// A byte buffer that is at least \a size bytes long that 1183 /// will receive the memory bytes. 1184 /// 1185 /// @return 1186 /// The number of bytes that were actually read into \a buf. 1187 //------------------------------------------------------------------ 1188 virtual size_t 1189 DoReadMemory (lldb::addr_t vm_addr, 1190 void *buf, 1191 size_t size, 1192 Error &error) = 0; 1193 1194 //------------------------------------------------------------------ 1195 /// Read of memory from a process. 1196 /// 1197 /// This function will read memory from the current process's 1198 /// address space and remove any traps that may have been inserted 1199 /// into the memory. 1200 /// 1201 /// This function is not meant to be overridden by Process 1202 /// subclasses, the subclasses should implement 1203 /// Process::DoReadMemory (lldb::addr_t, size_t, void *). 1204 /// 1205 /// @param[in] vm_addr 1206 /// A virtual load address that indicates where to start reading 1207 /// memory from. 1208 /// 1209 /// @param[out] buf 1210 /// A byte buffer that is at least \a size bytes long that 1211 /// will receive the memory bytes. 1212 /// 1213 /// @param[in] size 1214 /// The number of bytes to read. 1215 /// 1216 /// @return 1217 /// The number of bytes that were actually read into \a buf. If 1218 /// the returned number is greater than zero, yet less than \a 1219 /// size, then this function will get called again with \a 1220 /// vm_addr, \a buf, and \a size updated appropriately. Zero is 1221 /// returned to indicate an error. 1222 //------------------------------------------------------------------ 1223 size_t 1224 ReadMemory (lldb::addr_t vm_addr, 1225 void *buf, 1226 size_t size, 1227 Error &error); 1228 1229 //------------------------------------------------------------------ 1230 /// Actually do the writing of memory to a process. 1231 /// 1232 /// @param[in] vm_addr 1233 /// A virtual load address that indicates where to start writing 1234 /// memory to. 1235 /// 1236 /// @param[in] buf 1237 /// A byte buffer that is at least \a size bytes long that 1238 /// contains the data to write. 1239 /// 1240 /// @param[in] size 1241 /// The number of bytes to write. 1242 /// 1243 /// @return 1244 /// The number of bytes that were actually written. 1245 //------------------------------------------------------------------ 1246 virtual size_t 1247 DoWriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error) = 0; 1248 1249 //------------------------------------------------------------------ 1250 /// Write memory to a process. 1251 /// 1252 /// This function will write memory to the current process's 1253 /// address space and maintain any traps that might be present due 1254 /// to software breakpoints. 1255 /// 1256 /// This function is not meant to be overridden by Process 1257 /// subclasses, the subclasses should implement 1258 /// Process::DoWriteMemory (lldb::addr_t, size_t, void *). 1259 /// 1260 /// @param[in] vm_addr 1261 /// A virtual load address that indicates where to start writing 1262 /// memory to. 1263 /// 1264 /// @param[in] buf 1265 /// A byte buffer that is at least \a size bytes long that 1266 /// contains the data to write. 1267 /// 1268 /// @param[in] size 1269 /// The number of bytes to write. 1270 /// 1271 /// @return 1272 /// The number of bytes that were actually written. 1273 //------------------------------------------------------------------ 1274 size_t 1275 WriteMemory (lldb::addr_t vm_addr, const void *buf, size_t size, Error &error); 1276 1277 1278 //------------------------------------------------------------------ 1279 /// Actually allocate memory in the process. 1280 /// 1281 /// This function will allocate memory in the process's address 1282 /// space. This can't rely on the generic function calling mechanism, 1283 /// since that requires this function. 1284 /// 1285 /// @param[in] size 1286 /// The size of the allocation requested. 1287 /// 1288 /// @return 1289 /// The address of the allocated buffer in the process, or 1290 /// LLDB_INVALID_ADDRESS if the allocation failed. 1291 //------------------------------------------------------------------ 1292 1293 virtual lldb::addr_t 1294 DoAllocateMemory (size_t size, uint32_t permissions, Error &error) = 0; 1295 1296 //------------------------------------------------------------------ 1297 /// The public interface to allocating memory in the process. 1298 /// 1299 /// This function will allocate memory in the process's address 1300 /// space. This can't rely on the generic function calling mechanism, 1301 /// since that requires this function. 1302 /// 1303 /// @param[in] size 1304 /// The size of the allocation requested. 1305 /// 1306 /// @param[in] permissions 1307 /// Or together any of the lldb::Permissions bits. The permissions on 1308 /// a given memory allocation can't be changed after allocation. Note 1309 /// that a block that isn't set writable can still be written on from lldb, 1310 /// just not by the process itself. 1311 /// 1312 /// @return 1313 /// The address of the allocated buffer in the process, or 1314 /// LLDB_INVALID_ADDRESS if the allocation failed. 1315 //------------------------------------------------------------------ 1316 1317 lldb::addr_t 1318 AllocateMemory (size_t size, uint32_t permissions, Error &error); 1319 1320 //------------------------------------------------------------------ 1321 /// Actually deallocate memory in the process. 1322 /// 1323 /// This function will deallocate memory in the process's address 1324 /// space that was allocated with AllocateMemory. 1325 /// 1326 /// @param[in] ptr 1327 /// A return value from AllocateMemory, pointing to the memory you 1328 /// want to deallocate. 1329 /// 1330 /// @return 1331 /// \btrue if the memory was deallocated, \bfalse otherwise. 1332 //------------------------------------------------------------------ 1333 1334 virtual Error 1335 DoDeallocateMemory (lldb::addr_t ptr) = 0; 1336 1337 //------------------------------------------------------------------ 1338 /// The public interface to deallocating memory in the process. 1339 /// 1340 /// This function will deallocate memory in the process's address 1341 /// space that was allocated with AllocateMemory. 1342 /// 1343 /// @param[in] ptr 1344 /// A return value from AllocateMemory, pointing to the memory you 1345 /// want to deallocate. 1346 /// 1347 /// @return 1348 /// \btrue if the memory was deallocated, \bfalse otherwise. 1349 //------------------------------------------------------------------ 1350 1351 Error 1352 DeallocateMemory (lldb::addr_t ptr); 1353 1354 //------------------------------------------------------------------ 1355 /// Get any available STDOUT. 1356 /// 1357 /// If the process was launched without supplying valid file paths 1358 /// for stdin, stdout, and stderr, then the Process class might 1359 /// try to cache the STDOUT for the process if it is able. Events 1360 /// will be queued indicating that there is STDOUT available that 1361 /// can be retrieved using this function. 1362 /// 1363 /// @param[out] buf 1364 /// A buffer that will receive any STDOUT bytes that are 1365 /// currently available. 1366 /// 1367 /// @param[out] buf_size 1368 /// The size in bytes for the buffer \a buf. 1369 /// 1370 /// @return 1371 /// The number of bytes written into \a buf. If this value is 1372 /// equal to \a buf_size, another call to this function should 1373 /// be made to retrieve more STDOUT data. 1374 //------------------------------------------------------------------ 1375 virtual size_t 1376 GetSTDOUT (char *buf, size_t buf_size, Error &error) 1377 { 1378 error.SetErrorString("stdout unsupported"); 1379 return 0; 1380 } 1381 1382 1383 //------------------------------------------------------------------ 1384 /// Get any available STDERR. 1385 /// 1386 /// If the process was launched without supplying valid file paths 1387 /// for stdin, stdout, and stderr, then the Process class might 1388 /// try to cache the STDERR for the process if it is able. Events 1389 /// will be queued indicating that there is STDERR available that 1390 /// can be retrieved using this function. 1391 /// 1392 /// @param[out] buf 1393 /// A buffer that will receive any STDERR bytes that are 1394 /// currently available. 1395 /// 1396 /// @param[out] buf_size 1397 /// The size in bytes for the buffer \a buf. 1398 /// 1399 /// @return 1400 /// The number of bytes written into \a buf. If this value is 1401 /// equal to \a buf_size, another call to this function should 1402 /// be made to retrieve more STDERR data. 1403 //------------------------------------------------------------------ 1404 virtual size_t 1405 GetSTDERR (char *buf, size_t buf_size, Error &error) 1406 { 1407 error.SetErrorString("stderr unsupported"); 1408 return 0; 1409 } 1410 1411 virtual size_t 1412 PutSTDIN (const char *buf, size_t buf_size, Error &error) 1413 { 1414 error.SetErrorString("stdin unsupported"); 1415 return 0; 1416 } 1417 1418 //---------------------------------------------------------------------- 1419 // Process Breakpoints 1420 //---------------------------------------------------------------------- 1421 virtual size_t 1422 GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site) = 0; 1423 1424 virtual Error 1425 EnableBreakpoint (BreakpointSite *bp_site) = 0; 1426 1427 virtual Error 1428 DisableBreakpoint (BreakpointSite *bp_site) = 0; 1429 1430 // This is implemented completely using the lldb::Process API. Subclasses 1431 // don't need to implement this function unless the standard flow of 1432 // read existing opcode, write breakpoint opcode, verify breakpoint opcode 1433 // doesn't work for a specific process plug-in. 1434 virtual Error 1435 EnableSoftwareBreakpoint (BreakpointSite *bp_site); 1436 1437 // This is implemented completely using the lldb::Process API. Subclasses 1438 // don't need to implement this function unless the standard flow of 1439 // restoring original opcode in memory and verifying the restored opcode 1440 // doesn't work for a specific process plug-in. 1441 virtual Error 1442 DisableSoftwareBreakpoint (BreakpointSite *bp_site); 1443 1444 BreakpointSiteList & 1445 GetBreakpointSiteList(); 1446 1447 const BreakpointSiteList & 1448 GetBreakpointSiteList() const; 1449 1450 void 1451 DisableAllBreakpointSites (); 1452 1453 Error 1454 ClearBreakpointSiteByID (lldb::user_id_t break_id); 1455 1456 lldb::break_id_t 1457 CreateBreakpointSite (lldb::BreakpointLocationSP &owner, 1458 bool use_hardware); 1459 1460 Error 1461 DisableBreakpointSiteByID (lldb::user_id_t break_id); 1462 1463 Error 1464 EnableBreakpointSiteByID (lldb::user_id_t break_id); 1465 1466 1467 // BreakpointLocations use RemoveOwnerFromBreakpointSite to remove 1468 // themselves from the owner's list of this breakpoint sites. This has to 1469 // be a static function because you can't be sure that removing the 1470 // breakpoint from it's containing map won't delete the breakpoint site, 1471 // and doing that in an instance method isn't copasetic. 1472 void 1473 RemoveOwnerFromBreakpointSite (lldb::user_id_t owner_id, 1474 lldb::user_id_t owner_loc_id, 1475 lldb::BreakpointSiteSP &bp_site_sp); 1476 1477 //---------------------------------------------------------------------- 1478 // Process Watchpoints (optional) 1479 //---------------------------------------------------------------------- 1480 virtual Error 1481 EnableWatchpoint (WatchpointLocation *bp_loc); 1482 1483 virtual Error 1484 DisableWatchpoint (WatchpointLocation *bp_loc); 1485 1486 //------------------------------------------------------------------ 1487 // Thread Queries 1488 //------------------------------------------------------------------ 1489 virtual uint32_t 1490 UpdateThreadListIfNeeded () = 0; 1491 1492 ThreadList & 1493 GetThreadList (); 1494 1495 const ThreadList & 1496 GetThreadList () const; 1497 1498 uint32_t 1499 GetNextThreadIndexID (); 1500 1501 //------------------------------------------------------------------ 1502 // Event Handling 1503 //------------------------------------------------------------------ 1504 lldb::StateType 1505 GetNextEvent (lldb::EventSP &event_sp); 1506 1507 lldb::StateType 1508 WaitForProcessToStop (const TimeValue *timeout); 1509 1510 lldb::StateType 1511 WaitForStateChangedEvents (const TimeValue *timeout, lldb::EventSP &event_sp); 1512 1513 Event * 1514 PeekAtStateChangedEvents (); 1515 1516 1517 //------------------------------------------------------------------ 1518 /// If you need to ensure that you and only you will hear about some public 1519 /// event, then make a new listener, set to listen to process events, and 1520 /// then call this with that listener. Then you will have to wait on that 1521 /// listener explicitly for events (rather than using the GetNextEvent & WaitFor* 1522 /// calls above. Be sure to call RestoreProcessEvents when you are done. 1523 /// 1524 /// @param[in] listener 1525 /// This is the new listener to whom all process events will be delivered. 1526 /// 1527 /// @return 1528 /// Returns \b true if the new listener could be installed, 1529 /// \b false otherwise. 1530 //------------------------------------------------------------------ 1531 bool 1532 HijackProcessEvents (Listener *listener); 1533 1534 //------------------------------------------------------------------ 1535 /// Restores the process event broadcasting to its normal state. 1536 /// 1537 //------------------------------------------------------------------ 1538 void 1539 RestoreProcessEvents (); 1540 1541protected: 1542 //------------------------------------------------------------------ 1543 /// This is the part of the event handling that for a process event. 1544 /// It decides what to do with the event and returns true if the 1545 /// event needs to be propagated to the user, and false otherwise. 1546 /// If the event is not propagated, this call will most likely set 1547 /// the target to executing again. 1548 /// 1549 /// @param[in] event_ptr 1550 /// This is the event we are handling. 1551 /// 1552 /// @return 1553 /// Returns \b true if the event should be reported to the 1554 /// user, \b false otherwise. 1555 //------------------------------------------------------------------ 1556 bool 1557 ShouldBroadcastEvent (Event *event_ptr); 1558 1559public: 1560 //------------------------------------------------------------------ 1561 /// Gets the byte order for this process. 1562 /// 1563 /// @return 1564 /// A valid ByteOrder enumeration, or eByteOrderInvalid. 1565 //------------------------------------------------------------------ 1566 virtual lldb::ByteOrder 1567 GetByteOrder () const = 0; 1568 1569 const ConstString & 1570 GetTargetTriple () 1571 { 1572 return m_target_triple; 1573 } 1574 1575 const ABI * 1576 GetABI (); 1577 1578 virtual DynamicLoader * 1579 GetDynamicLoader (); 1580 1581 virtual LanguageRuntime * 1582 GetLanguageRuntime (lldb::LanguageType language); 1583 1584 virtual CPPLanguageRuntime * 1585 GetCPPLanguageRuntime (); 1586 1587 virtual ObjCLanguageRuntime * 1588 GetObjCLanguageRuntime (); 1589 1590 bool 1591 IsRunning () const; 1592 1593 DynamicCheckerFunctions *GetDynamicCheckers() 1594 { 1595 return m_dynamic_checkers_ap.get(); 1596 } 1597 1598 void SetDynamicCheckers(DynamicCheckerFunctions *dynamic_checkers) 1599 { 1600 m_dynamic_checkers_ap.reset(dynamic_checkers); 1601 } 1602 1603 //------------------------------------------------------------------ 1604 // lldb::ExecutionContextScope pure virtual functions 1605 //------------------------------------------------------------------ 1606 virtual Target * 1607 CalculateTarget (); 1608 1609 virtual Process * 1610 CalculateProcess (); 1611 1612 virtual Thread * 1613 CalculateThread (); 1614 1615 virtual StackFrame * 1616 CalculateStackFrame (); 1617 1618 virtual void 1619 CalculateExecutionContext (ExecutionContext &exe_ctx); 1620 1621 lldb::ProcessSP 1622 GetSP (); 1623 1624 ClangPersistentVariables & 1625 GetPersistentVariables(); 1626 1627protected: 1628 //------------------------------------------------------------------ 1629 // Member variables 1630 //------------------------------------------------------------------ 1631 Target & m_target; ///< The target that owns this process. 1632 ThreadSafeValue<lldb::StateType> m_public_state; 1633 ThreadSafeValue<lldb::StateType> m_private_state; // The actual state of our process 1634 Broadcaster m_private_state_broadcaster; // This broadcaster feeds state changed events into the private state thread's listener. 1635 Broadcaster m_private_state_control_broadcaster; // This is the control broadcaster, used to pause, resume & stop the private state thread. 1636 Listener m_private_state_listener; // This is the listener for the private state thread. 1637 Predicate<bool> m_private_state_control_wait; /// This Predicate is used to signal that a control operation is complete. 1638 lldb::thread_t m_private_state_thread; // Thread ID for the thread that watches interal state events 1639 uint32_t m_stop_id; ///< A count of many times the process has stopped. 1640 uint32_t m_thread_index_id; ///< Each thread is created with a 1 based index that won't get re-used. 1641 int m_exit_status; ///< The exit status of the process, or -1 if not set. 1642 std::string m_exit_string; ///< A textual description of why a process exited. 1643 ThreadList m_thread_list; ///< The threads for this process. 1644 std::vector<Notifications> m_notifications; ///< The list of notifications that this process can deliver. 1645 Listener &m_listener; 1646 BreakpointSiteList m_breakpoint_site_list; ///< This is the list of breakpoint locations we intend 1647 ///< to insert in the target. 1648 ClangPersistentVariables m_persistent_vars; ///< These are the persistent variables associated with this process for the expression parser. 1649 std::auto_ptr<DynamicCheckerFunctions> m_dynamic_checkers_ap; ///< The functions used by the expression parser to validate data that expressions use. 1650 UnixSignals m_unix_signals; /// This is the current signal set for this process. 1651 ConstString m_target_triple; 1652 lldb::ABISP m_abi_sp; 1653 1654 typedef std::map<lldb::LanguageType, lldb::LanguageRuntimeSP> LanguageRuntimeCollection; 1655 LanguageRuntimeCollection m_language_runtimes; 1656 1657 size_t 1658 RemoveBreakpointOpcodesFromBuffer (lldb::addr_t addr, size_t size, uint8_t *buf) const; 1659 1660 void 1661 SynchronouslyNotifyStateChanged (lldb::StateType state); 1662 1663 void 1664 SetPublicState (lldb::StateType new_state); 1665 1666 void 1667 SetPrivateState (lldb::StateType state); 1668 1669 bool 1670 StartPrivateStateThread (); 1671 1672 void 1673 StopPrivateStateThread (); 1674 1675 void 1676 PausePrivateStateThread (); 1677 1678 void 1679 ResumePrivateStateThread (); 1680 1681 static void * 1682 PrivateStateThread (void *arg); 1683 1684 void * 1685 RunPrivateStateThread (); 1686 1687 void 1688 HandlePrivateEvent (lldb::EventSP &event_sp); 1689 1690 lldb::StateType 1691 WaitForProcessStopPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); 1692 1693 Error 1694 CompleteAttach (); 1695 1696 1697 // This waits for both the state change broadcaster, and the control broadcaster. 1698 // If control_only, it only waits for the control broadcaster. 1699 1700 bool 1701 WaitForEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp, bool control_only); 1702 1703 lldb::StateType 1704 WaitForStateChangedEventsPrivate (const TimeValue *timeout, lldb::EventSP &event_sp); 1705 1706 lldb::StateType 1707 WaitForState (const TimeValue *timeout, 1708 const lldb::StateType *match_states, 1709 const uint32_t num_match_states); 1710 1711 size_t 1712 WriteMemoryPrivate (lldb::addr_t addr, const void *buf, size_t size, Error &error); 1713 1714private: 1715 //------------------------------------------------------------------ 1716 // For Process only 1717 //------------------------------------------------------------------ 1718 void ControlPrivateStateThread (uint32_t signal); 1719 1720 DISALLOW_COPY_AND_ASSIGN (Process); 1721 1722}; 1723 1724} // namespace lldb_private 1725 1726#endif // liblldb_Process_h_ 1727