This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Fix up msymbol type of dll trampoline to mst_solib_trampoline
- From: Yao Qi <yao at codesourcery dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: <gdb-patches at sourceware dot org>
- Date: Wed, 3 Jul 2013 08:26:27 +0800
- Subject: Re: [PATCH] Fix up msymbol type of dll trampoline to mst_solib_trampoline
- References: <1372043502-4618-1-git-send-email-yao at codesourcery dot com> <874ncjmgkl dot fsf at fleche dot redhat dot com> <51CD0054 dot 9040401 at codesourcery dot com> <87ehbmkzqr dot fsf at fleche dot redhat dot com>
On 06/28/2013 11:43 PM, Tom Tromey wrote:
> It seems to me that it would be more efficient to keep a hash table of
> minsyms under construction, and then do this lookup when entering a new
> minsym. This would avoid repeated loops over all minsyms being defined.
>
> That is, if the new symbol is _imp_x, look up x. If the symbol is x,
> look up _imp_x. Then modify a symbol if needed.
In the updated patch, I use hash table when looking for up minsyms, but
in a little different way. After currently constructing minsyms are
installed to OBJFILE, there is a hash table built, we can use that one,
instead of maintaining a separate one. That is, after the hash table
of minsyms of OBJFILE is built up, we can iterate all minsyms, if
symbol is _imp_x, look up x in the hash table. If found, modify the
found's type.
Regression tested on i686-pc-mingw32. The following fail is fixed.
FAIL: gdb.base/solib-symbol.exp: foo in libmd
--
Yao (éå)
gdb:
2013-07-03 Yao Qi <yao@codesourcery.com>
* coffread.c (coff_symfile_read): Iterate over minimal symbols,
if the name is prefixed by "__imp_" or "_imp_", look for minimal
symbol without prefix. If found, set its type to
'mst_solib_trampoline'.
---
gdb/coffread.c | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/gdb/coffread.c b/gdb/coffread.c
index bf39085..f9bb59f 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -650,6 +650,36 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
install_minimal_symbols (objfile);
+ if (pe_file)
+ {
+ int i;
+
+ for (i = objfile->minimal_symbol_count; i > 0; i--)
+ {
+ struct minimal_symbol *msym = &objfile->msymbols[i];
+ const char *name = SYMBOL_LINKAGE_NAME (msym);
+
+ /* If the minimal symbols whose name are prefixed by "__imp_"
+ or "_imp_", get rid of the prefix, and search the minimal
+ symbol in OBJFILE. Note that 'maintenance print msymbols'
+ shows that type of these "_imp_XXXX" symbols is mst_data. */
+ if (MSYMBOL_TYPE (msym) == mst_data
+ && (strncmp (name, "__imp_", 6) == 0
+ || strncmp (name, "_imp_", 5) == 0))
+ {
+ const char *name1 = (name[1] == '_' ? &name[7] : &name[6]);
+ struct minimal_symbol *found;
+
+ found = lookup_minimal_symbol (name1, NULL, objfile);
+ /* If found, there are symbols named "_imp_foo" and "foo"
+ respectively in OBJFILE. Set the type of symbol "foo"
+ as 'mst_solib_trampoline'. */
+ if (found != NULL && MSYMBOL_TYPE (found) == mst_text)
+ MSYMBOL_TYPE (found) = mst_solib_trampoline;
+ }
+ }
+ }
+
/* Free the installed minimal symbol data. */
do_cleanups (cleanup_minimal_symbols);
--
1.7.7.6