#ifndef liblldb_Target_h_
#define liblldb_Target_h_
#include "lldb/lldb-public.h"
#include "lldb/Breakpoint/BreakpointList.h"
#include "lldb/Breakpoint/BreakpointLocationCollection.h"
#include "lldb/Breakpoint/WatchpointList.h"
#include "lldb/Core/Broadcaster.h"
#include "lldb/Core/Event.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/UserSettingsController.h"
#include "lldb/Core/SourceManager.h"
#include "lldb/Expression/ClangPersistentVariables.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/NamedOptionValue.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Target/ABI.h"
#include "lldb/Target/ExecutionContextScope.h"
#include "lldb/Target/PathMappingList.h"
#include "lldb/Target/SectionLoadList.h"
namespace lldb_private {
class TargetInstanceSettings : public InstanceSettings
{
public:
static OptionEnumValueElement g_dynamic_value_types[];
TargetInstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, bool live_instance = true, const char *name = NULL);
TargetInstanceSettings (const TargetInstanceSettings &rhs);
virtual
~TargetInstanceSettings ();
TargetInstanceSettings&
operator= (const TargetInstanceSettings &rhs);
void
UpdateInstanceSettingsVariable (const ConstString &var_name,
const char *index_value,
const char *value,
const ConstString &instance_name,
const SettingEntry &entry,
VarSetOperationType op,
Error &err,
bool pending);
bool
GetInstanceSettingsValue (const SettingEntry &entry,
const ConstString &var_name,
StringList &value,
Error *err);
lldb::DynamicValueType
GetPreferDynamicValue()
{
return (lldb::DynamicValueType) g_dynamic_value_types[m_prefer_dynamic_value].value;
}
bool
GetEnableSyntheticValue ()
{
return m_enable_synthetic_value;
}
void
SetEnableSyntheticValue (bool b)
{
m_enable_synthetic_value = b;
}
bool
GetSkipPrologue()
{
return m_skip_prologue;
}
PathMappingList &
GetSourcePathMap ()
{
return m_source_map;
}
FileSpecList &
GetExecutableSearchPaths ()
{
return m_exe_search_paths;
}
const FileSpecList &
GetExecutableSearchPaths () const
{
return m_exe_search_paths;
}
uint32_t
GetMaximumNumberOfChildrenToDisplay()
{
return m_max_children_display;
}
uint32_t
GetMaximumSizeOfStringSummary()
{
return m_max_strlen_length;
}
bool
GetBreakpointsConsultPlatformAvoidList ()
{
return m_breakpoints_use_platform_avoid;
}
const Args &
GetRunArguments () const
{
return m_run_args;
}
void
SetRunArguments (const Args &args)
{
m_run_args = args;
}
void
GetHostEnvironmentIfNeeded ();
size_t
GetEnvironmentAsArgs (Args &env);
const char *
GetStandardInputPath () const
{
if (m_input_path.empty())
return NULL;
return m_input_path.c_str();
}
void
SetStandardInputPath (const char *path)
{
if (path && path[0])
m_input_path.assign (path);
else
{
std::string tmp;
tmp.swap (m_input_path);
}
}
const char *
GetStandardOutputPath () const
{
if (m_output_path.empty())
return NULL;
return m_output_path.c_str();
}
void
SetStandardOutputPath (const char *path)
{
if (path && path[0])
m_output_path.assign (path);
else
{
std::string tmp;
tmp.swap (m_output_path);
}
}
const char *
GetStandardErrorPath () const
{
if (m_error_path.empty())
return NULL;
return m_error_path.c_str();
}
void
SetStandardErrorPath (const char *path)
{
if (path && path[0])
m_error_path.assign (path);
else
{
std::string tmp;
tmp.swap (m_error_path);
}
}
bool
GetDisableASLR () const
{
return m_disable_aslr;
}
void
SetDisableASLR (bool b)
{
m_disable_aslr = b;
}
bool
GetDisableSTDIO () const
{
return m_disable_stdio;
}
void
SetDisableSTDIO (bool b)
{
m_disable_stdio = b;
}
protected:
void
CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
bool pending);
const ConstString
CreateInstanceName ();
OptionValueFileSpec m_expr_prefix_file;
std::string m_expr_prefix_contents;
int m_prefer_dynamic_value;
OptionValueBoolean m_enable_synthetic_value;
OptionValueBoolean m_skip_prologue;
PathMappingList m_source_map;
FileSpecList m_exe_search_paths;
uint32_t m_max_children_display;
uint32_t m_max_strlen_length;
OptionValueBoolean m_breakpoints_use_platform_avoid;
typedef std::map<std::string, std::string> dictionary;
Args m_run_args;
dictionary m_env_vars;
std::string m_input_path;
std::string m_output_path;
std::string m_error_path;
bool m_disable_aslr;
bool m_disable_stdio;
bool m_inherit_host_env;
bool m_got_host_env;
};
class Target :
public STD_ENABLE_SHARED_FROM_THIS(Target),
public Broadcaster,
public ExecutionContextScope,
public TargetInstanceSettings
{
public:
friend class TargetList;
enum
{
eBroadcastBitBreakpointChanged = (1 << 0),
eBroadcastBitModulesLoaded = (1 << 1),
eBroadcastBitModulesUnloaded = (1 << 2)
};
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 lldb::UserSettingsControllerSP &
GetSettingsController ();
static FileSpecList
GetDefaultExecutableSearchPaths ();
static ArchSpec
GetDefaultArchitecture ();
static void
SetDefaultArchitecture (const ArchSpec &arch);
void
UpdateInstanceName ();
lldb::ModuleSP
GetSharedModule (const ModuleSpec &module_spec,
Error *error_ptr = NULL);
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
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();
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,
bool check_inlines,
LazyBool skip_prologue = eLazyBoolCalculate,
bool internal = false);
lldb::BreakpointSP
CreateSourceRegexBreakpoint (const FileSpecList *containingModules,
const FileSpecList *source_file_list,
RegularExpression &source_regex,
bool internal = false);
lldb::BreakpointSP
CreateBreakpoint (lldb::addr_t load_addr,
bool internal = false);
lldb::BreakpointSP
CreateBreakpoint (Address &addr,
bool internal = false);
lldb::BreakpointSP
CreateFuncRegexBreakpoint (const FileSpecList *containingModules,
const FileSpecList *containingSourceFiles,
RegularExpression &func_regexp,
LazyBool skip_prologue = eLazyBoolCalculate,
bool internal = false);
lldb::BreakpointSP
CreateBreakpoint (const FileSpecList *containingModules,
const FileSpecList *containingSourceFiles,
const char *func_name,
uint32_t func_name_type_mask,
LazyBool skip_prologue = eLazyBoolCalculate,
bool internal = false);
lldb::BreakpointSP
CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal = false);
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 = eLazyBoolCalculate,
bool internal = false);
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 = eLazyBoolCalculate,
bool internal = false);
lldb::BreakpointSP
CreateBreakpoint (lldb::SearchFilterSP &filter_sp,
lldb::BreakpointResolverSP &resolver_sp,
bool internal = false);
lldb::WatchpointSP
CreateWatchpoint (lldb::addr_t addr,
size_t size,
uint32_t type,
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);
void
ModulesDidLoad (ModuleList &module_list);
void
ModulesDidUnload (ModuleList &module_list);
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:
void
ModuleAdded (lldb::ModuleSP &module_sp);
void
ModuleUpdated (lldb::ModuleSP &old_module_sp, lldb::ModuleSP &new_module_sp);
public:
lldb::ModuleSP
GetExecutableModule ();
Module*
GetExecutableModulePointer ();
void
SetExecutableModule (lldb::ModuleSP& module_sp, bool get_dependent_files);
ModuleList&
GetImages ()
{
return m_images;
}
const ModuleList&
GetImages () const
{
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
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_list;
}
const SectionLoadList&
GetSectionLoadList() const
{
return m_section_load_list;
}
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();
const char *
GetExpressionPrefixContentsAsCString ();
ExecutionResults
EvaluateExpression (const char *expression,
StackFrame *frame,
lldb_private::ExecutionPolicy execution_policy,
bool coerce_to_id,
bool unwind_on_error,
bool keep_in_memory,
lldb::DynamicValueType use_dynamic,
lldb::ValueObjectSP &result_valobj_sp,
uint32_t single_thread_timeout_usec = 500000);
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::auto_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
SetSuppressSyntheticValue (bool suppress)
{
bool old_value = m_suppress_synthetic_value;
m_suppress_synthetic_value = suppress;
return old_value;
}
bool
GetSuppressSyntheticValue ()
{
return m_suppress_synthetic_value;
}
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 ()
{
return m_source_manager;
}
class SettingsController : public UserSettingsController
{
public:
SettingsController ();
virtual
~SettingsController ();
bool
SetGlobalVariable (const ConstString &var_name,
const char *index_value,
const char *value,
const SettingEntry &entry,
const VarSetOperationType op,
Error&err);
bool
GetGlobalVariable (const ConstString &var_name,
StringList &value,
Error &err);
static SettingEntry global_settings_table[];
static SettingEntry instance_settings_table[];
ArchSpec &
GetArchitecture ()
{
return m_default_architecture;
}
protected:
lldb::InstanceSettingsSP
CreateInstanceSettings (const char *instance_name);
private:
ArchSpec m_default_architecture;
DISALLOW_COPY_AND_ASSIGN (SettingsController);
};
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; SectionLoadList m_section_load_list;
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;
bool m_valid;
lldb::SearchFilterSP m_search_filter_sp;
PathMappingList m_image_search_paths;
std::auto_ptr<ClangASTContext> m_scratch_ast_context_ap;
std::auto_ptr<ClangASTSource> m_scratch_ast_source_ap;
std::auto_ptr<ClangASTImporter> m_ast_importer_ap;
ClangPersistentVariables m_persistent_variables;
SourceManager m_source_manager;
typedef std::map<lldb::user_id_t, StopHookSP> StopHookCollection;
StopHookCollection m_stop_hooks;
lldb::user_id_t m_stop_hook_next_id;
bool m_suppress_stop_hooks;
bool m_suppress_synthetic_value;
static void
ImageSearchPathsChanged (const PathMappingList &path_list,
void *baton);
private:
DISALLOW_COPY_AND_ASSIGN (Target);
};
}
#endif // liblldb_Target_h_