This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH/pie] Add debugging output to svr4 solib


This patch to the ezannoni_pie-20030916-branch branch adds some useful
debug output to the solib stuff.

elena


2003-09-29  Elena Zannoni  <ezannoni@redhat.com>

	* solib-svr4.c: Include gdbcmd.h.
	(debug_solib): New variable.
	(elf_locate_base): Add some debugging statements.
	(svr4_current_sos): Likewise.
	(enable_break): Likewise.
	(svr4_relocate_main_executable): Likewise.
	(_initialize_svr4_solib): Add new 'set' command to control
	debugging output.
	* Makefile.in (solib-svr4.o): Update dependencies.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.444
diff -u -p -r1.444 Makefile.in
--- Makefile.in	13 Sep 2003 11:44:21 -0000	1.444
+++ Makefile.in	29 Sep 2003 17:33:28 -0000
@@ -2286,7 +2286,8 @@ solib-sunos.o: solib-sunos.c $(defs_h) $
 	$(bcache_h) $(regcache_h)
 solib-svr4.o: solib-svr4.c $(defs_h) $(elf_external_h) $(elf_common_h) \
 	$(elf_mips_h) $(symtab_h) $(bfd_h) $(symfile_h) $(objfiles_h) \
-	$(gdbcore_h) $(target_h) $(inferior_h) $(solist_h) $(solib_svr4_h)
+	$(gdbcore_h) $(target_h) $(inferior_h) $(solist_h) $(solib_svr4_h) \
+	$(gdbcmd_h)
 sol-thread.o: sol-thread.c $(defs_h) $(gdbthread_h) $(target_h) \
 	$(inferior_h) $(gdb_stat_h) $(gdbcmd_h) $(gdbcore_h) $(regcache_h) \
 	$(symfile_h) $(gregset_h)

Index: solib-svr4.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
retrieving revision 1.37
diff -u -p -r1.37 solib-svr4.c
--- solib-svr4.c	26 Aug 2003 23:35:19 -0000	1.37
+++ solib-svr4.c	29 Sep 2003 16:56:05 -0000
@@ -33,6 +33,7 @@
 #include "gdbcore.h"
 #include "target.h"
 #include "inferior.h"
+#include "gdbcmd.h"
 
 #include "solist.h"
 #include "solib-svr4.h"
@@ -116,6 +117,9 @@ static char *main_name_list[] =
   NULL
 };
 
+/* Control the printing of debugging statements.  */
+static int debug_solib;
+
 /* Macro to extract an address from a solib structure.  When GDB is
    configured for some 32-bit targets (e.g. Solaris 2.7 sparc), BFD is
    configured to handle 64-bit targets, so CORE_ADDR is 64 bits.  We
@@ -432,14 +436,26 @@ elf_locate_base (void)
   /* Find the start address of the .dynamic section.  */
   dyninfo_sect = bfd_get_section_by_name (exec_bfd, ".dynamic");
   if (dyninfo_sect == NULL)
-    return 0;
+    { 
+      if (debug_solib)
+	fprintf_unfiltered (gdb_stdlog,
+			    "elf_locate_base: didn't find .dynamic in %s\n",
+			    exec_bfd->filename);
+      return 0;
+    }
   dyninfo_addr = bfd_section_vma (exec_bfd, dyninfo_sect);
 
   /* Read in .dynamic section, silently ignore errors.  */
   dyninfo_sect_size = bfd_section_size (exec_bfd, dyninfo_sect);
   buf = alloca (dyninfo_sect_size);
   if (target_read_memory (dyninfo_addr, buf, dyninfo_sect_size))
-    return 0;
+    { 
+      if (debug_solib)
+	fprintf_unfiltered (gdb_stdlog,
+			    "elf_locate_base: coudn't read 0x%s\n",
+			    paddr_nz (dyninfo_addr));
+      return 0;
+    }
 
   /* Find the DT_DEBUG entry in the the .dynamic section.
      For mips elf we look for DT_MIPS_RLD_MAP, mips elf apparently has
@@ -466,6 +482,10 @@ elf_locate_base (void)
 	    {
 	      dyn_ptr = bfd_h_get_32 (exec_bfd, 
 				      (bfd_byte *) x_dynp->d_un.d_ptr);
+              if (debug_solib)
+                fprintf_unfiltered (gdb_stdlog,
+				    "elf_locate_base: DT_DEBUG entry has value 0x%s\n",
+				    paddr_nz (dyn_ptr));
 	      return dyn_ptr;
 	    }
 	  else if (dyn_tag == DT_MIPS_RLD_MAP)
@@ -732,7 +752,12 @@ svr4_current_sos (void)
       /* If we can't find the dynamic linker's base structure, this
 	 must not be a dynamically linked executable.  Hmm.  */
       if (! debug_base)
-	return 0;
+	{
+	  if (debug_solib)
+	    fprintf_unfiltered (gdb_stdlog, 
+				"svr4_current_sos: no DT_DEBUG found\n");
+	  return 0;
+	}
     }
 
   /* Walk the inferior's link map list, and build our list of
@@ -784,6 +809,10 @@ svr4_current_sos (void)
 	      new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
 	      xfree (buffer);
 	      strcpy (new->so_original_name, new->so_name);
+	      if (debug_solib)
+		fprintf_unfiltered (gdb_stdlog, 
+				    "svr4_current_sos: Processing DSO: %s\n",
+				    new->so_name);
 	    }
 
 	  /* If this entry has no name, or its name matches the name
@@ -976,6 +1005,10 @@ enable_break (void)
   /* Find the .interp section; if not found, warn the user and drop
      into the old breakpoint at symbol code.  */
   interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
+  if (debug_solib)
+    fprintf_unfiltered (gdb_stdlog,
+			"enable_break: search for .interp in %s\n",
+			exec_bfd->filename);
   if (interp_sect)
     {
       unsigned int interp_sect_size;
@@ -1008,6 +1041,10 @@ enable_break (void)
       if (tmp_fd >= 0)
 	tmp_bfd = bfd_fdopenr (tmp_pathname, gnutarget, tmp_fd);
 
+      if (debug_solib)
+	fprintf_unfiltered (gdb_stdlog,
+                            "enable_break: opening %s\n", tmp_pathname);
+
       if (tmp_bfd == NULL)
 	goto bkpt_at_symbol;
 
@@ -1086,6 +1123,9 @@ enable_break (void)
       if (sym_addr != 0)
 	{
 	  create_solib_event_breakpoint (load_addr + sym_addr);
+          if (debug_solib)
+            fprintf_unfiltered (gdb_stdlog,
+				"enable_break: solib bp set\n");
 	  return 1;
 	}
 
@@ -1232,6 +1272,11 @@ svr4_relocate_main_executable (void)
 	 The same language also appears in Edition 4.0 of the System V
 	 ABI and is left unspecified in some of the earlier editions.  */
 
+      fprintf_unfiltered (gdb_stdlog,
+                          "relocate_main: current pc is %s, bfd_start_address is %s\n",
+                          paddr_nz (pc),
+                          paddr_nz (bfd_get_start_address (exec_bfd)));
+
       displacement = pc - bfd_get_start_address (exec_bfd);
       changed = 0;
 
@@ -1500,4 +1545,8 @@ _initialize_svr4_solib (void)
 
   /* FIXME: Don't do this here.  *_gdbarch_init() should set so_ops. */
   current_target_so_ops = &svr4_so_ops;
+  add_show_from_set (add_set_cmd ("solib", no_class, var_zinteger,
+				  (char *) &debug_solib,
+				  "Set debugging of GNU/Linux shlib module.\n\
+Enables printf debugging output.\n", &setdebuglist), &showdebuglist);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]