2010-06-09 00:52:24 +08:00
|
|
|
//===-- BreakpointResolverName.cpp ------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-10-31 02:50:12 +08:00
|
|
|
#include "lldb/Breakpoint/BreakpointResolverName.h"
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
2018-03-13 05:17:04 +08:00
|
|
|
#include "lldb/Core/Architecture.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Symbol/Block.h"
|
|
|
|
#include "lldb/Symbol/Function.h"
|
|
|
|
#include "lldb/Symbol/Symbol.h"
|
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
2018-03-13 05:17:04 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2019-05-11 11:32:25 +08:00
|
|
|
#include "lldb/Target/Language.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2013-04-03 10:00:15 +08:00
|
|
|
BreakpointResolverName::BreakpointResolverName(
|
2018-10-26 04:45:40 +08:00
|
|
|
Breakpoint *bkpt, const char *name_cstr, FunctionNameType name_type_mask,
|
2013-04-03 10:00:15 +08:00
|
|
|
LanguageType language, Breakpoint::MatchType type, lldb::addr_t offset,
|
|
|
|
bool skip_prologue)
|
2016-03-10 02:59:13 +08:00
|
|
|
: BreakpointResolver(bkpt, BreakpointResolver::NameResolver, offset),
|
2015-07-22 06:05:07 +08:00
|
|
|
m_class_name(), m_regex(), m_match_type(type), m_language(language),
|
2011-07-13 01:06:17 +08:00
|
|
|
m_skip_prologue(skip_prologue) {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_match_type == Breakpoint::Regexp) {
|
2019-08-20 17:24:20 +08:00
|
|
|
m_regex = RegularExpression(llvm::StringRef::withNullAsEmpty(name_cstr));
|
|
|
|
if (!m_regex.IsValid()) {
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
|
2012-03-03 10:05:11 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Warning("function name regexp: \"%s\" did not compile.",
|
2013-04-03 10:00:15 +08:00
|
|
|
name_cstr);
|
2012-03-03 10:05:11 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2013-04-03 10:00:15 +08:00
|
|
|
AddNameLookup(ConstString(name_cstr), name_type_mask);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-03-06 08:37:27 +08:00
|
|
|
BreakpointResolverName::BreakpointResolverName(
|
|
|
|
Breakpoint *bkpt, const char *names[], size_t num_names,
|
2018-10-26 04:45:40 +08:00
|
|
|
FunctionNameType name_type_mask, LanguageType language, lldb::addr_t offset,
|
2012-03-06 08:37:27 +08:00
|
|
|
bool skip_prologue)
|
2016-03-10 02:59:13 +08:00
|
|
|
: BreakpointResolver(bkpt, BreakpointResolver::NameResolver, offset),
|
2012-03-06 08:37:27 +08:00
|
|
|
m_match_type(Breakpoint::Exact), m_language(language),
|
|
|
|
m_skip_prologue(skip_prologue) {
|
2013-04-03 10:00:15 +08:00
|
|
|
for (size_t i = 0; i < num_names; i++) {
|
|
|
|
AddNameLookup(ConstString(names[i]), name_type_mask);
|
2012-03-06 08:37:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 04:45:40 +08:00
|
|
|
BreakpointResolverName::BreakpointResolverName(Breakpoint *bkpt,
|
|
|
|
std::vector<std::string> names,
|
|
|
|
FunctionNameType name_type_mask,
|
|
|
|
LanguageType language,
|
|
|
|
lldb::addr_t offset,
|
|
|
|
bool skip_prologue)
|
2016-03-10 02:59:13 +08:00
|
|
|
: BreakpointResolver(bkpt, BreakpointResolver::NameResolver, offset),
|
2011-07-13 01:06:17 +08:00
|
|
|
m_match_type(Breakpoint::Exact), m_language(language),
|
|
|
|
m_skip_prologue(skip_prologue) {
|
|
|
|
for (const std::string &name : names) {
|
2013-04-03 10:00:15 +08:00
|
|
|
AddNameLookup(ConstString(name.c_str(), name.size()), name_type_mask);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-03-03 10:05:11 +08:00
|
|
|
BreakpointResolverName::BreakpointResolverName(Breakpoint *bkpt,
|
2019-08-17 05:25:36 +08:00
|
|
|
RegularExpression func_regex,
|
2016-03-10 02:59:13 +08:00
|
|
|
lldb::LanguageType language,
|
|
|
|
lldb::addr_t offset,
|
2012-03-03 10:05:11 +08:00
|
|
|
bool skip_prologue)
|
2016-03-10 02:59:13 +08:00
|
|
|
: BreakpointResolver(bkpt, BreakpointResolver::NameResolver, offset),
|
2019-08-17 05:25:36 +08:00
|
|
|
m_class_name(nullptr), m_regex(std::move(func_regex)),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_match_type(Breakpoint::Regexp), m_language(language),
|
2012-03-03 10:05:11 +08:00
|
|
|
m_skip_prologue(skip_prologue) {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-31 02:50:12 +08:00
|
|
|
BreakpointResolverName::~BreakpointResolverName() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2014-12-06 09:28:03 +08:00
|
|
|
BreakpointResolverName::BreakpointResolverName(
|
|
|
|
const BreakpointResolverName &rhs)
|
2016-03-10 02:59:13 +08:00
|
|
|
: BreakpointResolver(rhs.m_breakpoint, BreakpointResolver::NameResolver,
|
|
|
|
rhs.m_offset),
|
2014-12-06 09:28:03 +08:00
|
|
|
m_lookups(rhs.m_lookups), m_class_name(rhs.m_class_name),
|
|
|
|
m_regex(rhs.m_regex), m_match_type(rhs.m_match_type),
|
|
|
|
m_language(rhs.m_language), m_skip_prologue(rhs.m_skip_prologue) {}
|
|
|
|
|
2016-09-13 07:10:56 +08:00
|
|
|
BreakpointResolver *BreakpointResolverName::CreateFromStructuredData(
|
2016-09-13 09:58:08 +08:00
|
|
|
Breakpoint *bkpt, const StructuredData::Dictionary &options_dict,
|
2017-05-12 12:51:55 +08:00
|
|
|
Status &error) {
|
2016-09-13 07:10:56 +08:00
|
|
|
LanguageType language = eLanguageTypeUnknown;
|
2017-05-12 13:49:54 +08:00
|
|
|
llvm::StringRef language_name;
|
2016-09-13 07:10:56 +08:00
|
|
|
bool success = options_dict.GetValueForKeyAsString(
|
|
|
|
GetKey(OptionNames::LanguageName), language_name);
|
|
|
|
if (success) {
|
2016-09-17 10:00:02 +08:00
|
|
|
language = Language::GetLanguageTypeFromString(language_name);
|
2016-09-13 07:10:56 +08:00
|
|
|
if (language == eLanguageTypeUnknown) {
|
2017-05-12 13:49:54 +08:00
|
|
|
error.SetErrorStringWithFormatv("BRN::CFSD: Unknown language: {0}.",
|
|
|
|
language_name);
|
2016-09-13 07:10:56 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::addr_t offset = 0;
|
|
|
|
success =
|
|
|
|
options_dict.GetValueForKeyAsInteger(GetKey(OptionNames::Offset), offset);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorStringWithFormat("BRN::CFSD: Missing offset entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool skip_prologue;
|
|
|
|
success = options_dict.GetValueForKeyAsBoolean(
|
|
|
|
GetKey(OptionNames::SkipPrologue), skip_prologue);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorStringWithFormat("BRN::CFSD: Missing Skip prologue entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-12 13:49:54 +08:00
|
|
|
llvm::StringRef regex_text;
|
2016-09-13 07:10:56 +08:00
|
|
|
success = options_dict.GetValueForKeyAsString(
|
|
|
|
GetKey(OptionNames::RegexString), regex_text);
|
|
|
|
if (success) {
|
2019-09-04 17:47:18 +08:00
|
|
|
return new BreakpointResolverName(bkpt, RegularExpression(regex_text),
|
|
|
|
language, offset, skip_prologue);
|
2016-09-13 07:10:56 +08:00
|
|
|
} else {
|
|
|
|
StructuredData::Array *names_array;
|
|
|
|
success = options_dict.GetValueForKeyAsArray(
|
|
|
|
GetKey(OptionNames::SymbolNameArray), names_array);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorStringWithFormat("BRN::CFSD: Missing symbol names entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
StructuredData::Array *names_mask_array;
|
|
|
|
success = options_dict.GetValueForKeyAsArray(
|
|
|
|
GetKey(OptionNames::NameMaskArray), names_mask_array);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"BRN::CFSD: Missing symbol names mask entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t num_elem = names_array->GetSize();
|
|
|
|
if (num_elem != names_mask_array->GetSize()) {
|
|
|
|
error.SetErrorString(
|
|
|
|
"BRN::CFSD: names and names mask arrays have different sizes.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_elem == 0) {
|
|
|
|
error.SetErrorString(
|
|
|
|
"BRN::CFSD: no name entry in a breakpoint by name breakpoint.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
std::vector<std::string> names;
|
2018-10-26 04:45:40 +08:00
|
|
|
std::vector<FunctionNameType> name_masks;
|
2016-09-13 07:10:56 +08:00
|
|
|
for (size_t i = 0; i < num_elem; i++) {
|
2017-05-12 13:49:54 +08:00
|
|
|
llvm::StringRef name;
|
2016-09-13 07:10:56 +08:00
|
|
|
|
|
|
|
success = names_array->GetItemAtIndexAsString(i, name);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorString("BRN::CFSD: name entry is not a string.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-10-26 04:45:40 +08:00
|
|
|
std::underlying_type<FunctionNameType>::type fnt;
|
|
|
|
success = names_mask_array->GetItemAtIndexAsInteger(i, fnt);
|
2016-09-13 07:10:56 +08:00
|
|
|
if (!success) {
|
|
|
|
error.SetErrorString("BRN::CFSD: name mask entry is not an integer.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
names.push_back(name);
|
2018-10-26 04:45:40 +08:00
|
|
|
name_masks.push_back(static_cast<FunctionNameType>(fnt));
|
2016-09-13 07:10:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointResolverName *resolver = new BreakpointResolverName(
|
|
|
|
bkpt, names[0].c_str(), name_masks[0], language,
|
|
|
|
Breakpoint::MatchType::Exact, offset, skip_prologue);
|
|
|
|
for (size_t i = 1; i < num_elem; i++) {
|
|
|
|
resolver->AddNameLookup(ConstString(names[i]), name_masks[i]);
|
|
|
|
}
|
|
|
|
return resolver;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StructuredData::ObjectSP BreakpointResolverName::SerializeToStructuredData() {
|
|
|
|
StructuredData::DictionarySP options_dict_sp(
|
|
|
|
new StructuredData::Dictionary());
|
|
|
|
|
|
|
|
if (m_regex.IsValid()) {
|
|
|
|
options_dict_sp->AddStringItem(GetKey(OptionNames::RegexString),
|
|
|
|
m_regex.GetText());
|
|
|
|
} else {
|
|
|
|
StructuredData::ArraySP names_sp(new StructuredData::Array());
|
|
|
|
StructuredData::ArraySP name_masks_sp(new StructuredData::Array());
|
|
|
|
for (auto lookup : m_lookups) {
|
|
|
|
names_sp->AddItem(StructuredData::StringSP(
|
|
|
|
new StructuredData::String(lookup.GetName().AsCString())));
|
|
|
|
name_masks_sp->AddItem(StructuredData::IntegerSP(
|
|
|
|
new StructuredData::Integer(lookup.GetNameTypeMask())));
|
|
|
|
}
|
|
|
|
options_dict_sp->AddItem(GetKey(OptionNames::SymbolNameArray), names_sp);
|
|
|
|
options_dict_sp->AddItem(GetKey(OptionNames::NameMaskArray), name_masks_sp);
|
|
|
|
}
|
|
|
|
if (m_language != eLanguageTypeUnknown)
|
|
|
|
options_dict_sp->AddStringItem(
|
|
|
|
GetKey(OptionNames::LanguageName),
|
|
|
|
Language::GetNameForLanguageType(m_language));
|
|
|
|
options_dict_sp->AddBooleanItem(GetKey(OptionNames::SkipPrologue),
|
|
|
|
m_skip_prologue);
|
|
|
|
|
|
|
|
return WrapOptionsDict(options_dict_sp);
|
|
|
|
}
|
|
|
|
|
2019-03-07 05:22:25 +08:00
|
|
|
void BreakpointResolverName::AddNameLookup(ConstString name,
|
2018-10-26 04:45:40 +08:00
|
|
|
FunctionNameType name_type_mask) {
|
2019-05-11 11:32:25 +08:00
|
|
|
|
|
|
|
Module::LookupInfo lookup(name, name_type_mask, m_language);
|
|
|
|
m_lookups.emplace_back(lookup);
|
|
|
|
|
|
|
|
auto add_variant_funcs = [&](Language *lang) {
|
|
|
|
for (ConstString variant_name : lang->GetMethodNameVariants(name)) {
|
|
|
|
Module::LookupInfo variant_lookup(name, name_type_mask,
|
|
|
|
lang->GetLanguageType());
|
|
|
|
variant_lookup.SetLookupName(variant_name);
|
|
|
|
m_lookups.emplace_back(variant_lookup);
|
2013-04-03 10:00:15 +08:00
|
|
|
}
|
2019-05-11 11:32:25 +08:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (Language *lang = Language::FindPlugin(m_language)) {
|
|
|
|
add_variant_funcs(lang);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2019-05-11 11:32:25 +08:00
|
|
|
// Most likely m_language is eLanguageTypeUnknown. We check each language for
|
|
|
|
// possible variants or more qualified names and create lookups for those as
|
|
|
|
// well.
|
|
|
|
Language::ForEach(add_variant_funcs);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-04-03 10:00:15 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// FIXME: Right now we look at the module level, and call the module's
|
|
|
|
// "FindFunctions".
|
|
|
|
// Greg says he will add function tables, maybe at the CompileUnit level to
|
2018-05-01 00:49:04 +08:00
|
|
|
// accelerate function lookup. At that point, we should switch the depth to
|
|
|
|
// CompileUnit, and look in these tables.
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
Searcher::CallbackReturn
|
2015-10-31 02:50:12 +08:00
|
|
|
BreakpointResolverName::SearchCallback(SearchFilter &filter,
|
2019-10-10 19:26:51 +08:00
|
|
|
SymbolContext &context, Address *addr) {
|
2010-06-09 00:52:24 +08:00
|
|
|
SymbolContextList func_list;
|
2013-06-12 08:46:38 +08:00
|
|
|
// SymbolContextList sym_list;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t i;
|
|
|
|
bool new_location;
|
|
|
|
Address break_addr;
|
2015-10-31 02:50:12 +08:00
|
|
|
assert(m_breakpoint != nullptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_class_name) {
|
|
|
|
if (log)
|
|
|
|
log->Warning("Class/method function specification not supported yet.\n");
|
|
|
|
return Searcher::eCallbackReturnStop;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-06-12 08:46:38 +08:00
|
|
|
bool filter_by_cu =
|
2010-06-09 00:52:24 +08:00
|
|
|
(filter.GetFilterRequiredItems() & eSymbolContextCompUnit) != 0;
|
|
|
|
bool filter_by_language = (m_language != eLanguageTypeUnknown);
|
|
|
|
const bool include_symbols = !filter_by_cu;
|
2012-02-11 06:52:19 +08:00
|
|
|
const bool include_inlines = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
switch (m_match_type) {
|
|
|
|
case Breakpoint::Exact:
|
2010-06-29 05:30:43 +08:00
|
|
|
if (context.module_sp) {
|
2010-06-09 00:52:24 +08:00
|
|
|
for (const auto &lookup : m_lookups) {
|
2013-04-03 10:00:15 +08:00
|
|
|
const size_t start_func_idx = func_list.GetSize();
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-14 01:12:24 +08:00
|
|
|
context.module_sp->FindFunctions(
|
2010-06-09 00:52:24 +08:00
|
|
|
lookup.GetLookupName(), nullptr, lookup.GetNameTypeMask(),
|
2019-10-18 03:56:40 +08:00
|
|
|
include_symbols, include_inlines, func_list);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-03 10:00:15 +08:00
|
|
|
const size_t end_func_idx = func_list.GetSize();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-03 10:00:15 +08:00
|
|
|
if (start_func_idx < end_func_idx)
|
2010-06-09 00:52:24 +08:00
|
|
|
lookup.Prune(func_list, start_func_idx);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2013-06-12 08:46:38 +08:00
|
|
|
break;
|
2010-06-29 05:30:43 +08:00
|
|
|
case Breakpoint::Regexp:
|
|
|
|
if (context.module_sp) {
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-14 01:12:24 +08:00
|
|
|
context.module_sp->FindFunctions(
|
2013-06-12 08:46:38 +08:00
|
|
|
m_regex,
|
2014-07-02 05:22:11 +08:00
|
|
|
!filter_by_cu, // include symbols only if we aren't filtering by CU
|
2019-10-18 03:56:40 +08:00
|
|
|
include_inlines, func_list);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2010-06-29 05:30:43 +08:00
|
|
|
case Breakpoint::Glob:
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
2010-06-29 05:30:43 +08:00
|
|
|
log->Warning("glob is not supported yet.");
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-09-23 08:54:11 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// If the filter specifies a Compilation Unit, remove the ones that don't
|
|
|
|
// pass at this point.
|
2015-11-07 06:48:59 +08:00
|
|
|
if (filter_by_cu || filter_by_language) {
|
2011-09-23 08:54:11 +08:00
|
|
|
uint32_t num_functions = func_list.GetSize();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-23 08:54:11 +08:00
|
|
|
for (size_t idx = 0; idx < num_functions; idx++) {
|
2015-11-07 06:48:59 +08:00
|
|
|
bool remove_it = false;
|
2011-09-23 08:54:11 +08:00
|
|
|
SymbolContext sc;
|
|
|
|
func_list.GetContextAtIndex(idx, sc);
|
2015-11-07 06:48:59 +08:00
|
|
|
if (filter_by_cu) {
|
|
|
|
if (!sc.comp_unit || !filter.CompUnitPasses(*sc.comp_unit))
|
|
|
|
remove_it = true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-11-07 06:48:59 +08:00
|
|
|
if (filter_by_language) {
|
2015-12-17 03:40:00 +08:00
|
|
|
LanguageType sym_language = sc.GetLanguage();
|
|
|
|
if ((Language::GetPrimaryLanguage(sym_language) !=
|
|
|
|
Language::GetPrimaryLanguage(m_language)) &&
|
|
|
|
(sym_language != eLanguageTypeUnknown)) {
|
|
|
|
remove_it = true;
|
2011-09-23 08:54:11 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-11-07 06:48:59 +08:00
|
|
|
if (remove_it) {
|
2011-09-23 08:54:11 +08:00
|
|
|
func_list.RemoveContextAtIndex(idx);
|
|
|
|
num_functions--;
|
2016-09-07 04:57:50 +08:00
|
|
|
idx--;
|
|
|
|
}
|
2011-09-23 08:54:11 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-07-02 05:22:11 +08:00
|
|
|
// Remove any duplicates between the function list and the symbol list
|
2013-04-03 10:00:15 +08:00
|
|
|
SymbolContext sc;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (func_list.GetSize()) {
|
|
|
|
for (i = 0; i < func_list.GetSize(); i++) {
|
|
|
|
if (func_list.GetContextAtIndex(i, sc)) {
|
2014-01-11 07:46:59 +08:00
|
|
|
bool is_reexported = false;
|
2010-11-14 08:22:48 +08:00
|
|
|
|
|
|
|
if (sc.block && sc.block->GetInlinedFunctionInfo()) {
|
|
|
|
if (!sc.block->GetStartAddress(break_addr))
|
|
|
|
break_addr.Clear();
|
|
|
|
} else if (sc.function) {
|
2010-06-09 00:52:24 +08:00
|
|
|
break_addr = sc.function->GetAddressRange().GetBaseAddress();
|
2013-06-12 08:46:38 +08:00
|
|
|
if (m_skip_prologue && break_addr.IsValid()) {
|
|
|
|
const uint32_t prologue_byte_size =
|
|
|
|
sc.function->GetPrologueByteSize();
|
|
|
|
if (prologue_byte_size)
|
2013-10-22 04:04:47 +08:00
|
|
|
break_addr.SetOffset(break_addr.GetOffset() + prologue_byte_size);
|
|
|
|
}
|
|
|
|
} else if (sc.symbol) {
|
|
|
|
if (sc.symbol->GetType() == eSymbolTypeReExported) {
|
2013-06-12 08:46:38 +08:00
|
|
|
const Symbol *actual_symbol =
|
|
|
|
sc.symbol->ResolveReExportedSymbol(m_breakpoint->GetTarget());
|
2010-11-14 08:22:48 +08:00
|
|
|
if (actual_symbol) {
|
2014-01-11 07:46:59 +08:00
|
|
|
is_reexported = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
break_addr = actual_symbol->GetAddress();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2013-10-22 04:04:47 +08:00
|
|
|
break_addr = sc.symbol->GetAddress();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-06-12 08:46:38 +08:00
|
|
|
if (m_skip_prologue && break_addr.IsValid()) {
|
|
|
|
const uint32_t prologue_byte_size =
|
2013-10-22 04:04:47 +08:00
|
|
|
sc.symbol->GetPrologueByteSize();
|
2013-06-12 08:46:38 +08:00
|
|
|
if (prologue_byte_size)
|
|
|
|
break_addr.SetOffset(break_addr.GetOffset() + prologue_byte_size);
|
2018-03-13 05:17:04 +08:00
|
|
|
else {
|
2018-06-27 15:01:07 +08:00
|
|
|
const Architecture *arch =
|
2018-03-13 05:17:04 +08:00
|
|
|
m_breakpoint->GetTarget().GetArchitecturePlugin();
|
|
|
|
if (arch)
|
|
|
|
arch->AdjustBreakpointAddress(*sc.symbol, break_addr);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-06-12 08:46:38 +08:00
|
|
|
if (break_addr.IsValid()) {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (filter.AddressPasses(break_addr)) {
|
2016-03-10 02:59:13 +08:00
|
|
|
BreakpointLocationSP bp_loc_sp(
|
|
|
|
AddLocation(break_addr, &new_location));
|
2014-01-11 07:46:59 +08:00
|
|
|
bp_loc_sp->SetIsReExported(is_reexported);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (bp_loc_sp && new_location && !m_breakpoint->IsInternal()) {
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log) {
|
2010-06-09 00:52:24 +08:00
|
|
|
StreamString s;
|
|
|
|
bp_loc_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Added location: %s\n", s.GetData());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return Searcher::eCallbackReturnContinue;
|
|
|
|
}
|
|
|
|
|
2018-09-08 02:43:04 +08:00
|
|
|
lldb::SearchDepth BreakpointResolverName::GetDepth() {
|
|
|
|
return lldb::eSearchDepthModule;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointResolverName::GetDescription(Stream *s) {
|
|
|
|
if (m_match_type == Breakpoint::Regexp)
|
2016-09-22 00:01:28 +08:00
|
|
|
s->Printf("regex = '%s'", m_regex.GetText().str().c_str());
|
2010-10-12 12:29:14 +08:00
|
|
|
else {
|
2013-04-03 10:00:15 +08:00
|
|
|
size_t num_names = m_lookups.size();
|
2012-03-03 10:05:11 +08:00
|
|
|
if (num_names == 1)
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-14 01:12:24 +08:00
|
|
|
s->Printf("name = '%s'", m_lookups[0].GetName().GetCString());
|
2012-03-03 10:05:11 +08:00
|
|
|
else {
|
|
|
|
s->Printf("names = {");
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-14 01:12:24 +08:00
|
|
|
for (size_t i = 0; i < num_names; i++) {
|
|
|
|
s->Printf("%s'%s'", (i == 0 ? "" : ", "),
|
|
|
|
m_lookups[i].GetName().GetCString());
|
2012-03-03 10:05:11 +08:00
|
|
|
}
|
Centralize the way symbol and functions are looked up by making a Module::LookupInfo class that does all of the heavy lifting.
Background: symbols and functions can be looked up by full mangled name and by basename. SymbolFile and ObjectFile are expected to be able to do the lookups based on full mangled name or by basename, so when the user types something that is incomplete, we must be able to look it up efficiently. For example the user types "a::b::c" as a symbol to set a breakpoint on, we will break this down into a 'lookup "c"' and then weed out N matches down to just the ones that match "a::b::c". Previously this was done manaully in many functions by calling Module::PrepareForFunctionNameLookup(...) and then doing the lookup and manually pruning the results down afterward with duplicated code. Now all places use Module::LookupInfo to do the work in one place.
This allowed me to fix the name lookups to look for "func" with eFunctionNameTypeFull as the "name_type_mask", and correctly weed the results:
"func", "func()", "func(int)", "a::func()", "b::func()", and "a::b::func()" down to just "func", "func()", "func(int)". Previously we would have set 6 breakpoints, now we correctly set just 3. This also extends to the expression parser when it looks up names for functions it needs to not get multiple results so we can call the correct function.
<rdar://problem/24599697>
llvm-svn: 275281
2016-07-14 01:12:24 +08:00
|
|
|
s->Printf("}");
|
2015-11-07 06:48:59 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-11-07 06:48:59 +08:00
|
|
|
if (m_language != eLanguageTypeUnknown) {
|
|
|
|
s->Printf(", language = %s", Language::GetNameForLanguageType(m_language));
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointResolverName::Dump(Stream *s) const {}
|
|
|
|
|
2014-12-06 09:28:03 +08:00
|
|
|
lldb::BreakpointResolverSP
|
|
|
|
BreakpointResolverName::CopyForBreakpoint(Breakpoint &breakpoint) {
|
|
|
|
lldb::BreakpointResolverSP ret_sp(new BreakpointResolverName(*this));
|
|
|
|
ret_sp->SetBreakpoint(&breakpoint);
|
|
|
|
return ret_sp;
|
|
|
|
}
|