1 /* Data structures and API for event locations in GDB.
2 Copyright (C) 2013-2022 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "gdbsupport/gdb_assert.h"
25 #include "cli/cli-utils.h"
27 #include "cp-support.h"
32 /* An event location used to set a stop event in the inferior.
33 This structure is an amalgam of the various ways
34 to specify where a stop event should be set. */
38 /* The type of this breakpoint specification. */
39 enum event_location_type type
;
40 #define EL_TYPE(P) (P)->type
46 #define EL_PROBE(P) ((P)->u.addr_string)
48 /* A "normal" linespec. */
49 struct linespec_location linespec_location
;
50 #define EL_LINESPEC(P) (&(P)->u.linespec_location)
52 /* An address in the inferior. */
54 #define EL_ADDRESS(P) (P)->u.address
56 /* An explicit location. */
57 struct explicit_location explicit_loc
;
58 #define EL_EXPLICIT(P) (&((P)->u.explicit_loc))
61 /* Cached string representation of this location. This is used, e.g., to
62 save stop event locations to file. Malloc'd. */
64 #define EL_STRING(P) ((P)->as_string)
67 /* See description in location.h. */
69 enum event_location_type
70 event_location_type (const struct event_location
*location
)
72 return EL_TYPE (location
);
75 /* See description in location.h. */
78 initialize_explicit_location (struct explicit_location
*explicit_loc
)
80 memset (explicit_loc
, 0, sizeof (struct explicit_location
));
81 explicit_loc
->line_offset
.sign
= LINE_OFFSET_UNKNOWN
;
82 explicit_loc
->func_name_match_type
= symbol_name_match_type::WILD
;
85 /* See description in location.h. */
88 new_linespec_location (const char **linespec
,
89 symbol_name_match_type match_type
)
91 struct event_location
*location
;
93 location
= XCNEW (struct event_location
);
94 EL_TYPE (location
) = LINESPEC_LOCATION
;
95 EL_LINESPEC (location
)->match_type
= match_type
;
96 if (*linespec
!= NULL
)
99 const char *orig
= *linespec
;
101 linespec_lex_to_end (linespec
);
102 p
= remove_trailing_whitespace (orig
, *linespec
);
104 EL_LINESPEC (location
)->spec_string
= savestring (orig
, p
- orig
);
106 return event_location_up (location
);
109 /* See description in location.h. */
111 const linespec_location
*
112 get_linespec_location (const struct event_location
*location
)
114 gdb_assert (EL_TYPE (location
) == LINESPEC_LOCATION
);
115 return EL_LINESPEC (location
);
118 /* See description in location.h. */
121 new_address_location (CORE_ADDR addr
, const char *addr_string
,
124 struct event_location
*location
;
126 location
= XCNEW (struct event_location
);
127 EL_TYPE (location
) = ADDRESS_LOCATION
;
128 EL_ADDRESS (location
) = addr
;
129 if (addr_string
!= NULL
)
130 EL_STRING (location
) = xstrndup (addr_string
, addr_string_len
);
131 return event_location_up (location
);
134 /* See description in location.h. */
137 get_address_location (const struct event_location
*location
)
139 gdb_assert (EL_TYPE (location
) == ADDRESS_LOCATION
);
140 return EL_ADDRESS (location
);
143 /* See description in location.h. */
146 get_address_string_location (const struct event_location
*location
)
148 gdb_assert (EL_TYPE (location
) == ADDRESS_LOCATION
);
149 return EL_STRING (location
);
152 /* See description in location.h. */
155 new_probe_location (const char *probe
)
157 struct event_location
*location
;
159 location
= XCNEW (struct event_location
);
160 EL_TYPE (location
) = PROBE_LOCATION
;
162 EL_PROBE (location
) = xstrdup (probe
);
163 return event_location_up (location
);
166 /* See description in location.h. */
169 get_probe_location (const struct event_location
*location
)
171 gdb_assert (EL_TYPE (location
) == PROBE_LOCATION
);
172 return EL_PROBE (location
);
175 /* See description in location.h. */
178 new_explicit_location (const struct explicit_location
*explicit_loc
)
180 struct event_location tmp
;
182 memset (&tmp
, 0, sizeof (struct event_location
));
183 EL_TYPE (&tmp
) = EXPLICIT_LOCATION
;
184 initialize_explicit_location (EL_EXPLICIT (&tmp
));
185 if (explicit_loc
!= NULL
)
187 EL_EXPLICIT (&tmp
)->func_name_match_type
188 = explicit_loc
->func_name_match_type
;
190 if (explicit_loc
->source_filename
!= NULL
)
192 EL_EXPLICIT (&tmp
)->source_filename
193 = explicit_loc
->source_filename
;
196 if (explicit_loc
->function_name
!= NULL
)
197 EL_EXPLICIT (&tmp
)->function_name
198 = explicit_loc
->function_name
;
200 if (explicit_loc
->label_name
!= NULL
)
201 EL_EXPLICIT (&tmp
)->label_name
= explicit_loc
->label_name
;
203 if (explicit_loc
->line_offset
.sign
!= LINE_OFFSET_UNKNOWN
)
204 EL_EXPLICIT (&tmp
)->line_offset
= explicit_loc
->line_offset
;
207 return copy_event_location (&tmp
);
210 /* See description in location.h. */
212 struct explicit_location
*
213 get_explicit_location (struct event_location
*location
)
215 gdb_assert (EL_TYPE (location
) == EXPLICIT_LOCATION
);
216 return EL_EXPLICIT (location
);
219 /* See description in location.h. */
221 const struct explicit_location
*
222 get_explicit_location_const (const struct event_location
*location
)
224 gdb_assert (EL_TYPE (location
) == EXPLICIT_LOCATION
);
225 return EL_EXPLICIT (location
);
228 /* This convenience function returns a malloc'd string which
229 represents the location in EXPLICIT_LOC.
231 AS_LINESPEC is true if this string should be a linespec.
232 Otherwise it will be output in explicit form. */
234 static gdb::unique_xmalloc_ptr
<char>
235 explicit_to_string_internal (bool as_linespec
,
236 const struct explicit_location
*explicit_loc
)
238 bool need_space
= false;
239 char space
= as_linespec
? ':' : ' ';
242 if (explicit_loc
->source_filename
!= NULL
)
245 buf
.puts ("-source ");
246 buf
.puts (explicit_loc
->source_filename
);
250 if (explicit_loc
->function_name
!= NULL
)
254 if (explicit_loc
->func_name_match_type
== symbol_name_match_type::FULL
)
255 buf
.puts ("-qualified ");
257 buf
.puts ("-function ");
258 buf
.puts (explicit_loc
->function_name
);
262 if (explicit_loc
->label_name
!= NULL
)
267 buf
.puts ("-label ");
268 buf
.puts (explicit_loc
->label_name
);
272 if (explicit_loc
->line_offset
.sign
!= LINE_OFFSET_UNKNOWN
)
279 (explicit_loc
->line_offset
.sign
== LINE_OFFSET_NONE
? ""
280 : (explicit_loc
->line_offset
.sign
281 == LINE_OFFSET_PLUS
? "+" : "-")),
282 explicit_loc
->line_offset
.offset
);
285 return make_unique_xstrdup (buf
.c_str ());
288 /* See description in location.h. */
290 static gdb::unique_xmalloc_ptr
<char>
291 explicit_location_to_string (const struct explicit_location
*explicit_loc
)
293 return explicit_to_string_internal (false, explicit_loc
);
296 /* See description in location.h. */
298 gdb::unique_xmalloc_ptr
<char>
299 explicit_location_to_linespec (const struct explicit_location
*explicit_loc
)
301 return explicit_to_string_internal (true, explicit_loc
);
304 /* See description in location.h. */
307 copy_event_location (const struct event_location
*src
)
309 struct event_location
*dst
;
311 dst
= XCNEW (struct event_location
);
312 EL_TYPE (dst
) = EL_TYPE (src
);
313 if (EL_STRING (src
) != NULL
)
314 EL_STRING (dst
) = xstrdup (EL_STRING (src
));
316 switch (EL_TYPE (src
))
318 case LINESPEC_LOCATION
:
319 EL_LINESPEC (dst
)->match_type
= EL_LINESPEC (src
)->match_type
;
320 if (EL_LINESPEC (src
)->spec_string
!= NULL
)
321 EL_LINESPEC (dst
)->spec_string
322 = xstrdup (EL_LINESPEC (src
)->spec_string
);
325 case ADDRESS_LOCATION
:
326 EL_ADDRESS (dst
) = EL_ADDRESS (src
);
329 case EXPLICIT_LOCATION
:
330 EL_EXPLICIT (dst
)->func_name_match_type
331 = EL_EXPLICIT (src
)->func_name_match_type
;
332 if (EL_EXPLICIT (src
)->source_filename
!= NULL
)
333 EL_EXPLICIT (dst
)->source_filename
334 = xstrdup (EL_EXPLICIT (src
)->source_filename
);
336 if (EL_EXPLICIT (src
)->function_name
!= NULL
)
337 EL_EXPLICIT (dst
)->function_name
338 = xstrdup (EL_EXPLICIT (src
)->function_name
);
340 if (EL_EXPLICIT (src
)->label_name
!= NULL
)
341 EL_EXPLICIT (dst
)->label_name
= xstrdup (EL_EXPLICIT (src
)->label_name
);
343 EL_EXPLICIT (dst
)->line_offset
= EL_EXPLICIT (src
)->line_offset
;
348 if (EL_PROBE (src
) != NULL
)
349 EL_PROBE (dst
) = xstrdup (EL_PROBE (src
));
353 gdb_assert_not_reached ("unknown event location type");
356 return event_location_up (dst
);
360 event_location_deleter::operator() (event_location
*location
) const
362 if (location
!= NULL
)
364 xfree (EL_STRING (location
));
366 switch (EL_TYPE (location
))
368 case LINESPEC_LOCATION
:
369 xfree (EL_LINESPEC (location
)->spec_string
);
372 case ADDRESS_LOCATION
:
376 case EXPLICIT_LOCATION
:
377 xfree (EL_EXPLICIT (location
)->source_filename
);
378 xfree (EL_EXPLICIT (location
)->function_name
);
379 xfree (EL_EXPLICIT (location
)->label_name
);
383 xfree (EL_PROBE (location
));
387 gdb_assert_not_reached ("unknown event location type");
394 /* See description in location.h. */
397 event_location_to_string (struct event_location
*location
)
399 if (EL_STRING (location
) == NULL
)
401 switch (EL_TYPE (location
))
403 case LINESPEC_LOCATION
:
404 if (EL_LINESPEC (location
)->spec_string
!= NULL
)
406 linespec_location
*ls
= EL_LINESPEC (location
);
407 if (ls
->match_type
== symbol_name_match_type::FULL
)
410 = concat ("-qualified ", ls
->spec_string
, (char *) NULL
);
413 EL_STRING (location
) = xstrdup (ls
->spec_string
);
417 case ADDRESS_LOCATION
:
419 const char *addr_string
420 = core_addr_to_string (EL_ADDRESS (location
));
422 = xstrprintf ("*%s", addr_string
).release ();
426 case EXPLICIT_LOCATION
:
428 = explicit_location_to_string (EL_EXPLICIT (location
)).release ();
432 EL_STRING (location
) = xstrdup (EL_PROBE (location
));
436 gdb_assert_not_reached ("unknown event location type");
440 return EL_STRING (location
);
443 /* Find an instance of the quote character C in the string S that is
444 outside of all single- and double-quoted strings (i.e., any quoting
448 find_end_quote (const char *s
, char end_quote_char
)
450 /* zero if we're not in quotes;
451 '"' if we're in a double-quoted string;
452 '\'' if we're in a single-quoted string. */
453 char nested_quote_char
= '\0';
455 for (const char *scan
= s
; *scan
!= '\0'; scan
++)
457 if (nested_quote_char
!= '\0')
459 if (*scan
== nested_quote_char
)
460 nested_quote_char
= '\0';
461 else if (scan
[0] == '\\' && *(scan
+ 1) != '\0')
464 else if (*scan
== end_quote_char
&& nested_quote_char
== '\0')
466 else if (*scan
== '"' || *scan
== '\'')
467 nested_quote_char
= *scan
;
473 /* A lexer for explicit locations. This function will advance INP
474 past any strings that it lexes. Returns a malloc'd copy of the
475 lexed string or NULL if no lexing was done. */
477 static gdb::unique_xmalloc_ptr
<char>
478 explicit_location_lex_one (const char **inp
,
479 const struct language_defn
*language
,
480 explicit_completion_info
*completion_info
)
482 const char *start
= *inp
;
487 /* If quoted, skip to the ending quote. */
488 if (strchr (get_gdb_linespec_parser_quote_characters (), *start
))
490 if (completion_info
!= NULL
)
491 completion_info
->quoted_arg_start
= start
;
493 const char *end
= find_end_quote (start
+ 1, *start
);
497 if (completion_info
== NULL
)
498 error (_("Unmatched quote, %s."), start
);
500 end
= start
+ strlen (start
);
502 return gdb::unique_xmalloc_ptr
<char> (savestring (start
+ 1,
506 if (completion_info
!= NULL
)
507 completion_info
->quoted_arg_end
= end
;
509 return gdb::unique_xmalloc_ptr
<char> (savestring (start
+ 1,
513 /* If the input starts with '-' or '+', the string ends with the next
514 whitespace or comma. */
515 if (*start
== '-' || *start
== '+')
517 while (*inp
[0] != '\0' && *inp
[0] != ',' && !isspace (*inp
[0]))
522 /* Handle numbers first, stopping at the next whitespace or ','. */
523 while (isdigit (*inp
[0]))
525 if (*inp
[0] == '\0' || isspace (*inp
[0]) || *inp
[0] == ',')
526 return gdb::unique_xmalloc_ptr
<char> (savestring (start
,
529 /* Otherwise stop at the next occurrence of whitespace, '\0',
534 && !(isspace ((*inp
)[0])
535 || linespec_lexer_lex_keyword (&(*inp
)[1])))
537 /* Special case: C++ operator,. */
538 if (language
->la_language
== language_cplus
539 && startswith (*inp
, CP_OPERATOR_STR
))
540 (*inp
) += CP_OPERATOR_LEN
;
545 if (*inp
- start
> 0)
546 return gdb::unique_xmalloc_ptr
<char> (savestring (start
, *inp
- start
));
551 /* Return true if COMMA points past "operator". START is the start of
552 the line that COMMAND points to, hence when reading backwards, we
553 must not read any character before START. */
556 is_cp_operator (const char *start
, const char *comma
)
559 && (comma
- start
) >= CP_OPERATOR_LEN
)
561 const char *p
= comma
;
563 while (p
> start
&& isspace (p
[-1]))
565 if (p
- start
>= CP_OPERATOR_LEN
)
567 p
-= CP_OPERATOR_LEN
;
568 if (strncmp (p
, CP_OPERATOR_STR
, CP_OPERATOR_LEN
) == 0
570 || !(isalnum (p
[-1]) || p
[-1] == '_')))
579 /* When scanning the input string looking for the next explicit
580 location option/delimiter, we jump to the next option by looking
581 for ",", and "-". Such a character can also appear in C++ symbols
582 like "operator," and "operator-". So when we find such a
583 character, we call this function to check if we found such a
584 symbol, meaning we had a false positive for an option string. In
585 that case, we keep looking for the next delimiter, until we find
586 one that is not a false positive, or we reach end of string. FOUND
587 is the character that scanning found (either '-' or ','), and START
588 is the start of the line that FOUND points to, hence when reading
589 backwards, we must not read any character before START. Returns a
590 pointer to the next non-false-positive delimiter character, or NULL
591 if none was found. */
594 skip_op_false_positives (const char *start
, const char *found
)
596 while (found
!= NULL
&& is_cp_operator (start
, found
))
598 if (found
[0] == '-' && found
[1] == '-')
602 found
= find_toplevel_char (start
, *found
);
608 /* Assuming both FIRST and NEW_TOK point into the same string, return
609 the pointer that is closer to the start of the string. If FIRST is
610 NULL, returns NEW_TOK. If NEW_TOK is NULL, returns FIRST. */
613 first_of (const char *first
, const char *new_tok
)
617 else if (new_tok
!= NULL
&& new_tok
< first
)
623 /* A lexer for functions in explicit locations. This function will
624 advance INP past a function until the next option, or until end of
625 string. Returns a malloc'd copy of the lexed string or NULL if no
628 static gdb::unique_xmalloc_ptr
<char>
629 explicit_location_lex_one_function (const char **inp
,
630 const struct language_defn
*language
,
631 explicit_completion_info
*completion_info
)
633 const char *start
= *inp
;
638 /* If quoted, skip to the ending quote. */
639 if (strchr (get_gdb_linespec_parser_quote_characters (), *start
))
641 char quote_char
= *start
;
643 /* If the input is not an Ada operator, skip to the matching
644 closing quote and return the string. */
645 if (!(language
->la_language
== language_ada
646 && quote_char
== '\"' && is_ada_operator (start
)))
648 if (completion_info
!= NULL
)
649 completion_info
->quoted_arg_start
= start
;
651 const char *end
= find_toplevel_char (start
+ 1, quote_char
);
655 if (completion_info
== NULL
)
656 error (_("Unmatched quote, %s."), start
);
658 end
= start
+ strlen (start
);
660 char *saved
= savestring (start
+ 1, *inp
- start
- 1);
661 return gdb::unique_xmalloc_ptr
<char> (saved
);
664 if (completion_info
!= NULL
)
665 completion_info
->quoted_arg_end
= end
;
667 char *saved
= savestring (start
+ 1, *inp
- start
- 2);
668 return gdb::unique_xmalloc_ptr
<char> (saved
);
672 const char *comma
= find_toplevel_char (start
, ',');
674 /* If we have "-function -myfunction", or perhaps better example,
675 "-function -[BasicClass doIt]" (objc selector), treat
676 "-myfunction" as the function name. I.e., skip the first char if
677 it is an hyphen. Don't skip the first char always, because we
678 may have C++ "operator<", and find_toplevel_char needs to see the
682 ? find_toplevel_char (start
+ 1, '-')
683 : find_toplevel_char (start
, '-'));
685 /* Check for C++ "operator," and "operator-". */
686 comma
= skip_op_false_positives (start
, comma
);
687 hyphen
= skip_op_false_positives (start
, hyphen
);
689 /* Pick the one that appears first. */
690 const char *end
= first_of (hyphen
, comma
);
692 /* See if a linespec keyword appears first. */
693 const char *s
= start
;
694 const char *ws
= find_toplevel_char (start
, ' ');
695 while (ws
!= NULL
&& linespec_lexer_lex_keyword (ws
+ 1) == NULL
)
698 ws
= find_toplevel_char (s
, ' ');
701 end
= first_of (end
, ws
+ 1);
703 /* If we don't have any terminator, then take the whole string. */
705 end
= start
+ strlen (start
);
707 /* Trim whitespace at the end. */
708 while (end
> start
&& end
[-1] == ' ')
713 if (*inp
- start
> 0)
714 return gdb::unique_xmalloc_ptr
<char> (savestring (start
, *inp
- start
));
719 /* See description in location.h. */
722 string_to_explicit_location (const char **argp
,
723 const struct language_defn
*language
,
724 explicit_completion_info
*completion_info
)
726 event_location_up location
;
728 /* It is assumed that input beginning with '-' and a non-digit
729 character is an explicit location. "-p" is reserved, though,
730 for probe locations. */
734 || !isalpha ((*argp
)[1])
735 || ((*argp
)[0] == '-' && (*argp
)[1] == 'p'))
738 location
= new_explicit_location (NULL
);
740 /* Process option/argument pairs. dprintf_command
741 requires that processing stop on ','. */
742 while ((*argp
)[0] != '\0' && (*argp
)[0] != ',')
747 /* Clear these on each iteration, since they should be filled
748 with info about the last option. */
749 if (completion_info
!= NULL
)
751 completion_info
->quoted_arg_start
= NULL
;
752 completion_info
->quoted_arg_end
= NULL
;
755 /* If *ARGP starts with a keyword, stop processing
757 if (linespec_lexer_lex_keyword (*argp
) != NULL
)
760 /* Mark the start of the string in case we need to rewind. */
763 if (completion_info
!= NULL
)
764 completion_info
->last_option
= start
;
766 /* Get the option string. */
767 gdb::unique_xmalloc_ptr
<char> opt
768 = explicit_location_lex_one (argp
, language
, NULL
);
770 /* Use the length of the option to allow abbreviations. */
771 len
= strlen (opt
.get ());
773 /* Get the argument string. */
774 *argp
= skip_spaces (*argp
);
776 /* All options have a required argument. Checking for this
777 required argument is deferred until later. */
778 gdb::unique_xmalloc_ptr
<char> oarg
;
779 /* True if we have an argument. This is required because we'll
780 move from OARG before checking whether we have an
782 bool have_oarg
= false;
784 /* True if the option needs an argument. */
785 bool need_oarg
= false;
787 /* Convenience to consistently set both OARG/HAVE_OARG from
789 auto set_oarg
= [&] (gdb::unique_xmalloc_ptr
<char> arg
)
791 if (completion_info
!= NULL
)
793 /* We do this here because the set of options that take
794 arguments matches the set of explicit location
796 completion_info
->saw_explicit_location_option
= true;
798 oarg
= std::move (arg
);
799 have_oarg
= oarg
!= NULL
;
803 if (strncmp (opt
.get (), "-source", len
) == 0)
805 set_oarg (explicit_location_lex_one (argp
, language
,
807 EL_EXPLICIT (location
)->source_filename
= oarg
.release ();
809 else if (strncmp (opt
.get (), "-function", len
) == 0)
811 set_oarg (explicit_location_lex_one_function (argp
, language
,
813 EL_EXPLICIT (location
)->function_name
= oarg
.release ();
815 else if (strncmp (opt
.get (), "-qualified", len
) == 0)
817 EL_EXPLICIT (location
)->func_name_match_type
818 = symbol_name_match_type::FULL
;
820 else if (strncmp (opt
.get (), "-line", len
) == 0)
822 set_oarg (explicit_location_lex_one (argp
, language
, NULL
));
823 *argp
= skip_spaces (*argp
);
826 EL_EXPLICIT (location
)->line_offset
827 = linespec_parse_line_offset (oarg
.get ());
831 else if (strncmp (opt
.get (), "-label", len
) == 0)
833 set_oarg (explicit_location_lex_one (argp
, language
, completion_info
));
834 EL_EXPLICIT (location
)->label_name
= oarg
.release ();
836 /* Only emit an "invalid argument" error for options
837 that look like option strings. */
838 else if (opt
.get ()[0] == '-' && !isdigit (opt
.get ()[1]))
840 if (completion_info
== NULL
)
841 error (_("invalid explicit location argument, \"%s\""), opt
.get ());
845 /* End of the explicit location specification.
846 Stop parsing and return whatever explicit location was
852 *argp
= skip_spaces (*argp
);
854 /* It's a little lame to error after the fact, but in this
855 case, it provides a much better user experience to issue
856 the "invalid argument" error before any missing
858 if (need_oarg
&& !have_oarg
&& completion_info
== NULL
)
859 error (_("missing argument for \"%s\""), opt
.get ());
862 /* One special error check: If a source filename was given
863 without offset, function, or label, issue an error. */
864 if (EL_EXPLICIT (location
)->source_filename
!= NULL
865 && EL_EXPLICIT (location
)->function_name
== NULL
866 && EL_EXPLICIT (location
)->label_name
== NULL
867 && (EL_EXPLICIT (location
)->line_offset
.sign
== LINE_OFFSET_UNKNOWN
)
868 && completion_info
== NULL
)
870 error (_("Source filename requires function, label, or "
877 /* See description in location.h. */
880 string_to_event_location_basic (const char **stringp
,
881 const struct language_defn
*language
,
882 symbol_name_match_type match_type
)
884 event_location_up location
;
887 /* Try the input as a probe spec. */
889 if (cs
!= NULL
&& probe_linespec_to_static_ops (&cs
) != NULL
)
891 location
= new_probe_location (*stringp
);
892 *stringp
+= strlen (*stringp
);
896 /* Try an address location. */
897 if (*stringp
!= NULL
&& **stringp
== '*')
899 const char *arg
, *orig
;
902 orig
= arg
= *stringp
;
903 addr
= linespec_expression_to_pc (&arg
);
904 location
= new_address_location (addr
, orig
, arg
- orig
);
905 *stringp
+= arg
- orig
;
909 /* Everything else is a linespec. */
910 location
= new_linespec_location (stringp
, match_type
);
917 /* See description in location.h. */
920 string_to_event_location (const char **stringp
,
921 const struct language_defn
*language
,
922 symbol_name_match_type match_type
)
924 const char *arg
, *orig
;
926 /* Try an explicit location. */
927 orig
= arg
= *stringp
;
928 event_location_up location
= string_to_explicit_location (&arg
, language
, NULL
);
929 if (location
!= NULL
)
931 /* It was a valid explicit location. Advance STRINGP to
933 *stringp
+= arg
- orig
;
935 /* If the user really specified a location, then we're done. */
936 if (!event_location_empty_p (location
.get ()))
939 /* Otherwise, the user _only_ specified optional flags like
940 "-qualified", otherwise string_to_explicit_location would
941 have thrown an error. Save the flags for "basic" linespec
942 parsing below and discard the explicit location. */
943 match_type
= EL_EXPLICIT (location
)->func_name_match_type
;
946 /* Everything else is a "basic" linespec, address, or probe
948 return string_to_event_location_basic (stringp
, language
, match_type
);
951 /* See description in location.h. */
954 event_location_empty_p (const struct event_location
*location
)
956 switch (EL_TYPE (location
))
958 case LINESPEC_LOCATION
:
959 /* Linespecs are never "empty." (NULL is a valid linespec) */
962 case ADDRESS_LOCATION
:
965 case EXPLICIT_LOCATION
:
966 return (EL_EXPLICIT (location
)->source_filename
== NULL
967 && EL_EXPLICIT (location
)->function_name
== NULL
968 && EL_EXPLICIT (location
)->label_name
== NULL
969 && (EL_EXPLICIT (location
)->line_offset
.sign
970 == LINE_OFFSET_UNKNOWN
));
973 return EL_PROBE (location
) == NULL
;
976 gdb_assert_not_reached ("unknown event location type");
980 /* See description in location.h. */
983 set_event_location_string (struct event_location
*location
,
984 gdb::unique_xmalloc_ptr
<char> string
)
986 xfree (EL_STRING (location
));
987 EL_STRING (location
) = string
.release ();