From patchwork Thu Apr 19 19:15:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26858 Received: (qmail 46601 invoked by alias); 19 Apr 2018 19:16:04 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 46426 invoked by uid 89); 19 Apr 2018 19:15:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Enter X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.45.154) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Apr 2018 19:15:50 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 31545400D564E for ; Thu, 19 Apr 2018 14:15:48 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 9F24fF3BK5CKD9F24fnzD0; Thu, 19 Apr 2018 14:15:48 -0500 X-Authority-Reason: nr=8 Received: from 97-122-176-117.hlrn.qwest.net ([97.122.176.117]:44916 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1f9F23-0041O4-PQ; Thu, 19 Apr 2018 14:15:48 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 4/8] Constify prompt argument to read_command_lines Date: Thu, 19 Apr 2018 13:15:35 -0600 Message-Id: <20180419191539.661-5-tom@tromey.com> In-Reply-To: <20180419191539.661-1-tom@tromey.com> References: <20180419191539.661-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1f9F23-0041O4-PQ X-Source-Sender: 97-122-176-117.hlrn.qwest.net (bapiya.Home) [97.122.176.117]:44916 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes The prompt argument to read_command_lines can be const. This patch makes this change, and also removes some fixed-sized buffers in favor of using string_printf. 2018-04-19 Tom Tromey * tracepoint.c (actions_command): Update. * cli/cli-script.h (read_command_lines): Update. * cli/cli-script.c (read_command_lines): Constify prompt_arg. (MAX_TMPBUF): Remove define. (define_command): Use string_printf. (document_command): Likewise. * breakpoint.c (commands_command_1): Update. --- gdb/ChangeLog | 10 ++++++++++ gdb/breakpoint.c | 3 +-- gdb/cli/cli-script.c | 20 +++++++++----------- gdb/cli/cli-script.h | 2 +- gdb/tracepoint.c | 3 ++- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 2cb9c4b657..7d284e9a96 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -1256,8 +1256,7 @@ commands_command_1 (const char *arg, int from_tty, "%s, one per line."), arg); - cmd = read_command_lines (&str[0], - from_tty, 1, + cmd = read_command_lines (str.c_str (), from_tty, 1, (is_tracepoint (b) ? check_tracepoint_command : 0), b); diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index c7d405c0d0..36740b97ad 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -1121,7 +1121,7 @@ recurse_read_control_structure (char * (*read_next_line_func) (void), #define END_MESSAGE "End with a line saying just \"end\"." counted_command_line -read_command_lines (char *prompt_arg, int from_tty, int parse_commands, +read_command_lines (const char *prompt_arg, int from_tty, int parse_commands, void (*validator)(char *, void *), void *closure) { if (from_tty && input_interactive_p (current_ui)) @@ -1306,7 +1306,6 @@ user_defined_command (const char *ignore, int from_tty) static void define_command (const char *comname, int from_tty) { -#define MAX_TMPBUF 128 enum cmd_hook_type { CMD_NO_HOOK = 0, @@ -1315,7 +1314,6 @@ define_command (const char *comname, int from_tty) }; struct cmd_list_element *c, *newc, *hookc = 0, **list; const char *tem, *comfull; - char tmpbuf[MAX_TMPBUF]; int hook_type = CMD_NO_HOOK; int hook_name_size = 0; @@ -1379,9 +1377,10 @@ define_command (const char *comname, int from_tty) comname = xstrdup (comname); - xsnprintf (tmpbuf, sizeof (tmpbuf), - "Type commands for definition of \"%s\".", comfull); - counted_command_line cmds = read_command_lines (tmpbuf, from_tty, 1, 0, 0); + std::string prompt + = string_printf ("Type commands for definition of \"%s\".", comfull); + counted_command_line cmds = read_command_lines (prompt.c_str (), from_tty, + 1, 0, 0); newc = add_cmd (comname, class_user, user_defined_command, (c && c->theclass == class_user) @@ -1416,7 +1415,6 @@ document_command (const char *comname, int from_tty) struct cmd_list_element *c, **list; const char *tem; const char *comfull; - char tmpbuf[128]; comfull = comname; list = validate_comname (&comname); @@ -1427,10 +1425,10 @@ document_command (const char *comname, int from_tty) if (c->theclass != class_user) error (_("Command \"%s\" is built-in."), comfull); - xsnprintf (tmpbuf, sizeof (tmpbuf), "Type documentation for \"%s\".", - comfull); - counted_command_line doclines = read_command_lines (tmpbuf, from_tty, - 0, 0, 0); + std::string prompt = string_printf ("Type documentation for \"%s\".", + comfull); + counted_command_line doclines = read_command_lines (prompt.c_str (), + from_tty, 0, 0, 0); if (c->doc) xfree ((char *) c->doc); diff --git a/gdb/cli/cli-script.h b/gdb/cli/cli-script.h index 10b6c17789..7e5f94c0ad 100644 --- a/gdb/cli/cli-script.h +++ b/gdb/cli/cli-script.h @@ -105,7 +105,7 @@ private: } }; -extern counted_command_line read_command_lines (char *, int, int, +extern counted_command_line read_command_lines (const char *, int, int, void (*)(char *, void *), void *); extern counted_command_line read_command_lines_1 (char * (*) (void), int, diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 0c3842199f..0c62b957ef 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -578,7 +578,8 @@ actions_command (const char *args, int from_tty) string_printf ("Enter actions for tracepoint %d, one per line.", t->number); - counted_command_line l = read_command_lines (&tmpbuf[0], from_tty, 1, + counted_command_line l = read_command_lines (tmpbuf.c_str (), + from_tty, 1, check_tracepoint_command, t); breakpoint_set_commands (t, std::move (l));