[RFA,40/67] Constify some commands in tracepoint.c

Message ID 20170921051023.19023-41-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Sept. 21, 2017, 5:09 a.m. UTC
  ChangeLog
2017-09-20  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (delete_trace_variable_command)
	(tfind_end_command, tfind_start_command, tfind_pc_command)
	(tfind_tracepoint_command, tfind_line_command)
	(tfind_range_command, tfind_outside_command): Constify.
---
 gdb/ChangeLog    |  7 +++++++
 gdb/tracepoint.c | 42 ++++++++++++++++--------------------------
 2 files changed, 23 insertions(+), 26 deletions(-)
  

Comments

Pedro Alves Sept. 21, 2017, 10:03 a.m. UTC | #1
This looks OK, but ...

On 09/21/2017 06:09 AM, Tom Tromey wrote:

> @@ -2501,9 +2489,10 @@ tfind_range_command (char *args, int from_tty)
>  
>    if (0 != (tmp = strchr (args, ',')))
>      {
> -      *tmp++ = '\0';	/* Terminate start address.  */
> +      std::string start_addr (args, tmp);
> +      ++tmp;

... this fixes an actual bug:

 (gdb) tfind range 1, 2
 Breakpoint 4, tfind_range_command (args=0x30a0cbc "1, 2", from_tty=1) at src/gdb/tracepoint.c:2496
 ...
 (top gdb) c
 (gdb) <enter again for repeat>
 Breakpoint 4, tfind_range_command (args=0x30a0cbc "1", from_tty=1) at src/gdb/tracepoint.c:2496

Which is great, and shows that constification pays off.

I think it'd have been nice to split fixes like these to a
separate patch, or at least mention them in the commit log, though.

[/me goes read patches 2-40 again to double check.]

Thanks,
Pedro Alves
  
Tom Tromey Sept. 23, 2017, 4:33 a.m. UTC | #2
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> I think it'd have been nice to split fixes like these to a
Pedro> separate patch, or at least mention them in the commit log, though.

I wasn't actually even aware of that.

I added this to the commit message:

  In addition to the constification, this fixes a command-repeat bug.

Tom
  

Patch

diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 52a449a..30e3a3a 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -165,18 +165,6 @@  char *trace_notes = NULL;
 
 char *trace_stop_notes = NULL;
 
-/* ======= Important command functions: ======= */
-static void actions_command (char *, int);
-static void tstart_command (char *, int);
-static void tstop_command (char *, int);
-static void tstatus_command (char *, int);
-static void tfind_pc_command (char *, int);
-static void tfind_tracepoint_command (char *, int);
-static void tfind_line_command (char *, int);
-static void tfind_range_command (char *, int);
-static void tfind_outside_command (char *, int);
-static void tdump_command (char *, int);
-
 /* support routines */
 
 struct collection_list;
@@ -442,7 +430,7 @@  trace_variable_command (char *args, int from_tty)
 }
 
 static void
-delete_trace_variable_command (char *args, int from_tty)
+delete_trace_variable_command (const char *args, int from_tty)
 {
   if (args == NULL)
     {
@@ -2362,21 +2350,21 @@  tfind_command (char *args, int from_tty)
 
 /* tfind end */
 static void
-tfind_end_command (char *args, int from_tty)
+tfind_end_command (const char *args, int from_tty)
 {
   tfind_command_1 ("-1", from_tty);
 }
 
 /* tfind start */
 static void
-tfind_start_command (char *args, int from_tty)
+tfind_start_command (const char *args, int from_tty)
 {
   tfind_command_1 ("0", from_tty);
 }
 
 /* tfind pc command */
 static void
-tfind_pc_command (char *args, int from_tty)
+tfind_pc_command (const char *args, int from_tty)
 {
   CORE_ADDR pc;
 
@@ -2392,7 +2380,7 @@  tfind_pc_command (char *args, int from_tty)
 
 /* tfind tracepoint command */
 static void
-tfind_tracepoint_command (char *args, int from_tty)
+tfind_tracepoint_command (const char *args, int from_tty)
 {
   int tdp;
   struct tracepoint *tp;
@@ -2428,7 +2416,7 @@  tfind_tracepoint_command (char *args, int from_tty)
    corresponding to a source line OTHER THAN THE CURRENT ONE.  */
 
 static void
-tfind_line_command (char *args, int from_tty)
+tfind_line_command (const char *args, int from_tty)
 {
   check_trace_running (current_trace_status ());
 
@@ -2486,10 +2474,10 @@  tfind_line_command (char *args, int from_tty)
 
 /* tfind range command */
 static void
-tfind_range_command (char *args, int from_tty)
+tfind_range_command (const char *args, int from_tty)
 {
   static CORE_ADDR start, stop;
-  char *tmp;
+  const char *tmp;
 
   check_trace_running (current_trace_status ());
 
@@ -2501,9 +2489,10 @@  tfind_range_command (char *args, int from_tty)
 
   if (0 != (tmp = strchr (args, ',')))
     {
-      *tmp++ = '\0';	/* Terminate start address.  */
+      std::string start_addr (args, tmp);
+      ++tmp;
       tmp = skip_spaces (tmp);
-      start = parse_and_eval_address (args);
+      start = parse_and_eval_address (start_addr.c_str ());
       stop = parse_and_eval_address (tmp);
     }
   else
@@ -2517,10 +2506,10 @@  tfind_range_command (char *args, int from_tty)
 
 /* tfind outside command */
 static void
-tfind_outside_command (char *args, int from_tty)
+tfind_outside_command (const char *args, int from_tty)
 {
   CORE_ADDR start, stop;
-  char *tmp;
+  const char *tmp;
 
   if (current_trace_status ()->running
       && current_trace_status ()->filename == NULL)
@@ -2534,9 +2523,10 @@  tfind_outside_command (char *args, int from_tty)
 
   if (0 != (tmp = strchr (args, ',')))
     {
-      *tmp++ = '\0';	/* Terminate start address.  */
+      std::string start_addr (args, tmp);
+      ++tmp;
       tmp = skip_spaces (tmp);
-      start = parse_and_eval_address (args);
+      start = parse_and_eval_address (start_addr.c_str ());
       stop = parse_and_eval_address (tmp);
     }
   else