From patchwork Thu Apr 19 19:15:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26857 Received: (qmail 46572 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 46427 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.3 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=1487 X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.48.84) 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 gateway23.websitewelcome.com (Postfix) with ESMTP id 4FBA5311 for ; Thu, 19 Apr 2018 14:15:47 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 9F23fF39V5CKD9F23fnzBA; Thu, 19 Apr 2018 14:15:47 -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 1f9F22-0041O4-3b; Thu, 19 Apr 2018 14:15:47 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 3/8] Make print_command_trace varargs Date: Thu, 19 Apr 2018 13:15:34 -0600 Message-Id: <20180419191539.661-4-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: 1f9F22-0041O4-3b 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: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes I noticed some code in execute_control_command_1 that could be simplified by making print_command_trace a printf-like function. This patch makes this change. 2018-04-19 Tom Tromey * top.c (execute_command): Update. * cli/cli-script.h (print_command_lines): Now varargs. * cli/cli-script.c (print_command_lines): Now varargs. (execute_control_command_1) : Update. --- gdb/ChangeLog | 8 ++++++++ gdb/cli/cli-script.c | 22 ++++++++++------------ gdb/cli/cli-script.h | 3 ++- gdb/top.c | 2 +- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index b066da7d60..c7d405c0d0 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -426,8 +426,9 @@ reset_command_nest_depth (void) via while_command or if_command. Inner levels of 'if' and 'while' are dealt with directly. Therefore we can use these functions to determine whether the command has been printed already or not. */ +ATTRIBUTE_PRINTF (1, 2) void -print_command_trace (const char *cmd) +print_command_trace (const char *fmt, ...) { int i; @@ -443,7 +444,12 @@ print_command_trace (const char *cmd) for (i=0; i < command_nest_depth; i++) printf_filtered ("+"); - printf_filtered ("%s\n", cmd); + va_list args; + + va_start (args, fmt); + vprintf_filtered (fmt, args); + va_end (args); + puts_filtered ("\n"); } /* Helper for execute_control_command. */ @@ -490,11 +496,7 @@ execute_control_command_1 (struct command_line *cmd) case while_control: { - int len = strlen (cmd->line) + 7; - char *buffer = (char *) alloca (len); - - xsnprintf (buffer, len, "while %s", cmd->line); - print_command_trace (buffer); + print_command_trace ("while %s", cmd->line); /* Parse the loop control expression for the while statement. */ std::string new_line = insert_user_defined_cmd_args (cmd->line); @@ -555,11 +557,7 @@ execute_control_command_1 (struct command_line *cmd) case if_control: { - int len = strlen (cmd->line) + 4; - char *buffer = (char *) alloca (len); - - xsnprintf (buffer, len, "if %s", cmd->line); - print_command_trace (buffer); + print_command_trace ("if %s", cmd->line); /* Parse the conditional for the if statement. */ std::string new_line = insert_user_defined_cmd_args (cmd->line); diff --git a/gdb/cli/cli-script.h b/gdb/cli/cli-script.h index 58dede2342..10b6c17789 100644 --- a/gdb/cli/cli-script.h +++ b/gdb/cli/cli-script.h @@ -148,7 +148,8 @@ extern std::string insert_user_defined_cmd_args (const char *line); /* Exported to top.c */ -extern void print_command_trace (const char *cmd); +extern void print_command_trace (const char *cmd, ...) + ATTRIBUTE_PRINTF (1, 2); /* Exported to event-top.c */ diff --git a/gdb/top.c b/gdb/top.c index 8903a92983..6f5abd5a3d 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -571,7 +571,7 @@ execute_command (const char *p, int from_tty) line = p; /* If trace-commands is set then this will print this command. */ - print_command_trace (p); + print_command_trace ("%s", p); c = lookup_cmd (&cmd, cmdlist, "", 0, 1); p = cmd;