JDevlieghere created this revision. JDevlieghere added reviewers: jingham, clayborg. Herald added a project: All. JDevlieghere requested review of this revision.
Print the enum values and their description in the argument value help output. Here's what the output looks like: (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 (lldb) help <log-handler> <log-handler> -- 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 or to a file if one is specified. A buffer size (in bytes) can be specified with -b. If no buffer size is specified the output is unbuffered. circular : Write log messages to a fixed size circular buffer. A buffer size (number of messages) must be specified with -b. os : Write log messages to the operating system log. https://reviews.llvm.org/D129707 Files: lldb/source/Interpreter/CommandObject.cpp lldb/test/API/commands/help/TestHelp.py Index: lldb/test/API/commands/help/TestHelp.py =================================================================== --- lldb/test/API/commands/help/TestHelp.py +++ lldb/test/API/commands/help/TestHelp.py @@ -318,3 +318,16 @@ "\(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', + ]) + Index: lldb/source/Interpreter/CommandObject.cpp =================================================================== --- lldb/source/Interpreter/CommandObject.cpp +++ lldb/source/Interpreter/CommandObject.cpp @@ -17,6 +17,7 @@ #include "lldb/Core/Address.h" #include "lldb/Interpreter/Options.h" +#include "lldb/Interpreter/CommandOptionEnumValues.h" #include "lldb/Utility/ArchSpec.h" #include "llvm/ADT/ScopeExit.h" @@ -400,9 +401,27 @@ 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_type_enum_values[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) {
Index: lldb/test/API/commands/help/TestHelp.py =================================================================== --- lldb/test/API/commands/help/TestHelp.py +++ lldb/test/API/commands/help/TestHelp.py @@ -318,3 +318,16 @@ "\(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', + ]) + Index: lldb/source/Interpreter/CommandObject.cpp =================================================================== --- lldb/source/Interpreter/CommandObject.cpp +++ lldb/source/Interpreter/CommandObject.cpp @@ -17,6 +17,7 @@ #include "lldb/Core/Address.h" #include "lldb/Interpreter/Options.h" +#include "lldb/Interpreter/CommandOptionEnumValues.h" #include "lldb/Utility/ArchSpec.h" #include "llvm/ADT/ScopeExit.h" @@ -400,9 +401,27 @@ 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_type_enum_values[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) {
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits