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);
53 //----------------------------------------------------------------------
54 /// Set the executable file that will be used to launch the process and
55 /// optionally set it as the first argument in the argument vector.
57 /// This only needs to be specified if clients wish to carefully control
58 /// the exact path will be used to launch a binary. If you create a
59 /// target with a symlink, that symlink will get resolved in the target
60 /// and the resolved path will get used to launch the process. Calling
61 /// this function can help you still launch your process using the
62 /// path of your choice.
64 /// If this function is not called prior to launching with
65 /// SBTarget::Launch(...), the target will use the resolved executable
66 /// path that was used to create the target.
68 /// @param[in] exe_file
69 /// The override path to use when launching the executable.
71 /// @param[in] add_as_first_arg
72 /// If true, then the path will be inserted into the argument vector
73 /// prior to launching. Otherwise the argument vector will be left
75 //----------------------------------------------------------------------
77 SetExecutableFile (SBFileSpec exe_file, bool add_as_first_arg);
83 GetArgumentAtIndex (uint32_t idx);
86 SetArguments (const char **argv, bool append);
89 GetNumEnvironmentEntries ();
92 GetEnvironmentEntryAtIndex (uint32_t idx);
95 SetEnvironmentEntries (const char **envp, bool append);
101 GetWorkingDirectory () const;
104 SetWorkingDirectory (const char *working_dir);
110 SetLaunchFlags (uint32_t flags);
113 GetProcessPluginName ();
116 SetProcessPluginName (const char *plugin_name);
122 SetShell (const char * path);
128 SetResumeCount (uint32_t c);
131 AddCloseFileAction (int fd);
134 AddDuplicateFileAction (int fd, int dup_fd);
137 AddOpenFileAction (int fd, const char *path, bool read, bool write);
140 AddSuppressFileAction (int fd, bool read, bool write);
143 SetLaunchEventData (const char *data);
146 GetLaunchEventData () const;
149 GetDetachOnError() const;
152 SetDetachOnError(bool enable);
155 friend class SBTarget;
157 lldb_private::ProcessLaunchInfo &
160 ProcessLaunchInfoSP m_opaque_sp;
168 SBAttachInfo (lldb::pid_t pid);
170 SBAttachInfo (const char *path, bool wait_for);
172 SBAttachInfo (const SBAttachInfo &rhs);
177 operator = (const SBAttachInfo &rhs);
183 SetProcessID (lldb::pid_t pid);
186 SetExecutable (const char *path);
189 SetExecutable (lldb::SBFileSpec exe_file);
195 SetWaitForLaunch (bool b);
198 GetIgnoreExisting ();
201 SetIgnoreExisting (bool b);
207 SetResumeCount (uint32_t c);
210 GetProcessPluginName ();
213 SetProcessPluginName (const char *plugin_name);
228 SetUserID (uint32_t uid);
231 SetGroupID (uint32_t gid);
234 GetEffectiveUserID();
237 GetEffectiveGroupID();
240 EffectiveUserIDIsValid ();
243 EffectiveGroupIDIsValid ();
246 SetEffectiveUserID (uint32_t uid);
249 SetEffectiveGroupID (uint32_t gid);
252 GetParentProcessID ();
255 SetParentProcessID (lldb::pid_t pid);
258 ParentProcessIDIsValid();
262 friend class SBTarget;
264 lldb_private::ProcessAttachInfo &
267 ProcessAttachInfoSP m_opaque_sp;
273 //------------------------------------------------------------------
275 //------------------------------------------------------------------
278 eBroadcastBitBreakpointChanged = (1 << 0),
279 eBroadcastBitModulesLoaded = (1 << 1),
280 eBroadcastBitModulesUnloaded = (1 << 2),
281 eBroadcastBitWatchpointChanged = (1 << 3),
282 eBroadcastBitSymbolsLoaded = (1 << 4)
285 //------------------------------------------------------------------
287 //------------------------------------------------------------------
290 SBTarget (const lldb::SBTarget& rhs);
292 SBTarget (const lldb::TargetSP& target_sp);
294 const lldb::SBTarget&
295 operator = (const lldb::SBTarget& rhs);
297 //------------------------------------------------------------------
299 //------------------------------------------------------------------
306 GetBroadcasterClassName ();
311 //------------------------------------------------------------------
312 /// Install any binaries that need to be installed.
314 /// This function does nothing when debugging on the host system.
315 /// When connected to remote platforms, the target's main executable
316 /// and any modules that have their remote install path set will be
317 /// installed on the remote platform. If the main executable doesn't
318 /// have an install location set, it will be installed in the remote
319 /// platform's working directory.
322 /// An error describing anything that went wrong during
324 //------------------------------------------------------------------
328 //------------------------------------------------------------------
329 /// Launch a new process.
331 /// Launch a new process by spawning a new process using the
332 /// target object's executable module's file as the file to launch.
333 /// Arguments are given in \a argv, and the environment variables
334 /// are in \a envp. Standard input and output files can be
335 /// optionally re-directed to \a stdin_path, \a stdout_path, and
338 /// @param[in] listener
339 /// An optional listener that will receive all process events.
340 /// If \a listener is valid then \a listener will listen to all
341 /// process events. If not valid, then this target's debugger
342 /// (SBTarget::GetDebugger()) will listen to all process events.
345 /// The argument array.
348 /// The environment array.
350 /// @param[in] launch_flags
351 /// Flags to modify the launch (@see lldb::LaunchFlags)
353 /// @param[in] stdin_path
354 /// The path to use when re-directing the STDIN of the new
355 /// process. If all stdXX_path arguments are NULL, a pseudo
356 /// terminal will be used.
358 /// @param[in] stdout_path
359 /// The path to use when re-directing the STDOUT of the new
360 /// process. If all stdXX_path arguments are NULL, a pseudo
361 /// terminal will be used.
363 /// @param[in] stderr_path
364 /// The path to use when re-directing the STDERR of the new
365 /// process. If all stdXX_path arguments are NULL, a pseudo
366 /// terminal will be used.
368 /// @param[in] working_directory
369 /// The working directory to have the child process run in
371 /// @param[in] launch_flags
372 /// Some launch options specified by logical OR'ing
373 /// lldb::LaunchFlags enumeration values together.
375 /// @param[in] stop_at_entry
376 /// If false do not stop the inferior at the entry point.
379 /// An error object. Contains the reason if there is some failure.
382 /// A process object for the newly created process.
383 //------------------------------------------------------------------
385 Launch (SBListener &listener,
388 const char *stdin_path,
389 const char *stdout_path,
390 const char *stderr_path,
391 const char *working_directory,
392 uint32_t launch_flags, // See LaunchFlags
394 lldb::SBError& error);
397 //------------------------------------------------------------------
398 /// Launch a new process with sensible defaults.
401 /// The argument array.
404 /// The environment array.
406 /// @param[in] working_directory
407 /// The working directory to have the child process run in
409 /// Default: listener
410 /// Set to the target's debugger (SBTarget::GetDebugger())
412 /// Default: launch_flags
413 /// Empty launch flags
415 /// Default: stdin_path
416 /// Default: stdout_path
417 /// Default: stderr_path
418 /// A pseudo terminal will be used.
421 /// A process object for the newly created process.
422 //------------------------------------------------------------------
424 LaunchSimple (const char **argv,
426 const char *working_directory);
429 Launch (SBLaunchInfo &launch_info, SBError& error);
432 LoadCore (const char *core_file);
435 Attach (SBAttachInfo &attach_info, SBError& error);
437 //------------------------------------------------------------------
438 /// Attach to process with pid.
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 process ID to attach to.
450 /// An error explaining what went wrong if attach fails.
453 /// A process object for the attached process.
454 //------------------------------------------------------------------
456 AttachToProcessWithID (SBListener &listener,
458 lldb::SBError& error);
460 #if defined(__APPLE__)
461 // We need to keep this around for a build or two since Xcode links
462 // to the 32 bit version of this function. We will take it out soon.
464 AttachToProcessWithID (SBListener &listener,
465 ::pid_t pid, // 32 bit int process ID
466 lldb::SBError& error); // DEPRECATED
468 //------------------------------------------------------------------
469 /// Attach to process with name.
471 /// @param[in] listener
472 /// An optional listener that will receive all process events.
473 /// If \a listener is valid then \a listener will listen to all
474 /// process events. If not valid, then this target's debugger
475 /// (SBTarget::GetDebugger()) will listen to all process events.
478 /// Basename of process to attach to.
480 /// @param[in] wait_for
481 /// If true wait for a new instance of 'name' to be launched.
484 /// An error explaining what went wrong if attach fails.
487 /// A process object for the attached process.
488 //------------------------------------------------------------------
490 AttachToProcessWithName (SBListener &listener,
493 lldb::SBError& error);
495 //------------------------------------------------------------------
496 /// Connect to a remote debug server with url.
498 /// @param[in] listener
499 /// An optional listener that will receive all process events.
500 /// If \a listener is valid then \a listener will listen to all
501 /// process events. If not valid, then this target's debugger
502 /// (SBTarget::GetDebugger()) will listen to all process events.
505 /// The url to connect to, e.g., 'connect://localhost:12345'.
507 /// @param[in] plugin_name
508 /// The plugin name to be used; can be NULL.
511 /// An error explaining what went wrong if the connect fails.
514 /// A process object for the connected process.
515 //------------------------------------------------------------------
517 ConnectRemote (SBListener &listener,
519 const char *plugin_name,
526 AddModule (lldb::SBModule &module);
529 AddModule (const char *path,
534 AddModule (const char *path,
536 const char *uuid_cstr,
537 const char *symfile);
540 AddModule (const SBModuleSpec &module_spec);
543 GetNumModules () const;
546 GetModuleAtIndex (uint32_t idx);
549 RemoveModule (lldb::SBModule module);
555 FindModule (const lldb::SBFileSpec &file_spec);
561 GetAddressByteSize();
566 //------------------------------------------------------------------
567 /// Set the base load address for a module section.
569 /// @param[in] section
570 /// The section whose base load address will be set within this
573 /// @param[in] section_base_addr
574 /// The base address for the section.
577 /// An error to indicate success, fail, and any reason for
579 //------------------------------------------------------------------
581 SetSectionLoadAddress (lldb::SBSection section,
582 lldb::addr_t section_base_addr);
584 //------------------------------------------------------------------
585 /// Clear the base load address for a module section.
587 /// @param[in] section
588 /// The section whose base load address will be cleared within
592 /// An error to indicate success, fail, and any reason for
594 //------------------------------------------------------------------
596 ClearSectionLoadAddress (lldb::SBSection section);
598 //------------------------------------------------------------------
599 /// Slide all file addresses for all module sections so that \a module
600 /// appears to loaded at these slide addresses.
602 /// When you need all sections within a module to be loaded at a
603 /// rigid slide from the addresses found in the module object file,
604 /// this function will allow you to easily and quickly slide all
607 /// @param[in] module
608 /// The module to load.
610 /// @param[in] sections_offset
611 /// An offset that will be applied to all section file addresses
612 /// (the virtual addresses found in the object file itself).
615 /// An error to indicate success, fail, and any reason for
617 //------------------------------------------------------------------
619 SetModuleLoadAddress (lldb::SBModule module,
620 int64_t sections_offset);
623 //------------------------------------------------------------------
624 /// Clear the section base load addresses for all sections in a module.
626 /// @param[in] module
627 /// The module to unload.
630 /// An error to indicate success, fail, and any reason for
632 //------------------------------------------------------------------
634 ClearModuleLoadAddress (lldb::SBModule module);
636 //------------------------------------------------------------------
637 /// Find functions by name.
640 /// The name of the function we are looking for.
642 /// @param[in] name_type_mask
643 /// A logical OR of one or more FunctionNameType enum bits that
644 /// indicate what kind of names should be used when doing the
645 /// lookup. Bits include fully qualified names, base names,
646 /// C++ methods, or ObjC selectors.
647 /// See FunctionNameType for more details.
650 /// A lldb::SBSymbolContextList that gets filled in with all of
651 /// the symbol contexts for all the matches.
652 //------------------------------------------------------------------
653 lldb::SBSymbolContextList
654 FindFunctions (const char *name,
655 uint32_t name_type_mask = lldb::eFunctionNameTypeAny);
657 //------------------------------------------------------------------
658 /// Find global and static variables by name.
661 /// The name of the global or static variable we are looking
664 /// @param[in] max_matches
665 /// Allow the number of matches to be limited to \a max_matches.
668 /// A list of matched variables in an SBValueList.
669 //------------------------------------------------------------------
671 FindGlobalVariables (const char *name,
672 uint32_t max_matches);
674 //------------------------------------------------------------------
675 /// Find the first global (or static) variable by name.
678 /// The name of the global or static variable we are looking
682 /// An SBValue that gets filled in with the found variable (if any).
683 //------------------------------------------------------------------
685 FindFirstGlobalVariable (const char* name);
690 //------------------------------------------------------------------
691 /// Resolve a current load address into a section offset address.
693 /// @param[in] vm_addr
694 /// A virtual address from the current process state that is to
695 /// be translated into a section offset address.
698 /// An SBAddress which will be valid if \a vm_addr was
699 /// successfully resolved into a section offset address, or an
700 /// invalid SBAddress if \a vm_addr doesn't resolve to a section
702 //------------------------------------------------------------------
704 ResolveLoadAddress (lldb::addr_t vm_addr);
706 //------------------------------------------------------------------
707 /// Resolve a current load address into a section offset address
708 /// using the process stop ID to identify a time in the past.
710 /// @param[in] stop_id
711 /// Each time a process stops, the process stop ID integer gets
712 /// incremented. These stop IDs are used to identify past times
713 /// and can be used in history objects as a cheap way to store
714 /// the time at which the sample was taken. Specifying
715 /// UINT32_MAX will always resolve the address using the
716 /// currently loaded sections.
718 /// @param[in] vm_addr
719 /// A virtual address from the current process state that is to
720 /// be translated into a section offset address.
723 /// An SBAddress which will be valid if \a vm_addr was
724 /// successfully resolved into a section offset address, or an
725 /// invalid SBAddress if \a vm_addr doesn't resolve to a section
727 //------------------------------------------------------------------
729 ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr);
732 ResolveSymbolContextForAddress (const SBAddress& addr,
733 uint32_t resolve_scope);
736 BreakpointCreateByLocation (const char *file, uint32_t line);
739 BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line);
742 BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL);
744 // This version uses name_type_mask = eFunctionNameTypeAuto
746 BreakpointCreateByName (const char *symbol_name,
747 const SBFileSpecList &module_list,
748 const SBFileSpecList &comp_unit_list);
751 BreakpointCreateByName (const char *symbol_name,
752 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
753 const SBFileSpecList &module_list,
754 const SBFileSpecList &comp_unit_list);
757 BreakpointCreateByNames (const char *symbol_name[],
759 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
760 const SBFileSpecList &module_list,
761 const SBFileSpecList &comp_unit_list);
764 BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL);
767 BreakpointCreateByRegex (const char *symbol_name_regex,
768 const SBFileSpecList &module_list,
769 const SBFileSpecList &comp_unit_list);
772 BreakpointCreateBySourceRegex (const char *source_regex,
773 const lldb::SBFileSpec &source_file,
774 const char *module_name = NULL);
777 BreakpointCreateBySourceRegex (const char *source_regex,
778 const SBFileSpecList &module_list,
779 const lldb::SBFileSpecList &source_file);
782 BreakpointCreateForException (lldb::LanguageType language,
787 BreakpointCreateByAddress (addr_t address);
790 GetNumBreakpoints () const;
793 GetBreakpointAtIndex (uint32_t idx) const;
796 BreakpointDelete (break_id_t break_id);
799 FindBreakpointByID (break_id_t break_id);
802 EnableAllBreakpoints ();
805 DisableAllBreakpoints ();
808 DeleteAllBreakpoints ();
811 GetNumWatchpoints () const;
814 GetWatchpointAtIndex (uint32_t idx) const;
817 DeleteWatchpoint (lldb::watch_id_t watch_id);
820 FindWatchpointByID (lldb::watch_id_t watch_id);
823 WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError& error);
826 EnableAllWatchpoints ();
829 DisableAllWatchpoints ();
832 DeleteAllWatchpoints ();
835 GetBroadcaster () const;
838 FindFirstType (const char* type);
841 FindTypes (const char* type);
844 GetBasicType(lldb::BasicType type);
847 CreateValueFromAddress (const char *name, lldb::SBAddress addr, lldb::SBType type);
852 lldb::SBInstructionList
853 ReadInstructions (lldb::SBAddress base_addr, uint32_t count);
855 lldb::SBInstructionList
856 ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string);
858 lldb::SBInstructionList
859 GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size);
861 // The "WithFlavor" is necessary to keep SWIG from getting confused about overloaded arguments when
862 // using the buf + size -> Python Object magic.
864 lldb::SBInstructionList
865 GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size);
867 lldb::SBInstructionList
868 GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size);
870 lldb::SBInstructionList
871 GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size);
873 lldb::SBSymbolContextList
874 FindSymbols (const char *name,
875 lldb::SymbolType type = eSymbolTypeAny);
878 operator == (const lldb::SBTarget &rhs) const;
881 operator != (const lldb::SBTarget &rhs) const;
884 GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level);
887 EvaluateExpression (const char *expr, const SBExpressionOptions &options);
890 GetStackRedZoneSize();
893 friend class SBAddress;
894 friend class SBBlock;
895 friend class SBDebugger;
896 friend class SBFunction;
897 friend class SBInstruction;
898 friend class SBModule;
899 friend class SBProcess;
900 friend class SBSection;
901 friend class SBSourceManager;
902 friend class SBSymbol;
903 friend class SBValue;
905 //------------------------------------------------------------------
906 // Constructors are private, use static Target::Create function to
907 // create an instance of this class.
908 //------------------------------------------------------------------
914 SetSP (const lldb::TargetSP& target_sp);
918 //------------------------------------------------------------------
920 //------------------------------------------------------------------
922 lldb::TargetSP m_opaque_sp;
927 #endif // LLDB_SBTarget_h_