Author: David Spickett Date: 2022-05-16T10:46:56Z New Revision: e473e79cd194d7a74158ff7e8b97076a7f71c511
URL: https://github.com/llvm/llvm-project/commit/e473e79cd194d7a74158ff7e8b97076a7f71c511 DIFF: https://github.com/llvm/llvm-project/commit/e473e79cd194d7a74158ff7e8b97076a7f71c511.diff LOG: [lldb][NFC] Make cmd a reference in GenerateOptionUsage Nowhere in lldb do we call this with a null pointer. If we did, the first line of the function would fault anyway. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D125218 Added: Modified: lldb/include/lldb/Interpreter/Options.h lldb/source/Commands/CommandObjectDisassemble.cpp lldb/source/Commands/CommandObjectFrame.cpp lldb/source/Commands/CommandObjectTarget.cpp lldb/source/Interpreter/CommandObject.cpp lldb/source/Interpreter/Options.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Interpreter/Options.h b/lldb/include/lldb/Interpreter/Options.h index 5899a9edc47f9..a952d5f78df9e 100644 --- a/lldb/include/lldb/Interpreter/Options.h +++ b/lldb/include/lldb/Interpreter/Options.h @@ -86,7 +86,7 @@ class Options { const OptionDefinition &option_def, uint32_t output_max_columns); - void GenerateOptionUsage(Stream &strm, CommandObject *cmd, + void GenerateOptionUsage(Stream &strm, CommandObject &cmd, uint32_t screen_width); bool SupportsLongOption(const char *long_option); diff --git a/lldb/source/Commands/CommandObjectDisassemble.cpp b/lldb/source/Commands/CommandObjectDisassemble.cpp index b02e071e7ac4f..9d081c83c0fb7 100644 --- a/lldb/source/Commands/CommandObjectDisassemble.cpp +++ b/lldb/source/Commands/CommandObjectDisassemble.cpp @@ -474,7 +474,7 @@ bool CommandObjectDisassemble::DoExecute(Args &command, "\"disassemble\" arguments are specified as options.\n"); const int terminal_width = GetCommandInterpreter().GetDebugger().GetTerminalWidth(); - GetOptions()->GenerateOptionUsage(result.GetErrorStream(), this, + GetOptions()->GenerateOptionUsage(result.GetErrorStream(), *this, terminal_width); return false; } diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp index 2a1cef7264ea7..0e6ddfa156763 100644 --- a/lldb/source/Commands/CommandObjectFrame.cpp +++ b/lldb/source/Commands/CommandObjectFrame.cpp @@ -348,7 +348,7 @@ class CommandObjectFrameSelect : public CommandObjectParsed { "too many arguments; expected frame-index, saw '%s'.\n", command[0].c_str()); m_options.GenerateOptionUsage( - result.GetErrorStream(), this, + result.GetErrorStream(), *this, GetCommandInterpreter().GetDebugger().GetTerminalWidth()); return false; } diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index c3376d04854e1..f42588b673a46 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -3815,7 +3815,7 @@ class CommandObjectTargetModulesLookup : public CommandObjectParsed { default: m_options.GenerateOptionUsage( - result.GetErrorStream(), this, + result.GetErrorStream(), *this, GetCommandInterpreter().GetDebugger().GetTerminalWidth()); syntax_error = true; break; diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index dcae27ff54790..b38bf86dbb870 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -132,7 +132,7 @@ bool CommandObject::ParseOptions(Args &args, CommandReturnObject &result) { } else { // No error string, output the usage information into result options->GenerateOptionUsage( - result.GetErrorStream(), this, + result.GetErrorStream(), *this, GetCommandInterpreter().GetDebugger().GetTerminalWidth()); } } @@ -326,7 +326,7 @@ bool CommandObject::HelpTextContainsWord(llvm::StringRef search_word, if (!found_word && search_options && GetOptions() != nullptr) { StreamString usage_help; GetOptions()->GenerateOptionUsage( - usage_help, this, + usage_help, *this, GetCommandInterpreter().GetDebugger().GetTerminalWidth()); if (!usage_help.Empty()) { llvm::StringRef usage_text = usage_help.GetString(); @@ -863,7 +863,7 @@ void CommandObject::GenerateHelpText(Stream &output_strm) { Options *options = GetOptions(); if (options != nullptr) { options->GenerateOptionUsage( - output_strm, this, + output_strm, *this, GetCommandInterpreter().GetDebugger().GetTerminalWidth()); } llvm::StringRef long_help = GetHelpLong(); diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp index 7d1f7667fb635..5957f46f34425 100644 --- a/lldb/source/Interpreter/Options.cpp +++ b/lldb/source/Interpreter/Options.cpp @@ -388,21 +388,15 @@ static bool PrintOption(const OptionDefinition &opt_def, return true; } -void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd, +void Options::GenerateOptionUsage(Stream &strm, CommandObject &cmd, uint32_t screen_width) { - const bool only_print_args = cmd->IsDashDashCommand(); + const bool only_print_args = cmd.IsDashDashCommand(); auto opt_defs = GetDefinitions(); const uint32_t save_indent_level = strm.GetIndentLevel(); - llvm::StringRef name; - + llvm::StringRef name = cmd.GetCommandName(); StreamString arguments_str; - - if (cmd) { - name = cmd->GetCommandName(); - cmd->GetFormattedCommandArguments(arguments_str); - } else - name = ""; + cmd.GetFormattedCommandArguments(arguments_str); const uint32_t num_options = NumCommandOptions(); if (num_options == 0) @@ -432,8 +426,7 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd, // Different option sets may require diff erent args. StreamString args_str; - if (cmd) - cmd->GetFormattedCommandArguments(args_str, opt_set_mask); + cmd.GetFormattedCommandArguments(args_str, opt_set_mask); // First go through and print all options that take no arguments as a // single string. If a command has "-a" "-b" and "-c", this will show up @@ -482,7 +475,7 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd, } if (args_str.GetSize() > 0) { - if (cmd->WantsRawCommandString() && !only_print_args) + if (cmd.WantsRawCommandString() && !only_print_args) strm.Printf(" --"); strm << " " << args_str.GetString(); @@ -492,7 +485,7 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd, } } - if (cmd && (only_print_args || cmd->WantsRawCommandString()) && + if ((only_print_args || cmd.WantsRawCommandString()) && arguments_str.GetSize() > 0) { if (!only_print_args) strm.PutChar('\n'); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits