Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Re: Display libc function names instead of address ?
       [not found]       ` <1118936759.24041.23.camel@haypopc>
@ 2005-06-16 16:26         ` Daniel Jacobowitz
  2005-06-16 18:46           ` Eli Zaretskii
  2005-09-18  1:45           ` Daniel Jacobowitz
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2005-06-16 16:26 UTC (permalink / raw)
  To: Victor STINNER, Elena Zannoni; +Cc: gdb-patches

On Thu, Jun 16, 2005 at 05:45:59PM +0200, Victor STINNER wrote:
> Le jeudi 16 juin 2005 à 11:19 -0400, Daniel Jacobowitz a écrit :
> > Thanks for checking!  That's output from objdump, right?  It doesn't
> > seem to work for me in GDB, just in objdump.  But perhaps I can figure
> > out where to wire it in.
> 
> Yep, it's in objdump. I think that you just have to update bfd and
> opcodes libraries, no ?

No - GDB also needs a change.

This has been on my todo list for months, ever since objdump gained
support.  Here's an implementation - the patch applies to GDB CVS.
Elena, is this patch OK?

Tested on i686-pc-linux-gnu.  It leaves a stray if (1) to minimize the
size of the diff; I would remove that as an obvious followup.

-- 
Daniel Jacobowitz
CodeSourcery, LLC

2005-06-16  Daniel Jacobowitz  <dan@codesourcery.com>

	* elfread.c (elf_symtab_read): Add number_of_symbols and
	symbol_table as arguments.  Do not load the symbol table
	here.
	(elf_symfile_read): Load the static and dynamic symbol tables
	here, before calling elf_symtab_read.  Also load any synthetic
	symbols and process those.

Index: elfread.c
===================================================================
RCS file: /cvs/src/src/gdb/elfread.c,v
retrieving revision 1.50
diff -u -p -r1.50 elfread.c
--- elfread.c	21 Feb 2005 11:00:44 -0000	1.50
+++ elfread.c	16 Jun 2005 16:19:27 -0000
@@ -124,13 +124,14 @@ record_minimal_symbol (char *name, CORE_
 
    SYNOPSIS
 
-   void elf_symtab_read (struct objfile *objfile, int dynamic)
+   void elf_symtab_read (struct objfile *objfile, int dynamic,
+			 long number_of_symbols, asymbol **symbol_table)
 
    DESCRIPTION
 
-   Given an objfile and a flag that specifies whether or not the objfile
-   is for an executable or not (may be shared library for example), add
-   all the global function and data symbols to the minimal symbol table.
+   Given an objfile, a symbol table, and a flag indicating whether the
+   symbol table contains dynamic symbols, add all the global function
+   and data symbols to the minimal symbol table.
 
    In stabs-in-ELF, as implemented by Sun, there are some local symbols
    defined in the ELF symbol table, which can be used to locate
@@ -141,14 +142,12 @@ record_minimal_symbol (char *name, CORE_
  */
 
 static void
-elf_symtab_read (struct objfile *objfile, int dynamic)
+elf_symtab_read (struct objfile *objfile, int dynamic,
+		 long number_of_symbols, asymbol **symbol_table)
 {
   long storage_needed;
   asymbol *sym;
-  asymbol **symbol_table;
-  long number_of_symbols;
   long i;
-  struct cleanup *back_to;
   CORE_ADDR symaddr;
   CORE_ADDR offset;
   enum minimal_symbol_type ms_type;
@@ -165,34 +164,8 @@ elf_symtab_read (struct objfile *objfile
   struct dbx_symfile_info *dbx = objfile->deprecated_sym_stab_info;
   int stripped = (bfd_get_symcount (objfile->obfd) == 0);
 
-  if (dynamic)
-    {
-      storage_needed = bfd_get_dynamic_symtab_upper_bound (objfile->obfd);
-
-      /* Nothing to be done if there is no dynamic symtab.  */
-      if (storage_needed < 0)
-	return;
-    }
-  else
-    {
-      storage_needed = bfd_get_symtab_upper_bound (objfile->obfd);
-      if (storage_needed < 0)
-	error (_("Can't read symbols from %s: %s"), bfd_get_filename (objfile->obfd),
-	       bfd_errmsg (bfd_get_error ()));
-    }
-  if (storage_needed > 0)
+  if (1)
     {
-      symbol_table = (asymbol **) xmalloc (storage_needed);
-      back_to = make_cleanup (xfree, symbol_table);
-      if (dynamic)
-	number_of_symbols = bfd_canonicalize_dynamic_symtab (objfile->obfd,
-							     symbol_table);
-      else
-	number_of_symbols = bfd_canonicalize_symtab (objfile->obfd, symbol_table);
-      if (number_of_symbols < 0)
-	error (_("Can't read symbols from %s: %s"), bfd_get_filename (objfile->obfd),
-	       bfd_errmsg (bfd_get_error ()));
-
       for (i = 0; i < number_of_symbols; i++)
 	{
 	  sym = symbol_table[i];
@@ -450,7 +423,6 @@ elf_symtab_read (struct objfile *objfile
 	      ELF_MAKE_MSYMBOL_SPECIAL (sym, msym);
 	    }
 	}
-      do_cleanups (back_to);
     }
 }
 
@@ -493,6 +465,9 @@ elf_symfile_read (struct objfile *objfil
   struct elfinfo ei;
   struct cleanup *back_to;
   CORE_ADDR offset;
+  long symcount = 0, dynsymcount = 0, synthcount, storage_needed;
+  asymbol **symbol_table = NULL, **dyn_symbol_table = NULL;
+  asymbol *synthsyms;
 
   init_minimal_symbol_collection ();
   back_to = make_cleanup_discard_minimal_symbols ();
@@ -509,11 +484,65 @@ elf_symfile_read (struct objfile *objfil
      chain of info into the dbx_symfile_info in objfile->deprecated_sym_stab_info,
      which can later be used by elfstab_offset_sections.  */
 
-  elf_symtab_read (objfile, 0);
+  storage_needed = bfd_get_symtab_upper_bound (objfile->obfd);
+  if (storage_needed < 0)
+    error (_("Can't read symbols from %s: %s"), bfd_get_filename (objfile->obfd),
+	   bfd_errmsg (bfd_get_error ()));
+
+  if (storage_needed > 0)
+    {
+      symbol_table = (asymbol **) xmalloc (storage_needed);
+      make_cleanup (xfree, symbol_table);
+      symcount = bfd_canonicalize_symtab (objfile->obfd, symbol_table);
+
+      if (symcount < 0)
+	error (_("Can't read symbols from %s: %s"), bfd_get_filename (objfile->obfd),
+	       bfd_errmsg (bfd_get_error ()));
+
+      elf_symtab_read (objfile, 0, symcount, symbol_table);
+    }
 
   /* Add the dynamic symbols.  */
 
-  elf_symtab_read (objfile, 1);
+  storage_needed = bfd_get_dynamic_symtab_upper_bound (objfile->obfd);
+
+  if (storage_needed > 0)
+    {
+      dyn_symbol_table = (asymbol **) xmalloc (storage_needed);
+      make_cleanup (xfree, dyn_symbol_table);
+      dynsymcount = bfd_canonicalize_dynamic_symtab (objfile->obfd,
+						     dyn_symbol_table);
+
+      if (dynsymcount < 0)
+	error (_("Can't read symbols from %s: %s"), bfd_get_filename (objfile->obfd),
+	       bfd_errmsg (bfd_get_error ()));
+
+      elf_symtab_read (objfile, 1, dynsymcount, dyn_symbol_table);
+    }
+
+  /* Add synthetic symbols - for instance, names for any PLT entries.  */
+
+  synthcount = bfd_get_synthetic_symtab (abfd, symcount, symbol_table,
+					 dynsymcount, dyn_symbol_table,
+					 &synthsyms);
+  if (synthcount > 0)
+    {
+      asymbol **synth_symbol_table;
+      long i;
+
+      make_cleanup (xfree, synthsyms);
+      synth_symbol_table = xmalloc (sizeof (asymbol *) * synthcount);
+      for (i = 0; i < synthcount; i++)
+	{
+	  synth_symbol_table[i] = synthsyms + i;
+	  /* Synthetic symbols are not, strictly speaking, either local
+	     or global.  But we can treat them as global symbols, since
+	     they are effectively dynamic symbols.  */
+	  synth_symbol_table[i]->flags |= BSF_GLOBAL;
+	}
+      make_cleanup (xfree, synth_symbol_table);
+      elf_symtab_read (objfile, 0, synthcount, synth_symbol_table);
+    }
 
   /* Install any minimal symbols that have been collected as the current
      minimal symbols for this objfile.  The debug readers below this point


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Display libc function names instead of address ?
  2005-06-16 16:26         ` Display libc function names instead of address ? Daniel Jacobowitz
@ 2005-06-16 18:46           ` Eli Zaretskii
  2005-06-16 18:49             ` Daniel Jacobowitz
  2005-09-18  1:45           ` Daniel Jacobowitz
  1 sibling, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2005-06-16 18:46 UTC (permalink / raw)
  To: Victor STINNER; +Cc: gdb-patches, ezannoni

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1052 bytes --]

> Date: Thu, 16 Jun 2005 12:26:05 -0400
> From: Daniel Jacobowitz <drow@false.org>
> Cc: gdb-patches@sources.redhat.com
> 
> On Thu, Jun 16, 2005 at 05:45:59PM +0200, Victor STINNER wrote:
> > Le jeudi 16 juin 2005 à 11:19 -0400, Daniel Jacobowitz a écrit :
> > > Thanks for checking!  That's output from objdump, right?  It doesn't
> > > seem to work for me in GDB, just in objdump.  But perhaps I can figure
> > > out where to wire it in.
> > 
> > Yep, it's in objdump. I think that you just have to update bfd and
> > opcodes libraries, no ?
> 
> No - GDB also needs a change.
> 
> This has been on my todo list for months, ever since objdump gained
> support.  Here's an implementation - the patch applies to GDB CVS.
> Elena, is this patch OK?
> 
> Tested on i686-pc-linux-gnu.  It leaves a stray if (1) to minimize the
> size of the diff; I would remove that as an obvious followup.

Will this change modify what GDB displays in response to some command?
If so, please see whether something in the manual needs a suitable
change as well.

TIA


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Display libc function names instead of address ?
  2005-06-16 18:46           ` Eli Zaretskii
@ 2005-06-16 18:49             ` Daniel Jacobowitz
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2005-06-16 18:49 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Victor STINNER, gdb-patches, ezannoni

On Thu, Jun 16, 2005 at 09:44:47PM +0200, Eli Zaretskii wrote:
> Will this change modify what GDB displays in response to some command?
> If so, please see whether something in the manual needs a suitable
> change as well.

No, nothing in the manual needs to be updated.  Thanks for checking.

-- 
Daniel Jacobowitz
CodeSourcery, LLC


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Display libc function names instead of address ?
  2005-06-16 16:26         ` Display libc function names instead of address ? Daniel Jacobowitz
  2005-06-16 18:46           ` Eli Zaretskii
@ 2005-09-18  1:45           ` Daniel Jacobowitz
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2005-09-18  1:45 UTC (permalink / raw)
  To: Victor STINNER, Elena Zannoni, gdb-patches

On Thu, Jun 16, 2005 at 12:26:05PM -0400, Daniel Jacobowitz wrote:
> On Thu, Jun 16, 2005 at 05:45:59PM +0200, Victor STINNER wrote:
> > Le jeudi 16 juin 2005 à 11:19 -0400, Daniel Jacobowitz a écrit :
> > > Thanks for checking!  That's output from objdump, right?  It doesn't
> > > seem to work for me in GDB, just in objdump.  But perhaps I can figure
> > > out where to wire it in.
> > 
> > Yep, it's in objdump. I think that you just have to update bfd and
> > opcodes libraries, no ?
> 
> No - GDB also needs a change.
> 
> This has been on my todo list for months, ever since objdump gained
> support.  Here's an implementation - the patch applies to GDB CVS.
> Elena, is this patch OK?
> 
> Tested on i686-pc-linux-gnu.  It leaves a stray if (1) to minimize the
> size of the diff; I would remove that as an obvious followup.

Hi Elena,

Have you had a chance to look at this patch?  The original report is
here:
    http://sourceware.org/ml/gdb/2005-06/msg00166.html

The patch is here:
    http://sourceware.org/ml/gdb-patches/2005-06/msg00220.html

And an example of it working is here:
    http://sourceware.org/ml/gdb/2005-06/msg00174.html

> 2005-06-16  Daniel Jacobowitz  <dan@codesourcery.com>
> 
> 	* elfread.c (elf_symtab_read): Add number_of_symbols and
> 	symbol_table as arguments.  Do not load the symbol table
> 	here.
> 	(elf_symfile_read): Load the static and dynamic symbol tables
> 	here, before calling elf_symtab_read.  Also load any synthetic
> 	symbols and process those.


-- 
Daniel Jacobowitz
CodeSourcery, LLC


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-09-18  1:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1118892960.12713.5.camel@haypopc>
     [not found] ` <20050616044313.GA5950@nevyn.them.org>
     [not found]   ` <1118934045.2827.4.camel@haypopc>
     [not found]     ` <20050616151934.GA11296@nevyn.them.org>
     [not found]       ` <1118936759.24041.23.camel@haypopc>
2005-06-16 16:26         ` Display libc function names instead of address ? Daniel Jacobowitz
2005-06-16 18:46           ` Eli Zaretskii
2005-06-16 18:49             ` Daniel Jacobowitz
2005-09-18  1:45           ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox