[Lldb-commits] [lldb] bbea361 - [lldb][NFC] Remove all uses of StringRef::withNullAsEmpty in LLDB
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Tue May 18 00:41:41 PDT 2021
Author: Raphael Isemann
Date: 2021-05-18T09:41:20+02:00
New Revision: bbea361039c11dc2e6e281c80fa8aa569f1c7c2d
URL: https://github.com/llvm/llvm-project/commit/bbea361039c11dc2e6e281c80fa8aa569f1c7c2d
DIFF: https://github.com/llvm/llvm-project/commit/bbea361039c11dc2e6e281c80fa8aa569f1c7c2d.diff
LOG: [lldb][NFC] Remove all uses of StringRef::withNullAsEmpty in LLDB
A long time ago LLDB wanted to start using StringRef instead of
C-Strings/ConstString but was blocked by the fact that the StringRef constructor
that takes a C-string was asserting that the C-string isn't a nullptr. To
workaround this, D24697 introduced a special function called `withNullAsEmpty`
and that's what LLDB (and only LLDB) started to use to build StringRefs from
C-strings.
A bit later it seems that `withNullAsEmpty` was declared too awkward to use and
instead the assert in the StringRef constructor got removed (see D24904). The
rest of LLDB was then converted to StringRef by just calling the now perfectly
usable implicit constructor.
However, all the calls to `withNullAsEmpty` just remained and are now just
strange artefacts in the code base that just look out of place. It's also
curiously a LLDB-exclusive function and no other project ever called it since
it's introduction half a decade ago.
This patch removes all uses of `withNullAsEmpty`. The follow up will be to
remove the function from StringRef.
Reviewed By: JDevlieghere
Differential Revision: https://reviews.llvm.org/D102597
Added:
Modified:
lldb/include/lldb/Interpreter/OptionValueRegex.h
lldb/include/lldb/Interpreter/OptionValueString.h
lldb/source/API/SBDebugger.cpp
lldb/source/API/SBLanguageRuntime.cpp
lldb/source/API/SBPlatform.cpp
lldb/source/API/SBTypeCategory.cpp
lldb/source/Breakpoint/BreakpointResolverName.cpp
lldb/source/Commands/CommandObjectFrame.cpp
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Commands/CommandObjectType.cpp
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/source/Interpreter/OptionValue.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
lldb/source/Target/ThreadPlanStepInRange.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Interpreter/OptionValueRegex.h b/lldb/include/lldb/Interpreter/OptionValueRegex.h
index 9eb0247e0405f..129987484f195 100644
--- a/lldb/include/lldb/Interpreter/OptionValueRegex.h
+++ b/lldb/include/lldb/Interpreter/OptionValueRegex.h
@@ -17,8 +17,7 @@ namespace lldb_private {
class OptionValueRegex : public Cloneable<OptionValueRegex, OptionValue> {
public:
OptionValueRegex(const char *value = nullptr)
- : m_regex(llvm::StringRef::withNullAsEmpty(value)),
- m_default_regex_str(llvm::StringRef::withNullAsEmpty(value).str()) {}
+ : m_regex(value), m_default_regex_str(value) {}
~OptionValueRegex() override = default;
diff --git a/lldb/include/lldb/Interpreter/OptionValueString.h b/lldb/include/lldb/Interpreter/OptionValueString.h
index 5611b58490971..be42deb80da77 100644
--- a/lldb/include/lldb/Interpreter/OptionValueString.h
+++ b/lldb/include/lldb/Interpreter/OptionValueString.h
@@ -85,7 +85,7 @@ class OptionValueString : public Cloneable<OptionValueString, OptionValue> {
const Flags &GetOptions() const { return m_options; }
const char *operator=(const char *value) {
- SetCurrentValue(llvm::StringRef::withNullAsEmpty(value));
+ SetCurrentValue(value);
return m_current_value.c_str();
}
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 8bbb89516a0a9..8c84c5ffe9a2c 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1387,7 +1387,7 @@ void SBDebugger::SetPrompt(const char *prompt) {
LLDB_RECORD_METHOD(void, SBDebugger, SetPrompt, (const char *), prompt);
if (m_opaque_sp)
- m_opaque_sp->SetPrompt(llvm::StringRef::withNullAsEmpty(prompt));
+ m_opaque_sp->SetPrompt(llvm::StringRef(prompt));
}
const char *SBDebugger::GetReproducerPath() const {
diff --git a/lldb/source/API/SBLanguageRuntime.cpp b/lldb/source/API/SBLanguageRuntime.cpp
index 33c900d20c31a..e65b58270517d 100644
--- a/lldb/source/API/SBLanguageRuntime.cpp
+++ b/lldb/source/API/SBLanguageRuntime.cpp
@@ -18,8 +18,7 @@ SBLanguageRuntime::GetLanguageTypeFromString(const char *string) {
LLDB_RECORD_STATIC_METHOD(lldb::LanguageType, SBLanguageRuntime,
GetLanguageTypeFromString, (const char *), string);
- return Language::GetLanguageTypeFromString(
- llvm::StringRef::withNullAsEmpty(string));
+ return Language::GetLanguageTypeFromString(llvm::StringRef(string));
}
const char *
diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp
index f118048156b96..7043367b13438 100644
--- a/lldb/source/API/SBPlatform.cpp
+++ b/lldb/source/API/SBPlatform.cpp
@@ -413,8 +413,7 @@ SBError SBPlatform::ConnectRemote(SBPlatformConnectOptions &connect_options) {
PlatformSP platform_sp(GetSP());
if (platform_sp && connect_options.GetURL()) {
Args args;
- args.AppendArgument(
- llvm::StringRef::withNullAsEmpty(connect_options.GetURL()));
+ args.AppendArgument(connect_options.GetURL());
sb_error.ref() = platform_sp->ConnectRemote(args);
} else {
sb_error.SetErrorString("invalid platform");
diff --git a/lldb/source/API/SBTypeCategory.cpp b/lldb/source/API/SBTypeCategory.cpp
index 9ce1a57ec4f72..e7432959b2600 100644
--- a/lldb/source/API/SBTypeCategory.cpp
+++ b/lldb/source/API/SBTypeCategory.cpp
@@ -363,9 +363,7 @@ bool SBTypeCategory::AddTypeFormat(SBTypeNameSpecifier type_name,
if (type_name.IsRegex())
m_opaque_sp->GetRegexTypeFormatsContainer()->Add(
- RegularExpression(
- llvm::StringRef::withNullAsEmpty(type_name.GetName())),
- format.GetSP());
+ RegularExpression(type_name.GetName()), format.GetSP());
else
m_opaque_sp->GetTypeFormatsContainer()->Add(
ConstString(type_name.GetName()), format.GetSP());
@@ -442,9 +440,7 @@ bool SBTypeCategory::AddTypeSummary(SBTypeNameSpecifier type_name,
if (type_name.IsRegex())
m_opaque_sp->GetRegexTypeSummariesContainer()->Add(
- RegularExpression(
- llvm::StringRef::withNullAsEmpty(type_name.GetName())),
- summary.GetSP());
+ RegularExpression(type_name.GetName()), summary.GetSP());
else
m_opaque_sp->GetTypeSummariesContainer()->Add(
ConstString(type_name.GetName()), summary.GetSP());
@@ -487,9 +483,7 @@ bool SBTypeCategory::AddTypeFilter(SBTypeNameSpecifier type_name,
if (type_name.IsRegex())
m_opaque_sp->GetRegexTypeFiltersContainer()->Add(
- RegularExpression(
- llvm::StringRef::withNullAsEmpty(type_name.GetName())),
- filter.GetSP());
+ RegularExpression(type_name.GetName()), filter.GetSP());
else
m_opaque_sp->GetTypeFiltersContainer()->Add(
ConstString(type_name.GetName()), filter.GetSP());
@@ -566,9 +560,7 @@ bool SBTypeCategory::AddTypeSynthetic(SBTypeNameSpecifier type_name,
if (type_name.IsRegex())
m_opaque_sp->GetRegexTypeSyntheticsContainer()->Add(
- RegularExpression(
- llvm::StringRef::withNullAsEmpty(type_name.GetName())),
- synth.GetSP());
+ RegularExpression(type_name.GetName()), synth.GetSP());
else
m_opaque_sp->GetTypeSyntheticsContainer()->Add(
ConstString(type_name.GetName()), synth.GetSP());
diff --git a/lldb/source/Breakpoint/BreakpointResolverName.cpp b/lldb/source/Breakpoint/BreakpointResolverName.cpp
index 6fab20af5e597..b314135bc208f 100644
--- a/lldb/source/Breakpoint/BreakpointResolverName.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverName.cpp
@@ -31,7 +31,7 @@ BreakpointResolverName::BreakpointResolverName(const BreakpointSP &bkpt,
m_class_name(), m_regex(), m_match_type(type), m_language(language),
m_skip_prologue(skip_prologue) {
if (m_match_type == Breakpoint::Regexp) {
- m_regex = RegularExpression(llvm::StringRef::withNullAsEmpty(name_cstr));
+ m_regex = RegularExpression(name_cstr);
if (!m_regex.IsValid()) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp
index a656a99a1c712..b51bdb704fccf 100644
--- a/lldb/source/Commands/CommandObjectFrame.cpp
+++ b/lldb/source/Commands/CommandObjectFrame.cpp
@@ -460,7 +460,7 @@ class CommandObjectFrameVariable : public CommandObjectParsed {
protected:
llvm::StringRef GetScopeString(VariableSP var_sp) {
if (!var_sp)
- return llvm::StringRef::withNullAsEmpty(nullptr);
+ return llvm::StringRef();
switch (var_sp->GetScope()) {
case eValueTypeVariableGlobal:
@@ -477,7 +477,7 @@ class CommandObjectFrameVariable : public CommandObjectParsed {
break;
}
- return llvm::StringRef::withNullAsEmpty(nullptr);
+ return llvm::StringRef();
}
bool DoExecute(Args &command, CommandReturnObject &result) override {
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index f8d3a797ce5f3..bc038e326d976 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -848,8 +848,7 @@ class CommandObjectTargetVariable : public CommandObjectParsed {
size_t matches = 0;
bool use_var_name = false;
if (m_option_variable.use_regex) {
- RegularExpression regex(
- llvm::StringRef::withNullAsEmpty(arg.c_str()));
+ RegularExpression regex(arg.ref());
if (!regex.IsValid()) {
result.GetErrorStream().Printf(
"error: invalid regular expression: '%s'\n", arg.c_str());
diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index 8002b8719ce25..cc6bca09b0182 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -1080,8 +1080,7 @@ class CommandObjectTypeFormatterList : public CommandObjectParsed {
if (argc == 1) {
const char *arg = command.GetArgumentAtIndex(0);
- formatter_regex = std::make_unique<RegularExpression>(
- llvm::StringRef::withNullAsEmpty(arg));
+ formatter_regex = std::make_unique<RegularExpression>(arg);
if (!formatter_regex->IsValid()) {
result.AppendErrorWithFormat("syntax error in regular expression '%s'",
arg);
@@ -1167,9 +1166,7 @@ class CommandObjectTypeFormatterList : public CommandObjectParsed {
bool escape = true;
if (category->GetName() == category_regex->GetText()) {
escape = false;
- } else if (category_regex->Execute(
- llvm::StringRef::withNullAsEmpty(
- category->GetName()))) {
+ } else if (category_regex->Execute(category->GetName())) {
escape = false;
}
@@ -2175,8 +2172,7 @@ class CommandObjectTypeCategoryList : public CommandObjectParsed {
if (argc == 1) {
const char *arg = command.GetArgumentAtIndex(0);
- regex = std::make_unique<RegularExpression>(
- llvm::StringRef::withNullAsEmpty(arg));
+ regex = std::make_unique<RegularExpression>(arg);
if (!regex->IsValid()) {
result.AppendErrorWithFormat(
"syntax error in category regular expression '%s'", arg);
@@ -2196,8 +2192,7 @@ class CommandObjectTypeCategoryList : public CommandObjectParsed {
bool escape = true;
if (regex->GetText() == category_sp->GetName()) {
escape = false;
- } else if (regex->Execute(llvm::StringRef::withNullAsEmpty(
- category_sp->GetName()))) {
+ } else if (regex->Execute(category_sp->GetName())) {
escape = false;
}
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index a7aea8daf624e..81220843a008d 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -2986,9 +2986,9 @@ void CommandInterpreter::GetLLDBCommandsFromIOHandler(
IOHandlerSP io_handler_sp(
new IOHandlerEditline(debugger, IOHandler::Type::CommandList,
"lldb", // Name of input reader for history
- llvm::StringRef::withNullAsEmpty(prompt), // Prompt
- llvm::StringRef(), // Continuation prompt
- true, // Get multiple lines
+ llvm::StringRef(prompt), // Prompt
+ llvm::StringRef(), // Continuation prompt
+ true, // Get multiple lines
debugger.GetUseColor(),
0, // Don't show line numbers
delegate, // IOHandlerDelegate
@@ -3006,9 +3006,9 @@ void CommandInterpreter::GetPythonCommandsFromIOHandler(
IOHandlerSP io_handler_sp(
new IOHandlerEditline(debugger, IOHandler::Type::PythonCode,
"lldb-python", // Name of input reader for history
- llvm::StringRef::withNullAsEmpty(prompt), // Prompt
- llvm::StringRef(), // Continuation prompt
- true, // Get multiple lines
+ llvm::StringRef(prompt), // Prompt
+ llvm::StringRef(), // Continuation prompt
+ true, // Get multiple lines
debugger.GetUseColor(),
0, // Don't show line numbers
delegate, // IOHandlerDelegate
diff --git a/lldb/source/Interpreter/OptionValue.cpp b/lldb/source/Interpreter/OptionValue.cpp
index 0846fa9278cbe..79bdf74b6fd9b 100644
--- a/lldb/source/Interpreter/OptionValue.cpp
+++ b/lldb/source/Interpreter/OptionValue.cpp
@@ -543,8 +543,7 @@ lldb::OptionValueSP OptionValue::CreateValueFromCStringForTypeMask(
}
if (value_sp)
- error = value_sp->SetValueFromString(
- llvm::StringRef::withNullAsEmpty(value_cstr), eVarSetOperationAssign);
+ error = value_sp->SetValueFromString(value_cstr, eVarSetOperationAssign);
else
error.SetErrorString("unsupported type mask");
return value_sp;
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index 2b2d761594eda..b9151a01bbda6 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -663,8 +663,8 @@ class CommandObjectObjC_ClassTable_Dump : public CommandObjectParsed {
case 0:
break;
case 1: {
- regex_up = std::make_unique<RegularExpression>(
- llvm::StringRef::withNullAsEmpty(command.GetArgumentAtIndex(0)));
+ regex_up =
+ std::make_unique<RegularExpression>(command.GetArgumentAtIndex(0));
if (!regex_up->IsValid()) {
result.AppendError(
"invalid argument - please provide a valid regular expression");
diff --git a/lldb/source/Target/ThreadPlanStepInRange.cpp b/lldb/source/Target/ThreadPlanStepInRange.cpp
index 64ae0d7787d2b..69b4b918d467e 100644
--- a/lldb/source/Target/ThreadPlanStepInRange.cpp
+++ b/lldb/source/Target/ThreadPlanStepInRange.cpp
@@ -291,11 +291,10 @@ bool ThreadPlanStepInRange::ShouldStop(Event *event_ptr) {
}
void ThreadPlanStepInRange::SetAvoidRegexp(const char *name) {
- auto name_ref = llvm::StringRef::withNullAsEmpty(name);
if (m_avoid_regexp_up)
- *m_avoid_regexp_up = RegularExpression(name_ref);
+ *m_avoid_regexp_up = RegularExpression(name);
else
- m_avoid_regexp_up = std::make_unique<RegularExpression>(name_ref);
+ m_avoid_regexp_up = std::make_unique<RegularExpression>(name);
}
void ThreadPlanStepInRange::SetDefaultFlagValue(uint32_t new_value) {
More information about the lldb-commits
mailing list