aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectType.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-07-24 15:03:44 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-07-24 15:03:44 +0000
commit4b4fe385e49bd883fd183b5f21c1ea486c722e61 (patch)
treec3d8fdb355c9c73e57723718c22103aaf7d15aa6 /lldb/source/Commands/CommandObjectType.cpp
parent1f917f69ff07f09b6dbb670971f57f8efe718b84 (diff)
Diffstat (limited to 'lldb/source/Commands/CommandObjectType.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectType.cpp75
1 files changed, 26 insertions, 49 deletions
diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index 3ad3571b390c..11acbb5c627f 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -15,6 +15,7 @@
#include "lldb/Host/OptionParser.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandObject.h"
+#include "lldb/Interpreter/CommandOptionArgumentTable.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionGroupFormat.h"
@@ -119,12 +120,12 @@ private:
// Instance variables to hold the values for command options.
TypeSummaryImpl::Flags m_flags;
- bool m_regex;
+ bool m_regex = false;
std::string m_format_string;
ConstString m_name;
std::string m_python_script;
std::string m_python_function;
- bool m_is_add_script;
+ bool m_is_add_script = false;
std::string m_category;
};
@@ -1054,6 +1055,15 @@ protected:
return false;
}
+ static bool ShouldListItem(llvm::StringRef s, RegularExpression *regex) {
+ // If we have a regex, it can match two kinds of results:
+ // - An item created with that same regex string (exact string match), so
+ // the user can list it using the same string it used at creation time.
+ // - Items that match the regex.
+ // No regex means list everything.
+ return regex == nullptr || s == regex->GetText() || regex->Execute(s);
+ }
+
bool DoExecute(Args &command, CommandReturnObject &result) override {
const size_t argc = command.GetArgumentCount();
@@ -1095,24 +1105,13 @@ protected:
.SetExact([&result, &formatter_regex, &any_printed](
const TypeMatcher &type_matcher,
const FormatterSharedPointer &format_sp) -> bool {
- if (formatter_regex) {
- bool escape = true;
- if (type_matcher.CreatedBySameMatchString(
- ConstString(formatter_regex->GetText()))) {
- escape = false;
- } else if (formatter_regex->Execute(
- type_matcher.GetMatchString().GetStringRef())) {
- escape = false;
- }
-
- if (escape)
- return true;
+ if (ShouldListItem(type_matcher.GetMatchString().GetStringRef(),
+ formatter_regex.get())) {
+ any_printed = true;
+ result.GetOutputStream().Printf(
+ "%s: %s\n", type_matcher.GetMatchString().GetCString(),
+ format_sp->GetDescription().c_str());
}
-
- any_printed = true;
- result.GetOutputStream().Printf(
- "%s: %s\n", type_matcher.GetMatchString().GetCString(),
- format_sp->GetDescription().c_str());
return true;
});
@@ -1120,24 +1119,13 @@ protected:
.SetWithRegex([&result, &formatter_regex, &any_printed](
const TypeMatcher &type_matcher,
const FormatterSharedPointer &format_sp) -> bool {
- if (formatter_regex) {
- bool escape = true;
- if (type_matcher.CreatedBySameMatchString(
- ConstString(formatter_regex->GetText()))) {
- escape = false;
- } else if (formatter_regex->Execute(
- type_matcher.GetMatchString().GetStringRef())) {
- escape = false;
- }
-
- if (escape)
- return true;
+ if (ShouldListItem(type_matcher.GetMatchString().GetStringRef(),
+ formatter_regex.get())) {
+ any_printed = true;
+ result.GetOutputStream().Printf(
+ "%s: %s\n", type_matcher.GetMatchString().GetCString(),
+ format_sp->GetDescription().c_str());
}
-
- any_printed = true;
- result.GetOutputStream().Printf(
- "%s: %s\n", type_matcher.GetMatchString().GetCString(),
- format_sp->GetDescription().c_str());
return true;
});
@@ -1154,20 +1142,9 @@ protected:
DataVisualization::Categories::ForEach(
[&category_regex, &category_closure](
const lldb::TypeCategoryImplSP &category) -> bool {
- if (category_regex) {
- bool escape = true;
- if (category->GetName() == category_regex->GetText()) {
- escape = false;
- } else if (category_regex->Execute(category->GetName())) {
- escape = false;
- }
-
- if (escape)
- return true;
+ if (ShouldListItem(category->GetName(), category_regex.get())) {
+ category_closure(category);
}
-
- category_closure(category);
-
return true;
});