Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <yao@codesourcery.com>
To: Tom Tromey <tromey@redhat.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Fix up msymbol type of dll trampoline to mst_solib_trampoline
Date: Fri, 28 Jun 2013 07:37:00 -0000	[thread overview]
Message-ID: <51CD0054.9040401@codesourcery.com> (raw)
In-Reply-To: <874ncjmgkl.fsf@fleche.redhat.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)
 }
 \f
 
+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


  reply	other threads:[~2013-06-28  3:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-24  4:24 Yao Qi
2013-06-27 20:43 ` Tom Tromey
2013-06-28  7:37   ` Yao Qi [this message]
2013-06-28 15:58     ` Tom Tromey
2013-07-03  0:26       ` Yao Qi
2013-07-05  8:44         ` asmwarrior
2013-07-05 12:22           ` Yao Qi
2013-07-05 14:30             ` Eli Zaretskii
2013-07-06  7:21               ` Yao Qi
2013-07-06  7:41                 ` Eli Zaretskii
2013-07-06  8:20                   ` asmwarrior
2013-07-10  6:21         ` Yao Qi
2013-07-10 16:56         ` Tom Tromey
2013-07-18  2:09           ` Yao Qi
2013-07-18  3:26             ` Yao Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51CD0054.9040401@codesourcery.com \
    --to=yao@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox