1 /* Data structures and API for event locations in GDB.
2 Copyright (C) 2013-2019 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 "common/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 non-zero if this string should be a linespec.
232 Otherwise it will be output in explicit form. */
235 explicit_to_string_internal (int as_linespec
,
236 const struct explicit_location
*explicit_loc
)
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 xstrdup (buf
.c_str ());
288 /* See description in location.h. */
291 explicit_location_to_string (const struct explicit_location
*explicit_loc
)
293 return explicit_to_string_internal (0, explicit_loc
);
296 /* See description in location.h. */
299 explicit_location_to_linespec (const struct explicit_location
*explicit_loc
)
301 return explicit_to_string_internal (1, 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
:
420 core_addr_to_string (EL_ADDRESS (location
)));
423 case EXPLICIT_LOCATION
:
425 = explicit_location_to_string (EL_EXPLICIT (location
));
429 EL_STRING (location
) = xstrdup (EL_PROBE (location
));
433 gdb_assert_not_reached ("unknown event location type");
437 return EL_STRING (location
);
440 /* Find an instance of the quote character C in the string S that is
441 outside of all single- and double-quoted strings (i.e., any quoting
445 find_end_quote (const char *s
, char end_quote_char
)
447 /* zero if we're not in quotes;
448 '"' if we're in a double-quoted string;
449 '\'' if we're in a single-quoted string. */
450 char nested_quote_char
= '\0';
452 for (const char *scan
= s
; *scan
!= '\0'; scan
++)
454 if (nested_quote_char
!= '\0')
456 if (*scan
== nested_quote_char
)
457 nested_quote_char
= '\0';
458 else if (scan
[0] == '\\' && *(scan
+ 1) != '\0')
461 else if (*scan
== end_quote_char
&& nested_quote_char
== '\0')
463 else if (*scan
== '"' || *scan
== '\'')
464 nested_quote_char
= *scan
;
470 /* A lexer for explicit locations. This function will advance INP
471 past any strings that it lexes. Returns a malloc'd copy of the
472 lexed string or NULL if no lexing was done. */
474 static gdb::unique_xmalloc_ptr
<char>
475 explicit_location_lex_one (const char **inp
,
476 const struct language_defn
*language
,
477 explicit_completion_info
*completion_info
)
479 const char *start
= *inp
;
484 /* If quoted, skip to the ending quote. */
485 if (strchr (get_gdb_linespec_parser_quote_characters (), *start
))
487 if (completion_info
!= NULL
)
488 completion_info
->quoted_arg_start
= start
;
490 const char *end
= find_end_quote (start
+ 1, *start
);
494 if (completion_info
== NULL
)
495 error (_("Unmatched quote, %s."), start
);
497 end
= start
+ strlen (start
);
499 return gdb::unique_xmalloc_ptr
<char> (savestring (start
+ 1,
503 if (completion_info
!= NULL
)
504 completion_info
->quoted_arg_end
= end
;
506 return gdb::unique_xmalloc_ptr
<char> (savestring (start
+ 1,
510 /* If the input starts with '-' or '+', the string ends with the next
511 whitespace or comma. */
512 if (*start
== '-' || *start
== '+')
514 while (*inp
[0] != '\0' && *inp
[0] != ',' && !isspace (*inp
[0]))
519 /* Handle numbers first, stopping at the next whitespace or ','. */
520 while (isdigit (*inp
[0]))
522 if (*inp
[0] == '\0' || isspace (*inp
[0]) || *inp
[0] == ',')
523 return gdb::unique_xmalloc_ptr
<char> (savestring (start
,
526 /* Otherwise stop at the next occurrence of whitespace, '\0',
531 && !(isspace ((*inp
)[0])
532 || linespec_lexer_lex_keyword (&(*inp
)[1])))
534 /* Special case: C++ operator,. */
535 if (language
->la_language
== language_cplus
536 && startswith (*inp
, CP_OPERATOR_STR
))
537 (*inp
) += CP_OPERATOR_LEN
;
542 if (*inp
- start
> 0)
543 return gdb::unique_xmalloc_ptr
<char> (savestring (start
, *inp
- start
));
548 /* Return true if COMMA points past "operator". START is the start of
549 the line that COMMAND points to, hence when reading backwards, we
550 must not read any character before START. */
553 is_cp_operator (const char *start
, const char *comma
)
556 && (comma
- start
) >= CP_OPERATOR_LEN
)
558 const char *p
= comma
;
560 while (p
> start
&& isspace (p
[-1]))
562 if (p
- start
>= CP_OPERATOR_LEN
)
564 p
-= CP_OPERATOR_LEN
;
565 if (strncmp (p
, CP_OPERATOR_STR
, CP_OPERATOR_LEN
) == 0
567 || !(isalnum (p
[-1]) || p
[-1] == '_')))
576 /* When scanning the input string looking for the next explicit
577 location option/delimiter, we jump to the next option by looking
578 for ",", and "-". Such a character can also appear in C++ symbols
579 like "operator," and "operator-". So when we find such a
580 character, we call this function to check if we found such a
581 symbol, meaning we had a false positive for an option string. In
582 that case, we keep looking for the next delimiter, until we find
583 one that is not a false positive, or we reach end of string. FOUND
584 is the character that scanning found (either '-' or ','), and START
585 is the start of the line that FOUND points to, hence when reading
586 backwards, we must not read any character before START. Returns a
587 pointer to the next non-false-positive delimiter character, or NULL
588 if none was found. */
591 skip_op_false_positives (const char *start
, const char *found
)
593 while (found
!= NULL
&& is_cp_operator (start
, found
))
595 if (found
[0] == '-' && found
[1] == '-')
599 found
= find_toplevel_char (start
, *found
);
605 /* Assuming both FIRST and NEW_TOK point into the same string, return
606 the pointer that is closer to the start of the string. If FIRST is
607 NULL, returns NEW_TOK. If NEW_TOK is NULL, returns FIRST. */
610 first_of (const char *first
, const char *new_tok
)
614 else if (new_tok
!= NULL
&& new_tok
< first
)
620 /* A lexer for functions in explicit locations. This function will
621 advance INP past a function until the next option, or until end of
622 string. Returns a malloc'd copy of the lexed string or NULL if no
625 static gdb::unique_xmalloc_ptr
<char>
626 explicit_location_lex_one_function (const char **inp
,
627 const struct language_defn
*language
,
628 explicit_completion_info
*completion_info
)
630 const char *start
= *inp
;
635 /* If quoted, skip to the ending quote. */
636 if (strchr (get_gdb_linespec_parser_quote_characters (), *start
))
638 char quote_char
= *start
;
640 /* If the input is not an Ada operator, skip to the matching
641 closing quote and return the string. */
642 if (!(language
->la_language
== language_ada
643 && quote_char
== '\"' && is_ada_operator (start
)))
645 if (completion_info
!= NULL
)
646 completion_info
->quoted_arg_start
= start
;
648 const char *end
= find_toplevel_char (start
+ 1, quote_char
);
652 if (completion_info
== NULL
)
653 error (_("Unmatched quote, %s."), start
);
655 end
= start
+ strlen (start
);
657 char *saved
= savestring (start
+ 1, *inp
- start
- 1);
658 return gdb::unique_xmalloc_ptr
<char> (saved
);
661 if (completion_info
!= NULL
)
662 completion_info
->quoted_arg_end
= end
;
664 char *saved
= savestring (start
+ 1, *inp
- start
- 2);
665 return gdb::unique_xmalloc_ptr
<char> (saved
);
669 const char *comma
= find_toplevel_char (start
, ',');
671 /* If we have "-function -myfunction", or perhaps better example,
672 "-function -[BasicClass doIt]" (objc selector), treat
673 "-myfunction" as the function name. I.e., skip the first char if
674 it is an hyphen. Don't skip the first char always, because we
675 may have C++ "operator<", and find_toplevel_char needs to see the
679 ? find_toplevel_char (start
+ 1, '-')
680 : find_toplevel_char (start
, '-'));
682 /* Check for C++ "operator," and "operator-". */
683 comma
= skip_op_false_positives (start
, comma
);
684 hyphen
= skip_op_false_positives (start
, hyphen
);
686 /* Pick the one that appears first. */
687 const char *end
= first_of (hyphen
, comma
);
689 /* See if a linespec keyword appears first. */
690 const char *s
= start
;
691 const char *ws
= find_toplevel_char (start
, ' ');
692 while (ws
!= NULL
&& linespec_lexer_lex_keyword (ws
+ 1) == NULL
)
695 ws
= find_toplevel_char (s
, ' ');
698 end
= first_of (end
, ws
+ 1);
700 /* If we don't have any terminator, then take the whole string. */
702 end
= start
+ strlen (start
);
704 /* Trim whitespace at the end. */
705 while (end
> start
&& end
[-1] == ' ')
710 if (*inp
- start
> 0)
711 return gdb::unique_xmalloc_ptr
<char> (savestring (start
, *inp
- start
));
716 /* See description in location.h. */
719 string_to_explicit_location (const char **argp
,
720 const struct language_defn
*language
,
721 explicit_completion_info
*completion_info
)
723 event_location_up location
;
725 /* It is assumed that input beginning with '-' and a non-digit
726 character is an explicit location. "-p" is reserved, though,
727 for probe locations. */
731 || !isalpha ((*argp
)[1])
732 || ((*argp
)[0] == '-' && (*argp
)[1] == 'p'))
735 location
= new_explicit_location (NULL
);
737 /* Process option/argument pairs. dprintf_command
738 requires that processing stop on ','. */
739 while ((*argp
)[0] != '\0' && (*argp
)[0] != ',')
744 /* Clear these on each iteration, since they should be filled
745 with info about the last option. */
746 if (completion_info
!= NULL
)
748 completion_info
->quoted_arg_start
= NULL
;
749 completion_info
->quoted_arg_end
= NULL
;
752 /* If *ARGP starts with a keyword, stop processing
754 if (linespec_lexer_lex_keyword (*argp
) != NULL
)
757 /* Mark the start of the string in case we need to rewind. */
760 if (completion_info
!= NULL
)
761 completion_info
->last_option
= start
;
763 /* Get the option string. */
764 gdb::unique_xmalloc_ptr
<char> opt
765 = explicit_location_lex_one (argp
, language
, NULL
);
767 /* Use the length of the option to allow abbreviations. */
768 len
= strlen (opt
.get ());
770 /* Get the argument string. */
771 *argp
= skip_spaces (*argp
);
773 /* All options have a required argument. Checking for this
774 required argument is deferred until later. */
775 gdb::unique_xmalloc_ptr
<char> oarg
;
776 /* True if we have an argument. This is required because we'll
777 move from OARG before checking whether we have an
779 bool have_oarg
= false;
781 /* True if the option needs an argument. */
782 bool need_oarg
= false;
784 /* Convenience to consistently set both OARG/HAVE_OARG from
786 auto set_oarg
= [&] (gdb::unique_xmalloc_ptr
<char> arg
)
788 if (completion_info
!= NULL
)
790 /* We do this here because the set of options that take
791 arguments matches the set of explicit location
793 completion_info
->saw_explicit_location_option
= true;
795 oarg
= std::move (arg
);
796 have_oarg
= oarg
!= NULL
;
800 if (strncmp (opt
.get (), "-source", len
) == 0)
802 set_oarg (explicit_location_lex_one (argp
, language
,
804 EL_EXPLICIT (location
)->source_filename
= oarg
.release ();
806 else if (strncmp (opt
.get (), "-function", len
) == 0)
808 set_oarg (explicit_location_lex_one_function (argp
, language
,
810 EL_EXPLICIT (location
)->function_name
= oarg
.release ();
812 else if (strncmp (opt
.get (), "-qualified", len
) == 0)
814 EL_EXPLICIT (location
)->func_name_match_type
815 = symbol_name_match_type::FULL
;
817 else if (strncmp (opt
.get (), "-line", len
) == 0)
819 set_oarg (explicit_location_lex_one (argp
, language
, NULL
));
820 *argp
= skip_spaces (*argp
);
823 EL_EXPLICIT (location
)->line_offset
824 = linespec_parse_line_offset (oarg
.get ());
828 else if (strncmp (opt
.get (), "-label", len
) == 0)
830 set_oarg (explicit_location_lex_one (argp
, language
, completion_info
));
831 EL_EXPLICIT (location
)->label_name
= oarg
.release ();
833 /* Only emit an "invalid argument" error for options
834 that look like option strings. */
835 else if (opt
.get ()[0] == '-' && !isdigit (opt
.get ()[1]))
837 if (completion_info
== NULL
)
838 error (_("invalid explicit location argument, \"%s\""), opt
.get ());
842 /* End of the explicit location specification.
843 Stop parsing and return whatever explicit location was
849 *argp
= skip_spaces (*argp
);
851 /* It's a little lame to error after the fact, but in this
852 case, it provides a much better user experience to issue
853 the "invalid argument" error before any missing
855 if (need_oarg
&& !have_oarg
&& completion_info
== NULL
)
856 error (_("missing argument for \"%s\""), opt
.get ());
859 /* One special error check: If a source filename was given
860 without offset, function, or label, issue an error. */
861 if (EL_EXPLICIT (location
)->source_filename
!= NULL
862 && EL_EXPLICIT (location
)->function_name
== NULL
863 && EL_EXPLICIT (location
)->label_name
== NULL
864 && (EL_EXPLICIT (location
)->line_offset
.sign
== LINE_OFFSET_UNKNOWN
)
865 && completion_info
== NULL
)
867 error (_("Source filename requires function, label, or "
874 /* See description in location.h. */
877 string_to_event_location_basic (const char **stringp
,
878 const struct language_defn
*language
,
879 symbol_name_match_type match_type
)
881 event_location_up location
;
884 /* Try the input as a probe spec. */
886 if (cs
!= NULL
&& probe_linespec_to_static_ops (&cs
) != NULL
)
888 location
= new_probe_location (*stringp
);
889 *stringp
+= strlen (*stringp
);
893 /* Try an address location. */
894 if (*stringp
!= NULL
&& **stringp
== '*')
896 const char *arg
, *orig
;
899 orig
= arg
= *stringp
;
900 addr
= linespec_expression_to_pc (&arg
);
901 location
= new_address_location (addr
, orig
, arg
- orig
);
902 *stringp
+= arg
- orig
;
906 /* Everything else is a linespec. */
907 location
= new_linespec_location (stringp
, match_type
);
914 /* See description in location.h. */
917 string_to_event_location (const char **stringp
,
918 const struct language_defn
*language
,
919 symbol_name_match_type match_type
)
921 const char *arg
, *orig
;
923 /* Try an explicit location. */
924 orig
= arg
= *stringp
;
925 event_location_up location
= string_to_explicit_location (&arg
, language
, NULL
);
926 if (location
!= NULL
)
928 /* It was a valid explicit location. Advance STRINGP to
930 *stringp
+= arg
- orig
;
932 /* If the user really specified a location, then we're done. */
933 if (!event_location_empty_p (location
.get ()))
936 /* Otherwise, the user _only_ specified optional flags like
937 "-qualified", otherwise string_to_explicit_location would
938 have thrown an error. Save the flags for "basic" linespec
939 parsing below and discard the explicit location. */
940 match_type
= EL_EXPLICIT (location
)->func_name_match_type
;
943 /* Everything else is a "basic" linespec, address, or probe
945 return string_to_event_location_basic (stringp
, language
, match_type
);
948 /* See description in location.h. */
951 event_location_empty_p (const struct event_location
*location
)
953 switch (EL_TYPE (location
))
955 case LINESPEC_LOCATION
:
956 /* Linespecs are never "empty." (NULL is a valid linespec) */
959 case ADDRESS_LOCATION
:
962 case EXPLICIT_LOCATION
:
963 return (EL_EXPLICIT (location
) == NULL
964 || (EL_EXPLICIT (location
)->source_filename
== NULL
965 && EL_EXPLICIT (location
)->function_name
== NULL
966 && EL_EXPLICIT (location
)->label_name
== NULL
967 && (EL_EXPLICIT (location
)->line_offset
.sign
968 == LINE_OFFSET_UNKNOWN
)));
971 return EL_PROBE (location
) == NULL
;
974 gdb_assert_not_reached ("unknown event location type");
978 /* See description in location.h. */
981 set_event_location_string (struct event_location
*location
,
984 xfree (EL_STRING (location
));
985 EL_STRING (location
) = string
== NULL
? NULL
: xstrdup (string
);