From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id /UnFF1lgwl8sagAAWB0awg (envelope-from ) for ; Sat, 28 Nov 2020 09:36:09 -0500 Received: by simark.ca (Postfix, from userid 112) id 54C861F0AB; Sat, 28 Nov 2020 09:36:09 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 4FE671E552 for ; Sat, 28 Nov 2020 09:36:07 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 700373854808; Sat, 28 Nov 2020 14:36:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 700373854808 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606574166; bh=gVaE9iSlNHDgDVq9MHwARMbtWvipfriG+IwsRgh77oo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=rwcqHl8T2SGcv0OMX/bRW2XvzHX/0dnoSwBynmucm0TcFPljcXbOKJtSKNrvn1PBv F0FDsYBo3VUUf8bNk2fQeVySjwnJWGzSivFGDFUj2FQyUThgRTj9BNVlfqiM6HLAX7 JdeOvVpwFSZrJvuBq9AA/Y+gItomYGvO1n43M6Jk= Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id E8E5D3854808 for ; Sat, 28 Nov 2020 14:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E8E5D3854808 Received: by mail-pg1-x535.google.com with SMTP id 34so6591558pgp.10 for ; Sat, 28 Nov 2020 06:36:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :mime-version:content-transfer-encoding; bh=gVaE9iSlNHDgDVq9MHwARMbtWvipfriG+IwsRgh77oo=; b=p9W8AjpNOV2DhC+0bumubjnNbW6tJbvHvx4I/98H+uzCZJfgyr67YhW5wgx6iK/jav nTERoN/HXe6G8jYXfjS2TvsizyF6n0KiN61N0DBBYr5d4lELyQdOwMZcqT1awUA2XFl+ ef7idetwIoiZnneuSW49xw4fg508p1pWqgf09X5ru4ostDaViOPMs4gkM7uhVqnvrEA9 AsgoMFBd8OxHWAHnL+YY0aH3UHEZUnN8Cu6EK6kMJkhsarUvLH0FwAYD7J7DwTFlREKD t/1suwODo5MZnnTvnq6PGBLwpEivi0s09WbYADMzNS5fnlwecx/BlXkgEWWU08CexU69 DoPQ== X-Gm-Message-State: AOAM533cC3ikX7CNBtCxEghWGQUu4YJ6C5q1XBVCfhLUDYAHGEiemgOm JNG8CgMoeXF3sQ8sVwrLCDYw1F+nztQ= X-Google-Smtp-Source: ABdhPJyhu8ZTzf9BApdRZYZZHNyvnYMMppzyG474ytHiJe87cuJMMD37itPG1Gp55p3xumtObmDPlA== X-Received: by 2002:a62:e416:0:b029:197:eed6:c8b9 with SMTP id r22-20020a62e4160000b0290197eed6c8b9mr11505163pfh.57.1606574162503; Sat, 28 Nov 2020 06:36:02 -0800 (PST) Received: from raekf.iptime.org ([122.37.26.177]) by smtp.gmail.com with ESMTPSA id e21sm11030524pfd.107.2020.11.28.06.36.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2020 06:36:02 -0800 (PST) To: gdb-patches@sourceware.org Subject: [PATCH] gdb: multi-line support for "document" command Date: Sat, 28 Nov 2020 23:24:54 +0900 Message-Id: <20201128142453.893743-1-rae.kim@gmail.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Rae Kim via Gdb-patches Reply-To: Rae Kim Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" "document" command executed in python, gdb.execute("document \n...\nend\n"), will wait for user input. Python extension stops working from that point. "define" command works well with gdb.execute(). Looks like, when multi-line support was first introdued in commit 56bcdbea2b, "document" was left out. I checked the way "define" handles multi-line mode. And applied it to "document" command. gdb/ChangeLog: 2020-11-28 Rae Kim * gdb/cli/cli-script.c (do_document_command): Renamed from * document_command() and handles multi-line input (multi_line_command_p): Handles document_control. (build_command_line): Likewise. (execute_control_command_1): Likewise. (process_next_line): Likewise. (document_command): Calls do_document_command with. * gdb/cli/cli-script.h (enum command_control_type): Added document_control. --- gdb/cli/cli-script.c | 42 ++++++++++++++++++++++++++++++++++++++---- gdb/cli/cli-script.h | 1 + 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index afa44af95a..25807080e5 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -51,6 +51,9 @@ recurse_read_control_structure 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. */ @@ -71,6 +74,9 @@ static cmd_list_element *if_cmd_element = nullptr; /* 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 @@ -139,6 +145,7 @@ multi_line_command_p (enum command_control_type type) case python_control: case guile_control: case define_control: + case document_control: return 1; default: return 0; @@ -159,6 +166,8 @@ build_command_line (enum command_control_type type, const char *args) 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); @@ -679,6 +688,12 @@ execute_control_command_1 (struct command_line *cmd, int from_tty) 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: { @@ -1019,6 +1034,8 @@ process_next_line (const char *p, struct command_line **command, *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 @@ -1508,8 +1525,13 @@ define_command (const char *comname, int from_tty) 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; @@ -1526,8 +1548,14 @@ document_command (const char *comname, int from_tty) std::string prompt = string_printf ("Type documentation for \"%s\".", comfull); - counted_command_line doclines = read_command_lines (prompt.c_str (), + + counted_command_line doclines; + + if (commands == nullptr) + doclines = read_command_lines (prompt.c_str (), from_tty, 0, 0); + else + doclines = *commands; xfree ((char *) c->doc); @@ -1553,6 +1581,12 @@ document_command (const char *comname, int from_tty) } } +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 @@ -1676,11 +1710,11 @@ _initialize_cli_script () /* "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\ diff --git a/gdb/cli/cli-script.h b/gdb/cli/cli-script.h index fcae9abaa9..6ad6e61fb4 100644 --- a/gdb/cli/cli-script.h +++ b/gdb/cli/cli-script.h @@ -45,6 +45,7 @@ enum command_control_type guile_control, while_stepping_control, define_control, + document_control, invalid_control }; -- 2.28.0