SBTarget.h revision ebd63b28c6b7574ed9fbd71e57677c25e57c6a5b
1//===-- SBTarget.h ----------------------------------------------*- 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#ifndef LLDB_SBTarget_h_ 11#define LLDB_SBTarget_h_ 12 13#include "lldb/API/SBDefines.h" 14#include "lldb/API/SBBroadcaster.h" 15#include "lldb/API/SBFileSpec.h" 16 17namespace lldb { 18 19class SBBreakpoint; 20 21class SBTarget 22{ 23public: 24 //------------------------------------------------------------------ 25 // Broadcaster bits. 26 //------------------------------------------------------------------ 27 enum 28 { 29 eBroadcastBitBreakpointChanged = (1 << 0), 30 eBroadcastBitModulesLoaded = (1 << 1), 31 eBroadcastBitModulesUnloaded = (1 << 2) 32 }; 33 34 //------------------------------------------------------------------ 35 // Constructors 36 //------------------------------------------------------------------ 37 SBTarget (); 38 39 SBTarget (const lldb::SBTarget& rhs); 40 41#ifndef SWIG 42 const lldb::SBTarget& 43 operator = (const lldb::SBTarget& rhs); 44#endif 45 46 //------------------------------------------------------------------ 47 // Destructor 48 //------------------------------------------------------------------ 49 ~SBTarget(); 50 51 bool 52 IsValid() const; 53 54 lldb::SBProcess 55 GetProcess (); 56 57 //------------------------------------------------------------------ 58 /// Launch a new process. 59 /// 60 /// Launch a new process by spawning a new process using the 61 /// target object's executable module's file as the file to launch. 62 /// Arguments are given in \a argv, and the environment variables 63 /// are in \a envp. Standard input and output files can be 64 /// optionally re-directed to \a stdin_path, \a stdout_path, and 65 /// \a stderr_path. 66 /// 67 /// @param[in] listener 68 /// An optional listener that will receive all process events. 69 /// If \a listener is valid then \a listener will listen to all 70 /// process events. If not valid, then this target's debugger 71 /// (SBTarget::GetDebugger()) will listen to all process events. 72 /// 73 /// @param[in] argv 74 /// The argument array. 75 /// 76 /// @param[in] envp 77 /// The environment array. 78 /// 79 /// @param[in] launch_flags 80 /// Flags to modify the launch (@see lldb::LaunchFlags) 81 /// 82 /// @param[in] stdin_path 83 /// The path to use when re-directing the STDIN of the new 84 /// process. If all stdXX_path arguments are NULL, a pseudo 85 /// terminal will be used. 86 /// 87 /// @param[in] stdout_path 88 /// The path to use when re-directing the STDOUT of the new 89 /// process. If all stdXX_path arguments are NULL, a pseudo 90 /// terminal will be used. 91 /// 92 /// @param[in] stderr_path 93 /// The path to use when re-directing the STDERR of the new 94 /// process. If all stdXX_path arguments are NULL, a pseudo 95 /// terminal will be used. 96 /// 97 /// @param[in] working_directory 98 /// The working directory to have the child process run in 99 /// 100 /// @param[in] launch_flags 101 /// Some launch options specified by logical OR'ing 102 /// lldb::LaunchFlags enumeration values together. 103 /// 104 /// @param[in] stop_at_endtry 105 /// If false do not stop the inferior at the entry point. 106 /// 107 /// @param[out] 108 /// An error object. Contains the reason if there is some failure. 109 /// 110 /// @return 111 /// A process object for the newly created process. 112 //------------------------------------------------------------------ 113 lldb::SBProcess 114 Launch (SBListener &listener, 115 char const **argv, 116 char const **envp, 117 const char *stdin_path, 118 const char *stdout_path, 119 const char *stderr_path, 120 const char *working_directory, 121 uint32_t launch_flags, // See LaunchFlags 122 bool stop_at_entry, 123 lldb::SBError& error); 124 125 126 //------------------------------------------------------------------ 127 /// Launch a new process with sensible defaults. 128 /// 129 /// @param[in] argv 130 /// The argument array. 131 /// 132 /// @param[in] envp 133 /// The environment array. 134 /// 135 /// @param[in] working_directory 136 /// The working directory to have the child process run in 137 /// 138 /// Default: listener 139 /// Set to the target's debugger (SBTarget::GetDebugger()) 140 /// 141 /// Default: launch_flags 142 /// Empty launch flags 143 /// 144 /// Default: stdin_path 145 /// Default: stdout_path 146 /// Default: stderr_path 147 /// A pseudo terminal will be used. 148 /// 149 /// @return 150 /// A process object for the newly created process. 151 //------------------------------------------------------------------ 152 lldb::SBProcess 153 LaunchSimple (const char **argv, 154 const char **envp, 155 const char *working_directory); 156 157 //------------------------------------------------------------------ 158 /// Attach to process with pid. 159 /// 160 /// @param[in] listener 161 /// An optional listener that will receive all process events. 162 /// If \a listener is valid then \a listener will listen to all 163 /// process events. If not valid, then this target's debugger 164 /// (SBTarget::GetDebugger()) will listen to all process events. 165 /// 166 /// @param[in] pid 167 /// The process ID to attach to. 168 /// 169 /// @param[out] 170 /// An error explaining what went wrong if attach fails. 171 /// 172 /// @return 173 /// A process object for the attached process. 174 //------------------------------------------------------------------ 175 lldb::SBProcess 176 AttachToProcessWithID (SBListener &listener, 177 lldb::pid_t pid, 178 lldb::SBError& error); 179 180 //------------------------------------------------------------------ 181 /// Attach to process with name. 182 /// 183 /// @param[in] listener 184 /// An optional listener that will receive all process events. 185 /// If \a listener is valid then \a listener will listen to all 186 /// process events. If not valid, then this target's debugger 187 /// (SBTarget::GetDebugger()) will listen to all process events. 188 /// 189 /// @param[in] name 190 /// Basename of process to attach to. 191 /// 192 /// @param[in] wait_for 193 /// If true wait for a new instance of 'name' to be launched. 194 /// 195 /// @param[out] 196 /// An error explaining what went wrong if attach fails. 197 /// 198 /// @return 199 /// A process object for the attached process. 200 //------------------------------------------------------------------ 201 lldb::SBProcess 202 AttachToProcessWithName (SBListener &listener, 203 const char *name, 204 bool wait_for, 205 lldb::SBError& error); 206 207 //------------------------------------------------------------------ 208 /// Connect to a remote debug server with url. 209 /// 210 /// @param[in] listener 211 /// An optional listener that will receive all process events. 212 /// If \a listener is valid then \a listener will listen to all 213 /// process events. If not valid, then this target's debugger 214 /// (SBTarget::GetDebugger()) will listen to all process events. 215 /// 216 /// @param[in] url 217 /// The url to connect to, e.g., 'connect://localhost:12345'. 218 /// 219 /// @param[in] plugin_name 220 /// The plugin name to be used; can be NULL. 221 /// 222 /// @param[out] 223 /// An error explaining what went wrong if the connect fails. 224 /// 225 /// @return 226 /// A process object for the connected process. 227 //------------------------------------------------------------------ 228 lldb::SBProcess 229 ConnectRemote (SBListener &listener, 230 const char *url, 231 const char *plugin_name, 232 SBError& error); 233 234 lldb::SBFileSpec 235 GetExecutable (); 236 237 uint32_t 238 GetNumModules () const; 239 240 lldb::SBModule 241 GetModuleAtIndex (uint32_t idx); 242 243 lldb::SBDebugger 244 GetDebugger() const; 245 246 lldb::SBModule 247 FindModule (const lldb::SBFileSpec &file_spec); 248 249 //------------------------------------------------------------------ 250 /// Find functions by name. 251 /// 252 /// @param[in] name 253 /// The name of the function we are looking for. 254 /// 255 /// @param[in] name_type_mask 256 /// A logical OR of one or more FunctionNameType enum bits that 257 /// indicate what kind of names should be used when doing the 258 /// lookup. Bits include fully qualified names, base names, 259 /// C++ methods, or ObjC selectors. 260 /// See FunctionNameType for more details. 261 /// 262 /// @param[in] append 263 /// If true, any matches will be appended to \a sc_list, else 264 /// matches replace the contents of \a sc_list. 265 /// 266 /// @param[out] sc_list 267 /// A symbol context list that gets filled in with all of the 268 /// matches. 269 /// 270 /// @return 271 /// The number of matches added to \a sc_list. 272 //------------------------------------------------------------------ 273 uint32_t 274 FindFunctions (const char *name, 275 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits 276 bool append, 277 lldb::SBSymbolContextList& sc_list); 278 279 //------------------------------------------------------------------ 280 /// Find global and static variables by name. 281 /// 282 /// @param[in] name 283 /// The name of the global or static variable we are looking 284 /// for. 285 /// 286 /// @param[in] max_matches 287 /// Allow the number of matches to be limited to \a max_matches. 288 /// 289 /// @return 290 /// A list of matched variables in an SBValueList. 291 //------------------------------------------------------------------ 292 lldb::SBValueList 293 FindGlobalVariables (const char *name, 294 uint32_t max_matches); 295 296 void 297 Clear (); 298 299 bool 300 ResolveLoadAddress (lldb::addr_t vm_addr, 301 lldb::SBAddress& addr); 302 303 SBSymbolContext 304 ResolveSymbolContextForAddress (const SBAddress& addr, 305 uint32_t resolve_scope); 306 307 lldb::SBBreakpoint 308 BreakpointCreateByLocation (const char *file, uint32_t line); 309 310 lldb::SBBreakpoint 311 BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line); 312 313 lldb::SBBreakpoint 314 BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL); 315 316 lldb::SBBreakpoint 317 BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL); 318 319 lldb::SBBreakpoint 320 BreakpointCreateByAddress (addr_t address); 321 322 uint32_t 323 GetNumBreakpoints () const; 324 325 lldb::SBBreakpoint 326 GetBreakpointAtIndex (uint32_t idx) const; 327 328 bool 329 BreakpointDelete (break_id_t break_id); 330 331 lldb::SBBreakpoint 332 FindBreakpointByID (break_id_t break_id); 333 334 bool 335 EnableAllBreakpoints (); 336 337 bool 338 DisableAllBreakpoints (); 339 340 bool 341 DeleteAllBreakpoints (); 342 343 lldb::SBBroadcaster 344 GetBroadcaster () const; 345 346#ifndef SWIG 347 bool 348 operator == (const lldb::SBTarget &rhs) const; 349 350 bool 351 operator != (const lldb::SBTarget &rhs) const; 352 353#endif 354 355#ifndef SWIG 356 bool 357 GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level); 358#endif 359 360 bool 361 GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level) const; 362 363protected: 364 friend class SBAddress; 365 friend class SBDebugger; 366 friend class SBFunction; 367 friend class SBProcess; 368 friend class SBSymbol; 369 friend class SBModule; 370 371 //------------------------------------------------------------------ 372 // Constructors are private, use static Target::Create function to 373 // create an instance of this class. 374 //------------------------------------------------------------------ 375 376 SBTarget (const lldb::TargetSP& target_sp); 377 378 void 379 reset (const lldb::TargetSP& target_sp); 380 381 lldb_private::Target * 382 operator ->() const; 383 384 lldb_private::Target * 385 get() const; 386 387private: 388 //------------------------------------------------------------------ 389 // For Target only 390 //------------------------------------------------------------------ 391 392 lldb::TargetSP m_opaque_sp; 393}; 394 395} // namespace lldb 396 397#endif // LLDB_SBTarget_h_ 398