public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM] archer-tromey-ambiguous-linespec: make "break file.c:function" work with multiple hits ("break function" still does not) This also fixes http://sourceware.org/bugzilla/show_bug.cgi?id=12856
@ 2011-08-01 20:32 tromey
0 siblings, 0 replies; only message in thread
From: tromey @ 2011-08-01 20:32 UTC (permalink / raw)
To: archer-commits
The branch, archer-tromey-ambiguous-linespec has been updated
via 22f6851aae5dff720e202b0c91344e75114a3ead (commit)
from f3ae1cef514b61e36a377157017115a7f292e6dd (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit 22f6851aae5dff720e202b0c91344e75114a3ead
Author: Tom Tromey <tromey@redhat.com>
Date: Mon Aug 1 14:16:54 2011 -0600
make "break file.c:function" work with multiple hits
("break function" still does not)
This also fixes http://sourceware.org/bugzilla/show_bug.cgi?id=12856
-----------------------------------------------------------------------
Summary of changes:
gdb/linespec.c | 105 +++++++++++++++++++++++++++++++++++++++++---------------
gdb/symtab.c | 86 +++++++++++++++++++++++++++++++++-------------
gdb/symtab.h | 8 ++++
3 files changed, 147 insertions(+), 52 deletions(-)
First 500 lines of diff:
diff --git a/gdb/linespec.c b/gdb/linespec.c
index fec965a..68634e7 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -107,7 +107,8 @@ static struct symtabs_and_lines decode_line_2 (struct symbol *[],
struct linespec_result *);
static VEC (symtab_p) *symtab_from_filename (char **argptr,
- char *p, int is_quote_enclosed);
+ char *p, int is_quote_enclosed,
+ char **user_filename);
static struct symbol *find_function_symbol (char **argptr, char *p,
int is_quote_enclosed);
@@ -131,7 +132,8 @@ static int decode_label (struct symbol *function_symbol,
static struct symtabs_and_lines decode_variable (char *copy,
int funfirstline,
struct linespec_result *canonical,
- VEC (symtab_p) *file_symtabs);
+ VEC (symtab_p) *file_symtabs,
+ const char *);
static int symbol_to_sal (struct symtab_and_line *result,
int funfirstline, char *copy,
@@ -860,6 +862,9 @@ decode_line_internal (char **argptr, int funfirstline,
/* The "first half" of the linespec. */
char *first_half;
+ /* For "file:line", the "file" part. */
+ char *user_filename = NULL;
+
/* If we are parsing `function:label', this holds the symbol for the
function. */
struct symbol *function_symbol = NULL;
@@ -904,7 +909,8 @@ decode_line_internal (char **argptr, int funfirstline,
symtab and strip the filename from ARGPTR. */
TRY_CATCH (file_exception, RETURN_MASK_ERROR)
{
- file_symtabs = symtab_from_filename (argptr, p, is_quote_enclosed);
+ file_symtabs = symtab_from_filename (argptr, p, is_quote_enclosed,
+ &user_filename);
}
global_default_symtab = default_symtab;
@@ -917,6 +923,10 @@ decode_line_internal (char **argptr, int funfirstline,
if (file_exception.reason >= 0)
{
+ gdb_assert (user_filename != NULL);
+
+ make_cleanup (xfree, user_filename);
+
/* Check for single quotes on the non-filename part. */
is_quoted = (**argptr
&& strchr (get_gdb_completer_quote_characters (),
@@ -1104,7 +1114,8 @@ decode_line_internal (char **argptr, int funfirstline,
/* Look up that token as a variable.
If file specified, use that file's per-file block to start with. */
- return decode_variable (copy, funfirstline, canonical, file_symtabs);
+ return decode_variable (copy, funfirstline, canonical, file_symtabs,
+ user_filename);
}
struct symtabs_and_lines
@@ -1924,19 +1935,21 @@ cleanup_htab (void *arg)
of *ARGPTR ending at P, and advance ARGPTR past that filename. */
static VEC (symtab_p) *
-symtab_from_filename (char **argptr, char *p, int is_quote_enclosed)
+symtab_from_filename (char **argptr, char *p, int is_quote_enclosed,
+ char **user_filename)
{
char *p1;
char *copy;
struct symtab_collector collector;
- struct cleanup *cleanups;
+ struct cleanup *cleanups, *outer;
p1 = p;
while (p != *argptr && p[-1] == ' ')
--p;
if ((*p == '"') && is_quote_enclosed)
--p;
- copy = (char *) alloca (p - *argptr + 1);
+ copy = xmalloc (p - *argptr + 1);
+ outer = make_cleanup (xfree, copy);
memcpy (copy, *argptr, p - *argptr);
/* It may have the ending quote right after the file name. */
if ((is_quote_enclosed && copy[p - *argptr - 1] == '"')
@@ -1967,6 +1980,8 @@ symtab_from_filename (char **argptr, char *p, int is_quote_enclosed)
*argptr = p;
do_cleanups (cleanups);
+ discard_cleanups (outer);
+ *user_filename = copy;
return collector.symtabs;
}
@@ -2038,7 +2053,8 @@ decode_all_digits (char **argptr,
values.sals = NULL;
values.nelts = 0;
- canonical->pre_expanded = 1;
+ if (canonical)
+ canonical->pre_expanded = 1;
/* This is where we need to make sure that we have good defaults.
We must guarantee that this section of code is never executed
@@ -2246,21 +2262,48 @@ decode_label (struct symbol *function_symbol, char *copy,
return sym != NULL;
}
+struct collect_info
+{
+ char *initial_name;
+ struct symtabs_and_lines result;
+ int funfirstline;
+};
+
+static int
+collect_symbols (struct symbol *sym, void *data)
+{
+ struct collect_info *info = data;
+ struct symtab_and_line sal;
+
+ if (symbol_to_sal (&sal, info->funfirstline, info->initial_name, sym, 0))
+ add_sal_to_sals (&info->result, sal);
+
+ return 1;
+}
+
/* Decode a linespec that's a variable. If FILE_SYMTAB is non-NULL,
look in that symtab's static variables first. */
static struct symtabs_and_lines
decode_variable (char *copy, int funfirstline,
struct linespec_result *canonical,
- VEC (symtab_p) *file_symtabs)
+ VEC (symtab_p) *file_symtabs,
+ const char *user_filename)
{
int ix;
struct symtab *elt;
- struct symtabs_and_lines result;
+ struct collect_info info;
struct minimal_symbol *msymbol;
+ const char *lookup_name;
+ struct cleanup *cleanup;
- result.sals = NULL;
- result.nelts = 0;
+ info.result.sals = NULL;
+ info.result.nelts = 0;
+ info.initial_name = copy;
+ info.funfirstline = funfirstline;
+
+ cleanup = demangle_for_lookup (copy, current_language->la_language,
+ &lookup_name);
for (ix = 0; VEC_iterate (symtab_p, file_symtabs, ix, elt); ++ix)
{
@@ -2268,33 +2311,39 @@ decode_variable (char *copy, int funfirstline,
elt = maybe_use_global_symtab (elt);
- sym = lookup_symbol (copy, get_search_block (elt), VAR_DOMAIN, 0);
- if (sym != NULL)
- {
- struct symtab_and_line sal;
-
- if (symbol_to_sal (&sal, funfirstline, copy, sym, 0))
- add_sal_to_sals (&result, sal);
- }
+ iterate_over_symbols (get_search_block (elt), lookup_name,
+ VAR_DOMAIN, collect_symbols,
+ &info);
}
- if (result.nelts > 0)
+ if (info.result.nelts > 0)
{
- build_canonical_line_spec (&result, copy, canonical);
- return result;
+ if (canonical)
+ canonical->pre_expanded = 1;
+ build_canonical_line_spec (&info.result, copy, canonical);
+ return info.result;
}
- /* Try one last thing. FIXME. */
- msymbol = lookup_minimal_symbol (copy, NULL, NULL);
- if (msymbol != NULL)
- return minsym_found (funfirstline, msymbol);
+ /* Try one last thing, but only if no "file" part was given. */
+ /* FIXME should do better at iterating in general. */
+ if (VEC_length (symtab_p, file_symtabs) == 1
+ && VEC_index (symtab_p, file_symtabs, 0) == NULL)
+ {
+ msymbol = lookup_minimal_symbol (copy, NULL, NULL);
+ if (msymbol != NULL)
+ return minsym_found (funfirstline, msymbol);
+ }
if (!have_full_symbols ()
&& !have_partial_symbols ()
&& !have_minimal_symbols ())
throw_error (NOT_FOUND_ERROR,
_("No symbol table is loaded. Use the \"file\" command."));
- throw_error (NOT_FOUND_ERROR, _("Function \"%s\" not defined."), copy);
+ if (user_filename)
+ throw_error (NOT_FOUND_ERROR, _("Function \"%s\" not defined in \"%s\"."),
+ copy, user_filename);
+ else
+ throw_error (NOT_FOUND_ERROR, _("Function \"%s\" not defined."), copy);
}
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 229a1d8..f4ffe38 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1039,33 +1039,12 @@ fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
return sym;
}
-/* Find the definition for a specified symbol name NAME
- in domain DOMAIN, visible from lexical block BLOCK.
- Returns the struct symbol pointer, or zero if no symbol is found.
- C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
- NAME is a field of the current implied argument `this'. If so set
- *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
- BLOCK_FOUND is set to the block in which NAME is found (in the case of
- a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
-
-/* This function has a bunch of loops in it and it would seem to be
- attractive to put in some QUIT's (though I'm not really sure
- whether it can run long enough to be really important). But there
- are a few calls for which it would appear to be bad news to quit
- out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c. (Note
- that there is C++ code below which can error(), but that probably
- doesn't affect these calls since they are looking for a known
- variable and thus can probably assume it will never hit the C++
- code). */
-
-struct symbol *
-lookup_symbol_in_language (const char *name, const struct block *block,
- const domain_enum domain, enum language lang,
- int *is_a_field_of_this)
+struct cleanup *
+demangle_for_lookup (const char *name, enum language lang,
+ const char **result_name)
{
char *demangled_name = NULL;
const char *modified_name = NULL;
- struct symbol *returnval;
struct cleanup *cleanup = make_cleanup (null_cleanup, 0);
modified_name = name;
@@ -1112,6 +1091,38 @@ lookup_symbol_in_language (const char *name, const struct block *block,
}
}
+ *result_name = modified_name;
+ return cleanup;
+}
+
+/* Find the definition for a specified symbol name NAME
+ in domain DOMAIN, visible from lexical block BLOCK.
+ Returns the struct symbol pointer, or zero if no symbol is found.
+ C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
+ NAME is a field of the current implied argument `this'. If so set
+ *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
+ BLOCK_FOUND is set to the block in which NAME is found (in the case of
+ a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
+
+/* This function has a bunch of loops in it and it would seem to be
+ attractive to put in some QUIT's (though I'm not really sure
+ whether it can run long enough to be really important). But there
+ are a few calls for which it would appear to be bad news to quit
+ out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c. (Note
+ that there is C++ code below which can error(), but that probably
+ doesn't affect these calls since they are looking for a known
+ variable and thus can probably assume it will never hit the C++
+ code). */
+
+struct symbol *
+lookup_symbol_in_language (const char *name, const struct block *block,
+ const domain_enum domain, enum language lang,
+ int *is_a_field_of_this)
+{
+ const char *modified_name;
+ struct symbol *returnval;
+ struct cleanup *cleanup = demangle_for_lookup (name, lang, &modified_name);
+
returnval = lookup_symbol_aux (modified_name, block, domain, lang,
is_a_field_of_this);
do_cleanups (cleanup);
@@ -1804,6 +1815,33 @@ lookup_block_symbol (const struct block *block, const char *name,
}
}
+void
+iterate_over_symbols (const struct block *block, const char *name,
+ const domain_enum domain,
+ int (*callback) (struct symbol *, void *),
+ void *data)
+{
+ while (block)
+ {
+ struct dict_iterator iter;
+ struct symbol *sym;
+
+ for (sym = dict_iter_name_first (BLOCK_DICT (block), name, &iter);
+ sym != NULL;
+ sym = dict_iter_name_next (name, &iter))
+ {
+ if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
+ SYMBOL_DOMAIN (sym), domain))
+ {
+ if (!callback (sym, data))
+ return;
+ }
+ }
+
+ block = BLOCK_SUPERBLOCK (block);
+ }
+}
+
/* Find the symtab associated with PC and SECTION. Look through the
psymtabs and read in another symtab if necessary. */
diff --git a/gdb/symtab.h b/gdb/symtab.h
index cdb2046..e1d374d 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1318,4 +1318,12 @@ DEF_VEC_I (CORE_ADDR);
VEC (CORE_ADDR) *find_pcs_for_symtab_line (struct symtab *symtab, int line);
+void iterate_over_symbols (const struct block *block, const char *name,
+ const domain_enum domain,
+ int (*callback) (struct symbol *, void *),
+ void *data);
+
+struct cleanup *demangle_for_lookup (const char *name, enum language lang,
+ const char **result_name);
+
#endif /* !defined(SYMTAB_H) */
hooks/post-receive
--
Repository for Project Archer.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-08-01 20:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-01 20:32 [SCM] archer-tromey-ambiguous-linespec: make "break file.c:function" work with multiple hits ("break function" still does not) This also fixes http://sourceware.org/bugzilla/show_bug.cgi?id=12856 tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).