Added the ability for the target to specify Modules that will not be searched

when setting breakpoints, but only if no module is specified.  The Darwin 
platform uses this to not set breakpoints in dyld.

llvm-svn: 143249
This commit is contained in:
Jim Ingham 2011-10-28 23:14:11 +00:00
parent dba74af1b8
commit c6674fd597
8 changed files with 194 additions and 14 deletions

View File

@ -273,6 +273,24 @@ protected:
// now since you need a starting place for the search.
};
//----------------------------------------------------------------------
/// @class SearchFilterForNonModuleSpecificSearches SearchFilter.h "lldb/Core/SearchFilter.h"
/// @brief This is a SearchFilter that searches through all modules. It also consults the Target::ModuleIsExcludedForNonModuleSpecificSearches.
//----------------------------------------------------------------------
class SearchFilterForNonModuleSpecificSearches :
public SearchFilter
{
public:
SearchFilterForNonModuleSpecificSearches (lldb::TargetSP &targetSP) : SearchFilter(targetSP) {};
~SearchFilterForNonModuleSpecificSearches () {}
virtual bool
ModulePasses (const FileSpec &module_spec);
virtual bool
ModulePasses (const lldb::ModuleSP &module_sp);
};
//----------------------------------------------------------------------
/// @class SearchFilterByModule SearchFilter.h "lldb/Core/SearchFilter.h"
/// @brief This is a SearchFilter that restricts the search to a given module.

View File

@ -417,7 +417,15 @@ namespace lldb_private {
m_sdk_build = sdk_build;
}
// There may be modules that we don't want to find by default for operations like "setting breakpoint by name".
// The platform will return "true" from this call if the passed in module happens to be one of these.
virtual bool
ModuleIsExcludedForNonModuleSpecificSearches (Target &target, const lldb::ModuleSP &module_sp)
{
return false;
}
protected:
bool m_is_host;
// Set to true when we are able to actually set the OS version while

View File

@ -96,6 +96,12 @@ public:
{
return m_max_strlen_length;
}
bool
GetBreakpointsConsultPlatformAvoidList ()
{
return m_breakpoints_use_platform_avoid;
}
protected:
@ -113,6 +119,7 @@ protected:
PathMappingList m_source_map;
uint32_t m_max_children_display;
uint32_t m_max_strlen_length;
OptionValueBoolean m_breakpoints_use_platform_avoid;
};
@ -482,6 +489,48 @@ public:
{
return m_images;
}
//------------------------------------------------------------------
/// Return whether this FileSpec corresponds to a module that should be considered for general searches.
///
/// This API will be consulted by the SearchFilterForNonModuleSpecificSearches
/// and any module that returns \b true will not be searched. Note the
/// SearchFilterForNonModuleSpecificSearches is the search filter that
/// gets used in the CreateBreakpoint calls when no modules is provided.
///
/// The target call at present just consults the Platform's call of the
/// same name.
///
/// @param[in] module_sp
/// A shared pointer reference to the module that checked.
///
/// @return \b true if the module should be excluded, \b false otherwise.
//------------------------------------------------------------------
const bool
ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_spec);
//------------------------------------------------------------------
/// Return whether this module should be considered for general searches.
///
/// This API will be consulted by the SearchFilterForNonModuleSpecificSearches
/// and any module that returns \b true will not be searched. Note the
/// SearchFilterForNonModuleSpecificSearches is the search filter that
/// gets used in the CreateBreakpoint calls when no modules is provided.
///
/// The target call at present just consults the Platform's call of the
/// same name.
///
/// FIXME: When we get time we should add a way for the user to set modules that they
/// don't want searched, in addition to or instead of the platform ones.
///
/// @param[in] module_sp
/// A shared pointer reference to the module that checked.
///
/// @return \b true if the module should be excluded, \b false otherwise.
//------------------------------------------------------------------
const bool
ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp);
ArchSpec &
GetArchitecture ()

View File

@ -286,6 +286,29 @@ SearchFilter::DoFunctionIteration (Function *function, const SymbolContext &cont
return Searcher::eCallbackReturnContinue;
}
//----------------------------------------------------------------------
// SearchFilterForNonModuleSpecificSearches:
// Selects a shared library matching a given file spec, consulting the targets "black list".
//----------------------------------------------------------------------
bool
SearchFilterForNonModuleSpecificSearches::ModulePasses (const FileSpec &module_spec)
{
if (m_target_sp->ModuleIsExcludedForNonModuleSpecificSearches (module_spec))
return false;
else
return true;
}
bool
SearchFilterForNonModuleSpecificSearches::ModulePasses (const lldb::ModuleSP &module_sp)
{
if (m_target_sp->ModuleIsExcludedForNonModuleSpecificSearches (module_sp))
return false;
else
return true;
}
//----------------------------------------------------------------------
// SearchFilterByModule:
// Selects a shared library matching a given file spec

View File

@ -481,4 +481,16 @@ PlatformDarwin::GetGroupName (uint32_t gid)
return NULL;
}
bool
PlatformDarwin::ModuleIsExcludedForNonModuleSpecificSearches (lldb_private::Target &target, const lldb::ModuleSP &module_sp)
{
ObjectFile *obj_file = module_sp->GetObjectFile();
if (!obj_file)
return false;
ObjectFile::Type obj_type = obj_file->GetType();
if (obj_type == ObjectFile::eTypeDynamicLinker)
return true;
else
return false;
}

View File

@ -85,6 +85,9 @@ public:
lldb_private::Listener &listener,
lldb_private::Error &error);
virtual bool
ModuleIsExcludedForNonModuleSpecificSearches (lldb_private::Target &target, const lldb::ModuleSP &module_sp);
protected:
lldb::PlatformSP m_remote_platform_sp; // Allow multiple ways to connect to a remote darwin OS

View File

@ -591,4 +591,3 @@ Platform::DebugProcess (ProcessLaunchInfo &launch_info,
}
return process_sp;
}

View File

@ -252,7 +252,7 @@ BreakpointSP
Target::CreateBreakpoint (Address &addr, bool internal)
{
TargetSP target_sp = this->GetSP();
SearchFilterSP filter_sp(new SearchFilter (target_sp));
SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (target_sp));
BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
return CreateBreakpoint (filter_sp, resolver_sp, internal);
}
@ -295,7 +295,7 @@ Target::GetSearchFilterForModule (const FileSpec *containingModule)
else
{
if (m_search_filter_sp.get() == NULL)
m_search_filter_sp.reset (new SearchFilter (target_sp));
m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (target_sp));
filter_sp = m_search_filter_sp;
}
return filter_sp;
@ -315,7 +315,7 @@ Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
else
{
if (m_search_filter_sp.get() == NULL)
m_search_filter_sp.reset (new SearchFilter (target_sp));
m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (target_sp));
filter_sp = m_search_filter_sp;
}
return filter_sp;
@ -934,6 +934,50 @@ Target::ModulesDidUnload (ModuleList &module_list)
BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
}
const bool
Target::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_spec)
{
if (!m_breakpoints_use_platform_avoid)
return false;
else
{
ModuleList matchingModules;
const ArchSpec *arch_ptr = NULL;
const lldb_private::UUID *uuid_ptr= NULL;
const ConstString *object_name = NULL;
size_t num_modules = GetImages().FindModules(&module_spec, arch_ptr, uuid_ptr, object_name, matchingModules);
// If there is more than one module for this file spec, only return true if ALL the modules are on the
// black list.
if (num_modules > 0)
{
for (int i = 0; i < num_modules; i++)
{
if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i)))
return false;
}
return true;
}
else
return false;
}
}
const bool
Target::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp)
{
if (!m_breakpoints_use_platform_avoid)
return false;
else if (GetPlatform())
{
return GetPlatform()->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp);
}
else
return false;
}
size_t
Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
{
@ -1935,6 +1979,7 @@ Target::SettingsController::CreateInstanceSettings (const char *instance_name)
#define TSC_SOURCE_MAP "source-map"
#define TSC_MAX_CHILDREN "max-children-count"
#define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
#define TSC_PLATFORM_AVOID "breakpoints-use-platform-avoid-list"
static const ConstString &
@ -1986,6 +2031,14 @@ GetSettingNameForMaxStringSummaryLength ()
return g_const_string;
}
static const ConstString &
GetSettingNameForPlatformAvoid ()
{
static ConstString g_const_string (TSC_PLATFORM_AVOID);
return g_const_string;
}
bool
Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
const char *index_value,
@ -2039,7 +2092,8 @@ TargetInstanceSettings::TargetInstanceSettings
m_skip_prologue (true, true),
m_source_map (NULL, NULL),
m_max_children_display(256),
m_max_strlen_length(1024)
m_max_strlen_length(1024),
m_breakpoints_use_platform_avoid (true, true)
{
// CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
// until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
@ -2067,7 +2121,8 @@ TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rh
m_skip_prologue (rhs.m_skip_prologue),
m_source_map (rhs.m_source_map),
m_max_children_display(rhs.m_max_children_display),
m_max_strlen_length(rhs.m_max_strlen_length)
m_max_strlen_length(rhs.m_max_strlen_length),
m_breakpoints_use_platform_avoid (rhs.m_breakpoints_use_platform_avoid)
{
if (m_instance_name != InstanceSettings::GetDefaultName())
{
@ -2214,6 +2269,10 @@ TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_n
break;
}
}
else if (var_name == GetSettingNameForPlatformAvoid ())
{
err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_breakpoints_use_platform_avoid);
}
}
void
@ -2224,12 +2283,13 @@ TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &ne
if (!new_settings_ptr)
return;
m_expr_prefix_file = new_settings_ptr->m_expr_prefix_file;
m_expr_prefix_contents_sp = new_settings_ptr->m_expr_prefix_contents_sp;
m_prefer_dynamic_value = new_settings_ptr->m_prefer_dynamic_value;
m_skip_prologue = new_settings_ptr->m_skip_prologue;
m_max_children_display = new_settings_ptr->m_max_children_display;
m_max_strlen_length = new_settings_ptr->m_max_strlen_length;
m_expr_prefix_file = new_settings_ptr->m_expr_prefix_file;
m_expr_prefix_contents_sp = new_settings_ptr->m_expr_prefix_contents_sp;
m_prefer_dynamic_value = new_settings_ptr->m_prefer_dynamic_value;
m_skip_prologue = new_settings_ptr->m_skip_prologue;
m_max_children_display = new_settings_ptr->m_max_children_display;
m_max_strlen_length = new_settings_ptr->m_max_strlen_length;
m_breakpoints_use_platform_avoid = new_settings_ptr->m_breakpoints_use_platform_avoid;
}
bool
@ -2271,6 +2331,13 @@ TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
count_str.Printf ("%d", m_max_strlen_length);
value.AppendString (count_str.GetData());
}
else if (var_name == GetSettingNameForPlatformAvoid())
{
if (m_breakpoints_use_platform_avoid)
value.AppendString ("true");
else
value.AppendString ("false");
}
else
{
if (err)
@ -2326,5 +2393,6 @@ Target::SettingsController::instance_settings_table[] =
{ TSC_SOURCE_MAP , eSetVarTypeArray , NULL , NULL, false, false, "Source path remappings to use when locating source files from debug information." },
{ TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." },
{ TSC_MAX_STRLENSUMMARY , eSetVarTypeInt , "1024" , NULL, true, false, "Maximum number of characters to show when using %s in summary strings." },
{ TSC_PLATFORM_AVOID , eSetVarTypeBoolean, "true" , NULL, false, false, "Consult the platform module avoid list when setting non-module specific breakpoints." },
{ NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
};