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 /// Install any binaries that need to be installed.
273 /// This function does nothing when debugging on the host system.
274 /// When connected to remote platforms, the target's main executable
275 /// and any modules that have their remote install path set will be
276 /// installed on the remote platform. If the main executable doesn't
277 /// have an install location set, it will be installed in the remote
278 /// platform's working directory.
281 /// An error describing anything that went wrong during
283 //------------------------------------------------------------------
287 //------------------------------------------------------------------
288 /// Launch a new process.
290 /// Launch a new process by spawning a new process using the
291 /// target object's executable module's file as the file to launch.
292 /// Arguments are given in \a argv, and the environment variables
293 /// are in \a envp. Standard input and output files can be
294 /// optionally re-directed to \a stdin_path, \a stdout_path, and
297 /// @param[in] listener
298 /// An optional listener that will receive all process events.
299 /// If \a listener is valid then \a listener will listen to all
300 /// process events. If not valid, then this target's debugger
301 /// (SBTarget::GetDebugger()) will listen to all process events.
304 /// The argument array.
307 /// The environment array.
309 /// @param[in] launch_flags
310 /// Flags to modify the launch (@see lldb::LaunchFlags)
312 /// @param[in] stdin_path
313 /// The path to use when re-directing the STDIN of the new
314 /// process. If all stdXX_path arguments are NULL, a pseudo
315 /// terminal will be used.
317 /// @param[in] stdout_path
318 /// The path to use when re-directing the STDOUT of the new
319 /// process. If all stdXX_path arguments are NULL, a pseudo
320 /// terminal will be used.
322 /// @param[in] stderr_path
323 /// The path to use when re-directing the STDERR of the new
324 /// process. If all stdXX_path arguments are NULL, a pseudo
325 /// terminal will be used.
327 /// @param[in] working_directory
328 /// The working directory to have the child process run in
330 /// @param[in] launch_flags
331 /// Some launch options specified by logical OR'ing
332 /// lldb::LaunchFlags enumeration values together.
334 /// @param[in] stop_at_endtry
335 /// If false do not stop the inferior at the entry point.
338 /// An error object. Contains the reason if there is some failure.
341 /// A process object for the newly created process.
342 //------------------------------------------------------------------
344 Launch (SBListener &listener,
347 const char *stdin_path,
348 const char *stdout_path,
349 const char *stderr_path,
350 const char *working_directory,
351 uint32_t launch_flags, // See LaunchFlags
353 lldb::SBError& error);
356 //------------------------------------------------------------------
357 /// Launch a new process with sensible defaults.
360 /// The argument array.
363 /// The environment array.
365 /// @param[in] working_directory
366 /// The working directory to have the child process run in
368 /// Default: listener
369 /// Set to the target's debugger (SBTarget::GetDebugger())
371 /// Default: launch_flags
372 /// Empty launch flags
374 /// Default: stdin_path
375 /// Default: stdout_path
376 /// Default: stderr_path
377 /// A pseudo terminal will be used.
380 /// A process object for the newly created process.
381 //------------------------------------------------------------------
383 LaunchSimple (const char **argv,
385 const char *working_directory);
388 Launch (SBLaunchInfo &launch_info, SBError& error);
391 LoadCore (const char *core_file);
394 Attach (SBAttachInfo &attach_info, SBError& error);
396 //------------------------------------------------------------------
397 /// Attach to process with pid.
399 /// @param[in] listener
400 /// An optional listener that will receive all process events.
401 /// If \a listener is valid then \a listener will listen to all
402 /// process events. If not valid, then this target's debugger
403 /// (SBTarget::GetDebugger()) will listen to all process events.
406 /// The process ID to attach to.
409 /// An error explaining what went wrong if attach fails.
412 /// A process object for the attached process.
413 //------------------------------------------------------------------
415 AttachToProcessWithID (SBListener &listener,
417 lldb::SBError& error);
419 #if defined(__APPLE__)
420 // We need to keep this around for a build or two since Xcode links
421 // to the 32 bit version of this function. We will take it out soon.
423 AttachToProcessWithID (SBListener &listener,
424 ::pid_t pid, // 32 bit int process ID
425 lldb::SBError& error); // DEPRECATED
427 //------------------------------------------------------------------
428 /// Attach to process with name.
430 /// @param[in] listener
431 /// An optional listener that will receive all process events.
432 /// If \a listener is valid then \a listener will listen to all
433 /// process events. If not valid, then this target's debugger
434 /// (SBTarget::GetDebugger()) will listen to all process events.
437 /// Basename of process to attach to.
439 /// @param[in] wait_for
440 /// If true wait for a new instance of 'name' to be launched.
443 /// An error explaining what went wrong if attach fails.
446 /// A process object for the attached process.
447 //------------------------------------------------------------------
449 AttachToProcessWithName (SBListener &listener,
452 lldb::SBError& error);
454 //------------------------------------------------------------------
455 /// Connect to a remote debug server with url.
457 /// @param[in] listener
458 /// An optional listener that will receive all process events.
459 /// If \a listener is valid then \a listener will listen to all
460 /// process events. If not valid, then this target's debugger
461 /// (SBTarget::GetDebugger()) will listen to all process events.
464 /// The url to connect to, e.g., 'connect://localhost:12345'.
466 /// @param[in] plugin_name
467 /// The plugin name to be used; can be NULL.
470 /// An error explaining what went wrong if the connect fails.
473 /// A process object for the connected process.
474 //------------------------------------------------------------------
476 ConnectRemote (SBListener &listener,
478 const char *plugin_name,
485 AddModule (lldb::SBModule &module);
488 AddModule (const char *path,
493 AddModule (const char *path,
495 const char *uuid_cstr,
496 const char *symfile);
499 AddModule (const SBModuleSpec &module_spec);
502 GetNumModules () const;
505 GetModuleAtIndex (uint32_t idx);
508 RemoveModule (lldb::SBModule module);
514 FindModule (const lldb::SBFileSpec &file_spec);
520 GetAddressByteSize();
525 //------------------------------------------------------------------
526 /// Set the base load address for a module section.
528 /// @param[in] section
529 /// The section whose base load address will be set within this
532 /// @param[in] section_base_addr
533 /// The base address for the section.
536 /// An error to indicate success, fail, and any reason for
538 //------------------------------------------------------------------
540 SetSectionLoadAddress (lldb::SBSection section,
541 lldb::addr_t section_base_addr);
543 //------------------------------------------------------------------
544 /// Clear the base load address for a module section.
546 /// @param[in] section
547 /// The section whose base load address will be cleared within
551 /// An error to indicate success, fail, and any reason for
553 //------------------------------------------------------------------
555 ClearSectionLoadAddress (lldb::SBSection section);
557 //------------------------------------------------------------------
558 /// Slide all file addresses for all module sections so that \a module
559 /// appears to loaded at these slide addresses.
561 /// When you need all sections within a module to be loaded at a
562 /// rigid slide from the addresses found in the module object file,
563 /// this function will allow you to easily and quickly slide all
566 /// @param[in] module
567 /// The module to load.
569 /// @param[in] sections_offset
570 /// An offset that will be applied to all section file addresses
571 /// (the virtual addresses found in the object file itself).
574 /// An error to indicate success, fail, and any reason for
576 //------------------------------------------------------------------
578 SetModuleLoadAddress (lldb::SBModule module,
579 int64_t sections_offset);
582 //------------------------------------------------------------------
583 /// The the section base load addresses for all sections in a module.
585 /// @param[in] module
586 /// The module to unload.
589 /// An error to indicate success, fail, and any reason for
591 //------------------------------------------------------------------
593 ClearModuleLoadAddress (lldb::SBModule module);
595 //------------------------------------------------------------------
596 /// Find functions by name.
599 /// The name of the function we are looking for.
601 /// @param[in] name_type_mask
602 /// A logical OR of one or more FunctionNameType enum bits that
603 /// indicate what kind of names should be used when doing the
604 /// lookup. Bits include fully qualified names, base names,
605 /// C++ methods, or ObjC selectors.
606 /// See FunctionNameType for more details.
609 /// A lldb::SBSymbolContextList that gets filled in with all of
610 /// the symbol contexts for all the matches.
611 //------------------------------------------------------------------
612 lldb::SBSymbolContextList
613 FindFunctions (const char *name,
614 uint32_t name_type_mask = lldb::eFunctionNameTypeAny);
616 //------------------------------------------------------------------
617 /// Find global and static variables by name.
620 /// The name of the global or static variable we are looking
623 /// @param[in] max_matches
624 /// Allow the number of matches to be limited to \a max_matches.
627 /// A list of matched variables in an SBValueList.
628 //------------------------------------------------------------------
630 FindGlobalVariables (const char *name,
631 uint32_t max_matches);
633 //------------------------------------------------------------------
634 /// Find the first global (or static) variable by name.
637 /// The name of the global or static variable we are looking
641 /// An SBValue that gets filled in with the found variable (if any).
642 //------------------------------------------------------------------
644 FindFirstGlobalVariable (const char* name);
649 //------------------------------------------------------------------
650 /// Resolve a current load address into a section offset address.
652 /// @param[in] vm_addr
653 /// A virtual address from the current process state that is to
654 /// be translated into a section offset address.
657 /// An SBAddress which will be valid if \a vm_addr was
658 /// successfully resolved into a section offset address, or an
659 /// invalid SBAddress if \a vm_addr doesn't resolve to a section
661 //------------------------------------------------------------------
663 ResolveLoadAddress (lldb::addr_t vm_addr);
665 //------------------------------------------------------------------
666 /// Resolve a current load address into a section offset address
667 /// using the process stop ID to identify a time in the past.
669 /// @param[in] stop_id
670 /// Each time a process stops, the process stop ID integer gets
671 /// incremented. These stop IDs are used to identify past times
672 /// and can be used in history objects as a cheap way to store
673 /// the time at which the sample was taken. Specifying
674 /// UINT32_MAX will always resolve the address using the
675 /// currently loaded sections.
677 /// @param[in] vm_addr
678 /// A virtual address from the current process state that is to
679 /// be translated into a section offset address.
682 /// An SBAddress which will be valid if \a vm_addr was
683 /// successfully resolved into a section offset address, or an
684 /// invalid SBAddress if \a vm_addr doesn't resolve to a section
686 //------------------------------------------------------------------
688 ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr);
691 ResolveSymbolContextForAddress (const SBAddress& addr,
692 uint32_t resolve_scope);
695 BreakpointCreateByLocation (const char *file, uint32_t line);
698 BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line);
701 BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL);
703 // This version uses name_type_mask = eFunctionNameTypeAuto
705 BreakpointCreateByName (const char *symbol_name,
706 const SBFileSpecList &module_list,
707 const SBFileSpecList &comp_unit_list);
710 BreakpointCreateByName (const char *symbol_name,
711 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
712 const SBFileSpecList &module_list,
713 const SBFileSpecList &comp_unit_list);
716 BreakpointCreateByNames (const char *symbol_name[],
718 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
719 const SBFileSpecList &module_list,
720 const SBFileSpecList &comp_unit_list);
723 BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL);
726 BreakpointCreateByRegex (const char *symbol_name_regex,
727 const SBFileSpecList &module_list,
728 const SBFileSpecList &comp_unit_list);
731 BreakpointCreateBySourceRegex (const char *source_regex,
732 const lldb::SBFileSpec &source_file,
733 const char *module_name = NULL);
736 BreakpointCreateBySourceRegex (const char *source_regex,
737 const SBFileSpecList &module_list,
738 const lldb::SBFileSpecList &source_file);
741 BreakpointCreateForException (lldb::LanguageType language,
746 BreakpointCreateByAddress (addr_t address);
749 GetNumBreakpoints () const;
752 GetBreakpointAtIndex (uint32_t idx) const;
755 BreakpointDelete (break_id_t break_id);
758 FindBreakpointByID (break_id_t break_id);
761 EnableAllBreakpoints ();
764 DisableAllBreakpoints ();
767 DeleteAllBreakpoints ();
770 GetNumWatchpoints () const;
773 GetWatchpointAtIndex (uint32_t idx) const;
776 DeleteWatchpoint (lldb::watch_id_t watch_id);
779 FindWatchpointByID (lldb::watch_id_t watch_id);
782 WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError& error);
785 EnableAllWatchpoints ();
788 DisableAllWatchpoints ();
791 DeleteAllWatchpoints ();
794 GetBroadcaster () const;
797 FindFirstType (const char* type);
800 FindTypes (const char* type);
803 GetBasicType(lldb::BasicType type);
806 CreateValueFromAddress (const char *name, lldb::SBAddress addr, lldb::SBType type);
811 lldb::SBInstructionList
812 ReadInstructions (lldb::SBAddress base_addr, uint32_t count);
814 lldb::SBInstructionList
815 ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string);
817 lldb::SBInstructionList
818 GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size);
820 // The "WithFlavor" is necessary to keep SWIG from getting confused about overloaded arguments when
821 // using the buf + size -> Python Object magic.
823 lldb::SBInstructionList
824 GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size);
826 lldb::SBInstructionList
827 GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size);
829 lldb::SBInstructionList
830 GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size);
832 lldb::SBSymbolContextList
833 FindSymbols (const char *name,
834 lldb::SymbolType type = eSymbolTypeAny);
837 operator == (const lldb::SBTarget &rhs) const;
840 operator != (const lldb::SBTarget &rhs) const;
843 GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level);
846 EvaluateExpression (const char *expr, const SBExpressionOptions &options);
849 GetStackRedZoneSize();
852 friend class SBAddress;
853 friend class SBBlock;
854 friend class SBDebugger;
855 friend class SBFunction;
856 friend class SBInstruction;
857 friend class SBModule;
858 friend class SBProcess;
859 friend class SBSection;
860 friend class SBSourceManager;
861 friend class SBSymbol;
862 friend class SBValue;
864 //------------------------------------------------------------------
865 // Constructors are private, use static Target::Create function to
866 // create an instance of this class.
867 //------------------------------------------------------------------
873 SetSP (const lldb::TargetSP& target_sp);
877 //------------------------------------------------------------------
879 //------------------------------------------------------------------
881 lldb::TargetSP m_opaque_sp;
886 #endif // LLDB_SBTarget_h_