Constify some linespec functions
authorTom Tromey <tom@tromey.com>
Wed, 13 Sep 2017 00:32:41 +0000 (18:32 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 27 Sep 2017 14:44:45 +0000 (08:44 -0600)
This changes a few linespec functions to work on "const char *" and
then fixes up all the callers.  This allows further constification
elsewhere.

gdb/ChangeLog
2017-09-27  Tom Tromey  <tom@tromey.com>

* tracepoint.c (info_scope_command): Constify.
* python/python.c (gdbpy_decode_line): Constify.
* python/py-breakpoint.c (bppy_init): Constify.
* mi/mi-cmd-break.c (mi_cmd_break_insert_1): Constify.
* location.h: (new_linespec_location)
(string_to_event_location_basic, string_to_event_location):
Constify.
* location.c (new_linespec_location)
(string_to_event_location_basic, string_to_event_location):
Constify.
* linespec.h (decode_line_with_current_source)
(decode_line_with_last_displayed, linespec_lex_to_end): Constify.
* linespec.c (linespec_lex_to_end)
(decode_line_with_current_source)
(decode_line_with_last_displayed): Constify.
* guile/scm-breakpoint.c (gdbscm_register_breakpoint_x):
Constify.
* cli/cli-cmds.c (edit_command, list_command): Constify.
* breakpoint.h (until_break_command, watch_command_wrapper)
(awatch_command_wrapper, rwatch_command_wrapper)
(init_ada_exception_breakpoint): Constify.
* breakpoint.c (break_command_1, dprintf_command)
(break_range_command, watch_command_wrapper)
(rwatch_command_wrapper, awatch_command_wrapper)
(until_break_command, init_ada_exception_breakpoint)
(strace_marker_create_sals_from_location, trace_command)
(ftrace_command, strace_command, struct tracepoint): Constify.
* ax-gdb.c (agent_command_1): Constify.
* ada-lang.c (ada_exception_sal): Constify.

15 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/ax-gdb.c
gdb/breakpoint.c
gdb/breakpoint.h
gdb/cli/cli-cmds.c
gdb/guile/scm-breakpoint.c
gdb/linespec.c
gdb/linespec.h
gdb/location.c
gdb/location.h
gdb/mi/mi-cmd-break.c
gdb/python/py-breakpoint.c
gdb/python/python.c
gdb/tracepoint.c

index 8ed3b5275a7bdd73afcfa0582512c3c9e9cbde4e..08705c0340ce1426231b3f80a3f89cb73208128c 100644 (file)
@@ -1,3 +1,35 @@
+2017-09-27  Tom Tromey  <tom@tromey.com>
+
+       * tracepoint.c (info_scope_command): Constify.
+       * python/python.c (gdbpy_decode_line): Constify.
+       * python/py-breakpoint.c (bppy_init): Constify.
+       * mi/mi-cmd-break.c (mi_cmd_break_insert_1): Constify.
+       * location.h: (new_linespec_location)
+       (string_to_event_location_basic, string_to_event_location):
+       Constify.
+       * location.c (new_linespec_location)
+       (string_to_event_location_basic, string_to_event_location):
+       Constify.
+       * linespec.h (decode_line_with_current_source)
+       (decode_line_with_last_displayed, linespec_lex_to_end): Constify.
+       * linespec.c (linespec_lex_to_end)
+       (decode_line_with_current_source)
+       (decode_line_with_last_displayed): Constify.
+       * guile/scm-breakpoint.c (gdbscm_register_breakpoint_x):
+       Constify.
+       * cli/cli-cmds.c (edit_command, list_command): Constify.
+       * breakpoint.h (until_break_command, watch_command_wrapper)
+       (awatch_command_wrapper, rwatch_command_wrapper)
+       (init_ada_exception_breakpoint): Constify.
+       * breakpoint.c (break_command_1, dprintf_command)
+       (break_range_command, watch_command_wrapper)
+       (rwatch_command_wrapper, awatch_command_wrapper)
+       (until_break_command, init_ada_exception_breakpoint)
+       (strace_marker_create_sals_from_location, trace_command)
+       (ftrace_command, strace_command, struct tracepoint): Constify.
+       * ax-gdb.c (agent_command_1): Constify.
+       * ada-lang.c (ada_exception_sal): Constify.
+
 2017-09-27  Tom Tromey  <tom@tromey.com>
 
        * record.c (cmd_record_delete, cmd_record_stop, cmd_record_save)
index 64f1a336b729be2f20cb1cbfd8d23138180e643f..ea051c3e2c8d1b9f33b22aceac5adeb28ca2a517 100644 (file)
@@ -12925,7 +12925,7 @@ ada_exception_catchpoint_cond_string (const char *excep_string)
 
 static struct symtab_and_line
 ada_exception_sal (enum ada_exception_catchpoint_kind ex, char *excep_string,
-                  char **addr_string, const struct breakpoint_ops **ops)
+                  const char **addr_string, const struct breakpoint_ops **ops)
 {
   const char *sym_name;
   struct symbol *sym;
@@ -12984,7 +12984,7 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch,
                                 int disabled,
                                 int from_tty)
 {
-  char *addr_string = NULL;
+  const char *addr_string = NULL;
   const struct breakpoint_ops *ops = NULL;
   struct symtab_and_line sal
     = ada_exception_sal (ex_kind, excep_string, &addr_string, &ops);
index 227590b1a98bfcf0b1e88362911a0d85e65eb278..c4bf2a688e3396f0d8ab1188c6b04b0a29b7cd9e 100644 (file)
@@ -2622,7 +2622,7 @@ agent_eval_command_one (const char *exp, int eval, CORE_ADDR pc)
 }
 
 static void
-agent_command_1 (char *exp, int eval)
+agent_command_1 (const char *exp, int eval)
 {
   /* We don't deal with overlay debugging at the moment.  We need to
      think more carefully about this.  If you copy this code into
index 5549fe735810b03f6b2221b17ad12bf4e7f54dc6..1073418e7758f2b9ecd18feef59ecc410dd52b1a 100644 (file)
@@ -138,8 +138,6 @@ static void catch_command (char *, int);
 
 static int can_use_hardware_watchpoint (struct value *);
 
-static void break_command_1 (char *, int, int);
-
 static void mention (struct breakpoint *);
 
 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *,
@@ -9679,7 +9677,7 @@ create_breakpoint (struct gdbarch *gdbarch,
    and BP_TEMPFLAG.  */
 
 static void
-break_command_1 (char *arg, int flag, int from_tty)
+break_command_1 (const char *arg, int flag, int from_tty)
 {
   int tempflag = flag & BP_TEMPFLAG;
   enum bptype type_wanted = (flag & BP_HARDWAREFLAG
@@ -9867,8 +9865,9 @@ stopat_command (char *arg, int from_tty)
    line.  */
 
 static void
-dprintf_command (char *arg, int from_tty)
+dprintf_command (char *arg_in, int from_tty)
 {
+  const char *arg = arg_in;
   event_location_up location = string_to_event_location (&arg, current_language);
 
   /* If non-NULL, ARG should have been advanced past the location;
@@ -10082,9 +10081,11 @@ find_breakpoint_range_end (struct symtab_and_line sal)
 /* Implement the "break-range" CLI command.  */
 
 static void
-break_range_command (char *arg, int from_tty)
+break_range_command (char *arg_in, int from_tty)
 {
-  char *arg_start, *addr_string_start;
+  const char *arg = arg_in;
+  const char *arg_start;
+  char *addr_string_start;
   struct linespec_result canonical_start, canonical_end;
   int bp_count, can_use_bp, length;
   CORE_ADDR end;
@@ -11189,7 +11190,7 @@ can_use_hardware_watchpoint (struct value *v)
 }
 
 void
-watch_command_wrapper (char *arg, int from_tty, int internal)
+watch_command_wrapper (const char *arg, int from_tty, int internal)
 {
   watch_command_1 (arg, hw_write, from_tty, 0, internal);
 }
@@ -11220,7 +11221,7 @@ watch_command (char *arg, int from_tty)
 }
 
 void
-rwatch_command_wrapper (char *arg, int from_tty, int internal)
+rwatch_command_wrapper (const char *arg, int from_tty, int internal)
 {
   watch_command_1 (arg, hw_read, from_tty, 0, internal);
 }
@@ -11232,7 +11233,7 @@ rwatch_command (char *arg, int from_tty)
 }
 
 void
-awatch_command_wrapper (char *arg, int from_tty, int internal)
+awatch_command_wrapper (const char *arg, int from_tty, int internal)
 {
   watch_command_1 (arg, hw_access, from_tty, 0, internal);
 }
@@ -11353,7 +11354,7 @@ until_break_fsm_async_reply_reason (struct thread_fsm *self)
 }
 
 void
-until_break_command (char *arg, int from_tty, int anywhere)
+until_break_command (const char *arg, int from_tty, int anywhere)
 {
   struct frame_info *frame;
   struct gdbarch *frame_gdbarch;
@@ -11577,7 +11578,7 @@ void
 init_ada_exception_breakpoint (struct breakpoint *b,
                               struct gdbarch *gdbarch,
                               struct symtab_and_line sal,
-                              char *addr_string,
+                              const char *addr_string,
                               const struct breakpoint_ops *ops,
                               int tempflag,
                               int enabled,
@@ -13337,16 +13338,13 @@ strace_marker_create_sals_from_location (const struct event_location *location,
 {
   struct linespec_sals lsal;
   const char *arg_start, *arg;
-  char *str;
-  struct cleanup *cleanup;
 
   arg = arg_start = get_linespec_location (location);
   lsal.sals = decode_static_tracepoint_spec (&arg);
 
-  str = savestring (arg_start, arg - arg_start);
-  cleanup = make_cleanup (xfree, str);
-  canonical->location = new_linespec_location (&str);
-  do_cleanups (cleanup);
+  std::string str (arg_start, arg - arg_start);
+  const char *ptr = str.c_str ();
+  canonical->location = new_linespec_location (&ptr);
 
   lsal.canonical
     = xstrdup (event_location_to_string (canonical->location.get ()));
@@ -14786,8 +14784,9 @@ set_tracepoint_count (int num)
 }
 
 static void
-trace_command (char *arg, int from_tty)
+trace_command (char *arg_in, int from_tty)
 {
+  const char *arg = arg_in;
   struct breakpoint_ops *ops;
 
   event_location_up location = string_to_event_location (&arg,
@@ -14812,8 +14811,9 @@ trace_command (char *arg, int from_tty)
 }
 
 static void
-ftrace_command (char *arg, int from_tty)
+ftrace_command (char *arg_in, int from_tty)
 {
+  const char *arg = arg_in;
   event_location_up location = string_to_event_location (&arg,
                                                         current_language);
   create_breakpoint (get_current_arch (),
@@ -14832,8 +14832,9 @@ ftrace_command (char *arg, int from_tty)
 /* strace command implementation.  Creates a static tracepoint.  */
 
 static void
-strace_command (char *arg, int from_tty)
+strace_command (char *arg_in, int from_tty)
 {
+  const char *arg = arg_in;
   struct breakpoint_ops *ops;
   event_location_up location;
   struct cleanup *back_to;
@@ -14891,7 +14892,8 @@ read_uploaded_action (void)
 struct tracepoint *
 create_tracepoint_from_upload (struct uploaded_tp *utp)
 {
-  char *addr_str, small_buf[100];
+  const char *addr_str;
+  char small_buf[100];
   struct tracepoint *tp;
 
   if (utp->at_string)
index 6afe4cc5b381e3a7fbc17707cba437844bc4583f..154ff3aaff928ae8ee781401f0e726b5ef74de66 100644 (file)
@@ -1206,7 +1206,7 @@ extern int breakpoint_address_match (struct address_space *aspace1,
                                     struct address_space *aspace2,
                                     CORE_ADDR addr2);
 
-extern void until_break_command (char *, int, int);
+extern void until_break_command (const char *, int, int);
 
 /* Initialize a struct bp_location.  */
 
@@ -1255,9 +1255,9 @@ extern void break_command (char *, int);
 extern void hbreak_command_wrapper (char *, int);
 extern void thbreak_command_wrapper (char *, int);
 extern void rbreak_command_wrapper (char *, int);
-extern void watch_command_wrapper (char *, int, int);
-extern void awatch_command_wrapper (char *, int, int);
-extern void rwatch_command_wrapper (char *, int, int);
+extern void watch_command_wrapper (const char *, int, int);
+extern void awatch_command_wrapper (const char *, int, int);
+extern void rwatch_command_wrapper (const char *, int, int);
 extern void tbreak_command (char *, int);
 
 extern struct breakpoint_ops base_breakpoint_ops;
@@ -1288,7 +1288,7 @@ extern void
   init_ada_exception_breakpoint (struct breakpoint *b,
                                 struct gdbarch *gdbarch,
                                 struct symtab_and_line sal,
-                                char *addr_string,
+                                const char *addr_string,
                                 const struct breakpoint_ops *ops,
                                 int tempflag,
                                 int enabled,
index c522df9d41285cad2ae165b40f54199dbedb194d..c00994140f804fff97ae3fa8e1ec180ed9305d4d 100644 (file)
@@ -814,7 +814,7 @@ edit_command (char *arg, int from_tty)
     }
   else
     {
-      char *arg1;
+      const char *arg1;
 
       /* Now should only be one argument -- decode it in SAL.  */
       arg1 = arg;
@@ -892,7 +892,7 @@ static void
 list_command (char *arg, int from_tty)
 {
   struct symbol *sym;
-  char *arg1;
+  const char *arg1;
   int no_end = 1;
   int dummy_end = 0;
   int dummy_beg = 0;
index 91656848a0914d276d152805938027117223d24b..b6b68109f3059b42af3597986623a7bda58bb53b 100644 (file)
@@ -412,7 +412,7 @@ gdbscm_register_breakpoint_x (SCM self)
   breakpoint_smob *bp_smob
     = bpscm_get_breakpoint_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   struct gdb_exception except = exception_none;
-  char *location, *copy;
+  const char *location, *copy;
 
   /* We only support registering breakpoints created with make-breakpoint.  */
   if (!bp_smob->is_scheme_bkpt)
index 6e472e242972018521e275e1a95edb47fe141236..19db83ed62e07c2a959d6ba275d0eb1789eb8633 100644 (file)
@@ -2793,7 +2793,7 @@ linespec_parser_delete (void *arg)
 /* See description in linespec.h.  */
 
 void
-linespec_lex_to_end (char **stringp)
+linespec_lex_to_end (const char **stringp)
 {
   linespec_parser parser;
   struct cleanup *cleanup;
@@ -3338,7 +3338,7 @@ decode_line_1 (const struct event_location *location, int flags,
 /* See linespec.h.  */
 
 std::vector<symtab_and_line>
-decode_line_with_current_source (char *string, int flags)
+decode_line_with_current_source (const char *string, int flags)
 {
   if (string == 0)
     error (_("Empty line specification."));
@@ -3361,7 +3361,7 @@ decode_line_with_current_source (char *string, int flags)
 /* See linespec.h.  */
 
 std::vector<symtab_and_line>
-decode_line_with_last_displayed (char *string, int flags)
+decode_line_with_last_displayed (const char *string, int flags)
 {
   if (string == 0)
     error (_("Empty line specification."));
@@ -3472,19 +3472,21 @@ decode_objc (struct linespec_state *self, linespec_p ls, const char *arg)
 
       if (self->canonical)
        {
-         char *str;
+         std::string holder;
+         const char *str;
 
          self->canonical->pre_expanded = 1;
 
          if (ls->explicit_loc.source_filename)
            {
-             str = xstrprintf ("%s:%s",
-                               ls->explicit_loc.source_filename, saved_arg);
+             holder = string_printf ("%s:%s",
+                                     ls->explicit_loc.source_filename,
+                                     saved_arg);
+             str = holder.c_str ();
            }
          else
-           str = xstrdup (saved_arg);
+           str = saved_arg;
 
-         make_cleanup (xfree, str);
          self->canonical->location = new_linespec_location (&str);
        }
     }
index 6c9b0b3ee8c12ab029c015336b01c64031c987c9..b955728ff359995c509684e36796adb35c64ac7a 100644 (file)
@@ -136,12 +136,14 @@ extern void decode_line_full (const struct event_location *location, int flags,
    source symtab and line as defaults.
    This is for commands like "list" and "breakpoint".  */
 
-extern std::vector<symtab_and_line> decode_line_with_current_source (char *, int);
+extern std::vector<symtab_and_line> decode_line_with_current_source
+    (const char *, int);
 
 /* Given a string, return the line specified by it, using the last displayed
    codepoint's values as defaults, or nothing if they aren't valid.  */
 
-extern std::vector<symtab_and_line> decode_line_with_last_displayed (char *, int);
+extern std::vector<symtab_and_line> decode_line_with_last_displayed
+    (const char *, int);
 
 /* Does P represent one of the keywords?  If so, return
    the keyword.  If not, return NULL.  */
@@ -171,7 +173,7 @@ extern const char *find_toplevel_char (const char *s, char c);
 /* Find the end of the (first) linespec pointed to by *STRINGP.
    STRINGP will be advanced to this point.  */
 
-extern void linespec_lex_to_end (char **stringp);
+extern void linespec_lex_to_end (const char **stringp);
 
 extern const char * const linespec_keywords[];
 
index cda26e877b29ddcb115ea0dc6a615bea480e6e53..c78778edc1bff6497e081c38554e378bfcf9289f 100644 (file)
@@ -83,7 +83,7 @@ initialize_explicit_location (struct explicit_location *explicit_loc)
 /* See description in location.h.  */
 
 event_location_up
-new_linespec_location (char **linespec)
+new_linespec_location (const char **linespec)
 {
   struct event_location *location;
 
@@ -91,8 +91,8 @@ new_linespec_location (char **linespec)
   EL_TYPE (location) = LINESPEC_LOCATION;
   if (*linespec != NULL)
     {
-      char *p;
-      char *orig = *linespec;
+      const char *p;
+      const char *orig = *linespec;
 
       linespec_lex_to_end (linespec);
       p = remove_trailing_whitespace (orig, *linespec);
@@ -836,7 +836,7 @@ string_to_explicit_location (const char **argp,
 /* See description in location.h.  */
 
 event_location_up
-string_to_event_location_basic (char **stringp,
+string_to_event_location_basic (const char **stringp,
                                const struct language_defn *language)
 {
   event_location_up location;
@@ -875,7 +875,7 @@ string_to_event_location_basic (char **stringp,
 /* See description in location.h.  */
 
 event_location_up
-string_to_event_location (char **stringp,
+string_to_event_location (const char **stringp,
                          const struct language_defn *language)
 {
   const char *arg, *orig;
index 58536e0144b0571ae50bb5c3b5c9e8b26c278599..d954eac7207f6d933ce3ea59c51bf117fb414b7d 100644 (file)
@@ -127,7 +127,7 @@ typedef std::unique_ptr<event_location, event_location_deleter>
 
 /* Create a new linespec location.  */
 
-extern event_location_up new_linespec_location (char **linespec);
+extern event_location_up new_linespec_location (const char **linespec);
 
 /* Return the linespec location (a string) of the given event_location
    (which must be of type LINESPEC_LOCATION).  */
@@ -208,14 +208,14 @@ extern event_location_up
    legacy specifications of probe, address, and linespec locations.  */
 
 extern event_location_up
-  string_to_event_location (char **argp,
+  string_to_event_location (const char **argp,
                            const struct language_defn *langauge);
 
 /* Like string_to_event_location, but does not attempt to parse explicit
    locations.  */
 
 extern event_location_up
-  string_to_event_location_basic (char **argp,
+  string_to_event_location_basic (const char **argp,
                                  const struct language_defn *language);
 
 /* Structure filled in by string_to_explicit_location to aid the
index bae87116967192b51615d3afc2032117d84f43c0..188e4e2d656cbf047fe138c831d894b3b7f47cec 100644 (file)
@@ -165,7 +165,7 @@ mi_argv_to_format (char **argv, int argc)
 static void
 mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
 {
-  char *address = NULL;
+  const char *address = NULL;
   int hardware = 0;
   int temp_p = 0;
   int thread = -1;
index d57c2fa05e5145e46c61d6015ebfbdd2c617b1ac..86719d1b6eb90a971e7d78e2d0a02ade4b54fca2 100644 (file)
@@ -674,7 +674,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
     {
       gdb::unique_xmalloc_ptr<char>
        copy_holder (xstrdup (skip_spaces (spec)));
-      char *copy = copy_holder.get ();
+      const char *copy = copy_holder.get ();
 
       switch (type)
        {
index ff757fdc421e56f85bd66b5a887409b59441cc8b..b04057ec4a45da116d10397abf04b81af2411f3b 100644 (file)
@@ -647,7 +647,7 @@ gdbpy_solib_name (PyObject *self, PyObject *args)
 static PyObject *
 gdbpy_decode_line (PyObject *self, PyObject *args)
 {
-  char *arg = NULL;
+  const char *arg = NULL;
   gdbpy_ref<> result;
   gdbpy_ref<> unparsed;
   event_location_up location;
index 12cc2fb235e0fce83643de2e42ab794b40e4cf98..52a449a3dd0d5807f3771ae7195a2053be19f5b2 100644 (file)
@@ -2550,17 +2550,18 @@ tfind_outside_command (char *args, int from_tty)
 
 /* info scope command: list the locals for a scope.  */
 static void
-info_scope_command (char *args, int from_tty)
+info_scope_command (char *args_in, int from_tty)
 {
   struct symbol *sym;
   struct bound_minimal_symbol msym;
   const struct block *block;
   const char *symname;
-  char *save_args = args;
+  const char *save_args = args_in;
   struct block_iterator iter;
   int j, count = 0;
   struct gdbarch *gdbarch;
   int regno;
+  const char *args = args_in;
 
   if (args == 0 || *args == 0)
     error (_("requires an argument (function, "
This page took 0.045753 seconds and 4 git commands to generate.