* [RFA/commit 1/3] Revert "Search global symbols from the expression's block objfile first."
2012-05-31 20:37 [RFA 0/3] Make global symbol objfile search order arch-dependent Joel Brobecker
@ 2012-05-31 20:37 ` Joel Brobecker
2012-05-31 20:37 ` [RFA 3/3] Windows-specific iterate_over_objfiles_in_search_order Joel Brobecker
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: Joel Brobecker @ 2012-05-31 20:37 UTC (permalink / raw)
To: gdb-patches; +Cc: Joel Brobecker
The search order used in this patch breaks global symbol lookups
for certain symbols when copy-relocation is used. A slightly different
search order will be implemented later.
gdb/ChangeLog:
Revert the following patch:
* findvar.c (default_read_var_value): For LOC_UNRESOLVED symbols,
try locating the symbol in the symbol's own objfile first, before
extending the search to all objfiles.
* symtab.c (lookup_symbol_aux_objfile): New function, extracted
out of lookup_symbol_aux_symtabs.
(lookup_symbol_aux_symtabs): Add new parameter "exclude_objfile".
Replace extracted-out code by call to lookup_symbol_aux_objfile.
Do not search EXCLUDE_OBJFILE.
(lookup_static_symbol_aux): Update call to lookup_symbol_aux_symtabs.
(lookup_symbol_global): Search for matches in the block's objfile
first, before searching all other objfiles.
Will commit if patches #2 & #3 are OK.
---
gdb/findvar.c | 10 +-----
gdb/symtab.c | 108 +++++++++++++++++----------------------------------------
2 files changed, 33 insertions(+), 85 deletions(-)
diff --git a/gdb/findvar.c b/gdb/findvar.c
index ed7903c..9009e6f 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -562,15 +562,7 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
struct minimal_symbol *msym;
struct obj_section *obj_section;
- /* First, try locating the associated minimal symbol within
- the same objfile. This prevents us from selecting another
- symbol with the same name but located in a different objfile. */
- msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (var), NULL,
- SYMBOL_SYMTAB (var)->objfile);
- /* If the lookup failed, try expanding the search to all
- objfiles. */
- if (msym == NULL)
- msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (var), NULL, NULL);
+ msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (var), NULL, NULL);
if (msym == NULL)
error (_("No global symbol \"%s\"."), SYMBOL_LINKAGE_NAME (var));
if (overlay_debugging)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 85ddd1d..39d8c6f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -95,8 +95,7 @@ struct symbol *lookup_symbol_aux_local (const char *name,
static
struct symbol *lookup_symbol_aux_symtabs (int block_index,
const char *name,
- const domain_enum domain,
- struct objfile *exclude_objfile);
+ const domain_enum domain);
static
struct symbol *lookup_symbol_aux_quick (struct objfile *objfile,
@@ -1360,7 +1359,7 @@ lookup_static_symbol_aux (const char *name, const domain_enum domain)
struct objfile *objfile;
struct symbol *sym;
- sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, domain, NULL);
+ sym = lookup_symbol_aux_symtabs (STATIC_BLOCK, name, domain);
if (sym != NULL)
return sym;
@@ -1499,61 +1498,40 @@ lookup_global_symbol_from_objfile (const struct objfile *main_objfile,
return NULL;
}
-/* Check to see if the symbol is defined in one of the OBJFILE's
- symtabs. BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
+/* Check to see if the symbol is defined in one of the symtabs.
+ BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
depending on whether or not we want to search global symbols or
static symbols. */
static struct symbol *
-lookup_symbol_aux_objfile (struct objfile *objfile, int block_index,
- const char *name, const domain_enum domain)
-{
- struct symbol *sym = NULL;
- struct blockvector *bv;
- const struct block *block;
- struct symtab *s;
-
- if (objfile->sf)
- objfile->sf->qf->pre_expand_symtabs_matching (objfile, block_index,
- name, domain);
-
- ALL_OBJFILE_SYMTABS (objfile, s)
- if (s->primary)
- {
- bv = BLOCKVECTOR (s);
- block = BLOCKVECTOR_BLOCK (bv, block_index);
- sym = lookup_block_symbol (block, name, domain);
- if (sym)
- {
- block_found = block;
- return fixup_symbol_section (sym, objfile);
- }
- }
-
- return NULL;
-}
-
-/* Same as lookup_symbol_aux_objfile, except that it searches all
- objfiles except for EXCLUDE_OBJFILE. Return the first match found.
-
- If EXCLUDE_OBJFILE is NULL, then all objfiles are searched. */
-
-static struct symbol *
lookup_symbol_aux_symtabs (int block_index, const char *name,
- const domain_enum domain,
- struct objfile *exclude_objfile)
+ const domain_enum domain)
{
struct symbol *sym;
struct objfile *objfile;
+ struct blockvector *bv;
+ const struct block *block;
+ struct symtab *s;
ALL_OBJFILES (objfile)
{
- if (objfile != exclude_objfile)
- {
- sym = lookup_symbol_aux_objfile (objfile, block_index, name, domain);
- if (sym)
- return sym;
- }
+ if (objfile->sf)
+ objfile->sf->qf->pre_expand_symtabs_matching (objfile,
+ block_index,
+ name, domain);
+
+ ALL_OBJFILE_SYMTABS (objfile, s)
+ if (s->primary)
+ {
+ bv = BLOCKVECTOR (s);
+ block = BLOCKVECTOR_BLOCK (bv, block_index);
+ sym = lookup_block_symbol (block, name, domain);
+ if (sym)
+ {
+ block_found = block;
+ return fixup_symbol_section (sym, objfile);
+ }
+ }
}
return NULL;
@@ -1679,46 +1657,24 @@ lookup_symbol_global (const char *name,
const domain_enum domain)
{
struct symbol *sym = NULL;
- struct objfile *block_objfile = NULL;
struct objfile *objfile = NULL;
/* Call library-specific lookup procedure. */
- block_objfile = lookup_objfile_from_block (block);
- if (block_objfile != NULL)
- sym = solib_global_lookup (block_objfile, name, domain);
+ objfile = lookup_objfile_from_block (block);
+ if (objfile != NULL)
+ sym = solib_global_lookup (objfile, name, domain);
if (sym != NULL)
return sym;
- /* If BLOCK_OBJFILE is not NULL, then search this objfile first.
- In case the global symbol is defined in multiple objfiles,
- we have a better chance of finding the most relevant symbol. */
-
- if (block_objfile != NULL)
- {
- sym = lookup_symbol_aux_objfile (block_objfile, GLOBAL_BLOCK,
- name, domain);
- if (sym == NULL)
- sym = lookup_symbol_aux_quick (block_objfile, GLOBAL_BLOCK,
- name, domain);
- if (sym != NULL)
- return sym;
- }
-
- /* Symbol not found in the BLOCK_OBJFILE, so try all the other
- objfiles, starting with symtabs first, and then partial symtabs. */
-
- sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, domain, block_objfile);
+ sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, domain);
if (sym != NULL)
return sym;
ALL_OBJFILES (objfile)
{
- if (objfile != block_objfile)
- {
- sym = lookup_symbol_aux_quick (objfile, GLOBAL_BLOCK, name, domain);
- if (sym)
- return sym;
- }
+ sym = lookup_symbol_aux_quick (objfile, GLOBAL_BLOCK, name, domain);
+ if (sym)
+ return sym;
}
return NULL;
--
1.7.1
^ permalink raw reply [flat|nested] 10+ messages in thread* [RFA 3/3] Windows-specific iterate_over_objfiles_in_search_order
2012-05-31 20:37 [RFA 0/3] Make global symbol objfile search order arch-dependent Joel Brobecker
2012-05-31 20:37 ` [RFA/commit 1/3] Revert "Search global symbols from the expression's block objfile first." Joel Brobecker
@ 2012-05-31 20:37 ` Joel Brobecker
2012-06-02 13:57 ` Jan Kratochvil
2012-06-04 4:55 ` Doug Evans
2012-05-31 20:37 ` [RFA 2/3] New "iterate_over_objfiles_in_search_order" gdbarch method Joel Brobecker
2012-06-01 18:06 ` [RFA 0/3] Make global symbol objfile search order arch-dependent Pedro Alves
3 siblings, 2 replies; 10+ messages in thread
From: Joel Brobecker @ 2012-05-31 20:37 UTC (permalink / raw)
To: gdb-patches; +Cc: Joel Brobecker
This patch sets the windows target to use their own version of
the iterate_over_objfiles_in_search_order gdbarch method, in
order to make global symbol searches sensitive to the current
objfile.
gdb/ChangeLog:
* windows-tdep.h (windows_iterate_over_objfiles_in_search_order):
Add declaration.
* windows-tdep.c: #include "objfiles.h".
(windows_iterate_over_objfiles_in_search_order): New function.
* amd64-windows-tdep.c (amd64_windows_init_abi): Set
iterate_over_objfiles_in_search_order gdbarch method to
windows_iterate_over_objfiles_in_search_order.
* i386-cygwin-tdep.c (i386_cygwin_init_abi): Likewise.
I'll commit after patch #2 is approved, unless there are objections...
Thanks,
--
Joel
---
gdb/amd64-windows-tdep.c | 3 +++
gdb/i386-cygwin-tdep.c | 3 +++
gdb/windows-tdep.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
gdb/windows-tdep.h | 5 +++++
4 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
index 4a40f47..f375409 100644
--- a/gdb/amd64-windows-tdep.c
+++ b/gdb/amd64-windows-tdep.c
@@ -174,6 +174,9 @@ amd64_windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
set_gdbarch_return_value (gdbarch, amd64_windows_return_value);
set_gdbarch_skip_main_prologue (gdbarch, amd64_skip_main_prologue);
+ set_gdbarch_iterate_over_objfiles_in_search_order
+ (gdbarch, windows_iterate_over_objfiles_in_search_order);
+
set_solib_ops (gdbarch, &solib_target_so_ops);
}
diff --git a/gdb/i386-cygwin-tdep.c b/gdb/i386-cygwin-tdep.c
index fb940f8..bb395e7 100644
--- a/gdb/i386-cygwin-tdep.c
+++ b/gdb/i386-cygwin-tdep.c
@@ -257,6 +257,9 @@ i386_cygwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
/* Canonical paths on this target look like
`c:\Program Files\Foo App\mydll.dll', for example. */
set_gdbarch_has_dos_based_file_system (gdbarch, 1);
+
+ set_gdbarch_iterate_over_objfiles_in_search_order
+ (gdbarch, windows_iterate_over_objfiles_in_search_order);
}
static enum gdb_osabi
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index a704599..8c02294 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -26,6 +26,7 @@
#include "command.h"
#include "gdbcmd.h"
#include "gdbthread.h"
+#include "objfiles.h"
struct cmd_list_element *info_w32_cmdlist;
@@ -398,6 +399,51 @@ windows_xfer_shared_library (const char* so_name, CORE_ADDR load_addr,
obstack_grow_str (obstack, "\"/></library>");
}
+/* Implement the "iterate_over_objfiles_in_search_order" gdbarch
+ method. It searches all objfiles, starting with CURRENT_OBJFILE
+ first (if not NULL).
+
+ On Windows, the system behaves a little differently when two
+ objfiles each define a global symbol using the same name, compared
+ to other platforms such as GNU/Linux for instance. On GNU/Linux,
+ all instances of the symbol effectively get merged into a single
+ one, but on Windows, they remain distinct.
+
+ As a result, it usually makes sense to start global symbol searches
+ with the current objfile before expanding it to all other objfiles.
+ This helps for instance when a user debugs some code in a DLL that
+ refers to a global variable defined inside that DLL. When trying
+ to print the value of that global variable, it would be unhelpful
+ to print the value of another global variable defined with the same
+ name, but in a different DLL. */
+
+void
+windows_iterate_over_objfiles_in_search_order
+ (struct gdbarch *gdbarch,
+ int (*cb) (struct objfile *objfile, void *cb_data),
+ void *cb_data, struct objfile *current_objfile)
+{
+ int stop;
+ struct objfile *objfile;
+
+ if (current_objfile)
+ {
+ stop = cb (current_objfile, cb_data);
+ if (stop)
+ return;
+ }
+
+ ALL_OBJFILES (objfile)
+ {
+ if (objfile != current_objfile)
+ {
+ stop = cb (objfile, cb_data);
+ if (stop)
+ return;
+ }
+ }
+}
+
static void
show_maint_show_all_tib (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
diff --git a/gdb/windows-tdep.h b/gdb/windows-tdep.h
index c790e0a..81c460f 100644
--- a/gdb/windows-tdep.h
+++ b/gdb/windows-tdep.h
@@ -29,4 +29,9 @@ extern void windows_xfer_shared_library (const char* so_name,
CORE_ADDR load_addr,
struct gdbarch *gdbarch,
struct obstack *obstack);
+
+extern void windows_iterate_over_objfiles_in_search_order
+ (struct gdbarch *gdbarch,
+ int (*cb) (struct objfile *objfile, void *cb_data),
+ void *cb_data, struct objfile *current_objfile);
#endif
--
1.7.1
^ permalink raw reply [flat|nested] 10+ messages in thread* [RFA 2/3] New "iterate_over_objfiles_in_search_order" gdbarch method.
2012-05-31 20:37 [RFA 0/3] Make global symbol objfile search order arch-dependent Joel Brobecker
2012-05-31 20:37 ` [RFA/commit 1/3] Revert "Search global symbols from the expression's block objfile first." Joel Brobecker
2012-05-31 20:37 ` [RFA 3/3] Windows-specific iterate_over_objfiles_in_search_order Joel Brobecker
@ 2012-05-31 20:37 ` Joel Brobecker
2012-06-01 18:06 ` [RFA 0/3] Make global symbol objfile search order arch-dependent Pedro Alves
3 siblings, 0 replies; 10+ messages in thread
From: Joel Brobecker @ 2012-05-31 20:37 UTC (permalink / raw)
To: gdb-patches; +Cc: Joel Brobecker
This patch introduces the "iterate_over_objfiles_in_search_order"
gdbarch method, as well as its default implementation, and converts
the areas where it will matter to using this gdbarch method.
The default method implementation is the only one installed, and
the changes should have no functional impact in terms of behavior.
This only paves the way for the architectures that will need their
own version.
gdb/ChangeLog:
* gdbarch.sh: Add include of "objfiles.h" in gdbarch.c.
(iterate_over_objfiles_in_search_order): New gdbarch method.
* gdbarch.h, gdbarch.c: Regenerate.
* objfiles.h (default_iterate_over_objfiles_in_search_order):
Add declaration.
* objfiles.c (default_iterate_over_objfiles_in_search_order):
New function.
* symtab.c (lookup_symbol_aux_objfile): New function, extracted
out of lookup_symbol_aux_symtabs.
(lookup_symbol_aux_symtabs): Replace extracted-out code by
call to lookup_symbol_aux_objfile.
(struct global_sym_lookup_data): New type.
(lookup_symbol_global_iterator_cb): New function.
(lookup_symbol_global): Search for symbol using
gdbarch_iterate_over_objfiles_in_search_order and
lookup_symbol_global_iterator_cb.
* findvar.c (struct minsym_lookup_data): New type.
(minsym_lookup_iterator_cb): New function.
(default_read_var_value) [case LOC_UNRESOLVED]: Resolve the
symbol's address via gdbarch_iterate_over_objfiles_in_search_order
and minsym_lookup_iterator_cb.
OK to commit?
Thanks,
--
Joel
---
gdb/findvar.c | 42 +++++++++++++++++++-
gdb/gdbarch.c | 25 ++++++++++++
gdb/gdbarch.h | 18 ++++++++
gdb/gdbarch.sh | 16 ++++++++
gdb/objfiles.c | 25 ++++++++++++
gdb/objfiles.h | 5 ++
gdb/symtab.c | 118 ++++++++++++++++++++++++++++++++++++++++----------------
7 files changed, 215 insertions(+), 34 deletions(-)
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 9009e6f..66bcebe 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -406,6 +406,37 @@ symbol_read_needs_frame (struct symbol *sym)
return 1;
}
+/* Private data to be used with minsym_lookup_iterator_cb. */
+
+struct minsym_lookup_data
+{
+ /* The name of the minimal symbol we are searching for. */
+ const char *name;
+
+ /* The field where the callback should store the minimal symbol
+ if found. It should be initialized to NULL before the search
+ is started. */
+ struct minimal_symbol *result;
+};
+
+/* A callback function for gdbarch_iterate_over_objfiles_in_search_order.
+ It searches by name for a minimal symbol within the given OBJFILE.
+ The arguments are passed via CB_DATA, which in reality is a pointer
+ to struct minsym_lookup_data. */
+
+static int
+minsym_lookup_iterator_cb (struct objfile *objfile, void *cb_data)
+{
+ struct minsym_lookup_data *data = (struct minsym_lookup_data *) cb_data;
+
+ gdb_assert (data->result == NULL);
+
+ data->result = lookup_minimal_symbol (data->name, NULL, objfile);
+
+ /* The iterator should stop iff a match was found. */
+ return (data->result != NULL);
+}
+
/* A default implementation for the "la_read_var_value" hook in
the language vector which should work in most situations. */
@@ -559,10 +590,19 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
case LOC_UNRESOLVED:
{
+ struct minsym_lookup_data lookup_data;
struct minimal_symbol *msym;
struct obj_section *obj_section;
- msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (var), NULL, NULL);
+ memset (&lookup_data, 0, sizeof (lookup_data));
+ lookup_data.name = SYMBOL_LINKAGE_NAME (var);
+
+ gdbarch_iterate_over_objfiles_in_search_order
+ (get_objfile_arch (SYMBOL_SYMTAB (var)->objfile),
+ minsym_lookup_iterator_cb, &lookup_data,
+ SYMBOL_SYMTAB (var)->objfile);
+ msym = lookup_data.result;
+
if (msym == NULL)
error (_("No global symbol \"%s\"."), SYMBOL_LINKAGE_NAME (var));
if (overlay_debugging)
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 3ebe835..5d360af 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -49,6 +49,7 @@
#include "gdb_obstack.h"
#include "observer.h"
#include "regcache.h"
+#include "objfiles.h"
/* Static function declarations */
@@ -284,6 +285,7 @@ struct gdbarch
int has_dos_based_file_system;
gdbarch_gen_return_address_ftype *gen_return_address;
gdbarch_info_proc_ftype *info_proc;
+ gdbarch_iterate_over_objfiles_in_search_order_ftype *iterate_over_objfiles_in_search_order;
};
@@ -451,6 +453,7 @@ struct gdbarch startup_gdbarch =
0, /* has_dos_based_file_system */
default_gen_return_address, /* gen_return_address */
0, /* info_proc */
+ default_iterate_over_objfiles_in_search_order, /* iterate_over_objfiles_in_search_order */
/* startup_gdbarch() */
};
@@ -542,6 +545,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
gdbarch->auto_charset = default_auto_charset;
gdbarch->auto_wide_charset = default_auto_wide_charset;
gdbarch->gen_return_address = default_gen_return_address;
+ gdbarch->iterate_over_objfiles_in_search_order = default_iterate_over_objfiles_in_search_order;
/* gdbarch_alloc() */
return gdbarch;
@@ -750,6 +754,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of has_dos_based_file_system, invalid_p == 0 */
/* Skip verify of gen_return_address, invalid_p == 0 */
/* Skip verify of info_proc, has predicate. */
+ /* Skip verify of iterate_over_objfiles_in_search_order, invalid_p == 0 */
buf = ui_file_xstrdup (log, &length);
make_cleanup (xfree, buf);
if (length > 0)
@@ -1065,6 +1070,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
"gdbarch_dump: integer_to_address = <%s>\n",
host_address_to_string (gdbarch->integer_to_address));
fprintf_unfiltered (file,
+ "gdbarch_dump: iterate_over_objfiles_in_search_order = <%s>\n",
+ host_address_to_string (gdbarch->iterate_over_objfiles_in_search_order));
+ fprintf_unfiltered (file,
"gdbarch_dump: long_bit = %s\n",
plongest (gdbarch->long_bit));
fprintf_unfiltered (file,
@@ -4236,6 +4244,23 @@ set_gdbarch_info_proc (struct gdbarch *gdbarch,
gdbarch->info_proc = info_proc;
}
+void
+gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch *gdbarch, int (*cb) (struct objfile *objfile, void *cb_data), void *cb_data, struct objfile *current_objfile)
+{
+ gdb_assert (gdbarch != NULL);
+ gdb_assert (gdbarch->iterate_over_objfiles_in_search_order != NULL);
+ if (gdbarch_debug >= 2)
+ fprintf_unfiltered (gdb_stdlog, "gdbarch_iterate_over_objfiles_in_search_order called\n");
+ gdbarch->iterate_over_objfiles_in_search_order (gdbarch, cb, cb_data, current_objfile);
+}
+
+void
+set_gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch *gdbarch,
+ gdbarch_iterate_over_objfiles_in_search_order_ftype iterate_over_objfiles_in_search_order)
+{
+ gdbarch->iterate_over_objfiles_in_search_order = iterate_over_objfiles_in_search_order;
+}
+
/* Keep a registry of per-architecture data-pointers required by GDB
modules. */
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 5d73d72..8bbe0f0 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -1171,6 +1171,24 @@ typedef void (gdbarch_info_proc_ftype) (struct gdbarch *gdbarch, char *args, enu
extern void gdbarch_info_proc (struct gdbarch *gdbarch, char *args, enum info_proc_what what);
extern void set_gdbarch_info_proc (struct gdbarch *gdbarch, gdbarch_info_proc_ftype *info_proc);
+/* Iterate over all objfiles in the order that makes the most sense
+ for the architecture to make global symbol searches.
+
+ CB is a callback function where OBJFILE is the objfile to be searched,
+ and CB_DATA a pointer to user-defined data (the same data that is passed
+ when calling this gdbarch method). The iteration stops if this function
+ returns nonzero.
+
+ CB_DATA is a pointer to some user-defined data to be passed to
+ the callback.
+
+ If not NULL, CURRENT_OBJFILE corresponds to the objfile being
+ inspected when the symbol search was requested. */
+
+typedef void (gdbarch_iterate_over_objfiles_in_search_order_ftype) (struct gdbarch *gdbarch, int (*cb) (struct objfile *objfile, void *cb_data), void *cb_data, struct objfile *current_objfile);
+extern void gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch *gdbarch, int (*cb) (struct objfile *objfile, void *cb_data), void *cb_data, struct objfile *current_objfile);
+extern void set_gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch *gdbarch, gdbarch_iterate_over_objfiles_in_search_order_ftype *iterate_over_objfiles_in_search_order);
+
/* Definition for an unknown syscall, used basically in error-cases. */
#define UNKNOWN_SYSCALL (-1)
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index cc1fe65..167eb2e 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -934,6 +934,21 @@ m:void:gen_return_address:struct agent_expr *ax, struct axs_value *value, CORE_A
# Implement the "info proc" command.
M:void:info_proc:char *args, enum info_proc_what what:args, what
+# Iterate over all objfiles in the order that makes the most sense
+# for the architecture to make global symbol searches.
+#
+# CB is a callback function where OBJFILE is the objfile to be searched,
+# and CB_DATA a pointer to user-defined data (the same data that is passed
+# when calling this gdbarch method). The iteration stops if this function
+# returns nonzero.
+#
+# CB_DATA is a pointer to some user-defined data to be passed to
+# the callback.
+#
+# If not NULL, CURRENT_OBJFILE corresponds to the objfile being
+# inspected when the symbol search was requested.
+m:void:iterate_over_objfiles_in_search_order:int (*cb) (struct objfile *objfile, void *cb_data), void *cb_data, struct objfile *current_objfile:cb, cb_data, current_objfile:0:default_iterate_over_objfiles_in_search_order::0
+
EOF
}
@@ -1380,6 +1395,7 @@ cat <<EOF
#include "gdb_obstack.h"
#include "observer.h"
#include "regcache.h"
+#include "objfiles.h"
/* Static function declarations */
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 8d9f8a5..daa6068 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -1525,6 +1525,31 @@ gdb_bfd_unref (struct bfd *abfd)
xfree (name);
}
+/* The default implementation for the "iterate_over_objfiles_in_search_order"
+ gdbarch method. It is equivalent to use the ALL_OBJFILES macro,
+ searching the objfiles in the order they are stored internally,
+ ignoring CURRENT_OBJFILE.
+
+ On most platorms, it should be close enough to doing the best
+ we can without some knowledge specific to the architecture. */
+
+void
+default_iterate_over_objfiles_in_search_order
+ (struct gdbarch *gdbarch,
+ int (*cb) (struct objfile *objfile, void *cb_data),
+ void *cb_data, struct objfile *current_objfile)
+{
+ int stop = 0;
+ struct objfile *objfile;
+
+ ALL_OBJFILES (objfile)
+ {
+ stop = cb (objfile, cb_data);
+ if (stop)
+ return;
+ }
+}
+
/* Provide a prototype to silence -Wmissing-prototypes. */
extern initialize_file_ftype _initialize_objfiles;
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index d5c807f..0c4f723 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -525,6 +525,11 @@ extern void *objfile_data (struct objfile *objfile,
extern struct bfd *gdb_bfd_ref (struct bfd *abfd);
extern void gdb_bfd_unref (struct bfd *abfd);
extern int gdb_bfd_close_or_warn (struct bfd *abfd);
+
+extern void default_iterate_over_objfiles_in_search_order
+ (struct gdbarch *gdbarch,
+ int (*cb) (struct objfile *objfile, void *cb_data),
+ void *cb_data, struct objfile *current_objfile);
\f
/* Traverse all object files in the current program space.
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 39d8c6f..57c55b6 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1498,40 +1498,55 @@ lookup_global_symbol_from_objfile (const struct objfile *main_objfile,
return NULL;
}
-/* Check to see if the symbol is defined in one of the symtabs.
- BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
+/* Check to see if the symbol is defined in one of the OBJFILE's
+ symtabs. BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
depending on whether or not we want to search global symbols or
static symbols. */
static struct symbol *
+lookup_symbol_aux_objfile (struct objfile *objfile, int block_index,
+ const char *name, const domain_enum domain)
+{
+ struct symbol *sym = NULL;
+ struct blockvector *bv;
+ const struct block *block;
+ struct symtab *s;
+
+ if (objfile->sf)
+ objfile->sf->qf->pre_expand_symtabs_matching (objfile, block_index,
+ name, domain);
+
+ ALL_OBJFILE_SYMTABS (objfile, s)
+ if (s->primary)
+ {
+ bv = BLOCKVECTOR (s);
+ block = BLOCKVECTOR_BLOCK (bv, block_index);
+ sym = lookup_block_symbol (block, name, domain);
+ if (sym)
+ {
+ block_found = block;
+ return fixup_symbol_section (sym, objfile);
+ }
+ }
+
+ return NULL;
+}
+
+/* Same as lookup_symbol_aux_objfile, except that it searches all
+ objfiles. Return the first match found. */
+
+static struct symbol *
lookup_symbol_aux_symtabs (int block_index, const char *name,
const domain_enum domain)
{
struct symbol *sym;
struct objfile *objfile;
- struct blockvector *bv;
- const struct block *block;
- struct symtab *s;
ALL_OBJFILES (objfile)
{
- if (objfile->sf)
- objfile->sf->qf->pre_expand_symtabs_matching (objfile,
- block_index,
- name, domain);
-
- ALL_OBJFILE_SYMTABS (objfile, s)
- if (s->primary)
- {
- bv = BLOCKVECTOR (s);
- block = BLOCKVECTOR_BLOCK (bv, block_index);
- sym = lookup_block_symbol (block, name, domain);
- if (sym)
- {
- block_found = block;
- return fixup_symbol_section (sym, objfile);
- }
- }
+ sym = lookup_symbol_aux_objfile (objfile, block_index, name, domain);
+ if (sym)
+ return sym;
}
return NULL;
@@ -1648,6 +1663,46 @@ lookup_symbol_static (const char *name,
return NULL;
}
+/* Private data to be used with lookup_symbol_global_iterator_cb. */
+
+struct global_sym_lookup_data
+{
+ /* The name of the symbol we are searching for. */
+ const char *name;
+
+ /* The domain to use for our search. */
+ domain_enum domain;
+
+ /* The field where the callback should store the symbol if found.
+ It should be initialized to NULL before the search is started. */
+ struct symbol *result;
+};
+
+/* A callback function for gdbarch_iterate_over_objfiles_in_search_order.
+ It searches by name for a symbol in the GLOBAL_BLOCK of the given
+ OBJFILE. The arguments for the search are passed via CB_DATA,
+ which in reality is a pointer to struct global_sym_lookup_data. */
+
+static int
+lookup_symbol_global_iterator_cb (struct objfile *objfile,
+ void *cb_data)
+{
+ struct global_sym_lookup_data *data =
+ (struct global_sym_lookup_data *) cb_data;
+
+ gdb_assert (data->result == NULL);
+
+ data->result = lookup_symbol_aux_objfile (objfile, GLOBAL_BLOCK,
+ data->name, data->domain);
+ if (data->result == NULL)
+ data->result = lookup_symbol_aux_quick (objfile, GLOBAL_BLOCK,
+ data->name, data->domain);
+
+ /* If we found a match, tell the iterator to stop. Otherwise,
+ keep going. */
+ return (data->result != NULL);
+}
+
/* Lookup a symbol in all files' global blocks (searching psymtabs if
necessary). */
@@ -1658,6 +1713,7 @@ lookup_symbol_global (const char *name,
{
struct symbol *sym = NULL;
struct objfile *objfile = NULL;
+ struct global_sym_lookup_data lookup_data;
/* Call library-specific lookup procedure. */
objfile = lookup_objfile_from_block (block);
@@ -1666,18 +1722,14 @@ lookup_symbol_global (const char *name,
if (sym != NULL)
return sym;
- sym = lookup_symbol_aux_symtabs (GLOBAL_BLOCK, name, domain);
- if (sym != NULL)
- return sym;
-
- ALL_OBJFILES (objfile)
- {
- sym = lookup_symbol_aux_quick (objfile, GLOBAL_BLOCK, name, domain);
- if (sym)
- return sym;
- }
+ memset (&lookup_data, 0, sizeof (lookup_data));
+ lookup_data.name = name;
+ lookup_data.domain = domain;
+ gdbarch_iterate_over_objfiles_in_search_order
+ (objfile != NULL ? get_objfile_arch (objfile) : target_gdbarch,
+ lookup_symbol_global_iterator_cb, &lookup_data, objfile);
- return NULL;
+ return lookup_data.result;
}
int
--
1.7.1
^ permalink raw reply [flat|nested] 10+ messages in thread