Constify prompt argument to read_command_lines
authorTom Tromey <tom@tromey.com>
Wed, 18 Apr 2018 21:59:04 +0000 (15:59 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 4 May 2018 21:58:07 +0000 (15:58 -0600)
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.

ChangeLog
2018-05-04  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
gdb/breakpoint.c
gdb/cli/cli-script.c
gdb/cli/cli-script.h
gdb/tracepoint.c

index 96009336db5dab42600c454ff9dadc6f3667c0cf..3692ae60485e72f327836cd91377f4eafd2a525f 100644 (file)
@@ -1,3 +1,13 @@
+2018-05-04  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.
+
 2018-05-04  Tom Tromey  <tom@tromey.com>
 
        * top.c (execute_command): Update.
index 7d1daa266fc0451a3d899cee6e8a74a18e5d0c34..72a3e1608de4ca1a88a2723a70adbcb20972a45f 100644 (file)
@@ -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);
index c7d405c0d0bd6d44c83c388caee485406968f273..36740b97ad8cc91d586ce5ef954504ceefdab510 100644 (file)
@@ -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);
index 10b6c177892adb96c80f75dd0a55d5bdde9e46c0..7e5f94c0ad3dd20a500ad8fc728cbbacd78b4d7f 100644 (file)
@@ -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,
index 3926304bf601373ed2d38878a46ffc839cd0bd66..189a97d49f0865b78bbdc04ec20647b1c9c3747b 100644 (file)
@@ -577,7 +577,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));
This page took 0.036813 seconds and 4 git commands to generate.