jingham created this revision. jingham added reviewers: JDevlieghere, aprantl. Herald added a project: All. jingham requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
If you run: (lldb) type summary delete Foo that will only search for the type summary for Foo in the "default" category. That's by design, since this is "delete" you wouldn't want to accidentally delete a format it might be hard to get back, so making you specify the category or say "all" explicitly is a good safeguard. But the help is not at all clear that that's how it works and it has confused several people now. This patch fixes the help strings. Since all the `type X delete` commands go through a common base, I centralized the help output in the base class so the help would be consistent. I also removed an unused macro, and changed where we were calling these `formatter_kind_mask` to be `formatter_kind` since we only use them as a single enum element, we never use them as masks in this context. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D148282 Files: lldb/source/Commands/CommandObjectType.cpp
Index: lldb/source/Commands/CommandObjectType.cpp =================================================================== --- lldb/source/Commands/CommandObjectType.cpp +++ lldb/source/Commands/CommandObjectType.cpp @@ -39,9 +39,6 @@ #include <functional> #include <memory> -#define CHECK_FORMATTER_KIND_MASK(VAL) \ - ((m_formatter_kind_mask & (VAL)) == (VAL)) - using namespace lldb; using namespace lldb_private; @@ -100,6 +97,21 @@ return false; } +const char *FormatCategoryToString(FormatCategoryItem item, bool long_name) { + switch (item) { + case eFormatCategoryItemSummary: + return "summary"; + case eFormatCategoryItemFilter: + return "filter"; + case eFormatCategoryItemSynth: + if (long_name) + return "synthetic child provider"; + return "synthetic"; + case eFormatCategoryItemFormat: + return "format"; + } +}; + #define LLDB_OPTIONS_type_summary_add #include "CommandOptions.inc" @@ -754,16 +766,19 @@ }; CommandOptions m_options; - uint32_t m_formatter_kind_mask; + FormatCategoryItem m_formatter_kind; Options *GetOptions() override { return &m_options; } + + static const char *g_short_help_template; + static const char *g_long_help_template; public: CommandObjectTypeFormatterDelete(CommandInterpreter &interpreter, - uint32_t formatter_kind_mask, - const char *name, const char *help) - : CommandObjectParsed(interpreter, name, help, nullptr), - m_formatter_kind_mask(formatter_kind_mask) { + FormatCategoryItem formatter_kind) + : CommandObjectParsed(interpreter, + FormatCategoryToString(formatter_kind, false)), + m_formatter_kind(formatter_kind) { CommandArgumentEntry type_arg; CommandArgumentData type_style_arg; @@ -773,6 +788,19 @@ type_arg.push_back(type_style_arg); m_arguments.push_back(type_arg); + + const char *kind = FormatCategoryToString(formatter_kind, true); + const char *short_kind = FormatCategoryToString(formatter_kind, false); + + StreamString s; + s.Printf(g_short_help_template, kind); + SetHelp(s.GetData()); + s.Clear(); + s.Printf(g_long_help_template, kind, short_kind); + SetHelpLong(s.GetData()); + s.Clear(); + s.Printf("type %s delete", short_kind); + SetCommandName(s.GetData()); } ~CommandObjectTypeFormatterDelete() override = default; @@ -785,7 +813,7 @@ DataVisualization::Categories::ForEach( [this, &request](const lldb::TypeCategoryImplSP &category_sp) { - category_sp->AutoComplete(request, m_formatter_kind_mask); + category_sp->AutoComplete(request, m_formatter_kind); return true; }); } @@ -812,7 +840,7 @@ if (m_options.m_delete_all) { DataVisualization::Categories::ForEach( [this, typeCS](const lldb::TypeCategoryImplSP &category_sp) -> bool { - category_sp->Delete(typeCS, m_formatter_kind_mask); + category_sp->Delete(typeCS, m_formatter_kind); return true; }); result.SetStatus(eReturnStatusSuccessFinishNoResult); @@ -827,14 +855,14 @@ DataVisualization::Categories::GetCategory(m_options.m_language, category); if (category) - delete_category = category->Delete(typeCS, m_formatter_kind_mask); + delete_category = category->Delete(typeCS, m_formatter_kind); extra_deletion = FormatterSpecificDeletion(typeCS); } else { lldb::TypeCategoryImplSP category; DataVisualization::Categories::GetCategory( ConstString(m_options.m_category.c_str()), category); if (category) - delete_category = category->Delete(typeCS, m_formatter_kind_mask); + delete_category = category->Delete(typeCS, m_formatter_kind); extra_deletion = FormatterSpecificDeletion(typeCS); } @@ -848,6 +876,14 @@ } }; +const char *CommandObjectTypeFormatterDelete::g_short_help_template = + "Delete an existing %s for a type."; +const char *CommandObjectTypeFormatterDelete::g_long_help_template = + "Delete an existing %s for a type. Unless you specify a " + "specific category or all categories, only the " + "'default' category is searched. The names must be exactly as " + "shown in the 'type %s list' output"; + #define LLDB_OPTIONS_type_formatter_clear #include "CommandOptions.inc" @@ -888,16 +924,16 @@ }; CommandOptions m_options; - uint32_t m_formatter_kind_mask; + FormatCategoryItem m_formatter_kind; Options *GetOptions() override { return &m_options; } public: CommandObjectTypeFormatterClear(CommandInterpreter &interpreter, - uint32_t formatter_kind_mask, + FormatCategoryItem formatter_kind, const char *name, const char *help) : CommandObjectParsed(interpreter, name, help, nullptr), - m_formatter_kind_mask(formatter_kind_mask) { + m_formatter_kind(formatter_kind) { CommandArgumentData category_arg{eArgTypeName, eArgRepeatOptional}; m_arguments.push_back({category_arg}); } @@ -911,7 +947,7 @@ if (m_options.m_delete_all) { DataVisualization::Categories::ForEach( [this](const TypeCategoryImplSP &category_sp) -> bool { - category_sp->Clear(m_formatter_kind_mask); + category_sp->Clear(m_formatter_kind); return true; }); } else { @@ -924,7 +960,7 @@ DataVisualization::Categories::GetCategory(ConstString(nullptr), category); } - category->Clear(m_formatter_kind_mask); + category->Clear(m_formatter_kind); } FormatterSpecificDeletion(); @@ -940,8 +976,7 @@ public: CommandObjectTypeFormatDelete(CommandInterpreter &interpreter) : CommandObjectTypeFormatterDelete( - interpreter, eFormatCategoryItemFormat, "type format delete", - "Delete an existing formatting style for a type.") {} + interpreter, eFormatCategoryItemFormat) {} ~CommandObjectTypeFormatDelete() override = default; }; @@ -1609,8 +1644,7 @@ public: CommandObjectTypeSummaryDelete(CommandInterpreter &interpreter) : CommandObjectTypeFormatterDelete( - interpreter, eFormatCategoryItemSummary, "type summary delete", - "Delete an existing summary for a type.") {} + interpreter, eFormatCategoryItemSummary) {} ~CommandObjectTypeSummaryDelete() override = default; @@ -2159,8 +2193,7 @@ public: CommandObjectTypeFilterDelete(CommandInterpreter &interpreter) : CommandObjectTypeFormatterDelete( - interpreter, eFormatCategoryItemFilter, "type filter delete", - "Delete an existing filter for a type.") {} + interpreter, eFormatCategoryItemFilter) {} ~CommandObjectTypeFilterDelete() override = default; }; @@ -2173,8 +2206,7 @@ public: CommandObjectTypeSynthDelete(CommandInterpreter &interpreter) : CommandObjectTypeFormatterDelete( - interpreter, eFormatCategoryItemSynth, "type synthetic delete", - "Delete an existing synthetic provider for a type.") {} + interpreter, eFormatCategoryItemSynth) {} ~CommandObjectTypeSynthDelete() override = default; };
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits