#ifndef liblldb_Target_h_
#define liblldb_Target_h_
#include <list>
#include "lldb/lldb-public.h"
#include "lldb/Breakpoint/BreakpointList.h"
#include "lldb/Breakpoint/BreakpointLocationCollection.h"
#include "lldb/Breakpoint/WatchpointList.h"
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/Broadcaster.h"
#include "lldb/Core/Disassembler.h"
#include "lldb/Core/Event.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/UserSettingsController.h"
#include "lldb/Expression/ClangPersistentVariables.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/OptionValueBoolean.h"
#include "lldb/Interpreter/OptionValueEnumeration.h"
#include "lldb/Interpreter/OptionValueFileSpec.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Target/ABI.h"
#include "lldb/Target/ExecutionContextScope.h"
#include "lldb/Target/PathMappingList.h"
#include "lldb/Target/SectionLoadHistory.h"
namespace lldb_private {
extern OptionEnumValueElement g_dynamic_value_types[];
typedef enum InlineStrategy
{
eInlineBreakpointsNever = 0,
eInlineBreakpointsHeaders,
eInlineBreakpointsAlways
} InlineStrategy;
typedef enum LoadScriptFromSymFile
{
eLoadScriptFromSymFileTrue,
eLoadScriptFromSymFileFalse,
eLoadScriptFromSymFileWarn
} LoadScriptFromSymFile;
class TargetProperties : public Properties
{
public:
TargetProperties(Target *target);
virtual
~TargetProperties();
ArchSpec
GetDefaultArchitecture () const;
void
SetDefaultArchitecture (const ArchSpec& arch);
lldb::DynamicValueType
GetPreferDynamicValue() const;
bool
GetDisableASLR () const;
void
SetDisableASLR (bool b);
bool
GetDisableSTDIO () const;
void
SetDisableSTDIO (bool b);
const char *
GetDisassemblyFlavor() const;
InlineStrategy
GetInlineStrategy () const;
const char *
GetArg0 () const;
void
SetArg0 (const char *arg);
bool
GetRunArguments (Args &args) const;
void
SetRunArguments (const Args &args);
size_t
GetEnvironmentAsArgs (Args &env) const;
bool
GetSkipPrologue() const;
PathMappingList &
GetSourcePathMap () const;
FileSpecList &
GetExecutableSearchPaths ();
FileSpecList &
GetDebugFileSearchPaths ();
bool
GetEnableSyntheticValue () const;
uint32_t
GetMaximumNumberOfChildrenToDisplay() const;
uint32_t
GetMaximumSizeOfStringSummary() const;
uint32_t
GetMaximumMemReadSize () const;
FileSpec
GetStandardInputPath () const;
void
SetStandardInputPath (const char *path);
FileSpec
GetStandardOutputPath () const;
void
SetStandardOutputPath (const char *path);
FileSpec
GetStandardErrorPath () const;
void
SetStandardErrorPath (const char *path);
bool
GetBreakpointsConsultPlatformAvoidList ();
const char *
GetExpressionPrefixContentsAsCString ();
bool
GetUseHexImmediates() const;
bool
GetUseFastStepping() const;
bool
GetDisplayExpressionsInCrashlogs () const;
LoadScriptFromSymFile
GetLoadScriptFromSymbolFile() const;
Disassembler::HexImmediateStyle
GetHexImmediateStyle() const;
MemoryModuleLoadLevel
GetMemoryModuleLoadLevel() const;
};
typedef std::shared_ptr<TargetProperties> TargetPropertiesSP;
class EvaluateExpressionOptions
{
public:
static const uint32_t default_timeout = 500000;
EvaluateExpressionOptions() :
m_execution_policy(eExecutionPolicyOnlyWhenNeeded),
m_language (lldb::eLanguageTypeUnknown),
m_coerce_to_id(false),
m_unwind_on_error(true),
m_ignore_breakpoints (false),
m_keep_in_memory(false),
m_try_others(true),
m_stop_others(true),
m_debug(false),
m_trap_exceptions(true),
m_use_dynamic(lldb::eNoDynamicValues),
m_timeout_usec(default_timeout)
{}
ExecutionPolicy
GetExecutionPolicy () const
{
return m_execution_policy;
}
void
SetExecutionPolicy (ExecutionPolicy policy = eExecutionPolicyAlways)
{
m_execution_policy = policy;
}
lldb::LanguageType
GetLanguage() const
{
return m_language;
}
void
SetLanguage(lldb::LanguageType language)
{
m_language = language;
}
bool
DoesCoerceToId () const
{
return m_coerce_to_id;
}
void
SetCoerceToId (bool coerce = true)
{
m_coerce_to_id = coerce;
}
bool
DoesUnwindOnError () const
{
return m_unwind_on_error;
}
void
SetUnwindOnError (bool unwind = false)
{
m_unwind_on_error = unwind;
}
bool
DoesIgnoreBreakpoints () const
{
return m_ignore_breakpoints;
}
void
SetIgnoreBreakpoints (bool ignore = false)
{
m_ignore_breakpoints = ignore;
}
bool
DoesKeepInMemory () const
{
return m_keep_in_memory;
}
void
SetKeepInMemory (bool keep = true)
{
m_keep_in_memory = keep;
}
lldb::DynamicValueType
GetUseDynamic () const
{
return m_use_dynamic;
}
void
SetUseDynamic (lldb::DynamicValueType dynamic = lldb::eDynamicCanRunTarget)
{
m_use_dynamic = dynamic;
}
uint32_t
GetTimeoutUsec () const
{
return m_timeout_usec;
}
void
SetTimeoutUsec (uint32_t timeout = 0)
{
m_timeout_usec = timeout;
}
bool
GetTryAllThreads () const
{
return m_try_others;
}
void
SetTryAllThreads (bool try_others = true)
{
m_try_others = try_others;
}
bool
GetStopOthers () const
{
return m_stop_others;
}
void
SetStopOthers (bool stop_others = true)
{
m_stop_others = stop_others;
}
bool
GetDebug() const
{
return m_debug;
}
void
SetDebug(bool b)
{
m_debug = b;
}
bool
GetTrapExceptions() const
{
return m_trap_exceptions;
}
void
SetTrapExceptions (bool b)
{
m_trap_exceptions = b;
}
private:
ExecutionPolicy m_execution_policy;
lldb::LanguageType m_language;
bool m_coerce_to_id;
bool m_unwind_on_error;
bool m_ignore_breakpoints;
bool m_keep_in_memory;
bool m_try_others;
bool m_stop_others;
bool m_debug;
bool m_trap_exceptions;
lldb::DynamicValueType m_use_dynamic;
uint32_t m_timeout_usec;
};
class Target :
public std::enable_shared_from_this<Target>,
public TargetProperties,
public Broadcaster,
public ExecutionContextScope,
public ModuleList::Notifier
{
public:
friend class TargetList;
enum
{
eBroadcastBitBreakpointChanged = (1 << 0),
eBroadcastBitModulesLoaded = (1 << 1),
eBroadcastBitModulesUnloaded = (1 << 2),
eBroadcastBitWatchpointChanged = (1 << 3),
eBroadcastBitSymbolsLoaded = (1 << 4)
};
static ConstString &GetStaticBroadcasterClass ();
virtual ConstString &GetBroadcasterClass() const
{
return GetStaticBroadcasterClass();
}
class TargetEventData : public EventData
{
public:
static const ConstString &
GetFlavorString ();
virtual const ConstString &
GetFlavor () const;
TargetEventData (const lldb::TargetSP &new_target_sp);
lldb::TargetSP &
GetTarget()
{
return m_target_sp;
}
virtual
~TargetEventData();
virtual void
Dump (Stream *s) const;
static const lldb::TargetSP
GetTargetFromEvent (const lldb::EventSP &event_sp);
static const TargetEventData *
GetEventDataFromEvent (const Event *event_sp);
private:
lldb::TargetSP m_target_sp;
DISALLOW_COPY_AND_ASSIGN (TargetEventData);
};
static void
SettingsInitialize ();
static void
SettingsTerminate ();
static FileSpecList
GetDefaultExecutableSearchPaths ();
static FileSpecList
GetDefaultDebugFileSearchPaths ();
static ArchSpec
GetDefaultArchitecture ();
static void
SetDefaultArchitecture (const ArchSpec &arch);
lldb::ModuleSP
GetSharedModule (const ModuleSpec &module_spec,
Error *error_ptr = NULL);
static const TargetPropertiesSP &
GetGlobalProperties();
private:
Target (Debugger &debugger,
const ArchSpec &target_arch,
const lldb::PlatformSP &platform_sp);
bool
ProcessIsValid ();
public:
~Target();
Mutex &
GetAPIMutex ()
{
return m_mutex;
}
void
DeleteCurrentProcess ();
void
CleanupProcess ();
void
Dump (Stream *s, lldb::DescriptionLevel description_level);
const lldb::ProcessSP &
CreateProcess (Listener &listener,
const char *plugin_name,
const FileSpec *crash_file);
const lldb::ProcessSP &
GetProcessSP () const;
bool
IsValid()
{
return m_valid;
}
void
Destroy();
Error
Launch (Listener &listener,
ProcessLaunchInfo &launch_info);
BreakpointList &
GetBreakpointList(bool internal = false);
const BreakpointList &
GetBreakpointList(bool internal = false) const;
lldb::BreakpointSP
GetLastCreatedBreakpoint ()
{
return m_last_created_breakpoint;
}
lldb::BreakpointSP
GetBreakpointByID (lldb::break_id_t break_id);
lldb::BreakpointSP
CreateBreakpoint (const FileSpecList *containingModules,
const FileSpec &file,
uint32_t line_no,
LazyBool check_inlines,
LazyBool skip_prologue,
bool internal,
bool request_hardware);
lldb::BreakpointSP
CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
const FileSpecList *source_file_list,
RegularExpression &source_regex,
bool internal,
bool request_hardware);
lldb::BreakpointSP
CreateBreakpoint (lldb::addr_t load_addr,
bool internal,
bool request_hardware);
lldb::BreakpointSP
CreateBreakpoint (Address &addr,
bool internal,
bool request_hardware);
lldb::BreakpointSP
CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
const FileSpecList *containingSourceFiles,
RegularExpression &func_regexp,
LazyBool skip_prologue,
bool internal,
bool request_hardware);
lldb::BreakpointSP
CreateBreakpoint (const FileSpecList *containingModules,
const FileSpecList *containingSourceFiles,
const char *func_name,
uint32_t func_name_type_mask,
LazyBool skip_prologue,
bool internal,
bool request_hardware);
lldb::BreakpointSP
CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal);
lldb::BreakpointSP
CreateBreakpoint (const FileSpecList *containingModules,
const FileSpecList *containingSourceFiles,
const char *func_names[],
size_t num_names,
uint32_t func_name_type_mask,
LazyBool skip_prologue,
bool internal,
bool request_hardware);
lldb::BreakpointSP
CreateBreakpoint (const FileSpecList *containingModules,
const FileSpecList *containingSourceFiles,
const std::vector<std::string> &func_names,
uint32_t func_name_type_mask,
LazyBool skip_prologue,
bool internal,
bool request_hardware);
lldb::BreakpointSP
CreateBreakpoint (lldb::SearchFilterSP &filter_sp,
lldb::BreakpointResolverSP &resolver_sp,
bool internal,
bool request_hardware);
lldb::WatchpointSP
CreateWatchpoint (lldb::addr_t addr,
size_t size,
const ClangASTType *type,
uint32_t kind,
Error &error);
lldb::WatchpointSP
GetLastCreatedWatchpoint ()
{
return m_last_created_watchpoint;
}
WatchpointList &
GetWatchpointList()
{
return m_watchpoint_list;
}
void
RemoveAllBreakpoints (bool internal_also = false);
void
DisableAllBreakpoints (bool internal_also = false);
void
EnableAllBreakpoints (bool internal_also = false);
bool
DisableBreakpointByID (lldb::break_id_t break_id);
bool
EnableBreakpointByID (lldb::break_id_t break_id);
bool
RemoveBreakpointByID (lldb::break_id_t break_id);
bool
RemoveAllWatchpoints (bool end_to_end = true);
bool
DisableAllWatchpoints (bool end_to_end = true);
bool
EnableAllWatchpoints (bool end_to_end = true);
bool
ClearAllWatchpointHitCounts ();
bool
IgnoreAllWatchpoints (uint32_t ignore_count);
bool
DisableWatchpointByID (lldb::watch_id_t watch_id);
bool
EnableWatchpointByID (lldb::watch_id_t watch_id);
bool
RemoveWatchpointByID (lldb::watch_id_t watch_id);
bool
IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count);
lldb::addr_t
GetCallableLoadAddress (lldb::addr_t load_addr, lldb::AddressClass addr_class = lldb::eAddressClassInvalid) const;
lldb::addr_t
GetOpcodeLoadAddress (lldb::addr_t load_addr, lldb::AddressClass addr_class = lldb::eAddressClassInvalid) const;
protected:
virtual void
ModuleAdded (const ModuleList& module_list, const lldb::ModuleSP& module_sp);
virtual void
ModuleRemoved (const ModuleList& module_list, const lldb::ModuleSP& module_sp);
virtual void
ModuleUpdated (const ModuleList& module_list,
const lldb::ModuleSP& old_module_sp,
const lldb::ModuleSP& new_module_sp);
virtual void
WillClearList (const ModuleList& module_list);
public:
void
ModulesDidLoad (ModuleList &module_list);
void
ModulesDidUnload (ModuleList &module_list, bool delete_locations);
void
SymbolsDidLoad (ModuleList &module_list);
void
ClearModules(bool delete_locations);
void
DidExec ();
lldb::ModuleSP
GetExecutableModule ();
Module*
GetExecutableModulePointer ();
void
SetExecutableModule (lldb::ModuleSP& module_sp, bool get_dependent_files);
bool
LoadScriptingResources (std::list<Error>& errors,
Stream* feedback_stream = NULL,
bool continue_on_error = true)
{
return m_images.LoadScriptingResourcesInTarget(this,errors,feedback_stream,continue_on_error);
}
const ModuleList&
GetImages () const
{
return m_images;
}
ModuleList&
GetImages ()
{
return m_images;
}
bool
ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_spec);
bool
ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp);
ArchSpec &
GetArchitecture ()
{
return m_arch;
}
const ArchSpec &
GetArchitecture () const
{
return m_arch;
}
bool
SetArchitecture (const ArchSpec &arch_spec);
Debugger &
GetDebugger ()
{
return m_debugger;
}
size_t
ReadMemoryFromFileCache (const Address& addr,
void *dst,
size_t dst_len,
Error &error);
size_t
ReadMemory (const Address& addr,
bool prefer_file_cache,
void *dst,
size_t dst_len,
Error &error,
lldb::addr_t *load_addr_ptr = NULL);
size_t
ReadCStringFromMemory (const Address& addr, std::string &out_str, Error &error);
size_t
ReadCStringFromMemory (const Address& addr, char *dst, size_t dst_max_len, Error &result_error);
size_t
ReadScalarIntegerFromMemory (const Address& addr,
bool prefer_file_cache,
uint32_t byte_size,
bool is_signed,
Scalar &scalar,
Error &error);
uint64_t
ReadUnsignedIntegerFromMemory (const Address& addr,
bool prefer_file_cache,
size_t integer_byte_size,
uint64_t fail_value,
Error &error);
bool
ReadPointerFromMemory (const Address& addr,
bool prefer_file_cache,
Error &error,
Address &pointer_addr);
SectionLoadList&
GetSectionLoadList()
{
return m_section_load_history.GetCurrentSectionLoadList();
}
static Target *
GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr,
const SymbolContext *sc_ptr);
virtual lldb::TargetSP
CalculateTarget ();
virtual lldb::ProcessSP
CalculateProcess ();
virtual lldb::ThreadSP
CalculateThread ();
virtual lldb::StackFrameSP
CalculateStackFrame ();
virtual void
CalculateExecutionContext (ExecutionContext &exe_ctx);
PathMappingList &
GetImageSearchPathList ();
ClangASTContext *
GetScratchClangASTContext(bool create_on_demand=true);
ClangASTImporter *
GetClangASTImporter();
Error
Install(ProcessLaunchInfo *launch_info);
bool
ResolveLoadAddress (lldb::addr_t load_addr,
Address &so_addr,
uint32_t stop_id = SectionLoadHistory::eStopIDNow);
bool
SetSectionLoadAddress (const lldb::SectionSP §ion,
lldb::addr_t load_addr,
bool warn_multiple = false);
bool
SetSectionUnloaded (const lldb::SectionSP §ion_sp);
bool
SetSectionUnloaded (const lldb::SectionSP §ion_sp, lldb::addr_t load_addr);
void
ClearAllLoadedSections ();
ExecutionResults
EvaluateExpression (const char *expression,
StackFrame *frame,
lldb::ValueObjectSP &result_valobj_sp,
const EvaluateExpressionOptions& options = EvaluateExpressionOptions());
ClangPersistentVariables &
GetPersistentVariables()
{
return m_persistent_variables;
}
class StopHook : public UserID
{
public:
~StopHook ();
StopHook (const StopHook &rhs);
StringList *
GetCommandPointer ()
{
return &m_commands;
}
const StringList &
GetCommands()
{
return m_commands;
}
lldb::TargetSP &
GetTarget()
{
return m_target_sp;
}
void
SetCommands (StringList &in_commands)
{
m_commands = in_commands;
}
void
SetSpecifier (SymbolContextSpecifier *specifier)
{
m_specifier_sp.reset (specifier);
}
SymbolContextSpecifier *
GetSpecifier ()
{
return m_specifier_sp.get();
}
void
SetThreadSpecifier (ThreadSpec *specifier);
ThreadSpec *
GetThreadSpecifier()
{
return m_thread_spec_ap.get();
}
bool
IsActive()
{
return m_active;
}
void
SetIsActive (bool is_active)
{
m_active = is_active;
}
void
GetDescription (Stream *s, lldb::DescriptionLevel level) const;
private:
lldb::TargetSP m_target_sp;
StringList m_commands;
lldb::SymbolContextSpecifierSP m_specifier_sp;
std::unique_ptr<ThreadSpec> m_thread_spec_ap;
bool m_active;
StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid);
friend class Target;
};
typedef std::shared_ptr<StopHook> StopHookSP;
lldb::user_id_t
AddStopHook (StopHookSP &new_hook);
void
RunStopHooks ();
size_t
GetStopHookSize();
bool
SetSuppresStopHooks (bool suppress)
{
bool old_value = m_suppress_stop_hooks;
m_suppress_stop_hooks = suppress;
return old_value;
}
bool
GetSuppressStopHooks ()
{
return m_suppress_stop_hooks;
}
bool
RemoveStopHookByID (lldb::user_id_t uid);
void
RemoveAllStopHooks ();
StopHookSP
GetStopHookByID (lldb::user_id_t uid);
bool
SetStopHookActiveStateByID (lldb::user_id_t uid, bool active_state);
void
SetAllStopHooksActiveState (bool active_state);
size_t GetNumStopHooks () const
{
return m_stop_hooks.size();
}
StopHookSP
GetStopHookAtIndex (size_t index)
{
if (index >= GetNumStopHooks())
return StopHookSP();
StopHookCollection::iterator pos = m_stop_hooks.begin();
while (index > 0)
{
pos++;
index--;
}
return (*pos).second;
}
lldb::PlatformSP
GetPlatform ()
{
return m_platform_sp;
}
void
SetPlatform (const lldb::PlatformSP &platform_sp)
{
m_platform_sp = platform_sp;
}
SourceManager &
GetSourceManager ();
lldb::SearchFilterSP
GetSearchFilterForModule (const FileSpec *containingModule);
lldb::SearchFilterSP
GetSearchFilterForModuleList (const FileSpecList *containingModuleList);
lldb::SearchFilterSP
GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, const FileSpecList *containingSourceFiles);
protected:
Debugger & m_debugger;
lldb::PlatformSP m_platform_sp; Mutex m_mutex; ArchSpec m_arch;
ModuleList m_images; SectionLoadHistory m_section_load_history;
BreakpointList m_breakpoint_list;
BreakpointList m_internal_breakpoint_list;
lldb::BreakpointSP m_last_created_breakpoint;
WatchpointList m_watchpoint_list;
lldb::WatchpointSP m_last_created_watchpoint;
lldb::ProcessSP m_process_sp;
lldb::SearchFilterSP m_search_filter_sp;
PathMappingList m_image_search_paths;
std::unique_ptr<ClangASTContext> m_scratch_ast_context_ap;
std::unique_ptr<ClangASTSource> m_scratch_ast_source_ap;
std::unique_ptr<ClangASTImporter> m_ast_importer_ap;
ClangPersistentVariables m_persistent_variables;
std::unique_ptr<SourceManager> m_source_manager_ap;
typedef std::map<lldb::user_id_t, StopHookSP> StopHookCollection;
StopHookCollection m_stop_hooks;
lldb::user_id_t m_stop_hook_next_id;
bool m_valid;
bool m_suppress_stop_hooks;
static void
ImageSearchPathsChanged (const PathMappingList &path_list,
void *baton);
private:
DISALLOW_COPY_AND_ASSIGN (Target);
};
}
#endif // liblldb_Target_h_