20#include "gdbsupport/gdb_assert.h"
21#include "gdbsupport/gdb-checked-static-cast.h"
42 return (str !=
nullptr ? xstrdup (str) :
nullptr);
71 match_type (match_type_)
110 match_type (other.match_type),
129 const char *addr_string,
134 if (addr_string !=
nullptr)
135 m_as_string = std::string (addr_string, addr_string_len);
153 address (other.address)
160 const char *addr_string = core_addr_to_string (
address);
161 return std::string (
"*") + addr_string;
181 func_name_match_type (other.func_name_match_type),
224 return gdb::checked_static_cast<const linespec_location_spec *> (locspec);
243 return gdb::checked_static_cast<const address_location_spec *> (locspec);
260 return gdb::checked_static_cast<const probe_location_spec *> (locspec);
269 return gdb::checked_static_cast<const explicit_location_spec *> (locspec);
278 return gdb::checked_static_cast<explicit_location_spec *> (locspec);
291 bool need_space =
false;
292 char space = as_linespec ?
':' :
' ';
298 buf.
puts (
"-source ");
308 buf.
puts (
"-qualified ");
310 buf.
puts (
"-function ");
320 buf.
puts (
"-label ");
359 char nested_quote_char =
'\0';
363 if (nested_quote_char !=
'\0')
365 if (*
scan == nested_quote_char)
366 nested_quote_char =
'\0';
367 else if (
scan[0] ==
'\\' && *(
scan + 1) !=
'\0')
370 else if (*
scan == end_quote_char && nested_quote_char ==
'\0')
372 else if (*
scan ==
'"' || *
scan ==
'\'')
373 nested_quote_char = *
scan;
383static gdb::unique_xmalloc_ptr<char>
388 const char *start = *inp;
396 if (completion_info != NULL)
403 if (completion_info == NULL)
404 error (_(
"Unmatched quote, %s."), start);
406 end = start + strlen (start);
408 return gdb::unique_xmalloc_ptr<char> (savestring (start + 1,
412 if (completion_info != NULL)
415 return gdb::unique_xmalloc_ptr<char> (savestring (start + 1,
421 if (*start ==
'-' || *start ==
'+')
423 while (*inp[0] !=
'\0' && *inp[0] !=
',' && !isspace (*inp[0]))
429 while (isdigit (*inp[0]))
431 if (*inp[0] ==
'\0' || isspace (*inp[0]) || *inp[0] ==
',')
432 return gdb::unique_xmalloc_ptr<char> (savestring (start,
440 && !(isspace ((*inp)[0])
451 if (*inp - start > 0)
452 return gdb::unique_xmalloc_ptr<char> (savestring (start, *inp - start));
467 const char *p = comma;
469 while (p > start && isspace (p[-1]))
476 || !(isalnum (p[-1]) || p[-1] ==
'_')))
504 if (found[0] ==
'-' && found[1] ==
'-')
523 else if (new_tok != NULL && new_tok < first)
534static gdb::unique_xmalloc_ptr<char>
540 const char *start = *inp;
548 char quote_char = *start;
555 if (completion_info != NULL)
562 if (completion_info == NULL)
563 error (_(
"Unmatched quote, %s."), start);
565 end = start + strlen (start);
567 char *saved = savestring (start + 1, *inp - start - 1);
568 return gdb::unique_xmalloc_ptr<char> (saved);
571 if (completion_info != NULL)
574 char *saved = savestring (start + 1, *inp - start - 2);
575 return gdb::unique_xmalloc_ptr<char> (saved);
597 const char *end =
first_of (hyphen, comma);
600 const char *s = start;
612 end = start + strlen (start);
615 while (end > start && end[-1] ==
' ')
620 if (*inp - start > 0)
621 return gdb::unique_xmalloc_ptr<char> (savestring (start, *inp - start));
639 || !isalpha ((*argp)[1])
640 || ((*argp)[0] ==
'-' && (*argp)[1] ==
'p'))
643 std::unique_ptr<explicit_location_spec> locspec
648 while ((*argp)[0] !=
'\0' && (*argp)[0] !=
',')
655 if (completion_info != NULL)
669 if (completion_info != NULL)
673 gdb::unique_xmalloc_ptr<char> opt
677 len = strlen (opt.get ());
680 *argp = skip_spaces (*argp);
684 gdb::unique_xmalloc_ptr<char> oarg;
688 bool have_oarg =
false;
691 bool need_oarg =
false;
695 auto set_oarg = [&] (gdb::unique_xmalloc_ptr<char> arg)
697 if (completion_info != NULL)
704 oarg = std::move (arg);
705 have_oarg = oarg != NULL;
709 if (strncmp (opt.get (),
"-source", len) == 0)
713 locspec->source_filename = oarg.release ();
715 else if (strncmp (opt.get (),
"-function", len) == 0)
719 locspec->function_name = oarg.release ();
721 else if (strncmp (opt.get (),
"-qualified", len) == 0)
725 else if (strncmp (opt.get (),
"-line", len) == 0)
728 *argp = skip_spaces (*argp);
735 else if (strncmp (opt.get (),
"-label", len) == 0)
739 locspec->label_name = oarg.release ();
743 else if (opt.get ()[0] ==
'-' && !isdigit (opt.get ()[1]))
745 if (completion_info == NULL)
746 error (_(
"invalid explicit location argument, \"%s\""), opt.get ());
757 *argp = skip_spaces (*argp);
763 if (need_oarg && !have_oarg && completion_info == NULL)
764 error (_(
"missing argument for \"%s\""), opt.get ());
769 if (locspec->source_filename != NULL
770 && locspec->function_name == NULL
771 && locspec->label_name == NULL
773 && completion_info == NULL)
775 error (_(
"Source filename requires function, label, or "
797 *stringp += strlen (*stringp);
802 if (*stringp != NULL && **stringp ==
'*')
804 const char *arg, *orig;
807 orig = arg = *stringp;
810 *stringp += arg - orig;
829 const char *arg, *orig;
832 orig = arg = *stringp;
835 if (locspec !=
nullptr)
839 *stringp += arg - orig;
843 if (!locspec->empty_p ())
852 = gdb::checked_static_cast<explicit_location_spec *> (locspec.get ());
virtual void puts(const char *str)
void printf(const char *,...) ATTRIBUTE_PRINTF(2
const char * remove_trailing_whitespace(const char *start, const char *s)
const char * find_toplevel_char(const char *s, char c)
int is_ada_operator(const char *string)
void linespec_lex_to_end(const char **stringp)
const char * linespec_lexer_lex_keyword(const char *p)
const char * get_gdb_linespec_parser_quote_characters(void)
CORE_ADDR linespec_expression_to_pc(const char **exp_ptr)
struct line_offset linespec_parse_line_offset(const char *string)
static const char * first_of(const char *first, const char *new_tok)
const explicit_location_spec * as_explicit_location_spec(const location_spec *locspec)
location_spec_up new_address_location_spec(CORE_ADDR addr, const char *addr_string, int addr_string_len)
static const char * find_end_quote(const char *s, char end_quote_char)
static bool is_cp_operator(const char *start, const char *comma)
static char * maybe_xstrdup(const char *str)
static std::string explicit_to_string_internal(bool as_linespec, const explicit_location_spec *explicit_loc)
location_spec_up string_to_location_spec_basic(const char **stringp, const struct language_defn *language, symbol_name_match_type match_type)
const address_location_spec * as_address_location_spec(const location_spec *locspec)
const linespec_location_spec * as_linespec_location_spec(const location_spec *locspec)
static gdb::unique_xmalloc_ptr< char > explicit_location_spec_lex_one(const char **inp, const struct language_defn *language, explicit_completion_info *completion_info)
const probe_location_spec * as_probe_location_spec(const location_spec *locspec)
static gdb::unique_xmalloc_ptr< char > explicit_location_spec_lex_one_function(const char **inp, const struct language_defn *language, explicit_completion_info *completion_info)
location_spec_up string_to_location_spec(const char **stringp, const struct language_defn *language, symbol_name_match_type match_type)
location_spec_up new_probe_location_spec(std::string &&probe)
location_spec_up new_linespec_location_spec(const char **linespec, symbol_name_match_type match_type)
static const char * skip_op_false_positives(const char *start, const char *found)
location_spec_up string_to_explicit_location_spec(const char **argp, const struct language_defn *language, explicit_completion_info *completion_info)
std::unique_ptr< location_spec > location_spec_up
static void scan(growable_macro_buffer *dest, shared_macro_buffer *src, struct macro_name_list *no_loop, const macro_scope &scope)
const struct static_probe_ops * probe_linespec_to_static_ops(const char **linespecp)
bool empty_p() const override
std::string compute_string() const override
address_location_spec(CORE_ADDR addr, const char *addr_string, int addr_string_len)
location_spec_up clone() const override
const char * quoted_arg_end
const char * quoted_arg_start
bool saw_explicit_location_spec_option
~explicit_location_spec()
struct line_offset line_offset
bool empty_p() const override
std::string compute_string() const override
symbol_name_match_type func_name_match_type
location_spec_up clone() const override
std::string to_linespec() const
enum offset_relative_sign sign
symbol_name_match_type match_type
location_spec_up clone() const override
std::string compute_string() const override
bool empty_p() const override
~linespec_location_spec()
linespec_location_spec(const char **linespec, symbol_name_match_type match_type)
enum location_spec_type type() const
bool empty_p() const override
std::string compute_string() const override
probe_location_spec(std::string &&probe)
location_spec_up clone() const override