Make lldb::Regex use StringRef.

This updates getters and setters to use StringRef instead of
const char *.  I tested the build on Linux, Windows, and OSX
and saw no build or test failures.  I cannot test any BSD
or Android variants, however I expect the required changes
to be minimal or non-existant.

llvm-svn: 282079
This commit is contained in:
Zachary Turner 2016-09-21 16:01:28 +00:00
parent 07171f21d1
commit 95eae4235d
49 changed files with 232 additions and 194 deletions

View File

@ -236,7 +236,9 @@ protected:
/// so, and then set
/// breakpoint locations in this breakpoint for all the resultant addresses.
void SetSCMatchesByLine(SearchFilter &filter, SymbolContextList &sc_list,
bool skip_prologue, const char *log_ident);
bool skip_prologue, llvm::StringRef log_ident);
void SetSCMatchesByLine(SearchFilter &, SymbolContextList &, bool,
const char *) = delete;
lldb::BreakpointLocationSP AddLocation(Address loc_addr,
bool *new_location = NULL);

View File

@ -99,7 +99,8 @@ public:
//------------------------------------------------------------------
RegularExpression();
explicit RegularExpression(const char *re);
explicit RegularExpression(llvm::StringRef string);
explicit RegularExpression(const char *) = delete;
//------------------------------------------------------------------
/// Destructor.
@ -131,7 +132,8 @@ public:
/// \b true if the regular expression compiles successfully,
/// \b false otherwise.
//------------------------------------------------------------------
bool Compile(const char *re);
bool Compile(llvm::StringRef string);
bool Compile(const char *) = delete;
//------------------------------------------------------------------
/// Executes a regular expression.
@ -154,7 +156,8 @@ public:
/// \b true if \a string matches the compiled regular
/// expression, \b false otherwise.
//------------------------------------------------------------------
bool Execute(const char *string, Match *match = nullptr) const;
bool Execute(llvm::StringRef string, Match *match = nullptr) const;
bool Execute(const char *, Match * = nullptr) = delete;
size_t GetErrorAsCString(char *err_str, size_t err_str_max_len) const;
@ -176,7 +179,7 @@ public:
/// The NULL terminated C string that was used to compile the
/// current regular expression
//------------------------------------------------------------------
const char *GetText() const;
llvm::StringRef GetText() const;
//------------------------------------------------------------------
/// Test if valid.

View File

@ -123,7 +123,7 @@ public:
/// The number of bytes that were appended to the stream.
//------------------------------------------------------------------
size_t PrintfAsRawHex8(const char *format, ...)
__attribute__((format(printf, 2, 3)));
__attribute__((__format__(__printf__, 2, 3)));
//------------------------------------------------------------------
/// Format a C string from a printf style format and variable

View File

@ -259,7 +259,7 @@ protected:
MapIterator pos, end = m_format_map.map().end();
for (pos = m_format_map.map().begin(); pos != end; pos++) {
lldb::RegularExpressionSP regex = pos->first;
if (::strcmp(type.AsCString(), regex->GetText()) == 0) {
if (type.GetStringRef() == regex->GetText()) {
m_format_map.map().erase(pos);
if (m_format_map.listener)
m_format_map.listener->Changed();
@ -295,19 +295,17 @@ protected:
if (regex.get() == nullptr)
return lldb::TypeNameSpecifierImplSP();
return lldb::TypeNameSpecifierImplSP(
new TypeNameSpecifierImpl(regex->GetText(), true));
new TypeNameSpecifierImpl(regex->GetText().str().c_str(), true));
}
bool Get_Impl(ConstString key, MapValueType &value,
lldb::RegularExpressionSP *dummy) {
const char *key_cstr = key.AsCString();
if (!key_cstr)
return false;
llvm::StringRef key_str = key.GetStringRef();
std::lock_guard<std::recursive_mutex> guard(m_format_map.mutex());
MapIterator pos, end = m_format_map.map().end();
for (pos = m_format_map.map().begin(); pos != end; pos++) {
lldb::RegularExpressionSP regex = pos->first;
if (regex->Execute(key_cstr)) {
if (regex->Execute(key_str)) {
value = pos->second;
return true;
}
@ -321,7 +319,7 @@ protected:
MapIterator pos, end = m_format_map.map().end();
for (pos = m_format_map.map().begin(); pos != end; pos++) {
lldb::RegularExpressionSP regex = pos->first;
if (strcmp(regex->GetText(), key.AsCString()) == 0) {
if (regex->GetText() == key.GetStringRef()) {
value = pos->second;
return true;
}

View File

@ -22,7 +22,7 @@ namespace lldb_private {
class OptionValueRegex : public OptionValue {
public:
OptionValueRegex(const char *value = nullptr)
: OptionValue(), m_regex(value) {}
: OptionValue(), m_regex(llvm::StringRef::withNullAsEmpty(value)) {}
~OptionValueRegex() override = default;
@ -56,7 +56,7 @@ public:
void SetCurrentValue(const char *value) {
if (value && value[0])
m_regex.Compile(value);
m_regex.Compile(llvm::StringRef(value));
else
m_regex.Clear();
}

View File

@ -110,8 +110,10 @@ public:
}
const char *GetCurrentValue() const { return m_current_value.c_str(); }
llvm::StringRef GetCurrentValueAsRef() const { return m_current_value; }
const char *GetDefaultValue() const { return m_default_value.c_str(); }
llvm::StringRef GetDefaultValueAsRef() const { return m_default_value; }
Error SetCurrentValue(const char *value);

View File

@ -869,7 +869,7 @@ lldb::SBBreakpoint SBTarget::BreakpointCreateByRegex(
TargetSP target_sp(GetSP());
if (target_sp && symbol_name_regex && symbol_name_regex[0]) {
std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
RegularExpression regexp(symbol_name_regex);
RegularExpression regexp((llvm::StringRef(symbol_name_regex)));
const bool internal = false;
const bool hardware = false;
const LazyBool skip_prologue = eLazyBoolCalculate;
@ -978,7 +978,7 @@ lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
const bool hardware = false;
const LazyBool move_to_nearest_code = eLazyBoolCalculate;
RegularExpression regexp(source_regex);
RegularExpression regexp((llvm::StringRef(source_regex)));
std::unordered_set<std::string> func_names_set;
for (size_t i = 0; i < func_names.GetSize(); i++) {
func_names_set.insert(func_names.GetStringAtIndex(i));
@ -1599,18 +1599,19 @@ lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name,
MatchType matchtype) {
lldb::SBSymbolContextList sb_sc_list;
if (name && name[0]) {
llvm::StringRef name_ref(name);
TargetSP target_sp(GetSP());
if (target_sp) {
std::string regexstr;
switch (matchtype) {
case eMatchTypeRegex:
target_sp->GetImages().FindFunctions(RegularExpression(name), true,
target_sp->GetImages().FindFunctions(RegularExpression(name_ref), true,
true, true, *sb_sc_list);
break;
case eMatchTypeStartsWith:
regexstr = llvm::Regex::escape(name) + ".*";
target_sp->GetImages().FindFunctions(
RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list);
target_sp->GetImages().FindFunctions(RegularExpression(regexstr), true,
true, true, *sb_sc_list);
break;
default:
target_sp->GetImages().FindFunctions(ConstString(name),
@ -1778,6 +1779,7 @@ SBValueList SBTarget::FindGlobalVariables(const char *name,
TargetSP target_sp(GetSP());
if (name && target_sp) {
llvm::StringRef name_ref(name);
VariableList variable_list;
const bool append = true;
@ -1790,13 +1792,12 @@ SBValueList SBTarget::FindGlobalVariables(const char *name,
break;
case eMatchTypeRegex:
match_count = target_sp->GetImages().FindGlobalVariables(
RegularExpression(name), append, max_matches, variable_list);
RegularExpression(name_ref), append, max_matches, variable_list);
break;
case eMatchTypeStartsWith:
regexstr = llvm::Regex::escape(name) + ".*";
match_count = target_sp->GetImages().FindGlobalVariables(
RegularExpression(regexstr.c_str()), append, max_matches,
variable_list);
RegularExpression(regexstr), append, max_matches, variable_list);
break;
}

View File

@ -301,7 +301,8 @@ bool SBTypeCategory::AddTypeFormat(SBTypeNameSpecifier type_name,
if (type_name.IsRegex())
m_opaque_sp->GetRegexTypeFormatsContainer()->Add(
lldb::RegularExpressionSP(new RegularExpression(type_name.GetName())),
lldb::RegularExpressionSP(new RegularExpression(
llvm::StringRef::withNullAsEmpty(type_name.GetName()))),
format.GetSP());
else
m_opaque_sp->GetTypeFormatsContainer()->Add(
@ -373,7 +374,8 @@ bool SBTypeCategory::AddTypeSummary(SBTypeNameSpecifier type_name,
if (type_name.IsRegex())
m_opaque_sp->GetRegexTypeSummariesContainer()->Add(
lldb::RegularExpressionSP(new RegularExpression(type_name.GetName())),
lldb::RegularExpressionSP(new RegularExpression(
llvm::StringRef::withNullAsEmpty(type_name.GetName()))),
summary.GetSP());
else
m_opaque_sp->GetTypeSummariesContainer()->Add(
@ -411,7 +413,8 @@ bool SBTypeCategory::AddTypeFilter(SBTypeNameSpecifier type_name,
if (type_name.IsRegex())
m_opaque_sp->GetRegexTypeFiltersContainer()->Add(
lldb::RegularExpressionSP(new RegularExpression(type_name.GetName())),
lldb::RegularExpressionSP(new RegularExpression(
llvm::StringRef::withNullAsEmpty(type_name.GetName()))),
filter.GetSP());
else
m_opaque_sp->GetTypeFiltersContainer()->Add(
@ -483,7 +486,8 @@ bool SBTypeCategory::AddTypeSynthetic(SBTypeNameSpecifier type_name,
if (type_name.IsRegex())
m_opaque_sp->GetRegexTypeSyntheticsContainer()->Add(
lldb::RegularExpressionSP(new RegularExpression(type_name.GetName())),
lldb::RegularExpressionSP(new RegularExpression(
llvm::StringRef::withNullAsEmpty(type_name.GetName()))),
synth.GetSP());
else
m_opaque_sp->GetTypeSyntheticsContainer()->Add(

View File

@ -179,7 +179,7 @@ void BreakpointResolver::ResolveBreakpoint(SearchFilter &filter) {
void BreakpointResolver::SetSCMatchesByLine(SearchFilter &filter,
SymbolContextList &sc_list,
bool skip_prologue,
const char *log_ident) {
llvm::StringRef log_ident) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
while (sc_list.GetSize() > 0) {
@ -293,15 +293,14 @@ void BreakpointResolver::SetSCMatchesByLine(SearchFilter &filter,
} else if (log) {
log->Printf("Breakpoint %s at file address 0x%" PRIx64
" didn't pass the filter.\n",
log_ident ? log_ident : "",
line_start.GetFileAddress());
log_ident.str().c_str(), line_start.GetFileAddress());
}
} else {
if (log)
log->Printf(
"error: Unable to set breakpoint %s at file address 0x%" PRIx64
"\n",
log_ident ? log_ident : "", line_start.GetFileAddress());
log_ident.str().c_str(), line_start.GetFileAddress());
}
}
}

View File

@ -150,7 +150,7 @@ BreakpointResolverFileLine::SearchCallback(SearchFilter &filter,
s.Printf("for %s:%d ", m_file_spec.GetFilename().AsCString("<Unknown>"),
m_line_number);
SetSCMatchesByLine(filter, sc_list, m_skip_prologue, s.GetData());
SetSCMatchesByLine(filter, sc_list, m_skip_prologue, s.GetString());
return Searcher::eCallbackReturnContinue;
}

View File

@ -1,5 +1,4 @@
//===-- BreakpointResolverFileRegex.cpp --------------------------*- C++
//-*-===//
//===-- BreakpointResolverFileRegex.cpp -------------------------*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
@ -48,7 +47,7 @@ BreakpointResolver *BreakpointResolverFileRegex::CreateFromStructuredData(
error.SetErrorString("BRFR::CFSD: Couldn't find regex entry.");
return nullptr;
}
RegularExpression regex(regex_string.c_str());
RegularExpression regex(regex_string);
bool exact_match;
success = options_dict.GetValueForKeyAsBoolean(
@ -163,8 +162,8 @@ Searcher::Depth BreakpointResolverFileRegex::GetDepth() {
}
void BreakpointResolverFileRegex::GetDescription(Stream *s) {
s->Printf("source regex = \"%s\", exact_match = %d", m_regex.GetText(),
m_exact_match);
s->Printf("source regex = \"%s\", exact_match = %d",
m_regex.GetText().str().c_str(), m_exact_match);
}
void BreakpointResolverFileRegex::Dump(Stream *s) const {}

View File

@ -35,7 +35,7 @@ BreakpointResolverName::BreakpointResolverName(
m_class_name(), m_regex(), m_match_type(type), m_language(language),
m_skip_prologue(skip_prologue) {
if (m_match_type == Breakpoint::Regexp) {
if (!m_regex.Compile(name_cstr)) {
if (!m_regex.Compile(llvm::StringRef::withNullAsEmpty(name_cstr))) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
if (log)
@ -126,7 +126,7 @@ BreakpointResolver *BreakpointResolverName::CreateFromStructuredData(
success = options_dict.GetValueForKeyAsString(
GetKey(OptionNames::RegexString), regex_text);
if (success) {
RegularExpression regex(regex_text.c_str());
RegularExpression regex(regex_text);
return new BreakpointResolverName(bkpt, regex, language, offset,
skip_prologue);
} else {
@ -395,7 +395,7 @@ Searcher::Depth BreakpointResolverName::GetDepth() {
void BreakpointResolverName::GetDescription(Stream *s) {
if (m_match_type == Breakpoint::Regexp)
s->Printf("regex = '%s'", m_regex.GetText());
s->Printf("regex = '%s'", m_regex.GetText().str().c_str());
else {
size_t num_names = m_lookups.size();
if (num_names == 1)

View File

@ -511,7 +511,7 @@ CommandCompletions::SymbolCompleter::SymbolCompleter(
pos = regex_str.insert(pos, '\\');
pos = find_if(pos + 2, regex_str.end(), regex_chars);
}
m_regex.Compile(regex_str.c_str());
m_regex.Compile(regex_str);
}
Searcher::Depth CommandCompletions::SymbolCompleter::GetDepth() {

View File

@ -529,7 +529,7 @@ protected:
case eSetTypeFunctionRegexp: // Breakpoint by regular expression function
// name
{
RegularExpression regexp(m_options.m_func_regexp.c_str());
RegularExpression regexp(m_options.m_func_regexp);
if (!regexp.IsValid()) {
char err_str[1024];
regexp.GetErrorAsCString(err_str, sizeof(err_str));
@ -564,7 +564,7 @@ protected:
}
}
RegularExpression regexp(m_options.m_source_text_regexp.c_str());
RegularExpression regexp(m_options.m_source_text_regexp);
if (!regexp.IsValid()) {
char err_str[1024];
regexp.GetErrorAsCString(err_str, sizeof(err_str));

View File

@ -547,8 +547,9 @@ protected:
++idx) {
if (m_option_variable.use_regex) {
const size_t regex_start_index = regex_var_list.GetSize();
RegularExpression regex(name_cstr);
if (regex.Compile(name_cstr)) {
llvm::StringRef name_str(name_cstr);
RegularExpression regex(name_str);
if (regex.Compile(name_str)) {
size_t num_matches = 0;
const size_t num_new_regex_vars =
variable_list->AppendVariablesIfUnique(regex, regex_var_list,

View File

@ -807,7 +807,7 @@ protected:
size_t matches = 0;
bool use_var_name = false;
if (m_option_variable.use_regex) {
RegularExpression regex(arg);
RegularExpression regex(llvm::StringRef::withNullAsEmpty(arg));
if (!regex.IsValid()) {
result.GetErrorStream().Printf(
"error: invalid regular expression: '%s'\n", arg);
@ -941,7 +941,8 @@ protected:
} else if (sc.module_sp) {
// Get all global variables for this module
lldb_private::RegularExpression all_globals_regex(
"."); // Any global with at least one character
llvm::StringRef(
".")); // Any global with at least one character
VariableList variable_list;
sc.module_sp->FindGlobalVariables(all_globals_regex, append,
UINT32_MAX, variable_list);
@ -1517,7 +1518,7 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
ConstString symbol_name(name);
uint32_t num_matches = 0;
if (name_is_regex) {
RegularExpression name_regexp(name);
RegularExpression name_regexp(symbol_name.GetStringRef());
num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType(
name_regexp, eSymbolTypeAny, match_indexes);
} else {
@ -1579,7 +1580,7 @@ static size_t LookupFunctionInModule(CommandInterpreter &interpreter,
const bool append = true;
size_t num_matches = 0;
if (name_is_regex) {
RegularExpression function_name_regex(name);
RegularExpression function_name_regex((llvm::StringRef(name)));
num_matches = module->FindFunctions(function_name_regex, include_symbols,
include_inlines, append, sc_list);
} else {

View File

@ -697,7 +697,7 @@ protected:
if (typeCS) {
if (m_command_options.m_regex) {
RegularExpressionSP typeRX(new RegularExpression());
if (!typeRX->Compile(typeCS.GetCString())) {
if (!typeRX->Compile(typeCS.GetStringRef())) {
result.AppendError(
"regex format error (maybe this is not really a regex?)");
result.SetStatus(eReturnStatusFailed);
@ -1102,10 +1102,10 @@ protected:
if (m_options.m_category_regex.OptionWasSet()) {
category_regex.reset(new RegularExpression());
if (!category_regex->Compile(
m_options.m_category_regex.GetCurrentValue())) {
m_options.m_category_regex.GetCurrentValueAsRef())) {
result.AppendErrorWithFormat(
"syntax error in category regular expression '%s'",
m_options.m_category_regex.GetCurrentValue());
m_options.m_category_regex.GetCurrentValueAsRef().str().c_str());
result.SetStatus(eReturnStatusFailed);
return false;
}
@ -1114,7 +1114,7 @@ protected:
if (argc == 1) {
const char *arg = command.GetArgumentAtIndex(0);
formatter_regex.reset(new RegularExpression());
if (!formatter_regex->Compile(arg)) {
if (!formatter_regex->Compile(llvm::StringRef::withNullAsEmpty(arg))) {
result.AppendErrorWithFormat("syntax error in regular expression '%s'",
arg);
result.SetStatus(eReturnStatusFailed);
@ -1137,9 +1137,9 @@ protected:
const FormatterSharedPointer &format_sp) -> bool {
if (formatter_regex) {
bool escape = true;
if (0 == strcmp(name.AsCString(), formatter_regex->GetText())) {
if (name.GetStringRef() == formatter_regex->GetText()) {
escape = false;
} else if (formatter_regex->Execute(name.AsCString())) {
} else if (formatter_regex->Execute(name.GetStringRef())) {
escape = false;
}
@ -1159,7 +1159,7 @@ protected:
const FormatterSharedPointer &format_sp) -> bool {
if (formatter_regex) {
bool escape = true;
if (0 == strcmp(regex_sp->GetText(), formatter_regex->GetText())) {
if (regex_sp->GetText() == formatter_regex->GetText()) {
escape = false;
} else if (formatter_regex->Execute(regex_sp->GetText())) {
escape = false;
@ -1170,7 +1170,8 @@ protected:
}
any_printed = true;
result.GetOutputStream().Printf("%s: %s\n", regex_sp->GetText(),
result.GetOutputStream().Printf("%s: %s\n",
regex_sp->GetText().str().c_str(),
format_sp->GetDescription().c_str());
return true;
});
@ -1191,9 +1192,11 @@ protected:
const lldb::TypeCategoryImplSP &category) -> bool {
if (category_regex) {
bool escape = true;
if (0 == strcmp(category->GetName(), category_regex->GetText())) {
if (category->GetName() == category_regex->GetText()) {
escape = false;
} else if (category_regex->Execute(category->GetName())) {
} else if (category_regex->Execute(
llvm::StringRef::withNullAsEmpty(
category->GetName()))) {
escape = false;
}
@ -1693,7 +1696,7 @@ bool CommandObjectTypeSummaryAdd::AddSummary(ConstString type_name,
if (type == eRegexSummary) {
RegularExpressionSP typeRX(new RegularExpression());
if (!typeRX->Compile(type_name.GetCString())) {
if (!typeRX->Compile(type_name.GetStringRef())) {
if (error)
error->SetErrorString(
"regex format error (maybe this is not really a regex?)");
@ -2242,7 +2245,7 @@ protected:
if (argc == 1) {
regex.reset(new RegularExpression());
const char *arg = command.GetArgumentAtIndex(0);
if (!regex->Compile(arg)) {
if (!regex->Compile(llvm::StringRef::withNullAsEmpty(arg))) {
result.AppendErrorWithFormat(
"syntax error in category regular expression '%s'", arg);
result.SetStatus(eReturnStatusFailed);
@ -2259,9 +2262,10 @@ protected:
[&regex, &result](const lldb::TypeCategoryImplSP &category_sp) -> bool {
if (regex) {
bool escape = true;
if (0 == strcmp(category_sp->GetName(), regex->GetText())) {
if (regex->GetText() == category_sp->GetName()) {
escape = false;
} else if (regex->Execute(category_sp->GetName())) {
} else if (regex->Execute(llvm::StringRef::withNullAsEmpty(
category_sp->GetName()))) {
escape = false;
}
@ -2510,7 +2514,7 @@ bool CommandObjectTypeSynthAdd::AddSynth(ConstString type_name,
if (type == eRegexSynth) {
RegularExpressionSP typeRX(new RegularExpression());
if (!typeRX->Compile(type_name.GetCString())) {
if (!typeRX->Compile(type_name.GetStringRef())) {
if (error)
error->SetErrorString(
"regex format error (maybe this is not really a regex?)");
@ -2652,7 +2656,7 @@ private:
if (type == eRegexFilter) {
RegularExpressionSP typeRX(new RegularExpression());
if (!typeRX->Compile(type_name.GetCString())) {
if (!typeRX->Compile(type_name.GetStringRef())) {
if (error)
error->SetErrorString(
"regex format error (maybe this is not really a regex?)");

View File

@ -28,7 +28,7 @@ AddressResolverName::AddressResolverName(const char *func_name,
: AddressResolver(), m_func_name(func_name), m_class_name(nullptr),
m_regex(), m_match_type(type) {
if (m_match_type == AddressResolver::Regexp) {
if (!m_regex.Compile(m_func_name.AsCString())) {
if (!m_regex.Compile(m_func_name.GetStringRef())) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
if (log)
@ -186,7 +186,7 @@ void AddressResolverName::GetDescription(Stream *s) {
s->PutCString("Address by function name: ");
if (m_match_type == AddressResolver::Regexp)
s->Printf("'%s' (regular expression)", m_regex.GetText());
s->Printf("'%s' (regular expression)", m_regex.GetText().str().c_str());
else
s->Printf("'%s'", m_func_name.AsCString());
}

View File

@ -781,9 +781,10 @@ OptionValueSP Instruction::ReadArray(FILE *in_file, Stream *out_stream,
if (!line.empty()) {
std::string value;
static RegularExpression g_reg_exp("^[ \t]*([^ \t]+)[ \t]*$");
static RegularExpression g_reg_exp(
llvm::StringRef("^[ \t]*([^ \t]+)[ \t]*$"));
RegularExpression::Match regex_match(1);
bool reg_exp_success = g_reg_exp.Execute(line.c_str(), &regex_match);
bool reg_exp_success = g_reg_exp.Execute(line, &regex_match);
if (reg_exp_success)
regex_match.GetMatchAtIndex(line.c_str(), 1, value);
else
@ -843,11 +844,11 @@ OptionValueSP Instruction::ReadDictionary(FILE *in_file, Stream *out_stream) {
// Try to find a key-value pair in the current line and add it to the
// dictionary.
if (!line.empty()) {
static RegularExpression g_reg_exp(
"^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*=[ \t]*(.*)[ \t]*$");
static RegularExpression g_reg_exp(llvm::StringRef(
"^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)[ \t]*=[ \t]*(.*)[ \t]*$"));
RegularExpression::Match regex_match(2);
bool reg_exp_success = g_reg_exp.Execute(line.c_str(), &regex_match);
bool reg_exp_success = g_reg_exp.Execute(line, &regex_match);
std::string key;
std::string value;
if (reg_exp_success) {

View File

@ -1398,7 +1398,7 @@ size_t Module::FindSymbolsMatchingRegExAndType(const RegularExpression &regex,
Timer scoped_timer(
LLVM_PRETTY_FUNCTION,
"Module::FindSymbolsMatchingRegExAndType (regex = %s, type = %i)",
regex.GetText(), symbol_type);
regex.GetText().str().c_str(), symbol_type);
const size_t initial_size = sc_list.GetSize();
SymbolVendor *sym_vendor = GetSymbolVendor();
if (sym_vendor) {

View File

@ -40,10 +40,10 @@ RegularExpression::RegularExpression() : m_re(), m_comp_err(1), m_preg() {
// Constructor that compiles "re" using "flags" and stores the
// resulting compiled regular expression into this object.
//----------------------------------------------------------------------
RegularExpression::RegularExpression(const char *re)
RegularExpression::RegularExpression(llvm::StringRef str)
: m_re(), m_comp_err(1), m_preg() {
memset(&m_preg, 0, sizeof(m_preg));
Compile(re);
Compile(str);
}
RegularExpression::RegularExpression(const RegularExpression &rhs) {
@ -78,12 +78,12 @@ RegularExpression::~RegularExpression() { Free(); }
// True if the regular expression compiles successfully, false
// otherwise.
//----------------------------------------------------------------------
bool RegularExpression::Compile(const char *re) {
bool RegularExpression::Compile(llvm::StringRef str) {
Free();
if (re && re[0]) {
m_re = re;
m_comp_err = ::regcomp(&m_preg, re, DEFAULT_COMPILE_FLAGS);
if (!str.empty()) {
m_re = str;
m_comp_err = ::regcomp(&m_preg, m_re.c_str(), DEFAULT_COMPILE_FLAGS);
} else {
// No valid regular expression
m_comp_err = 1;
@ -100,13 +100,16 @@ bool RegularExpression::Compile(const char *re) {
// values that are present in "match_ptr". The regular expression
// will be executed using the "execute_flags".
//---------------------------------------------------------------------
bool RegularExpression::Execute(const char *s, Match *match) const {
bool RegularExpression::Execute(llvm::StringRef str, Match *match) const {
int err = 1;
if (s != nullptr && m_comp_err == 0) {
if (!str.empty() && m_comp_err == 0) {
// Argument to regexec must be null-terminated.
std::string reg_str = str;
if (match) {
err = ::regexec(&m_preg, s, match->GetSize(), match->GetData(), 0);
err = ::regexec(&m_preg, reg_str.c_str(), match->GetSize(),
match->GetData(), 0);
} else {
err = ::regexec(&m_preg, s, 0, nullptr, 0);
err = ::regexec(&m_preg, reg_str.c_str(), 0, nullptr, 0);
}
}
@ -176,9 +179,7 @@ bool RegularExpression::IsValid() const { return m_comp_err == 0; }
// Returns the text that was used to compile the current regular
// expression.
//----------------------------------------------------------------------
const char *RegularExpression::GetText() const {
return (m_re.empty() ? nullptr : m_re.c_str());
}
llvm::StringRef RegularExpression::GetText() const { return m_re; }
//----------------------------------------------------------------------
// Free any contained compiled regular expressions.

View File

@ -464,7 +464,7 @@ void SourceManager::File::FindLinesMatchingRegex(
std::string buffer;
if (!GetLine(line_no, buffer))
break;
if (regex.Execute(buffer.c_str())) {
if (regex.Execute(buffer)) {
match_lines.push_back(line_no);
}
}

View File

@ -1003,9 +1003,9 @@ void FormatManager::LoadSystemFormatters() {
new StringSummaryFormat(string_array_flags, "${var%s}"));
lldb::RegularExpressionSP any_size_char_arr(
new RegularExpression("char \\[[0-9]+\\]"));
new RegularExpression(llvm::StringRef("char \\[[0-9]+\\]")));
lldb::RegularExpressionSP any_size_wchar_arr(
new RegularExpression("wchar_t \\[[0-9]+\\]"));
new RegularExpression(llvm::StringRef("wchar_t \\[[0-9]+\\]")));
TypeCategoryImpl::SharedPointer sys_category_sp =
GetCategory(m_system_category_name);

View File

@ -34,7 +34,7 @@ void lldb_private::formatters::AddFormat(
if (regex)
category_sp->GetRegexTypeFormatsContainer()->Add(
RegularExpressionSP(new RegularExpression(type_name.AsCString())),
RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
format_sp);
else
category_sp->GetTypeFormatsContainer()->Add(type_name, format_sp);
@ -45,7 +45,7 @@ void lldb_private::formatters::AddSummary(
ConstString type_name, bool regex) {
if (regex)
category_sp->GetRegexTypeSummariesContainer()->Add(
RegularExpressionSP(new RegularExpression(type_name.AsCString())),
RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
summary_sp);
else
category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
@ -58,7 +58,7 @@ void lldb_private::formatters::AddStringSummary(
if (regex)
category_sp->GetRegexTypeSummariesContainer()->Add(
RegularExpressionSP(new RegularExpression(type_name.AsCString())),
RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
summary_sp);
else
category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
@ -72,7 +72,7 @@ void lldb_private::formatters::AddOneLineSummary(
if (regex)
category_sp->GetRegexTypeSummariesContainer()->Add(
RegularExpressionSP(new RegularExpression(type_name.AsCString())),
RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
summary_sp);
else
category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
@ -87,7 +87,7 @@ void lldb_private::formatters::AddCXXSummary(
new CXXFunctionSummaryFormat(flags, funct, description));
if (regex)
category_sp->GetRegexTypeSummariesContainer()->Add(
RegularExpressionSP(new RegularExpression(type_name.AsCString())),
RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
summary_sp);
else
category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
@ -102,7 +102,7 @@ void lldb_private::formatters::AddCXXSynthetic(
new CXXSyntheticChildren(flags, description, generator));
if (regex)
category_sp->GetRegexTypeSyntheticsContainer()->Add(
RegularExpressionSP(new RegularExpression(type_name.AsCString())),
RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
synth_sp);
else
category_sp->GetTypeSyntheticsContainer()->Add(type_name, synth_sp);
@ -117,7 +117,7 @@ void lldb_private::formatters::AddFilter(
filter_sp->AddExpressionPath(child);
if (regex)
category_sp->GetRegexTypeFiltersContainer()->Add(
RegularExpressionSP(new RegularExpression(type_name.AsCString())),
RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
filter_sp);
else
category_sp->GetTypeFiltersContainer()->Add(type_name, filter_sp);

View File

@ -1422,15 +1422,15 @@ void FileSpec::RemoveLastPathComponent() {
//------------------------------------------------------------------
bool FileSpec::IsSourceImplementationFile() const {
ConstString extension(GetFileNameExtension());
if (extension) {
static RegularExpression g_source_file_regex(
"^([cC]|[mM]|[mM][mM]|[cC][pP][pP]|[cC]\\+\\+|[cC][xX][xX]|[cC][cC]|["
"cC][pP]|[sS]|[aA][sS][mM]|[fF]|[fF]77|[fF]90|[fF]95|[fF]03|[fF][oO]["
"rR]|[fF][tT][nN]|[fF][pP][pP]|[aA][dD][aA]|[aA][dD][bB]|[aA][dD][sS])"
"$");
return g_source_file_regex.Execute(extension.GetCString());
}
return false;
if (!extension)
return false;
static RegularExpression g_source_file_regex(llvm::StringRef(
"^([cC]|[mM]|[mM][mM]|[cC][pP][pP]|[cC]\\+\\+|[cC][xX][xX]|[cC][cC]|["
"cC][pP]|[sS]|[aA][sS][mM]|[fF]|[fF]77|[fF]90|[fF]95|[fF]03|[fF][oO]["
"rR]|[fF][tT][nN]|[fF][pP][pP]|[aA][dD][aA]|[aA][dD][bB]|[aA][dD][sS])"
"$"));
return g_source_file_regex.Execute(extension.GetStringRef());
}
bool FileSpec::IsRelative() const {

View File

@ -253,9 +253,9 @@ Error Socket::UnixAbstractAccept(llvm::StringRef name,
bool Socket::DecodeHostAndPort(llvm::StringRef host_and_port,
std::string &host_str, std::string &port_str,
int32_t &port, Error *error_ptr) {
static RegularExpression g_regex("([^:]+):([0-9]+)");
static RegularExpression g_regex(llvm::StringRef("([^:]+):([0-9]+)"));
RegularExpression::Match regex_match(2);
if (g_regex.Execute(host_and_port.data(), &regex_match)) {
if (g_regex.Execute(host_and_port, &regex_match)) {
if (regex_match.GetMatchAtIndex(host_and_port.data(), 1, host_str) &&
regex_match.GetMatchAtIndex(host_and_port.data(), 2, port_str)) {
bool ok = false;

View File

@ -608,6 +608,8 @@ lldb::addr_t Args::StringToAddress(const ExecutionContext *exe_ctx,
Error *error_ptr) {
bool error_set = false;
if (s && s[0]) {
llvm::StringRef sref = s;
char *end = nullptr;
lldb::addr_t addr = ::strtoull(s, &end, 0);
if (*end == '\0') {
@ -662,10 +664,10 @@ lldb::addr_t Args::StringToAddress(const ExecutionContext *exe_ctx,
// Since the compiler can't handle things like "main + 12" we should
// try to do this for now. The compiler doesn't like adding offsets
// to function pointer types.
static RegularExpression g_symbol_plus_offset_regex(
"^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$");
static RegularExpression g_symbol_plus_offset_regex(llvm::StringRef(
"^(.*)([-\\+])[[:space:]]*(0x[0-9A-Fa-f]+|[0-9]+)[[:space:]]*$"));
RegularExpression::Match regex_match(3);
if (g_symbol_plus_offset_regex.Execute(s, &regex_match)) {
if (g_symbol_plus_offset_regex.Execute(sref, &regex_match)) {
uint64_t offset = 0;
bool add = true;
std::string name;

View File

@ -89,7 +89,8 @@ bool CommandObjectRegexCommand::AddRegexCommand(const char *re_cstr,
const char *command_cstr) {
m_entries.resize(m_entries.size() + 1);
// Only add the regular expression if it compiles
if (m_entries.back().regex.Compile(re_cstr)) {
if (m_entries.back().regex.Compile(
llvm::StringRef::withNullAsEmpty(re_cstr))) {
m_entries.back().command.assign(command_cstr);
return true;
}

View File

@ -26,10 +26,8 @@ void OptionValueRegex::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
if (dump_mask & eDumpOptionType)
strm.PutCString(" = ");
if (m_regex.IsValid()) {
const char *regex_text = m_regex.GetText();
if (regex_text && regex_text[0])
strm.Printf("%s", regex_text);
} else {
llvm::StringRef regex_text = m_regex.GetText();
strm.Printf("%s", regex_text.str().c_str());
}
}
}
@ -53,7 +51,7 @@ Error OptionValueRegex::SetValueFromString(llvm::StringRef value,
case eVarSetOperationReplace:
case eVarSetOperationAssign:
if (m_regex.Compile(value.str().c_str())) {
if (m_regex.Compile(value)) {
m_value_was_set = true;
NotifyValueChanged();
} else {
@ -70,5 +68,5 @@ Error OptionValueRegex::SetValueFromString(llvm::StringRef value,
}
lldb::OptionValueSP OptionValueRegex::DeepCopy() const {
return OptionValueSP(new OptionValueRegex(m_regex.GetText()));
return OptionValueSP(new OptionValueRegex(m_regex.GetText().str().c_str()));
}

View File

@ -371,11 +371,12 @@ public:
}
}
static RegularExpression s_regex("[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?");
static RegularExpression s_regex(
llvm::StringRef("[ \t]*([^ ^\t]+)[ \t]*([^ ^\t].*)?"));
RegularExpression::Match matches(3);
if (s_regex.Execute(out_string.c_str(), &matches)) {
if (s_regex.Execute(out_string, &matches)) {
matches.GetMatchAtIndex(out_string.c_str(), 1, m_opcode_name);
matches.GetMatchAtIndex(out_string.c_str(), 2, m_mnemonics);
}

View File

@ -999,7 +999,7 @@ size_t DynamicLoaderDarwin::FindEquivalentSymbols(
equivalent_regex_buf.append(trampoline_name.GetCString());
equivalent_regex_buf.append(resolver_name_regex);
RegularExpression equivalent_name_regex(equivalent_regex_buf.c_str());
RegularExpression equivalent_name_regex(equivalent_regex_buf);
const bool append = true;
images.FindSymbolsMatchingRegExAndType(equivalent_name_regex, eSymbolTypeCode,
equivalent_symbols, append);

View File

@ -57,7 +57,8 @@ AddressSanitizerRuntime::~AddressSanitizerRuntime() { Deactivate(); }
const RegularExpression &
AddressSanitizerRuntime::GetPatternForRuntimeLibrary() {
// FIXME: This shouldn't include the "dylib" suffix.
static RegularExpression regex("libclang_rt.asan_(.*)_dynamic\\.dylib");
static RegularExpression regex(
llvm::StringRef("libclang_rt.asan_(.*)_dynamic\\.dylib"));
return regex;
}

View File

@ -832,7 +832,7 @@ bool ThreadSanitizerRuntime::NotifyBreakpointHit(
}
const RegularExpression &ThreadSanitizerRuntime::GetPatternForRuntimeLibrary() {
static RegularExpression regex("libclang_rt.tsan_");
static RegularExpression regex(llvm::StringRef("libclang_rt.tsan_"));
return regex;
}

View File

@ -153,12 +153,13 @@ static bool IsValidBasename(const llvm::StringRef &basename) {
if (!basename.startswith("operator"))
return false;
static RegularExpression g_operator_regex("^(operator)( "
"?)([A-Za-z_][A-Za-z_0-9]*|\\(\\)|"
"\\[\\]|[\\^<>=!\\/"
"*+-]+)(<.*>)?(\\[\\])?$");
static RegularExpression g_operator_regex(
llvm::StringRef("^(operator)( "
"?)([A-Za-z_][A-Za-z_0-9]*|\\(\\)|"
"\\[\\]|[\\^<>=!\\/"
"*+-]+)(<.*>)?(\\[\\])?$"));
std::string basename_str(basename.str());
return g_operator_regex.Execute(basename_str.c_str(), nullptr);
return g_operator_regex.Execute(basename_str, nullptr);
}
void CPlusPlusLanguage::MethodName::Parse() {
@ -289,10 +290,11 @@ bool CPlusPlusLanguage::IsCPPMangledName(const char *name) {
bool CPlusPlusLanguage::ExtractContextAndIdentifier(
const char *name, llvm::StringRef &context, llvm::StringRef &identifier) {
static RegularExpression g_basename_regex(
"^(([A-Za-z_][A-Za-z_0-9]*::)*)(~?[A-Za-z_~][A-Za-z_0-9]*)$");
static RegularExpression g_basename_regex(llvm::StringRef(
"^(([A-Za-z_][A-Za-z_0-9]*::)*)(~?[A-Za-z_~][A-Za-z_0-9]*)$"));
RegularExpression::Match match(4);
if (g_basename_regex.Execute(name, &match)) {
if (g_basename_regex.Execute(llvm::StringRef::withNullAsEmpty(name),
&match)) {
match.GetMatchAtIndex(name, 1, context);
match.GetMatchAtIndex(name, 3, identifier);
return true;
@ -564,8 +566,8 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
ConstString("^std::__(ndk)?1::atomic<.+>$"), stl_synth_flags, true);
cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
RegularExpressionSP(
new RegularExpression("^(std::__(ndk)?1::)deque<.+>(( )?&)?$")),
RegularExpressionSP(new RegularExpression(
llvm::StringRef("^(std::__(ndk)?1::)deque<.+>(( )?&)?$"))),
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_synth_flags,
"lldb.formatters.cpp.libcxx.stddeque_SynthProvider")));
@ -750,34 +752,38 @@ static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
false);
cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
RegularExpressionSP(new RegularExpression("^std::vector<.+>(( )?&)?$")),
RegularExpressionSP(
new RegularExpression(llvm::StringRef("^std::vector<.+>(( )?&)?$"))),
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_synth_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdVectorSynthProvider")));
cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
RegularExpressionSP(new RegularExpression("^std::map<.+> >(( )?&)?$")),
RegularExpressionSP(
new RegularExpression(llvm::StringRef("^std::map<.+> >(( )?&)?$"))),
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_synth_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdMapSynthProvider")));
cpp_category_sp->GetRegexTypeSyntheticsContainer()->Add(
RegularExpressionSP(
new RegularExpression("^std::(__cxx11::)?list<.+>(( )?&)?$")),
RegularExpressionSP(new RegularExpression(
llvm::StringRef("^std::(__cxx11::)?list<.+>(( )?&)?$"))),
SyntheticChildrenSP(new ScriptedSyntheticChildren(
stl_synth_flags,
"lldb.formatters.cpp.gnu_libstdcpp.StdListSynthProvider")));
stl_summary_flags.SetDontShowChildren(false);
stl_summary_flags.SetSkipPointers(true);
cpp_category_sp->GetRegexTypeSummariesContainer()->Add(
RegularExpressionSP(new RegularExpression("^std::vector<.+>(( )?&)?$")),
TypeSummaryImplSP(
new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->GetRegexTypeSummariesContainer()->Add(
RegularExpressionSP(new RegularExpression("^std::map<.+> >(( )?&)?$")),
RegularExpressionSP(
new RegularExpression(llvm::StringRef("^std::vector<.+>(( )?&)?$"))),
TypeSummaryImplSP(
new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->GetRegexTypeSummariesContainer()->Add(
RegularExpressionSP(
new RegularExpression("^std::(__cxx11::)?list<.+>(( )?&)?$")),
new RegularExpression(llvm::StringRef("^std::map<.+> >(( )?&)?$"))),
TypeSummaryImplSP(
new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));
cpp_category_sp->GetRegexTypeSummariesContainer()->Add(
RegularExpressionSP(new RegularExpression(
llvm::StringRef("^std::(__cxx11::)?list<.+>(( )?&)?$"))),
TypeSummaryImplSP(
new StringSummaryFormat(stl_summary_flags, "size=${svar%#}")));

View File

@ -70,7 +70,7 @@ lldb::TypeCategoryImplSP JavaLanguage::GetFormatters() {
std::call_once(g_initialize, [this]() -> void {
DataVisualization::Categories::GetCategory(GetPluginName(), g_category);
if (g_category) {
const char *array_regexp = "^.*\\[\\]&?$";
llvm::StringRef array_regexp("^.*\\[\\]&?$");
lldb::TypeSummaryImplSP string_summary_sp(new CXXFunctionSummaryFormat(
TypeSummaryImpl::Flags().SetDontShowChildren(true),

View File

@ -542,7 +542,8 @@ protected:
break;
case 1: {
regex_up.reset(new RegularExpression());
if (!regex_up->Compile(command.GetArgumentAtIndex(0))) {
if (!regex_up->Compile(llvm::StringRef::withNullAsEmpty(
command.GetArgumentAtIndex(0)))) {
result.AppendError(
"invalid argument - please provide a valid regular expression");
result.SetStatus(lldb::eReturnStatusFailed);
@ -567,7 +568,8 @@ protected:
if (iterator->second) {
const char *class_name =
iterator->second->GetClassName().AsCString("<unknown>");
if (regex_up && class_name && !regex_up->Execute(class_name))
if (regex_up && class_name &&
!regex_up->Execute(llvm::StringRef(class_name)))
continue;
std_out.Printf("isa = 0x%" PRIx64, iterator->first);
std_out.Printf(" name = %s", class_name);
@ -607,7 +609,7 @@ protected:
nullptr);
}
} else {
if (regex_up && !regex_up->Execute(""))
if (regex_up && !regex_up->Execute(llvm::StringRef()))
continue;
std_out.Printf("isa = 0x%" PRIx64 " has no associated class.\n",
iterator->first);

View File

@ -1964,8 +1964,9 @@ void RenderScriptRuntime::FindStructTypeName(Element &elem,
// Find all the global variables from the script rs modules
VariableList variable_list;
for (auto module_sp : m_rsmodules)
module_sp->m_module->FindGlobalVariables(RegularExpression("."), true,
UINT32_MAX, variable_list);
module_sp->m_module->FindGlobalVariables(
RegularExpression(llvm::StringRef(".")), true, UINT32_MAX,
variable_list);
// Iterate over all the global variables looking for one with a matching type
// to the Element.
@ -3741,15 +3742,16 @@ public:
RegularExpression regex;
RegularExpression::Match regex_match(3);
llvm::StringRef id_ref = llvm::StringRef::withNullAsEmpty(id_cstr);
bool matched = false;
if (regex.Compile("^([0-9]+),([0-9]+),([0-9]+)$") &&
regex.Execute(id_cstr, &regex_match))
if (regex.Compile(llvm::StringRef("^([0-9]+),([0-9]+),([0-9]+)$")) &&
regex.Execute(id_ref, &regex_match))
matched = true;
else if (regex.Compile("^([0-9]+),([0-9]+)$") &&
regex.Execute(id_cstr, &regex_match))
else if (regex.Compile(llvm::StringRef("^([0-9]+),([0-9]+)$")) &&
regex.Execute(id_ref, &regex_match))
matched = true;
else if (regex.Compile("^([0-9]+)$") &&
regex.Execute(id_cstr, &regex_match))
else if (regex.Compile(llvm::StringRef("^([0-9]+)$")) &&
regex.Execute(id_ref, &regex_match))
matched = true;
for (uint32_t i = 0; i < 3; i++) {
std::string group;

View File

@ -125,9 +125,9 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict,
// LSBIT - the least significant bit at which the current register value
// ends at
static RegularExpression g_bitfield_regex(
"([A-Za-z_][A-Za-z0-9_]*)\\[([0-9]+):([0-9]+)\\]");
llvm::StringRef("([A-Za-z_][A-Za-z0-9_]*)\\[([0-9]+):([0-9]+)\\]"));
RegularExpression::Match regex_match(3);
if (g_bitfield_regex.Execute(slice_str.c_str(), &regex_match)) {
if (g_bitfield_regex.Execute(slice_str, &regex_match)) {
llvm::StringRef reg_name_str;
std::string msbit_str;
std::string lsbit_str;

View File

@ -404,11 +404,11 @@ GDBRemoteCommunication::WaitForPacketWithTimeoutMicroSecondsNoLock(
std::string regex_str = "^";
regex_str += echo_packet;
regex_str += "$";
response_regex.Compile(regex_str.c_str());
response_regex.Compile(regex_str);
} else {
echo_packet_len =
::snprintf(echo_packet, sizeof(echo_packet), "qC");
response_regex.Compile("^QC[0-9A-Fa-f]+$");
response_regex.Compile(llvm::StringRef("^QC[0-9A-Fa-f]+$"));
}
PacketResult echo_packet_result =
@ -422,8 +422,7 @@ GDBRemoteCommunication::WaitForPacketWithTimeoutMicroSecondsNoLock(
echo_response, timeout_usec, false);
if (echo_packet_result == PacketResult::Success) {
++successful_responses;
if (response_regex.Execute(
echo_response.GetStringRef().c_str())) {
if (response_regex.Execute(echo_response.GetStringRef())) {
sync_success = true;
break;
} else if (successful_responses == 1) {

View File

@ -312,7 +312,7 @@ private:
}
// Instantiate the regex so we can report any errors.
auto regex = RegularExpression(op_arg.c_str());
auto regex = RegularExpression(op_arg);
if (!regex.IsValid()) {
char error_text[256];
error_text[0] = '\0';

View File

@ -999,16 +999,18 @@ void DWARFCompileUnit::ParseProducerInfo() {
const char *producer_cstr = die->GetAttributeValueAsString(
m_dwarf2Data, this, DW_AT_producer, NULL);
if (producer_cstr) {
RegularExpression llvm_gcc_regex("^4\\.[012]\\.[01] \\(Based on Apple "
"Inc\\. build [0-9]+\\) \\(LLVM build "
"[\\.0-9]+\\)$");
if (llvm_gcc_regex.Execute(producer_cstr)) {
RegularExpression llvm_gcc_regex(
llvm::StringRef("^4\\.[012]\\.[01] \\(Based on Apple "
"Inc\\. build [0-9]+\\) \\(LLVM build "
"[\\.0-9]+\\)$"));
if (llvm_gcc_regex.Execute(llvm::StringRef(producer_cstr))) {
m_producer = eProducerLLVMGCC;
} else if (strstr(producer_cstr, "clang")) {
static RegularExpression g_clang_version_regex(
"clang-([0-9]+)\\.([0-9]+)\\.([0-9]+)");
llvm::StringRef("clang-([0-9]+)\\.([0-9]+)\\.([0-9]+)"));
RegularExpression::Match regex_match(3);
if (g_clang_version_regex.Execute(producer_cstr, &regex_match)) {
if (g_clang_version_regex.Execute(llvm::StringRef(producer_cstr),
&regex_match)) {
std::string str;
if (regex_match.GetMatchAtIndex(producer_cstr, 1, str))
m_producer_version_major =

View File

@ -535,18 +535,20 @@ FindCallbackString(SymbolFileDWARF *dwarf2Data, DWARFCompileUnit *cu,
const uint32_t curr_depth, void *userData) {
FindCallbackStringInfo *info = (FindCallbackStringInfo *)userData;
if (die) {
const char *die_name = die->GetName(dwarf2Data, cu);
if (die_name) {
if (info->regex) {
if (info->regex->Execute(die_name))
info->die_offsets.push_back(die->GetOffset());
} else {
if ((info->ignore_case ? strcasecmp(die_name, info->name)
: strcmp(die_name, info->name)) == 0)
info->die_offsets.push_back(die->GetOffset());
}
}
if (!die)
return next_offset;
const char *die_name = die->GetName(dwarf2Data, cu);
if (!die_name)
return next_offset;
if (info->regex) {
if (info->regex->Execute(llvm::StringRef(die_name)))
info->die_offsets.push_back(die->GetOffset());
} else {
if ((info->ignore_case ? strcasecmp(die_name, info->name)
: strcmp(die_name, info->name)) == 0)
info->die_offsets.push_back(die->GetOffset());
}
// Just return the current offset to parse the next CU or DIE entry

View File

@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "HashedNameToDIE.h"
#include "llvm/ADT/StringRef.h"
void DWARFMappedHash::ExtractDIEArray(const DIEInfoArray &die_info_array,
DIEArray &die_offsets) {
@ -469,7 +470,7 @@ DWARFMappedHash::MemoryTable::AppendHashDataForRegularExpression(
if (count > 0 &&
m_data.ValidOffsetForDataOfSize(*hash_data_offset_ptr,
min_total_hash_data_size)) {
const bool match = regex.Execute(strp_cstr);
const bool match = regex.Execute(llvm::StringRef(strp_cstr));
if (!match && m_header.header_data.HashDataHasFixedByteSize()) {
// If the regex doesn't match and we have fixed size data,

View File

@ -2198,7 +2198,7 @@ uint32_t SymbolFileDWARF::FindGlobalVariables(const RegularExpression &regex,
GetObjectFile()->GetModule()->LogMessage(
log, "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, "
"max_matches=%u, variables)",
regex.GetText(), append, max_matches);
regex.GetText().str().c_str(), append, max_matches);
}
DWARFDebugInfo *info = DebugInfo();
@ -2252,7 +2252,7 @@ uint32_t SymbolFileDWARF::FindGlobalVariables(const RegularExpression &regex,
GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
"the DWARF debug information has been modified (.apple_names "
"accelerator table had bad die 0x%8.8x for regex '%s')\n",
die_ref.die_offset, regex.GetText());
die_ref.die_offset, regex.GetText().str().c_str());
}
}
}
@ -2673,7 +2673,7 @@ uint32_t SymbolFileDWARF::FindFunctions(const RegularExpression &regex,
SymbolContextList &sc_list) {
Timer scoped_timer(LLVM_PRETTY_FUNCTION,
"SymbolFileDWARF::FindFunctions (regex = '%s')",
regex.GetText());
regex.GetText().str().c_str());
Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
@ -2681,7 +2681,7 @@ uint32_t SymbolFileDWARF::FindFunctions(const RegularExpression &regex,
GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
regex.GetText(), append);
regex.GetText().str().c_str(), append);
}
// If we aren't appending the results to this list, then clear the list

View File

@ -1020,7 +1020,7 @@ uint32_t SymbolFileDWARFDebugMap::FindFunctions(const RegularExpression &regex,
SymbolContextList &sc_list) {
Timer scoped_timer(LLVM_PRETTY_FUNCTION,
"SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')",
regex.GetText());
regex.GetText().str().c_str());
uint32_t initial_size = 0;
if (append)

View File

@ -574,9 +574,10 @@ bool ObjectFile::SplitArchivePathWithObject(const char *path_with_object,
FileSpec &archive_file,
ConstString &archive_object,
bool must_exist) {
RegularExpression g_object_regex("(.*)\\(([^\\)]+)\\)$");
RegularExpression g_object_regex(llvm::StringRef("(.*)\\(([^\\)]+)\\)$"));
RegularExpression::Match regex_match(2);
if (g_object_regex.Execute(path_with_object, &regex_match)) {
if (g_object_regex.Execute(llvm::StringRef::withNullAsEmpty(path_with_object),
&regex_match)) {
std::string path;
std::string obj;
if (regex_match.GetMatchAtIndex(path_with_object, 1, path) &&

View File

@ -382,9 +382,11 @@ Error Variable::GetValuesForVariableExpressionPath(
} break;
default: {
static RegularExpression g_regex("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)");
static RegularExpression g_regex(
llvm::StringRef("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)"));
RegularExpression::Match regex_match(1);
if (g_regex.Execute(variable_expr_path, &regex_match)) {
if (g_regex.Execute(llvm::StringRef::withNullAsEmpty(variable_expr_path),
&regex_match)) {
std::string variable_name;
if (regex_match.GetMatchAtIndex(variable_expr_path, 1, variable_name)) {
variable_list.Clear();

View File

@ -298,10 +298,11 @@ bool ThreadPlanStepInRange::ShouldStop(Event *event_ptr) {
}
void ThreadPlanStepInRange::SetAvoidRegexp(const char *name) {
auto name_ref = llvm::StringRef::withNullAsEmpty(name);
if (!m_avoid_regexp_ap)
m_avoid_regexp_ap.reset(new RegularExpression(name));
m_avoid_regexp_ap.reset(new RegularExpression(name_ref));
m_avoid_regexp_ap->Compile(name);
m_avoid_regexp_ap->Compile(name_ref);
}
void ThreadPlanStepInRange::SetDefaultFlagValue(uint32_t new_value) {
@ -361,7 +362,8 @@ bool ThreadPlanStepInRange::FrameMatchesAvoidCriteria() {
regex_match.GetMatchAtIndex(frame_function_name, 0, match);
log->Printf("Stepping out of function \"%s\" because it matches "
"the avoid regexp \"%s\" - match substring: \"%s\".",
frame_function_name, avoid_regexp_to_use->GetText(),
frame_function_name,
avoid_regexp_to_use->GetText().str().c_str(),
match.c_str());
}
}

View File

@ -36,8 +36,8 @@ bool lldb_private::NameMatches(const char *name, NameMatchType match_type,
case eNameMatchEndsWith:
return name_sref.endswith(match_sref);
case eNameMatchRegularExpression: {
RegularExpression regex(match);
return regex.Execute(name);
RegularExpression regex(match_sref);
return regex.Execute(name_sref);
} break;
}
}