diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index b8be3f54921..9b965ea9989 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -1345,7 +1345,7 @@ fput_aliases_definition_styled (const cmd_list_element &cmd, struct ui_file *stream) { for (const cmd_list_element &alias : cmd.aliases) - if (!alias.default_args.empty ()) + if (!alias.cmd_deprecated && !alias.default_args.empty ()) fput_alias_definition_styled (alias, stream); } @@ -1361,17 +1361,40 @@ fput_command_names_styled (const cmd_list_element &c, bool always_fput_c_name, const char *postfix, struct ui_file *stream) { - if (always_fput_c_name || !c.aliases.empty ()) + /* First, check if we are going to print something. That is, either if + ALWAYS_FPUT_C_NAME is true or if there exists at least one non-deprecated + alias. */ + + auto print_alias = [] (const cmd_list_element &alias) + { + return !alias.cmd_deprecated; + }; + + bool print_something = always_fput_c_name; + if (!print_something) + for (const cmd_list_element &alias : c.aliases) + { + if (!print_alias (alias)) + continue; + + print_something = true; + break; + } + + if (print_something) fput_command_name_styled (c, stream); for (const cmd_list_element &alias : c.aliases) { + if (!print_alias (alias)) + continue; + fputs_filtered (", ", stream); wrap_here (" "); fput_command_name_styled (alias, stream); } - if (always_fput_c_name || !c.aliases.empty ()) + if (print_something) fputs_filtered (postfix, stream); } diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp index 6785f9532b1..1dca419f0fb 100644 --- a/gdb/testsuite/gdb.base/commands.exp +++ b/gdb/testsuite/gdb.base/commands.exp @@ -709,6 +709,27 @@ maintenance deprecate set qqq_aaa" file delete $file1 } +# Test that the help for a command does not show deprecated aliases. + +proc_with_prefix deprecated_command_alias_help_test {} { + gdb_test_multiline "define real_command" \ + "define real_command" "End with a line saying just \"end\".." \ + "print 1" "" \ + "end" "" + + gdb_test_no_output "alias alias_command = real_command" + gdb_test_no_output "alias alias_with_args_command = real_command 123" + + gdb_test "help real_command" \ + "real_command, alias_with_args_command, alias_command\r\n alias alias_with_args_command = real_command 123\r\nUser-defined." \ + "help real_command, before" + gdb_test_no_output "maintenance deprecate alias_command" + gdb_test_no_output "maintenance deprecate alias_with_args_command" + gdb_test "help real_command" \ + "User-defined." \ + "help real_command, after" +} + proc_with_prefix bp_deleted_in_command_test {} { global gdb_prompt @@ -1203,6 +1224,7 @@ user_defined_command_manyargs_test watchpoint_command_test test_command_prompt_position deprecated_command_test +deprecated_command_alias_help_test bp_deleted_in_command_test temporary_breakpoint_commands stray_arg0_test