Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 4/8] Constify prompt argument to read_command_lines
Date: Thu, 19 Apr 2018 19:16:00 -0000	[thread overview]
Message-ID: <20180419191539.661-5-tom@tromey.com> (raw)
In-Reply-To: <20180419191539.661-1-tom@tromey.com>

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  <tom@tromey.com>

	* 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));
-- 
2.13.6


  parent reply	other threads:[~2018-04-19 19:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-19 19:16 [RFA 0/8] Various command-related improvements Tom Tromey
2018-04-19 19:16 ` [RFA 6/8] Use function_view in cli-script.c Tom Tromey
2018-04-22 19:02   ` Pedro Alves
2018-04-24 23:38     ` Tom Tromey
2018-04-19 19:16 ` Tom Tromey [this message]
2018-04-24 16:43   ` [RFA 4/8] Constify prompt argument to read_command_lines Pedro Alves
2018-04-19 19:16 ` [RFA 7/8] Allow breakpoint commands to be set from Python Tom Tromey
2018-04-19 19:31   ` Eli Zaretskii
2018-04-24 16:43   ` Pedro Alves
2018-04-19 19:16 ` [RFA 5/8] Allow defining a user command inside a user command Tom Tromey
2018-04-24 16:43   ` Pedro Alves
2018-04-24 23:24     ` Tom Tromey
2018-04-19 19:16 ` [RFA 2/8] Use counted_command_line everywhere Tom Tromey
2018-04-24 16:43   ` Pedro Alves
2018-04-24 23:11     ` Tom Tromey
2018-04-24 23:18     ` Tom Tromey
2018-04-19 19:16 ` [RFA 8/8] Let gdb.execute handle multi-line commands Tom Tromey
2018-04-19 19:32   ` Eli Zaretskii
2018-04-24 16:44   ` Pedro Alves
2018-04-19 19:16 ` [RFA 3/8] Make print_command_trace varargs Tom Tromey
2018-04-24 16:43   ` Pedro Alves
2018-04-19 19:16 ` [RFA 1/8] Allocate cmd_list_element with new Tom Tromey

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=20180419191539.661-5-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