*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / solib-dsbt.c
index 256939519f78b9bebbbbaddcba43b597504f10b2..fcc01a8f8659161eec20b5c92197c83a28bfb2a9 100644 (file)
@@ -1,5 +1,5 @@
 /* Handle TIC6X (DSBT) shared libraries for GDB, the GNU Debugger.
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2010-2012 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -30,6 +30,7 @@
 #include "gdbcmd.h"
 #include "elf-bfd.h"
 #include "exceptions.h"
+#include "gdb_bfd.h"
 
 #define GOT_MODULE_OFFSET 4
 
@@ -232,7 +233,7 @@ decode_loadmap (gdb_byte *buf)
   struct int_elf32_dsbt_loadmap *int_ldmbuf;
 
   int version, seg, nsegs;
-  int ext_ldmbuf_size, int_ldmbuf_size;
+  int int_ldmbuf_size;
 
   ext_ldmbuf = (struct ext_elf32_dsbt_loadmap *) buf;
 
@@ -508,76 +509,6 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
   return 0;
 }
 
-/* An expensive way to lookup the value of a single symbol for
-   bfd's that are only temporary anyway.  This is used by the
-   shared library support to find the address of the debugger
-   interface structures in the shared library.
-
-   Note that 0 is specifically allowed as an error return (no
-   such symbol).  */
-
-static CORE_ADDR
-bfd_lookup_symbol (bfd *abfd, char *symname)
-{
-  long storage_needed;
-  asymbol *sym;
-  asymbol **symbol_table;
-  unsigned int number_of_symbols;
-  unsigned int i;
-  struct cleanup *back_to;
-  CORE_ADDR symaddr = 0;
-
-  storage_needed = bfd_get_symtab_upper_bound (abfd);
-
-  if (storage_needed > 0)
-    {
-      symbol_table = (asymbol **) xmalloc (storage_needed);
-      back_to = make_cleanup (xfree, symbol_table);
-      number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
-
-      for (i = 0; i < number_of_symbols; i++)
-       {
-         sym = *symbol_table++;
-         if (strcmp (sym->name, symname) == 0)
-           {
-             /* Bfd symbols are section relative. */
-             symaddr = sym->value + sym->section->vma;
-             break;
-           }
-       }
-      do_cleanups (back_to);
-    }
-
-  if (symaddr)
-    return symaddr;
-
-  /* Look for the symbol in the dynamic string table too.  */
-
-  storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
-
-  if (storage_needed > 0)
-    {
-      symbol_table = (asymbol **) xmalloc (storage_needed);
-      back_to = make_cleanup (xfree, symbol_table);
-      number_of_symbols = bfd_canonicalize_dynamic_symtab (abfd, symbol_table);
-
-      for (i = 0; i < number_of_symbols; i++)
-       {
-         sym = *symbol_table++;
-         if (strcmp (sym->name, symname) == 0)
-           {
-             /* Bfd symbols are section relative. */
-             symaddr = sym->value + sym->section->vma;
-             break;
-           }
-       }
-      do_cleanups (back_to);
-    }
-
-  return symaddr;
-}
-
-
 /* If no open symbol file, attempt to locate and open the main symbol
    file.
 
@@ -852,6 +783,14 @@ enable_break_failure_warning (void)
           "and track explicitly loaded dynamic code."));
 }
 
+/* Helper function for gdb_bfd_lookup_symbol.  */
+
+static int
+cmp_name (asymbol *sym, void *data)
+{
+  return (strcmp (sym->name, (const char *) data) == 0);
+}
+
 /* The dynamic linkers has, as part of its debugger interface, support
    for arranging for the inferior to hit a breakpoint after mapping in
    the shared libraries.  This function enables that breakpoint.
@@ -903,8 +842,7 @@ enable_break2 (void)
       unsigned int interp_sect_size;
       gdb_byte *buf;
       bfd *tmp_bfd = NULL;
-      int status;
-      CORE_ADDR addr, interp_loadmap_addr;
+      CORE_ADDR addr;
       gdb_byte addr_buf[TIC6X_PTR_SIZE];
       struct int_elf32_dsbt_loadmap *ldm;
       volatile struct gdb_exception ex;
@@ -957,12 +895,12 @@ enable_break2 (void)
            info->interp_plt_sect_low + bfd_section_size (tmp_bfd, interp_sect);
        }
 
-      addr = bfd_lookup_symbol (tmp_bfd, "_dl_debug_addr");
+      addr = gdb_bfd_lookup_symbol (tmp_bfd, cmp_name, "_dl_debug_addr");
       if (addr == 0)
        {
          warning (_("Could not find symbol _dl_debug_addr in dynamic linker"));
          enable_break_failure_warning ();
-         bfd_close (tmp_bfd);
+         gdb_bfd_unref (tmp_bfd);
          return 0;
        }
 
@@ -1011,13 +949,13 @@ enable_break2 (void)
                     "(at address %s) from dynamic linker"),
                   hex_string_custom (addr + 8, 8));
          enable_break_failure_warning ();
-         bfd_close (tmp_bfd);
+         gdb_bfd_unref (tmp_bfd);
          return 0;
        }
       addr = extract_unsigned_integer (addr_buf, sizeof addr_buf, byte_order);
 
       /* We're done with the temporary bfd.  */
-      bfd_close (tmp_bfd);
+      gdb_bfd_unref (tmp_bfd);
 
       /* We're also done with the loadmap.  */
       xfree (ldm);
@@ -1091,8 +1029,6 @@ dsbt_special_symbol_handling (void)
 static void
 dsbt_relocate_main_executable (void)
 {
-  int status;
-  CORE_ADDR exec_addr, interp_addr;
   struct int_elf32_dsbt_loadmap *ldm;
   struct cleanup *old_chain;
   struct section_offsets *new_offsets;
This page took 0.025459 seconds and 4 git commands to generate.