From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21046 invoked by alias); 28 Jun 2013 03:18:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 21012 invoked by uid 89); 28 Jun 2013 03:18:14 -0000 X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,TW_BJ,TW_YM autolearn=no version=3.3.1 Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 28 Jun 2013 03:18:13 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1UsPCN-0001Ir-3z from Yao_Qi@mentor.com ; Thu, 27 Jun 2013 20:18:11 -0700 Received: from SVR-ORW-FEM-04.mgc.mentorg.com ([147.34.97.41]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 27 Jun 2013 20:18:11 -0700 Received: from qiyao.dyndns.org (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.2.247.3; Thu, 27 Jun 2013 20:18:10 -0700 Message-ID: <51CD0054.9040401@codesourcery.com> Date: Fri, 28 Jun 2013 07:37:00 -0000 From: Yao Qi User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Tom Tromey CC: Subject: Re: [PATCH] Fix up msymbol type of dll trampoline to mst_solib_trampoline References: <1372043502-4618-1-git-send-email-yao@codesourcery.com> <874ncjmgkl.fsf@fleche.redhat.com> In-Reply-To: <874ncjmgkl.fsf@fleche.redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-SW-Source: 2013-06/txt/msg00866.txt.bz2 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 * 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