aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2022-07-14 20:23:07 -0700
committerJonas Devlieghere <jonas@devlieghere.com>2022-07-14 21:18:08 -0700
commitbcae3cdbd029210e9ecf42f07d38cc4ed4a95230 (patch)
tree0ac363ec79354d4d3574c85ee8e232aa0baee799
parent7ced9fff95473c1794b51a3cfd099b4fea3d1a58 (diff)
downloadllvm-bcae3cdbd029210e9ecf42f07d38cc4ed4a95230.zip
llvm-bcae3cdbd029210e9ecf42f07d38cc4ed4a95230.tar.gz
llvm-bcae3cdbd029210e9ecf42f07d38cc4ed4a95230.tar.bz2
[lldb] Print the enum values and their description in the help output
Print the enum values and their description in the help output for argument values. Until now, there was no way to get these values and their description. Example output: (lldb) help <description-verbosity> <description-verbosity> -- How verbose the output of 'po' should be. compact : Only show the description string full : Show the full output, including persistent variable's name and type Differential revision: https://reviews.llvm.org/D129707
-rw-r--r--lldb/source/Interpreter/CommandObject.cpp22
-rw-r--r--lldb/test/API/commands/help/TestHelp.py13
2 files changed, 34 insertions, 1 deletions
diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp
index 609ac57..719cfbc 100644
--- a/lldb/source/Interpreter/CommandObject.cpp
+++ b/lldb/source/Interpreter/CommandObject.cpp
@@ -16,6 +16,7 @@
#include <cstdlib>
#include "lldb/Core/Address.h"
+#include "lldb/Interpreter/CommandOptionArgumentTable.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Utility/ArchSpec.h"
#include "llvm/ADT/ScopeExit.h"
@@ -398,9 +399,28 @@ void CommandObject::GetArgumentHelp(Stream &str, CommandArgumentType arg_type,
interpreter.OutputHelpText(str, name_str.GetString(), "--", help_text,
name_str.GetSize());
}
- } else
+ } else {
interpreter.OutputFormattedHelpText(str, name_str.GetString(), "--",
entry->help_text, name_str.GetSize());
+
+ // Print enum values and their description if any.
+ OptionEnumValues enum_values = g_argument_table[arg_type].enum_values;
+ if (!enum_values.empty()) {
+ str.EOL();
+ size_t longest = 0;
+ for (const OptionEnumValueElement &element : enum_values)
+ longest =
+ std::max(longest, llvm::StringRef(element.string_value).size());
+ str.IndentMore(5);
+ for (const OptionEnumValueElement &element : enum_values) {
+ str.Indent();
+ interpreter.OutputHelpText(str, element.string_value, ":",
+ element.usage, longest);
+ }
+ str.IndentLess(5);
+ str.EOL();
+ }
+ }
}
const char *CommandObject::GetArgumentName(CommandArgumentType arg_type) {
diff --git a/lldb/test/API/commands/help/TestHelp.py b/lldb/test/API/commands/help/TestHelp.py
index 6e0cfe4..7d19665 100644
--- a/lldb/test/API/commands/help/TestHelp.py
+++ b/lldb/test/API/commands/help/TestHelp.py
@@ -318,3 +318,16 @@ class HelpCommandTestCase(TestBase):
"\(does not apply to binary output\)."])
self.expect("help memory find", patterns=[
"--show-tags\n\s+Include memory tags in output."])
+
+ @no_debug_info_test
+ def test_help_show_enum_values(self):
+ """ Check the help output for a argument type contains the enum values
+ and their descriptions. """
+ self.expect("help <log-handler>", substrs=[
+ 'The log handle that will be used to write out log messages.',
+ 'default' , 'Use the default (stream) log handler',
+ 'stream' , 'Write log messages to the debugger output stream',
+ 'circular' , 'Write log messages to a fixed size circular buffer',
+ 'os' , 'Write log messages to the operating system log',
+ ])
+