SBTarget.h revision 1b925206e3c4867fea9eb55a4c6460962cf32564
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/SBAddress.h" 15#include "lldb/API/SBBroadcaster.h" 16#include "lldb/API/SBFileSpec.h" 17#include "lldb/API/SBFileSpecList.h" 18#include "lldb/API/SBType.h" 19#include "lldb/API/SBWatchpoint.h" 20 21namespace lldb { 22 23class SBBreakpoint; 24 25class SBTarget 26{ 27public: 28 //------------------------------------------------------------------ 29 // Broadcaster bits. 30 //------------------------------------------------------------------ 31 enum 32 { 33 eBroadcastBitBreakpointChanged = (1 << 0), 34 eBroadcastBitModulesLoaded = (1 << 1), 35 eBroadcastBitModulesUnloaded = (1 << 2) 36 }; 37 38 //------------------------------------------------------------------ 39 // Constructors 40 //------------------------------------------------------------------ 41 SBTarget (); 42 43 SBTarget (const lldb::SBTarget& rhs); 44 45#ifndef SWIG 46 const lldb::SBTarget& 47 operator = (const lldb::SBTarget& rhs); 48#endif 49 50 //------------------------------------------------------------------ 51 // Destructor 52 //------------------------------------------------------------------ 53 ~SBTarget(); 54 55 bool 56 IsValid() const; 57 58 lldb::SBProcess 59 GetProcess (); 60 61 //------------------------------------------------------------------ 62 /// Launch a new process. 63 /// 64 /// Launch a new process by spawning a new process using the 65 /// target object's executable module's file as the file to launch. 66 /// Arguments are given in \a argv, and the environment variables 67 /// are in \a envp. Standard input and output files can be 68 /// optionally re-directed to \a stdin_path, \a stdout_path, and 69 /// \a stderr_path. 70 /// 71 /// @param[in] listener 72 /// An optional listener that will receive all process events. 73 /// If \a listener is valid then \a listener will listen to all 74 /// process events. If not valid, then this target's debugger 75 /// (SBTarget::GetDebugger()) will listen to all process events. 76 /// 77 /// @param[in] argv 78 /// The argument array. 79 /// 80 /// @param[in] envp 81 /// The environment array. 82 /// 83 /// @param[in] launch_flags 84 /// Flags to modify the launch (@see lldb::LaunchFlags) 85 /// 86 /// @param[in] stdin_path 87 /// The path to use when re-directing the STDIN of the new 88 /// process. If all stdXX_path arguments are NULL, a pseudo 89 /// terminal will be used. 90 /// 91 /// @param[in] stdout_path 92 /// The path to use when re-directing the STDOUT of the new 93 /// process. If all stdXX_path arguments are NULL, a pseudo 94 /// terminal will be used. 95 /// 96 /// @param[in] stderr_path 97 /// The path to use when re-directing the STDERR of the new 98 /// process. If all stdXX_path arguments are NULL, a pseudo 99 /// terminal will be used. 100 /// 101 /// @param[in] working_directory 102 /// The working directory to have the child process run in 103 /// 104 /// @param[in] launch_flags 105 /// Some launch options specified by logical OR'ing 106 /// lldb::LaunchFlags enumeration values together. 107 /// 108 /// @param[in] stop_at_endtry 109 /// If false do not stop the inferior at the entry point. 110 /// 111 /// @param[out] 112 /// An error object. Contains the reason if there is some failure. 113 /// 114 /// @return 115 /// A process object for the newly created process. 116 //------------------------------------------------------------------ 117 lldb::SBProcess 118 Launch (SBListener &listener, 119 char const **argv, 120 char const **envp, 121 const char *stdin_path, 122 const char *stdout_path, 123 const char *stderr_path, 124 const char *working_directory, 125 uint32_t launch_flags, // See LaunchFlags 126 bool stop_at_entry, 127 lldb::SBError& error); 128 129 130 //------------------------------------------------------------------ 131 /// Launch a new process with sensible defaults. 132 /// 133 /// @param[in] argv 134 /// The argument array. 135 /// 136 /// @param[in] envp 137 /// The environment array. 138 /// 139 /// @param[in] working_directory 140 /// The working directory to have the child process run in 141 /// 142 /// Default: listener 143 /// Set to the target's debugger (SBTarget::GetDebugger()) 144 /// 145 /// Default: launch_flags 146 /// Empty launch flags 147 /// 148 /// Default: stdin_path 149 /// Default: stdout_path 150 /// Default: stderr_path 151 /// A pseudo terminal will be used. 152 /// 153 /// @return 154 /// A process object for the newly created process. 155 //------------------------------------------------------------------ 156 lldb::SBProcess 157 LaunchSimple (const char **argv, 158 const char **envp, 159 const char *working_directory); 160 161 //------------------------------------------------------------------ 162 /// Attach to process with pid. 163 /// 164 /// @param[in] listener 165 /// An optional listener that will receive all process events. 166 /// If \a listener is valid then \a listener will listen to all 167 /// process events. If not valid, then this target's debugger 168 /// (SBTarget::GetDebugger()) will listen to all process events. 169 /// 170 /// @param[in] pid 171 /// The process ID to attach to. 172 /// 173 /// @param[out] 174 /// An error explaining what went wrong if attach fails. 175 /// 176 /// @return 177 /// A process object for the attached process. 178 //------------------------------------------------------------------ 179 lldb::SBProcess 180 AttachToProcessWithID (SBListener &listener, 181 lldb::pid_t pid, 182 lldb::SBError& error); 183 184#if defined(__APPLE__) 185 // We need to keep this around for a build or two since Xcode links 186 // to the 32 bit version of this function. We will take it out soon. 187 lldb::SBProcess 188 AttachToProcessWithID (SBListener &listener, 189 ::pid_t pid, // 32 bit int process ID 190 lldb::SBError& error); // DEPRECATED 191#endif 192 //------------------------------------------------------------------ 193 /// Attach to process with name. 194 /// 195 /// @param[in] listener 196 /// An optional listener that will receive all process events. 197 /// If \a listener is valid then \a listener will listen to all 198 /// process events. If not valid, then this target's debugger 199 /// (SBTarget::GetDebugger()) will listen to all process events. 200 /// 201 /// @param[in] name 202 /// Basename of process to attach to. 203 /// 204 /// @param[in] wait_for 205 /// If true wait for a new instance of 'name' to be launched. 206 /// 207 /// @param[out] 208 /// An error explaining what went wrong if attach fails. 209 /// 210 /// @return 211 /// A process object for the attached process. 212 //------------------------------------------------------------------ 213 lldb::SBProcess 214 AttachToProcessWithName (SBListener &listener, 215 const char *name, 216 bool wait_for, 217 lldb::SBError& error); 218 219 //------------------------------------------------------------------ 220 /// Connect to a remote debug server with url. 221 /// 222 /// @param[in] listener 223 /// An optional listener that will receive all process events. 224 /// If \a listener is valid then \a listener will listen to all 225 /// process events. If not valid, then this target's debugger 226 /// (SBTarget::GetDebugger()) will listen to all process events. 227 /// 228 /// @param[in] url 229 /// The url to connect to, e.g., 'connect://localhost:12345'. 230 /// 231 /// @param[in] plugin_name 232 /// The plugin name to be used; can be NULL. 233 /// 234 /// @param[out] 235 /// An error explaining what went wrong if the connect fails. 236 /// 237 /// @return 238 /// A process object for the connected process. 239 //------------------------------------------------------------------ 240 lldb::SBProcess 241 ConnectRemote (SBListener &listener, 242 const char *url, 243 const char *plugin_name, 244 SBError& error); 245 246 lldb::SBFileSpec 247 GetExecutable (); 248 249 bool 250 AddModule (lldb::SBModule &module); 251 252 lldb::SBModule 253 AddModule (const char *path, 254 const char *triple, 255 const char *uuid); 256 257 uint32_t 258 GetNumModules () const; 259 260 lldb::SBModule 261 GetModuleAtIndex (uint32_t idx); 262 263 bool 264 RemoveModule (lldb::SBModule module); 265 266 lldb::SBDebugger 267 GetDebugger() const; 268 269 lldb::SBModule 270 FindModule (const lldb::SBFileSpec &file_spec); 271 272 lldb::ByteOrder 273 GetByteOrder (); 274 275 uint32_t 276 GetAddressByteSize(); 277 278 const char * 279 GetTriple (); 280 281 //------------------------------------------------------------------ 282 /// Set the base load address for a module section. 283 /// 284 /// @param[in] section 285 /// The section whose base load address will be set within this 286 /// target. 287 /// 288 /// @param[in] section_base_addr 289 /// The base address for the section. 290 /// 291 /// @return 292 /// An error to indicate success, fail, and any reason for 293 /// failure. 294 //------------------------------------------------------------------ 295 lldb::SBError 296 SetSectionLoadAddress (lldb::SBSection section, 297 lldb::addr_t section_base_addr); 298 299 //------------------------------------------------------------------ 300 /// Clear the base load address for a module section. 301 /// 302 /// @param[in] section 303 /// The section whose base load address will be cleared within 304 /// this target. 305 /// 306 /// @return 307 /// An error to indicate success, fail, and any reason for 308 /// failure. 309 //------------------------------------------------------------------ 310 lldb::SBError 311 ClearSectionLoadAddress (lldb::SBSection section); 312 313 //------------------------------------------------------------------ 314 /// Slide all file addresses for all module sections so that \a module 315 /// appears to loaded at these slide addresses. 316 /// 317 /// When you need all sections within a module to be loaded at a 318 /// rigid slide from the addresses found in the module object file, 319 /// this function will allow you to easily and quickly slide all 320 /// module sections. 321 /// 322 /// @param[in] module 323 /// The module to load. 324 /// 325 /// @param[in] sections_offset 326 /// An offset that will be applied to all section file addresses 327 /// (the virtual addresses found in the object file itself). 328 /// 329 /// @return 330 /// An error to indicate success, fail, and any reason for 331 /// failure. 332 //------------------------------------------------------------------ 333 lldb::SBError 334 SetModuleLoadAddress (lldb::SBModule module, 335 int64_t sections_offset); 336 337 338 //------------------------------------------------------------------ 339 /// The the section base load addresses for all sections in a module. 340 /// 341 /// @param[in] module 342 /// The module to unload. 343 /// 344 /// @return 345 /// An error to indicate success, fail, and any reason for 346 /// failure. 347 //------------------------------------------------------------------ 348 lldb::SBError 349 ClearModuleLoadAddress (lldb::SBModule module); 350 351 //------------------------------------------------------------------ 352 /// Find functions by name. 353 /// 354 /// @param[in] name 355 /// The name of the function we are looking for. 356 /// 357 /// @param[in] name_type_mask 358 /// A logical OR of one or more FunctionNameType enum bits that 359 /// indicate what kind of names should be used when doing the 360 /// lookup. Bits include fully qualified names, base names, 361 /// C++ methods, or ObjC selectors. 362 /// See FunctionNameType for more details. 363 /// 364 /// @param[in] append 365 /// If true, any matches will be appended to \a sc_list, else 366 /// matches replace the contents of \a sc_list. 367 /// 368 /// @param[out] sc_list 369 /// A symbol context list that gets filled in with all of the 370 /// matches. 371 /// 372 /// @return 373 /// The number of matches added to \a sc_list. 374 //------------------------------------------------------------------ 375 uint32_t 376 FindFunctions (const char *name, 377 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits 378 bool append, 379 lldb::SBSymbolContextList& sc_list); 380 381 //------------------------------------------------------------------ 382 /// Find global and static variables by name. 383 /// 384 /// @param[in] name 385 /// The name of the global or static variable we are looking 386 /// for. 387 /// 388 /// @param[in] max_matches 389 /// Allow the number of matches to be limited to \a max_matches. 390 /// 391 /// @return 392 /// A list of matched variables in an SBValueList. 393 //------------------------------------------------------------------ 394 lldb::SBValueList 395 FindGlobalVariables (const char *name, 396 uint32_t max_matches); 397 398 void 399 Clear (); 400 401 lldb::SBAddress 402 ResolveLoadAddress (lldb::addr_t vm_addr); 403 404 SBSymbolContext 405 ResolveSymbolContextForAddress (const SBAddress& addr, 406 uint32_t resolve_scope); 407 408 lldb::SBBreakpoint 409 BreakpointCreateByLocation (const char *file, uint32_t line); 410 411 lldb::SBBreakpoint 412 BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line); 413 414 lldb::SBBreakpoint 415 BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL); 416 417 // This version uses name_type_mask = eFunctionNameTypeAuto 418 lldb::SBBreakpoint 419 BreakpointCreateByName (const char *symbol_name, 420 const SBFileSpecList &module_list, 421 const SBFileSpecList &comp_unit_list); 422 423 lldb::SBBreakpoint 424 BreakpointCreateByName (const char *symbol_name, 425 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits 426 const SBFileSpecList &module_list, 427 const SBFileSpecList &comp_unit_list); 428 429 lldb::SBBreakpoint 430 BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL); 431 432 lldb::SBBreakpoint 433 BreakpointCreateByRegex (const char *symbol_name_regex, 434 const SBFileSpecList &module_list, 435 const SBFileSpecList &comp_unit_list); 436 437 lldb::SBBreakpoint 438 BreakpointCreateBySourceRegex (const char *source_regex, 439 const lldb::SBFileSpec &source_file, 440 const char *module_name = NULL); 441 442 lldb::SBBreakpoint 443 BreakpointCreateBySourceRegex (const char *source_regex, 444 const SBFileSpecList &module_list, 445 const lldb::SBFileSpecList &source_file); 446 447 lldb::SBBreakpoint 448 BreakpointCreateByAddress (addr_t address); 449 450 uint32_t 451 GetNumBreakpoints () const; 452 453 lldb::SBBreakpoint 454 GetBreakpointAtIndex (uint32_t idx) const; 455 456 bool 457 BreakpointDelete (break_id_t break_id); 458 459 lldb::SBBreakpoint 460 FindBreakpointByID (break_id_t break_id); 461 462 bool 463 EnableAllBreakpoints (); 464 465 bool 466 DisableAllBreakpoints (); 467 468 bool 469 DeleteAllBreakpoints (); 470 471 uint32_t 472 GetNumWatchpoints () const; 473 474 lldb::SBWatchpoint 475 GetWatchpointAtIndex (uint32_t idx) const; 476 477 bool 478 DeleteWatchpoint (lldb::watch_id_t watch_id); 479 480 lldb::SBWatchpoint 481 FindWatchpointByID (lldb::watch_id_t watch_id); 482 483 lldb::SBWatchpoint 484 WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write); 485 486 bool 487 EnableAllWatchpoints (); 488 489 bool 490 DisableAllWatchpoints (); 491 492 bool 493 DeleteAllWatchpoints (); 494 495 lldb::SBBroadcaster 496 GetBroadcaster () const; 497 498 lldb::SBType 499 FindFirstType (const char* type); 500 501 lldb::SBTypeList 502 FindTypes (const char* type); 503 504 SBSourceManager 505 GetSourceManager(); 506 507 lldb::SBInstructionList 508 GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size); 509 510 lldb::SBInstructionList 511 GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size); 512 513#ifndef SWIG 514 bool 515 operator == (const lldb::SBTarget &rhs) const; 516 517 bool 518 operator != (const lldb::SBTarget &rhs) const; 519 520#endif 521 522 bool 523 GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level); 524 525protected: 526 friend class SBAddress; 527 friend class SBDebugger; 528 friend class SBFunction; 529 friend class SBInstruction; 530 friend class SBModule; 531 friend class SBProcess; 532 friend class SBSourceManager; 533 friend class SBSymbol; 534 friend class SBValue; 535 536 //------------------------------------------------------------------ 537 // Constructors are private, use static Target::Create function to 538 // create an instance of this class. 539 //------------------------------------------------------------------ 540 541 SBTarget (const lldb::TargetSP& target_sp); 542 543 void 544 reset (const lldb::TargetSP& target_sp); 545 546 lldb_private::Target * 547 operator ->() const; 548 549 lldb_private::Target * 550 get() const; 551 552 const lldb::TargetSP & 553 get_sp () const; 554 555private: 556 //------------------------------------------------------------------ 557 // For Target only 558 //------------------------------------------------------------------ 559 560 lldb::TargetSP m_opaque_sp; 561}; 562 563} // namespace lldb 564 565#endif // LLDB_SBTarget_h_ 566