9231e41
Index: gdb-6.5/gdb/dwarf2read.c
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/dwarf2read.c	2006-07-11 02:47:11.000000000 -0300
9231e41
+++ gdb-6.5/gdb/dwarf2read.c	2006-07-11 02:56:58.000000000 -0300
9231e41
@@ -1208,7 +1208,7 @@ dwarf2_build_psymtabs (struct objfile *o
84cb84b
   else
84cb84b
     dwarf2_per_objfile->loc_buffer = NULL;
84cb84b
 
84cb84b
-  if (mainline
84cb84b
+  if ((mainline == 1)
84cb84b
       || (objfile->global_psymbols.size == 0
84cb84b
 	  && objfile->static_psymbols.size == 0))
84cb84b
     {
9231e41
Index: gdb-6.5/gdb/auxv.c
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/auxv.c	2006-07-11 02:47:06.000000000 -0300
9231e41
+++ gdb-6.5/gdb/auxv.c	2006-07-11 02:47:11.000000000 -0300
84cb84b
@@ -119,7 +119,7 @@ target_auxv_read (struct target_ops *ops
84cb84b
    Return 1 if an entry was read into *TYPEP and *VALP.  */
84cb84b
 int
9231e41
 target_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
9231e41
-		   gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
9231e41
+		   gdb_byte *endptr, ULONGEST *typep, CORE_ADDR *valp)
84cb84b
 {
84cb84b
   const int sizeof_auxv_field = TYPE_LENGTH (builtin_type_void_data_ptr);
9231e41
   gdb_byte *ptr = *readptr;
84cb84b
@@ -144,9 +144,10 @@ target_auxv_parse (struct target_ops *op
84cb84b
    an error getting the information.  On success, return 1 after
84cb84b
    storing the entry's value field in *VALP.  */
84cb84b
 int
84cb84b
-target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
84cb84b
+target_auxv_search (struct target_ops *ops, ULONGEST match, CORE_ADDR *valp)
84cb84b
 {
84cb84b
-  CORE_ADDR type, val;
84cb84b
+  CORE_ADDR val;
84cb84b
+  ULONGEST at_type;
9231e41
   gdb_byte *data;
84cb84b
   int n = target_auxv_read (ops, &data);
9231e41
   gdb_byte *ptr = data;
84cb84b
@@ -156,10 +157,10 @@ target_auxv_search (struct target_ops *o
84cb84b
     return n;
84cb84b
 
84cb84b
   while (1)
84cb84b
-    switch (target_auxv_parse (ops, &ptr, data + n, &type, &val))
84cb84b
+    switch (target_auxv_parse (ops, &ptr, data + n, &at_type, &val))
84cb84b
       {
84cb84b
       case 1:			/* Here's an entry, check it.  */
84cb84b
-	if (type == match)
84cb84b
+	if (at_type == match)
84cb84b
 	  {
84cb84b
 	    xfree (data);
84cb84b
 	    *valp = val;
84cb84b
@@ -182,7 +183,8 @@ target_auxv_search (struct target_ops *o
84cb84b
 int
84cb84b
 fprint_target_auxv (struct ui_file *file, struct target_ops *ops)
84cb84b
 {
84cb84b
-  CORE_ADDR type, val;
84cb84b
+  CORE_ADDR val;
84cb84b
+  ULONGEST at_type;
9231e41
   gdb_byte *data;
84cb84b
   int len = target_auxv_read (ops, &data);
9231e41
   gdb_byte *ptr = data;
84cb84b
@@ -191,14 +193,14 @@ fprint_target_auxv (struct ui_file *file
84cb84b
   if (len <= 0)
84cb84b
     return len;
84cb84b
 
84cb84b
-  while (target_auxv_parse (ops, &ptr, data + len, &type, &val) > 0)
84cb84b
+  while (target_auxv_parse (ops, &ptr, data + len, &at_type, &val) > 0)
84cb84b
     {
84cb84b
       extern int addressprint;
84cb84b
       const char *name = "???";
84cb84b
       const char *description = "";
84cb84b
       enum { dec, hex, str } flavor = hex;
84cb84b
 
84cb84b
-      switch (type)
84cb84b
+      switch (at_type)
84cb84b
 	{
84cb84b
 #define TAG(tag, text, kind) \
84cb84b
 	case tag: name = #tag; description = text; flavor = kind; break
84cb84b
@@ -249,7 +251,7 @@ fprint_target_auxv (struct ui_file *file
84cb84b
 	}
84cb84b
 
84cb84b
       fprintf_filtered (file, "%-4s %-20s %-30s ",
84cb84b
-			paddr_d (type), name, description);
84cb84b
+			paddr_d (at_type), name, description);
84cb84b
       switch (flavor)
84cb84b
 	{
84cb84b
 	case dec:
9231e41
Index: gdb-6.5/gdb/auxv.h
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/auxv.h	2006-07-11 02:47:06.000000000 -0300
9231e41
+++ gdb-6.5/gdb/auxv.h	2006-07-11 02:47:11.000000000 -0300
84cb84b
@@ -43,14 +43,14 @@ extern LONGEST target_auxv_read (struct 
84cb84b
    Return 1 if an entry was read into *TYPEP and *VALP.  */
84cb84b
 extern int target_auxv_parse (struct target_ops *ops,
9231e41
 			      gdb_byte **readptr, gdb_byte *endptr,
84cb84b
-			      CORE_ADDR *typep, CORE_ADDR *valp);
84cb84b
+			      ULONGEST *typep, CORE_ADDR *valp);
84cb84b
 
84cb84b
 /* Extract the auxiliary vector entry with a_type matching MATCH.
84cb84b
    Return zero if no such entry was found, or -1 if there was
84cb84b
    an error getting the information.  On success, return 1 after
84cb84b
    storing the entry's value field in *VALP.  */
84cb84b
 extern int target_auxv_search (struct target_ops *ops,
84cb84b
-			       CORE_ADDR match, CORE_ADDR *valp);
84cb84b
+			       ULONGEST match, CORE_ADDR *valp);
84cb84b
 
84cb84b
 /* Print the contents of the target's AUXV on the specified file. */
84cb84b
 extern int fprint_target_auxv (struct ui_file *file, struct target_ops *ops);
9231e41
Index: gdb-6.5/gdb/breakpoint.h
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/breakpoint.h	2006-07-11 02:47:06.000000000 -0300
9231e41
+++ gdb-6.5/gdb/breakpoint.h	2006-07-11 02:47:11.000000000 -0300
84cb84b
@@ -159,6 +159,7 @@ enum enable_state
84cb84b
 			   automatically enabled and reset when the call 
84cb84b
 			   "lands" (either completes, or stops at another 
84cb84b
 			   eventpoint). */
84cb84b
+    bp_startup_disabled,
84cb84b
     bp_permanent	/* There is a breakpoint instruction hard-wired into
84cb84b
 			   the target's code.  Don't try to write another
84cb84b
 			   breakpoint instruction on top of it, or restore
9231e41
@@ -807,8 +808,12 @@ extern void remove_thread_event_breakpoi
84cb84b
 
84cb84b
 extern void disable_breakpoints_in_shlibs (int silent);
84cb84b
 
84cb84b
+extern void disable_breakpoints_at_startup (int silent);
84cb84b
+
84cb84b
 extern void re_enable_breakpoints_in_shlibs (void);
84cb84b
 
84cb84b
+void re_enable_breakpoints_at_startup (void);
84cb84b
+
84cb84b
 extern void create_solib_load_event_breakpoint (char *, int, char *, char *);
84cb84b
 
84cb84b
 extern void create_solib_unload_event_breakpoint (char *, int,
9231e41
Index: gdb-6.5/gdb/symfile-mem.c
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/symfile-mem.c	2006-07-11 02:47:06.000000000 -0300
9231e41
+++ gdb-6.5/gdb/symfile-mem.c	2006-07-11 02:56:55.000000000 -0300
9231e41
@@ -110,7 +110,7 @@ symbol_file_add_from_memory (struct bfd 
84cb84b
       }
84cb84b
 
84cb84b
   objf = symbol_file_add_from_bfd (nbfd, from_tty,
84cb84b
-                                   sai, 0, OBJF_SHARED);
84cb84b
+                                   sai, 2, OBJF_SHARED);
84cb84b
 
84cb84b
   /* This might change our ideas about frames already looked at.  */
84cb84b
   reinit_frame_cache ();
9231e41
Index: gdb-6.5/gdb/infrun.c
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/infrun.c	2006-07-11 02:47:06.000000000 -0300
9231e41
+++ gdb-6.5/gdb/infrun.c	2006-07-11 02:56:58.000000000 -0300
9231e41
@@ -2230,6 +2230,11 @@ process_event_stop_test:
84cb84b
 	     code segments in shared libraries might be mapped in now. */
84cb84b
 	  re_enable_breakpoints_in_shlibs ();
84cb84b
 
84cb84b
+	  /* For PIE executables, we dont really know where the
84cb84b
+	     breakpoints are going to be until we start up the
84cb84b
+	     inferior.  */
84cb84b
+          re_enable_breakpoints_at_startup ();
84cb84b
+
84cb84b
 	  /* If requested, stop when the dynamic linker notifies
84cb84b
 	     gdb of events.  This allows the user to get control
84cb84b
 	     and place breakpoints in initializer routines for
9231e41
Index: gdb-6.5/gdb/objfiles.c
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/objfiles.c	2006-07-11 02:47:06.000000000 -0300
9231e41
+++ gdb-6.5/gdb/objfiles.c	2006-07-11 02:47:11.000000000 -0300
9231e41
@@ -47,6 +47,9 @@
84cb84b
 #include "dictionary.h"
9231e41
 #include "source.h"
84cb84b
 
9231e41
+#include "auxv.h"
84cb84b
+#include "elf/common.h"
84cb84b
+
84cb84b
 /* Prototypes for local functions */
84cb84b
 
84cb84b
 static void objfile_alloc_data (struct objfile *objfile);
9231e41
@@ -258,7 +261,19 @@ init_entry_point_info (struct objfile *o
84cb84b
 CORE_ADDR
84cb84b
 entry_point_address (void)
84cb84b
 {
84cb84b
-  return symfile_objfile ? symfile_objfile->ei.entry_point : 0;
84cb84b
+  int ret;
84cb84b
+  CORE_ADDR entry_addr;
84cb84b
+
84cb84b
+  /* Find the address of the entry point of the program from the
84cb84b
+     auxv vector.  */
84cb84b
+  ret = target_auxv_search (&current_target, AT_ENTRY, &entry_addr);
84cb84b
+  if (ret == 1)
84cb84b
+     return entry_addr;                                                                              
84cb84b
+  /*if (ret == 0 || ret == -1)*/
84cb84b
+  else
84cb84b
+    {
84cb84b
+      return symfile_objfile ? symfile_objfile->ei.entry_point : 0;
84cb84b
+    }
84cb84b
 }
84cb84b
 
84cb84b
 /* Create the terminating entry of OBJFILE's minimal symbol table.
9231e41
Index: gdb-6.5/gdb/solib-svr4.c
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/solib-svr4.c	2006-07-11 02:47:06.000000000 -0300
9231e41
+++ gdb-6.5/gdb/solib-svr4.c	2006-07-11 02:47:11.000000000 -0300
9231e41
@@ -34,6 +34,8 @@
84cb84b
 #include "gdbcore.h"
84cb84b
 #include "target.h"
84cb84b
 #include "inferior.h"
9231e41
+#include "auxv.h"
84cb84b
+#include "command.h"
84cb84b
 
9231e41
 #include "gdb_assert.h"
9231e41
 
9231e41
@@ -254,7 +256,9 @@ static CORE_ADDR breakpoint_addr;	/* Add
84cb84b
 
84cb84b
 /* Local function prototypes */
84cb84b
 
84cb84b
+#if 0
84cb84b
 static int match_main (char *);
84cb84b
+#endif
84cb84b
 
84cb84b
 static CORE_ADDR bfd_lookup_symbol (bfd *, char *, flagword);
84cb84b
 
9231e41
@@ -376,22 +380,79 @@ elf_locate_base (void)
84cb84b
 {
84cb84b
   struct bfd_section *dyninfo_sect;
84cb84b
   int dyninfo_sect_size;
84cb84b
-  CORE_ADDR dyninfo_addr;
84cb84b
+  CORE_ADDR dyninfo_addr, relocated_dyninfo_addr, entry_addr;
9231e41
   gdb_byte *buf;
9231e41
   gdb_byte *bufend;
84cb84b
   int arch_size;
84cb84b
+  int ret;
84cb84b
+
84cb84b
+  /* Find the address of the entry point of the program from the
84cb84b
+     auxv vector.  */
84cb84b
+  ret = target_auxv_search (&current_target, AT_ENTRY, &entry_addr);
84cb84b
+
84cb84b
+  if (ret == 0 || ret == -1)
84cb84b
+    {
84cb84b
+      /* No auxv info, maybe an older kernel. Fake our way through.  */
84cb84b
+      entry_addr = bfd_get_start_address (exec_bfd); 
84cb84b
+
84cb84b
+      if (debug_solib)
84cb84b
+	fprintf_unfiltered (gdb_stdlog,
84cb84b
+			    "elf_locate_base: program entry address not found. Using bfd's 0x%s for %s\n",
84cb84b
+			    paddr_nz (entry_addr), exec_bfd->filename);
84cb84b
+    }
84cb84b
+  else
84cb84b
+    {
84cb84b
+      if (debug_solib)
84cb84b
+	fprintf_unfiltered (gdb_stdlog,
84cb84b
+			    "elf_locate_base: found program entry address 0x%s for %s\n",
84cb84b
+			    paddr_nz (entry_addr), exec_bfd->filename);
84cb84b
+    }
84cb84b
 
84cb84b
   /* Find the start address of the .dynamic section.  */
84cb84b
   dyninfo_sect = bfd_get_section_by_name (exec_bfd, ".dynamic");
84cb84b
   if (dyninfo_sect == NULL)
84cb84b
-    return 0;
84cb84b
+    { 
84cb84b
+      if (debug_solib)
84cb84b
+	fprintf_unfiltered (gdb_stdlog,
84cb84b
+			    "elf_locate_base: .dynamic section not found in %s -- return now\n",
84cb84b
+			    exec_bfd->filename);
84cb84b
+      return 0;
84cb84b
+    }
84cb84b
+  else
84cb84b
+    { 
84cb84b
+      if (debug_solib)
84cb84b
+	fprintf_unfiltered (gdb_stdlog,
84cb84b
+			    "elf_locate_base: .dynamic section found in %s\n",
84cb84b
+			    exec_bfd->filename);
84cb84b
+    }
84cb84b
+
84cb84b
   dyninfo_addr = bfd_section_vma (exec_bfd, dyninfo_sect);
84cb84b
+  if (debug_solib)
84cb84b
+    fprintf_unfiltered (gdb_stdlog,
84cb84b
+			"elf_locate_base: unrelocated .dynamic addr 0x%s\n",
84cb84b
+			paddr_nz (dyninfo_addr));
84cb84b
+
84cb84b
+  relocated_dyninfo_addr = dyninfo_addr
84cb84b
+    + entry_addr - bfd_get_start_address(exec_bfd);
84cb84b
+  if (debug_solib) 
84cb84b
+    fprintf_unfiltered (gdb_stdlog, 
84cb84b
+			"elf_locate_base: relocated .dyn addr 0x%s for %s\n",
84cb84b
+			paddr_nz(relocated_dyninfo_addr), exec_bfd->filename);
84cb84b
 
84cb84b
   /* Read in .dynamic section, silently ignore errors.  */
84cb84b
   dyninfo_sect_size = bfd_section_size (exec_bfd, dyninfo_sect);
84cb84b
   buf = alloca (dyninfo_sect_size);
84cb84b
-  if (target_read_memory (dyninfo_addr, buf, dyninfo_sect_size))
84cb84b
-    return 0;
84cb84b
+  if (debug_solib) 
84cb84b
+    fprintf_unfiltered (gdb_stdlog, 
84cb84b
+                        "elf_locate_base: read in .dynamic section\n");
84cb84b
+  if (target_read_memory (relocated_dyninfo_addr, buf, dyninfo_sect_size))
84cb84b
+    { 
84cb84b
+      if (debug_solib)
84cb84b
+	fprintf_unfiltered (gdb_stdlog,
84cb84b
+			    "elf_locate_base: couldn't read .dynamic section at 0x%s -- return now\n",
84cb84b
+			    paddr_nz (relocated_dyninfo_addr));
84cb84b
+      return 0;
84cb84b
+    }
84cb84b
 
84cb84b
   /* Find the DT_DEBUG entry in the the .dynamic section.
84cb84b
      For mips elf we look for DT_MIPS_RLD_MAP, mips elf apparently has
9231e41
@@ -418,6 +479,10 @@ elf_locate_base (void)
84cb84b
 	    {
84cb84b
 	      dyn_ptr = bfd_h_get_32 (exec_bfd, 
84cb84b
 				      (bfd_byte *) x_dynp->d_un.d_ptr);
84cb84b
+              if (debug_solib)
84cb84b
+                fprintf_unfiltered (gdb_stdlog,
84cb84b
+				    "elf_locate_base: DT_DEBUG entry has value 0x%s -- return now\n",
84cb84b
+				    paddr_nz (dyn_ptr));
84cb84b
 	      return dyn_ptr;
84cb84b
 	    }
84cb84b
 	  else if (dyn_tag == DT_MIPS_RLD_MAP)
9231e41
@@ -543,6 +608,10 @@ solib_svr4_r_map (void)
9231e41
 {
9231e41
   struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
84cb84b
 
84cb84b
+  if (debug_solib)
84cb84b
+    fprintf_unfiltered (gdb_stdlog, 
9231e41
+                        "solib_svr4_r_map: read at 0x%s\n",
84cb84b
+                        paddr_nz (debug_base + lmo->r_map_offset));
9231e41
   return read_memory_typed_address (debug_base + lmo->r_map_offset,
9231e41
 				    builtin_type_void_data_ptr);
9231e41
 }
9231e41
@@ -669,6 +738,11 @@ svr4_current_sos (void)
84cb84b
   struct so_list **link_ptr = &head;
9231e41
   CORE_ADDR ldsomap = 0;
9231e41
 
84cb84b
+  if (debug_solib)
84cb84b
+    fprintf_unfiltered (gdb_stdlog, 
84cb84b
+                        "svr4_current_sos: exec_bfd %s\n",
84cb84b
+                        exec_bfd->filename);
9231e41
+
84cb84b
   /* Make sure we've looked up the inferior's dynamic linker's base
84cb84b
      structure.  */
9231e41
   if (! debug_base)
9231e41
@@ -678,11 +752,21 @@ svr4_current_sos (void)
84cb84b
       /* If we can't find the dynamic linker's base structure, this
84cb84b
 	 must not be a dynamically linked executable.  Hmm.  */
84cb84b
       if (! debug_base)
84cb84b
-	return 0;
84cb84b
+	{
84cb84b
+	  if (debug_solib)
84cb84b
+	    fprintf_unfiltered (gdb_stdlog, 
84cb84b
+				"svr4_current_sos: no DT_DEBUG found in %s -- return now\n",
84cb84b
+				exec_bfd->filename);
84cb84b
+	  return 0;
84cb84b
+	}
84cb84b
     }
84cb84b
 
84cb84b
   /* Walk the inferior's link map list, and build our list of
84cb84b
      `struct so_list' nodes.  */
84cb84b
+  if (debug_solib)
84cb84b
+    fprintf_unfiltered (gdb_stdlog, 
84cb84b
+                        "svr4_current_sos: walk link map in %s\n",
84cb84b
+                        exec_bfd->filename);
9231e41
   lm = solib_svr4_r_map ();
84cb84b
   while (lm)
84cb84b
     {
9231e41
@@ -697,23 +781,103 @@ svr4_current_sos (void)
9231e41
       new->lm_info->lm = xzalloc (lmo->link_map_size);
84cb84b
       make_cleanup (xfree, new->lm_info->lm);
84cb84b
 
84cb84b
+      if (debug_solib)
84cb84b
+        fprintf_unfiltered (gdb_stdlog, 
84cb84b
+                            "svr4_current_sos: read lm at 0x%s\n", paddr_nz(lm));
84cb84b
       read_memory (lm, new->lm_info->lm, lmo->link_map_size);
84cb84b
 
84cb84b
       lm = LM_NEXT (new);
84cb84b
 
84cb84b
+      if (debug_solib)
84cb84b
+        fprintf_unfiltered (gdb_stdlog,
84cb84b
+                            "svr4_current_sos: is first link entry? %d\n",
84cb84b
+                            IGNORE_FIRST_LINK_MAP_ENTRY (new));
84cb84b
+
84cb84b
       /* For SVR4 versions, the first entry in the link map is for the
84cb84b
          inferior executable, so we must ignore it.  For some versions of
84cb84b
          SVR4, it has no name.  For others (Solaris 2.3 for example), it
84cb84b
          does have a name, so we can no longer use a missing name to
84cb84b
          decide when to ignore it. */
9231e41
       if (IGNORE_FIRST_LINK_MAP_ENTRY (new) && ldsomap == 0)
84cb84b
-	free_so (new);
84cb84b
+	{
84cb84b
+          /* It is the first link map entry, i.e. it is the main executable.  */
84cb84b
+
84cb84b
+	  if (bfd_get_start_address (exec_bfd) == entry_point_address ())
84cb84b
+	    {
84cb84b
+              /* Non-pie case, main executable has not been relocated.  */
84cb84b
+	      free_so (new);
84cb84b
+	    }
84cb84b
+	  else
84cb84b
+	    {
84cb84b
+              /* Pie case, main executable has been relocated.  */
84cb84b
+	      struct so_list *gdb_solib;
84cb84b
+
84cb84b
+	      if (debug_solib)
84cb84b
+		fprintf_unfiltered (gdb_stdlog,
84cb84b
+				    "svr4_current_sos: Processing first link map entry\n");
84cb84b
+	      strncpy (new->so_name, exec_bfd->filename,
84cb84b
+		       SO_NAME_MAX_PATH_SIZE - 1);
84cb84b
+	      new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
84cb84b
+	      strcpy (new->so_original_name, new->so_name);
84cb84b
+	      /*new->main = 1;*/
84cb84b
+	      new->main_relocated = 0;
84cb84b
+            
84cb84b
+	      if (debug_solib)
84cb84b
+		{ 
84cb84b
+		  fprintf_unfiltered (gdb_stdlog,
84cb84b
+				      "svr4_current_sos: Processing nameless DSO\n");
84cb84b
+		  fprintf_unfiltered (gdb_stdlog,
84cb84b
+				      "svr4_current_sos: adding name %s\n",
84cb84b
+				      new->so_name);
84cb84b
+		}
84cb84b
+
84cb84b
+	      for (gdb_solib = master_so_list ();
84cb84b
+                   gdb_solib;
84cb84b
+                   gdb_solib = gdb_solib->next)
84cb84b
+		{
84cb84b
+		  if (debug_solib)
84cb84b
+		    fprintf_unfiltered (gdb_stdlog,
84cb84b
+					"svr4_current_sos: compare gdb %s and new %s\n",
84cb84b
+					gdb_solib->so_name, new->so_name);
84cb84b
+		  if (strcmp (gdb_solib->so_name, new->so_name) == 0)
84cb84b
+		    if (gdb_solib->main_relocated)
84cb84b
+		      { 
84cb84b
+			if (debug_solib)
84cb84b
+			  fprintf_unfiltered (gdb_stdlog,
84cb84b
+					      "svr4_current_sos: found main relocated\n");
84cb84b
+			break;
84cb84b
+		      }
84cb84b
+		}
84cb84b
+
84cb84b
+	      if ((gdb_solib && !gdb_solib->main_relocated) || (!gdb_solib))
84cb84b
+		{
84cb84b
+		  add_to_target_sections (0 /*from_tty*/, &current_target, new);
84cb84b
+		  new->main = 1;
84cb84b
+		}
84cb84b
+
84cb84b
+	      /* We need this in the list of shared libs we return because
84cb84b
+		 solib_add_stub will loop through it and add the symbol file.  */
84cb84b
+	      new->next = 0;
84cb84b
+	      *link_ptr = new;
84cb84b
+	      link_ptr = &new->next; 
84cb84b
+	    }
84cb84b
+	} /* End of IGNORE_FIRST_LINK_MAP_ENTRY  */
84cb84b
       else
84cb84b
 	{
84cb84b
+          /* This is not the first link map entry, i.e. is not the main
84cb84b
+             executable.  Note however that it could be the DSO supplied on
84cb84b
+             certain systems (i.e. Linux 2.6) containing information about
84cb84b
+             the vsyscall page.  We must ignore such entry. This entry is 
84cb84b
+             nameless (just like the one for the main executable, sigh).  */
84cb84b
+
84cb84b
 	  int errcode;
84cb84b
 	  char *buffer;
84cb84b
 
84cb84b
 	  /* Extract this shared object's name.  */
84cb84b
+	  if (debug_solib)
84cb84b
+	    fprintf_unfiltered (gdb_stdlog, 
84cb84b
+                                "svr4_current_sos: read LM_NAME\n");
84cb84b
+
84cb84b
 	  target_read_string (LM_NAME (new), &buffer,
84cb84b
 			      SO_NAME_MAX_PATH_SIZE - 1, &errcode);
84cb84b
 	  if (errcode != 0)
9231e41
@@ -721,22 +885,37 @@ svr4_current_sos (void)
9231e41
 		     safe_strerror (errcode));
84cb84b
 	  else
84cb84b
 	    {
9231e41
-	      strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
9231e41
-	      new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
9231e41
-	      xfree (buffer);
9231e41
-	      strcpy (new->so_original_name, new->so_name);
9231e41
-	    }
9231e41
-
9231e41
-	  /* If this entry has no name, or its name matches the name
9231e41
-	     for the main executable, don't include it in the list.  */
9231e41
-	  if (! new->so_name[0]
9231e41
-	      || match_main (new->so_name))
9231e41
-	    free_so (new);
9231e41
-	  else
9231e41
-	    {
9231e41
-	      new->next = 0;
9231e41
-	      *link_ptr = new;
9231e41
-	      link_ptr = &new->next;
84cb84b
+              if (debug_solib)
84cb84b
+                fprintf_unfiltered (gdb_stdlog, 
84cb84b
+                                    "svr4_current_sos: LM_NAME is <%s>\n",
84cb84b
+                                    buffer);
84cb84b
+              /* The name could be empty, in which case it is the
84cb84b
+                 system supplied DSO.  */
84cb84b
+              if (strcmp (buffer, "") == 0)
9231e41
+		{
84cb84b
+                 xfree (buffer);
84cb84b
+                 free_so (new);
9231e41
+		}
84cb84b
+              else
84cb84b
+                {
9231e41
+		  strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
9231e41
+		  new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
9231e41
+		  xfree (buffer);
9231e41
+		  strcpy (new->so_original_name, new->so_name);
9231e41
+		  if (debug_solib)
9231e41
+		    {
9231e41
+		      fprintf_unfiltered (gdb_stdlog, 
9231e41
+					  "svr4_current_sos: Processing DSO: %s\n",
9231e41
+					  new->so_name);
9231e41
+		      fprintf_unfiltered (gdb_stdlog,
9231e41
+					  "svr4_current_sos: first link entry %d\n",
9231e41
+					  IGNORE_FIRST_LINK_MAP_ENTRY (new));
9231e41
+		    }
84cb84b
+
9231e41
+		  new->next = 0;
9231e41
+		  *link_ptr = new;
9231e41
+		  link_ptr = &new->next;
9231e41
+		}
9231e41
 	    }
84cb84b
 	}
84cb84b
 
9231e41
@@ -750,6 +929,11 @@ svr4_current_sos (void)
84cb84b
       discard_cleanups (old_chain);
84cb84b
     }
84cb84b
 
84cb84b
+  if (debug_solib)
84cb84b
+    fprintf_unfiltered (gdb_stdlog, 
84cb84b
+                        "svr4_current_sos: ENDS %s\n",
84cb84b
+                        exec_bfd->filename);
84cb84b
+
84cb84b
   return head;
84cb84b
 }
84cb84b
 
9231e41
@@ -826,7 +1010,7 @@ svr4_fetch_objfile_link_map (struct objf
84cb84b
 /* On some systems, the only way to recognize the link map entry for
84cb84b
    the main executable file is by looking at its name.  Return
84cb84b
    non-zero iff SONAME matches one of the known main executable names.  */
84cb84b
-
84cb84b
+#if 0
84cb84b
 static int
84cb84b
 match_main (char *soname)
84cb84b
 {
9231e41
@@ -840,6 +1024,7 @@ match_main (char *soname)
84cb84b
 
84cb84b
   return (0);
84cb84b
 }
84cb84b
+#endif
84cb84b
 
84cb84b
 /* Return 1 if PC lies in the dynamic symbol resolution code of the
84cb84b
    SVR4 run time loader.  */
9231e41
@@ -939,6 +1124,11 @@ enable_break (void)
84cb84b
   /* Find the .interp section; if not found, warn the user and drop
84cb84b
      into the old breakpoint at symbol code.  */
84cb84b
   interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
84cb84b
+
84cb84b
+  if (debug_solib)
84cb84b
+     fprintf_unfiltered (gdb_stdlog,
84cb84b
+                         "enable_break: search for .interp in %s\n",
84cb84b
+                         exec_bfd->filename);
84cb84b
   if (interp_sect)
84cb84b
     {
84cb84b
       unsigned int interp_sect_size;
9231e41
@@ -972,6 +1162,9 @@ enable_break (void)
84cb84b
       if (tmp_fd >= 0)
9231e41
 	tmp_bfd = bfd_fopen (tmp_pathname, gnutarget, FOPEN_RB, tmp_fd);
84cb84b
 
84cb84b
+      if (debug_solib)
84cb84b
+         fprintf_unfiltered (gdb_stdlog,
84cb84b
+                            "enable_break: opening %s\n", tmp_pathname);
84cb84b
       if (tmp_bfd == NULL)
84cb84b
 	goto bkpt_at_symbol;
84cb84b
 
9231e41
@@ -1052,6 +1245,9 @@ enable_break (void)
84cb84b
       if (sym_addr != 0)
84cb84b
 	{
84cb84b
 	  create_solib_event_breakpoint (load_addr + sym_addr);
84cb84b
+          if (debug_solib)
84cb84b
+            fprintf_unfiltered (gdb_stdlog,
84cb84b
+                               "enable_break: solib bp set\n");
84cb84b
 	  return 1;
84cb84b
 	}
84cb84b
 
9231e41
@@ -1311,6 +1507,8 @@ svr4_solib_create_inferior_hook (void)
84cb84b
   while (stop_signal != TARGET_SIGNAL_TRAP);
84cb84b
   stop_soon = NO_STOP_QUIETLY;
84cb84b
 #endif /* defined(_SCO_DS) */
84cb84b
+ 
84cb84b
+   disable_breakpoints_at_startup (1); 
84cb84b
 }
84cb84b
 
84cb84b
 static void
9231e41
@@ -1493,6 +1691,75 @@ svr4_lp64_fetch_link_map_offsets (void)
84cb84b
 
84cb84b
   return lmp;
84cb84b
 }
84cb84b
+void
84cb84b
+info_linkmap_command (char *cmd, int from_tty)
84cb84b
+{
84cb84b
+  CORE_ADDR lm;
84cb84b
+                                                                                
84cb84b
+  /* Make sure we've looked up the inferior's dynamic linker's base
84cb84b
+     structure.  */
84cb84b
+  if (! debug_base)
84cb84b
+    {
84cb84b
+      debug_base = locate_base ();
84cb84b
+                                                                                
84cb84b
+      /* If we can't find the dynamic linker's base structure, this
84cb84b
+         must not be a dynamically linked executable.  Hmm.  */
84cb84b
+      if (! debug_base)
84cb84b
+        {
84cb84b
+          if (debug_solib)
84cb84b
+            fprintf_unfiltered (gdb_stdlog,
84cb84b
+                                "svr4_print_linkmap: no DT_DEBUG found in %s -- return now\n",
84cb84b
+                                exec_bfd->filename);
84cb84b
+          return;
84cb84b
+        }
84cb84b
+    }
84cb84b
+                                                                                
84cb84b
+  /* Walk the inferior's link map list, and print the info.  */
84cb84b
+ 
9231e41
+  lm = solib_svr4_r_map ();
84cb84b
+  while (lm)
84cb84b
+    {
84cb84b
+      int errcode;
84cb84b
+      char *buffer;
84cb84b
+      CORE_ADDR load_addr;
84cb84b
+
9231e41
+      struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
84cb84b
+      struct so_list *new
84cb84b
+        = (struct so_list *) xmalloc (sizeof (struct so_list));
84cb84b
+      struct cleanup *old_chain = make_cleanup (xfree, new);
9231e41
+
84cb84b
+      memset (new, 0, sizeof (*new));
84cb84b
+
84cb84b
+      new->lm_info = xmalloc (sizeof (struct lm_info));
84cb84b
+      make_cleanup (xfree, new->lm_info);
9231e41
+
84cb84b
+      new->lm_info->lm = xmalloc (lmo->link_map_size);
84cb84b
+      make_cleanup (xfree, new->lm_info->lm);
84cb84b
+      memset (new->lm_info->lm, 0, lmo->link_map_size);
9231e41
+
84cb84b
+      if (debug_solib)
84cb84b
+        fprintf_unfiltered (gdb_stdlog,
84cb84b
+                            "svr4_print_linkmap: read lm at 0x%s\n", paddr_nz(lm));
84cb84b
+      read_memory (lm, new->lm_info->lm, lmo->link_map_size);
9231e41
+
84cb84b
+      lm = LM_NEXT (new);
9231e41
+
84cb84b
+      /* Load address.  */
9231e41
+      load_addr = LM_ADDR_CHECK (new, NULL);
84cb84b
+      /* Shared object's name.  */
84cb84b
+      target_read_string (LM_NAME (new), &buffer,
84cb84b
+			  SO_NAME_MAX_PATH_SIZE - 1, &errcode);
84cb84b
+      make_cleanup (xfree, buffer);
84cb84b
+      if (errcode != 0)
84cb84b
+	{
84cb84b
+	  warning ("svr4_print_linkmap: Can't read pathname for load map: %s\n",
84cb84b
+		   safe_strerror (errcode));
84cb84b
+	}
84cb84b
+      fprintf_filtered (gdb_stdout, "%-8s %-30s\n", paddr(load_addr), buffer);
84cb84b
+      do_cleanups (old_chain);
84cb84b
+    }
84cb84b
+}                                                                                
84cb84b
+
84cb84b
 
84cb84b
 
84cb84b
 static struct target_so_ops svr4_so_ops;
9231e41
@@ -1515,4 +1782,8 @@ _initialize_svr4_solib (void)
84cb84b
 
84cb84b
   /* FIXME: Don't do this here.  *_gdbarch_init() should set so_ops. */
84cb84b
   current_target_so_ops = &svr4_so_ops;
84cb84b
+
84cb84b
+  add_info ("linkmap", info_linkmap_command,
84cb84b
+            "Display the inferior's linkmap.");
84cb84b
+
84cb84b
 }
9231e41
Index: gdb-6.5/gdb/varobj.c
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/varobj.c	2006-07-11 02:47:06.000000000 -0300
9231e41
+++ gdb-6.5/gdb/varobj.c	2006-07-11 02:56:57.000000000 -0300
9231e41
@@ -870,6 +870,62 @@ varobj_list (struct varobj ***varlist)
84cb84b
   return rootcount;
84cb84b
 }
84cb84b
 
84cb84b
+void
84cb84b
+varobj_refresh (void)
84cb84b
+{
84cb84b
+  struct varobj *var;
84cb84b
+  struct varobj_root *croot;
84cb84b
+  int mycount = rootcount;
84cb84b
+  char * name;
9231e41
+
84cb84b
+  croot = rootlist;
84cb84b
+  while ((croot != NULL) && (mycount > 0))
84cb84b
+    {
84cb84b
+      var = croot->rootvar;
9231e41
+
84cb84b
+      /* Get rid of the memory for the old expression.  This also
84cb84b
+         leaves var->root->exp == NULL, which is ok for the parsing
84cb84b
+         below.  */
9231e41
+      free_current_contents (&var->root->exp);
9231e41
+
84cb84b
+      value_free (var->value);
84cb84b
+      var->type = NULL;
84cb84b
+
84cb84b
+      name = xstrdup (var->name);
84cb84b
+
84cb84b
+      /* Reparse the expression.  Wrap the call to parse expression,
84cb84b
+         so we can return a sensible error. */
84cb84b
+      if (!gdb_parse_exp_1 (&name, var->root->valid_block, 0, &var->root->exp))
84cb84b
+        {
84cb84b
+          return;
84cb84b
+        }
9231e41
+
84cb84b
+      /* We definitively need to catch errors here.
84cb84b
+         If evaluate_expression succeeds we got the value we wanted.
84cb84b
+         But if it fails, we still go on with a call to evaluate_type()  */
84cb84b
+      if (gdb_evaluate_expression (var->root->exp, &var->value))
84cb84b
+        {
84cb84b
+          /* no error */
84cb84b
+          release_value (var->value);
9231e41
+          if (value_lazy (var->value))
84cb84b
+            gdb_value_fetch_lazy (var->value);
84cb84b
+        }
84cb84b
+      else
84cb84b
+        var->value = evaluate_type (var->root->exp);
9231e41
+
9231e41
+      var->type = value_type (var->value);
9231e41
+
84cb84b
+      mycount--;
84cb84b
+      croot = croot->next;
84cb84b
+    }
9231e41
+
84cb84b
+  if (mycount || (croot != NULL))
84cb84b
+    warning
84cb84b
+      ("varobj_refresh: assertion failed - wrong tally of root vars (%d:%d)",
84cb84b
+       rootcount, mycount);
84cb84b
+}
9231e41
+
84cb84b
+
84cb84b
 /* Update the values for a variable and its children.  This is a
84cb84b
    two-pronged attack.  First, re-parse the value for the root's
84cb84b
    expression to see if it's changed.  Then go all the way
9231e41
Index: gdb-6.5/gdb/solist.h
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/solist.h	2006-07-11 02:47:06.000000000 -0300
9231e41
+++ gdb-6.5/gdb/solist.h	2006-07-11 02:47:11.000000000 -0300
84cb84b
@@ -62,6 +62,8 @@ struct so_list
84cb84b
     bfd *abfd;
84cb84b
     char symbols_loaded;	/* flag: symbols read in yet? */
84cb84b
     char from_tty;		/* flag: print msgs? */
84cb84b
+    char main;                  /* flag: is this the main executable? */
84cb84b
+    char main_relocated;        /* flag: has it been relocated yet? */
84cb84b
     struct objfile *objfile;	/* objfile for loaded lib */
84cb84b
     struct section_table *sections;
84cb84b
     struct section_table *sections_end;
84cb84b
@@ -113,9 +115,15 @@ void free_so (struct so_list *so);
84cb84b
 /* Return address of first so_list entry in master shared object list.  */
84cb84b
 struct so_list *master_so_list (void);
84cb84b
 
84cb84b
+/* Return address of first so_list entry in master shared object list.  */
84cb84b
+struct so_list *master_so_list (void);
84cb84b
+
84cb84b
 /* Find solib binary file and open it.  */
84cb84b
 extern int solib_open (char *in_pathname, char **found_pathname);
84cb84b
 
84cb84b
+/* Add the list of sections in so_list to the target to_sections.  */
84cb84b
+extern void add_to_target_sections (int, struct target_ops *, struct so_list *);
84cb84b
+
84cb84b
 /* FIXME: gdbarch needs to control this variable */
84cb84b
 extern struct target_so_ops *current_target_so_ops;
84cb84b
 
9231e41
@@ -126,4 +134,6 @@ extern struct target_so_ops *current_tar
9231e41
 #define TARGET_SO_IN_DYNSYM_RESOLVE_CODE \
9231e41
   (current_target_so_ops->in_dynsym_resolve_code)
84cb84b
 
84cb84b
+/* Controls the printing of debugging output.  */
84cb84b
+extern int debug_solib;
84cb84b
 #endif
9231e41
Index: gdb-6.5/gdb/varobj.h
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/varobj.h	2006-07-11 02:47:06.000000000 -0300
9231e41
+++ gdb-6.5/gdb/varobj.h	2006-07-11 02:47:11.000000000 -0300
9231e41
@@ -99,4 +99,6 @@ extern int varobj_list (struct varobj **
84cb84b
 
84cb84b
 extern int varobj_update (struct varobj **varp, struct varobj ***changelist);
84cb84b
 
84cb84b
+extern void varobj_refresh(void);
84cb84b
+
84cb84b
 #endif /* VAROBJ_H */
9231e41
Index: gdb-6.5/gdb/symfile.c
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/symfile.c	2006-07-11 02:47:06.000000000 -0300
9231e41
+++ gdb-6.5/gdb/symfile.c	2006-07-11 02:56:57.000000000 -0300
9231e41
@@ -49,6 +49,7 @@
84cb84b
 #include "readline/readline.h"
84cb84b
 #include "gdb_assert.h"
84cb84b
 #include "block.h"
84cb84b
+#include "varobj.h"
9231e41
 #include "observer.h"
9231e41
 #include "exec.h"
84cb84b
 
9231e41
@@ -658,7 +659,7 @@ syms_from_objfile (struct objfile *objfi
84cb84b
 
84cb84b
   /* Now either addrs or offsets is non-zero.  */
84cb84b
 
84cb84b
-  if (mainline)
84cb84b
+  if (mainline == 1)
84cb84b
     {
84cb84b
       /* We will modify the main symbol table, make sure that all its users
84cb84b
          will be cleaned up if an error occurs during symbol reading.  */
9231e41
@@ -686,7 +687,7 @@ syms_from_objfile (struct objfile *objfi
84cb84b
 
84cb84b
      We no longer warn if the lowest section is not a text segment (as
84cb84b
      happens for the PA64 port.  */
84cb84b
-  if (!mainline && addrs && addrs->other[0].name)
84cb84b
+  if (/*!mainline &&*/ addrs && addrs->other[0].name)
84cb84b
     {
84cb84b
       asection *lower_sect;
84cb84b
       asection *sect;
9231e41
@@ -855,17 +856,21 @@ new_symfile_objfile (struct objfile *obj
84cb84b
   /* If this is the main symbol file we have to clean up all users of the
84cb84b
      old main symbol file. Otherwise it is sufficient to fixup all the
84cb84b
      breakpoints that may have been redefined by this symbol file.  */
84cb84b
-  if (mainline)
84cb84b
+  if (mainline == 1)
84cb84b
     {
84cb84b
       /* OK, make it the "real" symbol file.  */
84cb84b
       symfile_objfile = objfile;
84cb84b
 
84cb84b
       clear_symtab_users ();
84cb84b
     }
84cb84b
-  else
84cb84b
+  else if (mainline == 0)
84cb84b
     {
84cb84b
       breakpoint_re_set ();
84cb84b
     }
84cb84b
+  else
84cb84b
+    {
84cb84b
+      /* Don't reset breakpoints or it will screw up PIE.  */
84cb84b
+    }
84cb84b
 
84cb84b
   /* We're done reading the symbol file; finish off complaints.  */
84cb84b
   clear_complaints (&symfile_complaints, 0, verbo);
9231e41
@@ -908,7 +913,7 @@ symbol_file_add_with_addrs_or_offsets (b
84cb84b
      interactively wiping out any existing symbols.  */
84cb84b
 
84cb84b
   if ((have_full_symbols () || have_partial_symbols ())
84cb84b
-      && mainline
84cb84b
+      && (mainline == 1)
84cb84b
       && from_tty
84cb84b
       && !query ("Load new symbol table from \"%s\"? ", name))
9231e41
     error (_("Not confirmed."));
9231e41
@@ -1089,6 +1094,10 @@ symbol_file_clear (int from_tty)
9231e41
 		    symfile_objfile->name)
9231e41
 	  : !query (_("Discard symbol table? "))))
9231e41
     error (_("Not confirmed."));
84cb84b
+#ifdef CLEAR_SOLIB
84cb84b
+      CLEAR_SOLIB ();
84cb84b
+#endif
84cb84b
+
84cb84b
     free_all_objfiles ();
84cb84b
 
84cb84b
     /* solib descriptors may have handles to objfiles.  Since their
9231e41
@@ -2154,6 +2163,8 @@ reread_symbols (void)
84cb84b
 	      /* Discard cleanups as symbol reading was successful.  */
84cb84b
 	      discard_cleanups (old_cleanups);
84cb84b
 
84cb84b
+	      init_entry_point_info (objfile);
84cb84b
+
84cb84b
 	      /* If the mtime has changed between the time we set new_modtime
84cb84b
 	         and now, we *want* this to be out of date, so don't call stat
84cb84b
 	         again now.  */
9231e41
@@ -2529,6 +2540,7 @@ clear_symtab_users (void)
84cb84b
   clear_pc_function_cache ();
84cb84b
   if (deprecated_target_new_objfile_hook)
84cb84b
     deprecated_target_new_objfile_hook (NULL);
84cb84b
+  varobj_refresh ();
84cb84b
 }
84cb84b
 
84cb84b
 static void
9231e41
Index: gdb-6.5/gdb/breakpoint.c
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/breakpoint.c	2006-07-11 02:47:11.000000000 -0300
9231e41
+++ gdb-6.5/gdb/breakpoint.c	2006-07-11 02:56:59.000000000 -0300
9231e41
@@ -782,15 +782,15 @@ insert_watchpoints_for_new_thread (ptid_
9231e41
 	  struct value *v = b->owner->val_chain;
9231e41
 
9231e41
 	  /* Look at each value on the value chain.  */
9231e41
-	  for (; v; v = v->next)
9231e41
+	  for (; v; v = value_next (v))
9231e41
 	    {
9231e41
 	      /* If it's a memory location, and GDB actually needed
9231e41
 		 its contents to evaluate the expression, then we
9231e41
 		 must watch it.  */
9231e41
 	      if (VALUE_LVAL (v) == lval_memory
9231e41
-		  && ! VALUE_LAZY (v))
9231e41
+		  && ! value_lazy (v))
9231e41
 		{
9231e41
-		  struct type *vtype = check_typedef (VALUE_TYPE (v));
9231e41
+		  struct type *vtype = check_typedef (value_type (v));
9231e41
 		  
9231e41
 		  /* We only watch structs and arrays if user asked
9231e41
 		     for it explicitly, never if they just happen to
9231e41
@@ -802,8 +802,8 @@ insert_watchpoints_for_new_thread (ptid_
9231e41
 		      CORE_ADDR addr;
9231e41
 		      int len, type;
9231e41
 		      
9231e41
-		      addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
9231e41
-		      len = TYPE_LENGTH (VALUE_TYPE (v));
9231e41
+		      addr = VALUE_ADDRESS (v) + value_offset (v);
9231e41
+		      len = TYPE_LENGTH (value_type (v));
9231e41
 		      type = hw_write;
9231e41
 		      if (b->owner->type == bp_read_watchpoint)
9231e41
 			type = hw_read;
9231e41
@@ -2680,12 +2680,12 @@ mark_triggered_watchpoints (CORE_ADDR st
9231e41
 	|| b->type == bp_read_watchpoint
9231e41
 	|| b->type == bp_access_watchpoint)
9231e41
       {
9231e41
-	for (v = b->val_chain; v; v = v->next)
9231e41
+	for (v = b->val_chain; v; v = value_next (v))
9231e41
 	  {
9231e41
 	    if (VALUE_LVAL (v) == lval_memory
9231e41
-	        && ! VALUE_LAZY (v))
9231e41
+	        && ! value_lazy (v))
9231e41
 	      {
9231e41
-	        struct type *vtype = check_typedef (VALUE_TYPE (v));
9231e41
+	        struct type *vtype = check_typedef (value_type (v));
9231e41
 		    
9231e41
 		if (v == b->val_chain
9231e41
 		    || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
9231e41
@@ -2693,11 +2693,11 @@ mark_triggered_watchpoints (CORE_ADDR st
9231e41
 		  {
9231e41
 		    CORE_ADDR vaddr;
9231e41
 			
9231e41
-		    vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
9231e41
+		    vaddr = VALUE_ADDRESS (v) + value_offset (v);
9231e41
 		    /* Exact match not required.  Within range is
9231e41
 		       sufficient.  */
9231e41
 		    if (addr >= vaddr &&
9231e41
-		        addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
9231e41
+		        addr < vaddr + TYPE_LENGTH (value_type (v)))
9231e41
 		      b->watchpoint_triggered = 1;
9231e41
 		  }
9231e41
 	      }
9231e41
@@ -2867,12 +2867,12 @@ bpstat_stop_status (CORE_ADDR bp_addr, p
9231e41
 		bs->stop = 0;
9231e41
 		continue;
9231e41
 	      }
9231e41
-	    for (v = b->val_chain; v; v = v->next)
9231e41
+	    for (v = b->val_chain; v; v = value_next (v))
9231e41
 	      {
9231e41
 		if (VALUE_LVAL (v) == lval_memory
9231e41
-		    && ! VALUE_LAZY (v))
9231e41
+		    && ! value_lazy (v))
9231e41
 		  {
9231e41
-		    struct type *vtype = check_typedef (VALUE_TYPE (v));
9231e41
+		    struct type *vtype = check_typedef (value_type (v));
9231e41
 		    
9231e41
 		    if (v == b->val_chain
9231e41
 			|| (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
9231e41
@@ -2880,11 +2880,11 @@ bpstat_stop_status (CORE_ADDR bp_addr, p
9231e41
 		      {
9231e41
 			CORE_ADDR vaddr;
9231e41
 			
9231e41
-			vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
9231e41
+			vaddr = VALUE_ADDRESS (v) + value_offset (v);
9231e41
 			/* Exact match not required.  Within range is
9231e41
 			   sufficient.  */
9231e41
 			if (addr >= vaddr &&
9231e41
-			    addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
9231e41
+			    addr < vaddr + TYPE_LENGTH (value_type (v)))
9231e41
 			  must_check_value = 1;
9231e41
 		      }
9231e41
 		  }
9231e41
@@ -3931,6 +3931,7 @@ describe_other_breakpoints (CORE_ADDR pc
84cb84b
 			       b->number,
84cb84b
 			       ((b->enable_state == bp_disabled || 
84cb84b
 				 b->enable_state == bp_shlib_disabled || 
84cb84b
+				 b->enable_state == bp_startup_disabled || 
84cb84b
 				 b->enable_state == bp_call_disabled) 
84cb84b
 				? " (disabled)" 
84cb84b
 				: b->enable_state == bp_permanent 
9231e41
@@ -4609,6 +4610,62 @@ re_enable_breakpoints_in_shlibs (void)
9231e41
   }
9231e41
 }
84cb84b
 
84cb84b
+void
84cb84b
+disable_breakpoints_at_startup (int silent)
84cb84b
+{
84cb84b
+  struct breakpoint *b;
84cb84b
+  int disabled_startup_breaks = 0;
84cb84b
+
84cb84b
+  if (bfd_get_start_address (exec_bfd) != entry_point_address ())
84cb84b
+    {
84cb84b
+      ALL_BREAKPOINTS (b)
84cb84b
+	{
84cb84b
+	  if (((b->type == bp_breakpoint) ||
84cb84b
+	       (b->type == bp_hardware_breakpoint)) &&
84cb84b
+	      b->enable_state == bp_enabled &&
84cb84b
+	      !b->loc->duplicate)
84cb84b
+	    {
84cb84b
+	      b->enable_state = bp_startup_disabled;
84cb84b
+	      if (!silent)
84cb84b
+		{
84cb84b
+		  if (!disabled_startup_breaks)
84cb84b
+		    {
84cb84b
+		      target_terminal_ours_for_output ();
84cb84b
+		      warning ("Temporarily disabling breakpoints:");
84cb84b
+		    }
84cb84b
+		  disabled_startup_breaks = 1;
84cb84b
+		  warning ("breakpoint #%d addr 0x%s", b->number, paddr_nz(b->loc->address));
84cb84b
+		}
84cb84b
+	    }
84cb84b
+	}
84cb84b
+    }
84cb84b
+}
84cb84b
+
84cb84b
+/* Try to reenable any breakpoints after startup.  */
84cb84b
+void
84cb84b
+re_enable_breakpoints_at_startup (void)
84cb84b
+{
84cb84b
+  struct breakpoint *b;
84cb84b
+
84cb84b
+  if (bfd_get_start_address (exec_bfd) != entry_point_address ())
84cb84b
+    {
84cb84b
+      ALL_BREAKPOINTS (b)
84cb84b
+	if (b->enable_state == bp_startup_disabled)
84cb84b
+	  {
84cb84b
+	    char buf[1];
84cb84b
+
84cb84b
+	    /* Do not reenable the breakpoint if the shared library
84cb84b
+	       is still not mapped in.  */
84cb84b
+	    if (target_read_memory (b->loc->address, buf, 1) == 0)
84cb84b
+	      {
84cb84b
+		/*printf ("enabling breakpoint at 0x%s\n", paddr_nz(b->loc->address));*/
84cb84b
+		b->enable_state = bp_enabled;
84cb84b
+	      }
84cb84b
+	  }
84cb84b
+    }
84cb84b
+}
84cb84b
+
84cb84b
+
84cb84b
 static void
84cb84b
 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
84cb84b
 		     char *cond_string, enum bptype bp_kind)
9231e41
@@ -6955,6 +7012,7 @@ delete_breakpoint (struct breakpoint *bp
84cb84b
 	    && !b->loc->duplicate
84cb84b
 	    && b->enable_state != bp_disabled
84cb84b
 	    && b->enable_state != bp_shlib_disabled
84cb84b
+	    && b->enable_state != bp_startup_disabled
84cb84b
 	    && !b->pending
84cb84b
 	    && b->enable_state != bp_call_disabled)
84cb84b
 	{
9231e41
@@ -7170,7 +7228,8 @@ breakpoint_re_set_one (void *bint)
84cb84b
 	break;
84cb84b
 
84cb84b
       save_enable = b->enable_state;
84cb84b
-      if (b->enable_state != bp_shlib_disabled)
84cb84b
+      if (b->enable_state != bp_shlib_disabled
84cb84b
+          || b->enable_state != bp_shlib_disabled)
84cb84b
         b->enable_state = bp_disabled;
84cb84b
       else
84cb84b
 	/* If resetting a shlib-disabled breakpoint, we don't want to
9231e41
Index: gdb-6.5/gdb/solib.c
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/solib.c	2006-07-11 02:47:06.000000000 -0300
9231e41
+++ gdb-6.5/gdb/solib.c	2006-07-11 02:47:11.000000000 -0300
9231e41
@@ -72,6 +72,8 @@ solib_ops (struct gdbarch *gdbarch)
84cb84b
 
84cb84b
 /* external data declarations */
84cb84b
 
84cb84b
+int debug_solib;
84cb84b
+
84cb84b
 /* FIXME: gdbarch needs to control this variable */
84cb84b
 struct target_so_ops *current_target_so_ops;
84cb84b
 
9231e41
@@ -102,6 +104,8 @@ The search path for loading non-absolute
9231e41
 		    value);
9231e41
 }
84cb84b
 
84cb84b
+void add_to_target_sections (int, struct target_ops *, struct so_list *);
84cb84b
+
84cb84b
 /*
84cb84b
 
84cb84b
    GLOBAL FUNCTION
9231e41
@@ -372,7 +376,6 @@ free_so (struct so_list *so)
84cb84b
   xfree (so);
84cb84b
 }
84cb84b
 
84cb84b
-
84cb84b
 /* Return address of first so_list entry in master shared object list.  */
84cb84b
 struct so_list *
84cb84b
 master_so_list (void)
9231e41
@@ -380,7 +383,6 @@ master_so_list (void)
84cb84b
   return so_list_head;
84cb84b
 }
84cb84b
 
84cb84b
-
84cb84b
 /* A small stub to get us past the arg-passing pinhole of catch_errors.  */
84cb84b
 
84cb84b
 static int
9231e41
@@ -392,15 +394,40 @@ symbol_add_stub (void *arg)
84cb84b
   /* Have we already loaded this shared object?  */
84cb84b
   ALL_OBJFILES (so->objfile)
84cb84b
     {
84cb84b
-      if (strcmp (so->objfile->name, so->so_name) == 0)
84cb84b
+      /* Found an already loaded shared library.  */
84cb84b
+      if (strcmp (so->objfile->name, so->so_name) == 0
84cb84b
+          && !so->main)
84cb84b
 	return 1;
84cb84b
+      /* Found an already loaded main executable.  This could happen in
84cb84b
+         two circumstances. 
84cb84b
+         First case: the main file has already been read in
84cb84b
+         as the first thing that gdb does at startup, and the file
84cb84b
+         hasn't been relocated properly yet. Therefor we need to read
84cb84b
+         it in with the proper section info.
84cb84b
+         Second case: it has been read in with the correct relocation,
84cb84b
+         and therefore we need to skip it.  */
84cb84b
+      if (strcmp (so->objfile->name, so->so_name) == 0 
84cb84b
+          && so->main
84cb84b
+          && so->main_relocated)
84cb84b
+        return 1;
84cb84b
     }
84cb84b
 
84cb84b
   sap = build_section_addr_info_from_section_table (so->sections,
84cb84b
                                                     so->sections_end);
84cb84b
 
84cb84b
-  so->objfile = symbol_file_add (so->so_name, so->from_tty,
84cb84b
-				 sap, 0, OBJF_SHARED);
84cb84b
+  if (so->main)
84cb84b
+    {
84cb84b
+      if (debug_solib)
84cb84b
+        fprintf_unfiltered (gdb_stdlog,
84cb84b
+			    "symbol_add_stub: adding symbols for main\n");
84cb84b
+      so->objfile = symbol_file_add (so->so_name, /*so->from_tty*/ 0,
84cb84b
+   				     sap, 1, 0);
84cb84b
+      so->main_relocated = 1;
84cb84b
+    }
84cb84b
+  else
84cb84b
+    so->objfile = symbol_file_add (so->so_name, so->from_tty,
84cb84b
+				   sap, 0, OBJF_SHARED);
84cb84b
+
84cb84b
   free_section_addr_info (sap);
84cb84b
 
84cb84b
   return (1);
9231e41
@@ -523,6 +550,10 @@ update_solib_list (int from_tty, struct 
84cb84b
 	 the inferior's current list.  */
84cb84b
       while (i)
84cb84b
 	{
84cb84b
+          if (debug_solib)
84cb84b
+            fprintf_unfiltered (gdb_stdlog,
84cb84b
+                                "update_solib_list: compare gdb:%s and inferior:%s\n",
84cb84b
+                                gdb->so_original_name, i->so_original_name);
84cb84b
 	  if (! strcmp (gdb->so_original_name, i->so_original_name))
84cb84b
 	    break;
84cb84b
 
9231e41
@@ -576,28 +607,7 @@ update_solib_list (int from_tty, struct 
84cb84b
       /* Fill in the rest of each of the `struct so_list' nodes.  */
84cb84b
       for (i = inferior; i; i = i->next)
84cb84b
 	{
84cb84b
-	  i->from_tty = from_tty;
84cb84b
-
84cb84b
-	  /* Fill in the rest of the `struct so_list' node.  */
84cb84b
-	  catch_errors (solib_map_sections, i,
84cb84b
-			"Error while mapping shared library sections:\n",
84cb84b
-			RETURN_MASK_ALL);
84cb84b
-
84cb84b
-	  /* If requested, add the shared object's sections to the TARGET's
84cb84b
-	     section table.  Do this immediately after mapping the object so
84cb84b
-	     that later nodes in the list can query this object, as is needed
84cb84b
-	     in solib-osf.c.  */
84cb84b
-	  if (target)
84cb84b
-	    {
84cb84b
-	      int count = (i->sections_end - i->sections);
84cb84b
-	      if (count > 0)
84cb84b
-		{
84cb84b
-		  int space = target_resize_to_sections (target, count);
84cb84b
-		  memcpy (target->to_sections + space,
84cb84b
-			  i->sections,
84cb84b
-			  count * sizeof (i->sections[0]));
84cb84b
-		}
84cb84b
-	    }
84cb84b
+   	  add_to_target_sections (from_tty, target, i);
9231e41
 
9231e41
 	  /* Notify any observer that the shared object has been
9231e41
              loaded now that we've added it to GDB's tables.  */
9231e41
@@ -606,6 +616,41 @@ update_solib_list (int from_tty, struct 
84cb84b
     }
84cb84b
 }
84cb84b
 
84cb84b
+void
84cb84b
+add_to_target_sections (int from_tty, struct target_ops *target, struct so_list *solib)
84cb84b
+{
84cb84b
+  /* If this is set, then the sections have been already added to the
84cb84b
+     target list.  */
84cb84b
+  if (solib->main)
84cb84b
+    return;
84cb84b
+
84cb84b
+  solib->from_tty = from_tty;
84cb84b
+
84cb84b
+  /* Fill in the rest of the `struct so_list' node.  */
84cb84b
+  catch_errors (solib_map_sections, solib,
84cb84b
+		"Error while mapping shared library sections:\n",
84cb84b
+		RETURN_MASK_ALL);
84cb84b
+
84cb84b
+  /* If requested, add the shared object's sections to the TARGET's
84cb84b
+     section table.  Do this immediately after mapping the object so
84cb84b
+     that later nodes in the list can query this object, as is needed
84cb84b
+     in solib-osf.c.  */
84cb84b
+  if (target)
84cb84b
+    {
84cb84b
+      int count = (solib->sections_end - solib->sections);
84cb84b
+      if (count > 0)
84cb84b
+	{
84cb84b
+	  int space = target_resize_to_sections (target, count);
84cb84b
+          if (debug_solib)
84cb84b
+             fprintf_unfiltered (gdb_stdlog,
84cb84b
+                                 "add_to_target_sections: add %s to to_sections\n",
84cb84b
+                                 solib->so_original_name);
84cb84b
+	  memcpy (target->to_sections + space,
84cb84b
+		  solib->sections,
84cb84b
+		  count * sizeof (solib->sections[0]));
84cb84b
+	}
84cb84b
+    }
84cb84b
+}
84cb84b
 
84cb84b
 /* GLOBAL FUNCTION
84cb84b
 
9231e41
@@ -978,4 +1023,12 @@ This takes precedence over the environme
9231e41
 				     reload_shared_libraries,
9231e41
 				     show_solib_search_path,
9231e41
 				     &setlist, &showlist);
84cb84b
+
9231e41
+  add_setshow_boolean_cmd ("solib", no_class, &debug_solib,
9231e41
+			   _("\
9231e41
+Set debugging of GNU/Linux shlib module.\n"), _("\
9231e41
+Show debugging status of GNU/Linux shlib module.\n"), _("\
9231e41
+Enables printf debugging output of GNU/Linux shlib module.\n"),
9231e41
+			   NULL, NULL,
9231e41
+			   &setdebuglist, &showdebuglist);
84cb84b
 }
9231e41
Index: gdb-6.5/gdb/elfread.c
9231e41
===================================================================
9231e41
--- gdb-6.5.orig/gdb/elfread.c	2006-07-11 02:47:06.000000000 -0300
9231e41
+++ gdb-6.5/gdb/elfread.c	2006-07-11 02:47:11.000000000 -0300
9231e41
@@ -556,7 +556,7 @@ elf_symfile_read (struct objfile *objfil
84cb84b
   /* If we are reinitializing, or if we have never loaded syms yet,
84cb84b
      set table to empty.  MAINLINE is cleared so that *_read_psymtab
84cb84b
      functions do not all also re-initialize the psymbol table. */
84cb84b
-  if (mainline)
84cb84b
+  if (mainline == 1)
84cb84b
     {
84cb84b
       init_psymbol_list (objfile, 0);
84cb84b
       mainline = 0;