*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / exec.c
index 4358aca52a1718d564a513bfa9b4e160fa3e89d9..89511bd296d1c2a2dec29b515d73fa259661707f 100644 (file)
@@ -1,7 +1,7 @@
 /* Work with executable files, for GDB. 
 
    Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-   1998, 1999, 2000, 2001, 2002, 2003, 2007, 2008, 2009
+   1998, 1999, 2000, 2001, 2002, 2003, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -101,9 +101,7 @@ exec_close (void)
       bfd *abfd = exec_bfd;
       char *name = bfd_get_filename (abfd);
 
-      if (!bfd_close (abfd))
-       warning (_("cannot close \"%s\": %s"),
-                name, bfd_errmsg (bfd_get_error ()));
+      gdb_bfd_close_or_warn (abfd);
       xfree (name);
 
       /* Removing target sections may close the exec_ops target.
@@ -141,16 +139,8 @@ exec_close_1 (int quitting)
        }
       else if (vp->bfd != exec_bfd)
        /* FIXME-leak: We should be freeing vp->name too, I think.  */
-       if (!bfd_close (vp->bfd))
-         warning (_("cannot close \"%s\": %s"),
-                  vp->name, bfd_errmsg (bfd_get_error ()));
-
-      /* FIXME: This routine is #if 0'd in symfile.c.  What should we
-         be doing here?  Should we just free everything in
-         vp->objfile->symtabs?  Should free_objfile do that?
-         FIXME-as-well: free_objfile already free'd vp->name, so it isn't
-         valid here.  */
-      free_named_symtabs (vp->name);
+       gdb_bfd_close_or_warn (vp->bfd);
+
       xfree (vp);
     }
 
@@ -225,6 +215,7 @@ exec_file_attach (char *filename, int from_tty)
       char *scratch_pathname;
       int scratch_chan;
       struct target_section *sections = NULL, *sections_end = NULL;
+      char **matching;
 
       scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename,
                   write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY,
@@ -259,13 +250,14 @@ exec_file_attach (char *filename, int from_tty)
       scratch_pathname = xstrdup (scratch_pathname);
       cleanups = make_cleanup (xfree, scratch_pathname);
 
-      if (!bfd_check_format (exec_bfd, bfd_object))
+      if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
        {
          /* Make sure to close exec_bfd, or else "run" might try to use
             it.  */
          exec_close ();
          error (_("\"%s\": not in executable format: %s"),
-                scratch_pathname, bfd_errmsg (bfd_get_error ()));
+                scratch_pathname,
+                gdb_bfd_errmsg (bfd_get_error (), matching));
        }
 
       /* FIXME - This should only be run for RS6000, but the ifdef is a poor
@@ -674,8 +666,34 @@ print_section_info (struct target_section_table *t, bfd *abfd)
   wrap_here ("        ");
   printf_filtered (_("file type %s.\n"), bfd_get_target (abfd));
   if (abfd == exec_bfd)
-    printf_filtered (_("\tEntry point: %s\n"),
-                     paddress (gdbarch, bfd_get_start_address (abfd)));
+    {
+      /* gcc-3.4 does not like the initialization in <p == t->sections_end>.  */
+      bfd_vma displacement = 0;
+
+      for (p = t->sections; p < t->sections_end; p++)
+       {
+         asection *asect = p->the_bfd_section;
+
+         if ((bfd_get_section_flags (abfd, asect) & (SEC_ALLOC | SEC_LOAD))
+             != (SEC_ALLOC | SEC_LOAD))
+           continue;
+
+         if (bfd_get_section_vma (abfd, asect) <= abfd->start_address
+             && abfd->start_address < (bfd_get_section_vma (abfd, asect)
+                                       + bfd_get_section_size (asect)))
+           {
+             displacement = p->addr - bfd_get_section_vma (abfd, asect);
+             break;
+           }
+       }
+      if (p == t->sections_end)
+       warning (_("Cannot find section for the entry point of %s.\n"),
+                bfd_get_filename (abfd));
+
+      printf_filtered (_("\tEntry point: %s\n"),
+                      paddress (gdbarch, (bfd_get_start_address (abfd)
+                                          + displacement)));
+    }
   for (p = t->sections; p < t->sections_end; p++)
     {
       printf_filtered ("\t%s", hex_string_custom (p->addr, wid));
This page took 0.028935 seconds and 4 git commands to generate.