public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/7] location -> location spec
@ 2022-05-27 18:02 Pedro Alves
  2022-05-27 18:02 ` [PATCH 1/7] event_location -> location_spec Pedro Alves
                   ` (7 more replies)
  0 siblings, 8 replies; 14+ messages in thread
From: Pedro Alves @ 2022-05-27 18:02 UTC (permalink / raw)
  To: gdb-patches

Currently, GDB internally uses the term "location" for both the
location specification the user had input, and for actual resolved
locations, like the breakpoint locations, or the result of decoding a
location spec to SaLs.  This is expecially confusing in the
breakpoints module.

For the location spec, we currently have struct "event_location", and
even the "event" part is misnamed.

This series everything related to location specifications from
"location" to "location spec".  event_location is renamed to
location_spec.  And then cleans up location_spec and its subclasses.

Tested on x86_64 GNU/Linux.

Pedro Alves (7):
  event_location -> location_spec
  Eliminate the two-level data structures behind location_specs
  Eliminate copy_location_spec
  Convert location_spec_empty_p to a method
  Convert location_spec_type to a method
  Convert location_spec_to_string to a method
  Convert set_location_spec_string to a method

 gdb/ada-lang.c                   |   4 +-
 gdb/ax-gdb.c                     |   6 +-
 gdb/break-catch-throw.c          |  17 +-
 gdb/breakpoint.c                 | 367 +++++++++--------
 gdb/breakpoint.h                 |  62 +--
 gdb/cli/cli-cmds.c               |  32 +-
 gdb/completer.c                  |  42 +-
 gdb/elfread.c                    |   3 +-
 gdb/guile/scm-breakpoint.c       |  21 +-
 gdb/linespec.c                   | 157 ++++----
 gdb/linespec.h                   |  12 +-
 gdb/location.c                   | 662 ++++++++++++-------------------
 gdb/location.h                   | 359 ++++++++++-------
 gdb/mi/mi-cmd-break.c            |  35 +-
 gdb/probe.c                      |   8 +-
 gdb/probe.h                      |   4 +-
 gdb/python/py-breakpoint.c       |  39 +-
 gdb/python/py-finishbreakpoint.c |   6 +-
 gdb/python/python.c              |  10 +-
 gdb/remote.c                     |   6 +-
 gdb/tracepoint.c                 |   6 +-
 21 files changed, 877 insertions(+), 981 deletions(-)


base-commit: 509e6230915a050d510a36ca9482193c76a6a216
-- 
2.36.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/7] event_location -> location_spec
  2022-05-27 18:02 [PATCH 0/7] location -> location spec Pedro Alves
@ 2022-05-27 18:02 ` Pedro Alves
  2022-05-28 10:08   ` Philippe Waroquiers
  2022-05-27 18:02 ` [PATCH 2/7] Eliminate the two-level data structures behind location_specs Pedro Alves
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 14+ messages in thread
From: Pedro Alves @ 2022-05-27 18:02 UTC (permalink / raw)
  To: gdb-patches

Currently, GDB internally uses the term "location" for both the
location specification the user input (linespec, explicit location, or
an address location), and for actual resolved locations, like the
breakpoint locations, or the result of decoding a location spec to
SaLs.  This is expecially confusing in the breakpoints module, as
struct breakpoint has these two fields:

  breakpoint::location;
  breakpoint::loc;

"locations" is the location spec, and "loc" is the resolved locations.

And then, we have a method called "locations()", which returns the
resolved locations as range...

The location spec type is presently called event_location:

  /* Location we used to set the breakpoint.  */
  event_location_up location;

and it is described like this:

  /* The base class for all an event locations used to set a stop event
     in the inferior.  */

  struct event_location
  {

and even that is incorrect...  Location specs are used for finding
actual locations in the program in scenarios that have nothing to with
with stop events.  E.g., "list" works with linespecs.

To clean all this confusion up, this patch renames "event_location" to
"location_spec" throughout, and then all the variables that hold a
location spec, they are renamed to include "spec" in their name, like
e.g., "location" -> "locspec".  Similarly, functions that work with
location specs, and currently have just "location" in their name are
renamed to include "spec" in their name too.

Change-Id: I5814124798aa2b2003e79496e78f95c74e5eddca
---
 gdb/ada-lang.c                   |   4 +-
 gdb/ax-gdb.c                     |   6 +-
 gdb/break-catch-throw.c          |  10 +-
 gdb/breakpoint.c                 | 338 ++++++++++++++++---------------
 gdb/breakpoint.h                 |  62 +++---
 gdb/cli/cli-cmds.c               |  32 +--
 gdb/completer.c                  |  40 ++--
 gdb/elfread.c                    |   4 +-
 gdb/guile/scm-breakpoint.c       |  22 +-
 gdb/linespec.c                   |  72 +++----
 gdb/linespec.h                   |  12 +-
 gdb/location.c                   | 329 +++++++++++++++---------------
 gdb/location.h                   | 183 +++++++++--------
 gdb/mi/mi-cmd-break.c            |  12 +-
 gdb/probe.c                      |   8 +-
 gdb/probe.h                      |   4 +-
 gdb/python/py-breakpoint.c       |  20 +-
 gdb/python/py-finishbreakpoint.c |   6 +-
 gdb/python/python.c              |  10 +-
 gdb/remote.c                     |   6 +-
 gdb/tracepoint.c                 |   6 +-
 21 files changed, 600 insertions(+), 586 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 6ab01fd27d4..93e0c67613f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12144,8 +12144,8 @@ struct ada_catchpoint : public code_breakpoint
 
     enable_state = enabled ? bp_enabled : bp_disabled;
     disposition = tempflag ? disp_del : disp_donttouch;
-    location = string_to_event_location (&addr_string_,
-					 language_def (language_ada));
+    locspec = string_to_location_spec (&addr_string_,
+				       language_def (language_ada));
     language = language_ada;
   }
 
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index f8ea8adc626..1fccfde559e 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -2526,9 +2526,9 @@ maint_agent_command_1 (const char *exp, int eval)
     {
       struct linespec_result canonical;
 
-      event_location_up location
-	= new_linespec_location (&exp, symbol_name_match_type::WILD);
-      decode_line_full (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
+      location_spec_up locspec
+	= new_linespec_location_spec (&exp, symbol_name_match_type::WILD);
+      decode_line_full (locspec.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
 			NULL, 0, &canonical,
 			NULL, NULL);
       exp = skip_spaces (exp);
diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index 66cf80be1c5..3ef4b972d4f 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -215,9 +215,9 @@ exception_catchpoint::re_set ()
   /* We first try to use the probe interface.  */
   try
     {
-      event_location_up location
-	= new_probe_location (exception_functions[kind].probe);
-      sals = parse_probes (location.get (), filter_pspace, NULL);
+      location_spec_up locspec
+	= new_probe_location_spec (exception_functions[kind].probe);
+      sals = parse_probes (locspec.get (), filter_pspace, NULL);
     }
   catch (const gdb_exception_error &e)
     {
@@ -230,8 +230,8 @@ exception_catchpoint::re_set ()
 	  initialize_explicit_location (&explicit_loc);
 	  explicit_loc.function_name
 	    = ASTRDUP (exception_functions[kind].function);
-	  event_location_up location = new_explicit_location (&explicit_loc);
-	  sals = this->decode_location (location.get (), filter_pspace);
+	  location_spec_up locspec = new_explicit_location_spec (&explicit_loc);
+	  sals = this->decode_location_spec (locspec.get (), filter_pspace);
 	}
       catch (const gdb_exception_error &ex)
 	{
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index ed932a19ed7..2c86f275286 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -90,8 +90,8 @@ static void map_breakpoint_numbers (const char *,
 static void breakpoint_re_set_default (code_breakpoint *);
 
 static void
-  create_sals_from_location_default (struct event_location *location,
-				     struct linespec_result *canonical);
+  create_sals_from_location_spec_default (location_spec *locspec,
+					  linespec_result *canonical);
 
 static void create_breakpoints_sal (struct gdbarch *,
 				    struct linespec_result *,
@@ -102,8 +102,8 @@ static void create_breakpoints_sal (struct gdbarch *,
 				    int,
 				    int, int, int, unsigned);
 
-static std::vector<symtab_and_line> decode_location_default
-  (struct breakpoint *b, struct event_location *location,
+static std::vector<symtab_and_line> decode_location_spec_default
+  (struct breakpoint *b, struct location_spec *locspec,
    struct program_space *search_pspace);
 
 static int can_use_hardware_watchpoint
@@ -159,9 +159,9 @@ static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp,
 
 static void decref_bp_location (struct bp_location **loc);
 
-static std::vector<symtab_and_line> bkpt_probe_decode_location
+static std::vector<symtab_and_line> bkpt_probe_decode_location_spec
      (struct breakpoint *b,
-      struct event_location *location,
+      location_spec *locspec,
       struct program_space *search_pspace);
 
 static bool bl_address_is_meaningful (bp_location *loc);
@@ -218,30 +218,30 @@ static bool is_masked_watchpoint (const struct breakpoint *b);
 
 static int strace_marker_p (struct breakpoint *b);
 
-static void bkpt_probe_create_sals_from_location
-     (struct event_location *location,
+static void bkpt_probe_create_sals_from_location_spec
+     (location_spec *locspec,
       struct linespec_result *canonical);
-static void tracepoint_probe_create_sals_from_location
-     (struct event_location *location,
+static void tracepoint_probe_create_sals_from_location_spec
+     (location_spec *locspec,
       struct linespec_result *canonical);
 
 const struct breakpoint_ops code_breakpoint_ops =
 {
-  create_sals_from_location_default,
+  create_sals_from_location_spec_default,
   create_breakpoints_sal,
 };
 
 /* Breakpoints set on probes.  */
 static const struct breakpoint_ops bkpt_probe_breakpoint_ops =
 {
-  bkpt_probe_create_sals_from_location,
+  bkpt_probe_create_sals_from_location_spec,
   create_breakpoints_sal,
 };
 
 /* Tracepoints set on probes.  */
 static const struct breakpoint_ops tracepoint_probe_breakpoint_ops =
 {
-  tracepoint_probe_create_sals_from_location,
+  tracepoint_probe_create_sals_from_location_spec,
   create_breakpoints_sal,
 };
 
@@ -351,8 +351,8 @@ struct ranged_breakpoint : public ordinary_breakpoint
   explicit ranged_breakpoint (struct gdbarch *gdbarch,
 			      const symtab_and_line &sal_start,
 			      int length,
-			      event_location_up start_location,
-			      event_location_up end_location)
+			      location_spec_up start_locspec,
+			      location_spec_up end_locspec)
     : ordinary_breakpoint (gdbarch, bp_hardware_breakpoint)
   {
     bp_location *bl = add_location (sal_start);
@@ -360,8 +360,8 @@ struct ranged_breakpoint : public ordinary_breakpoint
 
     disposition = disp_donttouch;
 
-    location = std::move (start_location);
-    location_range_end = std::move (end_location);
+    locspec = std::move (start_locspec);
+    locspec_range_end = std::move (end_locspec);
   }
 
   int breakpoint_hit (const struct bp_location *bl,
@@ -381,8 +381,8 @@ struct static_marker_tracepoint : public tracepoint
 {
   using tracepoint::tracepoint;
 
-  std::vector<symtab_and_line> decode_location
-       (struct event_location *location,
+  std::vector<symtab_and_line> decode_location_spec
+       (struct location_spec *locspec,
 	struct program_space *search_pspace) override;
 };
 
@@ -3390,7 +3390,7 @@ create_overlay_event_breakpoint (void)
 				      bp_overlay_event);
       initialize_explicit_location (&explicit_loc);
       explicit_loc.function_name = ASTRDUP (func_name);
-      b->location = new_explicit_location (&explicit_loc);
+      b->locspec = new_explicit_location_spec (&explicit_loc);
 
       if (overlay_debugging == ovly_auto)
 	{
@@ -3447,7 +3447,7 @@ create_longjmp_master_breakpoint_probe (objfile *objfile)
       b = create_internal_breakpoint (gdbarch,
 				      p->get_relocated_address (objfile),
 				      bp_longjmp_master);
-      b->location = new_probe_location ("-probe-stap libc:longjmp");
+      b->locspec = new_probe_location_spec ("-probe-stap libc:longjmp");
       b->enable_state = bp_disabled;
     }
 
@@ -3497,7 +3497,7 @@ create_longjmp_master_breakpoint_names (objfile *objfile)
       b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master);
       initialize_explicit_location (&explicit_loc);
       explicit_loc.function_name = ASTRDUP (func_name);
-      b->location = new_explicit_location (&explicit_loc);
+      b->locspec = new_explicit_location_spec (&explicit_loc);
       b->enable_state = bp_disabled;
       installed_bp++;
     }
@@ -3580,7 +3580,7 @@ create_std_terminate_master_breakpoint (void)
 					  bp_std_terminate_master);
 	  initialize_explicit_location (&explicit_loc);
 	  explicit_loc.function_name = ASTRDUP (func_name);
-	  b->location = new_explicit_location (&explicit_loc);
+	  b->locspec = new_explicit_location_spec (&explicit_loc);
 	  b->enable_state = bp_disabled;
 	}
     }
@@ -3630,7 +3630,7 @@ create_exception_master_breakpoint_probe (objfile *objfile)
       b = create_internal_breakpoint (gdbarch,
 				      p->get_relocated_address (objfile),
 				      bp_exception_master);
-      b->location = new_probe_location ("-probe-stap libgcc:unwind");
+      b->locspec = new_probe_location_spec ("-probe-stap libgcc:unwind");
       b->enable_state = bp_disabled;
     }
 
@@ -3677,7 +3677,7 @@ create_exception_master_breakpoint_hook (objfile *objfile)
   b = create_internal_breakpoint (gdbarch, addr, bp_exception_master);
   initialize_explicit_location (&explicit_loc);
   explicit_loc.function_name = ASTRDUP (func_name);
-  b->location = new_explicit_location (&explicit_loc);
+  b->locspec = new_explicit_location_spec (&explicit_loc);
   b->enable_state = bp_disabled;
 
   return true;
@@ -3709,9 +3709,10 @@ create_exception_master_breakpoint (void)
 /* Does B have a location spec?  */
 
 static int
-breakpoint_event_location_empty_p (const struct breakpoint *b)
+breakpoint_location_spec_empty_p (const struct breakpoint *b)
 {
-  return b->location != NULL && event_location_empty_p (b->location.get ());
+  return (b->locspec != nullptr
+	  && location_spec_empty_p (b->locspec.get ()));
 }
 
 void
@@ -3825,7 +3826,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 (breakpoint_event_location_empty_p (b))
+      if (breakpoint_location_spec_empty_p (b))
 	{
 	  delete_breakpoint (b);
 	  continue;
@@ -6019,7 +6020,8 @@ print_breakpoint_location (const breakpoint *b,
     set_current_program_space (loc->pspace);
 
   if (b->display_canonical)
-    uiout->field_string ("what", event_location_to_string (b->location.get ()));
+    uiout->field_string ("what",
+			 location_spec_to_string (b->locspec.get ()));
   else if (loc && loc->symtab)
     {
       const struct symbol *sym = loc->symbol;
@@ -6054,7 +6056,7 @@ print_breakpoint_location (const breakpoint *b,
   else
     {
       uiout->field_string ("pending",
-			   event_location_to_string (b->location.get ()));
+			   location_spec_to_string (b->locspec.get ()));
       /* If extra_string is available, it could be holding a condition
 	 or dprintf arguments.  In either case, make sure it is printed,
 	 too, but only for non-MI streams.  */
@@ -6514,10 +6516,12 @@ print_one_breakpoint_location (struct breakpoint *b,
 
 	  uiout->field_string ("original-location", w->exp_string.get ());
 	}
-      else if (b->location != NULL
-	       && event_location_to_string (b->location.get ()) != NULL)
-	uiout->field_string ("original-location",
-			     event_location_to_string (b->location.get ()));
+      else if (b->locspec != nullptr)
+	{
+	  const char *str = location_spec_to_string (b->locspec.get ());
+	  if (str != nullptr)
+	    uiout->field_string ("original-location", str);
+	}
     }
 
   return result;
@@ -7534,8 +7538,8 @@ create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address)
   b = create_internal_breakpoint (gdbarch, address, bp_thread_event);
 
   b->enable_state = bp_enabled;
-  /* location has to be used or breakpoint_re_set will delete me.  */
-  b->location = new_address_location (b->loc->address, NULL, 0);
+  /* locspec has to be used or breakpoint_re_set will delete me.  */
+  b->locspec = new_address_location_spec (b->loc->address, NULL, 0);
 
   update_global_location_list_nothrow (UGLL_MAY_INSERT);
 
@@ -8243,7 +8247,7 @@ update_dprintf_commands (const char *args, int from_tty,
 code_breakpoint::code_breakpoint (struct gdbarch *gdbarch_,
 				  enum bptype type_,
 				  gdb::array_view<const symtab_and_line> sals,
-				  event_location_up &&location_,
+				  location_spec_up &&locspec_,
 				  gdb::unique_xmalloc_ptr<char> filter_,
 				  gdb::unique_xmalloc_ptr<char> cond_string_,
 				  gdb::unique_xmalloc_ptr<char> extra_string_,
@@ -8291,7 +8295,7 @@ code_breakpoint::code_breakpoint (struct gdbarch *gdbarch_,
 	{
 	  /* We already know the marker exists, otherwise, we wouldn't
 	     see a sal for it.  */
-	  const char *p = &event_location_to_string (location_.get ())[3];
+	  const char *p = &location_spec_to_string (locspec_.get ())[3];
 	  const char *endp;
 
 	  p = skip_spaces (p);
@@ -8360,17 +8364,17 @@ code_breakpoint::code_breakpoint (struct gdbarch *gdbarch_,
     }
 
   display_canonical = display_canonical_;
-  if (location_ != nullptr)
-    location = std::move (location_);
+  if (locspec_ != nullptr)
+    locspec = std::move (locspec_);
   else
-    location = new_address_location (this->loc->address, NULL, 0);
+    locspec = new_address_location_spec (this->loc->address, NULL, 0);
   filter = std::move (filter_);
 }
 
 static void
 create_breakpoint_sal (struct gdbarch *gdbarch,
 		       gdb::array_view<const symtab_and_line> sals,
-		       event_location_up &&location,
+		       location_spec_up &&locspec,
 		       gdb::unique_xmalloc_ptr<char> filter,
 		       gdb::unique_xmalloc_ptr<char> cond_string,
 		       gdb::unique_xmalloc_ptr<char> extra_string,
@@ -8384,7 +8388,7 @@ create_breakpoint_sal (struct gdbarch *gdbarch,
     = new_breakpoint_from_type (gdbarch,
 				type,
 				sals,
-				std::move (location),
+				std::move (locspec),
 				std::move (filter),
 				std::move (cond_string),
 				std::move (extra_string),
@@ -8429,14 +8433,14 @@ create_breakpoints_sal (struct gdbarch *gdbarch,
     {
       /* Note that 'location' can be NULL in the case of a plain
 	 'break', without arguments.  */
-      event_location_up location
-	= (canonical->location != NULL
-	   ? copy_event_location (canonical->location.get ()) : NULL);
+      location_spec_up locspec
+	= (canonical->locspec != NULL
+	   ? copy_location_spec (canonical->locspec.get ()) : NULL);
       gdb::unique_xmalloc_ptr<char> filter_string
 	(lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL);
 
       create_breakpoint_sal (gdbarch, lsal.sals,
-			     std::move (location),
+			     std::move (locspec),
 			     std::move (filter_string),
 			     std::move (cond_string),
 			     std::move (extra_string),
@@ -8447,23 +8451,23 @@ create_breakpoints_sal (struct gdbarch *gdbarch,
     }
 }
 
-/* Parse LOCATION which is assumed to be a SAL specification possibly
+/* Parse LOCSPEC which is assumed to be a SAL specification possibly
    followed by conditionals.  On return, SALS contains an array of SAL
-   addresses found.  LOCATION points to the end of the SAL (for
-   linespec locations).
+   addresses found.  LOCSPEC points to the end of the SAL (for
+   linespec locspecs).
 
    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 (struct event_location *location,
+parse_breakpoint_sals (location_spec *locspec,
 		       struct linespec_result *canonical)
 {
   struct symtab_and_line cursal;
 
-  if (event_location_type (location) == LINESPEC_LOCATION)
+  if (location_spec_type (locspec) == LINESPEC_LOCATION_SPEC)
     {
-      const char *spec = get_linespec_location (location)->spec_string;
+      const char *spec = get_linespec_location (locspec)->spec_string;
 
       if (spec == NULL)
 	{
@@ -8513,15 +8517,15 @@ parse_breakpoint_sals (struct event_location *location,
     {
       const char *spec = NULL;
 
-      if (event_location_type (location) == LINESPEC_LOCATION)
-	spec = get_linespec_location (location)->spec_string;
+      if (location_spec_type (locspec) == LINESPEC_LOCATION_SPEC)
+	spec = get_linespec_location (locspec)->spec_string;
 
       if (!cursal.symtab
 	  || (spec != NULL
 	      && strchr ("+-", spec[0]) != NULL
 	      && spec[1] != '['))
 	{
-	  decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
+	  decode_line_full (locspec, DECODE_LINE_FUNFIRSTLINE, NULL,
 			    get_last_displayed_symtab (),
 			    get_last_displayed_line (),
 			    canonical, NULL, NULL);
@@ -8529,7 +8533,7 @@ parse_breakpoint_sals (struct event_location *location,
 	}
     }
 
-  decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL,
+  decode_line_full (locspec, DECODE_LINE_FUNFIRSTLINE, NULL,
 		    cursal.symtab, cursal.line, canonical, NULL, NULL);
 }
 
@@ -8749,19 +8753,19 @@ decode_static_tracepoint_spec (const char **arg_p)
    according to IS_TRACEPOINT.  */
 
 static const struct breakpoint_ops *
-breakpoint_ops_for_event_location_type (enum event_location_type location_type,
-					bool is_tracepoint)
+breakpoint_ops_for_location_spec_type (enum location_spec_type locspec_type,
+				       bool is_tracepoint)
 {
   if (is_tracepoint)
     {
-      if (location_type == PROBE_LOCATION)
+      if (locspec_type == PROBE_LOCATION_SPEC)
 	return &tracepoint_probe_breakpoint_ops;
       else
 	return &code_breakpoint_ops;
     }
   else
     {
-      if (location_type == PROBE_LOCATION)
+      if (locspec_type == PROBE_LOCATION_SPEC)
 	return &bkpt_probe_breakpoint_ops;
       else
 	return &code_breakpoint_ops;
@@ -8771,12 +8775,12 @@ breakpoint_ops_for_event_location_type (enum event_location_type location_type,
 /* See breakpoint.h.  */
 
 const struct breakpoint_ops *
-breakpoint_ops_for_event_location (const struct event_location *location,
-				   bool is_tracepoint)
+breakpoint_ops_for_location_spec (const location_spec *locspec,
+				  bool is_tracepoint)
 {
-  if (location != nullptr)
-    return breakpoint_ops_for_event_location_type
-      (event_location_type (location), is_tracepoint);
+  if (locspec != nullptr)
+    return (breakpoint_ops_for_location_spec_type
+	    (location_spec_type (locspec), is_tracepoint));
   return &code_breakpoint_ops;
 }
 
@@ -8784,7 +8788,7 @@ breakpoint_ops_for_event_location (const struct event_location *location,
 
 int
 create_breakpoint (struct gdbarch *gdbarch,
-		   struct event_location *location,
+		   location_spec *locspec,
 		   const char *cond_string,
 		   int thread, const char *extra_string,
 		   bool force_condition, int parse_extra,
@@ -8808,7 +8812,7 @@ create_breakpoint (struct gdbarch *gdbarch,
 
   try
     {
-      ops->create_sals_from_location (location, &canonical);
+      ops->create_sals_from_location_spec (locspec, &canonical);
     }
   catch (const gdb_exception_error &e)
     {
@@ -8932,7 +8936,7 @@ create_breakpoint (struct gdbarch *gdbarch,
     {
       std::unique_ptr <breakpoint> b = new_breakpoint_from_type (gdbarch,
 								 type_wanted);
-      b->location = copy_event_location (location);
+      b->locspec = copy_location_spec (locspec);
 
       if (parse_extra)
 	b->cond_string = NULL;
@@ -8987,12 +8991,13 @@ break_command_1 (const char *arg, int flag, int from_tty)
 			     ? bp_hardware_breakpoint
 			     : bp_breakpoint);
 
-  event_location_up location = string_to_event_location (&arg, current_language);
-  const struct breakpoint_ops *ops = breakpoint_ops_for_event_location
-    (location.get (), false /* is_tracepoint */);
+  location_spec_up locspec = string_to_location_spec (&arg, current_language);
+  const struct breakpoint_ops *ops
+    = breakpoint_ops_for_location_spec (locspec.get (),
+					false /* is_tracepoint */);
 
   create_breakpoint (get_current_arch (),
-		     location.get (),
+		     locspec.get (),
 		     NULL, 0, arg, false, 1 /* parse arg */,
 		     tempflag, type_wanted,
 		     0 /* Ignore count */,
@@ -9091,7 +9096,7 @@ thbreak_command (const char *arg, int from_tty)
 static void
 dprintf_command (const char *arg, int from_tty)
 {
-  event_location_up location = string_to_event_location (&arg, current_language);
+  location_spec_up locspec = string_to_location_spec (&arg, current_language);
 
   /* If non-NULL, ARG should have been advanced past the location;
      the next character must be ','.  */
@@ -9107,7 +9112,7 @@ dprintf_command (const char *arg, int from_tty)
     }
 
   create_breakpoint (get_current_arch (),
-		     location.get (),
+		     locspec.get (),
 		     NULL, 0, arg, false, 1 /* parse arg */,
 		     0, bp_dprintf,
 		     0 /* Ignore count */,
@@ -9251,8 +9256,8 @@ void
 ranged_breakpoint::print_recreate (struct ui_file *fp) const
 {
   gdb_printf (fp, "break-range %s, %s",
-	      event_location_to_string (location.get ()),
-	      event_location_to_string (location_range_end.get ()));
+	      location_spec_to_string (locspec.get ()),
+	      location_spec_to_string (locspec_range_end.get ()));
   print_recreate_thread (fp);
 }
 
@@ -9312,9 +9317,9 @@ break_range_command (const char *arg, int from_tty)
     error(_("No address range specified."));
 
   arg_start = arg;
-  event_location_up start_location = string_to_event_location (&arg,
-							       current_language);
-  parse_breakpoint_sals (start_location.get (), &canonical_start);
+  location_spec_up start_locspec
+    = string_to_location_spec (&arg, current_language);
+  parse_breakpoint_sals (start_locspec.get (), &canonical_start);
 
   if (arg[0] != ',')
     error (_("Too few arguments."));
@@ -9333,18 +9338,19 @@ break_range_command (const char *arg, int from_tty)
   arg++;	/* Skip the comma.  */
   arg = skip_spaces (arg);
 
-  /* Parse the end location.  */
+  /* Parse the end location specification.  */
 
   arg_start = arg;
 
   /* We call decode_line_full directly here instead of using
-     parse_breakpoint_sals because we need to specify the start location's
-     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.  */
-  event_location_up end_location = string_to_event_location (&arg,
-							     current_language);
-  decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
+     parse_breakpoint_sals because we need to specify the start
+     location spec's 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 spec.  */
+  location_spec_up end_locspec
+    = string_to_location_spec (&arg, current_language);
+  decode_line_full (end_locspec.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
 		    sal_start.symtab, sal_start.line,
 		    &canonical_end, NULL, NULL);
 
@@ -9380,8 +9386,8 @@ break_range_command (const char *arg, int from_tty)
   std::unique_ptr<breakpoint> br
     (new ranged_breakpoint (get_current_arch (),
 			    sal_start, length,
-			    std::move (start_location),
-			    std::move (end_location)));
+			    std::move (start_locspec),
+			    std::move (end_locspec)));
 
   install_breakpoint (false, std::move (br), true);
 }
@@ -10447,14 +10453,14 @@ until_break_command (const char *arg, int from_tty, int anywhere)
   /* Set a breakpoint where the user wants it and at return from
      this function.  */
 
-  event_location_up location = string_to_event_location (&arg, current_language);
+  location_spec_up locspec = string_to_location_spec (&arg, current_language);
 
   std::vector<symtab_and_line> sals
     = (last_displayed_sal_is_valid ()
-       ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
+       ? decode_line_1 (locspec.get (), DECODE_LINE_FUNFIRSTLINE, NULL,
 			get_last_displayed_symtab (),
 			get_last_displayed_line ())
-       : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE,
+       : decode_line_1 (locspec.get (), DECODE_LINE_FUNFIRSTLINE,
 			NULL, NULL, 0));
 
   if (sals.empty ())
@@ -11360,18 +11366,18 @@ say_where (const breakpoint *b)
       if (b->extra_string == NULL)
 	{
 	  gdb_printf (_(" (%s) pending."),
-		      event_location_to_string (b->location.get ()));
+		      location_spec_to_string (b->locspec.get ()));
 	}
       else if (b->type == bp_dprintf)
 	{
 	  gdb_printf (_(" (%s,%s) pending."),
-		      event_location_to_string (b->location.get ()),
+		      location_spec_to_string (b->locspec.get ()),
 		      b->extra_string.get ());
 	}
       else
 	{
 	  gdb_printf (_(" (%s %s) pending."),
-		      event_location_to_string (b->location.get ()),
+		      location_spec_to_string (b->locspec.get ()),
 		      b->extra_string.get ());
 	}
     }
@@ -11400,7 +11406,7 @@ say_where (const breakpoint *b)
 	       different file name, and this at least reflects the
 	       real situation somewhat.  */
 	    gdb_printf (": %s.",
-			event_location_to_string (b->location.get ()));
+			location_spec_to_string (b->locspec.get ()));
 	}
 
       if (b->loc->next)
@@ -11477,8 +11483,8 @@ breakpoint::print_recreate (struct ui_file *fp) const
 }
 
 std::vector<symtab_and_line>
-breakpoint::decode_location (struct event_location *location,
-			     struct program_space *search_pspace)
+breakpoint::decode_location_spec (location_spec *locspec,
+				  program_space *search_pspace)
 {
   internal_error_pure_virtual_called ();
 }
@@ -11489,7 +11495,7 @@ void
 code_breakpoint::re_set ()
 {
   /* FIXME: is this still reachable?  */
-  if (breakpoint_event_location_empty_p (this))
+  if (breakpoint_location_spec_empty_p (this))
     {
       /* Anything without a location can't be re-set.  */
       delete_breakpoint (this);
@@ -11665,7 +11671,7 @@ ordinary_breakpoint::print_recreate (struct ui_file *fp) const
     internal_error (__FILE__, __LINE__,
 		    _("unhandled breakpoint type %d"), (int) type);
 
-  gdb_printf (fp, " %s", event_location_to_string (location.get ()));
+  gdb_printf (fp, " %s", location_spec_to_string (locspec.get ()));
 
   /* Print out extra_string if this breakpoint is pending.  It might
      contain, for example, conditions that were set by the user.  */
@@ -11676,13 +11682,13 @@ ordinary_breakpoint::print_recreate (struct ui_file *fp) const
 }
 
 std::vector<symtab_and_line>
-code_breakpoint::decode_location (struct event_location *location,
-				  struct program_space *search_pspace)
+code_breakpoint::decode_location_spec (location_spec *locspec,
+				       program_space *search_pspace)
 {
-  if (event_location_type (location) == PROBE_LOCATION)
-    return bkpt_probe_decode_location (this, location, search_pspace);
+  if (location_spec_type (locspec) == PROBE_LOCATION_SPEC)
+    return bkpt_probe_decode_location_spec (this, locspec, search_pspace);
 
-  return decode_location_default (this, location, search_pspace);
+  return decode_location_spec_default (this, locspec, search_pspace);
 }
 
 /* Virtual table for internal breakpoints.  */
@@ -11821,24 +11827,25 @@ longjmp_breakpoint::~longjmp_breakpoint ()
 }
 
 static void
-bkpt_probe_create_sals_from_location (struct event_location *location,
-				      struct linespec_result *canonical)
+bkpt_probe_create_sals_from_location_spec (location_spec *locspec,
+					   struct linespec_result *canonical)
 
 {
   struct linespec_sals lsal;
 
-  lsal.sals = parse_probes (location, NULL, canonical);
+  lsal.sals = parse_probes (locspec, NULL, canonical);
   lsal.canonical
-    = xstrdup (event_location_to_string (canonical->location.get ()));
+    = xstrdup (location_spec_to_string (canonical->locspec.get ()));
   canonical->lsals.push_back (std::move (lsal));
 }
 
 static std::vector<symtab_and_line>
-bkpt_probe_decode_location (struct breakpoint *b,
-			    struct event_location *location,
-			    struct program_space *search_pspace)
+bkpt_probe_decode_location_spec (struct breakpoint *b,
+				 location_spec *locspec,
+				 program_space *search_pspace)
 {
-  std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL);
+  std::vector<symtab_and_line> sals
+    = parse_probes (locspec, search_pspace, NULL);
   if (sals.empty ())
     error (_("probe not found"));
   return sals;
@@ -11911,7 +11918,7 @@ tracepoint::print_recreate (struct ui_file *fp) const
     internal_error (__FILE__, __LINE__,
 		    _("unhandled tracepoint type %d"), (int) type);
 
-  gdb_printf (fp, " %s", event_location_to_string (location.get ()));
+  gdb_printf (fp, " %s", location_spec_to_string (locspec.get ()));
   print_recreate_thread (fp);
 
   if (pass_count)
@@ -11921,12 +11928,12 @@ tracepoint::print_recreate (struct ui_file *fp) const
 /* Virtual table for tracepoints on static probes.  */
 
 static void
-tracepoint_probe_create_sals_from_location
-  (struct event_location *location,
+tracepoint_probe_create_sals_from_location_spec
+  (location_spec *locspec,
    struct linespec_result *canonical)
 {
   /* We use the same method for breakpoint on probes.  */
-  bkpt_probe_create_sals_from_location (location, canonical);
+  bkpt_probe_create_sals_from_location_spec (locspec, canonical);
 }
 
 void
@@ -11957,7 +11964,7 @@ void
 dprintf_breakpoint::print_recreate (struct ui_file *fp) const
 {
   gdb_printf (fp, "dprintf %s,%s",
-	      event_location_to_string (location.get ()),
+	      location_spec_to_string (locspec.get ()),
 	      extra_string.get ());
   print_recreate_thread (fp);
 }
@@ -11992,22 +11999,22 @@ dprintf_breakpoint::after_condition_true (struct bpstat *bs)
    markers (`-m').  */
 
 static void
-strace_marker_create_sals_from_location (struct event_location *location,
-					 struct linespec_result *canonical)
+strace_marker_create_sals_from_location_spec (location_spec *locspec,
+					      struct linespec_result *canonical)
 {
   struct linespec_sals lsal;
   const char *arg_start, *arg;
 
-  arg = arg_start = get_linespec_location (location)->spec_string;
+  arg = arg_start = get_linespec_location (locspec)->spec_string;
   lsal.sals = decode_static_tracepoint_spec (&arg);
 
   std::string str (arg_start, arg - arg_start);
   const char *ptr = str.c_str ();
-  canonical->location
-    = new_linespec_location (&ptr, symbol_name_match_type::FULL);
+  canonical->locspec
+    = new_linespec_location_spec (&ptr, symbol_name_match_type::FULL);
 
   lsal.canonical
-    = xstrdup (event_location_to_string (canonical->location.get ()));
+    = xstrdup (location_spec_to_string (canonical->locspec.get ()));
   canonical->lsals.push_back (std::move (lsal));
 }
 
@@ -12034,14 +12041,14 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
 
   for (size_t i = 0; i < lsal.sals.size (); i++)
     {
-      event_location_up location
-	= copy_event_location (canonical->location.get ());
+      location_spec_up locspec
+	= copy_location_spec (canonical->locspec.get ());
 
       std::unique_ptr<tracepoint> tp
 	(new tracepoint (gdbarch,
 			 type_wanted,
 			 lsal.sals[i],
-			 std::move (location),
+			 std::move (locspec),
 			 NULL,
 			 std::move (cond_string),
 			 std::move (extra_string),
@@ -12063,10 +12070,10 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
 }
 
 std::vector<symtab_and_line>
-static_marker_tracepoint::decode_location (struct event_location *location,
-					   struct program_space *search_pspace)
+static_marker_tracepoint::decode_location_spec (location_spec *locspec,
+						program_space *search_pspace)
 {
-  const char *s = get_linespec_location (location)->spec_string;
+  const char *s = get_linespec_location (locspec)->spec_string;
 
   std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s);
   if (sals.size () > static_trace_marker_id_idx)
@@ -12082,7 +12089,7 @@ static_marker_tracepoint::decode_location (struct event_location *location,
 /* Static tracepoints with marker (`-m').  */
 static struct breakpoint_ops strace_marker_breakpoint_ops =
 {
-  strace_marker_create_sals_from_location,
+  strace_marker_create_sals_from_location_spec,
   strace_marker_create_breakpoints_sal,
 };
 
@@ -12411,13 +12418,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;
 
-	  b->location.reset (NULL);
+	  b->locspec.reset (nullptr);
 	  initialize_explicit_location (&explicit_loc);
 	  explicit_loc.source_filename
 	    = ASTRDUP (symtab_to_filename_for_display (sal2.symtab));
 	  explicit_loc.line_offset.offset = b->loc->line_number;
 	  explicit_loc.line_offset.sign = LINE_OFFSET_NONE;
-	  b->location = new_explicit_location (&explicit_loc);
+	  b->locspec = new_explicit_location_spec (&explicit_loc);
 
 	  /* Might be nice to check if function changed, and warn if
 	     so.  */
@@ -12620,12 +12627,12 @@ update_breakpoint_locations (code_breakpoint *b,
     gdb::observers::breakpoint_modified.notify (b);
 }
 
-/* Find the SaL locations corresponding to the given LOCATION.
+/* Find the SaL locations corresponding to the given LOCSPEC.
    On return, FOUND will be 1 if any SaL was found, zero otherwise.  */
 
 static std::vector<symtab_and_line>
-location_to_sals (struct breakpoint *b, struct event_location *location,
-		  struct program_space *search_pspace, int *found)
+location_spec_to_sals (struct breakpoint *b, location_spec *locspec,
+		       struct program_space *search_pspace, int *found)
 {
   struct gdb_exception exception;
 
@@ -12633,7 +12640,7 @@ location_to_sals (struct breakpoint *b, struct event_location *location,
 
   try
     {
-      sals = b->decode_location (location, search_pspace);
+      sals = b->decode_location_spec (locspec, search_pspace);
     }
   catch (gdb_exception_error &e)
     {
@@ -12715,16 +12722,16 @@ breakpoint_re_set_default (code_breakpoint *b)
   std::vector<symtab_and_line> expanded, expanded_end;
 
   int found;
-  std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (),
-							filter_pspace, &found);
+  std::vector<symtab_and_line> sals
+    = location_spec_to_sals (b, b->locspec.get (), filter_pspace, &found);
   if (found)
     expanded = std::move (sals);
 
-  if (b->location_range_end != NULL)
+  if (b->locspec_range_end != nullptr)
     {
       std::vector<symtab_and_line> sals_end
-	= location_to_sals (b, b->location_range_end.get (),
-			    filter_pspace, &found);
+	= location_spec_to_sals (b, b->locspec_range_end.get (),
+				 filter_pspace, &found);
       if (found)
 	expanded_end = std::move (sals_end);
     }
@@ -12736,23 +12743,23 @@ breakpoint_re_set_default (code_breakpoint *b)
    calls parse_breakpoint_sals.  Return 1 for success, zero for failure.  */
 
 static void
-create_sals_from_location_default (struct event_location *location,
-				   struct linespec_result *canonical)
+create_sals_from_location_spec_default (location_spec *locspec,
+					struct linespec_result *canonical)
 {
-  parse_breakpoint_sals (location, canonical);
+  parse_breakpoint_sals (locspec, canonical);
 }
 
 /* Decode the line represented by S by calling decode_line_full.  This is the
    default function for the `decode_location' method of breakpoint_ops.  */
 
 static std::vector<symtab_and_line>
-decode_location_default (struct breakpoint *b,
-			 struct event_location *location,
-			 struct program_space *search_pspace)
+decode_location_spec_default (struct breakpoint *b,
+			      location_spec *locspec,
+			      program_space *search_pspace)
 {
   struct linespec_result canonical;
 
-  decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace,
+  decode_line_full (locspec, DECODE_LINE_FUNFIRSTLINE, search_pspace,
 		    NULL, 0, &canonical, multiple_symbols_all,
 		    b->filter.get ());
 
@@ -13510,13 +13517,13 @@ set_tracepoint_count (int num)
 static void
 trace_command (const char *arg, int from_tty)
 {
-  event_location_up location = string_to_event_location (&arg,
-							 current_language);
-  const struct breakpoint_ops *ops = breakpoint_ops_for_event_location
-    (location.get (), true /* is_tracepoint */);
+  location_spec_up locspec = string_to_location_spec (&arg,
+						      current_language);
+  const struct breakpoint_ops *ops = breakpoint_ops_for_location_spec
+    (locspec.get (), true /* is_tracepoint */);
 
   create_breakpoint (get_current_arch (),
-		     location.get (),
+		     locspec.get (),
 		     NULL, 0, arg, false, 1 /* parse arg */,
 		     0 /* tempflag */,
 		     bp_tracepoint /* type_wanted */,
@@ -13531,10 +13538,10 @@ trace_command (const char *arg, int from_tty)
 static void
 ftrace_command (const char *arg, int from_tty)
 {
-  event_location_up location = string_to_event_location (&arg,
-							 current_language);
+  location_spec_up locspec = string_to_location_spec (&arg,
+						      current_language);
   create_breakpoint (get_current_arch (),
-		     location.get (),
+		     locspec.get (),
 		     NULL, 0, arg, false, 1 /* parse arg */,
 		     0 /* tempflag */,
 		     bp_fast_tracepoint /* type_wanted */,
@@ -13552,7 +13559,7 @@ static void
 strace_command (const char *arg, int from_tty)
 {
   const struct breakpoint_ops *ops;
-  event_location_up location;
+  location_spec_up locspec;
   enum bptype type;
 
   /* Decide if we are dealing with a static tracepoint marker (`-m'),
@@ -13560,18 +13567,19 @@ strace_command (const char *arg, int from_tty)
   if (arg && startswith (arg, "-m") && isspace (arg[2]))
     {
       ops = &strace_marker_breakpoint_ops;
-      location = new_linespec_location (&arg, symbol_name_match_type::FULL);
+      locspec = new_linespec_location_spec (&arg,
+					    symbol_name_match_type::FULL);
       type = bp_static_marker_tracepoint;
     }
   else
     {
       ops = &code_breakpoint_ops;
-      location = string_to_event_location (&arg, current_language);
+      locspec = string_to_location_spec (&arg, current_language);
       type = bp_static_tracepoint;
     }
 
   create_breakpoint (get_current_arch (),
-		     location.get (),
+		     locspec.get (),
 		     NULL, 0, arg, false, 1 /* parse arg */,
 		     0 /* tempflag */,
 		     type /* type_wanted */,
@@ -13637,10 +13645,10 @@ create_tracepoint_from_upload (struct uploaded_tp *utp)
 	       "has no source form, ignoring it"),
 	     utp->number);
 
-  event_location_up location = string_to_event_location (&addr_str,
-							 current_language);
+  location_spec_up locspec = string_to_location_spec (&addr_str,
+						      current_language);
   if (!create_breakpoint (get_current_arch (),
-			  location.get (),
+			  locspec.get (),
 			  utp->cond_string.get (), -1, addr_str,
 			  false /* force_condition */,
 			  0 /* parse cond/thread */,
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 566f1285e46..f7884defce1 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -502,7 +502,7 @@ class bp_location : public refcounted_object
   struct symtab *symtab = NULL;
 
   /* The symbol found by the location parser, if any.  This may be used to
-     ascertain when an event location was set at a different location than
+     ascertain when a location spec was set at a different location than
      the one originally selected by parsing, e.g., inlined symbols.  */
   const struct symbol *symbol = NULL;
 
@@ -562,14 +562,15 @@ enum print_stop_action
 
 struct breakpoint_ops
 {
-  /* Create SALs from location, storing the result in linespec_result.
+  /* Create SALs from location spec, storing the result in
+     linespec_result.
 
      For an explanation about the arguments, see the function
-     `create_sals_from_location_default'.
+     `create_sals_from_location_spec_default'.
 
      This function is called inside `create_breakpoint'.  */
-  void (*create_sals_from_location) (struct event_location *location,
-				     struct linespec_result *canonical);
+  void (*create_sals_from_location_spec) (location_spec *locspec,
+					  struct linespec_result *canonical);
 
   /* This method will be responsible for creating a breakpoint given its SALs.
      Usually, it just calls `create_breakpoints_sal' (for ordinary
@@ -709,14 +710,14 @@ struct breakpoint
   /* Print to FP the CLI command that recreates this breakpoint.  */
   virtual void print_recreate (struct ui_file *fp) const;
 
-  /* Given the location (second parameter), this method decodes it and
-     returns the SAL locations related to it.  For ordinary
+  /* Given the location spec (second parameter), this method decodes
+     it and returns the SAL locations related to it.  For ordinary
      breakpoints, it calls `decode_line_full'.  If SEARCH_PSPACE is
      not NULL, symbol search is restricted to just that program space.
 
-     This function is called inside `location_to_sals'.  */
-  virtual std::vector<symtab_and_line> decode_location
-    (struct event_location *location,
+     This function is called inside `location_spec_to_sals'.  */
+  virtual std::vector<symtab_and_line> decode_location_spec
+    (location_spec *locspec,
      struct program_space *search_pspace);
 
   /* Return true if this breakpoint explains a signal.  See
@@ -774,16 +775,16 @@ struct breakpoint
      non-thread-specific ordinary breakpoints this is NULL.  */
   program_space *pspace = NULL;
 
-  /* Location we used to set the breakpoint.  */
-  event_location_up location;
+  /* The location specification we used to set the breakpoint.  */
+  location_spec_up locspec;
 
   /* The filter that should be passed to decode_line_full when
      re-setting this breakpoint.  This may be NULL.  */
   gdb::unique_xmalloc_ptr<char> filter;
 
-  /* For a ranged breakpoint, the location we used to find the end of
-     the range.  */
-  event_location_up location_range_end;
+  /* For a ranged breakpoint, the location specification we used to
+     find the end of the range.  */
+  location_spec_up locspec_range_end;
 
   /* Architecture we used to set the breakpoint.  */
   struct gdbarch *gdbarch;
@@ -859,7 +860,7 @@ struct code_breakpoint : public breakpoint
      location" from the address in the SAL.  */
   code_breakpoint (struct gdbarch *gdbarch, bptype type,
 		   gdb::array_view<const symtab_and_line> sals,
-		   event_location_up &&location,
+		   location_spec_up &&locspec,
 		   gdb::unique_xmalloc_ptr<char> filter,
 		   gdb::unique_xmalloc_ptr<char> cond_string,
 		   gdb::unique_xmalloc_ptr<char> extra_string,
@@ -882,8 +883,8 @@ struct code_breakpoint : public breakpoint
 		      const address_space *aspace,
 		      CORE_ADDR bp_addr,
 		      const target_waitstatus &ws) override;
-  std::vector<symtab_and_line> decode_location
-       (struct event_location *location,
+  std::vector<symtab_and_line> decode_location_spec
+       (struct location_spec *locspec,
 	struct program_space *search_pspace) override;
 };
 
@@ -1460,13 +1461,14 @@ extern void
 extern void install_breakpoint (int internal, std::unique_ptr<breakpoint> &&b,
 				int update_gll);
 
-/* Returns the breakpoint ops appropriate for use with with LOCATION and
-   according to IS_TRACEPOINT.  Use this to ensure, for example, that you pass
-   the correct ops to create_breakpoint for probe locations.  If LOCATION is
-   NULL, returns code_breakpoint_ops.  */
+/* Returns the breakpoint ops appropriate for use with with LOCSPEC
+   and according to IS_TRACEPOINT.  Use this to ensure, for example,
+   that you pass the correct ops to create_breakpoint for probe
+   location specs.  If LOCSPEC is NULL, returns
+   code_breakpoint_ops.  */
 
-extern const struct breakpoint_ops *breakpoint_ops_for_event_location
-  (const struct event_location *location, bool is_tracepoint);
+extern const struct breakpoint_ops *breakpoint_ops_for_location_spec
+  (const location_spec *locspec, bool is_tracepoint);
 
 /* Flags that can be passed down to create_breakpoint, etc., to affect
    breakpoint creation in several ways.  */
@@ -1478,15 +1480,15 @@ enum breakpoint_create_flags
     CREATE_BREAKPOINT_FLAGS_INSERTED = 1 << 0
   };
 
-/* Set a breakpoint.  This function is shared between CLI and MI functions
-   for setting a breakpoint at LOCATION.
+/* Set a breakpoint.  This function is shared between CLI and MI
+   functions for setting a breakpoint at LOCSPEC.
 
    This function has two major modes of operations, selected by the
    PARSE_EXTRA parameter.
 
-   If PARSE_EXTRA 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_EXTRA is zero, LOCSPEC is just the breakpoint's location
+   spec, with condition, thread, and extra string specified by the
+   COND_STRING, THREAD, and EXTRA_STRING parameters.
 
    If PARSE_EXTRA is non-zero, this function will attempt to extract
    the condition, thread, and extra string from EXTRA_STRING, ignoring
@@ -1503,7 +1505,7 @@ enum breakpoint_create_flags
    Returns true if any breakpoint was created; false otherwise.  */
 
 extern int create_breakpoint (struct gdbarch *gdbarch,
-			      struct event_location *location,
+			      struct location_spec *locspec,
 			      const char *cond_string, int thread,
 			      const char *extra_string,
 			      bool force_condition,
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 31911ebe61f..18fb6e6d869 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -970,13 +970,13 @@ edit_command (const char *arg, int from_tty)
 
       /* Now should only be one argument -- decode it in SAL.  */
       arg1 = arg;
-      event_location_up location = string_to_event_location (&arg1,
-							     current_language);
+      location_spec_up locspec = string_to_location_spec (&arg1,
+							  current_language);
 
       if (*arg1)
 	error (_("Junk at end of line specification."));
 
-      std::vector<symtab_and_line> sals = decode_line_1 (location.get (),
+      std::vector<symtab_and_line> sals = decode_line_1 (locspec.get (),
 							 DECODE_LINE_LIST_MODE,
 							 NULL, NULL, 0);
 
@@ -1241,18 +1241,18 @@ list_command (const char *arg, int from_tty)
     dummy_beg = 1;
   else
     {
-      event_location_up location = string_to_event_location (&arg1,
-							     current_language);
-
-      /* We know that the ARG string is not empty, yet the attempt to parse
-	 a location from the string consumed no characters.  This most
-	 likely means that the first thing in ARG looks like a location
-	 condition, and so the string_to_event_location call stopped
-	 parsing.  */
+      location_spec_up locspec
+	= string_to_location_spec (&arg1, current_language);
+
+      /* We know that the ARG string is not empty, yet the attempt to
+	 parse a location spec from the string consumed no characters.
+	 This most likely means that the first thing in ARG looks like
+	 a location spec condition, and so the string_to_location_spec
+	 call stopped parsing.  */
       if (arg1 == arg)
 	error (_("Junk at end of line specification."));
 
-      sals = decode_line_1 (location.get (), DECODE_LINE_LIST_MODE,
+      sals = decode_line_1 (locspec.get (), DECODE_LINE_LIST_MODE,
 			    NULL, NULL, 0);
       filter_sals (sals);
       if (sals.empty ())
@@ -1297,17 +1297,17 @@ list_command (const char *arg, int from_tty)
 	     know it was ambiguous.  */
 	  const char *end_arg = arg1;
 
-	  event_location_up location
-	    = string_to_event_location (&arg1, current_language);
+	  location_spec_up locspec
+	    = string_to_location_spec (&arg1, current_language);
 
 	  if (*arg1)
 	    error (_("Junk at end of line specification."));
 
 	  std::vector<symtab_and_line> sals_end
 	    = (dummy_beg
-	       ? decode_line_1 (location.get (), DECODE_LINE_LIST_MODE,
+	       ? decode_line_1 (locspec.get (), DECODE_LINE_LIST_MODE,
 				NULL, NULL, 0)
-	       : decode_line_1 (location.get (), DECODE_LINE_LIST_MODE,
+	       : decode_line_1 (locspec.get (), DECODE_LINE_LIST_MODE,
 				NULL, sal.symtab, sal.line));
 
 	  filter_sals (sals_end);
diff --git a/gdb/completer.c b/gdb/completer.c
index fea3eb9329d..2ec8d2eb594 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -707,13 +707,13 @@ string_or_empty (const char *string)
 
 static void
 collect_explicit_location_matches (completion_tracker &tracker,
-				   struct event_location *location,
+				   location_spec *locspec,
 				   enum explicit_location_match_type what,
 				   const char *word,
 				   const struct language_defn *language)
 {
   const struct explicit_location *explicit_loc
-    = get_explicit_location (location);
+    = get_explicit_location (locspec);
 
   /* True if the option expects an argument.  */
   bool needs_arg = true;
@@ -846,19 +846,19 @@ skip_keyword (completion_tracker &tracker,
   return -1;
 }
 
-/* A completer function for explicit locations.  This function
+/* A completer function for explicit location specs.  This function
    completes both options ("-source", "-line", etc) and values.  If
    completing a quoted string, then QUOTED_ARG_START and
    QUOTED_ARG_END point to the quote characters.  LANGUAGE is the
    current language.  */
 
 static void
-complete_explicit_location (completion_tracker &tracker,
-			    struct event_location *location,
-			    const char *text,
-			    const language_defn *language,
-			    const char *quoted_arg_start,
-			    const char *quoted_arg_end)
+complete_explicit_location_spec (completion_tracker &tracker,
+				 location_spec *locspec,
+				 const char *text,
+				 const language_defn *language,
+				 const char *quoted_arg_start,
+				 const char *quoted_arg_end)
 {
   if (*text != '-')
     return;
@@ -916,7 +916,7 @@ complete_explicit_location (completion_tracker &tracker,
 	}
 
       /* Now gather matches  */
-      collect_explicit_location_matches (tracker, location, what, text,
+      collect_explicit_location_matches (tracker, locspec, what, text,
 					 language);
     }
 }
@@ -943,9 +943,9 @@ location_completer (struct cmd_list_element *ignore,
   const char *copy = text;
 
   explicit_completion_info completion_info;
-  event_location_up location
-    = string_to_explicit_location (&copy, current_language,
-				   &completion_info);
+  location_spec_up locspec
+    = string_to_explicit_location_spec (&copy, current_language,
+					&completion_info);
   if (completion_info.quoted_arg_start != NULL
       && completion_info.quoted_arg_end == NULL)
     {
@@ -954,7 +954,7 @@ location_completer (struct cmd_list_element *ignore,
       tracker.advance_custom_word_point_by (1);
     }
 
-  if (completion_info.saw_explicit_location_option)
+  if (completion_info.saw_explicit_location_spec_option)
     {
       if (*copy != '\0')
 	{
@@ -987,15 +987,15 @@ location_completer (struct cmd_list_element *ignore,
 						- text);
 	  text = completion_info.last_option;
 
-	  complete_explicit_location (tracker, location.get (), text,
-				      current_language,
-				      completion_info.quoted_arg_start,
-				      completion_info.quoted_arg_end);
+	  complete_explicit_location_spec (tracker, locspec.get (), text,
+					   current_language,
+					   completion_info.quoted_arg_start,
+					   completion_info.quoted_arg_end);
 
 	}
     }
   /* This is an address or linespec location.  */
-  else if (location != NULL)
+  else if (locspec != nullptr)
     {
       /* Handle non-explicit location options.  */
 
@@ -1008,7 +1008,7 @@ location_completer (struct cmd_list_element *ignore,
 	  text = copy;
 
 	  symbol_name_match_type match_type
-	    = get_explicit_location (location.get ())->func_name_match_type;
+	    = get_explicit_location (locspec.get ())->func_name_match_type;
 	  complete_address_and_linespec_locations (tracker, text, match_type);
 	}
     }
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 32cb27c8967..2fe02805d01 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1026,8 +1026,8 @@ elf_gnu_ifunc_resolver_return_stop (code_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 (event_location_to_string (b->location.get ()),
-			      resolved_pc);
+  const char *locspec_str = location_spec_to_string (b->locspec.get ());
+  elf_gnu_ifunc_record_cache (locspec_str, resolved_pc);
 
   b->type = bp_breakpoint;
   update_breakpoint_locations (b, current_program_space,
diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c
index d6c89aa8c71..c358f0ba99d 100644
--- a/gdb/guile/scm-breakpoint.c
+++ b/gdb/guile/scm-breakpoint.c
@@ -187,9 +187,9 @@ bpscm_print_breakpoint_smob (SCM self, SCM port, scm_print_state *pstate)
       gdbscm_printf (port, " hit:%d", b->hit_count);
       gdbscm_printf (port, " ignore:%d", b->ignore_count);
 
-      if (b->location != nullptr)
+      if (b->locspec != nullptr)
 	{
-	  const char *str = event_location_to_string (b->location.get ());
+	  const char *str = location_spec_to_string (b->locspec.get ());
 	  if (str != nullptr)
 	    gdbscm_printf (port, " @%s", str);
 	}
@@ -448,10 +448,10 @@ gdbscm_register_breakpoint_x (SCM self)
   pending_breakpoint_scm = self;
   location = bp_smob->spec.location;
   copy = skip_spaces (location);
-  event_location_up eloc
-    = string_to_event_location_basic (&copy,
-				      current_language,
-				      symbol_name_match_type::WILD);
+  location_spec_up locspec
+    = string_to_location_spec_basic (&copy,
+				     current_language,
+				     symbol_name_match_type::WILD);
 
   try
     {
@@ -463,9 +463,9 @@ gdbscm_register_breakpoint_x (SCM self)
 	case bp_breakpoint:
 	  {
 	    const breakpoint_ops *ops =
-	      breakpoint_ops_for_event_location (eloc.get (), false);
+	      breakpoint_ops_for_location_spec (locspec.get (), false);
 	    create_breakpoint (get_current_arch (),
-			       eloc.get (), NULL, -1, NULL, false,
+			       locspec.get (), NULL, -1, NULL, false,
 			       0,
 			       temporary, bp_breakpoint,
 			       0,
@@ -855,13 +855,13 @@ gdbscm_breakpoint_location (SCM self)
 {
   breakpoint_smob *bp_smob
     = bpscm_get_valid_breakpoint_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  const char *str;
 
   if (bp_smob->bp->type != bp_breakpoint)
     return SCM_BOOL_F;
 
-  str = event_location_to_string (bp_smob->bp->location.get ());
-  if (! str)
+  const char *str
+    = location_spec_to_string (bp_smob->bp->locspec.get ());
+  if (str == nullptr)
     str = "";
 
   return gdbscm_scm_from_c_string (str);
diff --git a/gdb/linespec.c b/gdb/linespec.c
index c9558c8ae36..b12f5c87733 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1990,7 +1990,7 @@ linespec_parse_basic (linespec_parser *parser)
 static void
 canonicalize_linespec (struct linespec_state *state, const linespec *ls)
 {
-  struct event_location *canon;
+  location_spec *canon;
   struct explicit_location *explicit_loc;
 
   /* If canonicalization was not requested, no need to do anything.  */
@@ -1998,9 +1998,9 @@ canonicalize_linespec (struct linespec_state *state, const linespec *ls)
     return;
 
   /* Save everything as an explicit location.  */
-  state->canonical->location
-    = new_explicit_location (&ls->explicit_loc);
-  canon = state->canonical->location.get ();
+  state->canonical->locspec
+    = new_explicit_location_spec (&ls->explicit_loc);
+  canon = state->canonical->locspec.get ();
   explicit_loc = get_explicit_location (canon);
 
   if (explicit_loc->label_name != NULL)
@@ -2019,8 +2019,8 @@ canonicalize_linespec (struct linespec_state *state, const linespec *ls)
   /* If this location originally came from a linespec, save a string
      representation of it for display and saving to file.  */
   if (state->is_linespec)
-    set_event_location_string (canon,
-			       explicit_location_to_linespec (explicit_loc));
+    set_location_spec_string (canon,
+			      explicit_location_to_linespec (explicit_loc));
 }
 
 /* Given a line offset in LS, construct the relevant SALs.  */
@@ -3061,22 +3061,22 @@ linespec_complete (completion_tracker &tracker, const char *text,
 }
 
 /* A helper function for decode_line_full and decode_line_1 to
-   turn LOCATION into std::vector<symtab_and_line>.  */
+   turn LOCSPEC into std::vector<symtab_and_line>.  */
 
 static std::vector<symtab_and_line>
-event_location_to_sals (linespec_parser *parser,
-			const struct event_location *location)
+location_spec_to_sals (linespec_parser *parser,
+		       const location_spec *locspec)
 {
   std::vector<symtab_and_line> result;
 
-  switch (event_location_type (location))
+  switch (location_spec_type (locspec))
     {
-    case LINESPEC_LOCATION:
+    case LINESPEC_LOCATION_SPEC:
       {
 	PARSER_STATE (parser)->is_linespec = 1;
 	try
 	  {
-	    const linespec_location *ls = get_linespec_location (location);
+	    const linespec_location *ls = get_linespec_location (locspec);
 	    result = parse_linespec (parser,
 				     ls->spec_string, ls->match_type);
 	  }
@@ -3087,17 +3087,17 @@ event_location_to_sals (linespec_parser *parser,
       }
       break;
 
-    case ADDRESS_LOCATION:
+    case ADDRESS_LOCATION_SPEC:
       {
-	const char *addr_string = get_address_string_location (location);
-	CORE_ADDR addr = get_address_location (location);
+	const char *addr_string = get_address_string_location (locspec);
+	CORE_ADDR addr = get_address_location (locspec);
 
 	if (addr_string != NULL)
 	  {
 	    addr = linespec_expression_to_pc (&addr_string);
 	    if (PARSER_STATE (parser)->canonical != NULL)
-	      PARSER_STATE (parser)->canonical->location
-		= copy_event_location (location);
+	      PARSER_STATE (parser)->canonical->locspec
+		= copy_location_spec (locspec);
 	  }
 
 	result = convert_address_location_to_sals (PARSER_STATE (parser),
@@ -3105,24 +3105,24 @@ event_location_to_sals (linespec_parser *parser,
       }
       break;
 
-    case EXPLICIT_LOCATION:
+    case EXPLICIT_LOCATION_SPEC:
       {
 	const struct explicit_location *explicit_loc;
 
-	explicit_loc = get_explicit_location_const (location);
+	explicit_loc = get_explicit_location_const (locspec);
 	result = convert_explicit_location_to_sals (PARSER_STATE (parser),
 						    PARSER_RESULT (parser),
 						    explicit_loc);
       }
       break;
 
-    case PROBE_LOCATION:
+    case PROBE_LOCATION_SPEC:
       /* Probes are handled by their own decoders.  */
       gdb_assert_not_reached ("attempt to decode probe location");
       break;
 
     default:
-      gdb_assert_not_reached ("unhandled event location type");
+      gdb_assert_not_reached ("unhandled location spec type");
     }
 
   return result;
@@ -3131,7 +3131,7 @@ event_location_to_sals (linespec_parser *parser,
 /* See linespec.h.  */
 
 void
-decode_line_full (struct event_location *location, int flags,
+decode_line_full (struct location_spec *locspec, int flags,
 		  struct program_space *search_pspace,
 		  struct symtab *default_symtab,
 		  int default_line, struct linespec_result *canonical,
@@ -3156,13 +3156,13 @@ decode_line_full (struct event_location *location, int flags,
 
   scoped_restore_current_program_space restore_pspace;
 
-  std::vector<symtab_and_line> result = event_location_to_sals (&parser,
-								location);
+  std::vector<symtab_and_line> result = location_spec_to_sals (&parser,
+							       locspec);
   state = PARSER_STATE (&parser);
 
   if (result.size () == 0)
     throw_error (NOT_SUPPORTED_ERROR, _("Location %s not available"),
-		 event_location_to_string (location));
+		 location_spec_to_string (locspec));
 
   gdb_assert (result.size () == 1 || canonical->pre_expanded);
   canonical->pre_expanded = 1;
@@ -3200,7 +3200,7 @@ decode_line_full (struct event_location *location, int flags,
 /* See linespec.h.  */
 
 std::vector<symtab_and_line>
-decode_line_1 (const struct event_location *location, int flags,
+decode_line_1 (const location_spec *locspec, int flags,
 	       struct program_space *search_pspace,
 	       struct symtab *default_symtab,
 	       int default_line)
@@ -3211,7 +3211,7 @@ decode_line_1 (const struct event_location *location, int flags,
 
   scoped_restore_current_program_space restore_pspace;
 
-  return event_location_to_sals (&parser, location);
+  return location_spec_to_sals (&parser, locspec);
 }
 
 /* See linespec.h.  */
@@ -3226,10 +3226,10 @@ decode_line_with_current_source (const char *string, int flags)
      and get a default source symtab+line or it will recursively call us!  */
   symtab_and_line cursal = get_current_source_symtab_and_line ();
 
-  event_location_up location = string_to_event_location (&string,
-							 current_language);
+  location_spec_up locspec = string_to_location_spec (&string,
+						      current_language);
   std::vector<symtab_and_line> sals
-    = decode_line_1 (location.get (), flags, NULL, cursal.symtab, cursal.line);
+    = decode_line_1 (locspec.get (), flags, NULL, cursal.symtab, cursal.line);
 
   if (*string)
     error (_("Junk at end of line specification: %s"), string);
@@ -3245,14 +3245,14 @@ decode_line_with_last_displayed (const char *string, int flags)
   if (string == 0)
     error (_("Empty line specification."));
 
-  event_location_up location = string_to_event_location (&string,
-							 current_language);
+  location_spec_up locspec = string_to_location_spec (&string,
+						      current_language);
   std::vector<symtab_and_line> sals
     = (last_displayed_sal_is_valid ()
-       ? decode_line_1 (location.get (), flags, NULL,
+       ? decode_line_1 (locspec.get (), flags, NULL,
 			get_last_displayed_symtab (),
 			get_last_displayed_line ())
-       : decode_line_1 (location.get (), flags, NULL, NULL, 0));
+       : decode_line_1 (locspec.get (), flags, NULL, NULL, 0));
 
   if (*string)
     error (_("Junk at end of line specification: %s"), string);
@@ -3364,8 +3364,8 @@ decode_objc (struct linespec_state *self, linespec *ls, const char *arg)
 	  else
 	    str = saved_arg;
 
-	  self->canonical->location
-	    = new_linespec_location (&str, symbol_name_match_type::FULL);
+	  self->canonical->locspec
+	    = new_linespec_location_spec (&str, symbol_name_match_type::FULL);
 	}
     }
 
diff --git a/gdb/linespec.h b/gdb/linespec.h
index bb8975548a3..9d3e84d19fc 100644
--- a/gdb/linespec.h
+++ b/gdb/linespec.h
@@ -70,9 +70,9 @@ struct linespec_result
      object.  */
   bool pre_expanded = false;
 
-  /* If PRE_EXPANDED is non-zero, this is set to the location entered
-     by the user.  */
-  event_location_up location;
+  /* If PRE_EXPANDED is true, this is set to the location spec
+     entered by the user.  */
+  location_spec_up locspec;
 
   /* The sals.  The vector will be freed by the destructor.  */
   std::vector<linespec_sals> lsals;
@@ -81,11 +81,11 @@ struct linespec_result
 /* Decode a linespec using the provided default symtab and line.  */
 
 extern std::vector<symtab_and_line>
-	decode_line_1 (const struct event_location *location, int flags,
+	decode_line_1 (const location_spec *locspec, int flags,
 		       struct program_space *search_pspace,
 		       struct symtab *default_symtab, int default_line);
 
-/* Parse LOCATION and return results.  This is the "full"
+/* Parse LOCSPEC and return results.  This is the "full"
    interface to this module, which handles multiple results
    properly.
 
@@ -124,7 +124,7 @@ extern std::vector<symtab_and_line>
    strcmp sense) to FILTER will be returned; all others will be
    filtered out.  */
 
-extern void decode_line_full (struct event_location *location, int flags,
+extern void decode_line_full (struct location_spec *locspec, int flags,
 			      struct program_space *search_pspace,
 			      struct symtab *default_symtab, int default_line,
 			      struct linespec_result *canonical,
diff --git a/gdb/location.c b/gdb/location.c
index 0459980ab8c..a52503b2ff3 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -1,4 +1,4 @@
-/* Data structures and API for event locations in GDB.
+/* Data structures and API for location specs in GDB.
    Copyright (C) 2013-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -32,17 +32,17 @@
 static std::string explicit_location_to_string
      (const struct explicit_location *explicit_loc);
 
-/* The base class for all an event locations used to set a stop event
-   in the inferior.  */
+/* The base class for all an location specs used to match actual
+   locations in the inferior.  */
 
-struct event_location
+struct location_spec
 {
-  virtual ~event_location () = default;
+  virtual ~location_spec () = default;
 
   /* Clone this object.  */
-  virtual event_location_up clone () const = 0;
+  virtual location_spec_up clone () const = 0;
 
-  /* Return true if this location is empty, false otherwise.  */
+  /* Return true if this location spec is empty, false otherwise.  */
   virtual bool empty_p () const = 0;
 
   /* Return a string representation of this location.  */
@@ -55,29 +55,29 @@ struct event_location
     return as_string.c_str ();
   }
 
-  DISABLE_COPY_AND_ASSIGN (event_location);
+  DISABLE_COPY_AND_ASSIGN (location_spec);
 
-  /* The type of this breakpoint specification.  */
-  enum event_location_type type;
+  /* The type of this location specification.  */
+  enum location_spec_type type;
 
-  /* Cached string representation of this location.  This is used,
-     e.g., to save stop event locations to file.  */
+  /* Cached string representation of this location spec.  This is
+     used, e.g., to save location specs to file.  */
   mutable std::string as_string;
 
 protected:
 
-  explicit event_location (enum event_location_type t)
+  explicit location_spec (enum location_spec_type t)
     : type (t)
   {
   }
 
-  event_location (enum event_location_type t, std::string &&str)
+  location_spec (enum location_spec_type t, std::string &&str)
     : type (t),
       as_string (std::move (str))
   {
   }
 
-  explicit event_location (const event_location *to_clone)
+  explicit location_spec (const location_spec *to_clone)
     : type (to_clone->type),
       as_string (to_clone->as_string)
   {
@@ -89,16 +89,16 @@ struct event_location
 };
 
 /* A probe.  */
-struct event_location_probe : public event_location
+struct probe_location_spec : public location_spec
 {
-  explicit event_location_probe (std::string &&probe)
-    : event_location (PROBE_LOCATION, std::move (probe))
+  explicit probe_location_spec (std::string &&probe)
+    : location_spec (PROBE_LOCATION_SPEC, std::move (probe))
   {
   }
 
-  event_location_up clone () const override
+  location_spec_up clone () const override
   {
-    return event_location_up (new event_location_probe (this));
+    return location_spec_up (new probe_location_spec (this));
   }
 
   bool empty_p () const override
@@ -108,8 +108,8 @@ struct event_location_probe : public event_location
 
 protected:
 
-  explicit event_location_probe (const event_location_probe *to_clone)
-    : event_location (to_clone)
+  explicit probe_location_spec (const probe_location_spec *to_clone)
+    : location_spec (to_clone)
   {
   }
 
@@ -120,11 +120,11 @@ struct event_location_probe : public event_location
 };
 
 /* A "normal" linespec.  */
-struct event_location_linespec : public event_location
+struct linespec_location_spec : public location_spec
 {
-  event_location_linespec (const char **linespec,
-			   symbol_name_match_type match_type)
-    : event_location (LINESPEC_LOCATION)
+  linespec_location_spec (const char **linespec,
+			  symbol_name_match_type match_type)
+    : location_spec (LINESPEC_LOCATION_SPEC)
   {
     linespec_location.match_type = match_type;
     if (*linespec != NULL)
@@ -144,14 +144,14 @@ struct event_location_linespec : public event_location
       }
   }
 
-  ~event_location_linespec ()
+  ~linespec_location_spec ()
   {
     xfree (linespec_location.spec_string);
   }
 
-  event_location_up clone () const override
+  location_spec_up clone () const override
   {
-    return event_location_up (new event_location_linespec (this));
+    return location_spec_up (new linespec_location_spec (this));
   }
 
   bool empty_p () const override
@@ -163,8 +163,8 @@ struct event_location_linespec : public event_location
 
 protected:
 
-  explicit event_location_linespec (const event_location_linespec *to_clone)
-    : event_location (to_clone),
+  explicit linespec_location_spec (const linespec_location_spec *to_clone)
+    : location_spec (to_clone),
       linespec_location (to_clone->linespec_location)
   {
     if (linespec_location.spec_string != nullptr)
@@ -186,20 +186,20 @@ struct event_location_linespec : public event_location
 };
 
 /* An address in the inferior.  */
-struct event_location_address : public event_location
+struct address_location_spec : public location_spec
 {
-  event_location_address (CORE_ADDR addr, const char *addr_string,
-			  int addr_string_len)
-    : event_location (ADDRESS_LOCATION),
+  address_location_spec (CORE_ADDR addr, const char *addr_string,
+			 int addr_string_len)
+    : location_spec (ADDRESS_LOCATION_SPEC),
       address (addr)
   {
     if (addr_string != nullptr)
       as_string = std::string (addr_string, addr_string_len);
   }
 
-  event_location_up clone () const override
+  location_spec_up clone () const override
   {
-    return event_location_up (new event_location_address (this));
+    return location_spec_up (new address_location_spec (this));
   }
 
   bool empty_p () const override
@@ -211,8 +211,8 @@ struct event_location_address : public event_location
 
 protected:
 
-  event_location_address (const event_location_address *to_clone)
-    : event_location (to_clone),
+  address_location_spec (const address_location_spec *to_clone)
+    : location_spec (to_clone),
       address (to_clone->address)
   {
   }
@@ -224,25 +224,25 @@ struct event_location_address : public event_location
   }
 };
 
-/* An explicit location.  */
-struct event_location_explicit : public event_location
+/* An explicit location spec.  */
+struct explicit_location_spec : public location_spec
 {
-  explicit event_location_explicit (const struct explicit_location *loc)
-    : event_location (EXPLICIT_LOCATION)
+  explicit explicit_location_spec (const struct explicit_location *loc)
+    : location_spec (EXPLICIT_LOCATION_SPEC)
   {
     copy_loc (loc);
   }
 
-  ~event_location_explicit ()
+  ~explicit_location_spec ()
   {
     xfree (explicit_loc.source_filename);
     xfree (explicit_loc.function_name);
     xfree (explicit_loc.label_name);
   }
 
-  event_location_up clone () const override
+  location_spec_up clone () const override
   {
-    return event_location_up (new event_location_explicit (this));
+    return location_spec_up (new explicit_location_spec (this));
   }
 
   bool empty_p () const override
@@ -257,8 +257,8 @@ struct event_location_explicit : public event_location
 
 protected:
 
-  explicit event_location_explicit (const event_location_explicit *to_clone)
-    : event_location (to_clone)
+  explicit explicit_location_spec (const explicit_location_spec *to_clone)
+    : location_spec (to_clone)
   {
     copy_loc (&to_clone->explicit_loc);
   }
@@ -289,10 +289,10 @@ struct event_location_explicit : public event_location
 
 /* See description in location.h.  */
 
-enum event_location_type
-event_location_type (const struct event_location *location)
+enum location_spec_type
+location_spec_type (const location_spec *locspec)
 {
-  return location->type;
+  return locspec->type;
 }
 
 /* See description in location.h.  */
@@ -307,99 +307,99 @@ initialize_explicit_location (struct explicit_location *explicit_loc)
 
 /* See description in location.h.  */
 
-event_location_up
-new_linespec_location (const char **linespec,
-		       symbol_name_match_type match_type)
+location_spec_up
+new_linespec_location_spec (const char **linespec,
+			    symbol_name_match_type match_type)
 {
-  return event_location_up (new event_location_linespec (linespec,
-							 match_type));
+  return location_spec_up (new linespec_location_spec (linespec,
+						       match_type));
 }
 
 /* See description in location.h.  */
 
 const linespec_location *
-get_linespec_location (const struct event_location *location)
+get_linespec_location (const location_spec *locspec)
 {
-  gdb_assert (location->type == LINESPEC_LOCATION);
-  return &((event_location_linespec *) location)->linespec_location;
+  gdb_assert (locspec->type == LINESPEC_LOCATION_SPEC);
+  return &((linespec_location_spec *) locspec)->linespec_location;
 }
 
 /* See description in location.h.  */
 
-event_location_up
-new_address_location (CORE_ADDR addr, const char *addr_string,
-		      int addr_string_len)
+location_spec_up
+new_address_location_spec (CORE_ADDR addr, const char *addr_string,
+			   int addr_string_len)
 {
-  return event_location_up (new event_location_address (addr, addr_string,
-							addr_string_len));
+  return location_spec_up (new address_location_spec (addr, addr_string,
+						      addr_string_len));
 }
 
 /* See description in location.h.  */
 
 CORE_ADDR
-get_address_location (const struct event_location *location)
+get_address_location (const location_spec *locspec)
 {
-  gdb_assert (location->type == ADDRESS_LOCATION);
-  return ((event_location_address *) location)->address;
+  gdb_assert (locspec->type == ADDRESS_LOCATION_SPEC);
+  return ((address_location_spec *) locspec)->address;
 }
 
 /* See description in location.h.  */
 
 const char *
-get_address_string_location (const struct event_location *location)
+get_address_string_location (const location_spec *locspec)
 {
-  gdb_assert (location->type == ADDRESS_LOCATION);
-  return location->to_string ();
+  gdb_assert (locspec->type == ADDRESS_LOCATION_SPEC);
+  return locspec->to_string ();
 }
 
 /* See description in location.h.  */
 
-event_location_up
-new_probe_location (std::string &&probe)
+location_spec_up
+new_probe_location_spec (std::string &&probe)
 {
-  return event_location_up (new event_location_probe (std::move (probe)));
+  return location_spec_up (new probe_location_spec (std::move (probe)));
 }
 
 /* See description in location.h.  */
 
 const char *
-get_probe_location (const struct event_location *location)
+get_probe_location_spec_string (const location_spec *locspec)
 {
-  gdb_assert (location->type == PROBE_LOCATION);
-  return location->to_string ();
+  gdb_assert (locspec->type == PROBE_LOCATION_SPEC);
+  return locspec->to_string ();
 }
 
 /* See description in location.h.  */
 
-event_location_up
-new_explicit_location (const struct explicit_location *explicit_loc)
+location_spec_up
+new_explicit_location_spec (const explicit_location *explicit_loc)
 {
-  return event_location_up (new event_location_explicit (explicit_loc));
+  return location_spec_up (new explicit_location_spec (explicit_loc));
 }
 
 /* See description in location.h.  */
 
 struct explicit_location *
-get_explicit_location (struct event_location *location)
+get_explicit_location (location_spec *locspec)
 {
-  gdb_assert (location->type == EXPLICIT_LOCATION);
-  return &((event_location_explicit *) location)->explicit_loc;
+  gdb_assert (locspec->type == EXPLICIT_LOCATION_SPEC);
+  return &((explicit_location_spec *) locspec)->explicit_loc;
 }
 
 /* See description in location.h.  */
 
 const struct explicit_location *
-get_explicit_location_const (const struct event_location *location)
+get_explicit_location_const (const location_spec *locspec)
 {
-  gdb_assert (location->type == EXPLICIT_LOCATION);
-  return &((event_location_explicit *) location)->explicit_loc;
+  gdb_assert (locspec->type == EXPLICIT_LOCATION_SPEC);
+  return &((explicit_location_spec *) locspec)->explicit_loc;
 }
 
-/* This convenience function returns a malloc'd string which
-   represents the location in EXPLICIT_LOC.
+/* Return a string representation of the explicit location spec in
+   EXPLICIT_LOCSPEC.
 
-   AS_LINESPEC is true if this string should be a linespec.
-   Otherwise it will be output in explicit form.  */
+   AS_LINESPEC is true if this string should be a linespec.  Otherwise
+   it will be output in explicit form.  */
 
 static std::string
 explicit_to_string_internal (bool as_linespec,
@@ -473,24 +473,24 @@ explicit_location_to_linespec (const struct explicit_location *explicit_loc)
 
 /* See description in location.h.  */
 
-event_location_up
-copy_event_location (const struct event_location *src)
+location_spec_up
+copy_location_spec (const location_spec *src)
 {
   return src->clone ();
 }
 
 void
-event_location_deleter::operator() (event_location *location) const
+location_spec_deleter::operator() (location_spec *locspec) const
 {
-  delete location;
+  delete locspec;
 }
 
 /* See description in location.h.  */
 
 const char *
-event_location_to_string (struct event_location *location)
+location_spec_to_string (struct location_spec *locspec)
 {
-  return location->to_string ();
+  return locspec->to_string ();
 }
 
 /* Find an instance of the quote character C in the string S that is
@@ -523,14 +523,14 @@ find_end_quote (const char *s, char end_quote_char)
   return 0;
 }
 
-/* A lexer for explicit locations.  This function will advance INP
-   past any strings that it lexes.  Returns a malloc'd copy of the
+/* A lexer for explicit location specs.  This function will advance
+   INP past any strings that it lexes.  Returns a malloc'd copy of the
    lexed string or NULL if no lexing was done.  */
 
 static gdb::unique_xmalloc_ptr<char>
-explicit_location_lex_one (const char **inp,
-			   const struct language_defn *language,
-			   explicit_completion_info *completion_info)
+explicit_location_spec_lex_one (const char **inp,
+				const struct language_defn *language,
+				explicit_completion_info *completion_info)
 {
   const char *start = *inp;
 
@@ -630,7 +630,7 @@ is_cp_operator (const char *start, const char *comma)
 }
 
 /* When scanning the input string looking for the next explicit
-   location option/delimiter, we jump to the next option by looking
+   location spec option/delimiter, we jump to the next option by looking
    for ",", and "-".  Such a character can also appear in C++ symbols
    like "operator," and "operator-".  So when we find such a
    character, we call this function to check if we found such a
@@ -673,15 +673,16 @@ first_of (const char *first, const char *new_tok)
     return first;
 }
 
-/* A lexer for functions in explicit locations.  This function will
+/* A lexer for functions in explicit location specs.  This function will
    advance INP past a function until the next option, or until end of
    string.  Returns a malloc'd copy of the lexed string or NULL if no
    lexing was done.  */
 
 static gdb::unique_xmalloc_ptr<char>
-explicit_location_lex_one_function (const char **inp,
-				    const struct language_defn *language,
-				    explicit_completion_info *completion_info)
+explicit_location_spec_lex_one_function
+  (const char **inp,
+   const struct language_defn *language,
+   explicit_completion_info *completion_info)
 {
   const char *start = *inp;
 
@@ -771,10 +772,10 @@ explicit_location_lex_one_function (const char **inp,
 
 /* See description in location.h.  */
 
-event_location_up
-string_to_explicit_location (const char **argp,
-			     const struct language_defn *language,
-			     explicit_completion_info *completion_info)
+location_spec_up
+string_to_explicit_location_spec (const char **argp,
+				  const struct language_defn *language,
+				  explicit_completion_info *completion_info)
 {
   /* It is assumed that input beginning with '-' and a non-digit
      character is an explicit location.  "-p" is reserved, though,
@@ -786,8 +787,8 @@ string_to_explicit_location (const char **argp,
       || ((*argp)[0] == '-' && (*argp)[1] == 'p'))
     return NULL;
 
-  std::unique_ptr<event_location_explicit> location
-    (new event_location_explicit ((const explicit_location *) nullptr));
+  std::unique_ptr<explicit_location_spec> locspec
+    (new explicit_location_spec ((const explicit_location *) nullptr));
 
   /* Process option/argument pairs.  dprintf_command
      requires that processing stop on ','.  */
@@ -817,7 +818,7 @@ string_to_explicit_location (const char **argp,
 
       /* Get the option string.  */
       gdb::unique_xmalloc_ptr<char> opt
-	= explicit_location_lex_one (argp, language, NULL);
+	= explicit_location_spec_lex_one (argp, language, NULL);
 
       /* Use the length of the option to allow abbreviations.  */
       len = strlen (opt.get ());
@@ -845,7 +846,7 @@ string_to_explicit_location (const char **argp,
 	      /* We do this here because the set of options that take
 		 arguments matches the set of explicit location
 		 options.  */
-	      completion_info->saw_explicit_location_option = true;
+	      completion_info->saw_explicit_location_spec_option = true;
 	    }
 	  oarg = std::move (arg);
 	  have_oarg = oarg != NULL;
@@ -854,36 +855,37 @@ string_to_explicit_location (const char **argp,
 
       if (strncmp (opt.get (), "-source", len) == 0)
 	{
-	  set_oarg (explicit_location_lex_one (argp, language,
-					       completion_info));
-	  location->explicit_loc.source_filename = oarg.release ();
+	  set_oarg (explicit_location_spec_lex_one (argp, language,
+						    completion_info));
+	  locspec->explicit_loc.source_filename = oarg.release ();
 	}
       else if (strncmp (opt.get (), "-function", len) == 0)
 	{
-	  set_oarg (explicit_location_lex_one_function (argp, language,
-							completion_info));
-	  location->explicit_loc.function_name = oarg.release ();
+	  set_oarg (explicit_location_spec_lex_one_function (argp, language,
+							     completion_info));
+	  locspec->explicit_loc.function_name = oarg.release ();
 	}
       else if (strncmp (opt.get (), "-qualified", len) == 0)
 	{
-	  location->explicit_loc.func_name_match_type
+	  locspec->explicit_loc.func_name_match_type
 	    = symbol_name_match_type::FULL;
 	}
       else if (strncmp (opt.get (), "-line", len) == 0)
 	{
-	  set_oarg (explicit_location_lex_one (argp, language, NULL));
+	  set_oarg (explicit_location_spec_lex_one (argp, language, NULL));
 	  *argp = skip_spaces (*argp);
 	  if (have_oarg)
 	    {
-	      location->explicit_loc.line_offset
+	      locspec->explicit_loc.line_offset
 		= linespec_parse_line_offset (oarg.get ());
 	      continue;
 	    }
 	}
       else if (strncmp (opt.get (), "-label", len) == 0)
 	{
-	  set_oarg (explicit_location_lex_one (argp, language, completion_info));
-	  location->explicit_loc.label_name = oarg.release ();
+	  set_oarg (explicit_location_spec_lex_one (argp, language,
+						    completion_info));
+	  locspec->explicit_loc.label_name = oarg.release ();
 	}
       /* Only emit an "invalid argument" error for options
 	 that look like option strings.  */
@@ -913,39 +915,39 @@ string_to_explicit_location (const char **argp,
 
   /* One special error check:  If a source filename was given
      without offset, function, or label, issue an error.  */
-  if (location->explicit_loc.source_filename != NULL
-      && location->explicit_loc.function_name == NULL
-      && location->explicit_loc.label_name == NULL
-      && (location->explicit_loc.line_offset.sign == LINE_OFFSET_UNKNOWN)
+  if (locspec->explicit_loc.source_filename != NULL
+      && locspec->explicit_loc.function_name == NULL
+      && locspec->explicit_loc.label_name == NULL
+      && (locspec->explicit_loc.line_offset.sign == LINE_OFFSET_UNKNOWN)
       && completion_info == NULL)
     {
       error (_("Source filename requires function, label, or "
 	       "line offset."));
     }
 
-  return event_location_up (location.release ());
+  return location_spec_up (locspec.release ());
 }
 
 /* See description in location.h.  */
 
-event_location_up
-string_to_event_location_basic (const char **stringp,
-				const struct language_defn *language,
-				symbol_name_match_type match_type)
+location_spec_up
+string_to_location_spec_basic (const char **stringp,
+			       const struct language_defn *language,
+			       symbol_name_match_type match_type)
 {
-  event_location_up location;
+  location_spec_up locspec;
   const char *cs;
 
   /* Try the input as a probe spec.  */
   cs = *stringp;
   if (cs != NULL && probe_linespec_to_static_ops (&cs) != NULL)
     {
-      location = new_probe_location (*stringp);
+      locspec = new_probe_location_spec (*stringp);
       *stringp += strlen (*stringp);
     }
   else
     {
-      /* Try an address location.  */
+      /* Try an address location spec.  */
       if (*stringp != NULL && **stringp == '*')
 	{
 	  const char *arg, *orig;
@@ -953,69 +955,72 @@ string_to_event_location_basic (const char **stringp,
 
 	  orig = arg = *stringp;
 	  addr = linespec_expression_to_pc (&arg);
-	  location = new_address_location (addr, orig, arg - orig);
+	  locspec = new_address_location_spec (addr, orig, arg - orig);
 	  *stringp += arg - orig;
 	}
       else
 	{
 	  /* Everything else is a linespec.  */
-	  location = new_linespec_location (stringp, match_type);
+	  locspec = new_linespec_location_spec (stringp, match_type);
 	}
     }
 
-  return location;
+  return locspec;
 }
 
 /* See description in location.h.  */
 
-event_location_up
-string_to_event_location (const char **stringp,
-			  const struct language_defn *language,
-			  symbol_name_match_type match_type)
+location_spec_up
+string_to_location_spec (const char **stringp,
+			 const struct language_defn *language,
+			 symbol_name_match_type match_type)
 {
   const char *arg, *orig;
 
-  /* Try an explicit location.  */
+  /* Try an explicit location spec.  */
   orig = arg = *stringp;
-  event_location_up location = string_to_explicit_location (&arg, language, NULL);
-  if (location != NULL)
+  location_spec_up locspec
+    = string_to_explicit_location_spec (&arg, language, NULL);
+  if (locspec != nullptr)
     {
       /* It was a valid explicit location.  Advance STRINGP to
 	 the end of input.  */
       *stringp += arg - orig;
 
-      /* If the user really specified a location, then we're done.  */
-      if (!event_location_empty_p (location.get ()))
-	return location;
+      /* If the user really specified a location spec, then we're
+	 done.  */
+      if (!location_spec_empty_p (locspec.get ()))
+	return locspec;
 
       /* Otherwise, the user _only_ specified optional flags like
-	 "-qualified", otherwise string_to_explicit_location would
-	 have thrown an error.  Save the flags for "basic" linespec
-	 parsing below and discard the explicit location.  */
-      event_location_explicit *xloc
-	= dynamic_cast<event_location_explicit *> (location.get ());
+	 "-qualified", otherwise string_to_explicit_location_spec
+	 would have thrown an error.  Save the flags for "basic"
+	 linespec parsing below and discard the explicit location
+	 spec.  */
+      explicit_location_spec *xloc
+	= dynamic_cast<explicit_location_spec *> (locspec.get ());
       gdb_assert (xloc != nullptr);
       match_type = xloc->explicit_loc.func_name_match_type;
     }
 
-  /* Everything else is a "basic" linespec, address, or probe
-     location.  */
-  return string_to_event_location_basic (stringp, language, match_type);
+  /* Everything else is a "basic" linespec, address, or probe location
+     spec.  */
+  return string_to_location_spec_basic (stringp, language, match_type);
 }
 
 /* See description in location.h.  */
 
 int
-event_location_empty_p (const struct event_location *location)
+location_spec_empty_p (const location_spec *locspec)
 {
-  return location->empty_p ();
+  return locspec->empty_p ();
 }
 
 /* See description in location.h.  */
 
 void
-set_event_location_string (struct event_location *location,
-			   std::string &&string)
+set_location_spec_string (struct location_spec *locspec,
+			  std::string &&string)
 {
-  location->as_string = std::move (string);
+  locspec->as_string = std::move (string);
 }
diff --git a/gdb/location.h b/gdb/location.h
index ff21c1c21cc..602998de298 100644
--- a/gdb/location.h
+++ b/gdb/location.h
@@ -1,4 +1,4 @@
-/* Data structures and API for event locations in GDB.
+/* Data structures and API for location specs in GDB.
    Copyright (C) 2013-2022 Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -22,7 +22,7 @@
 #include "symtab.h"
 
 struct language_defn;
-struct event_location;
+struct location_spec;
 
 /* An enumeration of possible signs for a line offset.  */
 
@@ -50,22 +50,21 @@ struct line_offset
   enum offset_relative_sign sign;
 };
 
-/* An enumeration of the various ways to specify a stop event
-   location (used with create_breakpoint).  */
+/* An enumeration of the various ways to specify a location spec.  */
 
-enum event_location_type
+enum location_spec_type
 {
   /* A traditional linespec.  */
-  LINESPEC_LOCATION,
+  LINESPEC_LOCATION_SPEC,
 
-  /* An address in the inferior.  */
-  ADDRESS_LOCATION,
+  /* An address location spec.  */
+  ADDRESS_LOCATION_SPEC,
 
-  /* An explicit location.  */
-  EXPLICIT_LOCATION,
+  /* An explicit location spec.  */
+  EXPLICIT_LOCATION_SPEC,
 
-  /* A probe location.  */
-  PROBE_LOCATION
+  /* A probe location spec.  */
+  PROBE_LOCATION_SPEC
 };
 
 /* A traditional linespec.  */
@@ -79,7 +78,7 @@ struct linespec_location
   char *spec_string;
 };
 
-/* An explicit location.  This structure is used to bypass the
+/* An explicit location spec.  This structure is used to bypass the
    parsing done on linespecs.  It still has the same requirements
    as linespecs, though.  For example, source_filename requires
    at least one other field.  */
@@ -104,136 +103,137 @@ struct explicit_location
   struct line_offset line_offset;
 };
 
-/* Return the type of the given event location.  */
+/* Return the type of the given location spec.  */
 
-extern enum event_location_type
-  event_location_type (const struct event_location *);
+extern enum location_spec_type
+  location_spec_type (const location_spec *);
 
 /* Return a linespec string representation of the given explicit
-   location.  The location must already be canonicalized/valid.  */
+   location spec.  The location spec must already be
+   canonicalized/valid.  */
 
-extern std::string
-  explicit_location_to_linespec (const struct explicit_location *explicit_loc);
+extern std::string explicit_location_to_linespec
+  (const explicit_location *explicit_locspec);
 
-/* Return a string representation of the LOCATION.
+/* Return a string representation of LOCSPEC.
    This function may return NULL for unspecified linespecs,
-   e.g, LINESPEC_LOCATION and spec_string is NULL.
+   e.g, LINESPEC_LOCATION_SPEC and spec_string is NULL.
 
-   The result is cached in LOCATION.  */
+   The result is cached in LOCSPEC.  */
 
 extern const char *
-  event_location_to_string (struct event_location *location);
+  location_spec_to_string (location_spec *locspec);
 
-/* A deleter for a struct event_location.  */
+/* A deleter for a struct location_spec.  */
 
-struct event_location_deleter
+struct location_spec_deleter
 {
-  void operator() (event_location *location) const;
+  void operator() (location_spec *locspec) const;
 };
 
-/* A unique pointer for event_location.  */
-typedef std::unique_ptr<event_location, event_location_deleter>
-     event_location_up;
+/* A unique pointer for location_spec.  */
+typedef std::unique_ptr<location_spec, location_spec_deleter>
+     location_spec_up;
 
-/* Create a new linespec location.  */
+/* Create a new linespec location spec.  */
 
-extern event_location_up new_linespec_location
+extern location_spec_up new_linespec_location_spec
   (const char **linespec, symbol_name_match_type match_type);
 
-/* Return the linespec location of the given event_location (which
-   must be of type LINESPEC_LOCATION).  */
+/* Return the linespec location spec of the given location_spec (which
+   must be of type LINESPEC_LOCATION_SPEC).  */
 
 extern const linespec_location *
-  get_linespec_location (const struct event_location *location);
+  get_linespec_location (const location_spec *locspec);
 
-/* Create a new address location.
-   ADDR is the address corresponding to this event_location.
+/* Create a new address location spec.
+   ADDR is the address corresponding to this location_spec.
    ADDR_STRING, a string of ADDR_STRING_LEN characters, is
    the expression that was parsed to determine the address ADDR.  */
 
-extern event_location_up new_address_location (CORE_ADDR addr,
-					       const char *addr_string,
-					       int addr_string_len);
+extern location_spec_up new_address_location_spec (CORE_ADDR addr,
+						   const char *addr_string,
+						   int addr_string_len);
 
-/* Return the address location (a CORE_ADDR) of the given event_location
-   (which must be of type ADDRESS_LOCATION).  */
+/* Return the address (a CORE_ADDR) of the given location_spec, which
+   must be of type ADDRESS_LOCATION_SPEC.  */
 
 extern CORE_ADDR
-  get_address_location (const struct event_location *location);
+  get_address_location (const location_spec *locspec);
 
-/* Return the expression (a string) that was used to compute the address
-   of the given event_location (which must be of type ADDRESS_LOCATION).  */
+/* Return the expression (a string) that was used to compute the
+   address of the given location_spec, which must be of type
+   ADDRESS_LOCATION_SPEC.  */
 
 extern const char *
-  get_address_string_location (const struct event_location *location);
+  get_address_string_location (const location_spec *locspec);
 
 /* Create a new probe location.  */
 
-extern event_location_up new_probe_location (std::string &&probe);
+extern location_spec_up new_probe_location_spec (std::string &&probe);
 
-/* Return the probe location (a string) of the given event_location
-   (which must be of type PROBE_LOCATION).  */
+/* Return the probe location spec string of the given location_spec,
+   which must be of type PROBE_LOCATION_SPEC.  */
 
 extern const char *
-  get_probe_location (const struct event_location *location);
+  get_probe_location_spec_string (const location_spec *locspec);
 
 /* Initialize the given explicit location.  */
 
 extern void
-  initialize_explicit_location (struct explicit_location *explicit_loc);
+  initialize_explicit_location (explicit_location *locspec);
 
 /* Create a new explicit location.  If not NULL, EXPLICIT is checked for
    validity.  If invalid, an exception is thrown.  */
 
-extern event_location_up
-  new_explicit_location (const struct explicit_location *explicit_loc);
+extern location_spec_up
+  new_explicit_location_spec (const explicit_location *locspec);
 
-/* Return the explicit location of the given event_location
-   (which must be of type EXPLICIT_LOCATION).  */
+/* Return the explicit location spec of the given location_spec, which
+   must be of type EXPLICIT_LOCATION.  */
 
 extern struct explicit_location *
-  get_explicit_location (struct event_location *location);
+  get_explicit_location (location_spec *locspec);
 
 /* A const version of the above.  */
 
-extern const struct explicit_location *
-  get_explicit_location_const (const struct event_location *location);
+extern const explicit_location *
+  get_explicit_location_const (const location_spec *locspec);
 
-/* Return a copy of the given SRC location.  */
+/* Return a copy of the given SRC location spec.  */
 
-extern event_location_up
-  copy_event_location (const struct event_location *src);
+extern location_spec_up copy_location_spec (const location_spec *src);
 
-/* Attempt to convert the input string in *ARGP into an event_location.
+/* Attempt to convert the input string in *ARGP into a location_spec.
    ARGP is advanced past any processed input.  Always returns a non-nullptr
-   event_location unique pointer object.
+   location_spec unique pointer object.
 
    This function may call error() if *ARGP looks like properly formed, but
    invalid, input, e.g., if it is called with missing argument parameters
    or invalid options.
 
    This function is intended to be used by CLI commands and will parse
-   explicit locations in a CLI-centric way.  Other interfaces should use
-   string_to_event_location_basic if they want to maintain support for
-   legacy specifications of probe, address, and linespec locations.
+   explicit location specs in a CLI-centric way.  Other interfaces should use
+   string_to_location_spec_basic if they want to maintain support for
+   legacy specifications of probe, address, and linespec location specs.
 
    MATCH_TYPE should be either WILD or FULL.  If -q/--qualified is specified
    in the input string, it will take precedence over this parameter.  */
 
-extern event_location_up string_to_event_location
+extern location_spec_up string_to_location_spec
   (const char **argp, const struct language_defn *language,
    symbol_name_match_type match_type = symbol_name_match_type::WILD);
 
-/* Like string_to_event_location, but does not attempt to parse
-   explicit locations.  MATCH_TYPE indicates how function names should
-   be matched.  */
+/* Like string_to_location_spec, but does not attempt to parse
+   explicit location specs.  MATCH_TYPE indicates how function names
+   should be matched.  */
 
-extern event_location_up
-  string_to_event_location_basic (const char **argp,
-				  const struct language_defn *language,
-				  symbol_name_match_type match_type);
+extern location_spec_up
+  string_to_location_spec_basic (const char **argp,
+				 const struct language_defn *language,
+				 symbol_name_match_type match_type);
 
-/* Structure filled in by string_to_explicit_location to aid the
+/* Structure filled in by string_to_explicit_location_spec to aid the
    completer.  */
 struct explicit_completion_info
 {
@@ -249,35 +249,34 @@ struct explicit_completion_info
   const char *quoted_arg_start = NULL;
   const char *quoted_arg_end = NULL;
 
-  /* True if we saw an explicit location option, as opposed to only
-     flags that affect both explicit locations and linespecs, like
-     "-qualified".  */
-  bool saw_explicit_location_option = false;
+  /* True if we saw an explicit location spec option, as opposed to
+     only flags that affect both explicit location specs and
+     linespecs, like "-qualified".  */
+  bool saw_explicit_location_spec_option = false;
 };
 
-/* Attempt to convert the input string in *ARGP into an explicit location.
-   ARGP is advanced past any processed input.  Returns an event_location
-   (malloc'd) if an explicit location was successfully found in *ARGP,
-   NULL otherwise.
+/* Attempt to convert the input string in *ARGP into an explicit
+   location spec.  ARGP is advanced past any processed input.  Returns
+   a location_spec (malloc'd) if an explicit location spec was
+   successfully found in *ARGP, NULL otherwise.
 
    If COMPLETION_INFO is NULL, this function may call error() if *ARGP
    looks like improperly formed input, e.g., if it is called with
    missing argument parameters or invalid options.  If COMPLETION_INFO
    is not NULL, this function will not throw any exceptions.  */
 
-extern event_location_up
-  string_to_explicit_location (const char **argp,
-			       const struct language_defn *language,
-			       explicit_completion_info *completion_info);
+extern location_spec_up
+  string_to_explicit_location_spec (const char **argp,
+				    const struct language_defn *language,
+				    explicit_completion_info *completion_info);
 
-/* A convenience function for testing for unset locations.  */
+/* A convenience function for testing for unset location specs.  */
 
-extern int event_location_empty_p (const struct event_location *location);
+extern int location_spec_empty_p (const location_spec *locspec);
 
-/* Set the location's string representation.  */
+/* Set the location specs's string representation.  */
 
-extern void
-  set_event_location_string (struct event_location *location,
-			     std::string &&string);
+extern void set_location_spec_string (struct location_spec *locspec,
+				      std::string &&string);
 
 #endif /* LOCATION_H */
diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c
index d4a7562b281..dab0a471abc 100644
--- a/gdb/mi/mi-cmd-break.c
+++ b/gdb/mi/mi-cmd-break.c
@@ -179,7 +179,7 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
   int tracepoint = 0;
   symbol_name_match_type match_type = symbol_name_match_type::WILD;
   enum bptype type_wanted;
-  event_location_up location;
+  location_spec_up locspec;
   const struct breakpoint_ops *ops;
   int is_explicit = 0;
   struct explicit_location explicit_loc;
@@ -322,7 +322,7 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
 	 A simulator or an emulator could conceivably implement fast
 	 regular non-jump based tracepoints.  */
       type_wanted = hardware ? bp_fast_tracepoint : bp_tracepoint;
-      ops = breakpoint_ops_for_event_location (nullptr, true);
+      ops = breakpoint_ops_for_location_spec (nullptr, true);
     }
   else if (dprintf)
     {
@@ -348,17 +348,17 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
 
       explicit_loc.func_name_match_type = match_type;
 
-      location = new_explicit_location (&explicit_loc);
+      locspec = new_explicit_location_spec (&explicit_loc);
     }
   else
     {
-      location = string_to_event_location_basic (&address, current_language,
-						 match_type);
+      locspec = string_to_location_spec_basic (&address, current_language,
+					       match_type);
       if (*address)
 	error (_("Garbage '%s' at end of location"), address);
     }
 
-  create_breakpoint (get_current_arch (), location.get (), condition, thread,
+  create_breakpoint (get_current_arch (), locspec.get (), condition, thread,
 		     extra_string.c_str (),
 		     force_condition,
 		     0 /* condition and thread are valid.  */,
diff --git a/gdb/probe.c b/gdb/probe.c
index f0a40f5face..0b056eb88db 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -114,7 +114,7 @@ parse_probes_in_pspace (const static_probe_ops *spops,
 /* See definition in probe.h.  */
 
 std::vector<symtab_and_line>
-parse_probes (const struct event_location *location,
+parse_probes (const location_spec *locspec,
 	      struct program_space *search_pspace,
 	      struct linespec_result *canonical)
 {
@@ -122,8 +122,8 @@ parse_probes (const struct event_location *location,
   char *objfile_namestr = NULL, *provider = NULL, *name, *p;
   const char *arg_start, *cs;
 
-  gdb_assert (event_location_type (location) == PROBE_LOCATION);
-  arg_start = get_probe_location (location);
+  gdb_assert (location_spec_type (locspec) == PROBE_LOCATION_SPEC);
+  arg_start = get_probe_location_spec_string (locspec);
 
   cs = arg_start;
   const static_probe_ops *spops = probe_linespec_to_static_ops (&cs);
@@ -204,7 +204,7 @@ parse_probes (const struct event_location *location,
       std::string canon (arg_start, arg_end - arg_start);
       canonical->special_display = 1;
       canonical->pre_expanded = 1;
-      canonical->location = new_probe_location (std::move (canon));
+      canonical->locspec = new_probe_location_spec (std::move (canon));
     }
 
   return result;
diff --git a/gdb/probe.h b/gdb/probe.h
index 5fc4d22a6f4..fe933154663 100644
--- a/gdb/probe.h
+++ b/gdb/probe.h
@@ -22,7 +22,7 @@
 
 #include "symtab.h"
 
-struct event_location;
+struct location_spec;
 struct linespec_result;
 
 /* Structure useful for passing the header names in the method
@@ -263,7 +263,7 @@ struct bound_probe
    throws an error.  */
 
 extern std::vector<symtab_and_line> parse_probes
-  (const struct event_location *loc,
+  (const location_spec *locspec,
    struct program_space *pspace,
    struct linespec_result *canon);
 
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 74de0d90e23..029ced74136 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -412,8 +412,8 @@ bppy_get_location (PyObject *self, void *closure)
       && obj->bp->type != bp_hardware_breakpoint)
     Py_RETURN_NONE;
 
-  const char *str = event_location_to_string (obj->bp->location.get ());
-  if (! str)
+  const char *str = location_spec_to_string (obj->bp->locspec.get ());
+  if (str == nullptr)
     str = "";
   return host_string_to_python_string (str).release ();
 }
@@ -821,7 +821,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	case bp_breakpoint:
 	case bp_hardware_breakpoint:
 	  {
-	    event_location_up location;
+	    location_spec_up locspec;
 	    symbol_name_match_type func_name_match_type
 	      = (qualified != NULL && PyObject_IsTrue (qualified)
 		  ? symbol_name_match_type::FULL
@@ -833,9 +833,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 		  copy_holder (xstrdup (skip_spaces (spec)));
 		const char *copy = copy_holder.get ();
 
-		location  = string_to_event_location (&copy,
-						      current_language,
-						      func_name_match_type);
+		locspec  = string_to_location_spec (&copy,
+						    current_language,
+						    func_name_match_type);
 	      }
 	    else
 	      {
@@ -852,14 +852,14 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 
 		explicit_loc.func_name_match_type = func_name_match_type;
 
-		location = new_explicit_location (&explicit_loc);
+		locspec = new_explicit_location_spec (&explicit_loc);
 	      }
 
-	    const struct breakpoint_ops *ops =
-	      breakpoint_ops_for_event_location (location.get (), false);
+	    const struct breakpoint_ops *ops
+	      = breakpoint_ops_for_location_spec (locspec.get (), false);
 
 	    create_breakpoint (gdbpy_enter::get_gdbarch (),
-			       location.get (), NULL, -1, NULL, false,
+			       locspec.get (), NULL, -1, NULL, false,
 			       0,
 			       temporary_bp, type,
 			       0,
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index df54d3643ab..c80096f6810 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -296,10 +296,10 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   try
     {
       /* Set a breakpoint on the return address.  */
-      event_location_up location
-	= new_address_location (get_frame_pc (prev_frame), NULL, 0);
+      location_spec_up locspec
+	= new_address_location_spec (get_frame_pc (prev_frame), NULL, 0);
       create_breakpoint (gdbpy_enter::get_gdbarch (),
-			 location.get (), NULL, thread, NULL, false,
+			 locspec.get (), NULL, thread, NULL, false,
 			 0,
 			 1 /*temp_flag*/,
 			 bp_breakpoint,
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 11aaa7ae778..ae8bbe6f5e3 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -866,7 +866,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
   const char *arg = NULL;
   gdbpy_ref<> result;
   gdbpy_ref<> unparsed;
-  event_location_up location;
+  location_spec_up locspec;
 
   if (! PyArg_ParseTuple (args, "|s", &arg))
     return NULL;
@@ -881,17 +881,17 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
     }
 
   if (arg != NULL)
-    location = string_to_event_location_basic (&arg, current_language,
-					       symbol_name_match_type::WILD);
+    locspec = string_to_location_spec_basic (&arg, current_language,
+					     symbol_name_match_type::WILD);
 
   std::vector<symtab_and_line> decoded_sals;
   symtab_and_line def_sal;
   gdb::array_view<symtab_and_line> sals;
   try
     {
-      if (location != NULL)
+      if (locspec != NULL)
 	{
-	  decoded_sals = decode_line_1 (location.get (), 0, NULL, NULL, 0);
+	  decoded_sals = decode_line_1 (locspec.get (), 0, NULL, NULL, 0);
 	  sals = decoded_sals;
 	}
       else
diff --git a/gdb/remote.c b/gdb/remote.c
index f41e6ce82c2..7bcd6e3e336 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -13368,15 +13368,15 @@ remote_target::download_tracepoint (struct bp_location *loc)
 
   if (packet_support (PACKET_TracepointSource) == PACKET_ENABLE)
     {
-      if (b->location != NULL)
+      if (b->locspec != nullptr)
 	{
 	  ret = snprintf (buf.data (), buf.size (), "QTDPsrc:");
 
 	  if (ret < 0 || ret >= buf.size ())
 	    error ("%s", err_msg);
 
-	  encode_source_string (b->number, loc->address, "at",
-				event_location_to_string (b->location.get ()),
+	  const char *str = location_spec_to_string (b->locspec.get ());
+	  encode_source_string (b->number, loc->address, "at", str,
 				buf.data () + strlen (buf.data ()),
 				buf.size () - strlen (buf.data ()));
 	  putpkt (buf.data ());
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 44d16b55bca..75ac0cef3b0 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -2477,10 +2477,10 @@ info_scope_command (const char *args_in, int from_tty)
     error (_("requires an argument (function, "
 	     "line or *addr) to define a scope"));
 
-  event_location_up location = string_to_event_location (&args,
-							 current_language);
+  location_spec_up locspec = string_to_location_spec (&args,
+						      current_language);
   std::vector<symtab_and_line> sals
-    = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE,
+    = decode_line_1 (locspec.get (), DECODE_LINE_FUNFIRSTLINE,
 		     NULL, NULL, 0);
   if (sals.empty ())
     {
-- 
2.36.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 2/7] Eliminate the two-level data structures behind location_specs
  2022-05-27 18:02 [PATCH 0/7] location -> location spec Pedro Alves
  2022-05-27 18:02 ` [PATCH 1/7] event_location -> location_spec Pedro Alves
@ 2022-05-27 18:02 ` Pedro Alves
  2022-05-30 15:09   ` Pedro Alves
  2022-05-27 18:02 ` [PATCH 3/7] Eliminate copy_location_spec Pedro Alves
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 14+ messages in thread
From: Pedro Alves @ 2022-05-27 18:02 UTC (permalink / raw)
  To: gdb-patches

Currently, there's the location_spec hierarchy, and then some
location_spec subclasses have their own struct type holding all their
data fields.

I.e., there is this:

 location_spec
   explicit_location_spec
   linespec_location_spec
   address_location_spec
   probe_location_spec

and then these separate types:

  explicit_location
  linespec_location

where:

  explicit_location_spec
     has-a explicit_location
  linespec_location_spec
     has-a linespec_location

This patch eliminates explicit_location and linespec_location,
inlining their members in the corresponding location_spec type.

The location_spec subclasses were the ones currently defined in
location.c, so they are moved to the header.  Since the definitions of
the classes are now visible, we no longer need location_spec_deleter.

Some constructors that are used for cloning location_specs, like:

  explicit explicit_location_spec (const struct explicit_location *loc)

... were converted to proper copy ctors.

In the process, initialize_explicit_location is eliminated, and some
functions that returned the "data type behind a locspec", like
get_linespec_location are converted to downcast functions, like
as_linespec_location_spec.

Change-Id: Ia31ccef9382b25a52b00fa878c8df9b8cf2a6c5a
---
 gdb/break-catch-throw.c    |   9 +-
 gdb/breakpoint.c           |  44 ++--
 gdb/completer.c            |   6 +-
 gdb/linespec.c             | 106 ++++----
 gdb/location.c             | 512 ++++++++++++++-----------------------
 gdb/location.h             | 233 ++++++++++++-----
 gdb/mi/mi-cmd-break.c      |  25 +-
 gdb/probe.c                |   2 +-
 gdb/python/py-breakpoint.c |  21 +-
 9 files changed, 451 insertions(+), 507 deletions(-)

diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index 3ef4b972d4f..2eb24f3b76c 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -225,12 +225,9 @@ exception_catchpoint::re_set ()
 	 catchpoint mode.  */
       try
 	{
-	  struct explicit_location explicit_loc;
-
-	  initialize_explicit_location (&explicit_loc);
-	  explicit_loc.function_name
-	    = ASTRDUP (exception_functions[kind].function);
-	  location_spec_up locspec = new_explicit_location_spec (&explicit_loc);
+	  location_spec_up locspec
+	    = (new_explicit_location_spec_function
+	       (exception_functions[kind].function));
 	  sals = this->decode_location_spec (locspec.get (), filter_pspace);
 	}
       catch (const gdb_exception_error &ex)
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 2c86f275286..cdab60332ec 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3364,7 +3364,6 @@ create_overlay_event_breakpoint (void)
       struct breakpoint *b;
       struct breakpoint_objfile_data *bp_objfile_data;
       CORE_ADDR addr;
-      struct explicit_location explicit_loc;
 
       bp_objfile_data = get_breakpoint_objfile_data (objfile);
 
@@ -3388,9 +3387,7 @@ create_overlay_event_breakpoint (void)
       addr = bp_objfile_data->overlay_msym.value_address ();
       b = create_internal_breakpoint (objfile->arch (), addr,
 				      bp_overlay_event);
-      initialize_explicit_location (&explicit_loc);
-      explicit_loc.function_name = ASTRDUP (func_name);
-      b->locspec = new_explicit_location_spec (&explicit_loc);
+      b->locspec = new_explicit_location_spec_function (func_name);
 
       if (overlay_debugging == ovly_auto)
 	{
@@ -3473,7 +3470,6 @@ create_longjmp_master_breakpoint_names (objfile *objfile)
       struct breakpoint *b;
       const char *func_name;
       CORE_ADDR addr;
-      struct explicit_location explicit_loc;
 
       if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
 	continue;
@@ -3495,9 +3491,7 @@ create_longjmp_master_breakpoint_names (objfile *objfile)
 
       addr = bp_objfile_data->longjmp_msym[i].value_address ();
       b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master);
-      initialize_explicit_location (&explicit_loc);
-      explicit_loc.function_name = ASTRDUP (func_name);
-      b->locspec = new_explicit_location_spec (&explicit_loc);
+      b->locspec = new_explicit_location_spec_function (func_name);
       b->enable_state = bp_disabled;
       installed_bp++;
     }
@@ -3553,7 +3547,6 @@ create_std_terminate_master_breakpoint (void)
 	{
 	  struct breakpoint *b;
 	  struct breakpoint_objfile_data *bp_objfile_data;
-	  struct explicit_location explicit_loc;
 
 	  bp_objfile_data = get_breakpoint_objfile_data (objfile);
 
@@ -3578,9 +3571,7 @@ create_std_terminate_master_breakpoint (void)
 	  addr = bp_objfile_data->terminate_msym.value_address ();
 	  b = create_internal_breakpoint (objfile->arch (), addr,
 					  bp_std_terminate_master);
-	  initialize_explicit_location (&explicit_loc);
-	  explicit_loc.function_name = ASTRDUP (func_name);
-	  b->locspec = new_explicit_location_spec (&explicit_loc);
+	  b->locspec = new_explicit_location_spec_function (func_name);
 	  b->enable_state = bp_disabled;
 	}
     }
@@ -3648,7 +3639,6 @@ create_exception_master_breakpoint_hook (objfile *objfile)
   struct gdbarch *gdbarch;
   struct breakpoint_objfile_data *bp_objfile_data;
   CORE_ADDR addr;
-  struct explicit_location explicit_loc;
 
   bp_objfile_data = get_breakpoint_objfile_data (objfile);
 
@@ -3675,9 +3665,7 @@ create_exception_master_breakpoint_hook (objfile *objfile)
   addr = gdbarch_convert_from_func_ptr_addr
     (gdbarch, addr, current_inferior ()->top_target ());
   b = create_internal_breakpoint (gdbarch, addr, bp_exception_master);
-  initialize_explicit_location (&explicit_loc);
-  explicit_loc.function_name = ASTRDUP (func_name);
-  b->locspec = new_explicit_location_spec (&explicit_loc);
+  b->locspec = new_explicit_location_spec_function (func_name);
   b->enable_state = bp_disabled;
 
   return true;
@@ -8467,7 +8455,7 @@ parse_breakpoint_sals (location_spec *locspec,
 
   if (location_spec_type (locspec) == LINESPEC_LOCATION_SPEC)
     {
-      const char *spec = get_linespec_location (locspec)->spec_string;
+      const char *spec = as_linespec_location_spec (locspec)->spec_string;
 
       if (spec == NULL)
 	{
@@ -8518,7 +8506,7 @@ parse_breakpoint_sals (location_spec *locspec,
       const char *spec = NULL;
 
       if (location_spec_type (locspec) == LINESPEC_LOCATION_SPEC)
-	spec = get_linespec_location (locspec)->spec_string;
+	spec = as_linespec_location_spec (locspec)->spec_string;
 
       if (!cursal.symtab
 	  || (spec != NULL
@@ -12005,7 +11993,7 @@ strace_marker_create_sals_from_location_spec (location_spec *locspec,
   struct linespec_sals lsal;
   const char *arg_start, *arg;
 
-  arg = arg_start = get_linespec_location (locspec)->spec_string;
+  arg = arg_start = as_linespec_location_spec (locspec)->spec_string;
   lsal.sals = decode_static_tracepoint_spec (&arg);
 
   std::string str (arg_start, arg - arg_start);
@@ -12073,7 +12061,7 @@ std::vector<symtab_and_line>
 static_marker_tracepoint::decode_location_spec (location_spec *locspec,
 						program_space *search_pspace)
 {
-  const char *s = get_linespec_location (locspec)->spec_string;
+  const char *s = as_linespec_location_spec (locspec)->spec_string;
 
   std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s);
   if (sals.size () > static_trace_marker_id_idx)
@@ -12381,7 +12369,6 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
 	  struct symbol *sym;
 	  struct static_tracepoint_marker *tpmarker;
 	  struct ui_out *uiout = current_uiout;
-	  struct explicit_location explicit_loc;
 
 	  tpmarker = &markers[0];
 
@@ -12418,13 +12405,14 @@ 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;
 
-	  b->locspec.reset (nullptr);
-	  initialize_explicit_location (&explicit_loc);
-	  explicit_loc.source_filename
-	    = ASTRDUP (symtab_to_filename_for_display (sal2.symtab));
-	  explicit_loc.line_offset.offset = b->loc->line_number;
-	  explicit_loc.line_offset.sign = LINE_OFFSET_NONE;
-	  b->locspec = new_explicit_location_spec (&explicit_loc);
+	  std::unique_ptr<explicit_location_spec> els
+	    (new explicit_location_spec ());
+	  els->source_filename
+	    = xstrdup (symtab_to_filename_for_display (sal2.symtab));
+	  els->line_offset.offset = b->loc->line_number;
+	  els->line_offset.sign = LINE_OFFSET_NONE;
+
+	  b->locspec.reset (els.release ());
 
 	  /* Might be nice to check if function changed, and warn if
 	     so.  */
diff --git a/gdb/completer.c b/gdb/completer.c
index 2ec8d2eb594..b68b6de2057 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -712,8 +712,8 @@ collect_explicit_location_matches (completion_tracker &tracker,
 				   const char *word,
 				   const struct language_defn *language)
 {
-  const struct explicit_location *explicit_loc
-    = get_explicit_location (locspec);
+  const explicit_location_spec *explicit_loc
+    = as_explicit_location_spec (locspec);
 
   /* True if the option expects an argument.  */
   bool needs_arg = true;
@@ -1008,7 +1008,7 @@ location_completer (struct cmd_list_element *ignore,
 	  text = copy;
 
 	  symbol_name_match_type match_type
-	    = get_explicit_location (locspec.get ())->func_name_match_type;
+	    = as_explicit_location_spec (locspec.get ())->func_name_match_type;
 	  complete_address_and_linespec_locations (tracker, text, match_type);
 	}
     }
diff --git a/gdb/linespec.c b/gdb/linespec.c
index b12f5c87733..063944bb9a1 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -94,8 +94,8 @@ struct address_entry
 
 struct linespec
 {
-  /* An explicit location describing the SaLs.  */
-  struct explicit_location explicit_loc {};
+  /* An explicit location spec describing the SaLs.  */
+  explicit_location_spec explicit_loc;
 
   /* The list of symtabs to search to which to limit the search.
 
@@ -342,8 +342,8 @@ struct linespec_parser
   struct completion_tracker *completion_tracker = nullptr;
 };
 
-/* A convenience macro for accessing the explicit location result of
-   the parser.  */
+/* A convenience macro for accessing the explicit location spec result
+   of the parser.  */
 #define PARSER_EXPLICIT(PPTR) (&PARSER_RESULT ((PPTR))->explicit_loc)
 
 /* Prototypes for local functions.  */
@@ -1990,18 +1990,14 @@ linespec_parse_basic (linespec_parser *parser)
 static void
 canonicalize_linespec (struct linespec_state *state, const linespec *ls)
 {
-  location_spec *canon;
-  struct explicit_location *explicit_loc;
-
   /* If canonicalization was not requested, no need to do anything.  */
   if (!state->canonical)
     return;
 
   /* Save everything as an explicit location.  */
-  state->canonical->locspec
-    = new_explicit_location_spec (&ls->explicit_loc);
-  canon = state->canonical->locspec.get ();
-  explicit_loc = get_explicit_location (canon);
+  state->canonical->locspec = ls->explicit_loc.clone ();
+  explicit_location_spec *explicit_loc
+    = as_explicit_location_spec (state->canonical->locspec.get ());
 
   if (explicit_loc->label_name != NULL)
     {
@@ -2019,8 +2015,7 @@ canonicalize_linespec (struct linespec_state *state, const linespec *ls)
   /* If this location originally came from a linespec, save a string
      representation of it for display and saving to file.  */
   if (state->is_linespec)
-    set_location_spec_string (canon,
-			      explicit_location_to_linespec (explicit_loc));
+    set_location_spec_string (explicit_loc, explicit_loc->to_linespec ());
 }
 
 /* Given a line offset in LS, construct the relevant SALs.  */
@@ -2307,17 +2302,18 @@ convert_linespec_to_sals (struct linespec_state *state, linespec *ls)
   return sals;
 }
 
-/* Build RESULT from the explicit location components SOURCE_FILENAME,
-   FUNCTION_NAME, LABEL_NAME and LINE_OFFSET.  */
+/* Build RESULT from the explicit location spec components
+   SOURCE_FILENAME, FUNCTION_NAME, LABEL_NAME and LINE_OFFSET.  */
 
 static void
-convert_explicit_location_to_linespec (struct linespec_state *self,
-				       linespec *result,
-				       const char *source_filename,
-				       const char *function_name,
-				       symbol_name_match_type fname_match_type,
-				       const char *label_name,
-				       struct line_offset line_offset)
+convert_explicit_location_spec_to_linespec
+  (struct linespec_state *self,
+   linespec *result,
+   const char *source_filename,
+   const char *function_name,
+   symbol_name_match_type fname_match_type,
+   const char *label_name,
+   struct line_offset line_offset)
 {
   std::vector<bound_minimal_symbol> minimal_symbols;
 
@@ -2382,16 +2378,17 @@ convert_explicit_location_to_linespec (struct linespec_state *self,
 /* Convert the explicit location EXPLICIT_LOC into SaLs.  */
 
 static std::vector<symtab_and_line>
-convert_explicit_location_to_sals (struct linespec_state *self,
-				   linespec *result,
-				   const struct explicit_location *explicit_loc)
+convert_explicit_location_spec_to_sals
+  (struct linespec_state *self,
+   linespec *result,
+   const explicit_location_spec *explicit_spec)
 {
-  convert_explicit_location_to_linespec (self, result,
-					 explicit_loc->source_filename,
-					 explicit_loc->function_name,
-					 explicit_loc->func_name_match_type,
-					 explicit_loc->label_name,
-					 explicit_loc->line_offset);
+  convert_explicit_location_spec_to_linespec (self, result,
+					      explicit_spec->source_filename,
+					      explicit_spec->function_name,
+					      explicit_spec->func_name_match_type,
+					      explicit_spec->label_name,
+					      explicit_spec->line_offset);
   return convert_linespec_to_sals (self, result);
 }
 
@@ -2694,10 +2691,6 @@ linespec_state_destructor (struct linespec_state *self)
 
 linespec_parser::~linespec_parser ()
 {
-  xfree (PARSER_EXPLICIT (this)->source_filename);
-  xfree (PARSER_EXPLICIT (this)->label_name);
-  xfree (PARSER_EXPLICIT (this)->function_name);
-
   linespec_state_destructor (PARSER_STATE (this));
 }
 
@@ -2855,12 +2848,12 @@ linespec_complete_label (completion_tracker &tracker,
 
   try
     {
-      convert_explicit_location_to_linespec (PARSER_STATE (&parser),
-					     PARSER_RESULT (&parser),
-					     source_filename,
-					     function_name,
-					     func_name_match_type,
-					     NULL, unknown_offset);
+      convert_explicit_location_spec_to_linespec (PARSER_STATE (&parser),
+						  PARSER_RESULT (&parser),
+						  source_filename,
+						  function_name,
+						  func_name_match_type,
+						  NULL, unknown_offset);
     }
   catch (const gdb_exception_error &ex)
     {
@@ -3073,24 +3066,18 @@ location_spec_to_sals (linespec_parser *parser,
     {
     case LINESPEC_LOCATION_SPEC:
       {
+	const linespec_location_spec *ls = as_linespec_location_spec (locspec);
 	PARSER_STATE (parser)->is_linespec = 1;
-	try
-	  {
-	    const linespec_location *ls = get_linespec_location (locspec);
-	    result = parse_linespec (parser,
-				     ls->spec_string, ls->match_type);
-	  }
-	catch (const gdb_exception_error &except)
-	  {
-	    throw;
-	  }
+	result = parse_linespec (parser, ls->spec_string, ls->match_type);
       }
       break;
 
     case ADDRESS_LOCATION_SPEC:
       {
-	const char *addr_string = get_address_string_location (locspec);
-	CORE_ADDR addr = get_address_location (locspec);
+	const address_location_spec *addr_spec
+	  = as_address_location_spec (locspec);
+	const char *addr_string = addr_spec->to_string ();
+	CORE_ADDR addr;
 
 	if (addr_string != NULL)
 	  {
@@ -3099,6 +3086,8 @@ location_spec_to_sals (linespec_parser *parser,
 	      PARSER_STATE (parser)->canonical->locspec
 		= copy_location_spec (locspec);
 	  }
+	else
+	  addr = addr_spec->address;
 
 	result = convert_address_location_to_sals (PARSER_STATE (parser),
 						   addr);
@@ -3107,12 +3096,11 @@ location_spec_to_sals (linespec_parser *parser,
 
     case EXPLICIT_LOCATION_SPEC:
       {
-	const struct explicit_location *explicit_loc;
-
-	explicit_loc = get_explicit_location_const (locspec);
-	result = convert_explicit_location_to_sals (PARSER_STATE (parser),
-						    PARSER_RESULT (parser),
-						    explicit_loc);
+	const explicit_location_spec *explicit_locspec
+	  = as_explicit_location_spec (locspec);
+	result = convert_explicit_location_spec_to_sals (PARSER_STATE (parser),
+							 PARSER_RESULT (parser),
+							 explicit_locspec);
       }
       break;
 
diff --git a/gdb/location.c b/gdb/location.c
index a52503b2ff3..4d0b60ff9c7 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -29,280 +29,187 @@
 #include <ctype.h>
 #include <string.h>
 
-static std::string explicit_location_to_string
-     (const struct explicit_location *explicit_loc);
+static std::string
+  explicit_to_string_internal (bool as_linespec,
+			       const explicit_location_spec *explicit_loc);
+
+/* Return a xstrdup of STR if not NULL, otherwise return NULL.  */
 
-/* The base class for all an location specs used to match actual
-   locations in the inferior.  */
+static char *
+maybe_xstrdup (const char *str)
+{
+  return (str != nullptr ? xstrdup (str) : nullptr);
+}
+
+probe_location_spec::probe_location_spec (std::string &&probe)
+  : location_spec (PROBE_LOCATION_SPEC, std::move (probe))
+{
+}
 
-struct location_spec
+location_spec_up
+probe_location_spec::clone () const
 {
-  virtual ~location_spec () = default;
-
-  /* Clone this object.  */
-  virtual location_spec_up clone () const = 0;
-
-  /* Return true if this location spec is empty, false otherwise.  */
-  virtual bool empty_p () const = 0;
-
-  /* Return a string representation of this location.  */
-  const char *to_string () const
-  {
-    if (as_string.empty ())
-      as_string = compute_string ();
-    if (as_string.empty ())
-      return nullptr;
-    return as_string.c_str ();
-  }
-
-  DISABLE_COPY_AND_ASSIGN (location_spec);
-
-  /* The type of this location specification.  */
-  enum location_spec_type type;
-
-  /* Cached string representation of this location spec.  This is
-     used, e.g., to save location specs to file.  */
-  mutable std::string as_string;
-
-protected:
-
-  explicit location_spec (enum location_spec_type t)
-    : type (t)
-  {
-  }
-
-  location_spec (enum location_spec_type t, std::string &&str)
-    : type (t),
-      as_string (std::move (str))
-  {
-  }
-
-  explicit location_spec (const location_spec *to_clone)
-    : type (to_clone->type),
-      as_string (to_clone->as_string)
-  {
-  }
-
-  /* Compute the string representation of this object.  This is called
-     by to_string when needed.  */
-  virtual std::string compute_string () const = 0;
-};
-
-/* A probe.  */
-struct probe_location_spec : public location_spec
+  return location_spec_up (new probe_location_spec (*this));
+}
+
+bool
+probe_location_spec::empty_p () const
 {
-  explicit probe_location_spec (std::string &&probe)
-    : location_spec (PROBE_LOCATION_SPEC, std::move (probe))
-  {
-  }
-
-  location_spec_up clone () const override
-  {
-    return location_spec_up (new probe_location_spec (this));
-  }
-
-  bool empty_p () const override
-  {
-    return false;
-  }
-
-protected:
-
-  explicit probe_location_spec (const probe_location_spec *to_clone)
-    : location_spec (to_clone)
-  {
-  }
-
-  std::string compute_string () const override
-  {
-    return std::move (as_string);
-  }
-};
+  return false;
+}
+
+std::string probe_location_spec::compute_string () const
+{
+  return std::move (as_string);
+}
 
 /* A "normal" linespec.  */
-struct linespec_location_spec : public location_spec
+linespec_location_spec::linespec_location_spec
+  (const char **linespec, symbol_name_match_type match_type_)
+  : location_spec (LINESPEC_LOCATION_SPEC),
+    match_type (match_type_)
 {
-  linespec_location_spec (const char **linespec,
-			  symbol_name_match_type match_type)
-    : location_spec (LINESPEC_LOCATION_SPEC)
-  {
-    linespec_location.match_type = match_type;
-    if (*linespec != NULL)
-      {
-	const char *p;
-	const char *orig = *linespec;
-
-	linespec_lex_to_end (linespec);
-	p = remove_trailing_whitespace (orig, *linespec);
-
-	/* If there is no valid linespec then this will leave the
-	   spec_string as nullptr.  This behaviour is relied on in the
-	   breakpoint setting code, where spec_string being nullptr means
-	   to use the default breakpoint location.  */
-	if ((p - orig) > 0)
-	  linespec_location.spec_string = savestring (orig, p - orig);
-      }
-  }
-
-  ~linespec_location_spec ()
-  {
-    xfree (linespec_location.spec_string);
-  }
-
-  location_spec_up clone () const override
-  {
-    return location_spec_up (new linespec_location_spec (this));
-  }
-
-  bool empty_p () const override
-  {
-    return false;
-  }
-
-  struct linespec_location linespec_location {};
-
-protected:
-
-  explicit linespec_location_spec (const linespec_location_spec *to_clone)
-    : location_spec (to_clone),
-      linespec_location (to_clone->linespec_location)
-  {
-    if (linespec_location.spec_string != nullptr)
-      linespec_location.spec_string = xstrdup (linespec_location.spec_string);
-  }
-
-  std::string compute_string () const override
-  {
-    if (linespec_location.spec_string != nullptr)
-      {
-	const struct linespec_location *ls = &linespec_location;
-	if (ls->match_type == symbol_name_match_type::FULL)
-	  return std::string ("-qualified ") + ls->spec_string;
-	else
-	  return ls->spec_string;
-      }
-    return {};
-  }
-};
-
-/* An address in the inferior.  */
-struct address_location_spec : public location_spec
+  if (*linespec != NULL)
+    {
+      const char *p;
+      const char *orig = *linespec;
+
+      linespec_lex_to_end (linespec);
+      p = remove_trailing_whitespace (orig, *linespec);
+
+      /* If there is no valid linespec then this will leave the
+	 spec_string as nullptr.  This behaviour is relied on in the
+	 breakpoint setting code, where spec_string being nullptr means
+	 to use the default breakpoint location.  */
+      if ((p - orig) > 0)
+	spec_string = savestring (orig, p - orig);
+    }
+}
+
+linespec_location_spec::~linespec_location_spec ()
 {
-  address_location_spec (CORE_ADDR addr, const char *addr_string,
-			 int addr_string_len)
-    : location_spec (ADDRESS_LOCATION_SPEC),
-      address (addr)
-  {
-    if (addr_string != nullptr)
-      as_string = std::string (addr_string, addr_string_len);
-  }
-
-  location_spec_up clone () const override
-  {
-    return location_spec_up (new address_location_spec (this));
-  }
-
-  bool empty_p () const override
-  {
-    return false;
-  }
-
-  CORE_ADDR address;
-
-protected:
-
-  address_location_spec (const address_location_spec *to_clone)
-    : location_spec (to_clone),
-      address (to_clone->address)
-  {
-  }
-
-  std::string compute_string () const override
-  {
-    const char *addr_string = core_addr_to_string (address);
-    return std::string ("*") + addr_string;
-  }
-};
-
-/* An explicit location spec.  */
-struct explicit_location_spec : public location_spec
+  xfree (spec_string);
+}
+
+location_spec_up
+linespec_location_spec::clone () const
 {
-  explicit explicit_location_spec (const struct explicit_location *loc)
-    : location_spec (EXPLICIT_LOCATION_SPEC)
-  {
-    copy_loc (loc);
-  }
-
-  ~explicit_location_spec ()
-  {
-    xfree (explicit_loc.source_filename);
-    xfree (explicit_loc.function_name);
-    xfree (explicit_loc.label_name);
-  }
-
-  location_spec_up clone () const override
-  {
-    return location_spec_up (new explicit_location_spec (this));
-  }
-
-  bool empty_p () const override
-  {
-    return (explicit_loc.source_filename == nullptr
-	    && explicit_loc.function_name == nullptr
-	    && explicit_loc.label_name == nullptr
-	    && explicit_loc.line_offset.sign == LINE_OFFSET_UNKNOWN);
-  }
-
-  struct explicit_location explicit_loc;
-
-protected:
-
-  explicit explicit_location_spec (const explicit_location_spec *to_clone)
-    : location_spec (to_clone)
-  {
-    copy_loc (&to_clone->explicit_loc);
-  }
-
-  std::string compute_string () const override
-  {
-    return explicit_location_to_string (&explicit_loc);
-  }
-
-private:
-
-  void copy_loc (const struct explicit_location *loc)
-  {
-    initialize_explicit_location (&explicit_loc);
-    if (loc != nullptr)
-      {
-	explicit_loc.func_name_match_type = loc->func_name_match_type;
-	if (loc->source_filename != nullptr)
-	  explicit_loc.source_filename = xstrdup (loc->source_filename);
-	if (loc->function_name != nullptr)
-	  explicit_loc.function_name = xstrdup (loc->function_name);
-	if (loc->label_name != nullptr)
-	  explicit_loc.label_name = xstrdup (loc->label_name);
-	explicit_loc.line_offset = loc->line_offset;
-      }
-  }
-};
+  return location_spec_up (new linespec_location_spec (*this));
+}
 
-/* See description in location.h.  */
+bool
+linespec_location_spec::empty_p () const
+{
+  return false;
+}
 
-enum location_spec_type
-location_spec_type (const location_spec *locspec)
+linespec_location_spec::linespec_location_spec
+  (const linespec_location_spec &other)
+  : location_spec (other),
+    match_type (other.match_type),
+    spec_string (maybe_xstrdup (other.spec_string))
 {
-  return locspec->type;
+}
+
+std::string
+linespec_location_spec::compute_string () const
+{
+  if (spec_string != nullptr)
+    {
+      if (match_type == symbol_name_match_type::FULL)
+	return std::string ("-qualified ") + spec_string;
+      else
+	return spec_string;
+    }
+  return {};
+}
+
+address_location_spec::address_location_spec (CORE_ADDR addr,
+					      const char *addr_string,
+					      int addr_string_len)
+  : location_spec (ADDRESS_LOCATION_SPEC),
+    address (addr)
+{
+  if (addr_string != nullptr)
+    as_string = std::string (addr_string, addr_string_len);
+}
+
+location_spec_up
+address_location_spec::clone () const
+{
+  return location_spec_up (new address_location_spec (*this));
+}
+
+bool
+address_location_spec::empty_p () const
+{
+  return false;
+}
+
+address_location_spec::address_location_spec
+  (const address_location_spec &other)
+  : location_spec (other),
+    address (other.address)
+{
+}
+
+std::string
+address_location_spec::compute_string () const
+{
+  const char *addr_string = core_addr_to_string (address);
+  return std::string ("*") + addr_string;
+}
+
+explicit_location_spec::explicit_location_spec ()
+  : location_spec (EXPLICIT_LOCATION_SPEC)
+{
+}
+
+explicit_location_spec::~explicit_location_spec ()
+{
+  xfree (source_filename);
+  xfree (function_name);
+  xfree (label_name);
+}
+
+explicit_location_spec::explicit_location_spec
+  (const explicit_location_spec &other)
+  : location_spec (other),
+    source_filename (maybe_xstrdup (other.source_filename)),
+    function_name (maybe_xstrdup (other.function_name)),
+    func_name_match_type (other.func_name_match_type),
+    label_name (maybe_xstrdup (other.label_name)),
+    line_offset (other.line_offset)
+{
+}
+
+location_spec_up
+explicit_location_spec::clone () const
+{
+  return location_spec_up (new explicit_location_spec (*this));
+}
+
+bool
+explicit_location_spec::empty_p () const
+{
+  return (source_filename == nullptr
+	  && function_name == nullptr
+	  && label_name == nullptr
+	  && line_offset.sign == LINE_OFFSET_UNKNOWN);
+}
+
+std::string
+explicit_location_spec::compute_string () const
+{
+  return explicit_to_string_internal (false, this);
 }
 
 /* See description in location.h.  */
 
-void
-initialize_explicit_location (struct explicit_location *explicit_loc)
+enum location_spec_type
+location_spec_type (const location_spec *locspec)
 {
-  memset (explicit_loc, 0, sizeof (struct explicit_location));
-  explicit_loc->line_offset.sign = LINE_OFFSET_UNKNOWN;
-  explicit_loc->func_name_match_type = symbol_name_match_type::WILD;
+  return locspec->type;
 }
 
 /* See description in location.h.  */
@@ -317,11 +224,11 @@ new_linespec_location_spec (const char **linespec,
 
 /* See description in location.h.  */
 
-const linespec_location *
-get_linespec_location (const location_spec *locspec)
+const linespec_location_spec *
+as_linespec_location_spec (const location_spec *locspec)
 {
   gdb_assert (locspec->type == LINESPEC_LOCATION_SPEC);
-  return &((linespec_location_spec *) locspec)->linespec_location;
+  return static_cast<const linespec_location_spec *> (locspec);
 }
 
 /* See description in location.h.  */
@@ -336,20 +243,11 @@ new_address_location_spec (CORE_ADDR addr, const char *addr_string,
 
 /* See description in location.h.  */
 
-CORE_ADDR
-get_address_location (const location_spec *locspec)
+const address_location_spec *
+as_address_location_spec (const location_spec *locspec)
 {
   gdb_assert (locspec->type == ADDRESS_LOCATION_SPEC);
-  return ((address_location_spec *) locspec)->address;
-}
-
-/* See description in location.h.  */
-
-const char *
-get_address_string_location (const location_spec *locspec)
-{
-  gdb_assert (locspec->type == ADDRESS_LOCATION_SPEC);
-  return locspec->to_string ();
+  return static_cast<const address_location_spec *> (locspec);
 }
 
 /* See description in location.h.  */
@@ -362,37 +260,29 @@ new_probe_location_spec (std::string &&probe)
 
 /* See description in location.h.  */
 
-const char *
-get_probe_location_spec_string (const location_spec *locspec)
+const probe_location_spec *
+as_probe_location_spec (const location_spec *locspec)
 {
   gdb_assert (locspec->type == PROBE_LOCATION_SPEC);
-  return locspec->to_string ();
-}
-
-/* See description in location.h.  */
-
-location_spec_up
-new_explicit_location_spec (const explicit_location *explicit_loc)
-{
-  return location_spec_up (new explicit_location_spec (explicit_loc));
+  return static_cast<const probe_location_spec *> (locspec);
 }
 
 /* See description in location.h.  */
 
-struct explicit_location *
-get_explicit_location (location_spec *locspec)
+const explicit_location_spec *
+as_explicit_location_spec (const location_spec *locspec)
 {
   gdb_assert (locspec->type == EXPLICIT_LOCATION_SPEC);
-  return &((explicit_location_spec *) locspec)->explicit_loc;
+  return static_cast<const explicit_location_spec *> (locspec);
 }
 
 /* See description in location.h.  */
 
-const struct explicit_location *
-get_explicit_location_const (const location_spec *locspec)
+explicit_location_spec *
+as_explicit_location_spec (location_spec *locspec)
 {
   gdb_assert (locspec->type == EXPLICIT_LOCATION_SPEC);
-  return &((explicit_location_spec *) locspec)->explicit_loc;
+  return static_cast<explicit_location_spec *> (locspec);
 }
 
 /* Return a string representation of the explicit location spec in
@@ -403,7 +293,7 @@ get_explicit_location_const (const location_spec *locspec)
 
 static std::string
 explicit_to_string_internal (bool as_linespec,
-			     const struct explicit_location *explicit_loc)
+			     const explicit_location_spec *explicit_loc)
 {
   bool need_space = false;
   char space = as_linespec ? ':' : ' ';
@@ -457,18 +347,10 @@ explicit_to_string_internal (bool as_linespec,
 
 /* See description in location.h.  */
 
-static std::string
-explicit_location_to_string (const struct explicit_location *explicit_loc)
-{
-  return explicit_to_string_internal (false, explicit_loc);
-}
-
-/* See description in location.h.  */
-
 std::string
-explicit_location_to_linespec (const struct explicit_location *explicit_loc)
+explicit_location_spec::to_linespec () const
 {
-  return explicit_to_string_internal (true, explicit_loc);
+  return explicit_to_string_internal (true, this);
 }
 
 /* See description in location.h.  */
@@ -479,12 +361,6 @@ copy_location_spec (const location_spec *src)
   return src->clone ();
 }
 
-void
-location_spec_deleter::operator() (location_spec *locspec) const
-{
-  delete locspec;
-}
-
 /* See description in location.h.  */
 
 const char *
@@ -788,7 +664,7 @@ string_to_explicit_location_spec (const char **argp,
     return NULL;
 
   std::unique_ptr<explicit_location_spec> locspec
-    (new explicit_location_spec ((const explicit_location *) nullptr));
+    (new explicit_location_spec ());
 
   /* Process option/argument pairs.  dprintf_command
      requires that processing stop on ','.  */
@@ -857,18 +733,17 @@ string_to_explicit_location_spec (const char **argp,
 	{
 	  set_oarg (explicit_location_spec_lex_one (argp, language,
 						    completion_info));
-	  locspec->explicit_loc.source_filename = oarg.release ();
+	  locspec->source_filename = oarg.release ();
 	}
       else if (strncmp (opt.get (), "-function", len) == 0)
 	{
 	  set_oarg (explicit_location_spec_lex_one_function (argp, language,
 							     completion_info));
-	  locspec->explicit_loc.function_name = oarg.release ();
+	  locspec->function_name = oarg.release ();
 	}
       else if (strncmp (opt.get (), "-qualified", len) == 0)
 	{
-	  locspec->explicit_loc.func_name_match_type
-	    = symbol_name_match_type::FULL;
+	  locspec->func_name_match_type = symbol_name_match_type::FULL;
 	}
       else if (strncmp (opt.get (), "-line", len) == 0)
 	{
@@ -876,8 +751,7 @@ string_to_explicit_location_spec (const char **argp,
 	  *argp = skip_spaces (*argp);
 	  if (have_oarg)
 	    {
-	      locspec->explicit_loc.line_offset
-		= linespec_parse_line_offset (oarg.get ());
+	      locspec->line_offset = linespec_parse_line_offset (oarg.get ());
 	      continue;
 	    }
 	}
@@ -885,7 +759,7 @@ string_to_explicit_location_spec (const char **argp,
 	{
 	  set_oarg (explicit_location_spec_lex_one (argp, language,
 						    completion_info));
-	  locspec->explicit_loc.label_name = oarg.release ();
+	  locspec->label_name = oarg.release ();
 	}
       /* Only emit an "invalid argument" error for options
 	 that look like option strings.  */
@@ -915,10 +789,10 @@ string_to_explicit_location_spec (const char **argp,
 
   /* One special error check:  If a source filename was given
      without offset, function, or label, issue an error.  */
-  if (locspec->explicit_loc.source_filename != NULL
-      && locspec->explicit_loc.function_name == NULL
-      && locspec->explicit_loc.label_name == NULL
-      && (locspec->explicit_loc.line_offset.sign == LINE_OFFSET_UNKNOWN)
+  if (locspec->source_filename != NULL
+      && locspec->function_name == NULL
+      && locspec->label_name == NULL
+      && (locspec->line_offset.sign == LINE_OFFSET_UNKNOWN)
       && completion_info == NULL)
     {
       error (_("Source filename requires function, label, or "
@@ -1000,7 +874,7 @@ string_to_location_spec (const char **stringp,
       explicit_location_spec *xloc
 	= dynamic_cast<explicit_location_spec *> (locspec.get ());
       gdb_assert (xloc != nullptr);
-      match_type = xloc->explicit_loc.func_name_match_type;
+      match_type = xloc->func_name_match_type;
     }
 
   /* Everything else is a "basic" linespec, address, or probe location
diff --git a/gdb/location.h b/gdb/location.h
index 602998de298..f7e560aa26a 100644
--- a/gdb/location.h
+++ b/gdb/location.h
@@ -46,8 +46,8 @@ enum offset_relative_sign
 struct line_offset
 {
   /* Line offset and any specified sign.  */
-  int offset;
-  enum offset_relative_sign sign;
+  int offset = 0;
+  enum offset_relative_sign sign = LINE_OFFSET_UNKNOWN;
 };
 
 /* An enumeration of the various ways to specify a location spec.  */
@@ -67,15 +67,104 @@ enum location_spec_type
   PROBE_LOCATION_SPEC
 };
 
-/* A traditional linespec.  */
+/* A unique pointer for location_spec.  */
+typedef std::unique_ptr<location_spec> location_spec_up;
+
+/* The base class for all an location specs used to match actual
+   locations in the inferior.  */
 
-struct linespec_location
+struct location_spec
 {
+  virtual ~location_spec () = default;
+
+  /* Clone this object.  */
+  virtual location_spec_up clone () const = 0;
+
+  /* Return true if this location spec is empty, false otherwise.  */
+  virtual bool empty_p () const = 0;
+
+  /* Return a string representation of this location.  */
+  const char *to_string () const
+  {
+    if (as_string.empty ())
+      as_string = compute_string ();
+    if (as_string.empty ())
+      return nullptr;
+    return as_string.c_str ();
+  }
+
+  /* The type of this location specification.  */
+  enum location_spec_type type;
+
+  /* Cached string representation of this location spec.  This is
+     used, e.g., to save location specs to file.  */
+  mutable std::string as_string;
+
+protected:
+
+  explicit location_spec (enum location_spec_type t)
+    : type (t)
+  {
+  }
+
+  location_spec (enum location_spec_type t, std::string &&str)
+    : type (t),
+      as_string (std::move (str))
+  {
+  }
+
+  location_spec (const location_spec &other)
+    : type (other.type),
+      as_string (other.as_string)
+  {
+  }
+
+  /* Compute the string representation of this object.  This is called
+     by to_string when needed.  */
+  virtual std::string compute_string () const = 0;
+};
+
+/* A "normal" linespec.  */
+
+struct linespec_location_spec : public location_spec
+{
+  linespec_location_spec (const char **linespec,
+			  symbol_name_match_type match_type);
+
+  ~linespec_location_spec ();
+
+  location_spec_up clone () const override;
+
+  bool empty_p () const override;
+
   /* Whether the function name is fully-qualified or not.  */
   symbol_name_match_type match_type;
 
   /* The linespec.  */
-  char *spec_string;
+  char *spec_string = nullptr;
+
+protected:
+  linespec_location_spec (const linespec_location_spec &other);
+
+  std::string compute_string () const override;
+};
+
+/* An address in the inferior.  */
+struct address_location_spec : public location_spec
+{
+  address_location_spec (CORE_ADDR addr, const char *addr_string,
+			 int addr_string_len);
+
+  location_spec_up clone () const override;
+
+  bool empty_p () const override;
+
+  CORE_ADDR address;
+
+protected:
+  address_location_spec (const address_location_spec &other);
+
+  std::string compute_string () const override;
 };
 
 /* An explicit location spec.  This structure is used to bypass the
@@ -83,24 +172,58 @@ struct linespec_location
    as linespecs, though.  For example, source_filename requires
    at least one other field.  */
 
-struct explicit_location
+struct explicit_location_spec : public location_spec
 {
+  explicit_location_spec ();
+
+  ~explicit_location_spec ();
+
+  location_spec_up clone () const override;
+
+  bool empty_p () const override;
+
+  /* Return a linespec string representation of this explicit location
+     spec.  The explicit location spec must already be
+     canonicalized/valid.  */
+  std::string to_linespec () const;
+
   /* The source filename. Malloc'd.  */
-  char *source_filename;
+  char *source_filename = nullptr;
 
   /* The function name.  Malloc'd.  */
-  char *function_name;
+  char *function_name = nullptr;
 
   /* Whether the function name is fully-qualified or not.  */
-  symbol_name_match_type func_name_match_type;
+  symbol_name_match_type func_name_match_type
+    = symbol_name_match_type::WILD;
 
   /* The name of a label.  Malloc'd.  */
-  char *label_name;
+  char *label_name = nullptr;
 
   /* A line offset relative to the start of the symbol
      identified by the above fields or the current symtab
      if the other fields are NULL.  */
-  struct line_offset line_offset;
+  struct line_offset line_offset = {0, LINE_OFFSET_UNKNOWN};
+
+protected:
+  explicit_location_spec (const explicit_location_spec &other);
+
+  std::string compute_string () const override;
+};
+
+/* A probe.  */
+struct probe_location_spec : public location_spec
+{
+  explicit probe_location_spec (std::string &&probe);
+
+  location_spec_up clone () const override;
+
+  bool empty_p () const override;
+
+protected:
+  probe_location_spec (const probe_location_spec &other) = default;
+
+  std::string compute_string () const override;
 };
 
 /* Return the type of the given location spec.  */
@@ -108,13 +231,6 @@ struct explicit_location
 extern enum location_spec_type
   location_spec_type (const location_spec *);
 
-/* Return a linespec string representation of the given explicit
-   location spec.  The location spec must already be
-   canonicalized/valid.  */
-
-extern std::string explicit_location_to_linespec
-  (const explicit_location *explicit_locspec);
-
 /* Return a string representation of LOCSPEC.
    This function may return NULL for unspecified linespecs,
    e.g, LINESPEC_LOCATION_SPEC and spec_string is NULL.
@@ -124,27 +240,16 @@ extern std::string explicit_location_to_linespec
 extern const char *
   location_spec_to_string (location_spec *locspec);
 
-/* A deleter for a struct location_spec.  */
-
-struct location_spec_deleter
-{
-  void operator() (location_spec *locspec) const;
-};
-
-/* A unique pointer for location_spec.  */
-typedef std::unique_ptr<location_spec, location_spec_deleter>
-     location_spec_up;
-
 /* Create a new linespec location spec.  */
 
 extern location_spec_up new_linespec_location_spec
   (const char **linespec, symbol_name_match_type match_type);
 
-/* Return the linespec location spec of the given location_spec (which
-   must be of type LINESPEC_LOCATION_SPEC).  */
+/* Return the given location_spec as a linespec_location_spec.
+   LOCSPEC must be of type LINESPEC_LOCATION_SPEC.  */
 
-extern const linespec_location *
-  get_linespec_location (const location_spec *locspec);
+extern const linespec_location_spec *
+  as_linespec_location_spec (const location_spec *locspec);
 
 /* Create a new address location spec.
    ADDR is the address corresponding to this location_spec.
@@ -155,50 +260,42 @@ extern location_spec_up new_address_location_spec (CORE_ADDR addr,
 						   const char *addr_string,
 						   int addr_string_len);
 
-/* Return the address (a CORE_ADDR) of the given location_spec, which
-   must be of type ADDRESS_LOCATION_SPEC.  */
-
-extern CORE_ADDR
-  get_address_location (const location_spec *locspec);
+/* Return the given location_spec as an address_location_spec.
+   LOCSPEC must be of type ADDRESS_LOCATION_SPEC.  */
 
-/* Return the expression (a string) that was used to compute the
-   address of the given location_spec, which must be of type
-   ADDRESS_LOCATION_SPEC.  */
-
-extern const char *
-  get_address_string_location (const location_spec *locspec);
+const address_location_spec *
+  as_address_location_spec (const location_spec *locspec);
 
 /* Create a new probe location.  */
 
 extern location_spec_up new_probe_location_spec (std::string &&probe);
 
-/* Return the probe location spec string of the given location_spec,
-   which must be of type PROBE_LOCATION_SPEC.  */
-
-extern const char *
-  get_probe_location_spec_string (const location_spec *locspec);
-
-/* Initialize the given explicit location.  */
+/* Assuming LOCSPEC is of type PROBE_LOCATION_SPEC, return LOCSPEC
+   cast to probe_location_spec.  */
 
-extern void
-  initialize_explicit_location (explicit_location *locspec);
+const probe_location_spec *
+  as_probe_location_spec (const location_spec *locspec);
 
-/* Create a new explicit location.  If not NULL, EXPLICIT is checked for
-   validity.  If invalid, an exception is thrown.  */
+/* Create a new explicit location with explicit FUNCTION_NAME.  All
+   other fields are defaulted.  */
 
-extern location_spec_up
-  new_explicit_location_spec (const explicit_location *locspec);
-
-/* Return the explicit location spec of the given location_spec, which
-   must be of type EXPLICIT_LOCATION.  */
-
-extern struct explicit_location *
-  get_explicit_location (location_spec *locspec);
-
-/* A const version of the above.  */
-
-extern const explicit_location *
-  get_explicit_location_const (const location_spec *locspec);
+static inline location_spec_up
+new_explicit_location_spec_function (const char *function_name)
+{
+  explicit_location_spec *spec
+    = new explicit_location_spec ();
+  spec->function_name
+    = (function_name != nullptr ? xstrdup (function_name) : nullptr);
+  return location_spec_up (spec);
+}
+
+/* Assuming LOCSPEC is of type EXPLICIT_LOCATION_SPEC, return LOCSPEC
+   cast to explicit_location_spec.  */
+
+const explicit_location_spec *
+  as_explicit_location_spec (const location_spec *locspec);
+explicit_location_spec *
+  as_explicit_location_spec (location_spec *locspec);
 
 /* Return a copy of the given SRC location spec.  */
 
diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c
index dab0a471abc..53c032c3a81 100644
--- a/gdb/mi/mi-cmd-break.c
+++ b/gdb/mi/mi-cmd-break.c
@@ -182,7 +182,8 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
   location_spec_up locspec;
   const struct breakpoint_ops *ops;
   int is_explicit = 0;
-  struct explicit_location explicit_loc;
+  std::unique_ptr<explicit_location_spec> explicit_loc
+    (new explicit_location_spec ());
   std::string extra_string;
   bool force_condition = false;
 
@@ -220,8 +221,6 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
   int oind = 0;
   char *oarg;
 
-  initialize_explicit_location (&explicit_loc);
-
   while (1)
     {
       int opt = mi_getopt ("-break-insert", argc, argv,
@@ -259,19 +258,19 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
 	  break;
 	case EXPLICIT_SOURCE_OPT:
 	  is_explicit = 1;
-	  explicit_loc.source_filename = oarg;
+	  explicit_loc->source_filename = xstrdup (oarg);
 	  break;
 	case EXPLICIT_FUNC_OPT:
 	  is_explicit = 1;
-	  explicit_loc.function_name = oarg;
+	  explicit_loc->function_name = xstrdup (oarg);
 	  break;
 	case EXPLICIT_LABEL_OPT:
 	  is_explicit = 1;
-	  explicit_loc.label_name = oarg;
+	  explicit_loc->label_name = xstrdup (oarg);
 	  break;
 	case EXPLICIT_LINE_OPT:
 	  is_explicit = 1;
-	  explicit_loc.line_offset = linespec_parse_line_offset (oarg);
+	  explicit_loc->line_offset = linespec_parse_line_offset (oarg);
 	  break;
 	case FORCE_CONDITION_OPT:
 	  force_condition = true;
@@ -339,16 +338,14 @@ mi_cmd_break_insert_1 (int dprintf, const char *command, char **argv, int argc)
     {
       /* Error check -- we must have one of the other
 	 parameters specified.  */
-      if (explicit_loc.source_filename != NULL
-	  && explicit_loc.function_name == NULL
-	  && explicit_loc.label_name == NULL
-	  && explicit_loc.line_offset.sign == LINE_OFFSET_UNKNOWN)
+      if (explicit_loc->source_filename != NULL
+	  && explicit_loc->function_name == NULL
+	  && explicit_loc->label_name == NULL
+	  && explicit_loc->line_offset.sign == LINE_OFFSET_UNKNOWN)
 	error (_("-%s-insert: --source option requires --function, --label,"
 		 " or --line"), dprintf ? "dprintf" : "break");
 
-      explicit_loc.func_name_match_type = match_type;
-
-      locspec = new_explicit_location_spec (&explicit_loc);
+      locspec.reset (explicit_loc.release ());
     }
   else
     {
diff --git a/gdb/probe.c b/gdb/probe.c
index 0b056eb88db..5371b7eca46 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -123,7 +123,7 @@ parse_probes (const location_spec *locspec,
   const char *arg_start, *cs;
 
   gdb_assert (location_spec_type (locspec) == PROBE_LOCATION_SPEC);
-  arg_start = get_probe_location_spec_string (locspec);
+  arg_start = locspec->to_string ();
 
   cs = arg_start;
   const static_probe_ops *spops = probe_linespec_to_static_ops (&cs);
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 029ced74136..bab1c60a43e 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -839,20 +839,23 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	      }
 	    else
 	      {
-		struct explicit_location explicit_loc;
+		std::unique_ptr<explicit_location_spec> explicit_loc
+		  (new explicit_location_spec ());
 
-		initialize_explicit_location (&explicit_loc);
-		explicit_loc.source_filename = source;
-		explicit_loc.function_name = function;
-		explicit_loc.label_name = label;
+		explicit_loc->source_filename
+		  = source != nullptr ? xstrdup (source) : nullptr;
+		explicit_loc->function_name
+		  = function != nullptr ? xstrdup (function) : nullptr;
+		explicit_loc->label_name
+		  = label != nullptr ? xstrdup (label) : nullptr;
 
 		if (line != NULL)
-		  explicit_loc.line_offset =
-		    linespec_parse_line_offset (line.get ());
+		  explicit_loc->line_offset
+		    = linespec_parse_line_offset (line.get ());
 
-		explicit_loc.func_name_match_type = func_name_match_type;
+		explicit_loc->func_name_match_type = func_name_match_type;
 
-		locspec = new_explicit_location_spec (&explicit_loc);
+		locspec.reset (explicit_loc.release ());
 	      }
 
 	    const struct breakpoint_ops *ops
-- 
2.36.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 3/7] Eliminate copy_location_spec
  2022-05-27 18:02 [PATCH 0/7] location -> location spec Pedro Alves
  2022-05-27 18:02 ` [PATCH 1/7] event_location -> location_spec Pedro Alves
  2022-05-27 18:02 ` [PATCH 2/7] Eliminate the two-level data structures behind location_specs Pedro Alves
@ 2022-05-27 18:02 ` Pedro Alves
  2022-05-27 18:02 ` [PATCH 4/7] Convert location_spec_empty_p to a method Pedro Alves
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Pedro Alves @ 2022-05-27 18:02 UTC (permalink / raw)
  To: gdb-patches

copy_location_spec is just a wrapper around location_spec::clone(), so
remove it and call clone() directly.  This simplifies users, as they
no longer have to use std::unique_ptr::get().

Change-Id: I8ce8658589460b98888283b306b315a5b8f73976
---
 gdb/breakpoint.c | 10 +++++-----
 gdb/linespec.c   |  3 +--
 gdb/location.c   |  8 --------
 gdb/location.h   |  4 ----
 4 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index cdab60332ec..403b70067d7 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -8422,8 +8422,9 @@ create_breakpoints_sal (struct gdbarch *gdbarch,
       /* Note that 'location' can be NULL in the case of a plain
 	 'break', without arguments.  */
       location_spec_up locspec
-	= (canonical->locspec != NULL
-	   ? copy_location_spec (canonical->locspec.get ()) : NULL);
+	= (canonical->locspec != nullptr
+	   ? canonical->locspec->clone ()
+	   : nullptr);
       gdb::unique_xmalloc_ptr<char> filter_string
 	(lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL);
 
@@ -8924,7 +8925,7 @@ create_breakpoint (struct gdbarch *gdbarch,
     {
       std::unique_ptr <breakpoint> b = new_breakpoint_from_type (gdbarch,
 								 type_wanted);
-      b->locspec = copy_location_spec (locspec);
+      b->locspec = locspec->clone ();
 
       if (parse_extra)
 	b->cond_string = NULL;
@@ -12029,8 +12030,7 @@ strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch,
 
   for (size_t i = 0; i < lsal.sals.size (); i++)
     {
-      location_spec_up locspec
-	= copy_location_spec (canonical->locspec.get ());
+      location_spec_up locspec = canonical->locspec->clone ();
 
       std::unique_ptr<tracepoint> tp
 	(new tracepoint (gdbarch,
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 063944bb9a1..f992477b1d6 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3083,8 +3083,7 @@ location_spec_to_sals (linespec_parser *parser,
 	  {
 	    addr = linespec_expression_to_pc (&addr_string);
 	    if (PARSER_STATE (parser)->canonical != NULL)
-	      PARSER_STATE (parser)->canonical->locspec
-		= copy_location_spec (locspec);
+	      PARSER_STATE (parser)->canonical->locspec	= locspec->clone ();
 	  }
 	else
 	  addr = addr_spec->address;
diff --git a/gdb/location.c b/gdb/location.c
index 4d0b60ff9c7..19b58ab4f5b 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -355,14 +355,6 @@ explicit_location_spec::to_linespec () const
 
 /* See description in location.h.  */
 
-location_spec_up
-copy_location_spec (const location_spec *src)
-{
-  return src->clone ();
-}
-
-/* See description in location.h.  */
-
 const char *
 location_spec_to_string (struct location_spec *locspec)
 {
diff --git a/gdb/location.h b/gdb/location.h
index f7e560aa26a..f52469d770f 100644
--- a/gdb/location.h
+++ b/gdb/location.h
@@ -297,10 +297,6 @@ const explicit_location_spec *
 explicit_location_spec *
   as_explicit_location_spec (location_spec *locspec);
 
-/* Return a copy of the given SRC location spec.  */
-
-extern location_spec_up copy_location_spec (const location_spec *src);
-
 /* Attempt to convert the input string in *ARGP into a location_spec.
    ARGP is advanced past any processed input.  Always returns a non-nullptr
    location_spec unique pointer object.
-- 
2.36.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 4/7] Convert location_spec_empty_p to a method
  2022-05-27 18:02 [PATCH 0/7] location -> location spec Pedro Alves
                   ` (2 preceding siblings ...)
  2022-05-27 18:02 ` [PATCH 3/7] Eliminate copy_location_spec Pedro Alves
@ 2022-05-27 18:02 ` Pedro Alves
  2022-05-27 18:02 ` [PATCH 5/7] Convert location_spec_type " Pedro Alves
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Pedro Alves @ 2022-05-27 18:02 UTC (permalink / raw)
  To: gdb-patches

This converts location_spec_empty_p to a method of location_spec,
simplifying users, as they no longer have to use
std::unique_ptr::get().

Change-Id: I83381a729896f12e1c5a1b4d6d4c2eb1eb6582ff
---
 gdb/breakpoint.c |  3 +--
 gdb/location.c   | 10 +---------
 gdb/location.h   |  4 ----
 3 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 403b70067d7..ea54c6c161b 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3699,8 +3699,7 @@ create_exception_master_breakpoint (void)
 static int
 breakpoint_location_spec_empty_p (const struct breakpoint *b)
 {
-  return (b->locspec != nullptr
-	  && location_spec_empty_p (b->locspec.get ()));
+  return (b->locspec != nullptr && b->locspec->empty_p ());
 }
 
 void
diff --git a/gdb/location.c b/gdb/location.c
index 19b58ab4f5b..ae056f35296 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -855,7 +855,7 @@ string_to_location_spec (const char **stringp,
 
       /* If the user really specified a location spec, then we're
 	 done.  */
-      if (!location_spec_empty_p (locspec.get ()))
+      if (!locspec->empty_p ())
 	return locspec;
 
       /* Otherwise, the user _only_ specified optional flags like
@@ -876,14 +876,6 @@ string_to_location_spec (const char **stringp,
 
 /* See description in location.h.  */
 
-int
-location_spec_empty_p (const location_spec *locspec)
-{
-  return locspec->empty_p ();
-}
-
-/* See description in location.h.  */
-
 void
 set_location_spec_string (struct location_spec *locspec,
 			  std::string &&string)
diff --git a/gdb/location.h b/gdb/location.h
index f52469d770f..2b825ef0cb0 100644
--- a/gdb/location.h
+++ b/gdb/location.h
@@ -363,10 +363,6 @@ extern location_spec_up
 				    const struct language_defn *language,
 				    explicit_completion_info *completion_info);
 
-/* A convenience function for testing for unset location specs.  */
-
-extern int location_spec_empty_p (const location_spec *locspec);
-
 /* Set the location specs's string representation.  */
 
 extern void set_location_spec_string (struct location_spec *locspec,
-- 
2.36.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 5/7] Convert location_spec_type to a method
  2022-05-27 18:02 [PATCH 0/7] location -> location spec Pedro Alves
                   ` (3 preceding siblings ...)
  2022-05-27 18:02 ` [PATCH 4/7] Convert location_spec_empty_p to a method Pedro Alves
@ 2022-05-27 18:02 ` Pedro Alves
  2022-05-27 18:02 ` [PATCH 6/7] Convert location_spec_to_string " Pedro Alves
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Pedro Alves @ 2022-05-27 18:02 UTC (permalink / raw)
  To: gdb-patches

This converts location_spec_type to location_spec::type().

Change-Id: Iff4cbfafb1cf3d22adfa142ff939b4a148e52273
---
 gdb/breakpoint.c |  8 ++++----
 gdb/linespec.c   |  2 +-
 gdb/location.c   | 18 +++++-------------
 gdb/location.h   | 26 ++++++++++++++------------
 gdb/probe.c      |  2 +-
 5 files changed, 25 insertions(+), 31 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index ea54c6c161b..9f5514d8a1b 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -8453,7 +8453,7 @@ parse_breakpoint_sals (location_spec *locspec,
 {
   struct symtab_and_line cursal;
 
-  if (location_spec_type (locspec) == LINESPEC_LOCATION_SPEC)
+  if (locspec->type () == LINESPEC_LOCATION_SPEC)
     {
       const char *spec = as_linespec_location_spec (locspec)->spec_string;
 
@@ -8505,7 +8505,7 @@ parse_breakpoint_sals (location_spec *locspec,
     {
       const char *spec = NULL;
 
-      if (location_spec_type (locspec) == LINESPEC_LOCATION_SPEC)
+      if (locspec->type () == LINESPEC_LOCATION_SPEC)
 	spec = as_linespec_location_spec (locspec)->spec_string;
 
       if (!cursal.symtab
@@ -8768,7 +8768,7 @@ breakpoint_ops_for_location_spec (const location_spec *locspec,
 {
   if (locspec != nullptr)
     return (breakpoint_ops_for_location_spec_type
-	    (location_spec_type (locspec), is_tracepoint));
+	    (locspec->type (), is_tracepoint));
   return &code_breakpoint_ops;
 }
 
@@ -11673,7 +11673,7 @@ std::vector<symtab_and_line>
 code_breakpoint::decode_location_spec (location_spec *locspec,
 				       program_space *search_pspace)
 {
-  if (location_spec_type (locspec) == PROBE_LOCATION_SPEC)
+  if (locspec->type () == PROBE_LOCATION_SPEC)
     return bkpt_probe_decode_location_spec (this, locspec, search_pspace);
 
   return decode_location_spec_default (this, locspec, search_pspace);
diff --git a/gdb/linespec.c b/gdb/linespec.c
index f992477b1d6..976e728a301 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3062,7 +3062,7 @@ location_spec_to_sals (linespec_parser *parser,
 {
   std::vector<symtab_and_line> result;
 
-  switch (location_spec_type (locspec))
+  switch (locspec->type ())
     {
     case LINESPEC_LOCATION_SPEC:
       {
diff --git a/gdb/location.c b/gdb/location.c
index ae056f35296..9643ea857a3 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -206,14 +206,6 @@ explicit_location_spec::compute_string () const
 
 /* See description in location.h.  */
 
-enum location_spec_type
-location_spec_type (const location_spec *locspec)
-{
-  return locspec->type;
-}
-
-/* See description in location.h.  */
-
 location_spec_up
 new_linespec_location_spec (const char **linespec,
 			    symbol_name_match_type match_type)
@@ -227,7 +219,7 @@ new_linespec_location_spec (const char **linespec,
 const linespec_location_spec *
 as_linespec_location_spec (const location_spec *locspec)
 {
-  gdb_assert (locspec->type == LINESPEC_LOCATION_SPEC);
+  gdb_assert (locspec->type () == LINESPEC_LOCATION_SPEC);
   return static_cast<const linespec_location_spec *> (locspec);
 }
 
@@ -246,7 +238,7 @@ new_address_location_spec (CORE_ADDR addr, const char *addr_string,
 const address_location_spec *
 as_address_location_spec (const location_spec *locspec)
 {
-  gdb_assert (locspec->type == ADDRESS_LOCATION_SPEC);
+  gdb_assert (locspec->type () == ADDRESS_LOCATION_SPEC);
   return static_cast<const address_location_spec *> (locspec);
 }
 
@@ -263,7 +255,7 @@ new_probe_location_spec (std::string &&probe)
 const probe_location_spec *
 as_probe_location_spec (const location_spec *locspec)
 {
-  gdb_assert (locspec->type == PROBE_LOCATION_SPEC);
+  gdb_assert (locspec->type () == PROBE_LOCATION_SPEC);
   return static_cast<const probe_location_spec *> (locspec);
 }
 
@@ -272,7 +264,7 @@ as_probe_location_spec (const location_spec *locspec)
 const explicit_location_spec *
 as_explicit_location_spec (const location_spec *locspec)
 {
-  gdb_assert (locspec->type == EXPLICIT_LOCATION_SPEC);
+  gdb_assert (locspec->type () == EXPLICIT_LOCATION_SPEC);
   return static_cast<const explicit_location_spec *> (locspec);
 }
 
@@ -281,7 +273,7 @@ as_explicit_location_spec (const location_spec *locspec)
 explicit_location_spec *
 as_explicit_location_spec (location_spec *locspec)
 {
-  gdb_assert (locspec->type == EXPLICIT_LOCATION_SPEC);
+  gdb_assert (locspec->type () == EXPLICIT_LOCATION_SPEC);
   return static_cast<explicit_location_spec *> (locspec);
 }
 
diff --git a/gdb/location.h b/gdb/location.h
index 2b825ef0cb0..9783daadac6 100644
--- a/gdb/location.h
+++ b/gdb/location.h
@@ -93,8 +93,11 @@ struct location_spec
     return as_string.c_str ();
   }
 
-  /* The type of this location specification.  */
-  enum location_spec_type type;
+  /* Return this location spec's type.  */
+  enum location_spec_type type () const
+  {
+    return m_type;
+  }
 
   /* Cached string representation of this location spec.  This is
      used, e.g., to save location specs to file.  */
@@ -103,25 +106,29 @@ struct location_spec
 protected:
 
   explicit location_spec (enum location_spec_type t)
-    : type (t)
+    : m_type (t)
   {
   }
 
   location_spec (enum location_spec_type t, std::string &&str)
-    : type (t),
-      as_string (std::move (str))
+    : as_string (std::move (str)),
+      m_type (t)
   {
   }
 
   location_spec (const location_spec &other)
-    : type (other.type),
-      as_string (other.as_string)
+    : as_string (other.as_string),
+      m_type (other.m_type)
   {
   }
 
   /* Compute the string representation of this object.  This is called
      by to_string when needed.  */
   virtual std::string compute_string () const = 0;
+
+private:
+  /* The type of this location specification.  */
+  enum location_spec_type m_type;
 };
 
 /* A "normal" linespec.  */
@@ -226,11 +233,6 @@ struct probe_location_spec : public location_spec
   std::string compute_string () const override;
 };
 
-/* Return the type of the given location spec.  */
-
-extern enum location_spec_type
-  location_spec_type (const location_spec *);
-
 /* Return a string representation of LOCSPEC.
    This function may return NULL for unspecified linespecs,
    e.g, LINESPEC_LOCATION_SPEC and spec_string is NULL.
diff --git a/gdb/probe.c b/gdb/probe.c
index 5371b7eca46..ad7af77f722 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -122,7 +122,7 @@ parse_probes (const location_spec *locspec,
   char *objfile_namestr = NULL, *provider = NULL, *name, *p;
   const char *arg_start, *cs;
 
-  gdb_assert (location_spec_type (locspec) == PROBE_LOCATION_SPEC);
+  gdb_assert (locspec->type () == PROBE_LOCATION_SPEC);
   arg_start = locspec->to_string ();
 
   cs = arg_start;
-- 
2.36.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 6/7] Convert location_spec_to_string to a method
  2022-05-27 18:02 [PATCH 0/7] location -> location spec Pedro Alves
                   ` (4 preceding siblings ...)
  2022-05-27 18:02 ` [PATCH 5/7] Convert location_spec_type " Pedro Alves
@ 2022-05-27 18:02 ` Pedro Alves
  2022-05-27 18:02 ` [PATCH 7/7] Convert set_location_spec_string " Pedro Alves
  2022-06-15 19:47 ` [PATCH 0/7] location -> location spec Tom Tromey
  7 siblings, 0 replies; 14+ messages in thread
From: Pedro Alves @ 2022-05-27 18:02 UTC (permalink / raw)
  To: gdb-patches

This converts location_spec_to_string to a method of location_spec,
simplifying the code using it, as it no longer has to use
std::unique_ptr::get().

Change-Id: I621bdad8ea084470a2724163f614578caf8f2dd5
---
 gdb/breakpoint.c           | 38 +++++++++++++++-----------------------
 gdb/elfread.c              |  3 +--
 gdb/guile/scm-breakpoint.c |  5 ++---
 gdb/linespec.c             |  2 +-
 gdb/location.c             |  8 --------
 gdb/location.h             | 16 ++++++----------
 gdb/python/py-breakpoint.c |  2 +-
 gdb/remote.c               |  2 +-
 8 files changed, 27 insertions(+), 49 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 9f5514d8a1b..266866eed8d 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -6007,8 +6007,7 @@ print_breakpoint_location (const breakpoint *b,
     set_current_program_space (loc->pspace);
 
   if (b->display_canonical)
-    uiout->field_string ("what",
-			 location_spec_to_string (b->locspec.get ()));
+    uiout->field_string ("what", b->locspec->to_string ());
   else if (loc && loc->symtab)
     {
       const struct symbol *sym = loc->symbol;
@@ -6042,8 +6041,7 @@ print_breakpoint_location (const breakpoint *b,
     }
   else
     {
-      uiout->field_string ("pending",
-			   location_spec_to_string (b->locspec.get ()));
+      uiout->field_string ("pending", b->locspec->to_string ());
       /* If extra_string is available, it could be holding a condition
 	 or dprintf arguments.  In either case, make sure it is printed,
 	 too, but only for non-MI streams.  */
@@ -6505,7 +6503,7 @@ print_one_breakpoint_location (struct breakpoint *b,
 	}
       else if (b->locspec != nullptr)
 	{
-	  const char *str = location_spec_to_string (b->locspec.get ());
+	  const char *str = b->locspec->to_string ();
 	  if (str != nullptr)
 	    uiout->field_string ("original-location", str);
 	}
@@ -8282,7 +8280,7 @@ code_breakpoint::code_breakpoint (struct gdbarch *gdbarch_,
 	{
 	  /* We already know the marker exists, otherwise, we wouldn't
 	     see a sal for it.  */
-	  const char *p = &location_spec_to_string (locspec_.get ())[3];
+	  const char *p = &locspec_->to_string ()[3];
 	  const char *endp;
 
 	  p = skip_spaces (p);
@@ -9244,8 +9242,8 @@ void
 ranged_breakpoint::print_recreate (struct ui_file *fp) const
 {
   gdb_printf (fp, "break-range %s, %s",
-	      location_spec_to_string (locspec.get ()),
-	      location_spec_to_string (locspec_range_end.get ()));
+	      locspec->to_string (),
+	      locspec_range_end->to_string ());
   print_recreate_thread (fp);
 }
 
@@ -11353,19 +11351,18 @@ say_where (const breakpoint *b)
 	 a condition or dprintf arguments.  */
       if (b->extra_string == NULL)
 	{
-	  gdb_printf (_(" (%s) pending."),
-		      location_spec_to_string (b->locspec.get ()));
+	  gdb_printf (_(" (%s) pending."), b->locspec->to_string ());
 	}
       else if (b->type == bp_dprintf)
 	{
 	  gdb_printf (_(" (%s,%s) pending."),
-		      location_spec_to_string (b->locspec.get ()),
+		      b->locspec->to_string (),
 		      b->extra_string.get ());
 	}
       else
 	{
 	  gdb_printf (_(" (%s %s) pending."),
-		      location_spec_to_string (b->locspec.get ()),
+		      b->locspec->to_string (),
 		      b->extra_string.get ());
 	}
     }
@@ -11393,8 +11390,7 @@ say_where (const breakpoint *b)
 	    /* This is not ideal, but each location may have a
 	       different file name, and this at least reflects the
 	       real situation somewhat.  */
-	    gdb_printf (": %s.",
-			location_spec_to_string (b->locspec.get ()));
+	    gdb_printf (": %s.", b->locspec->to_string ());
 	}
 
       if (b->loc->next)
@@ -11659,7 +11655,7 @@ ordinary_breakpoint::print_recreate (struct ui_file *fp) const
     internal_error (__FILE__, __LINE__,
 		    _("unhandled breakpoint type %d"), (int) type);
 
-  gdb_printf (fp, " %s", location_spec_to_string (locspec.get ()));
+  gdb_printf (fp, " %s", locspec->to_string ());
 
   /* Print out extra_string if this breakpoint is pending.  It might
      contain, for example, conditions that were set by the user.  */
@@ -11822,8 +11818,7 @@ bkpt_probe_create_sals_from_location_spec (location_spec *locspec,
   struct linespec_sals lsal;
 
   lsal.sals = parse_probes (locspec, NULL, canonical);
-  lsal.canonical
-    = xstrdup (location_spec_to_string (canonical->locspec.get ()));
+  lsal.canonical = xstrdup (canonical->locspec->to_string ());
   canonical->lsals.push_back (std::move (lsal));
 }
 
@@ -11906,7 +11901,7 @@ tracepoint::print_recreate (struct ui_file *fp) const
     internal_error (__FILE__, __LINE__,
 		    _("unhandled tracepoint type %d"), (int) type);
 
-  gdb_printf (fp, " %s", location_spec_to_string (locspec.get ()));
+  gdb_printf (fp, " %s", locspec->to_string ());
   print_recreate_thread (fp);
 
   if (pass_count)
@@ -11951,9 +11946,7 @@ dprintf_breakpoint::re_set ()
 void
 dprintf_breakpoint::print_recreate (struct ui_file *fp) const
 {
-  gdb_printf (fp, "dprintf %s,%s",
-	      location_spec_to_string (locspec.get ()),
-	      extra_string.get ());
+  gdb_printf (fp, "dprintf %s,%s", locspec->to_string (), extra_string.get ());
   print_recreate_thread (fp);
 }
 
@@ -12001,8 +11994,7 @@ strace_marker_create_sals_from_location_spec (location_spec *locspec,
   canonical->locspec
     = new_linespec_location_spec (&ptr, symbol_name_match_type::FULL);
 
-  lsal.canonical
-    = xstrdup (location_spec_to_string (canonical->locspec.get ()));
+  lsal.canonical = xstrdup (canonical->locspec->to_string ());
   canonical->lsals.push_back (std::move (lsal));
 }
 
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 2fe02805d01..8ff62a1fed5 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1026,8 +1026,7 @@ elf_gnu_ifunc_resolver_return_stop (code_breakpoint *b)
   resolved_pc = gdbarch_addr_bits_remove (gdbarch, resolved_pc);
 
   gdb_assert (current_program_space == b->pspace || b->pspace == NULL);
-  const char *locspec_str = location_spec_to_string (b->locspec.get ());
-  elf_gnu_ifunc_record_cache (locspec_str, resolved_pc);
+  elf_gnu_ifunc_record_cache (b->locspec->to_string (), resolved_pc);
 
   b->type = bp_breakpoint;
   update_breakpoint_locations (b, current_program_space,
diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c
index c358f0ba99d..5406b74a389 100644
--- a/gdb/guile/scm-breakpoint.c
+++ b/gdb/guile/scm-breakpoint.c
@@ -189,7 +189,7 @@ bpscm_print_breakpoint_smob (SCM self, SCM port, scm_print_state *pstate)
 
       if (b->locspec != nullptr)
 	{
-	  const char *str = location_spec_to_string (b->locspec.get ());
+	  const char *str = b->locspec->to_string ();
 	  if (str != nullptr)
 	    gdbscm_printf (port, " @%s", str);
 	}
@@ -859,8 +859,7 @@ gdbscm_breakpoint_location (SCM self)
   if (bp_smob->bp->type != bp_breakpoint)
     return SCM_BOOL_F;
 
-  const char *str
-    = location_spec_to_string (bp_smob->bp->locspec.get ());
+  const char *str = bp_smob->bp->locspec->to_string ();
   if (str == nullptr)
     str = "";
 
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 976e728a301..5c75e2ec979 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3149,7 +3149,7 @@ decode_line_full (struct location_spec *locspec, int flags,
 
   if (result.size () == 0)
     throw_error (NOT_SUPPORTED_ERROR, _("Location %s not available"),
-		 location_spec_to_string (locspec));
+		 locspec->to_string ());
 
   gdb_assert (result.size () == 1 || canonical->pre_expanded);
   canonical->pre_expanded = 1;
diff --git a/gdb/location.c b/gdb/location.c
index 9643ea857a3..e22ee414070 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -345,14 +345,6 @@ explicit_location_spec::to_linespec () const
   return explicit_to_string_internal (true, this);
 }
 
-/* See description in location.h.  */
-
-const char *
-location_spec_to_string (struct location_spec *locspec)
-{
-  return locspec->to_string ();
-}
-
 /* Find an instance of the quote character C in the string S that is
    outside of all single- and double-quoted strings (i.e., any quoting
    other than C).  */
diff --git a/gdb/location.h b/gdb/location.h
index 9783daadac6..69524713402 100644
--- a/gdb/location.h
+++ b/gdb/location.h
@@ -83,7 +83,12 @@ struct location_spec
   /* Return true if this location spec is empty, false otherwise.  */
   virtual bool empty_p () const = 0;
 
-  /* Return a string representation of this location.  */
+  /* Return a string representation of this location.
+
+     This function may return NULL for unspecified linespecs, e.g,
+     LINESPEC_LOCATION_SPEC and spec_string is NULL.
+
+     The result is cached in the locspec.  */
   const char *to_string () const
   {
     if (as_string.empty ())
@@ -233,15 +238,6 @@ struct probe_location_spec : public location_spec
   std::string compute_string () const override;
 };
 
-/* Return a string representation of LOCSPEC.
-   This function may return NULL for unspecified linespecs,
-   e.g, LINESPEC_LOCATION_SPEC and spec_string is NULL.
-
-   The result is cached in LOCSPEC.  */
-
-extern const char *
-  location_spec_to_string (location_spec *locspec);
-
 /* Create a new linespec location spec.  */
 
 extern location_spec_up new_linespec_location_spec
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index bab1c60a43e..2b9f6f33cff 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -412,7 +412,7 @@ bppy_get_location (PyObject *self, void *closure)
       && obj->bp->type != bp_hardware_breakpoint)
     Py_RETURN_NONE;
 
-  const char *str = location_spec_to_string (obj->bp->locspec.get ());
+  const char *str = obj->bp->locspec->to_string ();
   if (str == nullptr)
     str = "";
   return host_string_to_python_string (str).release ();
diff --git a/gdb/remote.c b/gdb/remote.c
index 7bcd6e3e336..ed834228829 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -13375,7 +13375,7 @@ remote_target::download_tracepoint (struct bp_location *loc)
 	  if (ret < 0 || ret >= buf.size ())
 	    error ("%s", err_msg);
 
-	  const char *str = location_spec_to_string (b->locspec.get ());
+	  const char *str = b->locspec->to_string ();
 	  encode_source_string (b->number, loc->address, "at", str,
 				buf.data () + strlen (buf.data ()),
 				buf.size () - strlen (buf.data ()));
-- 
2.36.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 7/7] Convert set_location_spec_string to a method
  2022-05-27 18:02 [PATCH 0/7] location -> location spec Pedro Alves
                   ` (5 preceding siblings ...)
  2022-05-27 18:02 ` [PATCH 6/7] Convert location_spec_to_string " Pedro Alves
@ 2022-05-27 18:02 ` Pedro Alves
  2022-05-30 15:20   ` Pedro Alves
  2022-06-15 19:47 ` [PATCH 0/7] location -> location spec Tom Tromey
  7 siblings, 1 reply; 14+ messages in thread
From: Pedro Alves @ 2022-05-27 18:02 UTC (permalink / raw)
  To: gdb-patches

This converts set_location_spec_string to a method of location_spec,
and makes the location_spect::as_string field protected, renaming it
it to m_as_string along the way.

Change-Id: Iccfb1654e9fa7808d0512df89e775f9eacaeb9e0
---
 gdb/linespec.c |  2 +-
 gdb/location.c | 13 ++-----------
 gdb/location.h | 29 +++++++++++++++--------------
 3 files changed, 18 insertions(+), 26 deletions(-)

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 5c75e2ec979..e45c606d661 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2015,7 +2015,7 @@ canonicalize_linespec (struct linespec_state *state, const linespec *ls)
   /* If this location originally came from a linespec, save a string
      representation of it for display and saving to file.  */
   if (state->is_linespec)
-    set_location_spec_string (explicit_loc, explicit_loc->to_linespec ());
+    explicit_loc->set_spec_string (explicit_loc->to_linespec ());
 }
 
 /* Given a line offset in LS, construct the relevant SALs.  */
diff --git a/gdb/location.c b/gdb/location.c
index e22ee414070..2b31baa4c85 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -60,7 +60,7 @@ probe_location_spec::empty_p () const
 
 std::string probe_location_spec::compute_string () const
 {
-  return std::move (as_string);
+  return std::move (m_as_string);
 }
 
 /* A "normal" linespec.  */
@@ -131,7 +131,7 @@ address_location_spec::address_location_spec (CORE_ADDR addr,
     address (addr)
 {
   if (addr_string != nullptr)
-    as_string = std::string (addr_string, addr_string_len);
+    m_as_string = std::string (addr_string, addr_string_len);
 }
 
 location_spec_up
@@ -857,12 +857,3 @@ string_to_location_spec (const char **stringp,
      spec.  */
   return string_to_location_spec_basic (stringp, language, match_type);
 }
-
-/* See description in location.h.  */
-
-void
-set_location_spec_string (struct location_spec *locspec,
-			  std::string &&string)
-{
-  locspec->as_string = std::move (string);
-}
diff --git a/gdb/location.h b/gdb/location.h
index 69524713402..66ace484f5e 100644
--- a/gdb/location.h
+++ b/gdb/location.h
@@ -91,11 +91,11 @@ struct location_spec
      The result is cached in the locspec.  */
   const char *to_string () const
   {
-    if (as_string.empty ())
-      as_string = compute_string ();
-    if (as_string.empty ())
+    if (m_as_string.empty ())
+      m_as_string = compute_string ();
+    if (m_as_string.empty ())
       return nullptr;
-    return as_string.c_str ();
+    return m_as_string.c_str ();
   }
 
   /* Return this location spec's type.  */
@@ -104,9 +104,11 @@ struct location_spec
     return m_type;
   }
 
-  /* Cached string representation of this location spec.  This is
-     used, e.g., to save location specs to file.  */
-  mutable std::string as_string;
+  /* Set the location specs's string representation.  */
+  void set_spec_string (std::string &&string)
+  {
+    m_as_string = std::move (string);
+  }
 
 protected:
 
@@ -116,13 +118,13 @@ struct location_spec
   }
 
   location_spec (enum location_spec_type t, std::string &&str)
-    : as_string (std::move (str)),
+    : m_as_string (std::move (str)),
       m_type (t)
   {
   }
 
   location_spec (const location_spec &other)
-    : as_string (other.as_string),
+    : m_as_string (other.m_as_string),
       m_type (other.m_type)
   {
   }
@@ -131,6 +133,10 @@ struct location_spec
      by to_string when needed.  */
   virtual std::string compute_string () const = 0;
 
+  /* Cached string representation of this location spec.  This is
+     used, e.g., to save location specs to file.  */
+  mutable std::string m_as_string;
+
 private:
   /* The type of this location specification.  */
   enum location_spec_type m_type;
@@ -361,9 +367,4 @@ extern location_spec_up
 				    const struct language_defn *language,
 				    explicit_completion_info *completion_info);
 
-/* Set the location specs's string representation.  */
-
-extern void set_location_spec_string (struct location_spec *locspec,
-				      std::string &&string);
-
 #endif /* LOCATION_H */
-- 
2.36.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/7] event_location -> location_spec
  2022-05-27 18:02 ` [PATCH 1/7] event_location -> location_spec Pedro Alves
@ 2022-05-28 10:08   ` Philippe Waroquiers
  2022-05-30 15:02     ` Pedro Alves
  0 siblings, 1 reply; 14+ messages in thread
From: Philippe Waroquiers @ 2022-05-28 10:08 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On Fri, 2022-05-27 at 19:02 +0100, Pedro Alves wrote:
> Currently, GDB internally uses the term "location" for both the
> location specification the user input (linespec, explicit location, or
> an address location), and for actual resolved locations, like the
> breakpoint locations, or the result of decoding a location spec to
> SaLs.  This is expecially confusing in the breakpoints module, as
> struct breakpoint has these two fields:
FWIW, I think that the introduction of location spec in the manual and in
the code is a nice improvement/clarification.
Thanks for Pedro and Eli hard work on this.

A small question:
In GDB, when I do 
  (gdb) apropos -v location
possibly some occurrences of "location" might be changed by "locspec"
or "location specification".
(e.g.  in 'help breakpoint/break-range/disassemble/strace/...'
and I have not seen that the patches are modifying this online help.
Also, is the constant #define LOCATION_HELP_STRING
not better called  LOCATION_SPEC_HELP_STRING ?

Thanks
Philippe




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/7] event_location -> location_spec
  2022-05-28 10:08   ` Philippe Waroquiers
@ 2022-05-30 15:02     ` Pedro Alves
  0 siblings, 0 replies; 14+ messages in thread
From: Pedro Alves @ 2022-05-30 15:02 UTC (permalink / raw)
  To: Philippe Waroquiers, gdb-patches

On 2022-05-28 11:08, Philippe Waroquiers wrote:
> On Fri, 2022-05-27 at 19:02 +0100, Pedro Alves wrote:
>> Currently, GDB internally uses the term "location" for both the
>> location specification the user input (linespec, explicit location, or
>> an address location), and for actual resolved locations, like the
>> breakpoint locations, or the result of decoding a location spec to
>> SaLs.  This is expecially confusing in the breakpoints module, as
>> struct breakpoint has these two fields:
> FWIW, I think that the introduction of location spec in the manual and in
> the code is a nice improvement/clarification.
> Thanks for Pedro and Eli hard work on this.

Thanks!

> 
> A small question:
> In GDB, when I do 
>   (gdb) apropos -v location
> possibly some occurrences of "location" might be changed by "locspec"
> or "location specification".
> (e.g.  in 'help breakpoint/break-range/disassemble/strace/...'
> and I have not seen that the patches are modifying this online help.

Yeah, I was waiting until the manual changes landed.  I will look into that as
a separate patch.

> Also, is the constant #define LOCATION_HELP_STRING
> not better called  LOCATION_SPEC_HELP_STRING ?

Indeed.  I've done that change locally.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/7] Eliminate the two-level data structures behind location_specs
  2022-05-27 18:02 ` [PATCH 2/7] Eliminate the two-level data structures behind location_specs Pedro Alves
@ 2022-05-30 15:09   ` Pedro Alves
  0 siblings, 0 replies; 14+ messages in thread
From: Pedro Alves @ 2022-05-30 15:09 UTC (permalink / raw)
  To: gdb-patches

On 2022-05-27 19:02, Pedro Alves wrote:
> +	  std::unique_ptr<explicit_location_spec> els
> +	    (new explicit_location_spec ());
> +	  els->source_filename
> +	    = xstrdup (symtab_to_filename_for_display (sal2.symtab));
> +	  els->line_offset.offset = b->loc->line_number;
> +	  els->line_offset.sign = LINE_OFFSET_NONE;
> +
> +	  b->locspec.reset (els.release ());

I realized after sending the patch that even though els's type is
std::unique_ptr<explicit_location_spec>, and b->locspec is
a std::unique_ptr<location_spec>, we can do a move instead of
the reset/release above, like so:

 	  b->locspec = std::move (els);

I've made that change locally, here and in a couple other spots that could
do it.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 7/7] Convert set_location_spec_string to a method
  2022-05-27 18:02 ` [PATCH 7/7] Convert set_location_spec_string " Pedro Alves
@ 2022-05-30 15:20   ` Pedro Alves
  0 siblings, 0 replies; 14+ messages in thread
From: Pedro Alves @ 2022-05-30 15:20 UTC (permalink / raw)
  To: gdb-patches

On 2022-05-27 19:02, Pedro Alves wrote:
> This converts set_location_spec_string to a method of location_spec,
> and makes the location_spect::as_string field protected, renaming it
> it to m_as_string along the way.
> 
> Change-Id: Iccfb1654e9fa7808d0512df89e775f9eacaeb9e0
> ---
>  gdb/linespec.c |  2 +-
>  gdb/location.c | 13 ++-----------
>  gdb/location.h | 29 +++++++++++++++--------------
>  3 files changed, 18 insertions(+), 26 deletions(-)
> 
> diff --git a/gdb/linespec.c b/gdb/linespec.c
> index 5c75e2ec979..e45c606d661 100644
> --- a/gdb/linespec.c
> +++ b/gdb/linespec.c
> @@ -2015,7 +2015,7 @@ canonicalize_linespec (struct linespec_state *state, const linespec *ls)
>    /* If this location originally came from a linespec, save a string
>       representation of it for display and saving to file.  */
>    if (state->is_linespec)
> -    set_location_spec_string (explicit_loc, explicit_loc->to_linespec ());
> +    explicit_loc->set_spec_string (explicit_loc->to_linespec ());

Err, I don't know what I was thinking, but the method name should be
set_string, not set_spec_string, to go with "location_spec::to_string".

The function was originally called set_event_location_string,
and then "event_location" was replaced with "location_spec", yielding
set_location_spec_string.  

And then in this patch, I just blindly replaced "location" in set_location_spec_string
instead of replacing "location_spec"...  

From the original set_event_location_string name, we can see that the original
intention was "set_string".

Here's the fixed patch.  It also fixes the typos in the commit log.

From f1303a06ba43645428a41a593064168bbb980662 Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Fri, 27 May 2022 16:53:49 +0100
Subject: [PATCH 7/7] Convert set_location_spec_string to a method

This converts set_location_spec_string to a method of location_spec,
and makes the location_spec::as_string field protected, renaming it to
m_as_string along the way.

Change-Id: Iccfb1654e9fa7808d0512df89e775f9eacaeb9e0
---
 gdb/linespec.c |  2 +-
 gdb/location.c | 13 ++-----------
 gdb/location.h | 31 ++++++++++++++++---------------
 3 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 5c75e2ec979..10dca95e767 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2015,7 +2015,7 @@ canonicalize_linespec (struct linespec_state *state, const linespec *ls)
   /* If this location originally came from a linespec, save a string
      representation of it for display and saving to file.  */
   if (state->is_linespec)
-    set_location_spec_string (explicit_loc, explicit_loc->to_linespec ());
+    explicit_loc->set_string (explicit_loc->to_linespec ());
 }
 
 /* Given a line offset in LS, construct the relevant SALs.  */
diff --git a/gdb/location.c b/gdb/location.c
index e22ee414070..2b31baa4c85 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -60,7 +60,7 @@ probe_location_spec::empty_p () const
 
 std::string probe_location_spec::compute_string () const
 {
-  return std::move (as_string);
+  return std::move (m_as_string);
 }
 
 /* A "normal" linespec.  */
@@ -131,7 +131,7 @@ address_location_spec::address_location_spec (CORE_ADDR addr,
     address (addr)
 {
   if (addr_string != nullptr)
-    as_string = std::string (addr_string, addr_string_len);
+    m_as_string = std::string (addr_string, addr_string_len);
 }
 
 location_spec_up
@@ -857,12 +857,3 @@ string_to_location_spec (const char **stringp,
      spec.  */
   return string_to_location_spec_basic (stringp, language, match_type);
 }
-
-/* See description in location.h.  */
-
-void
-set_location_spec_string (struct location_spec *locspec,
-			  std::string &&string)
-{
-  locspec->as_string = std::move (string);
-}
diff --git a/gdb/location.h b/gdb/location.h
index 022f47cb79a..ef97060f7be 100644
--- a/gdb/location.h
+++ b/gdb/location.h
@@ -91,11 +91,17 @@ struct location_spec
      The result is cached in the locspec.  */
   const char *to_string () const
   {
-    if (as_string.empty ())
-      as_string = compute_string ();
-    if (as_string.empty ())
+    if (m_as_string.empty ())
+      m_as_string = compute_string ();
+    if (m_as_string.empty ())
       return nullptr;
-    return as_string.c_str ();
+    return m_as_string.c_str ();
+  }
+
+  /* Set this location spec's string representation.  */
+  void set_string (std::string &&string)
+  {
+    m_as_string = std::move (string);
   }
 
   /* Return this location spec's type.  */
@@ -104,10 +110,6 @@ struct location_spec
     return m_type;
   }
 
-  /* Cached string representation of this location spec.  This is
-     used, e.g., to save location specs to file.  */
-  mutable std::string as_string;
-
 protected:
 
   explicit location_spec (enum location_spec_type t)
@@ -116,13 +118,13 @@ struct location_spec
   }
 
   location_spec (enum location_spec_type t, std::string &&str)
-    : as_string (std::move (str)),
+    : m_as_string (std::move (str)),
       m_type (t)
   {
   }
 
   location_spec (const location_spec &other)
-    : as_string (other.as_string),
+    : m_as_string (other.m_as_string),
       m_type (other.m_type)
   {
   }
@@ -131,6 +133,10 @@ struct location_spec
      by to_string when needed.  */
   virtual std::string compute_string () const = 0;
 
+  /* Cached string representation of this location spec.  This is
+     used, e.g., to save location specs to file.  */
+  mutable std::string m_as_string;
+
 private:
   /* The type of this location specification.  */
   enum location_spec_type m_type;
@@ -361,9 +367,4 @@ extern location_spec_up
 				    const struct language_defn *language,
 				    explicit_completion_info *completion_info);
 
-/* Set the location specs's string representation.  */
-
-extern void set_location_spec_string (struct location_spec *locspec,
-				      std::string &&string);
-
 #endif /* LOCATION_H */

-- 
2.36.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/7] location -> location spec
  2022-05-27 18:02 [PATCH 0/7] location -> location spec Pedro Alves
                   ` (6 preceding siblings ...)
  2022-05-27 18:02 ` [PATCH 7/7] Convert set_location_spec_string " Pedro Alves
@ 2022-06-15 19:47 ` Tom Tromey
  2022-06-17  9:24   ` Pedro Alves
  7 siblings, 1 reply; 14+ messages in thread
From: Tom Tromey @ 2022-06-15 19:47 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

>>>>> Pedro Alves <pedro@palves.net> writes:

> Currently, GDB internally uses the term "location" for both the
> location specification the user had input, and for actual resolved
> locations, like the breakpoint locations, or the result of decoding a
> location spec to SaLs.  This is expecially confusing in the
> breakpoints module.

> For the location spec, we currently have struct "event_location", and
> even the "event" part is misnamed.

> This series everything related to location specifications from
> "location" to "location spec".  event_location is renamed to
> location_spec.  And then cleans up location_spec and its subclasses.

I agree with the renamings and changing to use methods.
I didn't really read the patches carefully but I think you should check
them in.

Tom

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/7] location -> location spec
  2022-06-15 19:47 ` [PATCH 0/7] location -> location spec Tom Tromey
@ 2022-06-17  9:24   ` Pedro Alves
  0 siblings, 0 replies; 14+ messages in thread
From: Pedro Alves @ 2022-06-17  9:24 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 2022-06-15 20:47, Tom Tromey wrote:
>>>>>> Pedro Alves <pedro@palves.net> writes:
> 
>> Currently, GDB internally uses the term "location" for both the
>> location specification the user had input, and for actual resolved
>> locations, like the breakpoint locations, or the result of decoding a
>> location spec to SaLs.  This is expecially confusing in the
>> breakpoints module.
> 
>> For the location spec, we currently have struct "event_location", and
>> even the "event" part is misnamed.
> 
>> This series everything related to location specifications from
>> "location" to "location spec".  event_location is renamed to
>> location_spec.  And then cleans up location_spec and its subclasses.
> 
> I agree with the renamings and changing to use methods.
> I didn't really read the patches carefully but I think you should check
> them in.

Thanks!  I merged this now.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-06-17  9:24 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-27 18:02 [PATCH 0/7] location -> location spec Pedro Alves
2022-05-27 18:02 ` [PATCH 1/7] event_location -> location_spec Pedro Alves
2022-05-28 10:08   ` Philippe Waroquiers
2022-05-30 15:02     ` Pedro Alves
2022-05-27 18:02 ` [PATCH 2/7] Eliminate the two-level data structures behind location_specs Pedro Alves
2022-05-30 15:09   ` Pedro Alves
2022-05-27 18:02 ` [PATCH 3/7] Eliminate copy_location_spec Pedro Alves
2022-05-27 18:02 ` [PATCH 4/7] Convert location_spec_empty_p to a method Pedro Alves
2022-05-27 18:02 ` [PATCH 5/7] Convert location_spec_type " Pedro Alves
2022-05-27 18:02 ` [PATCH 6/7] Convert location_spec_to_string " Pedro Alves
2022-05-27 18:02 ` [PATCH 7/7] Convert set_location_spec_string " Pedro Alves
2022-05-30 15:20   ` Pedro Alves
2022-06-15 19:47 ` [PATCH 0/7] location -> location spec Tom Tromey
2022-06-17  9:24   ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).