From patchwork Thu Sep 21 05:09:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 23025 Received: (qmail 53553 invoked by alias); 21 Sep 2017 05:40:10 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 53445 invoked by uid 89); 21 Sep 2017 05:40:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=displayed X-HELO: gproxy4-pub.mail.unifiedlayer.com Received: from gproxy4-pub.mail.unifiedlayer.com (HELO gproxy4-pub.mail.unifiedlayer.com) (69.89.23.142) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Sep 2017 05:40:06 +0000 Received: from CMOut01 (unknown [10.0.90.82]) by gproxy4.mail.unifiedlayer.com (Postfix) with ESMTP id A199F176037 for ; Wed, 20 Sep 2017 23:40:04 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id C5g11w00y2f2jeq015g4Xx; Wed, 20 Sep 2017 23:40:04 -0600 X-Authority-Analysis: v=2.2 cv=K4VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=yyccwEFJOCa7S_tWjpUA:9 a=EjwBic4y0L8NwAdu:21 a=fTcXjHS1STQf1Fel:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:36574 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dutkw-00118R-Qj; Wed, 20 Sep 2017 23:10:34 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 38/67] Constify some linespec functions Date: Wed, 20 Sep 2017 23:09:54 -0600 Message-Id: <20170921051023.19023-39-tom@tromey.com> In-Reply-To: <20170921051023.19023-1-tom@tromey.com> References: <20170921051023.19023-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dutkw-00118R-Qj X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:36574 X-Source-Auth: tom+tromey.com X-Email-Count: 41 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes a few linespec functions to work on "const char *" and then fixes up all the callers. This allows further constification elsewhere. ChangeLog 2017-09-20 Tom Tromey * 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. --- gdb/ChangeLog | 32 ++++++++++++++++++++++++++++++++ gdb/ada-lang.c | 4 ++-- gdb/ax-gdb.c | 2 +- gdb/breakpoint.c | 44 +++++++++++++++++++++++--------------------- gdb/breakpoint.h | 10 +++++----- gdb/cli/cli-cmds.c | 4 ++-- gdb/guile/scm-breakpoint.c | 2 +- gdb/linespec.c | 18 ++++++++++-------- gdb/linespec.h | 8 +++++--- gdb/location.c | 10 +++++----- gdb/location.h | 6 +++--- gdb/mi/mi-cmd-break.c | 2 +- gdb/python/py-breakpoint.c | 2 +- gdb/python/python.c | 2 +- gdb/tracepoint.c | 5 +++-- 15 files changed, 95 insertions(+), 56 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 64f1a33..ea051c3 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -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); diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 227590b..c4bf2a6 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -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 diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 5549fe7..1073418 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -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) diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index 6afe4cc..154ff3a 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -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, diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index e6239ca..4cc9fa6 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -807,7 +807,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; @@ -885,7 +885,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; diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c index 9165684..b6b6810 100644 --- a/gdb/guile/scm-breakpoint.c +++ b/gdb/guile/scm-breakpoint.c @@ -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) diff --git a/gdb/linespec.c b/gdb/linespec.c index 6e472e2..19db83e 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -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 -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 -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); } } diff --git a/gdb/linespec.h b/gdb/linespec.h index 6c9b0b3..b955728 100644 --- a/gdb/linespec.h +++ b/gdb/linespec.h @@ -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 decode_line_with_current_source (char *, int); +extern std::vector 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 decode_line_with_last_displayed (char *, int); +extern std::vector 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[]; diff --git a/gdb/location.c b/gdb/location.c index cda26e8..c78778e 100644 --- a/gdb/location.c +++ b/gdb/location.c @@ -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; diff --git a/gdb/location.h b/gdb/location.h index 58536e0..d954eac 100644 --- a/gdb/location.h +++ b/gdb/location.h @@ -127,7 +127,7 @@ typedef std::unique_ptr /* 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 diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c index bae8711..188e4e2 100644 --- a/gdb/mi/mi-cmd-break.c +++ b/gdb/mi/mi-cmd-break.c @@ -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; diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index d57c2fa..86719d1 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -674,7 +674,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) { gdb::unique_xmalloc_ptr copy_holder (xstrdup (skip_spaces (spec))); - char *copy = copy_holder.get (); + const char *copy = copy_holder.get (); switch (type) { diff --git a/gdb/python/python.c b/gdb/python/python.c index ff757fd..b04057e 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -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; diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 12cc2fb..52a449a 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -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, "