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/SBAttachInfo.h"
16 #include "lldb/API/SBBroadcaster.h"
17 #include "lldb/API/SBFileSpec.h"
18 #include "lldb/API/SBFileSpecList.h"
19 #include "lldb/API/SBLaunchInfo.h"
20 #include "lldb/API/SBSymbolContextList.h"
21 #include "lldb/API/SBType.h"
22 #include "lldb/API/SBValue.h"
23 #include "lldb/API/SBWatchpoint.h"
29 class LLDB_API SBTarget
32 //------------------------------------------------------------------
34 //------------------------------------------------------------------
37 eBroadcastBitBreakpointChanged = (1 << 0),
38 eBroadcastBitModulesLoaded = (1 << 1),
39 eBroadcastBitModulesUnloaded = (1 << 2),
40 eBroadcastBitWatchpointChanged = (1 << 3),
41 eBroadcastBitSymbolsLoaded = (1 << 4)
44 //------------------------------------------------------------------
46 //------------------------------------------------------------------
49 SBTarget (const lldb::SBTarget& rhs);
51 SBTarget (const lldb::TargetSP& target_sp);
54 operator = (const lldb::SBTarget& rhs);
56 //------------------------------------------------------------------
58 //------------------------------------------------------------------
65 EventIsTargetEvent (const lldb::SBEvent &event);
68 GetTargetFromEvent (const lldb::SBEvent &event);
71 GetNumModulesFromEvent (const lldb::SBEvent &event);
74 GetModuleAtIndexFromEvent (const uint32_t idx, const lldb::SBEvent &event);
77 GetBroadcasterClassName ();
82 //------------------------------------------------------------------
83 /// Return the platform object associated with the target.
85 /// After return, the platform object should be checked for
89 /// A platform object.
90 //------------------------------------------------------------------
94 //------------------------------------------------------------------
95 /// Install any binaries that need to be installed.
97 /// This function does nothing when debugging on the host system.
98 /// When connected to remote platforms, the target's main executable
99 /// and any modules that have their remote install path set will be
100 /// installed on the remote platform. If the main executable doesn't
101 /// have an install location set, it will be installed in the remote
102 /// platform's working directory.
105 /// An error describing anything that went wrong during
107 //------------------------------------------------------------------
111 //------------------------------------------------------------------
112 /// Launch a new process.
114 /// Launch a new process by spawning a new process using the
115 /// target object's executable module's file as the file to launch.
116 /// Arguments are given in \a argv, and the environment variables
117 /// are in \a envp. Standard input and output files can be
118 /// optionally re-directed to \a stdin_path, \a stdout_path, and
121 /// @param[in] listener
122 /// An optional listener that will receive all process events.
123 /// If \a listener is valid then \a listener will listen to all
124 /// process events. If not valid, then this target's debugger
125 /// (SBTarget::GetDebugger()) will listen to all process events.
128 /// The argument array.
131 /// The environment array.
133 /// @param[in] launch_flags
134 /// Flags to modify the launch (@see lldb::LaunchFlags)
136 /// @param[in] stdin_path
137 /// The path to use when re-directing the STDIN of the new
138 /// process. If all stdXX_path arguments are NULL, a pseudo
139 /// terminal will be used.
141 /// @param[in] stdout_path
142 /// The path to use when re-directing the STDOUT of the new
143 /// process. If all stdXX_path arguments are NULL, a pseudo
144 /// terminal will be used.
146 /// @param[in] stderr_path
147 /// The path to use when re-directing the STDERR of the new
148 /// process. If all stdXX_path arguments are NULL, a pseudo
149 /// terminal will be used.
151 /// @param[in] working_directory
152 /// The working directory to have the child process run in
154 /// @param[in] launch_flags
155 /// Some launch options specified by logical OR'ing
156 /// lldb::LaunchFlags enumeration values together.
158 /// @param[in] stop_at_entry
159 /// If false do not stop the inferior at the entry point.
161 /// @param[out] error
162 /// An error object. Contains the reason if there is some failure.
165 /// A process object for the newly created process.
166 //------------------------------------------------------------------
168 Launch (SBListener &listener,
171 const char *stdin_path,
172 const char *stdout_path,
173 const char *stderr_path,
174 const char *working_directory,
175 uint32_t launch_flags, // See LaunchFlags
177 lldb::SBError& error);
180 //------------------------------------------------------------------
181 /// Launch a new process with sensible defaults.
184 /// The argument array.
187 /// The environment array.
189 /// @param[in] working_directory
190 /// The working directory to have the child process run in
192 /// Default: listener
193 /// Set to the target's debugger (SBTarget::GetDebugger())
195 /// Default: launch_flags
196 /// Empty launch flags
198 /// Default: stdin_path
199 /// Default: stdout_path
200 /// Default: stderr_path
201 /// A pseudo terminal will be used.
204 /// A process object for the newly created process.
205 //------------------------------------------------------------------
207 LaunchSimple (const char **argv,
209 const char *working_directory);
212 Launch (SBLaunchInfo &launch_info, SBError& error);
215 LoadCore (const char *core_file);
218 Attach (SBAttachInfo &attach_info, SBError& error);
220 //------------------------------------------------------------------
221 /// Attach to process with pid.
223 /// @param[in] listener
224 /// An optional listener that will receive all process events.
225 /// If \a listener is valid then \a listener will listen to all
226 /// process events. If not valid, then this target's debugger
227 /// (SBTarget::GetDebugger()) will listen to all process events.
230 /// The process ID to attach to.
232 /// @param[out] error
233 /// An error explaining what went wrong if attach fails.
236 /// A process object for the attached process.
237 //------------------------------------------------------------------
239 AttachToProcessWithID (SBListener &listener,
241 lldb::SBError& error);
243 #if defined(__APPLE__)
244 // We need to keep this around for a build or two since Xcode links
245 // to the 32 bit version of this function. We will take it out soon.
247 AttachToProcessWithID (SBListener &listener,
248 ::pid_t pid, // 32 bit int process ID
249 lldb::SBError& error); // DEPRECATED
251 //------------------------------------------------------------------
252 /// Attach to process with name.
254 /// @param[in] listener
255 /// An optional listener that will receive all process events.
256 /// If \a listener is valid then \a listener will listen to all
257 /// process events. If not valid, then this target's debugger
258 /// (SBTarget::GetDebugger()) will listen to all process events.
261 /// Basename of process to attach to.
263 /// @param[in] wait_for
264 /// If true wait for a new instance of 'name' to be launched.
266 /// @param[out] error
267 /// An error explaining what went wrong if attach fails.
270 /// A process object for the attached process.
271 //------------------------------------------------------------------
273 AttachToProcessWithName (SBListener &listener,
276 lldb::SBError& error);
278 //------------------------------------------------------------------
279 /// Connect to a remote debug server with url.
281 /// @param[in] listener
282 /// An optional listener that will receive all process events.
283 /// If \a listener is valid then \a listener will listen to all
284 /// process events. If not valid, then this target's debugger
285 /// (SBTarget::GetDebugger()) will listen to all process events.
288 /// The url to connect to, e.g., 'connect://localhost:12345'.
290 /// @param[in] plugin_name
291 /// The plugin name to be used; can be NULL.
293 /// @param[out] error
294 /// An error explaining what went wrong if the connect fails.
297 /// A process object for the connected process.
298 //------------------------------------------------------------------
300 ConnectRemote (SBListener &listener,
302 const char *plugin_name,
309 AddModule (lldb::SBModule &module);
312 AddModule (const char *path,
317 AddModule (const char *path,
319 const char *uuid_cstr,
320 const char *symfile);
323 AddModule (const SBModuleSpec &module_spec);
326 GetNumModules () const;
329 GetModuleAtIndex (uint32_t idx);
332 RemoveModule (lldb::SBModule module);
338 FindModule (const lldb::SBFileSpec &file_spec);
344 GetAddressByteSize();
349 //------------------------------------------------------------------
350 /// Architecture data byte width accessor
353 /// The size in 8-bit (host) bytes of a minimum addressable
354 /// unit from the Architecture's data bus
355 //------------------------------------------------------------------
359 //------------------------------------------------------------------
360 /// Architecture code byte width accessor
363 /// The size in 8-bit (host) bytes of a minimum addressable
364 /// unit from the Architecture's code bus
365 //------------------------------------------------------------------
369 //------------------------------------------------------------------
370 /// Set the base load address for a module section.
372 /// @param[in] section
373 /// The section whose base load address will be set within this
376 /// @param[in] section_base_addr
377 /// The base address for the section.
380 /// An error to indicate success, fail, and any reason for
382 //------------------------------------------------------------------
384 SetSectionLoadAddress (lldb::SBSection section,
385 lldb::addr_t section_base_addr);
387 //------------------------------------------------------------------
388 /// Clear the base load address for a module section.
390 /// @param[in] section
391 /// The section whose base load address will be cleared within
395 /// An error to indicate success, fail, and any reason for
397 //------------------------------------------------------------------
399 ClearSectionLoadAddress (lldb::SBSection section);
401 //------------------------------------------------------------------
402 /// Slide all file addresses for all module sections so that \a module
403 /// appears to loaded at these slide addresses.
405 /// When you need all sections within a module to be loaded at a
406 /// rigid slide from the addresses found in the module object file,
407 /// this function will allow you to easily and quickly slide all
410 /// @param[in] module
411 /// The module to load.
413 /// @param[in] sections_offset
414 /// An offset that will be applied to all section file addresses
415 /// (the virtual addresses found in the object file itself).
418 /// An error to indicate success, fail, and any reason for
420 //------------------------------------------------------------------
422 SetModuleLoadAddress (lldb::SBModule module,
423 int64_t sections_offset);
426 //------------------------------------------------------------------
427 /// Clear the section base load addresses for all sections in a module.
429 /// @param[in] module
430 /// The module to unload.
433 /// An error to indicate success, fail, and any reason for
435 //------------------------------------------------------------------
437 ClearModuleLoadAddress (lldb::SBModule module);
439 //------------------------------------------------------------------
440 /// Find functions by name.
443 /// The name of the function we are looking for.
445 /// @param[in] name_type_mask
446 /// A logical OR of one or more FunctionNameType enum bits that
447 /// indicate what kind of names should be used when doing the
448 /// lookup. Bits include fully qualified names, base names,
449 /// C++ methods, or ObjC selectors.
450 /// See FunctionNameType for more details.
453 /// A lldb::SBSymbolContextList that gets filled in with all of
454 /// the symbol contexts for all the matches.
455 //------------------------------------------------------------------
456 lldb::SBSymbolContextList
457 FindFunctions (const char *name,
458 uint32_t name_type_mask = lldb::eFunctionNameTypeAny);
460 //------------------------------------------------------------------
461 /// Find global and static variables by name.
464 /// The name of the global or static variable we are looking
467 /// @param[in] max_matches
468 /// Allow the number of matches to be limited to \a max_matches.
471 /// A list of matched variables in an SBValueList.
472 //------------------------------------------------------------------
474 FindGlobalVariables (const char *name,
475 uint32_t max_matches);
477 //------------------------------------------------------------------
478 /// Find the first global (or static) variable by name.
481 /// The name of the global or static variable we are looking
485 /// An SBValue that gets filled in with the found variable (if any).
486 //------------------------------------------------------------------
488 FindFirstGlobalVariable (const char* name);
490 //------------------------------------------------------------------
491 /// Find global and static variables by pattern.
494 /// The pattern to search for global or static variables
496 /// @param[in] max_matches
497 /// Allow the number of matches to be limited to \a max_matches.
499 /// @param[in] matchtype
500 /// The match type to use.
503 /// A list of matched variables in an SBValueList.
504 //------------------------------------------------------------------
506 FindGlobalVariables(const char *name,
507 uint32_t max_matches,
508 MatchType matchtype);
510 //------------------------------------------------------------------
511 /// Find global functions by their name with pattern matching.
514 /// The pattern to search for global or static variables
516 /// @param[in] max_matches
517 /// Allow the number of matches to be limited to \a max_matches.
519 /// @param[in] matchtype
520 /// The match type to use.
523 /// A list of matched variables in an SBValueList.
524 //------------------------------------------------------------------
525 lldb::SBSymbolContextList
526 FindGlobalFunctions(const char *name,
527 uint32_t max_matches,
528 MatchType matchtype);
533 //------------------------------------------------------------------
534 /// Resolve a current file address into a section offset address.
536 /// @param[in] file_addr
539 /// An SBAddress which will be valid if...
540 //------------------------------------------------------------------
542 ResolveFileAddress (lldb::addr_t file_addr);
544 //------------------------------------------------------------------
545 /// Resolve a current load address into a section offset address.
547 /// @param[in] vm_addr
548 /// A virtual address from the current process state that is to
549 /// be translated into a section offset address.
552 /// An SBAddress which will be valid if \a vm_addr was
553 /// successfully resolved into a section offset address, or an
554 /// invalid SBAddress if \a vm_addr doesn't resolve to a section
556 //------------------------------------------------------------------
558 ResolveLoadAddress (lldb::addr_t vm_addr);
560 //------------------------------------------------------------------
561 /// Resolve a current load address into a section offset address
562 /// using the process stop ID to identify a time in the past.
564 /// @param[in] stop_id
565 /// Each time a process stops, the process stop ID integer gets
566 /// incremented. These stop IDs are used to identify past times
567 /// and can be used in history objects as a cheap way to store
568 /// the time at which the sample was taken. Specifying
569 /// UINT32_MAX will always resolve the address using the
570 /// currently loaded sections.
572 /// @param[in] vm_addr
573 /// A virtual address from the current process state that is to
574 /// be translated into a section offset address.
577 /// An SBAddress which will be valid if \a vm_addr was
578 /// successfully resolved into a section offset address, or an
579 /// invalid SBAddress if \a vm_addr doesn't resolve to a section
581 //------------------------------------------------------------------
583 ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr);
586 ResolveSymbolContextForAddress (const SBAddress& addr,
587 uint32_t resolve_scope);
589 //------------------------------------------------------------------
590 /// Read target memory. If a target process is running then memory
591 /// is read from here. Otherwise the memory is read from the object
592 /// files. For a target whose bytes are sized as a multiple of host
593 /// bytes, the data read back will preserve the target's byte order.
596 /// A target address to read from.
599 /// The buffer to read memory into.
602 /// The maximum number of host bytes to read in the buffer passed
605 /// @param[out] error
606 /// Error information is written here if the memory read fails.
609 /// The amount of data read in host bytes.
610 //------------------------------------------------------------------
612 ReadMemory (const SBAddress addr, void *buf, size_t size, lldb::SBError &error);
615 BreakpointCreateByLocation (const char *file, uint32_t line);
618 BreakpointCreateByLocation (const lldb::SBFileSpec &file_spec, uint32_t line);
621 BreakpointCreateByName (const char *symbol_name, const char *module_name = NULL);
623 // This version uses name_type_mask = eFunctionNameTypeAuto
625 BreakpointCreateByName (const char *symbol_name,
626 const SBFileSpecList &module_list,
627 const SBFileSpecList &comp_unit_list);
630 BreakpointCreateByName (const char *symbol_name,
631 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
632 const SBFileSpecList &module_list,
633 const SBFileSpecList &comp_unit_list);
636 BreakpointCreateByNames (const char *symbol_name[],
638 uint32_t name_type_mask, // Logical OR one or more FunctionNameType enum bits
639 const SBFileSpecList &module_list,
640 const SBFileSpecList &comp_unit_list);
643 BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name = NULL);
646 BreakpointCreateByRegex (const char *symbol_name_regex,
647 const SBFileSpecList &module_list,
648 const SBFileSpecList &comp_unit_list);
651 BreakpointCreateBySourceRegex (const char *source_regex,
652 const SBFileSpec &source_file,
653 const char *module_name = NULL);
656 BreakpointCreateBySourceRegex (const char *source_regex,
657 const SBFileSpecList &module_list,
658 const SBFileSpecList &source_file);
661 BreakpointCreateForException (lldb::LanguageType language,
666 BreakpointCreateByAddress (addr_t address);
669 GetNumBreakpoints () const;
672 GetBreakpointAtIndex (uint32_t idx) const;
675 BreakpointDelete (break_id_t break_id);
678 FindBreakpointByID (break_id_t break_id);
681 EnableAllBreakpoints ();
684 DisableAllBreakpoints ();
687 DeleteAllBreakpoints ();
690 GetNumWatchpoints () const;
693 GetWatchpointAtIndex (uint32_t idx) const;
696 DeleteWatchpoint (lldb::watch_id_t watch_id);
699 FindWatchpointByID (lldb::watch_id_t watch_id);
702 WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError& error);
705 EnableAllWatchpoints ();
708 DisableAllWatchpoints ();
711 DeleteAllWatchpoints ();
714 GetBroadcaster () const;
717 FindFirstType (const char* type);
720 FindTypes (const char* type);
723 GetBasicType(lldb::BasicType type);
726 CreateValueFromAddress (const char *name, lldb::SBAddress addr, lldb::SBType type);
729 CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type);
732 CreateValueFromExpression (const char *name, const char* expr);
737 lldb::SBInstructionList
738 ReadInstructions (lldb::SBAddress base_addr, uint32_t count);
740 lldb::SBInstructionList
741 ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string);
743 lldb::SBInstructionList
744 GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size);
746 // The "WithFlavor" is necessary to keep SWIG from getting confused about overloaded arguments when
747 // using the buf + size -> Python Object magic.
749 lldb::SBInstructionList
750 GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size);
752 lldb::SBInstructionList
753 GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size);
755 lldb::SBInstructionList
756 GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size);
758 lldb::SBSymbolContextList
759 FindSymbols (const char *name,
760 lldb::SymbolType type = eSymbolTypeAny);
763 operator == (const lldb::SBTarget &rhs) const;
766 operator != (const lldb::SBTarget &rhs) const;
769 GetDescription (lldb::SBStream &description, lldb::DescriptionLevel description_level);
772 EvaluateExpression (const char *expr);
775 EvaluateExpression (const char *expr, const SBExpressionOptions &options);
778 GetStackRedZoneSize();
781 GetLaunchInfo () const;
784 SetLaunchInfo (const lldb::SBLaunchInfo &launch_info);
787 friend class SBAddress;
788 friend class SBBlock;
789 friend class SBDebugger;
790 friend class SBExecutionContext;
791 friend class SBFunction;
792 friend class SBInstruction;
793 friend class SBModule;
794 friend class SBProcess;
795 friend class SBSection;
796 friend class SBSourceManager;
797 friend class SBSymbol;
798 friend class SBValue;
800 //------------------------------------------------------------------
801 // Constructors are private, use static Target::Create function to
802 // create an instance of this class.
803 //------------------------------------------------------------------
809 SetSP (const lldb::TargetSP& target_sp);
813 //------------------------------------------------------------------
815 //------------------------------------------------------------------
817 lldb::TargetSP m_opaque_sp;
822 #endif // LLDB_SBTarget_h_