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: Fri, 28 Jun 2013 11:17:40 +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>
On 06/28/2013 04:42 AM, Tom Tromey wrote:
> Yao> + minimal symbols just red in by matching the minimal symbol name
>
> s/red/read/
>
Fixed.
> Yao> + char *buffer = xstrdup (SYMBOL_LINKAGE_NAME (msym_dll));
>
> I don't think you need to copy the name here.
>
Oh, yes.
> Yao> +/* Look for the minimal symbol which name is NAME. Return NULL if not
>
> "whose name".
Fixed.
>
> I think this comment needs to be expanded (and moved, see below).
> It should at least mention that this only searches minsyms that are
> currently being constructed. Otherwise it isn't clear why you would use
> this function as opposed to lookup_minimal_symbol_and_objfile.
>
OK, the comments are moved to the declaration in minsyms.h, and mention
that look for minsyms "in minimal symbols that are currently being
constructed".
> Yao> +struct minimal_symbol* prim_find_minimal_symbol (const char *name);
>
> The comment should go here, the way it does for other functions in the
> minsyms module.
>
> Also, the first "*" is in the wrong place.
Fixed.
--
Yao (éå)
gdb:
2013-06-28 Yao Qi <yao@codesourcery.com>
* coffread.c: Use DEF_VEC_P to define vector type.
(coff_symtab_read): Define local variable 'dll_trampoline'.
Record minimal symbols into 'dll_trampoline' if their names
have prefix "_imp_ or "__imp_". Set the type of minimal
symbol to 'mst_solib_trampoline' if it is a dll trampoline.
* minsyms.c (prim_find_minimal_symbol): New function.
* minsyms.h (prim_find_minimal_symbol): Declare.
---
gdb/coffread.c | 41 +++++++++++++++++++++++++++++++++++++++++
gdb/minsyms.c | 26 ++++++++++++++++++++++++++
gdb/minsyms.h | 5 +++++
3 files changed, 72 insertions(+), 0 deletions(-)
diff --git a/gdb/coffread.c b/gdb/coffread.c
index bf39085..62f164c 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -724,6 +724,9 @@ coff_symfile_finish (struct objfile *objfile)
}
+typedef struct minimal_symbol *msymbolp;
+DEF_VEC_P (msymbolp);
+
/* Given pointers to a symbol table in coff style exec file,
analyze them and create struct symtab's describing the symbols.
NSYMS is the number of symbols in the symbol table.
@@ -757,6 +760,8 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
int val;
CORE_ADDR tmpaddr;
struct minimal_symbol *msym;
+ /* A set of minimal_symbol which has prefix "__imp_" or "_imp_". */
+ VEC (msymbolp) *name_prefix_imp = NULL;
/* Work around a stdio bug in SunOS4.1.1 (this makes me nervous....
it's hard to know I've really worked around it. The fix should
@@ -1006,6 +1011,16 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
SYMBOL_VALUE (sym) = tmpaddr;
SYMBOL_SECTION (sym) = sec;
}
+
+ /* Record minimal symbols whose name are prefixed by "__imp_"
+ or "_imp_" in set NAME_PREFIX_IMP if their type is
+ mst_data. Note that 'maintenance print msymbols' shows
+ that type of these "_imp_XXXX" symbols is mst_data. */
+ if (msym != NULL && ms_type == mst_data
+ && (strncmp (cs->c_name, "__imp_", 6) == 0
+ || strncmp (cs->c_name, "_imp_", 5) == 0))
+ VEC_safe_push (msymbolp, name_prefix_imp, msym);
+
}
break;
@@ -1151,6 +1166,32 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
}
}
+ if (pe_file)
+ {
+ int ix;
+ struct minimal_symbol *msym_dll;
+
+ /* Set NAME_PREFIX_IMP contains minimal symbols whose name is
+ prefixed by "__imp_" or "_imp_". In each iteration, look for the
+ minimal symbols just read in by matching the minimal symbol name
+ without the prefix. */
+ for (ix = 0;
+ VEC_iterate (msymbolp, name_prefix_imp, ix, msym_dll);
+ ix++)
+ {
+ const char *sname = SYMBOL_LINKAGE_NAME (msym_dll);
+ const char *name = (sname[1] == '_' ? &sname[7] : &sname[6]);
+ struct minimal_symbol *found
+ = prim_find_minimal_symbol (name);
+
+ /* If found, there are symbols named "_imp_foo" and "foo"
+ respectively read in from the current 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;
+ }
+ }
+
if ((nsyms == 0) && (pe_file))
{
/* We've got no debugging symbols, but it's a portable
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 89e538a..2d18545 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -1259,6 +1259,32 @@ install_minimal_symbols (struct objfile *objfile)
/* See minsyms.h. */
+struct minimal_symbol *
+prim_find_minimal_symbol (const char *name)
+{
+ struct msym_bunch *bunch;
+ int max;
+
+ max = msym_bunch_index;
+ for (bunch = msym_bunch; bunch != NULL; bunch = bunch->next)
+ {
+ int bindex;
+
+ for (bindex = 0; bindex < max; bindex++)
+ {
+ struct minimal_symbol *msym = &bunch->contents[bindex];
+
+ if (strcmp (name, SYMBOL_LINKAGE_NAME (msym)) == 0)
+ return msym;
+ }
+ max = BUNCH_SIZE;
+ }
+
+ return NULL;
+}
+
+/* See minsyms.h. */
+
void
terminate_minimal_symbol_table (struct objfile *objfile)
{
diff --git a/gdb/minsyms.h b/gdb/minsyms.h
index 4d48477..3500ec5 100644
--- a/gdb/minsyms.h
+++ b/gdb/minsyms.h
@@ -252,4 +252,9 @@ void iterate_over_minimal_symbols (struct objfile *objf,
void *),
void *user_data);
+/* Look for the minimal symbol whose name is NAME in minimal symbols that
+ are currently being constructed. Return NULL if not found. */
+
+struct minimal_symbol *prim_find_minimal_symbol (const char *name);
+
#endif /* MINSYMS_H */
--
1.7.7.6