[15/18] -Wwrite-strings: execute_command calls with string literals

Message ID 1491326751-16180-16-git-send-email-palves@redhat.com
State New, archived
Headers

Commit Message

Pedro Alves April 4, 2017, 5:25 p.m. UTC
  This is ugly, but it's just making the uglyness explicit.

All these places would better be calling some API function directly
instead of going through execute_command & friends...

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* event-top.c (command_line_handler): Add cast to execute_command
	call.
	* record-btrace.c (cmd_record_btrace_bts_start)
	(cmd_record_btrace_pt_start, cmd_record_btrace_start)
	(cmd_record_btrace_start): Add cast to execute_command call.
	* record-full.c (record_full_goto_insn):
	* record.c (record_start, record_stop): Add cast to
	execute_command_to_string calls.
	(cmd_record_start): Add cast to execute_command calls.
---
 gdb/event-top.c     |  2 +-
 gdb/record-btrace.c |  8 ++++----
 gdb/record-full.c   |  2 +-
 gdb/record.c        | 14 +++++++-------
 4 files changed, 13 insertions(+), 13 deletions(-)
  

Comments

Metzger, Markus T April 5, 2017, 7:13 a.m. UTC | #1
Hello Pedro,

> All these places would better be calling some API function directly
> instead of going through execute_command & friends...

Ah, and I thought this is the preferred way.


The patch looks good to me.  But I'm wondering if we should instead change
execute_command to take a const char *.

Regards,
Markus.

Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  
Pedro Alves April 5, 2017, 1:10 p.m. UTC | #2
On 04/05/2017 08:13 AM, Metzger, Markus T wrote:

> The patch looks good to me.  But I'm wondering if we should instead change
> execute_command to take a const char *.

That's not that simple, because some commands do want to modify the
input string.

For example, cli/cli-cmds.c:list_command does:

  /* If this command is repeated with RET,
     turn it into the no-arg variant.  */

  if (from_tty)
    *arg = 0;


and also, it'd require a lot of cascading constification
inside many commands, because lots of command args processing
passes "&args" to some routine that expects a "char **".

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/event-top.c b/gdb/event-top.c
index 5d8d077..dd2770a 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -766,7 +766,7 @@  command_line_handler (char *rl)
 	 hung up but GDB is still alive.  In such a case, we just quit
 	 gdb killing the inferior program too.  */
       printf_unfiltered ("quit\n");
-      execute_command ("quit", 1);
+      execute_command ((char *) "quit", 1);
     }
   else if (cmd == NULL)
     {
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index af025e2..61fba1e 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -2897,7 +2897,7 @@  cmd_record_btrace_bts_start (char *args, int from_tty)
 
   TRY
     {
-      execute_command ("target record-btrace", from_tty);
+      execute_command ((char *) "target record-btrace", from_tty);
     }
   CATCH (exception, RETURN_MASK_ALL)
     {
@@ -2919,7 +2919,7 @@  cmd_record_btrace_pt_start (char *args, int from_tty)
 
   TRY
     {
-      execute_command ("target record-btrace", from_tty);
+      execute_command ((char *) "target record-btrace", from_tty);
     }
   CATCH (exception, RETURN_MASK_ALL)
     {
@@ -2941,7 +2941,7 @@  cmd_record_btrace_start (char *args, int from_tty)
 
   TRY
     {
-      execute_command ("target record-btrace", from_tty);
+      execute_command ((char *) "target record-btrace", from_tty);
     }
   CATCH (exception, RETURN_MASK_ALL)
     {
@@ -2949,7 +2949,7 @@  cmd_record_btrace_start (char *args, int from_tty)
 
       TRY
 	{
-	  execute_command ("target record-btrace", from_tty);
+	  execute_command ((char *) "target record-btrace", from_tty);
 	}
       CATCH (exception, RETURN_MASK_ALL)
 	{
diff --git a/gdb/record-full.c b/gdb/record-full.c
index bd95acc..31ff558 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -2788,7 +2788,7 @@  record_full_goto_insn (struct record_full_entry *entry,
 static void
 cmd_record_full_start (char *args, int from_tty)
 {
-  execute_command ("target record-full", from_tty);
+  execute_command ((char *) "target record-full", from_tty);
 }
 
 static void
diff --git a/gdb/record.c b/gdb/record.c
index eff8fe1..16e5b03 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -99,25 +99,25 @@  record_start (const char *method, const char *format, int from_tty)
   if (method == NULL)
     {
       if (format == NULL)
-	execute_command_to_string ("record", from_tty);
+	execute_command_to_string ((char *) "record", from_tty);
       else
 	error (_("Invalid format."));
     }
   else if (strcmp (method, "full") == 0)
     {
       if (format == NULL)
-	execute_command_to_string ("record full", from_tty);
+	execute_command_to_string ((char *) "record full", from_tty);
       else
 	error (_("Invalid format."));
     }
   else if (strcmp (method, "btrace") == 0)
     {
       if (format == NULL)
-	execute_command_to_string ("record btrace", from_tty);
+	execute_command_to_string ((char *) "record btrace", from_tty);
       else if (strcmp (format, "bts") == 0)
-	execute_command_to_string ("record btrace bts", from_tty);
+	execute_command_to_string ((char *) "record btrace bts", from_tty);
       else if (strcmp (format, "pt") == 0)
-	execute_command_to_string ("record btrace pt", from_tty);
+	execute_command_to_string ((char *) "record btrace pt", from_tty);
       else
 	error (_("Invalid format."));
     }
@@ -130,7 +130,7 @@  record_start (const char *method, const char *format, int from_tty)
 void
 record_stop (int from_tty)
 {
-  execute_command_to_string ("record stop", from_tty);
+  execute_command_to_string ((char *) "record stop", from_tty);
 }
 
 /* See record.h.  */
@@ -265,7 +265,7 @@  show_record_debug (struct ui_file *file, int from_tty,
 static void
 cmd_record_start (char *args, int from_tty)
 {
-  execute_command ("target record-full", from_tty);
+  execute_command ((char *) "target record-full", from_tty);
 }
 
 /* Truncate the record log from the present point