aboutsummaryrefslogtreecommitdiff
path: root/gdb/linespec.c
diff options
context:
space:
mode:
authorMihail-Marian Nistor <mihail.nistor@freescale.com>2014-12-20 11:04:44 -0500
committerJoel Brobecker <brobecker@adacore.com>2014-12-20 11:32:25 -0500
commit87186c6a5ccf857d7f4e55478dda3aa06387c3c4 (patch)
treea85e9b9aca0ef2e2645846deeaf4395dd49cc4c6 /gdb/linespec.c
parentbd040da1dbb7e6640440f306ddf993af98441851 (diff)
downloadgdb-87186c6a5ccf857d7f4e55478dda3aa06387c3c4.zip
gdb-87186c6a5ccf857d7f4e55478dda3aa06387c3c4.tar.gz
gdb-87186c6a5ccf857d7f4e55478dda3aa06387c3c4.tar.bz2
gdb/17394: cannot put breakpoint only in selected ASM file.
This patch fixes a problem when trying to insert a breakpoint on a specific symbol defined in a specific file, eg: break foo.c:func This currently works for files in C/C++/Ada, etc, but doesn't always work for Asm files. Analysis of the problem showed that this related to a limitation in gas, which does not generate debug info for functions/ symbols. Thus, we have a symtab for the file ("info sources" shows the file), but it contains no symbols. When find_linespec_symbols is called in linespec_parse_basic, it calls find_function_symbols, which uses add_matching_symbols_to_info to collect all matching symbols. That function does [pardon any mangled formatting]: for (ix = 0; VEC_iterate (symtab_ptr, info->file_symtabs, ix, elt); ++ix) { if (elt == NULL) { iterate_over_all_matching_symtabs (info->state, name, VAR_DOMAIN, collect_symbols, info, pspace, 1); search_minsyms_for_name (info, name, pspace); } else if (pspace == NULL || pspace == SYMTAB_PSPACE (elt)) { /* 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); } } This iterates over the symtabs. In the failing use case, ELT is non-NULL (points to the symtab for the .s file), so it calls iterate_over_file_blocks. Herein is where the problem exists: it is assumed that if NAME exists, it must exist in the given symtab -- a reasonable assumption for "normal" (non-asm) cases. It never searches minimal symbols (or in the global default symtab). This patch fixes the problem by doing so. It is important to note that iterating over minsyms is fairly expensive, so this patch only adds that extra search if the language is language_asm and iterate_over_file_blocks returns no symbols. gdb/ChangeLog: 2014-12-20 Keith Seitz <keiths@redhat.com> Mihail-Marian Nistor <mihail.nistor@freescale.com> PR gdb/17394 * linespec.c (struct collect_minsyms): Add new member `symtab'. (add_minsym): Handle cases where info.symtab is non-NULL. (search_minsyms_for_name): Add new parameter `symtab'. Handle limiting searches to a specific symtab. (add_matching_symtabs_to_info): Search through minimal symbols for language_asm files for which no new symbols are found. gdb/testsuite/ChangeLog: 2014-12-20 Mihail-Marian Nistor <mihail.nistor@freescale.com> PR gdb/17394 * gdb.linespec/break-asm-file.c: New file. * gdb.linespec/break-asm-file.exp: New file. * gdb.linespec/break-asm-file0.s: New file. * gdb.linespec/break-asm-file1.s: New file.
Diffstat (limited to 'gdb/linespec.c')
-rw-r--r--gdb/linespec.c97
1 files changed, 73 insertions, 24 deletions
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 82384ca..ef4173c 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3448,6 +3448,9 @@ struct collect_minsyms
/* 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;
@@ -3507,6 +3510,24 @@ add_minsym (struct minimal_symbol *minsym, void *d)
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, &current_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)
switch (minsym->type)
@@ -3533,40 +3554,59 @@ add_minsym (struct minimal_symbol *minsym, void *d)
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 (bound_minimal_symbol_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 (bound_minimal_symbol_d, local.msyms))
@@ -3599,7 +3639,6 @@ search_minsyms_for_name (struct collect_info *info, const char *name,
}
do_cleanups (cleanup);
- }
}
/* A helper function to add all symbols matching NAME to INFO. If
@@ -3621,16 +3660,26 @@ add_matching_symbols_to_info (const char *name,
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);
}
}
}