This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v3 3/9] Explicit locations: use new location API
- From: Doug Evans <xdje42 at gmail dot com>
- To: Keith Seitz <keiths at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Sun, 01 Mar 2015 12:53:18 -0800
- Subject: Re: [PATCH v3 3/9] Explicit locations: use new location API
- Authentication-results: sourceware.org; auth=none
- References: <20150217220619 dot 1312 dot 39861 dot stgit at valrhona dot uglyboxes dot com> <20150217220643 dot 1312 dot 93245 dot stgit at valrhona dot uglyboxes dot com>
Keith Seitz <keiths@redhat.com> writes:
> This patch converts the code base to use the new struct event_location
> API being introduced. This patch preserves the current functionality and
> adds no new features.
>
> The "big picture" API usage introduced by this patch may be illustrated
> with a simple exmaple. Where previously developers would write:
>
> void
> my_command (char *arg, int from_tty)
> {
> create_breakpoint (..., arg, ...);
> ...
> }
>
> one now uses:
>
> void
> my_command (char *arg, int from_tty)
> {
> struct event_locaiton *location;
> struct cleanup *back_to;
>
> location = string_to_event_locaiton (&arg, ...);
> back_to = make_cleanup_delete_event_location (location);
> create_breakpoint (..., location, ...);
> do_cleanups (back_to);
> }
>
> Linespec-decoding functions (now called location-decoding) such as
> decode_line_full no longer skip argument pointers over processed input.
> That functionality has been moved into string_to_event_location as
> demonstrated above.
>
> gdb/ChangeLog
>
> * ax-gdb.c: Include location.h.
> (agent_command_1) Use linespec location instead of address
> string.
> * break-catch-throw.c: Include location.h.
> (re_set_exception_catchpoint): Use linespec locations instead
> of address strings.
> * breakpoint.c: Include location.h.
> (create_overlay_event_breakpoint): Use linespec location
> instead of address string.
> (create_longjmp_master_breakpoint): Likewise.
> (create_std_terminate_master_breakpoint): Likewise.
> (create_exception_master_breakpoint): Likewise.
> (update_breakpoints_after_exec): Likewise.
> (print_breakpoint_location): Use locations and
> event_location_to_string.
> (print_one_breakpoint_location): Likewise.
> (init_raw_breakpoint_without_location): Initialize
> b->location.
> (create_thread_event_breakpoint): Use linespec location instead of
> address string.
> (init_breakpoint_sal): Likewise.
> Only save extra_string if it is non-NULL and not the empty string.
> Use event_location_to_string instead of `addr_string'.
> Constify `p' and `endp'.
> Use skip_spaces_const/skip_space_const instead of non-const versions.
> Copy the location into the breakpoint.
> If LOCATION is NULL, save the breakpoint address as a linespec location
> instead of an address string.
> (create_breakpoint_sal): Change `addr_string' parameter to a struct
> event_location. All uses updated.
> (create_breakpoints_sal): Likewise for local variable `addr_string'.
> (parse_breakpoint_sals): Use locations instead of address strings.
> Remove check for empty linespec with conditional.
> Refactor.
> (decode_static_tracepoint_spec): Make argument const and update
> function.
> (create_breakpoint): Change `arg' to a struct event_location and
> rename.
> Remove `copy_arg' and `addr_start'.
> If EXTRA_STRING is empty, set it to NULL.
> Don't populate `canonical' for pending breakpoints.
> Pass `extra_string' to find_condition_and_thread.
> Clear `extra_string' if `rest' was NULL.
> Do not error with "garbage after location" if setting a dprintf
> breakpoint.
> Copy the location into the breakpoint instead of an address string.
> For pending breakpoints, append `extra_string' to the location's
> string representation and make a private copy of `extra_string' for
> the breakpoint.
> (break_command_1): Use string_to_event_location and pass this to
> create_breakpoint instead of an address string.
> Check against `arg_cp' for a probe linespec.
> (dprintf_command): Use string_to_event_location and pass this to
> create_breakpoint instead of an address string.
> (print_recreate_ranged_breakpoint): Use event_location_to_string
> instead of address strings.
> (break_range_command): Use locations instead of address strings.
> (until_break_command): Likewise.
> (init_ada_exception_breakpoint): Likewise.
> (say_where): Likewise.
> (base_breakpoint_dtor): Delete `location' and `location_range_end' of
> the breakpoint.
> (base_breakpoint_create_sals_from_location): Use struct event_location
> instead of address string.
> Remove `addr_start' and `copy_arg' parameters.
> (base_breakpoint_decode_location): Use struct event_location instead of
> address string.
> (bkpt_re_set): Use locations instead of address strings.
> Use event_location_empty_p to check for unset location.
> (bkpt_print_recreate): Use event_location_to_string instead of
> an address string.
> (bkpt_create_sals_from_location): Use struct event_location instead of
> address string.
> (bkpt_decode_location): Likewise.
> (bkpt_probe_create_sals_from_location): Likewise.
> (bkpt_probe_decode_location): Use struct event_location instead of
> address string.
> (tracepoint_print_recreate): Use event_location_to_string to
> recreate the tracepoint.
> (tracepoint_create_sals_from_location): Use struct event_location
> instead of address string.
> (tracepoint_decode_location): Likewise.
> (tracepoint_probe_create_sals_from_location): Likewise.
> (tracepoint_probe_decode_location): Likewise.
> (dprintf_print_recreate): Use event_location_to_string to recreate
> the dprintf.
> (strace_marker_create_sals_from_location): Use struct event_location
> instead of address string.
> (strace_marker_create_breakpoints_sal): Likewise.
> (strace_marker_decode_location): Likewise.
> (update_static_tracepoint): Likewise.
> (location_to_sals): Likewise.
> Pass `extra_string' to find_condition_and_thread.
> For newly resolved pending breakpoint locations, clear the location's
> string representation.
> (breakpoint_re_set_default): Use locations instead of address
> strings.
> (create_sals_from_location_default): Likewise.
> (decode_location_default): Use locations instead of address strings.
> (trace_command): Use locations instead of address strings.
> (ftrace_command): Likewise.
> (strace_command): Likewise.
> (create_tracepoint_from_upload): Likewise.
> * breakpoint.h (struct breakpoint_ops) <create_sals_from_location>:
> Use struct event_location instead of address string.
> Update all uses.
> <decode_location>: Likewise.
> (struct breakpoint) <addr_string>: Change to struct event_location
> and rename `location'.
> <addr_string_range_end>: Change to struct event_location and rename
> `location_range_end'.
> (create_breakpoint): Use struct event_location instead of address
> string.
> * cli/cli-cmds.c: Include location.h.
> (edit_command): Use locations instead of address strings.
> (list_command): Likewise.
> * elfread.c: Include location.h.
> (elf_gnu_ifunc_resolver_return_stop): Use event_location_to_string.
> * linespec.c: Include location.h.
> (struct ls_parser) <stream>: Change to const char *.
> (PARSER_STREAM): Update.
> (lionespec_lexer_lex_keyword): According to find_condition_and_thread,
> keywords must be followed by whitespace.
> (canonicalize_linespec): Save a linespec location into `canonical'.
> Save a canonical linespec into `canonical'.
> (parse_linespec): Change `argptr' to const char * and rename `arg'.
> All uses updated.
> Update function description.
> (linespec_parser_new): Initialize `parser'.
> Update initialization of parsing stream.
> (event_location_to_sals): New function.
> (decode_line_full): Change `argptr' to a struct event_location and
> rename it `location'.
> Use locations instead of address strings.
> Call event_location_to_sals instead of parse_linespec.
> (decode_line_1): Likewise.
> (decode_line_with_current_source): Use locations instead of
> address strings.
> (decode_line_with_last_displayed): Likewise.
> (decode_objc): Likewise.
> Change `argptr' to const char * and rename `arg'.
> (destroy_linespec_result): Delete the linespec result's location
> instead of freeing the address string.
> * linespec.h (struct linespec_result) <addr_string>: Change to
> struct event_location and rename to ...
> <location>: ... this.
> (decode_line_1): Change `argptr' to struct event_location.
> All callers updated.
> (decode_line_full): Likewise.
> * mi/mi-cmd-break.c: Include language.h, location.h, and linespec.h.
> (mi_cmd_break_insert_1): Use locations instead of address strings.
> Throw an error if there was "garbage" at the end of the specified
> linespec.
> * probe.c: Include location.h.
> (parse_probes): Change `argptr' to struct event_location.
> Use event locations instead of address strings.
> * probe.h (parse_probes): Change `argptr' to struct event_location.
> * python/py-breakpoint.c: Include location.h.
> (bppy_get_location): Constify local variable `str'.
> Use event_location_to_string.
> (bppy_init): Use locations instead of address strings.
> * python/py-finishbreakpoint.c: Include location.h.
> (bpfinishpy_init): Remove local variable `addr_str'.
> Use locations instead of address strings.
> * python/python.c: Include location.h.
> (gdbpy_decode_line): Use locations instead of address strings.
> * remote.c: Include location.h.
> (remote_download_tracepoint): Use locations instead of address
> strings.
> * spu-tdep.c: Include location.h.
> (spu_catch_start): Remove local variable `buf'.
> Use locations instead of address strings.
> * tracepoint.c: Include location.h.
> (scope_info): Use locations instead of address strings.
> (encode_source_string): Constify parameter `src'.
> * tracepoint.h (encode_source_string): Likewise.
Hi.
A few comments inline.
grep for ^====
> diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
> index 7a9d1e7..2fd5a1a 100644
> --- a/gdb/ax-gdb.c
> +++ b/gdb/ax-gdb.c
> @@ -40,6 +40,7 @@
> #include "arch-utils.h"
> #include "cli/cli-utils.h"
> #include "linespec.h"
> +#include "location.h"
> #include "objfiles.h"
>
> #include "valprint.h"
> @@ -2642,13 +2643,16 @@ agent_command_1 (char *exp, int eval)
> int ix;
> struct linespec_sals *iter;
> struct cleanup *old_chain;
> + struct event_location *location;
>
> exp = skip_spaces (exp);
> init_linespec_result (&canonical);
> - decode_line_full (&exp, DECODE_LINE_FUNFIRSTLINE,
> + location = new_linespec_location (&exp);
> + old_chain = make_cleanup_delete_event_location (location);
> + decode_line_full (location, DECODE_LINE_FUNFIRSTLINE,
> (struct symtab *) NULL, 0, &canonical,
> NULL, NULL);
> - old_chain = make_cleanup_destroy_linespec_result (&canonical);
> + make_cleanup_destroy_linespec_result (&canonical);
> exp = skip_spaces (exp);
> if (exp[0] == ',')
> {
> diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
> index 954e98b..551f722 100644
> --- a/gdb/break-catch-throw.c
> +++ b/gdb/break-catch-throw.c
> @@ -35,6 +35,7 @@
> #include "cp-abi.h"
> #include "gdb_regex.h"
> #include "cp-support.h"
> +#include "location.h"
>
> /* Enums for exception-handling support. */
> enum exception_event_kind
> @@ -206,27 +207,33 @@ re_set_exception_catchpoint (struct breakpoint *self)
> volatile struct gdb_exception e;
> struct cleanup *cleanup;
> enum exception_event_kind kind = classify_exception_breakpoint (self);
> + struct event_location *location;
> + char *p;
>
> /* We first try to use the probe interface. */
> + p = ASTRDUP (exception_functions[kind].probe);
> + location = new_linespec_location (&p);
> + cleanup = make_cleanup_delete_event_location (location);
> TRY_CATCH (e, RETURN_MASK_ERROR)
> {
> - char *spec = ASTRDUP (exception_functions[kind].probe);
> -
> - sals = parse_probes (&spec, NULL);
> + sals = parse_probes (location, NULL);
> }
> + do_cleanups (cleanup);
>
> if (e.reason < 0)
> {
> volatile struct gdb_exception ex;
> + char *func = ASTRDUP (exception_functions[kind].function);
>
> /* Using the probe interface failed. Let's fallback to the normal
> catchpoint mode. */
> + location = new_linespec_location (&func);
> + cleanup = make_cleanup_delete_event_location (location);
> TRY_CATCH (ex, RETURN_MASK_ERROR)
> {
> - char *spec = ASTRDUP (exception_functions[kind].function);
> -
> - self->ops->decode_location (self, &spec, &sals);
> + self->ops->decode_location (self, location, &sals);
> }
> + do_cleanups (cleanup);
>
> /* NOT_FOUND_ERROR just means the breakpoint will be pending, so
> let it through. */
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index c7d6c98..5c3be10 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -68,6 +68,7 @@
> #include "dummy-frame.h"
> #include "interps.h"
> #include "format.h"
> +#include "location.h"
>
> /* readline include files */
> #include "readline/readline.h"
> @@ -109,10 +110,10 @@ static int breakpoint_re_set_one (void *);
>
> static void breakpoint_re_set_default (struct breakpoint *);
>
> -static void create_sals_from_location_default (char **,
> - struct linespec_result *,
> - enum bptype, char *,
> - char **);
> +static void
> + create_sals_from_location_default (const struct event_location *location,
> + struct linespec_result *canonical,
> + enum bptype type_wanted);
>
> static void create_breakpoints_sal_default (struct gdbarch *,
> struct linespec_result *,
> @@ -122,8 +123,9 @@ static void create_breakpoints_sal_default (struct gdbarch *,
> const struct breakpoint_ops *,
> int, int, int, unsigned);
>
> -static void decode_location_default (struct breakpoint *, char **,
> - struct symtabs_and_lines *);
> +static void decode_location_default (struct breakpoint *b,
> + const struct event_location *location,
> + struct symtabs_and_lines *sals);
>
> static void clear_command (char *, int);
>
> @@ -3401,6 +3403,7 @@ create_overlay_event_breakpoint (void)
> struct breakpoint *b;
> struct breakpoint_objfile_data *bp_objfile_data;
> CORE_ADDR addr;
> + char *p;
>
> bp_objfile_data = get_breakpoint_objfile_data (objfile);
>
> @@ -3425,7 +3428,8 @@ create_overlay_event_breakpoint (void)
> b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
> bp_overlay_event,
> &internal_breakpoint_ops);
> - b->addr_string = xstrdup (func_name);
> + p = ASTRDUP (func_name);
> + b->location = new_linespec_location (&p);
>
> if (overlay_debugging == ovly_auto)
> {
> @@ -3492,6 +3496,7 @@ create_longjmp_master_breakpoint (void)
> int i;
> struct probe *probe;
> struct gdbarch *gdbarch = get_objfile_arch (objfile);
> + char *p;
>
> for (i = 0;
> VEC_iterate (probe_p,
> @@ -3506,7 +3511,8 @@ create_longjmp_master_breakpoint (void)
> objfile),
> bp_longjmp_master,
> &internal_breakpoint_ops);
> - b->addr_string = xstrdup ("-probe-stap libc:longjmp");
> + p = ASTRDUP ("-probe-stap libc:longjmp");
> + b->location = new_linespec_location (&p);
> b->enable_state = bp_disabled;
> }
>
> @@ -3521,6 +3527,7 @@ create_longjmp_master_breakpoint (void)
> struct breakpoint *b;
> const char *func_name;
> CORE_ADDR addr;
> + char *p;
>
> if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
> continue;
> @@ -3543,7 +3550,8 @@ create_longjmp_master_breakpoint (void)
> addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
> b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
> &internal_breakpoint_ops);
> - b->addr_string = xstrdup (func_name);
> + p = ASTRDUP (func_name);
> + b->location = new_linespec_location (&p);
> b->enable_state = bp_disabled;
> }
> }
> @@ -3574,6 +3582,7 @@ create_std_terminate_master_breakpoint (void)
> {
> struct breakpoint *b;
> struct breakpoint_objfile_data *bp_objfile_data;
> + char *p;
>
> bp_objfile_data = get_breakpoint_objfile_data (objfile);
>
> @@ -3599,7 +3608,8 @@ create_std_terminate_master_breakpoint (void)
> b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
> bp_std_terminate_master,
> &internal_breakpoint_ops);
> - b->addr_string = xstrdup (func_name);
> + p = ASTRDUP (func_name);
> + b->location = new_linespec_location (&p);
> b->enable_state = bp_disabled;
> }
> }
> @@ -3623,6 +3633,7 @@ create_exception_master_breakpoint (void)
> struct gdbarch *gdbarch;
> struct breakpoint_objfile_data *bp_objfile_data;
> CORE_ADDR addr;
> + char *p;
>
> bp_objfile_data = get_breakpoint_objfile_data (objfile);
>
> @@ -3663,13 +3674,15 @@ create_exception_master_breakpoint (void)
> ++i)
> {
> struct breakpoint *b;
> + char *p;
>
> b = create_internal_breakpoint (gdbarch,
> get_probe_address (probe,
> objfile),
> bp_exception_master,
> &internal_breakpoint_ops);
> - b->addr_string = xstrdup ("-probe-stap libgcc:unwind");
> + p = ASTRDUP ("-probe-stap libgcc:unwind");
> + b->location = new_linespec_location (&p);
> b->enable_state = bp_disabled;
> }
>
> @@ -3702,7 +3715,8 @@ create_exception_master_breakpoint (void)
> ¤t_target);
> b = create_internal_breakpoint (gdbarch, addr, bp_exception_master,
> &internal_breakpoint_ops);
> - b->addr_string = xstrdup (func_name);
> + p = ASTRDUP (func_name);
> + b->location = new_linespec_location (&p);
> b->enable_state = bp_disabled;
> }
>
> @@ -3823,7 +3837,7 @@ update_breakpoints_after_exec (void)
> /* Without a symbolic address, we have little hope of the
> pre-exec() address meaning the same thing in the post-exec()
> a.out. */
> - if (b->addr_string == NULL)
> + if (event_location_empty_p (b->location))
> {
> delete_breakpoint (b);
> continue;
> @@ -5994,7 +6008,8 @@ print_breakpoint_location (struct breakpoint *b,
> set_current_program_space (loc->pspace);
>
> if (b->display_canonical)
> - ui_out_field_string (uiout, "what", b->addr_string);
> + ui_out_field_string (uiout, "what",
> + event_location_to_string (b->location));
> else if (loc && loc->symtab)
> {
> struct symbol *sym
> @@ -6030,7 +6045,8 @@ print_breakpoint_location (struct breakpoint *b,
> do_cleanups (stb_chain);
> }
> else
> - ui_out_field_string (uiout, "pending", b->addr_string);
> + ui_out_field_string (uiout, "pending",
> + event_location_to_string (b->location));
>
> if (loc && is_breakpoint (b)
> && breakpoint_condition_evaluation_mode () == condition_evaluation_target
> @@ -6499,8 +6515,10 @@ print_one_breakpoint_location (struct breakpoint *b,
>
> ui_out_field_string (uiout, "original-location", w->exp_string);
> }
> - else if (b->addr_string)
> - ui_out_field_string (uiout, "original-location", b->addr_string);
> + else if (b->location != NULL
> + && event_location_to_string (b->location) != NULL)
> + ui_out_field_string (uiout, "original-location",
> + event_location_to_string (b->location));
> }
> }
>
> @@ -7270,6 +7288,7 @@ init_raw_breakpoint_without_location (struct breakpoint *b,
> b->condition_not_parsed = 0;
> b->py_bp_object = NULL;
> b->related_breakpoint = b;
> + b->location = NULL;
> }
>
> /* Helper to set_raw_breakpoint below. Creates a breakpoint
> @@ -7610,15 +7629,19 @@ delete_std_terminate_breakpoint (void)
> struct breakpoint *
> create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
> {
> + char *tmp;
> struct breakpoint *b;
> + struct cleanup *cleanup;
>
> b = create_internal_breakpoint (gdbarch, address, bp_thread_event,
> &internal_breakpoint_ops);
>
> b->enable_state = bp_enabled;
> - /* addr_string has to be used or breakpoint_re_set will delete me. */
> - b->addr_string
> - = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
> + /* location has to be used or breakpoint_re_set will delete me. */
> + tmp = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
> + cleanup = make_cleanup (xfree, tmp);
> + b->location = new_linespec_location (&tmp);
> + do_cleanups (cleanup);
>
> update_global_location_list_nothrow (UGLL_MAY_INSERT);
>
> @@ -9450,13 +9473,14 @@ update_dprintf_commands (char *args, int from_tty,
> }
> }
>
> -/* Create a breakpoint with SAL as location. Use ADDR_STRING
> - as textual description of the location, and COND_STRING
> +/* Create a breakpoint with SAL as location. Use LOCATION
> + as a description of the location, and COND_STRING
> as condition expression. */
>
> static void
> init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
> - struct symtabs_and_lines sals, char *addr_string,
> + struct symtabs_and_lines sals,
> + struct event_location *location,
> char *filter, char *cond_string,
> char *extra_string,
> enum bptype type, enum bpdisp disposition,
> @@ -9505,7 +9529,10 @@ init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
> b->task = task;
>
> b->cond_string = cond_string;
> - b->extra_string = extra_string;
> + if (extra_string != NULL && *extra_string != '\0')
> + b->extra_string = extra_string;
> + else
> + b->extra_string = NULL;
> b->ignore_count = ignore_count;
> b->enable_state = enabled ? bp_enabled : bp_disabled;
> b->disposition = disposition;
> @@ -9522,13 +9549,13 @@ init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
> {
> /* We already know the marker exists, otherwise, we
> wouldn't see a sal for it. */
> - char *p = &addr_string[3];
> - char *endp;
> + const char *p = &event_location_to_string (b->location)[3];
> + const char *endp;
> char *marker_str;
>
> - p = skip_spaces (p);
> + p = skip_spaces_const (p);
>
> - endp = skip_to_space (p);
> + endp = skip_to_space_const (p);
>
> marker_str = savestring (p, endp - p);
> t->static_trace_marker_id = marker_str;
> @@ -9584,19 +9611,26 @@ init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
> }
>
> b->display_canonical = display_canonical;
> - if (addr_string)
> - b->addr_string = addr_string;
> + if (location != NULL)
> + b->location = location;
> else
> - /* addr_string has to be used or breakpoint_re_set will delete
> - me. */
> - b->addr_string
> - = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address));
> + {
> + char *tmp;
> + struct cleanup *cleanup;
> +
> + tmp = xstrprintf ("*%s",
> + paddress (b->loc->gdbarch, b->loc->address));
> + cleanup = make_cleanup (xfree, tmp);
> + b->location = new_linespec_location (&tmp);
> + do_cleanups (cleanup);
> + }
> b->filter = filter;
> }
>
> static void
> create_breakpoint_sal (struct gdbarch *gdbarch,
> - struct symtabs_and_lines sals, char *addr_string,
> + struct symtabs_and_lines sals,
> + struct event_location *location,
> char *filter, char *cond_string,
> char *extra_string,
> enum bptype type, enum bpdisp disposition,
> @@ -9621,7 +9655,7 @@ create_breakpoint_sal (struct gdbarch *gdbarch,
> old_chain = make_cleanup (xfree, b);
>
> init_breakpoint_sal (b, gdbarch,
> - sals, addr_string,
> + sals, location,
> filter, cond_string, extra_string,
> type, disposition,
> thread, task, ignore_count,
> @@ -9665,17 +9699,17 @@ create_breakpoints_sal (struct gdbarch *gdbarch,
>
> for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i)
> {
> - /* Note that 'addr_string' can be NULL in the case of a plain
> + /* Note that 'location' can be NULL in the case of a plain
> 'break', without arguments. */
> - char *addr_string = (canonical->addr_string
> - ? xstrdup (canonical->addr_string)
> - : NULL);
> + struct event_location *location
> + = (canonical->location != NULL
> + ? copy_event_location (canonical->location) : NULL);
> char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL;
> - struct cleanup *inner = make_cleanup (xfree, addr_string);
> + struct cleanup *inner = make_cleanup_delete_event_location (location);
>
> make_cleanup (xfree, filter_string);
> create_breakpoint_sal (gdbarch, lsal->sals,
> - addr_string,
> + location,
> filter_string,
> cond_string, extra_string,
> type, disposition,
> @@ -9686,84 +9720,97 @@ create_breakpoints_sal (struct gdbarch *gdbarch,
> }
> }
>
> -/* Parse ADDRESS which is assumed to be a SAL specification possibly
> +/* Parse LOCATION which is assumed to be a SAL specification possibly
> followed by conditionals. On return, SALS contains an array of SAL
> - addresses found. ADDR_STRING contains a vector of (canonical)
> - address strings. ADDRESS points to the end of the SAL.
> + addresses found. LOCATION points to the end of the SAL (for
> + linespec locations).
>
> The array and the line spec strings are allocated on the heap, it is
> the caller's responsibility to free them. */
>
> static void
> -parse_breakpoint_sals (char **address,
> +parse_breakpoint_sals (const struct event_location *location,
> struct linespec_result *canonical)
> {
> - /* If no arg given, or if first arg is 'if ', use the default
> - breakpoint. */
> - if ((*address) == NULL
> - || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
> + struct symtab_and_line cursal;
> +
> + if (event_location_type (location) == LINESPEC_LOCATION)
> {
> - /* The last displayed codepoint, if it's valid, is our default breakpoint
> - address. */
> - if (last_displayed_sal_is_valid ())
> + const char *address = get_linespec_location (location);
> +
> + if (address == NULL)
> {
> - struct linespec_sals lsal;
> - struct symtab_and_line sal;
> - CORE_ADDR pc;
> -
> - init_sal (&sal); /* Initialize to zeroes. */
> - lsal.sals.sals = (struct symtab_and_line *)
> - xmalloc (sizeof (struct symtab_and_line));
> -
> - /* Set sal's pspace, pc, symtab, and line to the values
> - corresponding to the last call to print_frame_info.
> - Be sure to reinitialize LINE with NOTCURRENT == 0
> - as the breakpoint line number is inappropriate otherwise.
> - find_pc_line would adjust PC, re-set it back. */
> - get_last_displayed_sal (&sal);
> - pc = sal.pc;
> - sal = find_pc_line (pc, 0);
> -
> - /* "break" without arguments is equivalent to "break *PC"
> - where PC is the last displayed codepoint's address. So
> - make sure to set sal.explicit_pc to prevent GDB from
> - trying to expand the list of sals to include all other
> - instances with the same symtab and line. */
> - sal.pc = pc;
> - sal.explicit_pc = 1;
> -
> - lsal.sals.sals[0] = sal;
> - lsal.sals.nelts = 1;
> - lsal.canonical = NULL;
> -
> - VEC_safe_push (linespec_sals, canonical->sals, &lsal);
> + /* The last displayed codepoint, if it's valid, is our default
> + breakpoint address. */
> + if (last_displayed_sal_is_valid ())
> + {
> + struct linespec_sals lsal;
> + struct symtab_and_line sal;
> + CORE_ADDR pc;
> +
> + init_sal (&sal); /* Initialize to zeroes. */
> + lsal.sals.sals = (struct symtab_and_line *)
> + xmalloc (sizeof (struct symtab_and_line));
> +
> + /* Set sal's pspace, pc, symtab, and line to the values
> + corresponding to the last call to print_frame_info.
> + Be sure to reinitialize LINE with NOTCURRENT == 0
> + as the breakpoint line number is inappropriate otherwise.
> + find_pc_line would adjust PC, re-set it back. */
> + get_last_displayed_sal (&sal);
> + pc = sal.pc;
> + sal = find_pc_line (pc, 0);
> +
> + /* "break" without arguments is equivalent to "break *PC"
> + where PC is the last displayed codepoint's address. So
> + make sure to set sal.explicit_pc to prevent GDB from
> + trying to expand the list of sals to include all other
> + instances with the same symtab and line. */
> + sal.pc = pc;
> + sal.explicit_pc = 1;
> +
> + lsal.sals.sals[0] = sal;
> + lsal.sals.nelts = 1;
> + lsal.canonical = NULL;
> +
> + VEC_safe_push (linespec_sals, canonical->sals, &lsal);
> + return;
> + }
> + else
> + error (_("No default breakpoint address now."));
> }
> - else
> - error (_("No default breakpoint address now."));
> }
> - else
> +
> + /* Force almost all breakpoints to be in terms of the
> + current_source_symtab (which is decode_line_1's default).
> + This should produce the results we want almost all of the
> + time while leaving default_breakpoint_* alone.
> +
> + ObjC: However, don't match an Objective-C method name which
> + may have a '+' or '-' succeeded by a '['. */
> + cursal = get_current_source_symtab_and_line ();
> + if (last_displayed_sal_is_valid ())
> {
> - struct symtab_and_line cursal = get_current_source_symtab_and_line ();
> + const char *address = NULL;
>
> - /* Force almost all breakpoints to be in terms of the
> - current_source_symtab (which is decode_line_1's default).
> - This should produce the results we want almost all of the
> - time while leaving default_breakpoint_* alone.
> + if (event_location_type (location) == LINESPEC_LOCATION)
> + address = get_linespec_location (location);
>
> - ObjC: However, don't match an Objective-C method name which
> - may have a '+' or '-' succeeded by a '['. */
> - if (last_displayed_sal_is_valid ()
> - && (!cursal.symtab
> - || ((strchr ("+-", (*address)[0]) != NULL)
> - && ((*address)[1] != '['))))
> - decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
> - get_last_displayed_symtab (),
> - get_last_displayed_line (),
> - canonical, NULL, NULL);
> - else
> - decode_line_full (address, DECODE_LINE_FUNFIRSTLINE,
> - cursal.symtab, cursal.line, canonical, NULL, NULL);
> + if (!cursal.symtab
> + || (address != NULL
> + && strchr ("+-", address[0]) != NULL
> + && address[1] != '['))
> + {
> + decode_line_full (location, DECODE_LINE_FUNFIRSTLINE,
> + get_last_displayed_symtab (),
> + get_last_displayed_line (),
> + canonical, NULL, NULL);
> + return;
> + }
> }
> +
> + decode_line_full (location, DECODE_LINE_FUNFIRSTLINE,
> + cursal.symtab, cursal.line, canonical, NULL, NULL);
> }
>
>
> @@ -9909,19 +9956,19 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc,
> /* Decode a static tracepoint marker spec. */
>
> static struct symtabs_and_lines
> -decode_static_tracepoint_spec (char **arg_p)
> +decode_static_tracepoint_spec (const char **arg_p)
> {
> VEC(static_tracepoint_marker_p) *markers = NULL;
> struct symtabs_and_lines sals;
> struct cleanup *old_chain;
> - char *p = &(*arg_p)[3];
> - char *endp;
> + const char *p = &(*arg_p)[3];
> + const char *endp;
> char *marker_str;
> int i;
>
> - p = skip_spaces (p);
> + p = skip_spaces_const (p);
>
> - endp = skip_to_space (p);
> + endp = skip_to_space_const (p);
>
> marker_str = savestring (p, endp - p);
> old_chain = make_cleanup (xfree, marker_str);
> @@ -9953,20 +10000,30 @@ decode_static_tracepoint_spec (char **arg_p)
> return sals;
> }
>
> -/* Set a breakpoint. This function is shared between CLI and MI
> - functions for setting a breakpoint. This function has two major
> - modes of operations, selected by the PARSE_ARG parameter. If
> - non-zero, the function will parse ARG, extracting location,
> - condition, thread and extra string. Otherwise, ARG is just the
> - breakpoint's location, with condition, thread, and extra string
> - specified by the COND_STRING, THREAD and EXTRA_STRING parameters.
> +/* Set a breakpoint. This function is shared between CLI and MI functions
> + for setting a breakpoint at LOCATION.
> +
> + This function has two major modes of operations, selected by the PARSE_ARG
> + parameter.
> +
> + If PARSE_ARG is zero, LOCATION is just the breakpoint's location,
> + with condition, thread, and extra string specified by the COND_STRING,
> + THREAD, and EXTRA_STRING parameters.
> +
> + If PARSE_ARG is non-zero and LOCATION is a linespec location,
> + this function will attempt to extract the location, condition, thread,
> + and extra string from the linespec stored in LOCATION.
> + For non-linespec locations EXTRA_STRING is parsed for condition, thread,
> + and extra string.
> +
> If INTERNAL is non-zero, the breakpoint number will be allocated
> - from the internal breakpoint count. Returns true if any breakpoint
> - was created; false otherwise. */
> + from the internal breakpoint count.
> +
> + Returns true if any breakpoint was created; false otherwise. */
>
> int
> create_breakpoint (struct gdbarch *gdbarch,
> - char *arg, char *cond_string,
> + const struct event_location *location, char *cond_string,
> int thread, char *extra_string,
> int parse_arg,
====
Rename parse_arg to parse_location or parse_extra?
["parse_arg" made sense when "arg" was a parameter, but it's confusing now]
> int tempflag, enum bptype type_wanted,
> @@ -9977,8 +10034,6 @@ create_breakpoint (struct gdbarch *gdbarch,
> unsigned flags)
> {
> volatile struct gdb_exception e;
> - char *copy_arg = NULL;
> - char *addr_start = arg;
> struct linespec_result canonical;
> struct cleanup *old_chain;
> struct cleanup *bkpt_chain = NULL;
> @@ -9988,12 +10043,15 @@ create_breakpoint (struct gdbarch *gdbarch,
>
> gdb_assert (ops != NULL);
>
> + /* If extra_string isn't useful, set it to NULL. */
> + if (extra_string != NULL && *extra_string == '\0')
> + extra_string = NULL;
> +
> init_linespec_result (&canonical);
>
> TRY_CATCH (e, RETURN_MASK_ALL)
> {
> - ops->create_sals_from_location (&arg, &canonical, type_wanted,
> - addr_start, ©_arg);
> + ops->create_sals_from_location (location, &canonical, type_wanted);
> }
>
> /* If caller is interested in rc value from parse, set value. */
> @@ -10027,17 +10085,7 @@ create_breakpoint (struct gdbarch *gdbarch,
> a pending breakpoint and selected yes, or pending
> breakpoint behavior is on and thus a pending breakpoint
> is defaulted on behalf of the user. */
> - {
> - struct linespec_sals lsal;
> -
> - copy_arg = xstrdup (addr_start);
> - lsal.canonical = xstrdup (copy_arg);
> - lsal.sals.nelts = 1;
> - lsal.sals.sals = XNEW (struct symtab_and_line);
> - init_sal (&lsal.sals.sals[0]);
> pending = 1;
> - VEC_safe_push (linespec_sals, canonical.sals, &lsal);
> - }
> break;
> default:
> throw_exception (e);
> @@ -10082,6 +10130,8 @@ create_breakpoint (struct gdbarch *gdbarch,
> breakpoint. */
> if (!pending)
> {
> + char *arg = extra_string;
====
I gather having "arg" is here to minimize changes, but it reduces
readability a bit.
> +
> if (parse_arg)
> {
> char *rest;
> @@ -10102,11 +10152,13 @@ create_breakpoint (struct gdbarch *gdbarch,
> make_cleanup (xfree, rest);
> if (rest)
> extra_string = rest;
> + else
> + extra_string = NULL;
> }
> else
> {
> - if (*arg != '\0')
> - error (_("Garbage '%s' at end of location"), arg);
> + if (type_wanted != bp_dprintf && arg != NULL && *arg != '\0')
> + error (_("Garbage '%s' at end of location"), arg);
>
> /* Create a private copy of condition string. */
> if (cond_string)
> @@ -10132,8 +10184,6 @@ create_breakpoint (struct gdbarch *gdbarch,
> {
> struct breakpoint *b;
>
> - make_cleanup (xfree, copy_arg);
> -
> if (is_tracepoint_type (type_wanted))
> {
> struct tracepoint *t;
> @@ -10145,8 +10195,21 @@ create_breakpoint (struct gdbarch *gdbarch,
> b = XNEW (struct breakpoint);
>
> init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops);
> + b->location = copy_event_location (location);
> +
> + /* Append extra_string, if set, to the canonical representation
> + of the lsal. This preserves any conditions that the user may
> + have specified. */
> + if (extra_string != NULL)
> + {
> + char *new = xstrprintf ("%s %s",
> + event_location_to_string_const (location),
> + extra_string);
> +
> + set_event_location_string (b->location, new);
> + xfree (new);
> + }
>
> - b->addr_string = copy_arg;
> if (parse_arg)
> b->cond_string = NULL;
> else
> @@ -10159,7 +10222,15 @@ create_breakpoint (struct gdbarch *gdbarch,
> }
> b->cond_string = cond_string;
> }
> - b->extra_string = NULL;
> +
> + /* Make a private copy of extra_string for the breakpoint. */
> + if (extra_string != NULL)
> + {
> + b->extra_string = xstrdup (extra_string);
> + make_cleanup (xfree, b->extra_string);
====
This cleanup is odd. I would have expected a cleanup for "b" to
completely clean itself up. However, it looks like no cleanup for "b"
is ever created. So that's an existing bug which I wouldn't impose
on this patchset to fix, but OTOH this cleanup still feels wrong.
Also, the docs of extra_string in breakpoint.h are lacking.
It's not something that has to be fixed with this patchset,
but I'm having to dig too deep to figure out how extra_string
is different from cond_string. Can I trouble you to clarify things?
> + }
> + else
> + b->extra_string = NULL;
> b->ignore_count = ignore_count;
> b->disposition = tempflag ? disp_del : disp_donttouch;
> b->condition_not_parsed = 1;
> @@ -10206,16 +10277,21 @@ break_command_1 (char *arg, int flag, int from_tty)
> : bp_breakpoint);
> struct breakpoint_ops *ops;
> const char *arg_cp = arg;
> + struct event_location *location;
> + struct cleanup *cleanup;
> +
> + location = string_to_event_location (&arg, current_language);
> + cleanup = make_cleanup_delete_event_location (location);
>
> /* Matching breakpoints on probes. */
> - if (arg && probe_linespec_to_ops (&arg_cp) != NULL)
> + if (arg_cp != NULL && probe_linespec_to_ops (&arg_cp) != NULL)
====
Extra space before &&.
> ops = &bkpt_probe_breakpoint_ops;
> else
> ops = &bkpt_breakpoint_ops;
>
> create_breakpoint (get_current_arch (),
> - arg,
> - NULL, 0, NULL, 1 /* parse arg */,
> + location,
> + NULL, 0, arg, 1 /* parse arg */,
> tempflag, type_wanted,
> 0 /* Ignore count */,
> pending_break_support,
> @@ -10224,6 +10300,7 @@ break_command_1 (char *arg, int flag, int from_tty)
> 1 /* enabled */,
> 0 /* internal */,
> 0);
> + do_cleanups (cleanup);
> }
>
> /* Helper function for break_command_1 and disassemble_command. */
> @@ -10390,9 +10467,15 @@ stopat_command (char *arg, int from_tty)
> static void
> dprintf_command (char *arg, int from_tty)
> {
> + struct event_location *location;
> + struct cleanup *cleanup;
> +
> + location = string_to_event_location (&arg, current_language);
> + cleanup = make_cleanup_delete_event_location (location);
> +
> create_breakpoint (get_current_arch (),
> - arg,
> - NULL, 0, NULL, 1 /* parse arg */,
> + location,
> + NULL, 0, arg, 1 /* parse arg */,
> 0, bp_dprintf,
> 0 /* Ignore count */,
> pending_break_support,
> @@ -10401,6 +10484,7 @@ dprintf_command (char *arg, int from_tty)
> 1 /* enabled */,
> 0 /* internal */,
> 0);
> + do_cleanups (cleanup);
> }
>
> static void
> @@ -10545,8 +10629,9 @@ print_mention_ranged_breakpoint (struct breakpoint *b)
> static void
> print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp)
> {
> - fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string,
> - b->addr_string_range_end);
> + fprintf_unfiltered (fp, "break-range %s, %s",
> + event_location_to_string (b->location),
> + event_location_to_string (b->location_range_end));
> print_recreate_thread (b, fp);
> }
>
> @@ -10597,6 +10682,7 @@ break_range_command (char *arg, int from_tty)
> struct symtab_and_line sal_start, sal_end;
> struct cleanup *cleanup_bkpt;
> struct linespec_sals *lsal_start, *lsal_end;
> + struct event_location *start_location, *end_location;
>
> /* We don't support software ranged breakpoints. */
> if (target_ranged_break_num_registers () < 0)
> @@ -10616,9 +10702,10 @@ break_range_command (char *arg, int from_tty)
> init_linespec_result (&canonical_start);
>
> arg_start = arg;
> - parse_breakpoint_sals (&arg, &canonical_start);
> -
> - cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start);
> + start_location = string_to_event_location (&arg, current_language);
> + cleanup_bkpt = make_cleanup_delete_event_location (start_location);
> + parse_breakpoint_sals (start_location, &canonical_start);
> + make_cleanup_destroy_linespec_result (&canonical_start);
>
> if (arg[0] != ',')
> error (_("Too few arguments."));
> @@ -10648,7 +10735,9 @@ break_range_command (char *arg, int from_tty)
> symtab and line as the default symtab and line for the end of the
> range. This makes it possible to have ranges like "foo.c:27, +14",
> where +14 means 14 lines from the start location. */
> - decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE,
> + end_location = string_to_event_location (&arg, current_language);
> + make_cleanup_delete_event_location (end_location);
> + decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE,
> sal_start.symtab, sal_start.line,
> &canonical_end, NULL, NULL);
>
> @@ -10663,8 +10752,6 @@ break_range_command (char *arg, int from_tty)
> error (_("Cannot create a ranged breakpoint with multiple locations."));
>
> sal_end = lsal_end->sals.sals[0];
> - addr_string_end = savestring (arg_start, arg - arg_start);
> - make_cleanup (xfree, addr_string_end);
>
> end = find_breakpoint_range_end (sal_end);
> if (sal_start.pc > end)
> @@ -10691,8 +10778,8 @@ break_range_command (char *arg, int from_tty)
> set_breakpoint_count (breakpoint_count + 1);
> b->number = breakpoint_count;
> b->disposition = disp_donttouch;
> - b->addr_string = xstrdup (addr_string_start);
> - b->addr_string_range_end = xstrdup (addr_string_end);
> + b->location = copy_event_location (start_location);
> + b->location_range_end = copy_event_location (end_location);
> b->loc->length = length;
>
> do_cleanups (cleanup_bkpt);
> @@ -11819,21 +11906,25 @@ until_break_command (char *arg, int from_tty, int anywhere)
> struct frame_id caller_frame_id;
> struct breakpoint *breakpoint;
> struct breakpoint *breakpoint2 = NULL;
> - struct cleanup *old_chain;
> + struct cleanup *old_chain, *cleanup;
> int thread;
> struct thread_info *tp;
> + struct event_location *location;
>
> clear_proceed_status (0);
>
> /* Set a breakpoint where the user wants it and at return from
> this function. */
>
> + location = string_to_event_location (&arg, current_language);
> + cleanup = make_cleanup_delete_event_location (location);
> +
> if (last_displayed_sal_is_valid ())
> - sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
> + sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE,
> get_last_displayed_symtab (),
> get_last_displayed_line ());
> else
> - sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE,
> + sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE,
> (struct symtab *) NULL, 0);
>
> if (sals.nelts != 1)
> @@ -11919,6 +12010,8 @@ until_break_command (char *arg, int from_tty, int anywhere)
> }
> else
> do_cleanups (old_chain);
> +
> + do_cleanups (cleanup);
> }
>
> /* This function attempts to parse an optional "if <cond>" clause
> @@ -12074,7 +12167,8 @@ init_ada_exception_breakpoint (struct breakpoint *b,
>
> b->enable_state = enabled ? bp_enabled : bp_disabled;
> b->disposition = tempflag ? disp_del : disp_donttouch;
> - b->addr_string = addr_string;
> + b->location = string_to_event_location (&addr_string,
> + language_def (language_ada));
> b->language = language_ada;
> }
>
> @@ -13030,7 +13124,8 @@ say_where (struct breakpoint *b)
> single string. */
> if (b->loc == NULL)
> {
> - printf_filtered (_(" (%s) pending."), b->addr_string);
> + printf_filtered (_(" (%s) pending."),
> + event_location_to_string (b->location));
> }
> else
> {
> @@ -13052,7 +13147,8 @@ say_where (struct breakpoint *b)
> /* This is not ideal, but each location may have a
> different file name, and this at least reflects the
> real situation somewhat. */
> - printf_filtered (": %s.", b->addr_string);
> + printf_filtered (": %s.",
> + event_location_to_string (b->location));
> }
>
> if (b->loc->next)
> @@ -13094,9 +13190,9 @@ base_breakpoint_dtor (struct breakpoint *self)
> decref_counted_command_line (&self->commands);
> xfree (self->cond_string);
> xfree (self->extra_string);
> - xfree (self->addr_string);
> xfree (self->filter);
> - xfree (self->addr_string_range_end);
> + delete_event_location (self->location);
> + delete_event_location (self->location_range_end);
> }
>
> static struct bp_location *
> @@ -13189,11 +13285,10 @@ base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
> }
>
> static void
> -base_breakpoint_create_sals_from_location (char **arg,
> - struct linespec_result *canonical,
> - enum bptype type_wanted,
> - char *addr_start,
> - char **copy_arg)
> +base_breakpoint_create_sals_from_location
> + (const struct event_location *location,
> + struct linespec_result *canonical,
> + enum bptype type_wanted)
> {
> internal_error_pure_virtual_called ();
> }
> @@ -13215,7 +13310,8 @@ base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch,
> }
>
> static void
> -base_breakpoint_decode_location (struct breakpoint *b, char **s,
> +base_breakpoint_decode_location (struct breakpoint *b,
> + const struct event_location *location,
> struct symtabs_and_lines *sals)
> {
> internal_error_pure_virtual_called ();
> @@ -13266,9 +13362,9 @@ static void
> bkpt_re_set (struct breakpoint *b)
> {
> /* FIXME: is this still reachable? */
> - if (b->addr_string == NULL)
> + if (event_location_empty_p (b->location))
> {
> - /* Anything without a string can't be re-set. */
> + /* Anything without a location can't be re-set. */
> delete_breakpoint (b);
> return;
> }
> @@ -13420,18 +13516,17 @@ bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp)
> internal_error (__FILE__, __LINE__,
> _("unhandled breakpoint type %d"), (int) tp->type);
>
> - fprintf_unfiltered (fp, " %s", tp->addr_string);
> + fprintf_unfiltered (fp, " %s",
> + event_location_to_string (tp->location));
> print_recreate_thread (tp, fp);
> }
>
> static void
> -bkpt_create_sals_from_location (char **arg,
> - struct linespec_result *canonical,
> - enum bptype type_wanted,
> - char *addr_start, char **copy_arg)
> +bkpt_create_sals_from_location (const struct event_location *location,
> + struct linespec_result *canonical,
> + enum bptype type_wanted)
> {
> - create_sals_from_location_default (arg, canonical, type_wanted,
> - addr_start, copy_arg);
> + create_sals_from_location_default (location, canonical, type_wanted);
> }
>
> static void
> @@ -13456,10 +13551,11 @@ bkpt_create_breakpoints_sal (struct gdbarch *gdbarch,
> }
>
> static void
> -bkpt_decode_location (struct breakpoint *b, char **s,
> +bkpt_decode_location (struct breakpoint *b,
> + const struct event_location *location,
> struct symtabs_and_lines *sals)
> {
> - decode_location_default (b, s, sals);
> + decode_location_default (b, location, sals);
> }
>
> /* Virtual table for internal breakpoints. */
> @@ -13659,26 +13755,23 @@ bkpt_probe_remove_location (struct bp_location *bl)
> }
>
> static void
> -bkpt_probe_create_sals_from_location (char **arg,
> +bkpt_probe_create_sals_from_location (const struct event_location *location,
> struct linespec_result *canonical,
> - enum bptype type_wanted,
> - char *addr_start, char **copy_arg)
> + enum bptype type_wanted)
> {
> struct linespec_sals lsal;
>
> - lsal.sals = parse_probes (arg, canonical);
> -
> - *copy_arg = xstrdup (canonical->addr_string);
> - lsal.canonical = xstrdup (*copy_arg);
> -
> + lsal.sals = parse_probes (location, canonical);
> + lsal.canonical = xstrdup (event_location_to_string (canonical->location));
> VEC_safe_push (linespec_sals, canonical->sals, &lsal);
> }
>
> static void
> -bkpt_probe_decode_location (struct breakpoint *b, char **s,
> +bkpt_probe_decode_location (struct breakpoint *b,
> + const struct event_location *location,
> struct symtabs_and_lines *sals)
> {
> - *sals = parse_probes (s, NULL);
> + *sals = parse_probes (location, NULL);
> if (!sals->sals)
> error (_("probe not found"));
> }
> @@ -13760,7 +13853,8 @@ tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
> internal_error (__FILE__, __LINE__,
> _("unhandled tracepoint type %d"), (int) self->type);
>
> - fprintf_unfiltered (fp, " %s", self->addr_string);
> + fprintf_unfiltered (fp, " %s",
> + event_location_to_string (self->location));
> print_recreate_thread (self, fp);
>
> if (tp->pass_count)
> @@ -13768,13 +13862,11 @@ tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp)
> }
>
> static void
> -tracepoint_create_sals_from_location (char **arg,
> - struct linespec_result *canonical,
> - enum bptype type_wanted,
> - char *addr_start, char **copy_arg)
> +tracepoint_create_sals_from_location (const struct event_location *location,
> + struct linespec_result *canonical,
> + enum bptype type_wanted)
> {
> - create_sals_from_location_default (arg, canonical, type_wanted,
> - addr_start, copy_arg);
> + create_sals_from_location_default (location, canonical, type_wanted);
> }
>
> static void
> @@ -13799,10 +13891,11 @@ tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch,
> }
>
> static void
> -tracepoint_decode_location (struct breakpoint *b, char **s,
> +tracepoint_decode_location (struct breakpoint *b,
> + const struct event_location *location,
> struct symtabs_and_lines *sals)
> {
> - decode_location_default (b, s, sals);
> + decode_location_default (b, location, sals);
> }
>
> struct breakpoint_ops tracepoint_breakpoint_ops;
> @@ -13811,22 +13904,22 @@ struct breakpoint_ops tracepoint_breakpoint_ops;
> static probe. */
>
> static void
> -tracepoint_probe_create_sals_from_location (char **arg,
> - struct linespec_result *canonical,
> - enum bptype type_wanted,
> - char *addr_start, char **copy_arg)
> +tracepoint_probe_create_sals_from_location
> + (const struct event_location *location,
> + struct linespec_result *canonical,
> + enum bptype type_wanted)
> {
> /* We use the same method for breakpoint on probes. */
> - bkpt_probe_create_sals_from_location (arg, canonical, type_wanted,
> - addr_start, copy_arg);
> + bkpt_probe_create_sals_from_location (location, canonical, type_wanted);
> }
>
> static void
> -tracepoint_probe_decode_location (struct breakpoint *b, char **s,
> +tracepoint_probe_decode_location (struct breakpoint *b,
> + const struct event_location *location,
> struct symtabs_and_lines *sals)
> {
> /* We use the same method for breakpoint on probes. */
> - bkpt_probe_decode_location (b, s, sals);
> + bkpt_probe_decode_location (b, location, sals);
> }
>
> static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
> @@ -13865,7 +13958,8 @@ dprintf_re_set (struct breakpoint *b)
> static void
> dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
> {
> - fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string,
> + fprintf_unfiltered (fp, "dprintf %s%s",
> + event_location_to_string (tp->location),
> tp->extra_string);
> print_recreate_thread (tp, fp);
> }
> @@ -13912,19 +14006,28 @@ dprintf_after_condition_true (struct bpstats *bs)
> markers (`-m'). */
>
> static void
> -strace_marker_create_sals_from_location (char **arg,
> +strace_marker_create_sals_from_location (const struct event_location *location,
> struct linespec_result *canonical,
> - enum bptype type_wanted,
> - char *addr_start, char **copy_arg)
> + enum bptype type_wanted)
> {
> struct linespec_sals lsal;
> + const char *arg_start, *arg;
> +
> + arg = arg_start = get_linespec_location (location);
> + lsal.sals = decode_static_tracepoint_spec (&arg);
>
> - lsal.sals = decode_static_tracepoint_spec (arg);
> + if (canonical != NULL)
> + {
> + char *str;
> + struct cleanup *cleanup;
>
> - *copy_arg = savestring (addr_start, *arg - addr_start);
> + str = savestring (arg_start, arg - arg_start);
> + cleanup = make_cleanup (xfree, str);
> + canonical->location = new_linespec_location (&str);
> + do_cleanups (cleanup);
> + }
>
> - canonical->addr_string = xstrdup (*copy_arg);
> - lsal.canonical = xstrdup (*copy_arg);
> + lsal.canonical = xstrdup (event_location_to_string (canonical->location));
> VEC_safe_push (linespec_sals, canonical->sals, &lsal);
> }
>
> @@ -13957,17 +14060,17 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
> struct symtabs_and_lines expanded;
> struct tracepoint *tp;
> struct cleanup *old_chain;
> - char *addr_string;
> + struct event_location *location;
>
> expanded.nelts = 1;
> expanded.sals = &lsal->sals.sals[i];
>
> - addr_string = xstrdup (canonical->addr_string);
> - old_chain = make_cleanup (xfree, addr_string);
> + location = copy_event_location (canonical->location);
> + old_chain = make_cleanup_delete_event_location (location);
>
> tp = XCNEW (struct tracepoint);
> init_breakpoint_sal (&tp->base, gdbarch, expanded,
> - addr_string, NULL,
> + location, NULL,
> cond_string, extra_string,
> type_wanted, disposition,
> thread, task, ignore_count, ops,
> @@ -13988,12 +14091,14 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
> }
>
> static void
> -strace_marker_decode_location (struct breakpoint *b, char **s,
> +strace_marker_decode_location (struct breakpoint *b,
> + const struct event_location *location,
> struct symtabs_and_lines *sals)
> {
> struct tracepoint *tp = (struct tracepoint *) b;
> + const char *s = get_linespec_location (location);
>
> - *sals = decode_static_tracepoint_spec (s);
> + *sals = decode_static_tracepoint_spec (&s);
> if (sals->nelts > tp->static_trace_marker_id_idx)
> {
> sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx];
> @@ -14325,10 +14430,12 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
>
> if (!VEC_empty(static_tracepoint_marker_p, markers))
> {
> + char *p, *tmp;
> struct symtab_and_line sal2;
> struct symbol *sym;
> struct static_tracepoint_marker *tpmarker;
> struct ui_out *uiout = current_uiout;
> + struct cleanup *cleanup;
>
> tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0);
>
> @@ -14369,10 +14476,13 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
> b->loc->line_number = sal2.line;
> b->loc->symtab = sym != NULL ? sal2.symtab : NULL;
>
> - xfree (b->addr_string);
> - b->addr_string = xstrprintf ("%s:%d",
> - symtab_to_filename_for_display (sal2.symtab),
> - b->loc->line_number);
> + delete_event_location (b->location);
> + p = tmp = xstrprintf ("%s:%d",
> + symtab_to_filename_for_display (sal2.symtab),
> + b->loc->line_number);
> + cleanup = make_cleanup (xfree, tmp);
> + b->location = new_linespec_location (&tmp);
> + do_cleanups (cleanup);
>
> /* Might be nice to check if function changed, and warn if
> so. */
> @@ -14529,22 +14639,21 @@ update_breakpoint_locations (struct breakpoint *b,
> update_global_location_list (UGLL_MAY_INSERT);
> }
>
> -/* Find the SaL locations corresponding to the given ADDR_STRING.
> +/* Find the SaL locations corresponding to the given LOCATION.
> On return, FOUND will be 1 if any SaL was found, zero otherwise. */
>
> static struct symtabs_and_lines
> -location_to_sals (struct breakpoint *b, char *addr_string, int *found)
> +location_to_sals (struct breakpoint *b, struct event_location *location,
> + int *found)
> {
> - char *s;
> struct symtabs_and_lines sals = {0};
> volatile struct gdb_exception e;
>
> gdb_assert (b->ops != NULL);
> - s = addr_string;
>
> TRY_CATCH (e, RETURN_MASK_ERROR)
> {
> - b->ops->decode_location (b, &s, &sals);
> + b->ops->decode_location (b, location, &sals);
> }
> if (e.reason < 0)
> {
> @@ -14582,21 +14691,37 @@ location_to_sals (struct breakpoint *b, char *addr_string, int *found)
>
> for (i = 0; i < sals.nelts; ++i)
> resolve_sal_pc (&sals.sals[i]);
> - if (b->condition_not_parsed && s && s[0])
> + if (b->condition_not_parsed)
> {
> - char *cond_string, *extra_string;
> - int thread, task;
> + const char *s = b->extra_string;
>
> - find_condition_and_thread (s, sals.sals[0].pc,
> - &cond_string, &thread, &task,
> - &extra_string);
> - if (cond_string)
> - b->cond_string = cond_string;
> - b->thread = thread;
> - b->task = task;
> - if (extra_string)
> - b->extra_string = extra_string;
> - b->condition_not_parsed = 0;
> + if (s != NULL && *s != '\0')
====
If we have a rule that b->extra_string is never "" (only NULL) then
we can simplify this, and even remove this extra nested "if".
E.g., just have
+ if (b->condition_not_parsed && b->extra_string != NULL)
> + {
> + char *cond_string, *extra_string;
> + int thread, task;
> + const char *orig = s;
> +
> + find_condition_and_thread (s, sals.sals[0].pc,
> + &cond_string, &thread, &task,
> + &extra_string);
> + if (cond_string)
> + b->cond_string = cond_string;
> + b->thread = thread;
> + b->task = task;
> + if (extra_string)
> + {
> + xfree (b->extra_string);
> + b->extra_string = extra_string;
> + }
> + b->condition_not_parsed = 0;
> +
> + /* If the breakpoint was pending and is now resolved,
> + clear the location's string representation. This
> + is necessary since pending breakpoints may have
> + condition, thread, or task keywords embedded into it. */
> + if (b->loc == NULL)
> + set_event_location_string (b->location, NULL);
> + }
> }
>
> if (b->type == bp_static_tracepoint && !strace_marker_p (b))
> @@ -14622,16 +14747,16 @@ breakpoint_re_set_default (struct breakpoint *b)
> struct symtabs_and_lines expanded = {0};
> struct symtabs_and_lines expanded_end = {0};
>
> - sals = location_to_sals (b, b->addr_string, &found);
> + sals = location_to_sals (b, b->location, &found);
> if (found)
> {
> make_cleanup (xfree, sals.sals);
> expanded = sals;
> }
>
> - if (b->addr_string_range_end)
> + if (b->location_range_end != NULL)
> {
> - sals_end = location_to_sals (b, b->addr_string_range_end, &found);
> + sals_end = location_to_sals (b, b->location_range_end, &found);
> if (found)
> {
> make_cleanup (xfree, sals_end.sals);
> @@ -14646,12 +14771,11 @@ breakpoint_re_set_default (struct breakpoint *b)
> calls parse_breakpoint_sals. Return 1 for success, zero for failure. */
>
> static void
> -create_sals_from_location_default (char **arg,
> - struct linespec_result *canonical,
> - enum bptype type_wanted,
> - char *addr_start, char **copy_arg)
> +create_sals_from_location_default (const struct event_location *location,
> + struct linespec_result *canonical,
> + enum bptype type_wanted)
> {
> - parse_breakpoint_sals (arg, canonical);
> + parse_breakpoint_sals (location, canonical);
> }
>
> /* Call create_breakpoints_sal for the given arguments. This is the default
> @@ -14682,13 +14806,14 @@ create_breakpoints_sal_default (struct gdbarch *gdbarch,
> default function for the `decode_location' method of breakpoint_ops. */
>
> static void
> -decode_location_default (struct breakpoint *b, char **s,
> +decode_location_default (struct breakpoint *b,
> + const struct event_location *location,
> struct symtabs_and_lines *sals)
> {
> struct linespec_result canonical;
>
> init_linespec_result (&canonical);
> - decode_line_full (s, DECODE_LINE_FUNFIRSTLINE,
> + decode_line_full (location, DECODE_LINE_FUNFIRSTLINE,
> (struct symtab *) NULL, 0,
> &canonical, multiple_symbols_all,
> b->filter);
> @@ -15421,16 +15546,20 @@ static void
> trace_command (char *arg, int from_tty)
> {
> struct breakpoint_ops *ops;
> + struct event_location *location;
> + struct cleanup *back_to;
> const char *arg_cp = arg;
>
> - if (arg && probe_linespec_to_ops (&arg_cp))
> + location = string_to_event_location (&arg, current_language);
> + back_to = make_cleanup_delete_event_location (location);
> + if (arg_cp != NULL && probe_linespec_to_ops (&arg_cp) != NULL)
> ops = &tracepoint_probe_breakpoint_ops;
> else
> ops = &tracepoint_breakpoint_ops;
>
> create_breakpoint (get_current_arch (),
> - arg,
> - NULL, 0, NULL, 1 /* parse arg */,
> + location,
> + NULL, 0, arg, 1 /* parse arg */,
> 0 /* tempflag */,
> bp_tracepoint /* type_wanted */,
> 0 /* Ignore count */,
> @@ -15439,14 +15568,20 @@ trace_command (char *arg, int from_tty)
> from_tty,
> 1 /* enabled */,
> 0 /* internal */, 0);
> + do_cleanups (back_to);
> }
>
> static void
> ftrace_command (char *arg, int from_tty)
> {
> + struct event_location *location;
> + struct cleanup *back_to;
> +
> + location = string_to_event_location (&arg, current_language);
> + back_to = make_cleanup_delete_event_location (location);
> create_breakpoint (get_current_arch (),
> - arg,
> - NULL, 0, NULL, 1 /* parse arg */,
> + location,
> + NULL, 0, arg, 1 /* parse arg */,
> 0 /* tempflag */,
> bp_fast_tracepoint /* type_wanted */,
> 0 /* Ignore count */,
> @@ -15455,6 +15590,7 @@ ftrace_command (char *arg, int from_tty)
> from_tty,
> 1 /* enabled */,
> 0 /* internal */, 0);
> + do_cleanups (back_to);
> }
>
> /* strace command implementation. Creates a static tracepoint. */
> @@ -15463,17 +15599,26 @@ static void
> strace_command (char *arg, int from_tty)
> {
> struct breakpoint_ops *ops;
> + struct event_location *location;
> + struct cleanup *back_to;
>
> /* Decide if we are dealing with a static tracepoint marker (`-m'),
> or with a normal static tracepoint. */
> if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
> - ops = &strace_marker_breakpoint_ops;
> + {
> + ops = &strace_marker_breakpoint_ops;
> + location = new_linespec_location (&arg);
> + }
> else
> - ops = &tracepoint_breakpoint_ops;
> + {
> + ops = &tracepoint_breakpoint_ops;
> + location = string_to_event_location (&arg, current_language);
> + }
>
> + back_to = make_cleanup_delete_event_location (location);
> create_breakpoint (get_current_arch (),
> - arg,
> - NULL, 0, NULL, 1 /* parse arg */,
> + location,
> + NULL, 0, arg, 1 /* parse arg */,
> 0 /* tempflag */,
> bp_static_tracepoint /* type_wanted */,
> 0 /* Ignore count */,
> @@ -15482,6 +15627,7 @@ strace_command (char *arg, int from_tty)
> from_tty,
> 1 /* enabled */,
> 0 /* internal */, 0);
> + do_cleanups (back_to);
> }
>
> /* Set up a fake reader function that gets command lines from a linked
> @@ -15513,6 +15659,8 @@ create_tracepoint_from_upload (struct uploaded_tp *utp)
> {
> char *addr_str, small_buf[100];
> struct tracepoint *tp;
> + struct event_location *location;
> + struct cleanup *cleanup;
>
> if (utp->at_string)
> addr_str = utp->at_string;
> @@ -15535,9 +15683,11 @@ create_tracepoint_from_upload (struct uploaded_tp *utp)
> "has no source form, ignoring it"),
> utp->number);
>
> + location = string_to_event_location (&addr_str, current_language);
> + cleanup = make_cleanup_delete_event_location (location);
> if (!create_breakpoint (get_current_arch (),
> - addr_str,
> - utp->cond_string, -1, NULL,
> + location,
> + utp->cond_string, -1, addr_str,
> 0 /* parse cond/thread */,
> 0 /* tempflag */,
> utp->type /* type_wanted */,
> @@ -15548,7 +15698,12 @@ create_tracepoint_from_upload (struct uploaded_tp *utp)
> utp->enabled /* enabled */,
> 0 /* internal */,
> CREATE_BREAKPOINT_FLAGS_INSERTED))
> - return NULL;
> + {
> + do_cleanups (cleanup);
> + return NULL;
> + }
> +
> + do_cleanups (cleanup);
>
> /* Get the tracepoint we just created. */
> tp = get_tracepoint (tracepoint_count);
> diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
> index 42c7427..5027ff4 100644
> --- a/gdb/breakpoint.h
> +++ b/gdb/breakpoint.h
> @@ -37,6 +37,7 @@ struct bpstats;
> struct bp_location;
> struct linespec_result;
> struct linespec_sals;
> +struct event_location;
>
> /* This is the maximum number of bytes a breakpoint instruction can
> take. Feel free to increase it. It's just used in a few places to
> @@ -560,8 +561,9 @@ struct breakpoint_ops
> `create_sals_from_location_default'.
>
> This function is called inside `create_breakpoint'. */
> - void (*create_sals_from_location) (char **, struct linespec_result *,
> - enum bptype, char *, char **);
> + void (*create_sals_from_location) (const struct event_location *location,
> + struct linespec_result *canonical,
> + enum bptype type_wanted);
>
> /* This method will be responsible for creating a breakpoint given its SALs.
> Usually, it just calls `create_breakpoints_sal' (for ordinary
> @@ -582,8 +584,9 @@ struct breakpoint_ops
> it calls `decode_line_full'.
>
> This function is called inside `location_to_sals'. */
> - void (*decode_location) (struct breakpoint *, char **,
> - struct symtabs_and_lines *);
> + void (*decode_location) (struct breakpoint *b,
> + const struct event_location *location,
> + struct symtabs_and_lines *sals);
>
> /* Return true if this breakpoint explains a signal. See
> bpstat_explains_signal. */
> @@ -682,17 +685,17 @@ struct breakpoint
> non-thread-specific ordinary breakpoints this is NULL. */
> struct program_space *pspace;
>
> - /* String we used to set the breakpoint (malloc'd). */
> - char *addr_string;
> + /* Location we used to set the breakpoint (malloc'd). */
> + struct event_location *location;
>
> /* The filter that should be passed to decode_line_full when
> re-setting this breakpoint. This may be NULL, but otherwise is
> allocated with xmalloc. */
> char *filter;
>
> - /* For a ranged breakpoint, the string we used to find
> + /* For a ranged breakpoint, the location we used to find
> the end of the range (malloc'd). */
> - char *addr_string_range_end;
> + struct event_location *location_range_end;
>
> /* Architecture we used to set the breakpoint. */
> struct gdbarch *gdbarch;
> @@ -1274,7 +1277,8 @@ enum breakpoint_create_flags
> CREATE_BREAKPOINT_FLAGS_INSERTED = 1 << 0
> };
>
> -extern int create_breakpoint (struct gdbarch *gdbarch, char *arg,
> +extern int create_breakpoint (struct gdbarch *gdbarch,
> + const struct event_location *location,
> char *cond_string, int thread,
> char *extra_string,
> int parse_arg,
> diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
> index e46f036..ebca1fc 100644
> --- a/gdb/cli/cli-cmds.c
> +++ b/gdb/cli/cli-cmds.c
> @@ -38,6 +38,7 @@
> #include "disasm.h"
> #include "tracepoint.h"
> #include "filestuff.h"
> +#include "location.h"
>
> #include "ui-out.h"
>
> @@ -782,7 +783,6 @@ edit_command (char *arg, int from_tty)
> struct symtabs_and_lines sals;
> struct symtab_and_line sal;
> struct symbol *sym;
> - char *arg1;
> char *editor;
> char *p;
> const char *fn;
> @@ -804,21 +804,28 @@ edit_command (char *arg, int from_tty)
> }
> else
> {
> - /* Now should only be one argument -- decode it in SAL. */
> + struct cleanup *cleanup;
> + struct event_location *location;
> + char *arg1;
>
> + /* Now should only be one argument -- decode it in SAL. */
> arg1 = arg;
> - sals = decode_line_1 (&arg1, DECODE_LINE_LIST_MODE, 0, 0);
> + location = string_to_event_location (&arg1, current_language);
> + cleanup = make_cleanup_delete_event_location (location);
> + sals = decode_line_1 (location, DECODE_LINE_LIST_MODE, 0, 0);
>
> filter_sals (&sals);
> if (! sals.nelts)
> {
> /* C++ */
> + do_cleanups (cleanup);
> return;
> }
> if (sals.nelts > 1)
> {
> ambiguous_line_spec (&sals);
> xfree (sals.sals);
> + do_cleanups (cleanup);
> return;
> }
>
> @@ -860,6 +867,7 @@ edit_command (char *arg, int from_tty)
>
> if (sal.symtab == 0)
> error (_("No line number known for %s."), arg);
> + do_cleanups (cleanup);
> }
>
> if ((editor = (char *) getenv ("EDITOR")) == NULL)
> @@ -888,6 +896,9 @@ list_command (char *arg, int from_tty)
> int dummy_beg = 0;
> int linenum_beg = 0;
> char *p;
> + struct cleanup *cleanup;
> +
> + cleanup = make_cleanup (null_cleanup, NULL);
>
> /* Pull in the current default source line if necessary. */
> if (arg == 0 || arg[0] == '+' || arg[0] == '-')
> @@ -951,15 +962,24 @@ list_command (char *arg, int from_tty)
> dummy_beg = 1;
> else
> {
> - sals = decode_line_1 (&arg1, DECODE_LINE_LIST_MODE, 0, 0);
> + struct event_location *location;
> +
> + location = string_to_event_location (&arg1, current_language);
> + make_cleanup_delete_event_location (location);
> + sals = decode_line_1 (location, DECODE_LINE_LIST_MODE, 0, 0);
>
> filter_sals (&sals);
> if (!sals.nelts)
> - return; /* C++ */
> + {
> + /* C++ */
> + do_cleanups (cleanup);
> + return;
> + }
> if (sals.nelts > 1)
> {
> ambiguous_line_spec (&sals);
> xfree (sals.sals);
> + do_cleanups (cleanup);
> return;
> }
>
> @@ -984,18 +1004,28 @@ list_command (char *arg, int from_tty)
> dummy_end = 1;
> else
> {
> + struct event_location *location;
> +
> + location = string_to_event_location (&arg1, current_language);
> + make_cleanup_delete_event_location (location);
> if (dummy_beg)
> - sals_end = decode_line_1 (&arg1, DECODE_LINE_LIST_MODE, 0, 0);
> + sals_end = decode_line_1 (location,
> + DECODE_LINE_LIST_MODE, 0, 0);
> else
> - sals_end = decode_line_1 (&arg1, DECODE_LINE_LIST_MODE,
> + sals_end = decode_line_1 (location, DECODE_LINE_LIST_MODE,
> sal.symtab, sal.line);
> +
> filter_sals (&sals_end);
> if (sals_end.nelts == 0)
> - return;
> + {
> + do_cleanups (cleanup);
> + return;
> + }
> if (sals_end.nelts > 1)
> {
> ambiguous_line_spec (&sals_end);
> xfree (sals_end.sals);
> + do_cleanups (cleanup);
> return;
> }
> sal_end = sals_end.sals[0];
> @@ -1076,6 +1106,7 @@ list_command (char *arg, int from_tty)
> ? sal.line + get_lines_to_list ()
> : sal_end.line + 1),
> 0);
> + do_cleanups (cleanup);
> }
>
> /* Subroutine of disassemble_command to simplify it.
> diff --git a/gdb/elfread.c b/gdb/elfread.c
> index fbe3917..03a6a4f 100644
> --- a/gdb/elfread.c
> +++ b/gdb/elfread.c
> @@ -45,6 +45,7 @@
> #include "bcache.h"
> #include "gdb_bfd.h"
> #include "build-id.h"
> +#include "location.h"
>
> extern void _initialize_elfread (void);
>
> @@ -1077,7 +1078,8 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
> resolved_pc = gdbarch_addr_bits_remove (gdbarch, resolved_pc);
>
> gdb_assert (current_program_space == b->pspace || b->pspace == NULL);
> - elf_gnu_ifunc_record_cache (b->addr_string, resolved_pc);
> + elf_gnu_ifunc_record_cache (event_location_to_string (b->location),
> + resolved_pc);
>
> sal = find_pc_line (resolved_pc, 0);
> sals.nelts = 1;
> diff --git a/gdb/linespec.c b/gdb/linespec.c
> index f2ae93b..29e32e3 100644
> --- a/gdb/linespec.c
> +++ b/gdb/linespec.c
> @@ -43,6 +43,7 @@
> #include "filenames.h"
> #include "ada-lang.h"
> #include "stack.h"
> +#include "location.h"
>
> typedef struct symbol *symbolp;
> DEF_VEC_P (symbolp);
> @@ -280,8 +281,8 @@ struct ls_parser
> const char *saved_arg;
>
> /* Head of the input stream. */
> - const char **stream;
> -#define PARSER_STREAM(P) (*(P)->lexer.stream)
> + const char *stream;
> +#define PARSER_STREAM(P) ((P)->lexer.stream)
>
> /* The current token. */
> linespec_token current;
> @@ -319,7 +320,7 @@ static CORE_ADDR linespec_expression_to_pc (const char **exp_ptr);
>
> static struct symtabs_and_lines decode_objc (struct linespec_state *self,
> linespec_p ls,
> - const char **argptr);
> + const char *arg);
>
> static VEC (symtab_ptr) *symtabs_from_filename (const char *);
>
> @@ -433,10 +434,9 @@ linespec_lexer_lex_keyword (const char *p)
> int len = strlen (linespec_keywords[i]);
>
> /* If P begins with one of the keywords and the next
> - character is not a valid identifier character,
> - we have found a keyword. */
> + character is whitespace, we have found a keyword. */
> if (strncmp (p, linespec_keywords[i], len) == 0
> - && !(isalnum (p[len]) || p[len] == '_'))
> + && isspace (p[len]))
====
I think I'm ok with this change, but it seems separate from this patchset.
Submit it separately?
> return linespec_keywords[i];
> }
> }
> @@ -1765,21 +1765,29 @@ linespec_parse_basic (linespec_parser *parser)
> STATE->canonical. */
>
> static void
> -canonicalize_linespec (struct linespec_state *state, linespec_p ls)
> +canonicalize_linespec (struct linespec_state *state, const linespec_p ls)
> {
> + char *tmp;
> +
> /* If canonicalization was not requested, no need to do anything. */
> if (!state->canonical)
> return;
>
> /* Shortcut expressions, which can only appear by themselves. */
> if (ls->expression != NULL)
> - state->canonical->addr_string = xstrdup (ls->expression);
> + {
> + tmp = ASTRDUP (ls->expression);
====
No need to make this change now (assuming it's doable),
but I'm curious if the parser needs to modify its argument
or whether we can pass a const char * and remove the ASTRDUP here
(and elsewhere).
> + state->canonical->location = new_linespec_location (&tmp);
> + }
> else
> {
> struct ui_file *buf;
> int need_colon = 0;
> + struct cleanup *cleanup;
>
> buf = mem_fileopen ();
> + cleanup = make_cleanup_ui_file_delete (buf);
> +
> if (ls->source_filename)
> {
> fputs_unfiltered (ls->source_filename, buf);
> @@ -1828,8 +1836,10 @@ canonicalize_linespec (struct linespec_state *state, linespec_p ls)
> ls->line_offset.offset);
> }
>
> - state->canonical->addr_string = ui_file_xstrdup (buf, NULL);
> - ui_file_delete (buf);
> + tmp = ui_file_xstrdup (buf, NULL);
> + make_cleanup (xfree, tmp);
> + state->canonical->location = new_linespec_location (&tmp);
> + do_cleanups (cleanup);
> }
> }
>
> @@ -2097,8 +2107,6 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
> }
>
> /* Parse a string that specifies a linespec.
> - Pass the address of a char * variable; that variable will be
> - advanced over the characters actually parsed.
>
> The basic grammar of linespecs:
>
> @@ -2147,10 +2155,10 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
> if no file is validly specified. Callers must check that.
> Also, the line number returned may be invalid. */
>
> -/* Parse the linespec in ARGPTR. */
> +/* Parse the linespec in ARG. */
>
> static struct symtabs_and_lines
> -parse_linespec (linespec_parser *parser, const char **argptr)
> +parse_linespec (linespec_parser *parser, const char *arg)
> {
> linespec_token token;
> struct symtabs_and_lines values;
> @@ -2161,17 +2169,17 @@ parse_linespec (linespec_parser *parser, const char **argptr)
> IDEs to work around bugs in the previous parser by quoting
> the entire linespec, so we attempt to deal with this nicely. */
> parser->is_quote_enclosed = 0;
> - if (!is_ada_operator (*argptr)
> - && strchr (linespec_quote_characters, **argptr) != NULL)
> + if (!is_ada_operator (arg)
> + && strchr (linespec_quote_characters, *arg) != NULL)
> {
> const char *end;
>
> - end = skip_quote_char (*argptr + 1, **argptr);
> + end = skip_quote_char (arg + 1, *arg);
> if (end != NULL && is_closing_quote_enclosed (end))
> {
> - /* Here's the special case. Skip ARGPTR past the initial
> + /* Here's the special case. Skip ARG past the initial
> quote. */
> - ++(*argptr);
> + ++arg;
> parser->is_quote_enclosed = 1;
> }
> }
> @@ -2180,8 +2188,8 @@ parse_linespec (linespec_parser *parser, const char **argptr)
> Consider "b thread thread 42". */
> parser->keyword_ok = 0;
>
> - parser->lexer.saved_arg = *argptr;
> - parser->lexer.stream = argptr;
> + parser->lexer.saved_arg = arg;
> + parser->lexer.stream = arg;
> file_exception.reason = 0;
>
> /* Initialize the default symtab and line offset. */
> @@ -2189,7 +2197,7 @@ parse_linespec (linespec_parser *parser, const char **argptr)
> &PARSER_STATE (parser)->default_line);
>
> /* Objective-C shortcut. */
> - values = decode_objc (PARSER_STATE (parser), PARSER_RESULT (parser), argptr);
> + values = decode_objc (PARSER_STATE (parser), PARSER_RESULT (parser), arg);
> if (values.sals != NULL)
> return values;
>
> @@ -2373,6 +2381,7 @@ linespec_parser_new (linespec_parser *parser,
> int default_line,
> struct linespec_result *canonical)
> {
> + memset (parser, 0, sizeof (linespec_parser));
> parser->lexer.current.type = LSTOKEN_CONSUMED;
> memset (PARSER_RESULT (parser), 0, sizeof (struct linespec));
> PARSER_RESULT (parser)->line_offset.sign = LINE_OFFSET_UNKNOWN;
> @@ -2437,7 +2446,7 @@ linespec_lex_to_end (char **stringp)
> parser.lexer.saved_arg = *stringp;
> parser.keyword_ok = 1;
> orig = p = *stringp;
> - parser.lexer.stream = &p;
> + parser.lexer.stream = p;
>
> TRY_CATCH (e, RETURN_MASK_ERROR)
> {
> @@ -2474,10 +2483,42 @@ linespec_lex_to_end (char **stringp)
> do_cleanups (cleanup);
> }
>
> +/* A helper function for decode_line_full and decode_line_1 to
> + turn LOCATION into symtabs_and_lines. */
> +
> +static struct symtabs_and_lines
> +event_location_to_sals (linespec_parser *parser,
> + const struct event_location *location)
> +{
> + struct symtabs_and_lines result = {NULL, 0};
> +
> + switch (event_location_type (location))
> + {
> + case LINESPEC_LOCATION:
> + {
> + volatile struct gdb_exception except;
> +
> + TRY_CATCH (except, RETURN_MASK_ERROR)
> + {
> + result = parse_linespec (parser, get_linespec_location (location));
> + }
> +
> + if (except.reason < 0)
> + throw_exception (except);
> + }
> + break;
> +
> + default:
> + gdb_assert_not_reached ("unhandled event location type");
> + }
> +
> + return result;
> +}
> +
> /* See linespec.h. */
>
> void
> -decode_line_full (char **argptr, int flags,
> +decode_line_full (const struct event_location *location, int flags,
> struct symtab *default_symtab,
> int default_line, struct linespec_result *canonical,
> const char *select_mode,
> @@ -2488,7 +2529,6 @@ decode_line_full (char **argptr, int flags,
> VEC (const_char_ptr) *filters = NULL;
> linespec_parser parser;
> struct linespec_state *state;
> - const char *copy, *orig;
>
> gdb_assert (canonical != NULL);
> /* The filter only makes sense for 'all'. */
> @@ -2504,13 +2544,10 @@ decode_line_full (char **argptr, int flags,
> cleanups = make_cleanup (linespec_parser_delete, &parser);
> save_current_program_space ();
>
> - orig = copy = *argptr;
> - result = parse_linespec (&parser, ©);
> - *argptr += copy - orig;
> + result = event_location_to_sals (&parser, location);
> state = PARSER_STATE (&parser);
>
> gdb_assert (result.nelts == 1 || canonical->pre_expanded);
> - gdb_assert (canonical->addr_string != NULL);
> canonical->pre_expanded = 1;
>
> /* Arrange for allocated canonical names to be freed. */
> @@ -2554,23 +2591,20 @@ decode_line_full (char **argptr, int flags,
> /* See linespec.h. */
>
> struct symtabs_and_lines
> -decode_line_1 (char **argptr, int flags,
> +decode_line_1 (const struct event_location *location, int flags,
> struct symtab *default_symtab,
> int default_line)
> {
> struct symtabs_and_lines result;
> linespec_parser parser;
> struct cleanup *cleanups;
> - const char *copy, *orig;
>
> linespec_parser_new (&parser, flags, current_language, default_symtab,
> default_line, NULL);
> cleanups = make_cleanup (linespec_parser_delete, &parser);
> save_current_program_space ();
>
> - orig = copy = *argptr;
> - result = parse_linespec (&parser, ©);
> - *argptr += copy - orig;
> + result = event_location_to_sals (&parser, location);
>
> do_cleanups (cleanups);
> return result;
> @@ -2583,6 +2617,8 @@ decode_line_with_current_source (char *string, int flags)
> {
> struct symtabs_and_lines sals;
> struct symtab_and_line cursal;
> + struct event_location *location;
> + struct cleanup *cleanup;
>
> if (string == 0)
> error (_("Empty line specification."));
> @@ -2591,11 +2627,15 @@ decode_line_with_current_source (char *string, int flags)
> and get a default source symtab+line or it will recursively call us! */
> cursal = get_current_source_symtab_and_line ();
>
> - sals = decode_line_1 (&string, flags,
> + location = string_to_event_location (&string, current_language);
> + cleanup = make_cleanup_delete_event_location (location);
> + sals = decode_line_1 (location, flags,
> cursal.symtab, cursal.line);
>
> if (*string)
> error (_("Junk at end of line specification: %s"), string);
> +
> + do_cleanups (cleanup);
> return sals;
> }
>
> @@ -2605,19 +2645,25 @@ struct symtabs_and_lines
> decode_line_with_last_displayed (char *string, int flags)
> {
> struct symtabs_and_lines sals;
> + struct event_location *location;
> + struct cleanup *cleanup;
>
> if (string == 0)
> error (_("Empty line specification."));
>
> + location = string_to_event_location (&string, current_language);
> + cleanup = make_cleanup_delete_event_location (location);
> if (last_displayed_sal_is_valid ())
> - sals = decode_line_1 (&string, flags,
> + sals = decode_line_1 (location, flags,
> get_last_displayed_symtab (),
> get_last_displayed_line ());
> else
> - sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0);
> + sals = decode_line_1 (location, flags, (struct symtab *) NULL, 0);
>
> if (*string)
> error (_("Junk at end of line specification: %s"), string);
> +
> + do_cleanups (cleanup);
> return sals;
> }
>
> @@ -2670,7 +2716,7 @@ linespec_expression_to_pc (const char **exp_ptr)
> the existing C++ code to let the user choose one. */
>
> static struct symtabs_and_lines
> -decode_objc (struct linespec_state *self, linespec_p ls, const char **argptr)
> +decode_objc (struct linespec_state *self, linespec_p ls, const char *arg)
> {
> struct collect_info info;
> VEC (const_char_ptr) *symbol_names = NULL;
> @@ -2688,7 +2734,7 @@ decode_objc (struct linespec_state *self, linespec_p ls, const char **argptr)
> values.nelts = 0;
> values.sals = NULL;
>
> - new_argptr = find_imps (*argptr, &symbol_names);
> + new_argptr = find_imps (arg, &symbol_names);
> if (VEC_empty (const_char_ptr, symbol_names))
> {
> do_cleanups (cleanup);
> @@ -2702,9 +2748,9 @@ decode_objc (struct linespec_state *self, linespec_p ls, const char **argptr)
> {
> char *saved_arg;
>
> - saved_arg = alloca (new_argptr - *argptr + 1);
> - memcpy (saved_arg, *argptr, new_argptr - *argptr);
> - saved_arg[new_argptr - *argptr] = '\0';
> + saved_arg = alloca (new_argptr - arg + 1);
> + memcpy (saved_arg, arg, new_argptr - arg);
> + saved_arg[new_argptr - arg] = '\0';
>
> ls->function_name = xstrdup (saved_arg);
> ls->function_symbols = info.result.symbols;
> @@ -2713,17 +2759,23 @@ decode_objc (struct linespec_state *self, linespec_p ls, const char **argptr)
>
> if (self->canonical)
> {
> + char *str;
> +
> self->canonical->pre_expanded = 1;
> +
> if (ls->source_filename)
> - self->canonical->addr_string
> - = xstrprintf ("%s:%s", ls->source_filename, saved_arg);
> + {
> + str = xstrprintf ("%s:%s",
> + ls->source_filename, saved_arg);
> + }
> else
> - self->canonical->addr_string = xstrdup (saved_arg);
> + str = xstrdup (saved_arg);
> +
> + make_cleanup (xfree, str);
> + self->canonical->location = new_linespec_location (&str);
> }
> }
>
> - *argptr = new_argptr;
> -
> do_cleanups (cleanup);
>
> return values;
> @@ -3800,7 +3852,7 @@ destroy_linespec_result (struct linespec_result *ls)
> int i;
> struct linespec_sals *lsal;
>
> - xfree (ls->addr_string);
> + delete_event_location (ls->location);
> for (i = 0; VEC_iterate (linespec_sals, ls->sals, i, lsal); ++i)
> {
> xfree (lsal->canonical);
> diff --git a/gdb/linespec.h b/gdb/linespec.h
> index 728b1bd..5f5bc71 100644
> --- a/gdb/linespec.h
> +++ b/gdb/linespec.h
> @@ -39,7 +39,7 @@ enum decode_line_flags
>
> struct linespec_sals
> {
> - /* This is the linespec corresponding to the sals contained in this
> + /* This is the location corresponding to the sals contained in this
> object. It can be passed as the FILTER argument to future calls
> to decode_line_full. This is freed by
> destroy_linespec_result. */
> @@ -71,9 +71,9 @@ struct linespec_result
> object. */
> int pre_expanded;
>
> - /* If PRE_EXPANDED is non-zero, this is set to the linespec entered
> + /* If PRE_EXPANDED is non-zero, this is set to the location entered
> by the user. This will be freed by destroy_linespec_result. */
> - char *addr_string;
> + struct event_location *location;
>
> /* The sals. The vector will be freed by
> destroy_linespec_result. */
> @@ -96,10 +96,10 @@ extern struct cleanup *
> /* Decode a linespec using the provided default symtab and line. */
>
> extern struct symtabs_and_lines
> - decode_line_1 (char **argptr, int flags,
> + decode_line_1 (const struct event_location *location, int flags,
> struct symtab *default_symtab, int default_line);
>
> -/* Parse *ARGPTR as a linespec and return results. This is the "full"
> +/* Parse LOCATION and return results. This is the "full"
> interface to this module, which handles multiple results
> properly.
>
> @@ -135,7 +135,7 @@ extern struct symtabs_and_lines
> strcmp sense) to FILTER will be returned; all others will be
> filtered out. */
>
> -extern void decode_line_full (char **argptr, int flags,
> +extern void decode_line_full (const struct event_location *location, int flags,
> struct symtab *default_symtab, int default_line,
> struct linespec_result *canonical,
> const char *select_mode,
> diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c
> index 186f807..c8c988d 100644
> --- a/gdb/mi/mi-cmd-break.c
> +++ b/gdb/mi/mi-cmd-break.c
> @@ -28,6 +28,9 @@
> #include "observer.h"
> #include "mi-main.h"
> #include "mi-cmd-break.h"
> +#include "language.h"
> +#include "location.h"
> +#include "linespec.h"
> #include "gdb_obstack.h"
> #include <ctype.h>
>
> @@ -177,6 +180,7 @@ mi_cmd_break_insert_1 (int dprintf, char *command, char **argv, int argc)
> int tracepoint = 0;
> struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
> enum bptype type_wanted;
> + struct event_location *location;
> struct breakpoint_ops *ops;
> char *extra_string = NULL;
>
> @@ -287,7 +291,13 @@ mi_cmd_break_insert_1 (int dprintf, char *command, char **argv, int argc)
> ops = &bkpt_breakpoint_ops;
> }
>
> - create_breakpoint (get_current_arch (), address, condition, thread,
> + location = string_to_event_location (&address, current_language);
> + make_cleanup_delete_event_location (location);
> +
> + if (*address)
> + error (_("Garbage '%s' at end of location"), address);
> +
> + create_breakpoint (get_current_arch (), location, condition, thread,
> extra_string,
> 0 /* condition and thread are valid. */,
> temp_p, type_wanted,
> diff --git a/gdb/probe.c b/gdb/probe.c
> index 56b5fc1..61236ee 100644
> --- a/gdb/probe.c
> +++ b/gdb/probe.c
> @@ -30,6 +30,8 @@
> #include "gdb_regex.h"
> #include "frame.h"
> #include "arch-utils.h"
> +#include "location.h"
> +
> #include <ctype.h>
>
> typedef struct bound_probe bound_probe_s;
> @@ -40,23 +42,24 @@ DEF_VEC_O (bound_probe_s);
> /* See definition in probe.h. */
>
> struct symtabs_and_lines
> -parse_probes (char **argptr, struct linespec_result *canonical)
> +parse_probes (const struct event_location *location,
> + struct linespec_result *canonical)
> {
> - char *arg_start, *arg_end, *arg;
> + char *arg_end, *arg;
> char *objfile_namestr = NULL, *provider = NULL, *name, *p;
> struct cleanup *cleanup;
> struct symtabs_and_lines result;
> struct objfile *objfile;
> struct program_space *pspace;
> const struct probe_ops *probe_ops;
> - const char *cs;
> + const char *arg_start, *cs;
>
> result.sals = NULL;
> result.nelts = 0;
>
> - arg_start = *argptr;
> + arg_start = get_linespec_location (location);
>
> - cs = *argptr;
> + cs = arg_start;
> probe_ops = probe_linespec_to_ops (&cs);
> if (probe_ops == NULL)
> error (_("'%s' is not a probe linespec"), arg_start);
> @@ -167,12 +170,15 @@ parse_probes (char **argptr, struct linespec_result *canonical)
>
> if (canonical)
> {
> + char *canon;
> +
> + canon = savestring (arg_start, arg_end - arg_start);
> + make_cleanup (xfree, canon);
> canonical->special_display = 1;
> canonical->pre_expanded = 1;
> - canonical->addr_string = savestring (*argptr, arg_end - *argptr);
> + canonical->location = new_linespec_location (&canon);
> }
>
> - *argptr = arg_end;
> do_cleanups (cleanup);
>
> return result;
> diff --git a/gdb/probe.h b/gdb/probe.h
> index 1dd582d..33c6d1d 100644
> --- a/gdb/probe.h
> +++ b/gdb/probe.h
> @@ -20,6 +20,8 @@
> #if !defined (PROBE_H)
> #define PROBE_H 1
>
> +struct event_location;
> +
> #include "gdb_vecs.h"
>
> /* Definition of a vector of probes. */
> @@ -201,9 +203,9 @@ struct bound_probe
> };
>
> /* A helper for linespec that decodes a probe specification. It returns a
> - symtabs_and_lines object and updates *ARGPTR or throws an error. */
> + symtabs_and_lines object and updates LOC or throws an error. */
>
> -extern struct symtabs_and_lines parse_probes (char **argptr,
> +extern struct symtabs_and_lines parse_probes (const struct event_location *loc,
> struct linespec_result *canon);
>
> /* Helper function to register the proper probe_ops to a newly created probe.
> diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
> index 7807e4e..ecd55e4 100644
> --- a/gdb/python/py-breakpoint.c
> +++ b/gdb/python/py-breakpoint.c
> @@ -30,6 +30,7 @@
> #include "ada-lang.h"
> #include "arch-utils.h"
> #include "language.h"
> +#include "location.h"
>
> /* Number of live breakpoints. */
> static int bppy_live;
> @@ -368,7 +369,7 @@ bppy_set_hit_count (PyObject *self, PyObject *newvalue, void *closure)
> static PyObject *
> bppy_get_location (PyObject *self, void *closure)
> {
> - char *str;
> + const char *str;
> gdbpy_breakpoint_object *obj = (gdbpy_breakpoint_object *) self;
>
> BPPY_REQUIRE_VALID (obj);
> @@ -376,8 +377,7 @@ bppy_get_location (PyObject *self, void *closure)
> if (obj->bp->type != bp_breakpoint)
> Py_RETURN_NONE;
>
> - str = obj->bp->addr_string;
> -
> + str = event_location_to_string (obj->bp->location);
> if (! str)
> str = "";
> return PyString_Decode (str, strlen (str), host_charset (), NULL);
> @@ -653,8 +653,12 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
> {
> case bp_breakpoint:
> {
> + struct event_location *location;
> +
> + location = new_linespec_location (©);
> + make_cleanup_delete_event_location (location);
> create_breakpoint (python_gdbarch,
> - copy, NULL, -1, NULL,
> + location, NULL, -1, NULL,
> 0,
> temporary_bp, bp_breakpoint,
> 0,
> diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
> index 94f19e0..bbb408a 100644
> --- a/gdb/python/py-finishbreakpoint.c
> +++ b/gdb/python/py-finishbreakpoint.c
> @@ -29,6 +29,7 @@
> #include "observer.h"
> #include "inferior.h"
> #include "block.h"
> +#include "location.h"
>
> /* Function that is called when a Python finish bp is found out of scope. */
> static char * const outofscope_func = "out_of_scope";
> @@ -167,7 +168,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
> int internal_bp = 0;
> CORE_ADDR finish_pc, pc;
> volatile struct gdb_exception except;
> - char *addr_str, small_buf[100];
> + char small_buf[100], *p;
> struct symbol *function;
>
> if (!PyArg_ParseTupleAndKeywords (args, kwargs, "|OO", keywords,
> @@ -286,13 +287,17 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
>
> TRY_CATCH (except, RETURN_MASK_ALL)
> {
> + struct event_location *location;
> + struct cleanup *back_to;
> +
> /* Set a breakpoint on the return address. */
> finish_pc = get_frame_pc (prev_frame);
> xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (finish_pc));
> - addr_str = small_buf;
> -
> + p = small_buf;
> + location = new_linespec_location (&p);
> + back_to = make_cleanup_delete_event_location (location);
> create_breakpoint (python_gdbarch,
> - addr_str, NULL, thread, NULL,
> + location, NULL, thread, NULL,
> 0,
> 1 /*temp_flag*/,
> bp_breakpoint,
> @@ -300,6 +305,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
> AUTO_BOOLEAN_TRUE,
> &bkpt_breakpoint_ops,
> 0, 1, internal_bp, 0);
> + do_cleanups (back_to);
> }
> GDB_PY_SET_HANDLE_EXCEPTION (except);
>
> diff --git a/gdb/python/python.c b/gdb/python/python.c
> index 344d8d2..b34d036 100644
> --- a/gdb/python/python.c
> +++ b/gdb/python/python.c
> @@ -34,6 +34,7 @@
> #include "extension-priv.h"
> #include "cli/cli-utils.h"
> #include <ctype.h>
> +#include "location.h"
>
> /* Declared constants and enum for python stack printing. */
> static const char python_excp_none[] = "none";
> @@ -713,13 +714,13 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
> struct symtabs_and_lines sals = { NULL, 0 }; /* Initialize to
> appease gcc. */
> struct symtab_and_line sal;
> - const char *arg = NULL;
> - char *copy_to_free = NULL, *copy = NULL;
> + char *arg = NULL;
> struct cleanup *cleanups;
> PyObject *result = NULL;
> PyObject *return_result = NULL;
> PyObject *unparsed = NULL;
> volatile struct gdb_exception except;
> + struct event_location *location;
>
> if (! PyArg_ParseTuple (args, "|s", &arg))
> return NULL;
> @@ -727,14 +728,16 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
> cleanups = make_cleanup (null_cleanup, NULL);
>
> sals.sals = NULL;
> + if (arg != NULL)
> + {
> + location = new_linespec_location (&arg);
> + make_cleanup_delete_event_location (location);
> + }
> +
> TRY_CATCH (except, RETURN_MASK_ALL)
> {
> if (arg)
> - {
> - copy = xstrdup (arg);
> - copy_to_free = copy;
> - sals = decode_line_1 (©, 0, 0, 0);
> - }
> + sals = decode_line_1 (location, 0, 0, 0);
> else
> {
> set_default_source_symtab_and_line ();
> @@ -745,10 +748,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
> }
>
> if (sals.sals != NULL && sals.sals != &sal)
> - {
> - make_cleanup (xfree, copy_to_free);
> - make_cleanup (xfree, sals.sals);
> - }
> + make_cleanup (xfree, sals.sals);
>
> if (except.reason < 0)
> {
> @@ -792,9 +792,9 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
> goto error;
> }
>
> - if (copy && strlen (copy) > 0)
> + if (arg != NULL && strlen (arg) > 0)
> {
> - unparsed = PyString_FromString (copy);
> + unparsed = PyString_FromString (arg);
> if (unparsed == NULL)
> {
> Py_DECREF (result);
> diff --git a/gdb/remote.c b/gdb/remote.c
> index dbfc10b..329c300 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -44,6 +44,7 @@
> #include "gdb_bfd.h"
> #include "filestuff.h"
> #include "rsp-low.h"
> +#include "location.h"
>
> #include <sys/time.h>
>
> @@ -10672,13 +10673,12 @@ remote_download_tracepoint (struct target_ops *self, struct bp_location *loc)
>
> if (packet_support (PACKET_TracepointSource) == PACKET_ENABLE)
> {
> - if (b->addr_string)
> + if (b->location != NULL)
> {
> strcpy (buf, "QTDPsrc:");
> - encode_source_string (b->number, loc->address,
> - "at", b->addr_string, buf + strlen (buf),
> - 2048 - strlen (buf));
> -
> + encode_source_string (b->number, loc->address, "at",
> + event_location_to_string (b->location),
> + buf + strlen (buf), 2048 - strlen (buf));
> putpkt (buf);
> remote_get_noisy_reply (&target_buf, &target_buf_size);
> if (strcmp (target_buf, "OK"))
> diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c
> index 36ad312..86af2ae 100644
> --- a/gdb/spu-tdep.c
> +++ b/gdb/spu-tdep.c
> @@ -45,7 +45,7 @@
> #include "dwarf2-frame.h"
> #include "ax.h"
> #include "spu-tdep.h"
> -
> +#include "location.h"
>
> /* The list of available "set spu " and "show spu " commands. */
> static struct cmd_list_element *setspucmdlist = NULL;
> @@ -1955,7 +1955,9 @@ spu_catch_start (struct objfile *objfile)
> struct bound_minimal_symbol minsym;
> struct compunit_symtab *cust;
> CORE_ADDR pc;
> - char buf[32];
> + struct event_location *location;
> + struct cleanup *back_to;
> + char *p;
>
> /* Do this only if requested by "set spu stop-on-load on". */
> if (!spu_stop_on_load_p)
> @@ -1999,8 +2001,10 @@ spu_catch_start (struct objfile *objfile)
>
> /* Use a numerical address for the set_breakpoint command to avoid having
> the breakpoint re-set incorrectly. */
> - xsnprintf (buf, sizeof buf, "*%s", core_addr_to_string (pc));
> - create_breakpoint (get_objfile_arch (objfile), buf /* arg */,
> + p = ASTRDUP (core_addr_to_string (pc));
====
The leading '*' got dropped.
I can imagine this is just temporary anyway, as a later patch
(address locations) redoes this again.
I'm ok with leaving it as is, but I'd be remiss if I didn't
point it out.
> + location = new_linespec_location (&p);
> + back_to = make_cleanup_delete_event_location (location);
> + create_breakpoint (get_objfile_arch (objfile), location,
> NULL /* cond_string */, -1 /* thread */,
> NULL /* extra_string */,
> 0 /* parse_condition_and_thread */, 1 /* tempflag */,
> @@ -2009,6 +2013,7 @@ spu_catch_start (struct objfile *objfile)
> AUTO_BOOLEAN_FALSE /* pending_break_support */,
> &bkpt_breakpoint_ops /* ops */, 0 /* from_tty */,
> 1 /* enabled */, 0 /* internal */, 0);
> + do_cleanups (back_to);
> }
>
>
> diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
> index 0774f5e..a4167ae 100644
> --- a/gdb/tracepoint.c
> +++ b/gdb/tracepoint.c
> @@ -55,6 +55,7 @@
> #include "filestuff.h"
> #include "rsp-low.h"
> #include "tracefile.h"
> +#include "location.h"
>
> /* readline include files */
> #include "readline/readline.h"
> @@ -2712,14 +2713,22 @@ scope_info (char *args, int from_tty)
> int j, count = 0;
> struct gdbarch *gdbarch;
> int regno;
> + struct event_location *location;
> + struct cleanup *back_to;
>
> if (args == 0 || *args == 0)
> error (_("requires an argument (function, "
> "line or *addr) to define a scope"));
>
> - sals = decode_line_1 (&args, DECODE_LINE_FUNFIRSTLINE, NULL, 0);
> + location = string_to_event_location (&args, current_language);
> + back_to = make_cleanup_delete_event_location (location);
> + sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, 0);
> if (sals.nelts == 0)
> - return; /* Presumably decode_line_1 has already warned. */
> + {
> + /* Presumably decode_line_1 has already warned. */
> + do_cleanups (back_to);
> + return;
> + }
>
> /* Resolve line numbers to PC. */
> resolve_sal_pc (&sals.sals[0]);
> @@ -2856,6 +2865,7 @@ scope_info (char *args, int from_tty)
> if (count <= 0)
> printf_filtered ("Scope for %s contains no locals or arguments.\n",
> save_args);
> + do_cleanups (back_to);
> }
>
> /* Helper for trace_dump_command. Dump the action list starting at
> @@ -3078,7 +3088,7 @@ trace_dump_command (char *args, int from_tty)
>
> extern int
> encode_source_string (int tpnum, ULONGEST addr,
> - char *srctype, char *src, char *buf, int buf_size)
> + char *srctype, const char *src, char *buf, int buf_size)
> {
> if (80 + strlen (srctype) > buf_size)
> error (_("Buffer too small for source encoding"));
> diff --git a/gdb/tracepoint.h b/gdb/tracepoint.h
> index f34be15..549cf61 100644
> --- a/gdb/tracepoint.h
> +++ b/gdb/tracepoint.h
> @@ -298,7 +298,7 @@ extern struct trace_state_variable *
> extern struct trace_state_variable *create_trace_state_variable (const char *name);
>
> extern int encode_source_string (int num, ULONGEST addr,
> - char *srctype, char *src,
> + char *srctype, const char *src,
> char *buf, int buf_size);
>
> extern void parse_trace_status (char *line, struct trace_status *ts);