/* Parser for linespec for the GNU debugger, GDB.
- Copyright (C) 1986-2013 Free Software Foundation, Inc.
+ Copyright (C) 1986-2015 Free Software Foundation, Inc.
This file is part of GDB.
#include "block.h"
#include "objc-lang.h"
#include "linespec.h"
-#include "exceptions.h"
#include "language.h"
#include "interps.h"
#include "mi/mi-cmds.h"
CORE_ADDR addr;
};
-/* A helper struct which just holds a minimal symbol and the object
- file from which it came. */
+typedef struct bound_minimal_symbol bound_minimal_symbol_d;
-typedef struct minsym_and_objfile
-{
- struct minimal_symbol *minsym;
- struct objfile *objfile;
-} minsym_and_objfile_d;
-
-DEF_VEC_O (minsym_and_objfile_d);
+DEF_VEC_O (bound_minimal_symbol_d);
/* An enumeration of possible signs for a line offset. */
enum offset_relative_sign
/* 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 (minsym_and_objfile_d) *minimal_symbols;
+ VEC (bound_minimal_symbol_d) *minimal_symbols;
/* The name of a label and matching symbols. */
struct
{
VEC (symbolp) *symbols;
- VEC (minsym_and_objfile_d) *minimal_symbols;
+ VEC (bound_minimal_symbol_d) *minimal_symbols;
} result;
};
/* List of keywords */
static const char * const linespec_keywords[] = { "if", "thread", "task" };
+#define IF_KEYWORD_INDEX 0
/* A token of the linespec lexer */
struct
{
/* Save head of input stream. */
- char *saved_arg;
+ const char *saved_arg;
/* Head of the input stream. */
- char **stream;
+ const char **stream;
#define PARSER_STREAM(P) (*(P)->lexer.stream)
/* The current token. */
/* Is the entire linespec quote-enclosed? */
int is_quote_enclosed;
- /* Is a keyword syntactically valid at this point?
- In, e.g., "break thread thread 1", the leading "keyword" must not
- be interpreted as such. */
- int keyword_ok;
-
/* The state of the parse. */
struct linespec_state state;
#define PARSER_STATE(PPTR) (&(PPTR)->state)
static struct symtabs_and_lines decode_objc (struct linespec_state *self,
linespec_p ls,
- char **argptr);
+ const char **argptr);
static VEC (symtab_ptr) *symtabs_from_filename (const char *);
VEC (symtab_ptr) *file_symtabs,
const char *name,
VEC (symbolp) **symbols,
- VEC (minsym_and_objfile_d) **minsyms);
+ VEC (bound_minimal_symbol_d) **minsyms);
static struct line_offset
linespec_parse_variable (struct linespec_state *self,
return 1;
}
-/* Does P represent one of the keywords? If so, return
- the keyword. If not, return NULL. */
+/* See linespec.h. */
-static const char *
+const char *
linespec_lexer_lex_keyword (const char *p)
{
int i;
int len = strlen (linespec_keywords[i]);
/* If P begins with one of the keywords and the next
- character is not a valid identifier character,
- we have found a keyword. */
+ character is whitespace, we may have found a keyword.
+ It is only a keyword if it is not followed by another
+ keyword. */
if (strncmp (p, linespec_keywords[i], len) == 0
- && !(isalnum (p[len]) || p[len] == '_'))
- return linespec_keywords[i];
+ && isspace (p[len]))
+ {
+ int j;
+
+ /* Special case: "if" ALWAYS stops the lexer, since it
+ is not possible to predict what is going to appear in
+ the condition, which can only be parsed after SaLs have
+ been found. */
+ if (i != IF_KEYWORD_INDEX)
+ {
+ p += len;
+ p = skip_spaces_const (p);
+ for (j = 0; j < ARRAY_SIZE (linespec_keywords); ++j)
+ {
+ int nextlen = strlen (linespec_keywords[j]);
+
+ if (strncmp (p, linespec_keywords[j], nextlen) == 0
+ && isspace (p[nextlen]))
+ return NULL;
+ }
+ }
+
+ return linespec_keywords[i];
+ }
}
}
for (mapping = ada_opname_table;
mapping->encoded != NULL
- && strncmp (mapping->decoded, string,
- strlen (mapping->decoded)) != 0; ++mapping)
+ && !startswith (string, mapping->decoded); ++mapping)
;
return mapping->decoded == NULL ? 0 : strlen (mapping->decoded);
This helper function assists with lexing string segments
which might contain valid (non-terminating) commas. */
-static char *
-find_parameter_list_end (char *input)
+static const char *
+find_parameter_list_end (const char *input)
{
char end_char, start_char;
int depth;
- char *p;
+ const char *p;
start_char = *input;
if (start_char == '(')
linespec_lexer_lex_string (linespec_parser *parser)
{
linespec_token token;
- char *start = PARSER_STREAM (parser);
+ const char *start = PARSER_STREAM (parser);
token.type = LSTOKEN_STRING;
}
else
{
- char *p;
+ const char *p;
/* Otherwise, only identifier characters are permitted.
Spaces are the exception. In general, we keep spaces,
{
if (isspace (*PARSER_STREAM (parser)))
{
- p = skip_spaces (PARSER_STREAM (parser));
+ p = skip_spaces_const (PARSER_STREAM (parser));
/* When we get here we know we've found something followed by
a space (we skip over parens and templates below).
So if we find a keyword now, we know it is a keyword and not,
else if (*PARSER_STREAM (parser) == '<'
|| *PARSER_STREAM (parser) == '(')
{
- char *p;
+ const char *p;
p = find_parameter_list_end (PARSER_STREAM (parser));
if (p != NULL)
if (parser->lexer.current.type == LSTOKEN_CONSUMED)
{
/* Skip any whitespace. */
- PARSER_STREAM (parser) = skip_spaces (PARSER_STREAM (parser));
+ PARSER_STREAM (parser) = skip_spaces_const (PARSER_STREAM (parser));
/* Check for a keyword, they end the linespec. */
- keyword = NULL;
- if (parser->keyword_ok)
- keyword = linespec_lexer_lex_keyword (PARSER_STREAM (parser));
+ keyword = linespec_lexer_lex_keyword (PARSER_STREAM (parser));
if (keyword != NULL)
{
parser->lexer.current.type = LSTOKEN_KEYWORD;
LS_TOKEN_KEYWORD (parser->lexer.current) = keyword;
+ /* We do not advance the stream here intentionally:
+ we would like lexing to stop when a keyword is seen.
+
+ PARSER_STREAM (parser) += strlen (keyword); */
+
return parser->lexer.current;
}
linespec_lexer_peek_token (linespec_parser *parser)
{
linespec_token next;
- char *saved_stream = PARSER_STREAM (parser);
+ const char *saved_stream = PARSER_STREAM (parser);
linespec_token saved_token = parser->lexer.current;
next = linespec_lexer_consume_token (parser);
if (symname != NULL)
canonical->suffix = xstrdup (symname);
else
- canonical->suffix = NULL;
+ canonical->suffix = xstrdup ("<unknown>");
canonical->symtab = NULL;
}
}
ALL_OBJFILES (objfile)
{
- struct symtab *symtab;
+ struct compunit_symtab *cu;
if (objfile->sf)
objfile->sf->qf->expand_symtabs_matching (objfile, NULL,
iterate_name_matcher,
- ALL_DOMAIN,
+ NULL, ALL_DOMAIN,
&matcher_data);
- ALL_OBJFILE_PRIMARY_SYMTABS (objfile, symtab)
+ ALL_OBJFILE_COMPUNITS (objfile, cu)
{
+ struct symtab *symtab = COMPUNIT_FILETABS (cu);
+
iterate_over_file_blocks (symtab, name, domain, callback, data);
if (include_inline)
int i;
for (i = FIRST_LOCAL_BLOCK;
- i < BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (symtab)); i++)
+ i < BLOCKVECTOR_NBLOCKS (SYMTAB_BLOCKVECTOR (symtab));
+ i++)
{
- block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), i);
+ block = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), i);
state->language->la_iterate_over_symbols
(block, name, domain, iterate_inline_only, &cad);
}
/* Returns the block to be used for symbol searches from
the current location. */
-static struct block *
+static const struct block *
get_current_search_block (void)
{
- struct block *block;
+ const struct block *block;
enum language save_language;
/* get_selected_block can change the current language when there is
{
struct block *block;
- for (block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
+ for (block = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), STATIC_BLOCK);
block != NULL;
block = BLOCK_SUPERBLOCK (block))
LA_ITERATE_OVER_SYMBOLS (block, name, domain, callback, data);
{
int method_counter;
- CHECK_TYPEDEF (t);
+ t = check_typedef (t);
/* Loop over each method name. At this level, all overloads of a name
are counted as a single name. There is an inner loop which loops over
const char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
char dem_opname[64];
- if (strncmp (method_name, "__", 2) == 0 ||
- strncmp (method_name, "op", 2) == 0 ||
- strncmp (method_name, "type", 4) == 0)
+ if (startswith (method_name, "__") ||
+ startswith (method_name, "op") ||
+ startswith (method_name, "type"))
{
if (cplus_demangle_opname (method_name, dem_opname, DMGL_ANSI))
method_name = dem_opname;
if (s != NULL)
{
/* Found first char in HAYSTACK; check rest of string. */
- if (strncmp (s, needle, strlen (needle)) == 0)
+ if (startswith (s, needle))
return s;
/* Didn't find it; loop over HAYSTACK, looking for the next
char *name;
linespec_token token;
VEC (symbolp) *symbols, *labels;
- VEC (minsym_and_objfile_d) *minimal_symbols;
+ VEC (bound_minimal_symbol_d) *minimal_symbols;
struct cleanup *cleanup;
/* Get the next token. */
discard_cleanups (cleanup);
return;
}
+
+ /* The convenience variable/history value parsed correctly.
+ NAME is no longer needed. */
+ do_cleanups (cleanup);
}
else
{
{
struct linetable_entry *best_entry = NULL;
int *filter;
- struct block **blocks;
+ const struct block **blocks;
struct cleanup *cleanup;
struct symtabs_and_lines intermediate_results;
int i, j;
filter = XNEWVEC (int, intermediate_results.nelts);
make_cleanup (xfree, filter);
- blocks = XNEWVEC (struct block *, intermediate_results.nelts);
+ blocks = XNEWVEC (const struct block *, intermediate_results.nelts);
make_cleanup (xfree, blocks);
for (i = 0; i < intermediate_results.nelts; ++i)
for (i = 0; VEC_iterate (symbolp, ls->labels.label_symbols, i, sym); ++i)
{
- struct program_space *pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
+ struct program_space *pspace = SYMTAB_PSPACE (symbol_symtab (sym));
if (symbol_to_sal (&sal, state->funfirstline, sym)
&& maybe_add_address (state->addr_set, pspace, sal.pc))
int i;
struct symtab_and_line sal;
struct symbol *sym;
- minsym_and_objfile_d *elem;
+ bound_minimal_symbol_d *elem;
struct program_space *pspace;
if (ls->function_symbols != NULL)
for (i = 0; VEC_iterate (symbolp, ls->function_symbols, i, sym); ++i)
{
- pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
+ pspace = SYMTAB_PSPACE (symbol_symtab (sym));
set_current_program_space (pspace);
if (symbol_to_sal (&sal, state->funfirstline, sym)
&& maybe_add_address (state->addr_set, pspace, sal.pc))
if (ls->minimal_symbols != NULL)
{
/* Sort minimal symbols by program space, too. */
- qsort (VEC_address (minsym_and_objfile_d, ls->minimal_symbols),
- VEC_length (minsym_and_objfile_d, ls->minimal_symbols),
- sizeof (minsym_and_objfile_d), compare_msymbols);
+ qsort (VEC_address (bound_minimal_symbol_d, ls->minimal_symbols),
+ VEC_length (bound_minimal_symbol_d, ls->minimal_symbols),
+ sizeof (bound_minimal_symbol_d), compare_msymbols);
for (i = 0;
- VEC_iterate (minsym_and_objfile_d, ls->minimal_symbols, i, elem);
+ VEC_iterate (bound_minimal_symbol_d, ls->minimal_symbols,
+ i, elem);
++i)
{
pspace = elem->objfile->pspace;
/* Parse the linespec in ARGPTR. */
static struct symtabs_and_lines
-parse_linespec (linespec_parser *parser, char **argptr)
+parse_linespec (linespec_parser *parser, const char **argptr)
{
linespec_token token;
struct symtabs_and_lines values;
- volatile struct gdb_exception file_exception;
+ struct gdb_exception file_exception = exception_none;
struct cleanup *cleanup;
/* A special case to start. It has become quite popular for
}
}
- /* A keyword at the start cannot be interpreted as such.
- Consider "b thread thread 42". */
- parser->keyword_ok = 0;
-
parser->lexer.saved_arg = *argptr;
parser->lexer.stream = argptr;
- file_exception.reason = 0;
/* Initialize the default symtab and line offset. */
initialize_defaults (&PARSER_STATE (parser)->default_symtab,
else if (token.type != LSTOKEN_STRING && token.type != LSTOKEN_NUMBER)
unexpected_linespec_error (parser);
- /* Now we can recognize keywords. */
- parser->keyword_ok = 1;
-
/* Shortcut: If the next token is not LSTOKEN_COLON, we know that
this token cannot represent a filename. */
token = linespec_lexer_peek_token (parser);
user_filename = copy_token_string (token);
/* Check if the input is a filename. */
- TRY_CATCH (file_exception, RETURN_MASK_ERROR)
+ TRY
{
PARSER_RESULT (parser)->file_symtabs
= symtabs_from_filename (user_filename);
}
+ CATCH (ex, RETURN_MASK_ERROR)
+ {
+ file_exception = ex;
+ }
+ END_CATCH
if (file_exception.reason >= 0)
{
VEC_free (symbolp, PARSER_RESULT (parser)->function_symbols);
if (PARSER_RESULT (parser)->minimal_symbols != NULL)
- VEC_free (minsym_and_objfile_d, PARSER_RESULT (parser)->minimal_symbols);
+ VEC_free (bound_minimal_symbol_d, PARSER_RESULT (parser)->minimal_symbols);
if (PARSER_RESULT (parser)->labels.label_symbols != NULL)
VEC_free (symbolp, PARSER_RESULT (parser)->labels.label_symbols);
VEC (const_char_ptr) *filters = NULL;
linespec_parser parser;
struct linespec_state *state;
+ const char *copy, *orig;
gdb_assert (canonical != NULL);
/* The filter only makes sense for 'all'. */
cleanups = make_cleanup (linespec_parser_delete, &parser);
save_current_program_space ();
- result = parse_linespec (&parser, argptr);
+ orig = copy = *argptr;
+ result = parse_linespec (&parser, ©);
+ *argptr += copy - orig;
state = PARSER_STATE (&parser);
gdb_assert (result.nelts == 1 || canonical->pre_expanded);
struct symtabs_and_lines result;
linespec_parser parser;
struct cleanup *cleanups;
+ const char *copy, *orig;
linespec_parser_new (&parser, flags, current_language, default_symtab,
default_line, NULL);
cleanups = make_cleanup (linespec_parser_delete, &parser);
save_current_program_space ();
- result = parse_linespec (&parser, argptr);
+ orig = copy = *argptr;
+ result = parse_linespec (&parser, ©);
+ *argptr += copy - orig;
do_cleanups (cleanups);
return result;
the existing C++ code to let the user choose one. */
static struct symtabs_and_lines
-decode_objc (struct linespec_state *self, linespec_p ls, char **argptr)
+decode_objc (struct linespec_state *self, linespec_p ls, const char **argptr)
{
struct collect_info info;
VEC (const_char_ptr) *symbol_names = NULL;
struct symtabs_and_lines values;
- char *new_argptr;
+ const char *new_argptr;
struct cleanup *cleanup = make_cleanup (VEC_cleanup (const_char_ptr),
&symbol_names);
add_all_symbol_names_from_pspace (&info, NULL, symbol_names);
if (!VEC_empty (symbolp, info.result.symbols)
- || !VEC_empty (minsym_and_objfile_d, info.result.minimal_symbols))
+ || !VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols))
{
char *saved_arg;
return 1; /* Continue iterating. */
t = SYMBOL_TYPE (sym);
- CHECK_TYPEDEF (t);
+ t = check_typedef (t);
if (TYPE_CODE (t) != TYPE_CODE_STRUCT
&& TYPE_CODE (t) != TYPE_CODE_UNION
&& TYPE_CODE (t) != TYPE_CODE_NAMESPACE)
struct symbol * const *sb = b;
uintptr_t uia, uib;
- uia = (uintptr_t) SYMTAB_PSPACE (SYMBOL_SYMTAB (*sa));
- uib = (uintptr_t) SYMTAB_PSPACE (SYMBOL_SYMTAB (*sb));
+ uia = (uintptr_t) SYMTAB_PSPACE (symbol_symtab (*sa));
+ uib = (uintptr_t) SYMTAB_PSPACE (symbol_symtab (*sb));
if (uia < uib)
return -1;
static int
compare_msymbols (const void *a, const void *b)
{
- const struct minsym_and_objfile *sa = a;
- const struct minsym_and_objfile *sb = b;
+ const struct bound_minimal_symbol *sa = a;
+ const struct bound_minimal_symbol *sb = b;
uintptr_t uia, uib;
uia = (uintptr_t) sa->objfile->pspace;
find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs,
const char *class_name, const char *method_name,
VEC (symbolp) *sym_classes, VEC (symbolp) **symbols,
- VEC (minsym_and_objfile_d) **minsyms)
+ VEC (bound_minimal_symbol_d) **minsyms)
{
struct symbol *sym;
struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
/* Program spaces that are executing startup should have
been filtered out earlier. */
- gdb_assert (!SYMTAB_PSPACE (SYMBOL_SYMTAB (sym))->executing_startup);
- pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
+ pspace = SYMTAB_PSPACE (symbol_symtab (sym));
+ gdb_assert (!pspace->executing_startup);
set_current_program_space (pspace);
t = check_typedef (SYMBOL_TYPE (sym));
find_methods (t, method_name, &result_names, &superclass_vec);
sure not to miss the last batch. */
if (ix == VEC_length (symbolp, sym_classes) - 1
|| (pspace
- != SYMTAB_PSPACE (SYMBOL_SYMTAB (VEC_index (symbolp, sym_classes,
+ != SYMTAB_PSPACE (symbol_symtab (VEC_index (symbolp, sym_classes,
ix + 1)))))
{
/* If we did not find a direct implementation anywhere in
}
if (!VEC_empty (symbolp, info.result.symbols)
- || !VEC_empty (minsym_and_objfile_d, info.result.minimal_symbols))
+ || !VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols))
{
*symbols = info.result.symbols;
*minsyms = info.result.minimal_symbols;
find_function_symbols (struct linespec_state *state,
VEC (symtab_ptr) *file_symtabs, const char *name,
VEC (symbolp) **symbols,
- VEC (minsym_and_objfile_d) **minsyms)
+ VEC (bound_minimal_symbol_d) **minsyms)
{
struct collect_info info;
VEC (const_char_ptr) *symbol_names = NULL;
info.file_symtabs = file_symtabs;
/* Try NAME as an Objective-C selector. */
- find_imps ((char *) name, &symbol_names);
+ find_imps (name, &symbol_names);
if (!VEC_empty (const_char_ptr, symbol_names))
add_all_symbol_names_from_pspace (&info, NULL, symbol_names);
else
else
*symbols = info.result.symbols;
- if (VEC_empty (minsym_and_objfile_d, info.result.minimal_symbols))
+ if (VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols))
{
- VEC_free (minsym_and_objfile_d, info.result.minimal_symbols);
+ VEC_free (bound_minimal_symbol_d, info.result.minimal_symbols);
*minsyms = NULL;
}
else
VEC (symtab_ptr) *file_symtabs,
const char *name,
VEC (symbolp) **symbols,
- VEC (minsym_and_objfile_d) **minsyms)
+ VEC (bound_minimal_symbol_d) **minsyms)
{
struct cleanup *cleanup;
char *canon;
const char *lookup_name;
- volatile struct gdb_exception except;
cleanup = demangle_for_lookup (name, state->language->la_language,
&lookup_name);
the name into class and method names and searching the class and its
baseclasses. */
if (VEC_empty (symbolp, *symbols)
- && VEC_empty (minsym_and_objfile_d, *minsyms))
+ && VEC_empty (bound_minimal_symbol_d, *minsyms))
{
char *klass, *method;
const char *last, *p, *scope_op;
if (!VEC_empty (symbolp, classes))
{
/* Now locate a list of suitable methods named METHOD. */
- TRY_CATCH (except, RETURN_MASK_ERROR)
+ TRY
{
find_method (state, file_symtabs, klass, method, classes,
symbols, minsyms);
/* If successful, we're done. If NOT_FOUND_ERROR
was not thrown, rethrow the exception that we did get. */
- if (except.reason < 0 && except.error != NOT_FOUND_ERROR)
- throw_exception (except);
+ CATCH (except, RETURN_MASK_ERROR)
+ {
+ if (except.error != NOT_FOUND_ERROR)
+ throw_exception (except);
+ }
+ END_CATCH
}
}
VEC (symbolp) **label_funcs_ret, const char *name)
{
int ix;
- struct block *block;
+ const struct block *block;
struct symbol *sym;
struct symbol *fn_sym;
VEC (symbolp) *result = NULL;
for (ix = 0;
VEC_iterate (symbolp, function_symbols, ix, fn_sym); ++ix)
{
- set_current_program_space (SYMTAB_PSPACE (SYMBOL_SYMTAB (fn_sym)));
+ set_current_program_space (SYMTAB_PSPACE (symbol_symtab (fn_sym)));
block = SYMBOL_BLOCK_VALUE (fn_sym);
sym = lookup_symbol (name, block, LABEL_DOMAIN, 0);
}
/* We've found a minimal symbol MSYMBOL in OBJFILE to associate with our
- linespec; return the SAL in RESULT. */
+ linespec; return the SAL in RESULT. This function should return SALs
+ matching those from find_function_start_sal, otherwise false
+ multiple-locations breakpoints could be placed. */
static void
minsym_found (struct linespec_state *self, struct objfile *objfile,
CORE_ADDR pc;
struct symtab_and_line sal;
- sal = find_pc_sect_line (SYMBOL_VALUE_ADDRESS (msymbol),
+ sal = find_pc_sect_line (MSYMBOL_VALUE_ADDRESS (objfile, msymbol),
(struct obj_section *) 0, 0);
- sal.section = SYMBOL_OBJ_SECTION (objfile, msymbol);
+ sal.section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
/* The minimal symbol might point to a function descriptor;
resolve it to the actual code address instead. */
sal = find_pc_sect_line (pc, NULL, 0);
if (self->funfirstline)
- skip_prologue_sal (&sal);
+ {
+ if (sal.symtab != NULL
+ && (COMPUNIT_LOCATIONS_VALID (SYMTAB_COMPUNIT (sal.symtab))
+ || SYMTAB_LANGUAGE (sal.symtab) == language_asm))
+ {
+ /* If gdbarch_convert_from_func_ptr_addr does not apply then
+ sal.SECTION, sal.LINE&co. will stay correct from above.
+ If gdbarch_convert_from_func_ptr_addr applies then
+ sal.SECTION is cleared from above and sal.LINE&co. will
+ stay correct from the last find_pc_sect_line above. */
+ sal.pc = MSYMBOL_VALUE_ADDRESS (objfile, msymbol);
+ sal.pc = gdbarch_convert_from_func_ptr_addr (gdbarch, sal.pc,
+ ¤t_target);
+ }
+ else
+ skip_prologue_sal (&sal);
+ }
if (maybe_add_address (self->addr_set, objfile->pspace, sal.pc))
- add_sal_to_sals (self, result, &sal, SYMBOL_NATURAL_NAME (msymbol), 0);
+ add_sal_to_sals (self, result, &sal, MSYMBOL_NATURAL_NAME (msymbol), 0);
}
/* A helper struct to pass some data through
/* The objfile we're examining. */
struct objfile *objfile;
+ /* Only search the given symtab, or NULL to search for all symbols. */
+ struct symtab *symtab;
+
/* The funfirstline setting from the initial call. */
int funfirstline;
int list_mode;
/* The resulting symbols. */
- VEC (minsym_and_objfile_d) *msyms;
+ VEC (bound_minimal_symbol_d) *msyms;
};
/* A helper function to classify a minimal_symbol_type according to
static int
compare_msyms (const void *a, const void *b)
{
- const minsym_and_objfile_d *moa = a;
- const minsym_and_objfile_d *mob = b;
+ const bound_minimal_symbol_d *moa = a;
+ const bound_minimal_symbol_d *mob = b;
enum minimal_symbol_type ta = MSYMBOL_TYPE (moa->minsym);
enum minimal_symbol_type tb = MSYMBOL_TYPE (mob->minsym);
add_minsym (struct minimal_symbol *minsym, void *d)
{
struct collect_minsyms *info = d;
- minsym_and_objfile_d mo;
+ bound_minimal_symbol_d mo;
+
+ mo.minsym = minsym;
+ mo.objfile = info->objfile;
+
+ if (info->symtab != NULL)
+ {
+ CORE_ADDR pc;
+ struct symtab_and_line sal;
+ struct gdbarch *gdbarch = get_objfile_arch (info->objfile);
+
+ sal = find_pc_sect_line (MSYMBOL_VALUE_ADDRESS (info->objfile, minsym),
+ NULL, 0);
+ sal.section = MSYMBOL_OBJ_SECTION (info->objfile, minsym);
+ pc
+ = gdbarch_convert_from_func_ptr_addr (gdbarch, sal.pc, ¤t_target);
+ if (pc != sal.pc)
+ sal = find_pc_sect_line (pc, NULL, 0);
+
+ if (info->symtab != sal.symtab)
+ return;
+ }
/* Exclude data symbols when looking for breakpoint locations. */
if (!info->list_mode)
before we decide to discard it. */
struct gdbarch *gdbarch = get_objfile_arch (info->objfile);
CORE_ADDR addr = gdbarch_convert_from_func_ptr_addr
- (gdbarch, SYMBOL_VALUE_ADDRESS (minsym),
+ (gdbarch, BMSYMBOL_VALUE_ADDRESS (mo),
¤t_target);
- if (addr == SYMBOL_VALUE_ADDRESS (minsym))
+ if (addr == BMSYMBOL_VALUE_ADDRESS (mo))
return;
}
}
- mo.minsym = minsym;
- mo.objfile = info->objfile;
- VEC_safe_push (minsym_and_objfile_d, info->msyms, &mo);
+ VEC_safe_push (bound_minimal_symbol_d, info->msyms, &mo);
}
-/* Search minimal symbols in all objfiles for NAME. If SEARCH_PSPACE
+/* Search for minimal symbols called NAME. If SEARCH_PSPACE
is not NULL, the search is restricted to just that program
- space. */
+ space.
+
+ If SYMTAB is NULL, search all objfiles, otherwise
+ restrict results to the given SYMTAB. */
static void
search_minsyms_for_name (struct collect_info *info, const char *name,
- struct program_space *search_pspace)
+ struct program_space *search_pspace,
+ struct symtab *symtab)
{
- struct objfile *objfile;
- struct program_space *pspace;
+ struct collect_minsyms local;
+ struct cleanup *cleanup;
- ALL_PSPACES (pspace)
- {
- struct collect_minsyms local;
- struct cleanup *cleanup;
+ memset (&local, 0, sizeof (local));
+ local.funfirstline = info->state->funfirstline;
+ local.list_mode = info->state->list_mode;
+ local.symtab = symtab;
- if (search_pspace != NULL && search_pspace != pspace)
- continue;
- if (pspace->executing_startup)
- continue;
+ cleanup = make_cleanup (VEC_cleanup (bound_minimal_symbol_d), &local.msyms);
- set_current_program_space (pspace);
+ if (symtab == NULL)
+ {
+ struct program_space *pspace;
- memset (&local, 0, sizeof (local));
- local.funfirstline = info->state->funfirstline;
- local.list_mode = info->state->list_mode;
+ ALL_PSPACES (pspace)
+ {
+ struct objfile *objfile;
- cleanup = make_cleanup (VEC_cleanup (minsym_and_objfile_d),
- &local.msyms);
+ if (search_pspace != NULL && search_pspace != pspace)
+ continue;
+ if (pspace->executing_startup)
+ continue;
- ALL_OBJFILES (objfile)
+ set_current_program_space (pspace);
+
+ ALL_OBJFILES (objfile)
+ {
+ local.objfile = objfile;
+ iterate_over_minimal_symbols (objfile, name, add_minsym, &local);
+ }
+ }
+ }
+ else
{
- local.objfile = objfile;
- iterate_over_minimal_symbols (objfile, name, add_minsym, &local);
+ if (search_pspace == NULL || SYMTAB_PSPACE (symtab) == search_pspace)
+ {
+ set_current_program_space (SYMTAB_PSPACE (symtab));
+ local.objfile = SYMTAB_OBJFILE(symtab);
+ iterate_over_minimal_symbols (local.objfile, name, add_minsym,
+ &local);
+ }
}
- if (!VEC_empty (minsym_and_objfile_d, local.msyms))
+ if (!VEC_empty (bound_minimal_symbol_d, local.msyms))
{
int classification;
int ix;
- minsym_and_objfile_d *item;
+ bound_minimal_symbol_d *item;
- qsort (VEC_address (minsym_and_objfile_d, local.msyms),
- VEC_length (minsym_and_objfile_d, local.msyms),
- sizeof (minsym_and_objfile_d),
+ qsort (VEC_address (bound_minimal_symbol_d, local.msyms),
+ VEC_length (bound_minimal_symbol_d, local.msyms),
+ sizeof (bound_minimal_symbol_d),
compare_msyms);
/* Now the minsyms are in classification order. So, we walk
over them and process just the minsyms with the same
classification as the very first minsym in the list. */
- item = VEC_index (minsym_and_objfile_d, local.msyms, 0);
+ item = VEC_index (bound_minimal_symbol_d, local.msyms, 0);
classification = classify_mtype (MSYMBOL_TYPE (item->minsym));
for (ix = 0;
- VEC_iterate (minsym_and_objfile_d, local.msyms, ix, item);
+ VEC_iterate (bound_minimal_symbol_d, local.msyms, ix, item);
++ix)
{
if (classify_mtype (MSYMBOL_TYPE (item->minsym)) != classification)
break;
- VEC_safe_push (minsym_and_objfile_d,
+ VEC_safe_push (bound_minimal_symbol_d,
info->result.minimal_symbols, item);
}
}
do_cleanups (cleanup);
- }
}
/* A helper function to add all symbols matching NAME to INFO. If
iterate_over_all_matching_symtabs (info->state, name, VAR_DOMAIN,
collect_symbols, info,
pspace, 1);
- search_minsyms_for_name (info, name, pspace);
+ search_minsyms_for_name (info, name, pspace, NULL);
}
else if (pspace == NULL || pspace == SYMTAB_PSPACE (elt))
{
+ int prev_len = VEC_length (symbolp, info->result.symbols);
+
/* Program spaces that are executing startup should have
been filtered out earlier. */
gdb_assert (!SYMTAB_PSPACE (elt)->executing_startup);
set_current_program_space (SYMTAB_PSPACE (elt));
iterate_over_file_blocks (elt, name, VAR_DOMAIN,
collect_symbols, info);
+
+ /* If no new symbols were found in this iteration and this symtab
+ is in assembler, we might actually be looking for a label for
+ which we don't have debug info. Check for a minimal symbol in
+ this case. */
+ if (prev_len == VEC_length (symbolp, info->result.symbols)
+ && elt->language == language_asm)
+ search_minsyms_for_name (info, name, pspace, elt);
}
}
}
if (SYMBOL_CLASS (sym) == LOC_LABEL && SYMBOL_VALUE_ADDRESS (sym) != 0)
{
init_sal (result);
- result->symtab = SYMBOL_SYMTAB (sym);
+ result->symtab = symbol_symtab (sym);
result->line = SYMBOL_LINE (sym);
result->pc = SYMBOL_VALUE_ADDRESS (sym);
- result->pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
+ result->pspace = SYMTAB_PSPACE (result->symtab);
result->explicit_pc = 1;
return 1;
}
{
/* We know its line number. */
init_sal (result);
- result->symtab = SYMBOL_SYMTAB (sym);
+ result->symtab = symbol_symtab (sym);
result->line = SYMBOL_LINE (sym);
- result->pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
+ result->pspace = SYMTAB_PSPACE (result->symtab);
return 1;
}
}