summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-09-21 16:01:28 +0000
committerZachary Turner <zturner@google.com>2016-09-21 16:01:28 +0000
commit95eae4235d4cfa5cee67ab6c4e686baf8a57e9e5 (patch)
tree0e9d2a42e76e13cf5ed5d6a8f0b935a83e40ea69 /lldb/source/Core
parent07171f21d148d340115ec634be6a7f296799517d (diff)
downloadbcm5719-llvm-95eae4235d4cfa5cee67ab6c4e686baf8a57e9e5.tar.gz
bcm5719-llvm-95eae4235d4cfa5cee67ab6c4e686baf8a57e9e5.zip
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
Diffstat (limited to 'lldb/source/Core')
-rw-r--r--lldb/source/Core/AddressResolverName.cpp4
-rw-r--r--lldb/source/Core/Disassembler.cpp11
-rw-r--r--lldb/source/Core/Module.cpp2
-rw-r--r--lldb/source/Core/RegularExpression.cpp27
-rw-r--r--lldb/source/Core/SourceManager.cpp2
5 files changed, 24 insertions, 22 deletions
diff --git a/lldb/source/Core/AddressResolverName.cpp b/lldb/source/Core/AddressResolverName.cpp
index a2a45e6cd4f..d9b6dad5e4e 100644
--- a/lldb/source/Core/AddressResolverName.cpp
+++ b/lldb/source/Core/AddressResolverName.cpp
@@ -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());
}
diff --git a/lldb/source/Core/Disassembler.cpp b/lldb/source/Core/Disassembler.cpp
index 34fa6a54438..a2bbf71d501 100644
--- a/lldb/source/Core/Disassembler.cpp
+++ b/lldb/source/Core/Disassembler.cpp
@@ -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) {
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index aa9e516d152..765f71598f4 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -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) {
diff --git a/lldb/source/Core/RegularExpression.cpp b/lldb/source/Core/RegularExpression.cpp
index bc3b516ff2f..6cbdcff79cc 100644
--- a/lldb/source/Core/RegularExpression.cpp
+++ b/lldb/source/Core/RegularExpression.cpp
@@ -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.
diff --git a/lldb/source/Core/SourceManager.cpp b/lldb/source/Core/SourceManager.cpp
index b262ad68f08..6ecd8da33d8 100644
--- a/lldb/source/Core/SourceManager.cpp
+++ b/lldb/source/Core/SourceManager.cpp
@@ -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);
}
}
OpenPOWER on IntegriCloud