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_
15 // Other libraries and framework includes
17 #include "lldb/API/SBDefines.h"
18 #include "lldb/API/SBAddress.h"
19 #include "lldb/API/SBAttachInfo.h"
20 #include "lldb/API/SBBroadcaster.h"
21 #include "lldb/API/SBFileSpec.h"
22 #include "lldb/API/SBFileSpecList.h"
23 #include "lldb/API/SBLaunchInfo.h"
24 #include "lldb/API/SBSymbolContextList.h"
25 #include "lldb/API/SBType.h"
26 #include "lldb/API/SBValue.h"
27 #include "lldb/API/SBWatchpoint.h"
33 class LLDB_API SBTarget
36 //------------------------------------------------------------------
38 //------------------------------------------------------------------
41 eBroadcastBitBreakpointChanged = (1 << 0),
42 eBroadcastBitModulesLoaded = (1 << 1),
43 eBroadcastBitModulesUnloaded = (1 << 2),
44 eBroadcastBitWatchpointChanged = (1 << 3),
45 eBroadcastBitSymbolsLoaded = (1 << 4)
48 //------------------------------------------------------------------
50 //------------------------------------------------------------------
53 SBTarget (const lldb::SBTarget& rhs);
55 SBTarget (const lldb::TargetSP& target_sp);
57 //------------------------------------------------------------------
59 //------------------------------------------------------------------
63 operator = (const lldb::SBTarget& rhs);
69 EventIsTargetEvent (const lldb::SBEvent &event);
72 GetTargetFromEvent (const lldb::SBEvent &event);
75 GetNumModulesFromEvent (const lldb::SBEvent &event);
78 GetModuleAtIndexFromEvent (const uint32_t idx, const lldb::SBEvent &event);
81 GetBroadcasterClassName ();
86 //------------------------------------------------------------------
87 /// Return the platform object associated with the target.
89 /// After return, the platform object should be checked for
93 /// A platform object.
94 //------------------------------------------------------------------
98 //------------------------------------------------------------------
99 /// Install any binaries that need to be installed.
101 /// This function does nothing when debugging on the host system.
102 /// When connected to remote platforms, the target's main executable
103 /// and any modules that have their remote install path set will be
104 /// installed on the remote platform. If the main executable doesn't
105 /// have an install location set, it will be installed in the remote
106 /// platform's working directory.
109 /// An error describing anything that went wrong during
111 //------------------------------------------------------------------
115 //------------------------------------------------------------------
116 /// Launch a new process.
118 /// Launch a new process by spawning a new process using the
119 /// target object's executable module's file as the file to launch.
120 /// Arguments are given in \a argv, and the environment variables
121 /// are in \a envp. Standard input and output files can be
122 /// optionally re-directed to \a stdin_path, \a stdout_path, and
125 /// @param[in] listener
126 /// An optional listener that will receive all process events.
127 /// If \a listener is valid then \a listener will listen to all
128 /// process events. If not valid, then this target's debugger
129 /// (SBTarget::GetDebugger()) will listen to all process events.
132 /// The argument array.
135 /// The environment array.
137 /// @param[in] launch_flags
138 /// Flags to modify the launch (@see lldb::LaunchFlags)
140 /// @param[in] stdin_path
141 /// The path to use when re-directing the STDIN of the new
142 /// process. If all stdXX_path arguments are nullptr, a pseudo
143 /// terminal will be used.
145 /// @param[in] stdout_path
146 /// The path to use when re-directing the STDOUT of the new
147 /// process. If all stdXX_path arguments are nullptr, a pseudo
148 /// terminal will be used.
150 /// @param[in] stderr_path
151 /// The path to use when re-directing the STDERR of the new
152 /// process. If all stdXX_path arguments are nullptr, a pseudo
153 /// terminal will be used.
155 /// @param[in] working_directory
156 /// The working directory to have the child process run in
158 /// @param[in] launch_flags
159 /// Some launch options specified by logical OR'ing
160 /// lldb::LaunchFlags enumeration values together.
162 /// @param[in] stop_at_entry
163 /// If false do not stop the inferior at the entry point.
165 /// @param[out] error
166 /// An error object. Contains the reason if there is some failure.
169 /// A process object for the newly created process.
170 //------------------------------------------------------------------
172 Launch (SBListener &listener,
175 const char *stdin_path,
176 const char *stdout_path,
177 const char *stderr_path,
178 const char *working_directory,
179 uint32_t launch_flags, // See LaunchFlags
181 lldb::SBError& error);
184 LoadCore (const char *core_file);
186 //------------------------------------------------------------------
187 /// Launch a new process with sensible defaults.
190 /// The argument array.
193 /// The environment array.
195 /// @param[in] working_directory
196 /// The working directory to have the child process run in
198 /// Default: listener
199 /// Set to the target's debugger (SBTarget::GetDebugger())
201 /// Default: launch_flags
202 /// Empty launch flags
204 /// Default: stdin_path
205 /// Default: stdout_path
206 /// Default: stderr_path
207 /// A pseudo terminal will be used.
210 /// A process object for the newly created process.
211 //------------------------------------------------------------------
213 LaunchSimple (const char **argv,
215 const char *working_directory);
218 Launch (SBLaunchInfo &launch_info, SBError& error);
221 Attach (SBAttachInfo &attach_info, SBError& error);
223 //------------------------------------------------------------------
224 /// Attach to process with pid.
226 /// @param[in] listener
227 /// An optional listener that will receive all process events.
228 /// If \a listener is valid then \a listener will listen to all
229 /// process events. If not valid, then this target's debugger
230 /// (SBTarget::GetDebugger()) will listen to all process events.
233 /// The process ID to attach to.
235 /// @param[out] error
236 /// An error explaining what went wrong if attach fails.
239 /// A process object for the attached process.
240 //------------------------------------------------------------------
242 AttachToProcessWithID (SBListener &listener,
244 lldb::SBError& error);
246 #if defined(__APPLE__)
247 // We need to keep this around for a build or two since Xcode links
248 // to the 32 bit version of this function. We will take it out soon.
250 AttachToProcessWithID (SBListener &listener,
251 ::pid_t pid, // 32 bit int process ID
252 lldb::SBError& error); // DEPRECATED
255 //------------------------------------------------------------------
256 /// Attach to process with name.
258 /// @param[in] listener
259 /// An optional listener that will receive all process events.
260 /// If \a listener is valid then \a listener will listen to all
261 /// process events. If not valid, then this target's debugger
262 /// (SBTarget::GetDebugger()) will listen to all process events.
265 /// Basename of process to attach to.
267 /// @param[in] wait_for
268 /// If true wait for a new instance of 'name' to be launched.
270 /// @param[out] error
271 /// An error explaining what went wrong if attach fails.
274 /// A process object for the attached process.
275 //------------------------------------------------------------------
277 AttachToProcessWithName (SBListener &listener,
280 lldb::SBError& error);
282 //------------------------------------------------------------------
283 /// Connect to a remote debug server with url.
285 /// @param[in] listener
286 /// An optional listener that will receive all process events.
287 /// If \a listener is valid then \a listener will listen to all
288 /// process events. If not valid, then this target's debugger
289 /// (SBTarget::GetDebugger()) will listen to all process events.
292 /// The url to connect to, e.g., 'connect://localhost:12345'.
294 /// @param[in] plugin_name
295 /// The plugin name to be used; can be nullptr.
297 /// @param[out] error
298 /// An error explaining what went wrong if the connect fails.
301 /// A process object for the connected process.
302 //------------------------------------------------------------------
304 ConnectRemote (SBListener &listener,
306 const char *plugin_name,
313 AddModule (lldb::SBModule &module);
316 AddModule (const char *path,
321 AddModule (const char *path,
323 const char *uuid_cstr,
324 const char *symfile);
327 AddModule (const SBModuleSpec &module_spec);
330 GetNumModules () const;
333 GetModuleAtIndex (uint32_t idx);
336 RemoveModule (lldb::SBModule module);
342 FindModule (const lldb::SBFileSpec &file_spec);
348 GetAddressByteSize();
353 //------------------------------------------------------------------
354 /// Architecture data byte width accessor
357 /// The size in 8-bit (host) bytes of a minimum addressable
358 /// unit from the Architecture's data bus
359 //------------------------------------------------------------------
363 //------------------------------------------------------------------
364 /// Architecture code byte width accessor
367 /// The size in 8-bit (host) bytes of a minimum addressable
368 /// unit from the Architecture's code bus
369 //------------------------------------------------------------------
373 //------------------------------------------------------------------
374 /// Set the base load address for a module section.
376 /// @param[in] section
377 /// The section whose base load address will be set within this
380 /// @param[in] section_base_addr
381 /// The base address for the section.
384 /// An error to indicate success, fail, and any reason for
386 //------------------------------------------------------------------
388 SetSectionLoadAddress (lldb::SBSection section,
389 lldb::addr_t section_base_addr);
391 //------------------------------------------------------------------
392 /// Clear the base load address for a module section.
394 /// @param[in] section
395 /// The section whose base load address will be cleared within
399 /// An error to indicate success, fail, and any reason for
401 //------------------------------------------------------------------
403 ClearSectionLoadAddress (lldb::SBSection section);
405 //------------------------------------------------------------------
406 /// Slide all file addresses for all module sections so that \a module
407 /// appears to loaded at these slide addresses.
409 /// When you need all sections within a module to be loaded at a
410 /// rigid slide from the addresses found in the module object file,
411 /// this function will allow you to easily and quickly slide all
414 /// @param[in] module
415 /// The module to load.
417 /// @param[in] sections_offset
418 /// An offset that will be applied to all section file addresses
419 /// (the virtual addresses found in the object file itself).
422 /// An error to indicate success, fail, and any reason for
424 //------------------------------------------------------------------
426 SetModuleLoadAddress (lldb::SBModule module,
427 int64_t sections_offset);
429 //------------------------------------------------------------------
430 /// Clear the section base load addresses for all sections in a module.
432 /// @param[in] module
433 /// The module to unload.
436 /// An error to indicate success, fail, and any reason for
438 //------------------------------------------------------------------
440 ClearModuleLoadAddress (lldb::SBModule module);
442 //------------------------------------------------------------------
443 /// Find functions by name.
446 /// The name of the function we are looking for.
448 /// @param[in] name_type_mask
449 /// A logical OR of one or more FunctionNameType enum bits that
450 /// indicate what kind of names should be used when doing the
451 /// lookup. Bits include fully qualified names, base names,
452 /// C++ methods, or ObjC selectors.
453 /// See FunctionNameType for more details.
456 /// A lldb::SBSymbolContextList that gets filled in with all of
457 /// the symbol contexts for all the matches.
458 //------------------------------------------------------------------
459 lldb::SBSymbolContextList
460 FindFunctions (const char *name,
461 uint32_t name_type_mask = lldb::eFunctionNameTypeAny);
463 //------------------------------------------------------------------
464 /// Find global and static variables by name.
467 /// The name of the global or static variable we are looking
470 /// @param[in] max_matches
471 /// Allow the number of matches to be limited to \a max_matches.
474 /// A list of matched variables in an SBValueList.
475 //------------------------------------------------------------------
477 FindGlobalVariables (const char *name,
478 uint32_t max_matches);
480 //------------------------------------------------------------------
481 /// Find the first global (or static) variable by name.
484 /// The name of the global or static variable we are looking
488 /// An SBValue that gets filled in with the found variable (if any).
489 //------------------------------------------------------------------
491 FindFirstGlobalVariable (const char* name);
493 //------------------------------------------------------------------
494 /// Find global and static variables by pattern.
497 /// The pattern to search for global or static variables
499 /// @param[in] max_matches
500 /// Allow the number of matches to be limited to \a max_matches.
502 /// @param[in] matchtype
503 /// The match type to use.
506 /// A list of matched variables in an SBValueList.
507 //------------------------------------------------------------------
509 FindGlobalVariables(const char *name,
510 uint32_t max_matches,
511 MatchType matchtype);
513 //------------------------------------------------------------------
514 /// Find global functions by their name with pattern matching.
517 /// The pattern to search for global or static variables
519 /// @param[in] max_matches
520 /// Allow the number of matches to be limited to \a max_matches.
522 /// @param[in] matchtype
523 /// The match type to use.
526 /// A list of matched variables in an SBValueList.
527 //------------------------------------------------------------------
528 lldb::SBSymbolContextList
529 FindGlobalFunctions(const char *name,
530 uint32_t max_matches,
531 MatchType matchtype);
536 //------------------------------------------------------------------
537 /// Resolve a current file address into a section offset address.
539 /// @param[in] file_addr
542 /// An SBAddress which will be valid if...
543 //------------------------------------------------------------------
545 ResolveFileAddress (lldb::addr_t file_addr);
547 //------------------------------------------------------------------
548 /// Resolve a current load address into a section offset address.
550 /// @param[in] vm_addr
551 /// A virtual address from the current process state that is to
552 /// be translated into a section offset address.
555 /// An SBAddress which will be valid if \a vm_addr was
556 /// successfully resolved into a section offset address, or an
557 /// invalid SBAddress if \a vm_addr doesn't resolve to a section
559 //------------------------------------------------------------------
561 ResolveLoadAddress (lldb::addr_t vm_addr);
563 //------------------------------------------------------------------
564 /// Resolve a current load address into a section offset address
565 /// using the process stop ID to identify a time in the past.
567 /// @param[in] stop_id
568 /// Each time a process stops, the process stop ID integer gets
569 /// incremented. These stop IDs are used to identify past times
570 /// and can be used in history objects as a cheap way to store
571 /// the time at which the sample was taken. Specifying
572 /// UINT32_MAX will always resolve the address using the
573 /// currently loaded sections.
575 /// @param[in] vm_addr
576 /// A virtual address from the current process state that is to
577 /// be translated into a section offset address.
580 /// An SBAddress which will be valid if \a vm_addr was
581 /// successfully resolved into a section offset address, or an
582 /// invalid SBAddress if \a vm_addr doesn't resolve to a section
584 //------------------------------------------------------------------
586 ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr);
589 ResolveSymbolContextForAddress (const SBAddress& addr,
590 uint32_t resolve_scope);
592 //------------------------------------------------------------------
593 /// Read target memory. If a target process is running then memory
594 /// is read from here. Otherwise the memory is read from the object
595 /// files. For a target whose bytes are sized as a multiple of host
596 /// bytes, the data read back will preserve the target's byte order.
599 /// A target address to read from.
602 /// The buffer to read memory into.
605 /// The maximum number of host bytes to read in the buffer passed
608 /// @param[out] error
609 /// Error information is written here if the memory read fails.
612 /// The amount of data read in host bytes.
613 //------------------------------------------------------------------
615 ReadMemory (const SBAddress addr, void *buf, size_t size, lldb::SBError &error);
618 BreakpointCreateByLocation (const char *file, uint32_t line);
621 BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line);
624 BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line, lldb::addr_t offset);
627 BreakpointCreateByName(const char *symbol_name, const char *module_name = nullptr);
629 // This version uses name_type_mask = eFunctionNameTypeAuto
631 BreakpointCreateByName (const char *symbol_name,
632 const SBFileSpecList &module_list,
633 const SBFileSpecList &comp_unit_list);
636 BreakpointCreateByName (const char *symbol_name,
637 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
638 const SBFileSpecList &module_list,
639 const SBFileSpecList &comp_unit_list);
642 BreakpointCreateByName (const char *symbol_name,
643 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
644 lldb::LanguageType symbol_language,
645 const SBFileSpecList &module_list,
646 const SBFileSpecList &comp_unit_list);
649 BreakpointCreateByNames (const char *symbol_name[],
651 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
652 const SBFileSpecList &module_list,
653 const SBFileSpecList &comp_unit_list);
656 BreakpointCreateByNames (const char *symbol_name[],
658 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
659 lldb::LanguageType symbol_language,
660 const SBFileSpecList &module_list,
661 const SBFileSpecList &comp_unit_list);
664 BreakpointCreateByNames (const char *symbol_name[],
666 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
667 lldb::LanguageType symbol_language,
669 const SBFileSpecList &module_list,
670 const SBFileSpecList &comp_unit_list);
673 BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = nullptr);
676 BreakpointCreateByRegex (const char *symbol_name_regex,
677 const SBFileSpecList &module_list,
678 const SBFileSpecList &comp_unit_list);
681 BreakpointCreateByRegex (const char *symbol_name_regex,
682 lldb::LanguageType symbol_language,
683 const SBFileSpecList &module_list,
684 const SBFileSpecList &comp_unit_list);
687 BreakpointCreateBySourceRegex(const char *source_regex,
688 const SBFileSpec &source_file,
689 const char *module_name = nullptr);
692 BreakpointCreateBySourceRegex (const char *source_regex,
693 const SBFileSpecList &module_list,
694 const SBFileSpecList &source_file);
697 BreakpointCreateBySourceRegex (const char *source_regex,
698 const SBFileSpecList &module_list,
699 const SBFileSpecList &source_file,
700 const SBStringList &func_names);
703 BreakpointCreateForException (lldb::LanguageType language,
708 BreakpointCreateByAddress (addr_t address);
711 BreakpointCreateBySBAddress (SBAddress &address);
714 GetNumBreakpoints () const;
717 GetBreakpointAtIndex (uint32_t idx) const;
720 BreakpointDelete (break_id_t break_id);
723 FindBreakpointByID (break_id_t break_id);
726 EnableAllBreakpoints ();
729 DisableAllBreakpoints ();
732 DeleteAllBreakpoints ();
735 GetNumWatchpoints () const;
738 GetWatchpointAtIndex (uint32_t idx) const;
741 DeleteWatchpoint (lldb::watch_id_t watch_id);
744 FindWatchpointByID (lldb::watch_id_t watch_id);
747 WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError& error);
750 EnableAllWatchpoints ();
753 DisableAllWatchpoints ();
756 DeleteAllWatchpoints ();
759 GetBroadcaster () const;
762 FindFirstType (const char* type);
765 FindTypes (const char* type);
768 GetBasicType(lldb::BasicType type);
771 CreateValueFromAddress (const char *name, lldb::SBAddress addr, lldb::SBType type);
774 CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type);
777 CreateValueFromExpression (const char *name, const char* expr);
782 lldb::SBInstructionList
783 ReadInstructions (lldb::SBAddress base_addr, uint32_t count);
785 lldb::SBInstructionList
786 ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string);
788 lldb::SBInstructionList
789 GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size);
791 // The "WithFlavor" is necessary to keep SWIG from getting confused about overloaded arguments when
792 // using the buf + size -> Python Object magic.
794 lldb::SBInstructionList
795 GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size);
797 lldb::SBInstructionList
798 GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size);
800 lldb::SBInstructionList
801 GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size);
803 lldb::SBSymbolContextList
804 FindSymbols (const char *name,
805 lldb::SymbolType type = eSymbolTypeAny);
808 operator == (const lldb::SBTarget &rhs) const;
811 operator != (const lldb::SBTarget &rhs) const;
814 GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level);
817 EvaluateExpression (const char *expr);
820 EvaluateExpression (const char *expr, const SBExpressionOptions &options);
823 GetStackRedZoneSize();
826 GetLaunchInfo () const;
829 SetLaunchInfo (const lldb::SBLaunchInfo &launch_info);
832 friend class SBAddress;
833 friend class SBBlock;
834 friend class SBDebugger;
835 friend class SBExecutionContext;
836 friend class SBFunction;
837 friend class SBInstruction;
838 friend class SBModule;
839 friend class SBProcess;
840 friend class SBSection;
841 friend class SBSourceManager;
842 friend class SBSymbol;
843 friend class SBValue;
845 //------------------------------------------------------------------
846 // Constructors are private, use static Target::Create function to
847 // create an instance of this class.
848 //------------------------------------------------------------------
854 SetSP (const lldb::TargetSP& target_sp);
857 lldb::TargetSP m_opaque_sp;
862 #endif // LLDB_SBTarget_h_