1 //===-- SBTarget.h ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLDB_SBTarget_h_
11 #define LLDB_SBTarget_h_
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/SBSymbolContextList.h"
19 #include "lldb/API/SBType.h"
20 #include "lldb/API/SBValue.h"
21 #include "lldb/API/SBWatchpoint.h"
28 SBLaunchInfo (const char **argv);
45 SetUserID (uint32_t uid);
48 SetGroupID (uint32_t gid);
54 GetArgumentAtIndex (uint32_t idx);
57 SetArguments (const char **argv, bool append);
60 GetNumEnvironmentEntries ();
63 GetEnvironmentEntryAtIndex (uint32_t idx);
66 SetEnvironmentEntries (const char **envp, bool append);
72 GetWorkingDirectory () const;
75 SetWorkingDirectory (const char *working_dir);
81 SetLaunchFlags (uint32_t flags);
84 GetProcessPluginName ();
87 SetProcessPluginName (const char *plugin_name);
93 SetShell (const char * path);
99 SetResumeCount (uint32_t c);
102 AddCloseFileAction (int fd);
105 AddDuplicateFileAction (int fd, int dup_fd);
108 AddOpenFileAction (int fd, const char *path, bool read, bool write);
111 AddSuppressFileAction (int fd, bool read, bool write);
114 friend class SBTarget;
116 lldb_private::ProcessLaunchInfo &
119 ProcessLaunchInfoSP m_opaque_sp;
127 SBAttachInfo (lldb::pid_t pid);
129 SBAttachInfo (const char *path, bool wait_for);
131 SBAttachInfo (const SBAttachInfo &rhs);
136 operator = (const SBAttachInfo &rhs);
142 SetProcessID (lldb::pid_t pid);
145 SetExecutable (const char *path);
148 SetExecutable (lldb::SBFileSpec exe_file);
154 SetWaitForLaunch (bool b);
157 GetIgnoreExisting ();
160 SetIgnoreExisting (bool b);
166 SetResumeCount (uint32_t c);
169 GetProcessPluginName ();
172 SetProcessPluginName (const char *plugin_name);
187 SetUserID (uint32_t uid);
190 SetGroupID (uint32_t gid);
193 GetEffectiveUserID();
196 GetEffectiveGroupID();
199 EffectiveUserIDIsValid ();
202 EffectiveGroupIDIsValid ();
205 SetEffectiveUserID (uint32_t uid);
208 SetEffectiveGroupID (uint32_t gid);
211 GetParentProcessID ();
214 SetParentProcessID (lldb::pid_t pid);
217 ParentProcessIDIsValid();
221 friend class SBTarget;
223 lldb_private::ProcessAttachInfo &
226 ProcessAttachInfoSP m_opaque_sp;
232 //------------------------------------------------------------------
234 //------------------------------------------------------------------
237 eBroadcastBitBreakpointChanged = (1 << 0),
238 eBroadcastBitModulesLoaded = (1 << 1),
239 eBroadcastBitModulesUnloaded = (1 << 2),
240 eBroadcastBitWatchpointChanged = (1 << 3),
241 eBroadcastBitSymbolsLoaded = (1 << 4)
244 //------------------------------------------------------------------
246 //------------------------------------------------------------------
249 SBTarget (const lldb::SBTarget& rhs);
251 SBTarget (const lldb::TargetSP& target_sp);
253 const lldb::SBTarget&
254 operator = (const lldb::SBTarget& rhs);
256 //------------------------------------------------------------------
258 //------------------------------------------------------------------
265 GetBroadcasterClassName ();
270 //------------------------------------------------------------------
271 /// Launch a new process.
273 /// Launch a new process by spawning a new process using the
274 /// target object's executable module's file as the file to launch.
275 /// Arguments are given in \a argv, and the environment variables
276 /// are in \a envp. Standard input and output files can be
277 /// optionally re-directed to \a stdin_path, \a stdout_path, and
280 /// @param[in] listener
281 /// An optional listener that will receive all process events.
282 /// If \a listener is valid then \a listener will listen to all
283 /// process events. If not valid, then this target's debugger
284 /// (SBTarget::GetDebugger()) will listen to all process events.
287 /// The argument array.
290 /// The environment array.
292 /// @param[in] launch_flags
293 /// Flags to modify the launch (@see lldb::LaunchFlags)
295 /// @param[in] stdin_path
296 /// The path to use when re-directing the STDIN of the new
297 /// process. If all stdXX_path arguments are NULL, a pseudo
298 /// terminal will be used.
300 /// @param[in] stdout_path
301 /// The path to use when re-directing the STDOUT of the new
302 /// process. If all stdXX_path arguments are NULL, a pseudo
303 /// terminal will be used.
305 /// @param[in] stderr_path
306 /// The path to use when re-directing the STDERR of the new
307 /// process. If all stdXX_path arguments are NULL, a pseudo
308 /// terminal will be used.
310 /// @param[in] working_directory
311 /// The working directory to have the child process run in
313 /// @param[in] launch_flags
314 /// Some launch options specified by logical OR'ing
315 /// lldb::LaunchFlags enumeration values together.
317 /// @param[in] stop_at_endtry
318 /// If false do not stop the inferior at the entry point.
321 /// An error object. Contains the reason if there is some failure.
324 /// A process object for the newly created process.
325 //------------------------------------------------------------------
327 Launch (SBListener &listener,
330 const char *stdin_path,
331 const char *stdout_path,
332 const char *stderr_path,
333 const char *working_directory,
334 uint32_t launch_flags, // See LaunchFlags
336 lldb::SBError& error);
339 //------------------------------------------------------------------
340 /// Launch a new process with sensible defaults.
343 /// The argument array.
346 /// The environment array.
348 /// @param[in] working_directory
349 /// The working directory to have the child process run in
351 /// Default: listener
352 /// Set to the target's debugger (SBTarget::GetDebugger())
354 /// Default: launch_flags
355 /// Empty launch flags
357 /// Default: stdin_path
358 /// Default: stdout_path
359 /// Default: stderr_path
360 /// A pseudo terminal will be used.
363 /// A process object for the newly created process.
364 //------------------------------------------------------------------
366 LaunchSimple (const char **argv,
368 const char *working_directory);
371 Launch (SBLaunchInfo &launch_info, SBError& error);
374 LoadCore (const char *core_file);
377 Attach (SBAttachInfo &attach_info, SBError& error);
379 //------------------------------------------------------------------
380 /// Attach to process with pid.
382 /// @param[in] listener
383 /// An optional listener that will receive all process events.
384 /// If \a listener is valid then \a listener will listen to all
385 /// process events. If not valid, then this target's debugger
386 /// (SBTarget::GetDebugger()) will listen to all process events.
389 /// The process ID to attach to.
392 /// An error explaining what went wrong if attach fails.
395 /// A process object for the attached process.
396 //------------------------------------------------------------------
398 AttachToProcessWithID (SBListener &listener,
400 lldb::SBError& error);
402 #if defined(__APPLE__)
403 // We need to keep this around for a build or two since Xcode links
404 // to the 32 bit version of this function. We will take it out soon.
406 AttachToProcessWithID (SBListener &listener,
407 ::pid_t pid, // 32 bit int process ID
408 lldb::SBError& error); // DEPRECATED
410 //------------------------------------------------------------------
411 /// Attach to process with name.
413 /// @param[in] listener
414 /// An optional listener that will receive all process events.
415 /// If \a listener is valid then \a listener will listen to all
416 /// process events. If not valid, then this target's debugger
417 /// (SBTarget::GetDebugger()) will listen to all process events.
420 /// Basename of process to attach to.
422 /// @param[in] wait_for
423 /// If true wait for a new instance of 'name' to be launched.
426 /// An error explaining what went wrong if attach fails.
429 /// A process object for the attached process.
430 //------------------------------------------------------------------
432 AttachToProcessWithName (SBListener &listener,
435 lldb::SBError& error);
437 //------------------------------------------------------------------
438 /// Connect to a remote debug server with url.
440 /// @param[in] listener
441 /// An optional listener that will receive all process events.
442 /// If \a listener is valid then \a listener will listen to all
443 /// process events. If not valid, then this target's debugger
444 /// (SBTarget::GetDebugger()) will listen to all process events.
447 /// The url to connect to, e.g., 'connect://localhost:12345'.
449 /// @param[in] plugin_name
450 /// The plugin name to be used; can be NULL.
453 /// An error explaining what went wrong if the connect fails.
456 /// A process object for the connected process.
457 //------------------------------------------------------------------
459 ConnectRemote (SBListener &listener,
461 const char *plugin_name,
468 AddModule (lldb::SBModule &module);
471 AddModule (const char *path,
476 AddModule (const char *path,
478 const char *uuid_cstr,
479 const char *symfile);
482 AddModule (const SBModuleSpec &module_spec);
485 GetNumModules () const;
488 GetModuleAtIndex (uint32_t idx);
491 RemoveModule (lldb::SBModule module);
497 FindModule (const lldb::SBFileSpec &file_spec);
503 GetAddressByteSize();
508 //------------------------------------------------------------------
509 /// Set the base load address for a module section.
511 /// @param[in] section
512 /// The section whose base load address will be set within this
515 /// @param[in] section_base_addr
516 /// The base address for the section.
519 /// An error to indicate success, fail, and any reason for
521 //------------------------------------------------------------------
523 SetSectionLoadAddress (lldb::SBSection section,
524 lldb::addr_t section_base_addr);
526 //------------------------------------------------------------------
527 /// Clear the base load address for a module section.
529 /// @param[in] section
530 /// The section whose base load address will be cleared within
534 /// An error to indicate success, fail, and any reason for
536 //------------------------------------------------------------------
538 ClearSectionLoadAddress (lldb::SBSection section);
540 //------------------------------------------------------------------
541 /// Slide all file addresses for all module sections so that \a module
542 /// appears to loaded at these slide addresses.
544 /// When you need all sections within a module to be loaded at a
545 /// rigid slide from the addresses found in the module object file,
546 /// this function will allow you to easily and quickly slide all
549 /// @param[in] module
550 /// The module to load.
552 /// @param[in] sections_offset
553 /// An offset that will be applied to all section file addresses
554 /// (the virtual addresses found in the object file itself).
557 /// An error to indicate success, fail, and any reason for
559 //------------------------------------------------------------------
561 SetModuleLoadAddress (lldb::SBModule module,
562 int64_t sections_offset);
565 //------------------------------------------------------------------
566 /// The the section base load addresses for all sections in a module.
568 /// @param[in] module
569 /// The module to unload.
572 /// An error to indicate success, fail, and any reason for
574 //------------------------------------------------------------------
576 ClearModuleLoadAddress (lldb::SBModule module);
578 //------------------------------------------------------------------
579 /// Find functions by name.
582 /// The name of the function we are looking for.
584 /// @param[in] name_type_mask
585 /// A logical OR of one or more FunctionNameType enum bits that
586 /// indicate what kind of names should be used when doing the
587 /// lookup. Bits include fully qualified names, base names,
588 /// C++ methods, or ObjC selectors.
589 /// See FunctionNameType for more details.
592 /// A lldb::SBSymbolContextList that gets filled in with all of
593 /// the symbol contexts for all the matches.
594 //------------------------------------------------------------------
595 lldb::SBSymbolContextList
596 FindFunctions (const char *name,
597 uint32_t name_type_mask = lldb::eFunctionNameTypeAny);
599 //------------------------------------------------------------------
600 /// Find global and static variables by name.
603 /// The name of the global or static variable we are looking
606 /// @param[in] max_matches
607 /// Allow the number of matches to be limited to \a max_matches.
610 /// A list of matched variables in an SBValueList.
611 //------------------------------------------------------------------
613 FindGlobalVariables (const char *name,
614 uint32_t max_matches);
616 //------------------------------------------------------------------
617 /// Find the first global (or static) variable by name.
620 /// The name of the global or static variable we are looking
624 /// An SBValue that gets filled in with the found variable (if any).
625 //------------------------------------------------------------------
627 FindFirstGlobalVariable (const char* name);
633 ResolveLoadAddress (lldb::addr_t vm_addr);
636 ResolveSymbolContextForAddress (const SBAddress& addr,
637 uint32_t resolve_scope);
640 BreakpointCreateByLocation (const char *file, uint32_t line);
643 BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line);
646 BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL);
648 // This version uses name_type_mask = eFunctionNameTypeAuto
650 BreakpointCreateByName (const char *symbol_name,
651 const SBFileSpecList &module_list,
652 const SBFileSpecList &comp_unit_list);
655 BreakpointCreateByName (const char *symbol_name,
656 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
657 const SBFileSpecList &module_list,
658 const SBFileSpecList &comp_unit_list);
661 BreakpointCreateByNames (const char *symbol_name[],
663 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
664 const SBFileSpecList &module_list,
665 const SBFileSpecList &comp_unit_list);
668 BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL);
671 BreakpointCreateByRegex (const char *symbol_name_regex,
672 const SBFileSpecList &module_list,
673 const SBFileSpecList &comp_unit_list);
676 BreakpointCreateBySourceRegex (const char *source_regex,
677 const lldb::SBFileSpec &source_file,
678 const char *module_name = NULL);
681 BreakpointCreateBySourceRegex (const char *source_regex,
682 const SBFileSpecList &module_list,
683 const lldb::SBFileSpecList &source_file);
686 BreakpointCreateForException (lldb::LanguageType language,
691 BreakpointCreateByAddress (addr_t address);
694 GetNumBreakpoints () const;
697 GetBreakpointAtIndex (uint32_t idx) const;
700 BreakpointDelete (break_id_t break_id);
703 FindBreakpointByID (break_id_t break_id);
706 EnableAllBreakpoints ();
709 DisableAllBreakpoints ();
712 DeleteAllBreakpoints ();
715 GetNumWatchpoints () const;
718 GetWatchpointAtIndex (uint32_t idx) const;
721 DeleteWatchpoint (lldb::watch_id_t watch_id);
724 FindWatchpointByID (lldb::watch_id_t watch_id);
727 WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError& error);
730 EnableAllWatchpoints ();
733 DisableAllWatchpoints ();
736 DeleteAllWatchpoints ();
739 GetBroadcaster () const;
742 FindFirstType (const char* type);
745 FindTypes (const char* type);
748 GetBasicType(lldb::BasicType type);
753 lldb::SBInstructionList
754 ReadInstructions (lldb::SBAddress base_addr, uint32_t count);
756 lldb::SBInstructionList
757 ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string);
759 lldb::SBInstructionList
760 GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size);
762 // The "WithFlavor" is necessary to keep SWIG from getting confused about overloaded arguments when
763 // using the buf + size -> Python Object magic.
765 lldb::SBInstructionList
766 GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size);
768 lldb::SBInstructionList
769 GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size);
771 lldb::SBInstructionList
772 GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size);
774 lldb::SBSymbolContextList
775 FindSymbols (const char *name,
776 lldb::SymbolType type = eSymbolTypeAny);
779 operator == (const lldb::SBTarget &rhs) const;
782 operator != (const lldb::SBTarget &rhs) const;
785 GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level);
788 EvaluateExpression (const char *expr, const SBExpressionOptions &options);
791 GetStackRedZoneSize();
794 friend class SBAddress;
795 friend class SBBlock;
796 friend class SBDebugger;
797 friend class SBFunction;
798 friend class SBInstruction;
799 friend class SBModule;
800 friend class SBProcess;
801 friend class SBSection;
802 friend class SBSourceManager;
803 friend class SBSymbol;
804 friend class SBValue;
806 //------------------------------------------------------------------
807 // Constructors are private, use static Target::Create function to
808 // create an instance of this class.
809 //------------------------------------------------------------------
815 SetSP (const lldb::TargetSP& target_sp);
819 //------------------------------------------------------------------
821 //------------------------------------------------------------------
823 lldb::TargetSP m_opaque_sp;
828 #endif // LLDB_SBTarget_h_