DEF_VEC_O (bound_minimal_symbol_d);
-/* An enumeration of possible signs for a line offset. */
-enum offset_relative_sign
-{
- /* No sign */
- LINE_OFFSET_NONE,
-
- /* A plus sign ("+") */
- LINE_OFFSET_PLUS,
-
- /* A minus sign ("-") */
- LINE_OFFSET_MINUS,
-
- /* A special "sign" for unspecified offset. */
- LINE_OFFSET_UNKNOWN
-};
-
-/* A line offset in a linespec. */
-
-struct line_offset
-{
- /* Line offset and any specified sign. */
- int offset;
- enum offset_relative_sign sign;
-};
-
/* A linespec. Elements of this structure are filled in by a parser
(either parse_linespec or some other function). The structure is
then converted into SALs by convert_linespec_to_sals. */
struct linespec
{
- /* An expression and the resulting PC. Specifying an expression
- currently precludes the use of other members. */
-
- /* The expression entered by the user. */
- const char *expression;
-
- /* The resulting PC expression derived from evaluating EXPRESSION. */
- CORE_ADDR expr_pc;
-
- /* Any specified file symtabs. */
-
- /* The user-supplied source filename or NULL if none was specified. */
- const char *source_filename;
+ /* An explicit location describing the SaLs. */
+ struct explicit_location explicit_loc;
/* The list of symtabs to search to which to limit the search. May not
- be NULL. If SOURCE_FILENAME is NULL (no user-specified filename),
- FILE_SYMTABS should contain one single NULL member. This will
- cause the code to use the default symtab. */
+ be NULL. If explicit.SOURCE_FILENAME is NULL (no user-specified
+ filename), FILE_SYMTABS should contain one single NULL member. This
+ will cause the code to use the default symtab. */
VEC (symtab_ptr) *file_symtabs;
- /* The name of a function or method and any matching symbols. */
-
- /* The user-specified function name. If no function name was
- supplied, this may be NULL. */
- const char *function_name;
-
/* A list of matching function symbols and minimal symbols. Both lists
may be NULL if no matching symbols were found. */
VEC (symbolp) *function_symbols;
VEC (bound_minimal_symbol_d) *minimal_symbols;
- /* The name of a label and matching symbols. */
-
- /* The user-specified label name. */
- const char *label_name;
-
/* A structure of matching label symbols and the corresponding
function symbol in which the label was found. Both may be NULL
or both must be non-NULL. */
VEC (symbolp) *label_symbols;
VEC (symbolp) *function_symbols;
} labels;
-
- /* Line offset. It may be LINE_OFFSET_UNKNOWN, meaning that no
- offset was specified. */
- struct line_offset line_offset;
};
typedef struct linespec *linespec_p;
/* This is a set of address_entry objects which is used to prevent
duplicate symbols from being entered into the result. */
htab_t addr_set;
+
+ /* Are we building a linespec? */
+ int is_linespec;
};
/* This is a helper object that is used when collecting symbols into a
};
typedef struct ls_parser linespec_parser;
+/* A convenience macro for accessing the explicit location result of
+ the parser. */
+#define PARSER_EXPLICIT(PPTR) (&PARSER_RESULT ((PPTR))->explicit_loc)
+
/* Prototypes for local functions. */
static void iterate_over_file_blocks (struct symtab *symtab,
static int compare_msymbols (const void *a, const void *b);
-static const char *find_toplevel_char (const char *s, char c);
-
/* Permitted quote characters for the parser. This is different from the
completer's quote characters to allow backward compatibility with the
previous parser. */
return NULL;
}
-/* Does STRING represent an Ada operator? If so, return the length
- of the decoded operator name. If not, return 0. */
+/* See description in linespec.h. */
-static int
+int
is_ada_operator (const char *string)
{
const struct ada_opname_map *mapping;
strings. Also, ignore the char within a template name, like a ','
within foo<int, int>. */
-static const char *
+const char *
find_toplevel_char (const char *s, char c)
{
int quoted = 0; /* zero if we're not in quotes;
/* Prepare ITEMS array. */
items_count = result->nelts;
- items = xmalloc (sizeof (*items) * items_count);
+ items = XNEWVEC (struct decode_line_2_item, items_count);
make_cleanup (xfree, items);
for (i = 0; i < items_count; ++i)
{
token_type_strings[token.type]);
}
-/* Parse and return a line offset in STRING. */
+/* Throw an undefined label error. */
-static struct line_offset
+static void ATTRIBUTE_NORETURN
+undefined_label_error (const char *function, const char *label)
+{
+ if (function != NULL)
+ throw_error (NOT_FOUND_ERROR,
+ _("No label \"%s\" defined in function \"%s\"."),
+ label, function);
+ else
+ throw_error (NOT_FOUND_ERROR,
+ _("No label \"%s\" defined in current function."),
+ label);
+}
+
+/* Throw a source file not found error. */
+
+static void ATTRIBUTE_NORETURN
+source_file_not_found_error (const char *name)
+{
+ throw_error (NOT_FOUND_ERROR, _("No source file named %s."), name);
+}
+
+/* See description in linespec.h. */
+
+struct line_offset
linespec_parse_line_offset (const char *string)
{
+ const char *start = string;
struct line_offset line_offset = {0, LINE_OFFSET_NONE};
if (*string == '+')
++string;
}
+ if (*string != '\0' && !isdigit (*string))
+ error (_("malformed line offset: \"%s\""), start);
+
/* Right now, we only allow base 10 for offsets. */
line_offset.offset = atoi (string);
return line_offset;
/* Record the line offset and get the next token. */
name = copy_token_string (token);
cleanup = make_cleanup (xfree, name);
- PARSER_RESULT (parser)->line_offset = linespec_parse_line_offset (name);
+ PARSER_EXPLICIT (parser)->line_offset = linespec_parse_line_offset (name);
do_cleanups (cleanup);
/* Get the next token. */
{
PARSER_RESULT (parser)->function_symbols = symbols;
PARSER_RESULT (parser)->minimal_symbols = minimal_symbols;
- PARSER_RESULT (parser)->function_name = name;
+ PARSER_EXPLICIT (parser)->function_name = name;
symbols = NULL;
discard_cleanups (cleanup);
}
{
PARSER_RESULT (parser)->labels.label_symbols = labels;
PARSER_RESULT (parser)->labels.function_symbols = symbols;
- PARSER_RESULT (parser)->label_name = name;
+ PARSER_EXPLICIT (parser)->label_name = name;
symbols = NULL;
discard_cleanups (cleanup);
}
&& *LS_TOKEN_STOKEN (token).ptr == '$')
{
/* User specified a convenience variable or history value. */
- PARSER_RESULT (parser)->line_offset
+ PARSER_EXPLICIT (parser)->line_offset
= linespec_parse_variable (PARSER_STATE (parser), name);
- if (PARSER_RESULT (parser)->line_offset.sign == LINE_OFFSET_UNKNOWN)
+ if (PARSER_EXPLICIT (parser)->line_offset.sign == LINE_OFFSET_UNKNOWN)
{
/* The user-specified variable was not valid. Do not
throw an error here. parse_linespec will do it for us. */
- PARSER_RESULT (parser)->function_name = name;
+ PARSER_EXPLICIT (parser)->function_name = name;
discard_cleanups (cleanup);
return;
}
an error here. parse_linespec will do it for us. */
/* Save a copy of the name we were trying to lookup. */
- PARSER_RESULT (parser)->function_name = name;
+ PARSER_EXPLICIT (parser)->function_name = name;
discard_cleanups (cleanup);
return;
}
get the next token. */
name = copy_token_string (token);
cleanup = make_cleanup (xfree, name);
- PARSER_RESULT (parser)->line_offset
+ PARSER_EXPLICIT (parser)->line_offset
= linespec_parse_line_offset (name);
do_cleanups (cleanup);
{
PARSER_RESULT (parser)->labels.label_symbols = labels;
PARSER_RESULT (parser)->labels.function_symbols = symbols;
- PARSER_RESULT (parser)->label_name = name;
+ PARSER_EXPLICIT (parser)->label_name = name;
symbols = NULL;
discard_cleanups (cleanup);
}
else
{
/* We don't know what it was, but it isn't a label. */
- throw_error (NOT_FOUND_ERROR,
- _("No label \"%s\" defined in function \"%s\"."),
- name, PARSER_RESULT (parser)->function_name);
+ undefined_label_error (PARSER_EXPLICIT (parser)->function_name,
+ name);
}
/* Check for a line offset. */
name = copy_token_string (token);
cleanup = make_cleanup (xfree, name);
- PARSER_RESULT (parser)->line_offset
+ PARSER_EXPLICIT (parser)->line_offset
= linespec_parse_line_offset (name);
do_cleanups (cleanup);
}
/* Canonicalize the linespec contained in LS. The result is saved into
- STATE->canonical. */
+ STATE->canonical. This function handles both linespec and explicit
+ locations. */
static void
canonicalize_linespec (struct linespec_state *state, const linespec_p ls)
{
- char *tmp;
- struct ui_file *buf;
- int need_colon = 0;
- struct cleanup *cleanup;
+ struct event_location *canon;
+ struct explicit_location *explicit_loc;
/* If canonicalization was not requested, no need to do anything. */
if (!state->canonical)
return;
- buf = mem_fileopen ();
- cleanup = make_cleanup_ui_file_delete (buf);
-
- if (ls->source_filename)
- {
- fputs_unfiltered (ls->source_filename, buf);
- need_colon = 1;
- }
-
- if (ls->function_name)
- {
- if (need_colon)
- fputc_unfiltered (':', buf);
- fputs_unfiltered (ls->function_name, buf);
- need_colon = 1;
- }
+ /* Save everything as an explicit location. */
+ canon = state->canonical->location
+ = new_explicit_location (&ls->explicit_loc);
+ explicit_loc = get_explicit_location (canon);
- if (ls->label_name)
+ if (explicit_loc->label_name != NULL)
{
- if (need_colon)
- fputc_unfiltered (':', buf);
+ state->canonical->special_display = 1;
- if (ls->function_name == NULL)
+ if (explicit_loc->function_name == NULL)
{
struct symbol *s;
&& (VEC_length (symbolp, ls->labels.function_symbols)
== 1));
s = VEC_index (symbolp, ls->labels.function_symbols, 0);
- fputs_unfiltered (SYMBOL_NATURAL_NAME (s), buf);
- fputc_unfiltered (':', buf);
+ explicit_loc->function_name = xstrdup (SYMBOL_NATURAL_NAME (s));
}
-
- fputs_unfiltered (ls->label_name, buf);
- need_colon = 1;
- state->canonical->special_display = 1;
}
- if (ls->line_offset.sign != LINE_OFFSET_UNKNOWN)
+ /* If this location originally came from a linespec, save a string
+ representation of it for display and saving to file. */
+ if (state->is_linespec)
{
- if (need_colon)
- fputc_unfiltered (':', buf);
- fprintf_filtered (buf, "%s%d",
- (ls->line_offset.sign == LINE_OFFSET_NONE ? ""
- : (ls->line_offset.sign
- == LINE_OFFSET_PLUS ? "+" : "-")),
- ls->line_offset.offset);
- }
+ char *linespec = explicit_location_to_linespec (explicit_loc);
- tmp = ui_file_xstrdup (buf, NULL);
- make_cleanup (xfree, tmp);
- state->canonical->location = new_linespec_location (&tmp);
- do_cleanups (cleanup);
+ set_event_location_string (canon, linespec);
+ xfree (linespec);
+ }
}
/* Given a line offset in LS, construct the relevant SALs. */
use_default = 1;
}
- val.line = ls->line_offset.offset;
- switch (ls->line_offset.sign)
+ val.line = ls->explicit_loc.line_offset.offset;
+ switch (ls->explicit_loc.line_offset.sign)
{
case LINE_OFFSET_PLUS:
- if (ls->line_offset.offset == 0)
+ if (ls->explicit_loc.line_offset.offset == 0)
val.line = 5;
if (use_default)
val.line = self->default_line + val.line;
break;
case LINE_OFFSET_MINUS:
- if (ls->line_offset.offset == 0)
+ if (ls->explicit_loc.line_offset.offset == 0)
val.line = 15;
if (use_default)
val.line = self->default_line - val.line;
if (values.nelts == 0)
{
- if (ls->source_filename)
+ if (ls->explicit_loc.source_filename)
throw_error (NOT_FOUND_ERROR, _("No line %d in file \"%s\"."),
- val.line, ls->source_filename);
+ val.line, ls->explicit_loc.source_filename);
else
throw_error (NOT_FOUND_ERROR, _("No line %d in the current file."),
val.line);
}
}
}
- else if (ls->line_offset.sign != LINE_OFFSET_UNKNOWN)
+ else if (ls->explicit_loc.line_offset.sign != LINE_OFFSET_UNKNOWN)
{
/* Only an offset was specified. */
sals = create_sals_line_offset (state, ls);
/* Make sure we have a filename for canonicalization. */
- if (ls->source_filename == NULL)
+ if (ls->explicit_loc.source_filename == NULL)
{
const char *fullname = symtab_to_fullname (state->default_symtab);
form so that displaying SOURCE_FILENAME can follow the current
FILENAME_DISPLAY_STRING setting. But as it is used only rarely
it has been kept for code simplicity only in absolute form. */
- ls->source_filename = xstrdup (fullname);
+ ls->explicit_loc.source_filename = xstrdup (fullname);
}
}
else
return sals;
}
+/* Convert the explicit location EXPLICIT_LOC into SaLs. */
+
+static struct symtabs_and_lines
+convert_explicit_location_to_sals (struct linespec_state *self,
+ linespec_p result,
+ const struct explicit_location *explicit_loc)
+{
+ VEC (symbolp) *symbols, *labels;
+ VEC (bound_minimal_symbol_d) *minimal_symbols;
+
+ if (explicit_loc->source_filename != NULL)
+ {
+ TRY
+ {
+ result->file_symtabs
+ = symtabs_from_filename (explicit_loc->source_filename);
+ }
+ CATCH (except, RETURN_MASK_ERROR)
+ {
+ source_file_not_found_error (explicit_loc->source_filename);
+ }
+ END_CATCH
+ result->explicit_loc.source_filename
+ = xstrdup (explicit_loc->source_filename);
+ }
+ else
+ {
+ /* A NULL entry means to use the default symtab. */
+ VEC_safe_push (symtab_ptr, result->file_symtabs, NULL);
+ }
+
+ if (explicit_loc->function_name != NULL)
+ {
+ find_linespec_symbols (self, result->file_symtabs,
+ explicit_loc->function_name, &symbols,
+ &minimal_symbols);
+
+ if (symbols == NULL && minimal_symbols == NULL)
+ symbol_not_found_error (explicit_loc->function_name,
+ result->explicit_loc.source_filename);
+
+ result->explicit_loc.function_name
+ = xstrdup (explicit_loc->function_name);
+ result->function_symbols = symbols;
+ result->minimal_symbols = minimal_symbols;
+ }
+
+ if (explicit_loc->label_name != NULL)
+ {
+ symbols = NULL;
+ labels = find_label_symbols (self, result->function_symbols,
+ &symbols, explicit_loc->label_name);
+
+ if (labels == NULL)
+ undefined_label_error (result->explicit_loc.function_name,
+ explicit_loc->label_name);
+
+ result->explicit_loc.label_name = xstrdup (explicit_loc->label_name);
+ result->labels.label_symbols = labels;
+ result->labels.function_symbols = symbols;
+ }
+
+ if (explicit_loc->line_offset.sign != LINE_OFFSET_UNKNOWN)
+ result->explicit_loc.line_offset = explicit_loc->line_offset;
+
+ return convert_linespec_to_sals (self, result);
+}
+
/* Parse a string that specifies a linespec.
The basic grammar of linespecs:
/* User specified a convenience variable or history value. */
var = copy_token_string (token);
cleanup = make_cleanup (xfree, var);
- PARSER_RESULT (parser)->line_offset
+ PARSER_EXPLICIT (parser)->line_offset
= linespec_parse_variable (PARSER_STATE (parser), var);
do_cleanups (cleanup);
/* If a line_offset wasn't found (VAR is the name of a user
variable/function), then skip to normal symbol processing. */
- if (PARSER_RESULT (parser)->line_offset.sign != LINE_OFFSET_UNKNOWN)
+ if (PARSER_EXPLICIT (parser)->line_offset.sign != LINE_OFFSET_UNKNOWN)
{
/* Consume this token. */
linespec_lexer_consume_token (parser);
if (file_exception.reason >= 0)
{
/* Symtabs were found for the file. Record the filename. */
- PARSER_RESULT (parser)->source_filename = user_filename;
+ PARSER_EXPLICIT (parser)->source_filename = user_filename;
/* Get the next token. */
token = linespec_lexer_consume_token (parser);
if (PARSER_RESULT (parser)->function_symbols == NULL
&& PARSER_RESULT (parser)->labels.label_symbols == NULL
- && PARSER_RESULT (parser)->line_offset.sign == LINE_OFFSET_UNKNOWN
+ && PARSER_EXPLICIT (parser)->line_offset.sign == LINE_OFFSET_UNKNOWN
&& PARSER_RESULT (parser)->minimal_symbols == NULL)
{
/* The linespec didn't parse. Re-throw the file exception if
throw_exception (file_exception);
/* Otherwise, the symbol is not found. */
- symbol_not_found_error (PARSER_RESULT (parser)->function_name,
- PARSER_RESULT (parser)->source_filename);
+ symbol_not_found_error (PARSER_EXPLICIT (parser)->function_name,
+ PARSER_EXPLICIT (parser)->source_filename);
}
convert_to_sals:
self->program_space = current_program_space;
self->addr_set = htab_create_alloc (10, hash_address_entry, eq_address_entry,
xfree, xcalloc, xfree);
+ self->is_linespec = 0;
}
/* Initialize a new linespec parser. */
memset (parser, 0, sizeof (linespec_parser));
parser->lexer.current.type = LSTOKEN_CONSUMED;
memset (PARSER_RESULT (parser), 0, sizeof (struct linespec));
- PARSER_RESULT (parser)->line_offset.sign = LINE_OFFSET_UNKNOWN;
+ PARSER_EXPLICIT (parser)->line_offset.sign = LINE_OFFSET_UNKNOWN;
linespec_state_constructor (PARSER_STATE (parser), flags, language,
default_symtab, default_line, canonical);
}
{
linespec_parser *parser = (linespec_parser *) arg;
- xfree ((char *) PARSER_RESULT (parser)->expression);
- xfree ((char *) PARSER_RESULT (parser)->source_filename);
- xfree ((char *) PARSER_RESULT (parser)->label_name);
- xfree ((char *) PARSER_RESULT (parser)->function_name);
+ xfree (PARSER_EXPLICIT (parser)->source_filename);
+ xfree (PARSER_EXPLICIT (parser)->label_name);
+ xfree (PARSER_EXPLICIT (parser)->function_name);
if (PARSER_RESULT (parser)->file_symtabs != NULL)
VEC_free (symtab_ptr, PARSER_RESULT (parser)->file_symtabs);
{
case LINESPEC_LOCATION:
{
+ PARSER_STATE (parser)->is_linespec = 1;
TRY
{
result = parse_linespec (parser, get_linespec_location (location));
get_address_location (location));
break;
+ case EXPLICIT_LOCATION:
+ {
+ const struct explicit_location *explicit_loc;
+
+ explicit_loc = get_explicit_location_const (location);
+ result = convert_explicit_location_to_sals (PARSER_STATE (parser),
+ PARSER_RESULT (parser),
+ explicit_loc);
+ }
+ break;
+
+ case PROBE_LOCATION:
+ /* 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");
}
memcpy (saved_arg, arg, new_argptr - arg);
saved_arg[new_argptr - arg] = '\0';
- ls->function_name = xstrdup (saved_arg);
+ ls->explicit_loc.function_name = xstrdup (saved_arg);
ls->function_symbols = info.result.symbols;
ls->minimal_symbols = info.result.minimal_symbols;
values = convert_linespec_to_sals (self, ls);
self->canonical->pre_expanded = 1;
- if (ls->source_filename)
+ if (ls->explicit_loc.source_filename)
{
str = xstrprintf ("%s:%s",
- ls->source_filename, saved_arg);
+ ls->explicit_loc.source_filename, saved_arg);
}
else
str = xstrdup (saved_arg);
throw_error (NOT_FOUND_ERROR,
_("No symbol table is loaded. "
"Use the \"file\" command."));
- throw_error (NOT_FOUND_ERROR, _("No source file named %s."), filename);
+ source_file_not_found_error (filename);
}
return result;
sal.pc = MSYMBOL_VALUE_ADDRESS (objfile, msymbol);
sal.pc = gdbarch_convert_from_func_ptr_addr (gdbarch, sal.pc,
¤t_target);
+ if (gdbarch_skip_entrypoint_p (gdbarch))
+ sal.pc = gdbarch_skip_entrypoint (gdbarch, sal.pc);
}
else
skip_prologue_sal (&sal);
{
return make_cleanup (cleanup_linespec_result, ls);
}
+
+/* Return the quote characters permitted by the linespec parser. */
+
+const char *
+get_gdb_linespec_parser_quote_characters (void)
+{
+ return linespec_quote_characters;
+}