2011-12-13 Shinichiro Hamaji <shinichiro.hamaji@gmail.com>
authorTristan Gingold <gingold@adacore.com>
Tue, 13 Dec 2011 14:02:20 +0000 (14:02 +0000)
committerTristan Gingold <gingold@adacore.com>
Tue, 13 Dec 2011 14:02:20 +0000 (14:02 +0000)
* dwarf2.c (bfd_dwarf2_cleanup_debug_info): Accept stash as an
argument like other functions to support formats other than ELF.
* elf-bfd.h (bfd_dwarf2_cleanup_debug_info): Move to bfd-in.h.
* elf.c (_bfd_elf_close_and_cleanup): Pass dwarf2_find_line_info
in tdata as a parameter.
* libbfd-in.h (bfd_dwarf2_cleanup_debug_info): Move from
elf-bfd.h.
* libbfd.h (bfd_dwarf2_cleanup_debug_info): Regenerate.
* mach-o-target.c (bfd_mach_o_close_and_cleanup): Remove the
fallback macro.
(bfd_mach_o_find_nearest_line): Likewise.
* mach-o.c (bfd_mach_o_find_nearest_line): Add the definition
which calls _bfd_dwarf2_find_nearest_line.
(bfd_mach_o_close_and_cleanup): Likewise.
* mach-o.h (mach_o_data_struct): Add dwarf2_find_line_info.
(bfd_mach_o_find_nearest_line): Add declaration.
(bfd_mach_o_close_and_cleanup): Add declaration.

bfd/ChangeLog
bfd/dwarf2.c
bfd/elf-bfd.h
bfd/elf.c
bfd/libbfd-in.h
bfd/libbfd.h
bfd/mach-o-target.c
bfd/mach-o.c
bfd/mach-o.h

index ce03f4b71e7063e6f94be4b93b3ca9e218e50d70..cf07be239d8a5e735c69287c8b4ef842b830785b 100644 (file)
@@ -1,3 +1,23 @@
+2011-12-13  Shinichiro Hamaji  <shinichiro.hamaji@gmail.com>
+
+       * dwarf2.c (bfd_dwarf2_cleanup_debug_info): Accept stash as an
+       argument like other functions to support formats other than ELF.
+       * elf-bfd.h (bfd_dwarf2_cleanup_debug_info): Move to bfd-in.h.
+       * elf.c (_bfd_elf_close_and_cleanup): Pass dwarf2_find_line_info
+       in tdata as a parameter.
+       * libbfd-in.h (bfd_dwarf2_cleanup_debug_info): Move from
+       elf-bfd.h.
+       * libbfd.h (bfd_dwarf2_cleanup_debug_info): Regenerate.
+       * mach-o-target.c (bfd_mach_o_close_and_cleanup): Remove the
+       fallback macro.
+       (bfd_mach_o_find_nearest_line): Likewise.
+       * mach-o.c (bfd_mach_o_find_nearest_line): Add the definition
+       which calls _bfd_dwarf2_find_nearest_line.
+       (bfd_mach_o_close_and_cleanup): Likewise.
+       * mach-o.h (mach_o_data_struct): Add dwarf2_find_line_info.
+       (bfd_mach_o_find_nearest_line): Add declaration.
+       (bfd_mach_o_close_and_cleanup): Add declaration.
+
 2011-12-13  Tristan Gingold  <gingold@adacore.com>
 
        * mach-o.c (bfd_mach_o_read_symtab_symbols): Make global.  Remove
index 577f2783222a0b5eba1c42b7d7ec6e003ca903c6..767fa52b42038e88d3bfea827347644dc120ee08 100644 (file)
@@ -3527,17 +3527,12 @@ _bfd_dwarf2_find_inliner_info (bfd *abfd ATTRIBUTE_UNUSED,
 }
 
 void
-_bfd_dwarf2_cleanup_debug_info (bfd *abfd)
+_bfd_dwarf2_cleanup_debug_info (bfd *abfd, void **pinfo)
 {
+  struct dwarf2_debug *stash = (struct dwarf2_debug *) *pinfo;;
   struct comp_unit *each;
-  struct dwarf2_debug *stash;
-
-  if (abfd == NULL || elf_tdata (abfd) == NULL)
-    return;
-
-  stash = (struct dwarf2_debug *) elf_tdata (abfd)->dwarf2_find_line_info;
 
-  if (stash == NULL)
+  if (abfd == NULL || stash == NULL)
     return;
 
   for (each = stash->all_comp_units; each; each = each->next_unit)
index 486b76eecf123488e11785a9b35d30dad74479b4..c7846e118f088ae2f6e8d974d8ca2e3ba3993e9e 100644 (file)
@@ -2132,9 +2132,6 @@ extern unsigned int _bfd_elf_common_section_index
 extern asection *_bfd_elf_common_section
   (asection *);
 
-extern void _bfd_dwarf2_cleanup_debug_info
-  (bfd *);
-
 extern bfd_vma _bfd_elf_default_got_elt_size
 (bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, bfd *,
  unsigned long);
index f1e4882530d1ffb6944f175b94b90336abad0d2c..bafb3bbd80b20124bf61b274ac406d279d5b6730 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -7698,11 +7698,12 @@ _bfd_elf_validate_reloc (bfd *abfd, arelent *areloc)
 bfd_boolean
 _bfd_elf_close_and_cleanup (bfd *abfd)
 {
-  if (bfd_get_format (abfd) == bfd_object)
+  struct elf_obj_tdata *tdata = elf_tdata (abfd);
+  if (bfd_get_format (abfd) == bfd_object && tdata != NULL)
     {
-      if (elf_tdata (abfd) != NULL && elf_shstrtab (abfd) != NULL)
+      if (elf_shstrtab (abfd) != NULL)
        _bfd_elf_strtab_free (elf_shstrtab (abfd));
-      _bfd_dwarf2_cleanup_debug_info (abfd);
+      _bfd_dwarf2_cleanup_debug_info (abfd, &tdata->dwarf2_find_line_info);
     }
 
   return _bfd_generic_close_and_cleanup (abfd);
index ccc6c6542eccdf9349c2a76c005b77e93acfccc4..7db09e4a08eaee37538ff93cb5e82a37a6b0b428 100644 (file)
@@ -548,7 +548,11 @@ bfd_boolean _bfd_generic_find_line
 /* Find inliner info after calling bfd_find_nearest_line. */
 extern bfd_boolean _bfd_dwarf2_find_inliner_info
   (bfd *, const char **, const char **, unsigned int *, void **);
-  
+
+/* Clean up the data used to handle DWARF 2 debugging information. */
+extern void _bfd_dwarf2_cleanup_debug_info
+  (bfd *, void **);
+
 /* Create a new section entry.  */
 extern struct bfd_hash_entry *bfd_section_hash_newfunc
   (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
index d08c2ba829dfe4f04a0655f8b5a6727954b80d2d..e459f8269f13a1ff06eebd1a219106b03e14a531 100644 (file)
@@ -553,7 +553,11 @@ bfd_boolean _bfd_generic_find_line
 /* Find inliner info after calling bfd_find_nearest_line. */
 extern bfd_boolean _bfd_dwarf2_find_inliner_info
   (bfd *, const char **, const char **, unsigned int *, void **);
-  
+
+/* Clean up the data used to handle DWARF 2 debugging information. */
+extern void _bfd_dwarf2_cleanup_debug_info
+  (bfd *, void **);
+
 /* Create a new section entry.  */
 extern struct bfd_hash_entry *bfd_section_hash_newfunc
   (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
index 5e12f849f3116324156a9bf39c30b0a75dc311fd..d92c58bf75d1099445628cbfcdc817688601eb44 100644 (file)
 #ifndef MACH_O_TARGET_COMMON_DEFINED
 #define MACH_O_TARGET_COMMON_DEFINED
 
-#define bfd_mach_o_close_and_cleanup                  _bfd_generic_close_and_cleanup
 #define bfd_mach_o_bfd_free_cached_info               _bfd_generic_bfd_free_cached_info
 #define bfd_mach_o_get_section_contents_in_window     _bfd_generic_get_section_contents_in_window
 #define bfd_mach_o_bfd_print_private_bfd_data        _bfd_generic_bfd_print_private_bfd_data
 #define bfd_mach_o_bfd_is_target_special_symbol       ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
 #define bfd_mach_o_bfd_is_local_label_name            bfd_generic_is_local_label_name
 #define bfd_mach_o_get_lineno                         _bfd_nosymbols_get_lineno
-#define bfd_mach_o_find_nearest_line                  _bfd_nosymbols_find_nearest_line
 #define bfd_mach_o_find_inliner_info                  _bfd_nosymbols_find_inliner_info
 #define bfd_mach_o_bfd_make_debug_symbol              _bfd_nosymbols_bfd_make_debug_symbol
 #define bfd_mach_o_read_minisymbols                   _bfd_generic_read_minisymbols
index 0a614c30ce169a85ab840826cbea84d101ce2ef1..54edd079a0f75fcae77254a5a81787ac846c63e8 100644 (file)
@@ -3480,6 +3480,38 @@ bfd_mach_o_core_file_failing_signal (bfd *abfd ATTRIBUTE_UNUSED)
   return 0;
 }
 
+bfd_boolean
+bfd_mach_o_find_nearest_line (bfd *abfd,
+                             asection *section,
+                             asymbol **symbols,
+                             bfd_vma offset,
+                             const char **filename_ptr,
+                             const char **functionname_ptr,
+                             unsigned int *line_ptr)
+{
+  bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
+  /* TODO: Handle executables and dylibs by using dSYMs. */
+  if (mdata->header.filetype != BFD_MACH_O_MH_OBJECT)
+    return FALSE;
+  if (_bfd_dwarf2_find_nearest_line (abfd, dwarf_debug_sections,
+                                    section, symbols, offset,
+                                    filename_ptr, functionname_ptr,
+                                    line_ptr, 0,
+                                    &mdata->dwarf2_find_line_info))
+    return TRUE;
+  return FALSE;
+}
+
+bfd_boolean
+bfd_mach_o_close_and_cleanup (bfd *abfd)
+{
+  bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
+  if (bfd_get_format (abfd) == bfd_object && mdata != NULL)
+    _bfd_dwarf2_cleanup_debug_info (abfd, &mdata->dwarf2_find_line_info);
+
+  return _bfd_generic_close_and_cleanup (abfd);
+}
+
 #define bfd_mach_o_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup 
 #define bfd_mach_o_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
 
index d85224e9f745e25d1ca1672a4e82d31781762b77..686bb90dece4e4c7bbb60bdf0aa25f57848d8476 100644 (file)
@@ -516,6 +516,9 @@ typedef struct mach_o_data_struct
      is expected.  */
   bfd_mach_o_symtab_command *symtab;
   bfd_mach_o_dysymtab_command *dysymtab;
+
+  /* A place to stash dwarf2 info for this bfd.  */
+  void *dwarf2_find_line_info;
 }
 bfd_mach_o_data_struct;
 
@@ -590,6 +593,10 @@ unsigned int bfd_mach_o_get_section_type_from_name (const char *);
 unsigned int bfd_mach_o_get_section_attribute_from_name (const char *);
 void bfd_mach_o_normalize_section_name (const char *, const char *,
                                         const char **, flagword *);
+bfd_boolean bfd_mach_o_find_nearest_line (bfd *, asection *, asymbol **,
+                                          bfd_vma, const char **,
+                                          const char **, unsigned int *);
+bfd_boolean bfd_mach_o_close_and_cleanup (bfd *);
 
 unsigned int bfd_mach_o_section_get_nbr_indirect (bfd *, bfd_mach_o_section *);
 unsigned int bfd_mach_o_section_get_entry_size (bfd *, bfd_mach_o_section *);