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/ezannoni_pie-20040323-branch] New branch and pie


I gave up updating the old branch that I had created for PIE work.
I just created a new one: ezannoni_pie-20040323-branch.

Here is what I have checked in, I'll explain in detail when I send
each patch for inclusion in mainline. But here it is for people to
play with.

You do need the latest Linux 2.6 kernels, because of auxv support.
For instance, this works with the fedora RedHat distro.

There are no regressions on the linux platforms with auxv support,
when the testuite is run normally and with "--target_board=unix/-fpie -pie".
(this includes ppc, ppc64, ia64, i386, x86-64, s390, s390x).

Similarly on a Red Hat linux 9 system which doesn't have PIE or auxv
(of course this is true only for the vanilla testsuite run).

Since there are changes in the solib handling (especially
solib-svr4.c) I think I need to do a little more testing on other
platforms that use that file. 

I need to clean up the patch a little bit more, I just noticed that I
have still some ifdeffed out code, and similar things.  But you get
the idea.



2004-03-23  Elena Zannoni  <ezannoni@redhat.com>

       * solib-svr4.c (svr4_solib_create_inferior_hook): Disable
       breakpoints at startup.
       (elf_locate_base): Find out where the entry point for the program
       is, using the auxv vector, if possible. Compute the address of
       .dynamic using it.
       (svr4_current_sos): Don't ignore the first entry if we have PIE,
       it's our main program. Delete code that was skipping over the
       solib entry for main executable.
       * solist.h (struct so_list): Add fields main and main_relocated.
        (add_to_target_sections): Export.
       * solib.c (symbol_add_stub): Handle main executable in shared
       library list. Ignore it if it has been relocated already. Add it
       as the main symbol file, otherwise.
       * infrun.c (handle_inferior_event): Re-enable startup breakpoints.

       * solib-svr4.c (elf_locate_base, first_link_map_member)
       svr4_current_sos, enable_break): Add debugging output.
       * solist.h (debug_solib): Export.
       * solib.c (debug_solib): New variable to enable debugging output.
       (symbol_add_stub, update_solib_list, update_solib_list)
       (add_to_target_sections): Add debugging output.
       (_initialize_solib): Add new comand to enable printing of
       debugging output.
       (add_to_target_sections): New function. Factored out from
       update_solib_list.
       (update_solib_list): Call add_to_target_sections.

       * varobj.h (varobj_refresh): New prototype.
       * varobj.c (varobj_refresh): New function.
       * symfile.c (reread_symbols): Make sure that we recompute the
       entry point for the program.
       (symbol_file_clear): Clear the solibs as well, if we change symbol
       files.
       (clear_symtab_users): Refresh the varobjs that depend on the symtabs
       we are clearing.
       * objfiles.c (entry_point_address): Rewrite, to fetch entry point
       from auxv vector, if possible.
       Add include of elf/common.h.
       * breakpoint.h (enum bptype): Add bp type bp_startup_disabled.
       (re_enable_breakpoints_at_startup)
       (disable_breakpoints_at_startup): Add prototypes
       * breakpoint.c (re_enable_breakpoints_at_startup)
       (disable_breakpoints_at_startup): New functions.
       (describe_other_breakpoints, delete_breakpoint)
       (breakpoint_re_set_one): Handle new bp type.
       * auxv.h (target_auxv_parse, target_auxv_search): Update.
       * auxv.c (target_auxv_parse, target_auxv_search)
       (fprint_target_auxv): Use ULONGEST instead of CORE_ADDR for
       variable. Change variable name to at_type.


Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.529
diff -u -p -r1.529 Makefile.in
--- Makefile.in	23 Mar 2004 14:12:30 -0000	1.529
+++ Makefile.in	24 Mar 2004 04:02:06 -0000
@@ -2412,7 +2412,7 @@ symfile.o: symfile.c $(defs_h) $(bfdlink
 	$(complaints_h) $(demangle_h) $(inferior_h) $(filenames_h) \
 	$(gdb_stabs_h) $(gdb_obstack_h) $(completer_h) $(bcache_h) \
 	$(hashtab_h) $(readline_h) $(gdb_assert_h) $(block_h) \
-	$(gdb_string_h) $(gdb_stat_h)
+	$(gdb_string_h) $(gdb_stat_h) $(varobj_h)
 symmisc.o: symmisc.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(bfd_h) \
 	$(symfile_h) $(objfiles_h) $(breakpoint_h) $(command_h) \
 	$(gdb_obstack_h) $(language_h) $(bcache_h) $(block_h) $(gdb_regex_h) \
Index: auxv.c
===================================================================
RCS file: /cvs/src/src/gdb/auxv.c,v
retrieving revision 1.2
diff -u -p -r1.2 auxv.c
--- auxv.c	24 Feb 2004 01:00:30 -0000	1.2
+++ auxv.c	24 Mar 2004 04:02:08 -0000
@@ -119,7 +119,7 @@ target_auxv_read (struct target_ops *ops
    Return 1 if an entry was read into *TYPEP and *VALP.  */
 int
 target_auxv_parse (struct target_ops *ops, char **readptr, char *endptr,
-		   CORE_ADDR *typep, CORE_ADDR *valp)
+		   ULONGEST *typep, CORE_ADDR *valp)
 {
   const int sizeof_auxv_field = TYPE_LENGTH (builtin_type_void_data_ptr);
   char *ptr = *readptr;
@@ -144,9 +144,10 @@ target_auxv_parse (struct target_ops *op
    an error getting the information.  On success, return 1 after
    storing the entry's value field in *VALP.  */
 int
-target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
+target_auxv_search (struct target_ops *ops, ULONGEST match, CORE_ADDR *valp)
 {
-  CORE_ADDR type, val;
+  CORE_ADDR val;
+  ULONGEST at_type;
   char *data;
   int n = target_auxv_read (ops, &data);
   char *ptr = data;
@@ -156,10 +157,10 @@ target_auxv_search (struct target_ops *o
     return n;
 
   while (1)
-    switch (target_auxv_parse (ops, &ptr, data + n, &type, &val))
+    switch (target_auxv_parse (ops, &ptr, data + n, &at_type, &val))
       {
       case 1:			/* Here's an entry, check it.  */
-	if (type == match)
+	if (at_type == match)
 	  {
 	    xfree (data);
 	    *valp = val;
@@ -182,7 +183,8 @@ target_auxv_search (struct target_ops *o
 int
 fprint_target_auxv (struct ui_file *file, struct target_ops *ops)
 {
-  CORE_ADDR type, val;
+  CORE_ADDR val;
+  ULONGEST at_type;
   char *data;
   int len = target_auxv_read (ops, &data);
   char *ptr = data;
@@ -191,14 +193,14 @@ fprint_target_auxv (struct ui_file *file
   if (len <= 0)
     return len;
 
-  while (target_auxv_parse (ops, &ptr, data + len, &type, &val) > 0)
+  while (target_auxv_parse (ops, &ptr, data + len, &at_type, &val) > 0)
     {
       extern int addressprint;
       const char *name = "???";
       const char *description = "";
       enum { dec, hex, str } flavor = hex;
 
-      switch (type)
+      switch (at_type)
 	{
 #define TAG(tag, text, kind) \
 	case tag: name = #tag; description = text; flavor = kind; break
@@ -249,7 +251,7 @@ fprint_target_auxv (struct ui_file *file
 	}
 
       fprintf_filtered (file, "%-4s %-20s %-30s ",
-			paddr_d (type), name, description);
+			paddr_d (at_type), name, description);
       switch (flavor)
 	{
 	case dec:
Index: auxv.h
===================================================================
RCS file: /cvs/src/src/gdb/auxv.h,v
retrieving revision 1.1
diff -u -p -r1.1 auxv.h
--- auxv.h	1 Feb 2004 22:35:24 -0000	1.1
+++ auxv.h	24 Mar 2004 04:02:08 -0000
@@ -43,14 +43,14 @@ extern LONGEST target_auxv_read (struct 
    Return 1 if an entry was read into *TYPEP and *VALP.  */
 extern int target_auxv_parse (struct target_ops *ops,
 			      char **readptr, char *endptr,
-			      CORE_ADDR *typep, CORE_ADDR *valp);
+			      ULONGEST *typep, CORE_ADDR *valp);
 
 /* Extract the auxiliary vector entry with a_type matching MATCH.
    Return zero if no such entry was found, or -1 if there was
    an error getting the information.  On success, return 1 after
    storing the entry's value field in *VALP.  */
 extern int target_auxv_search (struct target_ops *ops,
-			       CORE_ADDR match, CORE_ADDR *valp);
+			       ULONGEST match, CORE_ADDR *valp);
 
 /* Print the contents of the target's AUXV on the specified file. */
 extern int fprint_target_auxv (struct ui_file *file, struct target_ops *ops);
Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.165
diff -u -p -r1.165 breakpoint.c
--- breakpoint.c	23 Mar 2004 14:47:55 -0000	1.165
+++ breakpoint.c	24 Mar 2004 04:02:15 -0000
@@ -3793,6 +3793,7 @@ describe_other_breakpoints (CORE_ADDR pc
 			       b->number,
 			       ((b->enable_state == bp_disabled || 
 				 b->enable_state == bp_shlib_disabled || 
+				 b->enable_state == bp_startup_disabled || 
 				 b->enable_state == bp_call_disabled) 
 				? " (disabled)" 
 				: b->enable_state == bp_permanent 
@@ -4427,6 +4428,62 @@ re_enable_breakpoints_in_shlibs (void)
 
 #endif
 
+void
+disable_breakpoints_at_startup (int silent)
+{
+  struct breakpoint *b;
+  int disabled_startup_breaks = 0;
+
+  if (bfd_get_start_address (exec_bfd) != entry_point_address ())
+    {
+      ALL_BREAKPOINTS (b)
+	{
+	  if (((b->type == bp_breakpoint) ||
+	       (b->type == bp_hardware_breakpoint)) &&
+	      b->enable_state == bp_enabled &&
+	      !b->loc->duplicate)
+	    {
+	      b->enable_state = bp_startup_disabled;
+	      if (!silent)
+		{
+		  if (!disabled_startup_breaks)
+		    {
+		      target_terminal_ours_for_output ();
+		      warning ("Temporarily disabling breakpoints:");
+		    }
+		  disabled_startup_breaks = 1;
+		  warning ("breakpoint #%d addr 0x%s", b->number, paddr_nz(b->loc->address));
+		}
+	    }
+	}
+    }
+}
+
+/* Try to reenable any breakpoints after startup.  */
+void
+re_enable_breakpoints_at_startup (void)
+{
+  struct breakpoint *b;
+
+  if (bfd_get_start_address (exec_bfd) != entry_point_address ())
+    {
+      ALL_BREAKPOINTS (b)
+	if (b->enable_state == bp_startup_disabled)
+	  {
+	    char buf[1];
+
+	    /* Do not reenable the breakpoint if the shared library
+	       is still not mapped in.  */
+	    if (target_read_memory (b->loc->address, buf, 1) == 0)
+	      {
+		/*printf ("enabling breakpoint at 0x%s\n", paddr_nz(b->loc->address));*/
+		b->enable_state = bp_enabled;
+	      }
+	  }
+    }
+}
+
+
 static void
 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
 		     char *cond_string, enum bptype bp_kind)
@@ -6940,6 +6997,7 @@ delete_breakpoint (struct breakpoint *bp
 	    && !b->loc->duplicate
 	    && b->enable_state != bp_disabled
 	    && b->enable_state != bp_shlib_disabled
+	    && b->enable_state != bp_startup_disabled
 	    && !b->pending
 	    && b->enable_state != bp_call_disabled)
 	{
@@ -7151,7 +7209,8 @@ breakpoint_re_set_one (void *bint)
 	break;
 
       save_enable = b->enable_state;
-      if (b->enable_state != bp_shlib_disabled)
+      if (b->enable_state != bp_shlib_disabled
+          || b->enable_state != bp_shlib_disabled)
         b->enable_state = bp_disabled;
 
       set_language (b->language);
Index: breakpoint.h
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.h,v
retrieving revision 1.31
diff -u -p -r1.31 breakpoint.h
--- breakpoint.h	2 Feb 2004 21:10:49 -0000	1.31
+++ breakpoint.h	24 Mar 2004 04:02:16 -0000
@@ -159,6 +159,7 @@ enum enable_state
 			   automatically enabled and reset when the call 
 			   "lands" (either completes, or stops at another 
 			   eventpoint). */
+    bp_startup_disabled,
     bp_permanent	/* There is a breakpoint instruction hard-wired into
 			   the target's code.  Don't try to write another
 			   breakpoint instruction on top of it, or restore
@@ -771,7 +772,11 @@ extern void remove_thread_event_breakpoi
 
 extern void disable_breakpoints_in_shlibs (int silent);
 
+extern void disable_breakpoints_at_startup (int silent);
+
 extern void re_enable_breakpoints_in_shlibs (void);
+
+void re_enable_breakpoints_at_startup (void);
 
 extern void create_solib_load_event_breakpoint (char *, int, char *, char *);
 
Index: infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.142
diff -u -p -r1.142 infrun.c
--- infrun.c	23 Mar 2004 14:47:56 -0000	1.142
+++ infrun.c	24 Mar 2004 04:02:21 -0000
@@ -2355,6 +2355,11 @@ process_event_stop_test:
 	     code segments in shared libraries might be mapped in now. */
 	  re_enable_breakpoints_in_shlibs ();
 
+	  /* For PIE executables, we dont really know where the
+	     breakpoints are going to be until we start up the
+	     inferior.  */
+          re_enable_breakpoints_at_startup ();
+
 	  /* If requested, stop when the dynamic linker notifies
 	     gdb of events.  This allows the user to get control
 	     and place breakpoints in initializer routines for
Index: objfiles.c
===================================================================
RCS file: /cvs/src/src/gdb/objfiles.c,v
retrieving revision 1.51
diff -u -p -r1.51 objfiles.c
--- objfiles.c	17 Feb 2004 19:37:37 -0000	1.51
+++ objfiles.c	24 Mar 2004 04:02:23 -0000
@@ -46,6 +46,8 @@
 #include "block.h"
 #include "dictionary.h"
 
+#include "elf/common.h"
+
 /* Prototypes for local functions */
 
 static void objfile_alloc_data (struct objfile *objfile);
@@ -263,7 +265,19 @@ init_entry_point_info (struct objfile *o
 CORE_ADDR
 entry_point_address (void)
 {
-  return symfile_objfile ? symfile_objfile->ei.entry_point : 0;
+  int ret;
+  CORE_ADDR entry_addr;
+
+  /* Find the address of the entry point of the program from the
+     auxv vector.  */
+  ret = target_auxv_search (&current_target, AT_ENTRY, &entry_addr);
+  if (ret == 1)
+     return entry_addr;                                                                              
+  /*if (ret == 0 || ret == -1)*/
+  else
+    {
+      return symfile_objfile ? symfile_objfile->ei.entry_point : 0;
+    }
 }
 
 /* Create the terminating entry of OBJFILE's minimal symbol table.
Index: solib-svr4.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
retrieving revision 1.43
diff -u -p -r1.43 solib-svr4.c
--- solib-svr4.c	15 Mar 2004 20:38:08 -0000	1.43
+++ solib-svr4.c	24 Mar 2004 04:02:25 -0000
@@ -179,7 +179,9 @@ static CORE_ADDR breakpoint_addr;	/* Add
 
 /* Local function prototypes */
 
+#if 0
 static int match_main (char *);
+#endif
 
 static CORE_ADDR bfd_lookup_symbol (bfd *, char *, flagword);
 
@@ -428,22 +430,79 @@ elf_locate_base (void)
 {
   struct bfd_section *dyninfo_sect;
   int dyninfo_sect_size;
-  CORE_ADDR dyninfo_addr;
+  CORE_ADDR dyninfo_addr, relocated_dyninfo_addr, entry_addr;
   char *buf;
   char *bufend;
   int arch_size;
+  int ret;
+
+  /* Find the address of the entry point of the program from the
+     auxv vector.  */
+  ret = target_auxv_search (&current_target, AT_ENTRY, &entry_addr);
+
+  if (ret == 0 || ret == -1)
+    {
+      /* No auxv info, maybe an older kernel. Fake our way through.  */
+      entry_addr = bfd_get_start_address (exec_bfd); 
+
+      if (debug_solib)
+	fprintf_unfiltered (gdb_stdlog,
+			    "elf_locate_base: program entry address not found. Using bfd's 0x%s for %s\n",
+			    paddr_nz (entry_addr), exec_bfd->filename);
+    }
+  else
+    {
+      if (debug_solib)
+	fprintf_unfiltered (gdb_stdlog,
+			    "elf_locate_base: found program entry address 0x%s for %s\n",
+			    paddr_nz (entry_addr), exec_bfd->filename);
+    }
 
   /* 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: .dynamic section not found in %s -- return now\n",
+			    exec_bfd->filename);
+      return 0;
+    }
+  else
+    { 
+      if (debug_solib)
+	fprintf_unfiltered (gdb_stdlog,
+			    "elf_locate_base: .dynamic section found in %s\n",
+			    exec_bfd->filename);
+    }
+
   dyninfo_addr = bfd_section_vma (exec_bfd, dyninfo_sect);
+  if (debug_solib)
+    fprintf_unfiltered (gdb_stdlog,
+			"elf_locate_base: unrelocated .dynamic addr 0x%s\n",
+			paddr_nz (dyninfo_addr));
+
+  relocated_dyninfo_addr = dyninfo_addr
+    + entry_addr - bfd_get_start_address(exec_bfd);
+  if (debug_solib) 
+    fprintf_unfiltered (gdb_stdlog, 
+			"elf_locate_base: relocated .dyn addr 0x%s for %s\n",
+			paddr_nz(relocated_dyninfo_addr), exec_bfd->filename);
 
   /* 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: read in .dynamic section\n");
+  if (target_read_memory (relocated_dyninfo_addr, buf, dyninfo_sect_size))
+    { 
+      if (debug_solib)
+	fprintf_unfiltered (gdb_stdlog,
+			    "elf_locate_base: couldn't read .dynamic section at 0x%s -- return now\n",
+			    paddr_nz (relocated_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
@@ -470,6 +529,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 -- return now\n",
+				    paddr_nz (dyn_ptr));
 	      return dyn_ptr;
 	    }
 	  else if (dyn_tag == DT_MIPS_RLD_MAP)
@@ -613,6 +676,10 @@ first_link_map_member (void)
   char *r_map_buf = xmalloc (lmo->r_map_size);
   struct cleanup *cleanups = make_cleanup (xfree, r_map_buf);
 
+  if (debug_solib)
+    fprintf_unfiltered (gdb_stdlog, 
+                        "first_link_map_member: read at 0x%s\n",
+                        paddr_nz (debug_base + lmo->r_map_offset));
   read_memory (debug_base + lmo->r_map_offset, r_map_buf, lmo->r_map_size);
 
   /* Assume that the address is unsigned.  */
@@ -726,6 +793,10 @@ svr4_current_sos (void)
   CORE_ADDR lm;
   struct so_list *head = 0;
   struct so_list **link_ptr = &head;
+  if (debug_solib)
+    fprintf_unfiltered (gdb_stdlog, 
+                        "svr4_current_sos: exec_bfd %s\n",
+                        exec_bfd->filename);
 
   /* Make sure we've looked up the inferior's dynamic linker's base
      structure.  */
@@ -736,12 +807,22 @@ 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 in %s -- return now\n",
+				exec_bfd->filename);
+	  return 0;
+	}
     }
 
   /* Walk the inferior's link map list, and build our list of
      `struct so_list' nodes.  */
-  lm = first_link_map_member ();  
+  if (debug_solib)
+    fprintf_unfiltered (gdb_stdlog, 
+                        "svr4_current_sos: walk link map in %s\n",
+                        exec_bfd->filename);
+  lm = first_link_map_member (); 
   while (lm)
     {
       struct link_map_offsets *lmo = SVR4_FETCH_LINK_MAP_OFFSETS ();
@@ -758,54 +839,133 @@ svr4_current_sos (void)
       make_cleanup (xfree, new->lm_info->lm);
       memset (new->lm_info->lm, 0, lmo->link_map_size);
 
+      if (debug_solib)
+        fprintf_unfiltered (gdb_stdlog, 
+                            "svr4_current_sos: read lm at 0x%s\n", paddr_nz(lm));
       read_memory (lm, new->lm_info->lm, lmo->link_map_size);
 
       lm = LM_NEXT (new);
 
+      if (debug_solib)
+        fprintf_unfiltered (gdb_stdlog,
+                            "svr4_current_sos: is first link entry? %d\n",
+                            IGNORE_FIRST_LINK_MAP_ENTRY (new));
+
       /* For SVR4 versions, the first entry in the link map is for the
          inferior executable, so we must ignore it.  For some versions of
          SVR4, it has no name.  For others (Solaris 2.3 for example), it
          does have a name, so we can no longer use a missing name to
          decide when to ignore it. */
       if (IGNORE_FIRST_LINK_MAP_ENTRY (new))
-	free_so (new);
+	{
+
+	  if (bfd_get_start_address (exec_bfd) == entry_point_address ())
+	    {
+	      free_so (new);
+	    }
+	  else
+	    {
+	      struct so_list *gdb_solib;
+	      if (debug_solib)
+		fprintf_unfiltered (gdb_stdlog,
+				    "svr4_current_sos: Processing first link map entry\n");
+	      strncpy (new->so_name, exec_bfd->filename,
+		       SO_NAME_MAX_PATH_SIZE - 1);
+	      new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
+	      strcpy (new->so_original_name, new->so_name);
+	      /*new->main = 1;*/
+	      new->main_relocated = 0;
+            
+	      if (debug_solib)
+		{ 
+		  fprintf_unfiltered (gdb_stdlog,
+				      "svr4_current_sos: Processing nameless DSO\n");
+		  fprintf_unfiltered (gdb_stdlog,
+				      "svr4_current_sos: adding name %s\n",
+				      new->so_name);
+		}
+
+	      for (gdb_solib = master_so_list (); gdb_solib; gdb_solib = gdb_solib->next)
+		{
+		  if (debug_solib)
+		    fprintf_unfiltered (gdb_stdlog,
+					"svr4_current_sos: compare gdb %s and new %s\n",
+					gdb_solib->so_name, new->so_name);
+		  if (!strcmp (gdb_solib->so_name, new->so_name))
+		    if (gdb_solib->main_relocated)
+		      { 
+			if (debug_solib)
+			  fprintf_unfiltered (gdb_stdlog,
+					      "svr4_current_sos: found main relocated\n");
+			break;
+		      }
+		}
+
+	      if ((gdb_solib && !gdb_solib->main_relocated) || (!gdb_solib))
+		{
+		  add_to_target_sections (0 /*from_tty*/, &current_target, new);
+		  new->main = 1;
+		}
+	      /* We need this in the list of shared libs we return because
+		 solib_add_stub will loop through it and add the symbol file.  */
+	      new->next = 0;
+	      *link_ptr = new;
+	      link_ptr = &new->next; 
+	    }
+	}
       else
 	{
 	  int errcode;
 	  char *buffer;
 
 	  /* Extract this shared object's name.  */
+	  if (debug_solib)
+	    fprintf_unfiltered (gdb_stdlog, 
+                                "svr4_current_sos: read LM_NAME\n");
+
 	  target_read_string (LM_NAME (new), &buffer,
 			      SO_NAME_MAX_PATH_SIZE - 1, &errcode);
 	  if (errcode != 0)
 	    {
-	      warning ("current_sos: Can't read pathname for load map: %s\n",
+	      warning ("svr4_current_sos: Can't read pathname for load map: %s\n",
 		       safe_strerror (errcode));
 	    }
 	  else
 	    {
+              if (debug_solib)
+                fprintf_unfiltered (gdb_stdlog, 
+                                    "svr4_current_sos: LM_NAME is <%s>\n",
+                                    buffer);
+
 	      strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
 	      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);
+		  fprintf_unfiltered (gdb_stdlog,
+				      "svr4_current_sos: first link entry %d\n",
+				      IGNORE_FIRST_LINK_MAP_ENTRY (new));
+		}
 	    }
 
-	  /* If this entry has no name, or its name matches the name
-	     for the main executable, don't include it in the list.  */
-	  if (! new->so_name[0]
-	      || match_main (new->so_name))
-	    free_so (new);
-	  else
-	    {
-	      new->next = 0;
-	      *link_ptr = new;
-	      link_ptr = &new->next;
-	    }
+	  new->next = 0;
+	  *link_ptr = new;
+	  link_ptr = &new->next;
+
 	}
 
       discard_cleanups (old_chain);
     }
 
+  if (debug_solib)
+    fprintf_unfiltered (gdb_stdlog, 
+                        "svr4_current_sos: ENDS %s\n",
+                        exec_bfd->filename);
+
   return head;
 }
 
@@ -824,7 +984,7 @@ svr4_fetch_objfile_link_map (struct objf
     return 0;   /* failed somehow... */
 
   /* Position ourselves on the first link map.  */
-  lm = first_link_map_member ();  
+  lm = first_link_map_member ();
   while (lm)
     {
       /* Get info on the layout of the r_debug and link_map structures. */
@@ -885,7 +1045,7 @@ svr4_fetch_objfile_link_map (struct objf
 /* On some systems, the only way to recognize the link map entry for
    the main executable file is by looking at its name.  Return
    non-zero iff SONAME matches one of the known main executable names.  */
-
+#if 0
 static int
 match_main (char *soname)
 {
@@ -899,6 +1059,7 @@ match_main (char *soname)
 
   return (0);
 }
+#endif
 
 /* Return 1 if PC lies in the dynamic symbol resolution code of the
    SVR4 run time loader.  */
@@ -998,6 +1159,11 @@ 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;
@@ -1031,6 +1197,9 @@ 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;
 
@@ -1112,6 +1281,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;
 	}
 
@@ -1371,6 +1543,8 @@ svr4_solib_create_inferior_hook (void)
   while (stop_signal != TARGET_SIGNAL_TRAP);
   stop_soon = NO_STOP_QUIETLY;
 #endif /* defined(_SCO_DS) */
+ 
+   disable_breakpoints_at_startup (1); 
 }
 
 static void
Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.64
diff -u -p -r1.64 solib.c
--- solib.c	11 Mar 2004 17:04:40 -0000	1.64
+++ solib.c	24 Mar 2004 04:02:26 -0000
@@ -46,6 +46,8 @@
 
 /* external data declarations */
 
+int debug_solib;
+
 /* FIXME: gdbarch needs to control this variable */
 struct target_so_ops *current_target_so_ops;
 
@@ -68,6 +70,8 @@ static char *solib_absolute_prefix = NUL
    and LD_LIBRARY_PATH.  */
 static char *solib_search_path = NULL;
 
+void add_to_target_sections (int, struct target_ops *, struct so_list *);
+
 /*
 
    GLOBAL FUNCTION
@@ -340,7 +344,6 @@ master_so_list (void)
   return so_list_head;
 }
 
-
 /* A small stub to get us past the arg-passing pinhole of catch_errors.  */
 
 static int
@@ -352,15 +355,40 @@ symbol_add_stub (void *arg)
   /* Have we already loaded this shared object?  */
   ALL_OBJFILES (so->objfile)
     {
-      if (strcmp (so->objfile->name, so->so_name) == 0)
+      /* Found an already loaded shared library.  */
+      if (strcmp (so->objfile->name, so->so_name) == 0
+          && !so->main)
 	return 1;
+      /* Found an already loaded main executable.  This could happen in
+         two circumstances. 
+         First case: the main file has already been read in
+         as the first thing that gdb does at startup, and the file
+         hasn't been relocated properly yet. Therefor we need to read
+         it in with the proper section info.
+         Second case: it has been read in with the correct relocation,
+         and therefore we need to skip it.  */
+      if (strcmp (so->objfile->name, so->so_name) == 0 
+          && so->main
+          && so->main_relocated)
+        return 1;
     }
 
   sap = build_section_addr_info_from_section_table (so->sections,
                                                     so->sections_end);
 
-  so->objfile = symbol_file_add (so->so_name, so->from_tty,
-				 sap, 0, OBJF_SHARED);
+  if (so->main)
+    {
+      if (debug_solib)
+        fprintf_unfiltered (gdb_stdlog,
+			    "symbol_add_stub: adding symbols for main\n");
+      so->objfile = symbol_file_add (so->so_name, /*so->from_tty*/ 0,
+   				     sap, 1, 0);
+      so->main_relocated = 1;
+    }
+  else
+    so->objfile = symbol_file_add (so->so_name, so->from_tty,
+				   sap, 0, OBJF_SHARED);
+
   free_section_addr_info (sap);
 
   return (1);
@@ -455,6 +483,10 @@ update_solib_list (int from_tty, struct 
 	 the inferior's current list.  */
       while (i)
 	{
+          if (debug_solib)
+            fprintf_unfiltered (gdb_stdlog,
+                                "update_solib_list: compare gdb:%s and inferior:%s\n",
+                                gdb->so_original_name, i->so_original_name);
 	  if (! strcmp (gdb->so_original_name, i->so_original_name))
 	    break;
 
@@ -504,32 +536,46 @@ update_solib_list (int from_tty, struct 
       /* Fill in the rest of each of the `struct so_list' nodes.  */
       for (i = inferior; i; i = i->next)
 	{
-	  i->from_tty = from_tty;
-
-	  /* Fill in the rest of the `struct so_list' node.  */
-	  catch_errors (solib_map_sections, i,
-			"Error while mapping shared library sections:\n",
-			RETURN_MASK_ALL);
-
-	  /* If requested, add the shared object's sections to the TARGET's
-	     section table.  Do this immediately after mapping the object so
-	     that later nodes in the list can query this object, as is needed
-	     in solib-osf.c.  */
-	  if (target)
-	    {
-	      int count = (i->sections_end - i->sections);
-	      if (count > 0)
-		{
-		  int space = target_resize_to_sections (target, count);
-		  memcpy (target->to_sections + space,
-			  i->sections,
-			  count * sizeof (i->sections[0]));
-		}
-	    }
+   	  add_to_target_sections (from_tty, target, i);
 	}
     }
 }
 
+void
+add_to_target_sections (int from_tty, struct target_ops *target, struct so_list *solib)
+{
+  /* If this is set, then the sections have been already added to the
+     target list.  */
+  if (solib->main)
+    return;
+
+  solib->from_tty = from_tty;
+
+  /* Fill in the rest of the `struct so_list' node.  */
+  catch_errors (solib_map_sections, solib,
+		"Error while mapping shared library sections:\n",
+		RETURN_MASK_ALL);
+
+  /* If requested, add the shared object's sections to the TARGET's
+     section table.  Do this immediately after mapping the object so
+     that later nodes in the list can query this object, as is needed
+     in solib-osf.c.  */
+  if (target)
+    {
+      int count = (solib->sections_end - solib->sections);
+      if (count > 0)
+	{
+	  int space = target_resize_to_sections (target, count);
+          if (debug_solib)
+             fprintf_unfiltered (gdb_stdlog,
+                                 "add_to_target_sections: add %s to to_sections\n",
+                                 solib->so_original_name);
+	  memcpy (target->to_sections + space,
+		  solib->sections,
+		  count * sizeof (solib->sections[0]));
+	}
+    }
+}
 
 /* GLOBAL FUNCTION
 
@@ -917,4 +963,10 @@ This takes precedence over the environme
   add_show_from_set (c, &showlist);
   set_cmd_cfunc (c, reload_shared_libraries);
   set_cmd_completer (c, filename_completer);
+
+  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: solist.h
===================================================================
RCS file: /cvs/src/src/gdb/solist.h,v
retrieving revision 1.9
diff -u -p -r1.9 solist.h
--- solist.h	11 Mar 2004 17:04:40 -0000	1.9
+++ solist.h	24 Mar 2004 04:02:26 -0000
@@ -62,6 +62,8 @@ struct so_list
     bfd *abfd;
     char symbols_loaded;	/* flag: symbols read in yet? */
     char from_tty;		/* flag: print msgs? */
+    char main;                  /* flag: is this the main executable? */
+    char main_relocated;        /* flag: has it been relocated yet? */
     struct objfile *objfile;	/* objfile for loaded lib */
     struct section_table *sections;
     struct section_table *sections_end;
@@ -113,9 +115,15 @@ void free_so (struct so_list *so);
 /* Return address of first so_list entry in master shared object list.  */
 struct so_list *master_so_list (void);
 
+/* Return address of first so_list entry in master shared object list.  */
+struct so_list *master_so_list (void);
+
 /* Find solib binary file and open it.  */
 extern int solib_open (char *in_pathname, char **found_pathname);
 
+/* Add the list of sections in so_list to the target to_sections.  */
+extern void add_to_target_sections (int, struct target_ops *, struct so_list *);
+
 /* FIXME: gdbarch needs to control this variable */
 extern struct target_so_ops *current_target_so_ops;
 
@@ -135,4 +143,6 @@ extern struct target_so_ops *current_tar
 #define TARGET_SO_FIND_AND_OPEN_SOLIB \
   (current_target_so_ops->find_and_open_solib)
 
+/* Controls the printing of debugging output.  */
+extern int debug_solib;
 #endif
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.124
diff -u -p -r1.124 symfile.c
--- symfile.c	28 Feb 2004 18:04:37 -0000	1.124
+++ symfile.c	24 Mar 2004 04:02:30 -0000
@@ -48,6 +48,7 @@
 #include "readline/readline.h"
 #include "gdb_assert.h"
 #include "block.h"
+#include "varobj.h"
 
 #include <sys/types.h>
 #include <fcntl.h>
@@ -573,7 +574,7 @@ syms_from_objfile (struct objfile *objfi
 
      We no longer warn if the lowest section is not a text segment (as
      happens for the PA64 port.  */
-  if (!mainline && addrs && addrs->other[0].name)
+  if (/*!mainline &&*/ addrs && addrs->other[0].name)
     {
       asection *lower_sect;
       asection *sect;
@@ -960,6 +961,10 @@ symbol_file_clear (int from_tty)
       && !query ("Discard symbol table from `%s'? ",
 		 symfile_objfile->name))
     error ("Not confirmed.");
+#ifdef CLEAR_SOLIB
+      CLEAR_SOLIB ();
+#endif
+
     free_all_objfiles ();
 
     /* solib descriptors may have handles to objfiles.  Since their
@@ -1957,6 +1962,8 @@ reread_symbols (void)
 	      /* Discard cleanups as symbol reading was successful.  */
 	      discard_cleanups (old_cleanups);
 
+	      init_entry_point_info (objfile);
+
 	      /* If the mtime has changed between the time we set new_modtime
 	         and now, we *want* this to be out of date, so don't call stat
 	         again now.  */
@@ -2312,6 +2319,7 @@ clear_symtab_users (void)
   clear_pc_function_cache ();
   if (target_new_objfile_hook)
     target_new_objfile_hook (NULL);
+  varobj_refresh();
 }
 
 static void
Index: varobj.c
===================================================================
RCS file: /cvs/src/src/gdb/varobj.c,v
retrieving revision 1.40
diff -u -p -r1.40 varobj.c
--- varobj.c	3 Sep 2003 20:46:02 -0000	1.40
+++ varobj.c	24 Mar 2004 04:02:32 -0000
@@ -854,6 +854,62 @@ varobj_list (struct varobj ***varlist)
   return rootcount;
 }
 
+void
+varobj_refresh (void)
+{
+  struct varobj *var;
+  struct varobj_root *croot;
+  int mycount = rootcount;
+  char * name;
+                                                                                
+  croot = rootlist;
+  while ((croot != NULL) && (mycount > 0))
+    {
+      var = croot->rootvar;
+                                                                                
+      /* Get rid of the memory for the old expression.  This also
+         leaves var->root->exp == NULL, which is ok for the parsing
+         below.  */
+      free_current_contents ((char **) &var->root->exp);
+                                                                                
+      value_free (var->value);
+      var->type = NULL;
+
+      name = xstrdup (var->name);
+
+      /* Reparse the expression.  Wrap the call to parse expression,
+         so we can return a sensible error. */
+      if (!gdb_parse_exp_1 (&name, var->root->valid_block, 0, &var->root->exp))
+        {
+          return;
+        }
+                                                                                
+      /* We definitively need to catch errors here.
+         If evaluate_expression succeeds we got the value we wanted.
+         But if it fails, we still go on with a call to evaluate_type()  */
+      if (gdb_evaluate_expression (var->root->exp, &var->value))
+        {
+          /* no error */
+          release_value (var->value);
+          if (VALUE_LAZY (var->value))
+            gdb_value_fetch_lazy (var->value);
+        }
+      else
+        var->value = evaluate_type (var->root->exp);
+                                                                                
+      var->type = VALUE_TYPE (var->value);
+                                                                                
+      mycount--;
+      croot = croot->next;
+    }
+                                                                                
+  if (mycount || (croot != NULL))
+    warning
+      ("varobj_refresh: assertion failed - wrong tally of root vars (%d:%d)",
+       rootcount, mycount);
+}
+                                                                                
+
 /* Update the values for a variable and its children.  This is a
    two-pronged attack.  First, re-parse the value for the root's
    expression to see if it's changed.  Then go all the way
Index: varobj.h
===================================================================
RCS file: /cvs/src/src/gdb/varobj.h,v
retrieving revision 1.4
diff -u -p -r1.4 varobj.h
--- varobj.h	17 Aug 2001 18:56:49 -0000	1.4
+++ varobj.h	24 Mar 2004 04:02:32 -0000
@@ -97,4 +97,6 @@ extern int varobj_list (struct varobj **
 
 extern int varobj_update (struct varobj **varp, struct varobj ***changelist);
 
+extern void varobj_refresh(void);
+
 #endif /* VAROBJ_H */


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