static void do_define_command (const char *comname, int from_tty,
const counted_command_line *commands);
+static void do_document_command (const char *comname, int from_tty,
+ const counted_command_line *commands);
+
static const char *read_next_line ();
/* Level of control structure when reading. */
/* Command element for the 'define' command. */
static cmd_list_element *define_cmd_element = nullptr;
+/* Command element for the 'document' command. */
+static cmd_list_element *document_cmd_element = nullptr;
+
/* Structure for arguments to user defined functions. */
class user_args
case python_control:
case guile_control:
case define_control:
+ case document_control:
return 1;
default:
return 0;
error (_("while command requires an argument."));
else if (type == define_control)
error (_("define command requires an argument."));
+ else if (type == document_control)
+ error (_("document command requires an argument."));
}
gdb_assert (args != NULL);
ret = simple_control;
break;
+ case document_control:
+ print_command_trace ("document %s", cmd->line);
+ do_document_command (cmd->line, 0, &cmd->body_list_0);
+ ret = simple_control;
+ break;
+
case python_control:
case guile_control:
{
*command = build_command_line (commands_control, line_first_arg (p));
else if (cmd == define_cmd_element)
*command = build_command_line (define_control, line_first_arg (p));
+ else if (cmd == document_cmd_element)
+ *command = build_command_line (document_control, line_first_arg (p));
else if (cmd == python_cmd_element && !inline_cmd)
{
/* Note that we ignore the inline "python command" form
do_define_command (comname, from_tty, nullptr);
}
+/* Document a user-defined command. If COMMANDS is NULL, then this is a
+ top-level call and the document will be read using read_command_lines.
+ Otherwise, it is a "document" command in an existing command and the
+ commands are provided. */
static void
-document_command (const char *comname, int from_tty)
+do_document_command (const char *comname, int from_tty,
+ const counted_command_line *commands)
{
struct cmd_list_element *c, **list;
const char *tem;
if (c->theclass != class_user)
error (_("Command \"%s\" is built-in."), comfull);
- std::string prompt = string_printf ("Type documentation for \"%s\".",
- comfull);
- counted_command_line doclines = read_command_lines (prompt.c_str (),
- from_tty, 0, 0);
+ counted_command_line doclines;
+
+ if (commands == nullptr)
+ {
+ std::string prompt
+ = string_printf ("Type documentation for \"%s\".", comfull);
+ doclines = read_command_lines (prompt.c_str (), from_tty, 0, 0);
+ }
+ else
+ doclines = *commands;
xfree ((char *) c->doc);
}
}
+static void
+document_command (const char *comname, int from_tty)
+{
+ do_document_command (comname, from_tty, nullptr);
+}
+
/* Implementation of the "define-prefix" command. */
static void
/* "document", "define" and "define-prefix" use command_completer,
as this helps the user to either type the command name and/or
its prefixes. */
- c = add_com ("document", class_support, document_command, _("\
+ document_cmd_element = add_com ("document", class_support, document_command,
+ _("\
Document a user-defined command.\n\
Give command name as argument. Give documentation on following lines.\n\
End with a line of just \"end\"."));
- set_cmd_completer (c, command_completer);
+ set_cmd_completer (document_cmd_element, command_completer);
define_cmd_element = add_com ("define", class_support, define_command, _("\
Define a new command name. Command name is argument.\n\
Definition appears on following lines, one command per line.\n\
--- /dev/null
+# Copyright 1998-2020 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile break.c break1.c
+
+if {[prepare_for_testing "failed to prepare" ${testfile} \
+ [list $srcfile $srcfile2] {debug nowarnings}]} {
+ return -1
+}
+
+# test document command used within user command.
+gdb_test_multiple "define do-document" "" {
+ -re "Type commands for definition of \"do-document\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+ gdb_test "document do-document\nusage: do-document\nend\nend" "" "define do-document"
+ }
+}
+gdb_test_no_output "do-document" "invoke do-document"
+gdb_test "help do-document" "usage: do-document" "invoke help do-document"