RamNalamothu updated this revision to Diff 389884. RamNalamothu edited the summary of this revision. RamNalamothu added a comment.
Address review comments. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D114448/new/ https://reviews.llvm.org/D114448 Files: lldb/include/lldb/Interpreter/OptionGroupFormat.h lldb/source/Commands/CommandObjectMemory.cpp lldb/source/Interpreter/OptionGroupFormat.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 @@ -225,3 +225,21 @@ "help format", matching=True, substrs=['<format> -- One of the format names']) + + @no_debug_info_test + def test_help_option_group_format_options_usage(self): + """Test that help on commands that use OptionGroupFormat options provide relevant help specific to that command.""" + self.expect( + "help memory read", + matching=True, + substrs=[ + "-f <format> ( --format <format> )", "Specify a format to be used for display.", + "-s <byte-size> ( --size <byte-size> )", "The size in bytes to use when displaying with the selected format."]) + + self.expect( + "help memory write", + matching=True, + substrs=[ + "-f <format> ( --format <format> )", "The format to use for each of the value to be written.", + "-s <byte-size> ( --size <byte-size> )", "The size in bytes to write from input file or each value."]) + Index: lldb/source/Interpreter/OptionGroupFormat.cpp =================================================================== --- lldb/source/Interpreter/OptionGroupFormat.cpp +++ lldb/source/Interpreter/OptionGroupFormat.cpp @@ -16,31 +16,55 @@ using namespace lldb; using namespace lldb_private; -OptionGroupFormat::OptionGroupFormat(lldb::Format default_format, - uint64_t default_byte_size, - uint64_t default_count) +OptionGroupFormat::OptionGroupFormat( + lldb::Format default_format, uint64_t default_byte_size, + uint64_t default_count, OptionGroupFormatUsageTextVector usage_text_vector) : m_format(default_format, default_format), m_byte_size(default_byte_size, default_byte_size), m_count(default_count, default_count), m_prev_gdb_format('x'), - m_prev_gdb_size('w') {} + m_prev_gdb_size('w') { + auto default_opt_defs = OptionGroupFormat::GetDefaultDefinitions(); + m_option_definition[0] = default_opt_defs[0]; + m_option_definition[1] = default_opt_defs[1]; + m_option_definition[2] = default_opt_defs[2]; + m_option_definition[3] = default_opt_defs[3]; -static constexpr OptionDefinition g_option_table[] = { - {LLDB_OPT_SET_1, false, "format", 'f', OptionParser::eRequiredArgument, - nullptr, {}, 0, eArgTypeFormat, - "Specify a format to be used for display."}, - {LLDB_OPT_SET_2, false, "gdb-format", 'G', OptionParser::eRequiredArgument, - nullptr, {}, 0, eArgTypeGDBFormat, - "Specify a format using a GDB format specifier string."}, - {LLDB_OPT_SET_3, false, "size", 's', OptionParser::eRequiredArgument, - nullptr, {}, 0, eArgTypeByteSize, - "The size in bytes to use when displaying with the selected format."}, - {LLDB_OPT_SET_4, false, "count", 'c', OptionParser::eRequiredArgument, - nullptr, {}, 0, eArgTypeCount, - "The number of total items to display."}, -}; + if (!usage_text_vector.empty()) { + for (auto usage_text_tuple : usage_text_vector) { + switch (std::get<0>(usage_text_tuple)) { + case eArgTypeFormat: + m_option_definition[0].usage_text = std::get<1>(usage_text_tuple); + break; + case eArgTypeByteSize: + m_option_definition[2].usage_text = std::get<1>(usage_text_tuple); + break; + default: + llvm_unreachable("Unimplemented option"); + } + } + } +} + +const llvm::ArrayRef<OptionDefinition> +OptionGroupFormat::GetDefaultDefinitions() { + return { + // clang-format off + {LLDB_OPT_SET_1, false, "format", 'f', OptionParser::eRequiredArgument, + nullptr, {}, 0, eArgTypeFormat, + "Specify a format to be used for display."}, + {LLDB_OPT_SET_2, false, "gdb-format", 'G', + OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeGDBFormat, + "Specify a format using a GDB format specifier string."}, + {LLDB_OPT_SET_3, false, "size", 's', OptionParser::eRequiredArgument, + nullptr, {}, 0, eArgTypeByteSize, + "The size in bytes to use when displaying with the selected format."}, + {LLDB_OPT_SET_4, false, "count", 'c', OptionParser::eRequiredArgument, + nullptr, {}, 0, eArgTypeCount, + "The number of total items to display."}}; +} // clang-format on llvm::ArrayRef<OptionDefinition> OptionGroupFormat::GetDefinitions() { - auto result = llvm::makeArrayRef(g_option_table); + auto result = llvm::makeArrayRef(m_option_definition); if (m_byte_size.GetDefaultValue() < UINT64_MAX) { if (m_count.GetDefaultValue() < UINT64_MAX) return result; @@ -54,7 +78,7 @@ llvm::StringRef option_arg, ExecutionContext *execution_context) { Status error; - const int short_option = g_option_table[option_idx].short_option; + const int short_option = m_option_definition[option_idx].short_option; switch (short_option) { case 'f': Index: lldb/source/Commands/CommandObjectMemory.cpp =================================================================== --- lldb/source/Commands/CommandObjectMemory.cpp +++ lldb/source/Commands/CommandObjectMemory.cpp @@ -1222,7 +1222,15 @@ interpreter, "memory write", "Write to the memory of the current target process.", nullptr, eCommandRequiresProcess | eCommandProcessMustBeLaunched), - m_option_group(), m_format_options(eFormatBytes, 1, UINT64_MAX), + m_option_group(), + m_format_options( + eFormatBytes, 1, UINT64_MAX, + {std::make_tuple( + eArgTypeFormat, + "The format to use for each of the value to be written."), + std::make_tuple( + eArgTypeByteSize, + "The size in bytes to write from input file or each value.")}), m_memory_options() { CommandArgumentEntry arg1; CommandArgumentEntry arg2; Index: lldb/include/lldb/Interpreter/OptionGroupFormat.h =================================================================== --- lldb/include/lldb/Interpreter/OptionGroupFormat.h +++ lldb/include/lldb/Interpreter/OptionGroupFormat.h @@ -16,6 +16,9 @@ namespace lldb_private { +typedef std::vector<std::tuple<lldb::CommandArgumentType, const char *>> + OptionGroupFormatUsageTextVector; + // OptionGroupFormat class OptionGroupFormat : public OptionGroup { @@ -30,12 +33,17 @@ uint64_t default_byte_size = UINT64_MAX, // Pass UINT64_MAX to disable the "--size" option uint64_t default_count = - UINT64_MAX); // Pass UINT64_MAX to disable the "--count" option + UINT64_MAX, // Pass UINT64_MAX to disable the "--count" option + OptionGroupFormatUsageTextVector usage_text_vector = {} + // Use to override default option usage text with the command specific one + ); ~OptionGroupFormat() override = default; llvm::ArrayRef<OptionDefinition> GetDefinitions() override; + static const llvm::ArrayRef<OptionDefinition> GetDefaultDefinitions(); + Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, ExecutionContext *execution_context) override; @@ -73,6 +81,7 @@ char m_prev_gdb_format; char m_prev_gdb_size; bool m_has_gdb_format; + OptionDefinition m_option_definition[4]; }; } // namespace lldb_private
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits