From: Enrico Granata Date: Wed, 30 Mar 2016 22:45:13 +0000 (+0000) Subject: Enhance the 'type X list' commands such that they actually alert the user if no forma... X-Git-Tag: llvmorg-3.9.0-rc1~10439 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b64d3d61e321cb8e7907f38ac93ba94359179462;p=platform%2Fupstream%2Fllvm.git Enhance the 'type X list' commands such that they actually alert the user if no formatters matching the constraints could be found llvm-svn: 264957 --- diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py index 64e9931..f8209f0 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py @@ -155,6 +155,7 @@ class CategoriesDataFormatterTestCase(TestBase): self.runCmd("type category enable Category1") self.runCmd("type summary list -w Category1") + self.expect("type summary list -w NoSuchCategoryHere", substrs=['no matching results found']) self.expect("frame variable r1 r2 r3", substrs = ['r1 = Category1', diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-named-summaries/TestDataFormatterNamedSummaries.py b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-named-summaries/TestDataFormatterNamedSummaries.py index 94df520..e9ac79a 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-named-summaries/TestDataFormatterNamedSummaries.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-named-summaries/TestDataFormatterNamedSummaries.py @@ -48,7 +48,9 @@ class NamedSummariesDataFormatterTestCase(TestBase): self.runCmd("type summary add --summary-string \"First: x=${var.x} y=${var.y} dummy=${var.dummy}\" First") self.runCmd("type summary add --summary-string \"Second: x=${var.x} y=${var.y%hex}\" Second") self.runCmd("type summary add --summary-string \"Third: x=${var.x} z=${var.z}\" Third") - + + self.expect('type summary list', substrs=['AllUseIt']) + self.expect("frame variable first", substrs = ['First: x=12']) diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp index ac71453..47fcac1 100644 --- a/lldb/source/Commands/CommandObjectType.cpp +++ b/lldb/source/Commands/CommandObjectType.cpp @@ -1310,9 +1310,10 @@ public: ~CommandObjectTypeFormatterList() override = default; protected: - virtual void + virtual bool FormatterSpecificList (CommandReturnObject &result) { + return false; } bool @@ -1346,10 +1347,13 @@ protected: } } - auto category_closure = [&result, &formatter_regex] (const lldb::TypeCategoryImplSP& category) -> void { + bool any_printed = false; + + auto category_closure = [&result, &formatter_regex, &any_printed] (const lldb::TypeCategoryImplSP& category) -> void { result.GetOutputStream().Printf("-----------------------\nCategory: %s\n-----------------------\n", category->GetName()); + TypeCategoryImpl::ForEachCallbacks foreach; - foreach.SetExact([&result, &formatter_regex] (ConstString name, const FormatterSharedPointer& format_sp) -> bool { + foreach.SetExact([&result, &formatter_regex, &any_printed] (ConstString name, const FormatterSharedPointer& format_sp) -> bool { if (formatter_regex) { bool escape = true; @@ -1365,13 +1369,13 @@ protected: if (escape) return true; } - + + any_printed = true; result.GetOutputStream().Printf ("%s: %s\n", name.AsCString(), format_sp->GetDescription().c_str()); - return true; }); - foreach.SetWithRegex( [&result, &formatter_regex] (RegularExpressionSP regex_sp, const FormatterSharedPointer& format_sp) -> bool { + foreach.SetWithRegex([&result, &formatter_regex, &any_printed] (RegularExpressionSP regex_sp, const FormatterSharedPointer& format_sp) -> bool { if (formatter_regex) { bool escape = true; @@ -1388,8 +1392,8 @@ protected: return true; } + any_printed = true; result.GetOutputStream().Printf ("%s: %s\n", regex_sp->GetText(), format_sp->GetDescription().c_str()); - return true; }); @@ -1427,10 +1431,16 @@ protected: return true; }); - FormatterSpecificList(result); + any_printed = FormatterSpecificList(result) | any_printed; } - result.SetStatus(eReturnStatusSuccessFinishResult); + if (any_printed) + result.SetStatus(eReturnStatusSuccessFinishResult); + else + { + result.GetOutputStream().PutCString("no matching results found."); + result.SetStatus(eReturnStatusSuccessFinishNoResult); + } return result.Succeeded(); } }; @@ -2028,7 +2038,7 @@ public: } protected: - void + bool FormatterSpecificList (CommandReturnObject &result) override { if (DataVisualization::NamedSummaryFormats::GetCount() > 0) @@ -2038,7 +2048,9 @@ protected: result.GetOutputStream().Printf ("%s: %s\n", name.AsCString(), summary_sp->GetDescription().c_str()); return true; }); + return true; } + return false; } };