This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 6/9] symtab.c (basic_lookup_symbol_nonlocal): Add comment.
- From: Doug Evans <xdje42 at gmail dot com>
- To: gdb-patches at sourceware dot org
- Date: Sun, 26 Oct 2014 21:50:18 -0700
- Subject: [PATCH 6/9] symtab.c (basic_lookup_symbol_nonlocal): Add comment.
- Authentication-results: sourceware.org; auth=none
Hi.
This patch just adds a comment.
The topic here is whether, when searching all objfiles for global syms,
to first search the "current" objfile (the objfile of the BLOCK parameter),
or to just search all objfiles starting from the beginning.
There is actually a gdbarch API routine for this:
gdbarch_iterate_over_objfiles_in_search_order
The default is to not do anything special.
Windows has its own version in windows-tdep.c for this reason:
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.
The performance cost here can be significant with several libraries
(100s or 1000s). Plus as a user searching the current objfile is the
intuitively obvious thing to do (to me anyway),
regardless of whether the system has any rules as to whether it matters
what the search order is. Thus I think we could always just use the
windows search order, and this gdbarch API routine can go away,
but that's another patch for another day.
2014-10-26 Doug Evans <xdje42@gmail.com>
* symtab.c (basic_lookup_symbol_nonlocal): Add comment.
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 17f7499..07e9fce 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1789,6 +1789,10 @@ basic_lookup_symbol_nonlocal (const char *name,
than that one, so I don't think we should worry about that for
now. */
+ /* NOTE: dje/2014-10-26: The lookup in all objfiles search could skip
+ the current objfile. Searching the current objfile first is useful
+ for both matching user expectations as well as performance. */
+
sym = lookup_symbol_in_static_block (name, block, domain);
if (sym != NULL)
return sym;