From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA v2 3/8] Make print_command_trace varargs
Date: Wed, 25 Apr 2018 15:41:00 -0000 [thread overview]
Message-ID: <20180425154133.3989-4-tom@tromey.com> (raw)
In-Reply-To: <20180425154133.3989-1-tom@tromey.com>
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.
gdb/ChangeLog
2018-04-25 Tom Tromey <tom@tromey.com>
* 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) <case while_control, case if_control>:
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;
--
2.13.6
next prev parent reply other threads:[~2018-04-25 15:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-25 15:41 [RFA v2 0/8] Various command-related improvements Tom Tromey
2018-04-25 15:41 ` [RFA v2 7/8] Allow breakpoint commands to be set from Python Tom Tromey
2018-04-25 16:13 ` Eli Zaretskii
2018-04-30 13:07 ` Phil Muldoon
2018-04-30 14:40 ` Tom Tromey
2018-04-25 15:41 ` [RFA v2 8/8] Let gdb.execute handle multi-line commands Tom Tromey
2018-04-25 16:16 ` Eli Zaretskii
2018-04-25 15:41 ` Tom Tromey [this message]
2018-04-25 15:41 ` [RFA v2 6/8] Use function_view in cli-script.c Tom Tromey
2018-04-25 15:41 ` [RFA v2 4/8] Constify prompt argument to read_command_lines Tom Tromey
2018-04-25 15:41 ` [RFA v2 1/8] Allocate cmd_list_element with new Tom Tromey
2018-04-25 15:41 ` [RFA v2 2/8] Use counted_command_line everywhere Tom Tromey
2018-04-25 15:41 ` [RFA v2 5/8] Allow defining a user command inside a user command Tom Tromey
2018-05-04 19:09 ` [RFA v2 0/8] Various command-related improvements Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180425154133.3989-4-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).