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]

[rfa/dwarf] Kill some more unnecessary global variables


Now that we pass the section to dwarf2_read_section, we don't need to
pass the offset and size parameters also.  After removing them, it turns out
that the global offset variables are only:
  - passed to dwarf2_read_section
  - tested for non-zero-ness to indicate presence of the section
And testing the section pointer works just as well, so we can remove the
offsets.

This is part of the global state in dwarf2read crusade.  The remaining
section info is probably going to move into the objfile as per-objfile data,
but I wanted to prune the deadwood first.

OK?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2003-11-23  Daniel Jacobowitz  <drow@mvista.com>

	* dwarf2read.c (dwarf_info_offset, dwarf_abbrev_offset)
	(dwarf_line_offset, dwarf_pubnames_offset, dwarf_aranges_offset)
	(dwarf_loc_offset, dwarf_macinfo_offset, dwarf_str_offset)
	(dwarf_ranges_offset, dwarf_frame_offset, dwarf_eh_frame_offset):
	Delete.
	(dwarf2_read_section): Remove offset and size arguments.  Use
	bfd_get_section_size_before_reloc and sectp->filepos.
	(dwarf2_has_info): Clear section variables instead of offsets.
	(dwarf2_locate_sections): Don't initialize the deleted variables.
	(dwarf2_build_psymtabs): Update calls to dwarf2_read_section.
	(dwarf2_build_psymtabs_easy): Likewise.
	* dwarf2-frame.c (dwarf_frame_offset, dwarf_frame_size)
	(dwarf_eh_frame_offset, dwarf_eh_frame_size): Remove extern
	declarations.
	(dwarf2_read_section): Update prototype.
	(dwarf2_build_frame_info): Update calls to dwarf2_read_section.
	Use bfd_get_section_size_before_reloc instead of global size
	variables.

Index: dwarf2-frame.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2-frame.c,v
retrieving revision 1.19
diff -u -p -r1.19 dwarf2-frame.c
--- dwarf2-frame.c	7 Nov 2003 20:36:15 -0000	1.19
+++ dwarf2-frame.c	23 Nov 2003 22:35:50 -0000
@@ -1508,16 +1508,11 @@ decode_frame_entry (struct comp_unit *un
    dwarf2read.c in a better way.  */
 
 /* Imported from dwarf2read.c.  */
-extern file_ptr dwarf_frame_offset;
-extern unsigned int dwarf_frame_size;
 extern asection *dwarf_frame_section;
-extern file_ptr dwarf_eh_frame_offset;
-extern unsigned int dwarf_eh_frame_size;
 extern asection *dwarf_eh_frame_section;
 
 /* Imported from dwarf2read.c.  */
-extern char *dwarf2_read_section (struct objfile *objfile, file_ptr offset,
-				  unsigned int size, asection *sectp);
+extern char *dwarf2_read_section (struct objfile *objfile, asection *sectp);
 
 void
 dwarf2_build_frame_info (struct objfile *objfile)
@@ -1534,17 +1529,16 @@ dwarf2_build_frame_info (struct objfile 
 
   /* First add the information from the .eh_frame section.  That way,
      the FDEs from that section are searched last.  */
-  if (dwarf_eh_frame_offset)
+  if (dwarf_eh_frame_section)
     {
       asection *got, *txt;
 
       unit.cie = NULL;
       unit.dwarf_frame_buffer = dwarf2_read_section (objfile,
-						     dwarf_eh_frame_offset,
-						     dwarf_eh_frame_size,
 						     dwarf_eh_frame_section);
 
-      unit.dwarf_frame_size = dwarf_eh_frame_size;
+      unit.dwarf_frame_size
+	= bfd_get_section_size_before_reloc (dwarf_eh_frame_section);
       unit.dwarf_frame_section = dwarf_eh_frame_section;
 
       /* FIXME: kettenis/20030602: This is the DW_EH_PE_datarel base
@@ -1566,14 +1560,13 @@ dwarf2_build_frame_info (struct objfile 
 	frame_ptr = decode_frame_entry (&unit, frame_ptr, 1);
     }
 
-  if (dwarf_frame_offset)
+  if (dwarf_frame_section)
     {
       unit.cie = NULL;
       unit.dwarf_frame_buffer = dwarf2_read_section (objfile,
-						     dwarf_frame_offset,
-						     dwarf_frame_size,
 						     dwarf_frame_section);
-      unit.dwarf_frame_size = dwarf_frame_size;
+      unit.dwarf_frame_size
+	= bfd_get_section_size_before_reloc (dwarf_frame_section);
       unit.dwarf_frame_section = dwarf_frame_section;
 
       frame_ptr = unit.dwarf_frame_buffer;
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.114
diff -u -p -r1.114 dwarf2read.c
--- dwarf2read.c	19 Nov 2003 15:08:01 -0000	1.114
+++ dwarf2read.c	23 Nov 2003 22:35:52 -0000
@@ -128,18 +128,6 @@ _STATEMENT_PROLOGUE;
 
 /* offsets and sizes of debugging sections */
 
-static file_ptr dwarf_info_offset;
-static file_ptr dwarf_abbrev_offset;
-static file_ptr dwarf_line_offset;
-static file_ptr dwarf_pubnames_offset;
-static file_ptr dwarf_aranges_offset;
-static file_ptr dwarf_loc_offset;
-static file_ptr dwarf_macinfo_offset;
-static file_ptr dwarf_str_offset;
-static file_ptr dwarf_ranges_offset;
-file_ptr dwarf_frame_offset;
-file_ptr dwarf_eh_frame_offset;
-
 static unsigned int dwarf_info_size;
 static unsigned int dwarf_abbrev_size;
 static unsigned int dwarf_line_size;
@@ -697,8 +685,7 @@ static void dwarf2_psymtab_to_symtab (st
 
 static void psymtab_to_symtab_1 (struct partial_symtab *);
 
-char *dwarf2_read_section (struct objfile *, file_ptr, unsigned int,
-			   asection *);
+char *dwarf2_read_section (struct objfile *, asection *);
 
 static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
 
@@ -931,25 +918,18 @@ dwarf2_symbol_mark_computed (struct attr
 int
 dwarf2_has_info (bfd *abfd)
 {
-  dwarf_info_offset = 0;
-  dwarf_abbrev_offset = 0;
-  dwarf_line_offset = 0;
-  dwarf_str_offset = 0;
-  dwarf_macinfo_offset = 0;
-  dwarf_frame_offset = 0;
-  dwarf_eh_frame_offset = 0;
-  dwarf_ranges_offset = 0;
-  dwarf_loc_offset = 0;
+  dwarf_info_section = 0;
+  dwarf_abbrev_section = 0;
+  dwarf_line_section = 0;
+  dwarf_str_section = 0;
+  dwarf_macinfo_section = 0;
+  dwarf_frame_section = 0;
+  dwarf_eh_frame_section = 0;
+  dwarf_ranges_section = 0;
+  dwarf_loc_section = 0;
   
   bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL);
-  if (dwarf_info_offset && dwarf_abbrev_offset)
-    {
-      return 1;
-    }
-  else
-    {
-      return 0;
-    }
+  return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL);
 }
 
 /* This function is mapped across the sections and remembers the
@@ -961,55 +941,46 @@ dwarf2_locate_sections (bfd *ignore_abfd
 {
   if (strcmp (sectp->name, INFO_SECTION) == 0)
     {
-      dwarf_info_offset = sectp->filepos;
       dwarf_info_size = bfd_get_section_size_before_reloc (sectp);
       dwarf_info_section = sectp;
     }
   else if (strcmp (sectp->name, ABBREV_SECTION) == 0)
     {
-      dwarf_abbrev_offset = sectp->filepos;
       dwarf_abbrev_size = bfd_get_section_size_before_reloc (sectp);
       dwarf_abbrev_section = sectp;
     }
   else if (strcmp (sectp->name, LINE_SECTION) == 0)
     {
-      dwarf_line_offset = sectp->filepos;
       dwarf_line_size = bfd_get_section_size_before_reloc (sectp);
       dwarf_line_section = sectp;
     }
   else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0)
     {
-      dwarf_pubnames_offset = sectp->filepos;
       dwarf_pubnames_size = bfd_get_section_size_before_reloc (sectp);
       dwarf_pubnames_section = sectp;
     }
   else if (strcmp (sectp->name, ARANGES_SECTION) == 0)
     {
-      dwarf_aranges_offset = sectp->filepos;
       dwarf_aranges_size = bfd_get_section_size_before_reloc (sectp);
       dwarf_aranges_section = sectp;
     }
   else if (strcmp (sectp->name, LOC_SECTION) == 0)
     {
-      dwarf_loc_offset = sectp->filepos;
       dwarf_loc_size = bfd_get_section_size_before_reloc (sectp);
       dwarf_loc_section = sectp;
     }
   else if (strcmp (sectp->name, MACINFO_SECTION) == 0)
     {
-      dwarf_macinfo_offset = sectp->filepos;
       dwarf_macinfo_size = bfd_get_section_size_before_reloc (sectp);
       dwarf_macinfo_section = sectp;
     }
   else if (strcmp (sectp->name, STR_SECTION) == 0)
     {
-      dwarf_str_offset = sectp->filepos;
       dwarf_str_size = bfd_get_section_size_before_reloc (sectp);
       dwarf_str_section = sectp;
     }
   else if (strcmp (sectp->name, FRAME_SECTION) == 0)
     {
-      dwarf_frame_offset = sectp->filepos;
       dwarf_frame_size = bfd_get_section_size_before_reloc (sectp);
       dwarf_frame_section = sectp;
     }
@@ -1018,14 +989,12 @@ dwarf2_locate_sections (bfd *ignore_abfd
       flagword aflag = bfd_get_section_flags (ignore_abfd, sectp);
       if (aflag & SEC_HAS_CONTENTS)
         {
-          dwarf_eh_frame_offset = sectp->filepos;
           dwarf_eh_frame_size = bfd_get_section_size_before_reloc (sectp);
           dwarf_eh_frame_section = sectp;
         }
     }
   else if (strcmp (sectp->name, RANGES_SECTION) == 0)
     {
-      dwarf_ranges_offset = sectp->filepos;
       dwarf_ranges_size = bfd_get_section_size_before_reloc (sectp);
       dwarf_ranges_section = sectp;
     }
@@ -1039,52 +1008,32 @@ dwarf2_build_psymtabs (struct objfile *o
 
   /* We definitely need the .debug_info and .debug_abbrev sections */
 
-  dwarf_info_buffer = dwarf2_read_section (objfile,
-					   dwarf_info_offset,
-					   dwarf_info_size,
-					   dwarf_info_section);
-  dwarf_abbrev_buffer = dwarf2_read_section (objfile,
-					     dwarf_abbrev_offset,
-					     dwarf_abbrev_size,
-					     dwarf_abbrev_section);
-
-  if (dwarf_line_offset)
-    dwarf_line_buffer = dwarf2_read_section (objfile,
-					     dwarf_line_offset,
-					     dwarf_line_size,
-					     dwarf_line_section);
+  dwarf_info_buffer = dwarf2_read_section (objfile, dwarf_info_section);
+  dwarf_abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section);
+
+  if (dwarf_line_section)
+    dwarf_line_buffer = dwarf2_read_section (objfile, dwarf_line_section);
   else
     dwarf_line_buffer = NULL;
 
-  if (dwarf_str_offset)
-    dwarf_str_buffer = dwarf2_read_section (objfile,
-					    dwarf_str_offset,
-					    dwarf_str_size,
-					    dwarf_str_section);
+  if (dwarf_str_section)
+    dwarf_str_buffer = dwarf2_read_section (objfile, dwarf_str_section);
   else
     dwarf_str_buffer = NULL;
 
-  if (dwarf_macinfo_offset)
+  if (dwarf_macinfo_section)
     dwarf_macinfo_buffer = dwarf2_read_section (objfile,
-                                                dwarf_macinfo_offset,
-                                                dwarf_macinfo_size,
 						dwarf_macinfo_section);
   else
     dwarf_macinfo_buffer = NULL;
 
-  if (dwarf_ranges_offset)
-    dwarf_ranges_buffer = dwarf2_read_section (objfile,
-					       dwarf_ranges_offset,
-					       dwarf_ranges_size,
-					       dwarf_ranges_section);
+  if (dwarf_ranges_section)
+    dwarf_ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section);
   else
     dwarf_ranges_buffer = NULL;
 
-  if (dwarf_loc_offset)
-    dwarf_loc_buffer = dwarf2_read_section (objfile,
-					    dwarf_loc_offset,
-					    dwarf_loc_size,
-					    dwarf_loc_section);
+  if (dwarf_loc_section)
+    dwarf_loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section);
   else
     dwarf_loc_buffer = NULL;
 
@@ -1125,8 +1074,6 @@ dwarf2_build_psymtabs_easy (struct objfi
   unsigned int entry_length, version, info_offset, info_size;
 
   pubnames_buffer = dwarf2_read_section (objfile,
-					 dwarf_pubnames_offset,
-					 dwarf_pubnames_size,
 					 dwarf_pubnames_section);
   pubnames_ptr = pubnames_buffer;
   while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size)
@@ -1146,8 +1093,6 @@ dwarf2_build_psymtabs_easy (struct objfi
     }
 
   aranges_buffer = dwarf2_read_section (objfile,
-					dwarf_aranges_offset,
-					dwarf_aranges_size,
 					dwarf_aranges_section);
 
 }
@@ -3857,11 +3802,11 @@ make_cleanup_free_die_list (struct die_i
    object file specified by OBJFILE into the psymbol_obstack and return it.  */
 
 char *
-dwarf2_read_section (struct objfile *objfile, file_ptr offset,
-		     unsigned int size, asection *sectp)
+dwarf2_read_section (struct objfile *objfile, asection *sectp)
 {
   bfd *abfd = objfile->obfd;
   char *buf, *retbuf;
+  bfd_size_type size = bfd_get_section_size_before_reloc (sectp);
 
   if (size == 0)
     return NULL;
@@ -3872,13 +3817,11 @@ dwarf2_read_section (struct objfile *obj
   if (retbuf != NULL)
     return retbuf;
 
-  if ((bfd_seek (abfd, offset, SEEK_SET) != 0) ||
-      (bfd_bread (buf, size, abfd) != size))
-    {
-      buf = NULL;
-      error ("Dwarf Error: Can't read DWARF data from '%s'",
-	     bfd_get_filename (abfd));
-    }
+  if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
+      || bfd_bread (buf, size, abfd) != size)
+    error ("Dwarf Error: Can't read DWARF data from '%s'",
+	   bfd_get_filename (abfd));
+
   return buf;
 }
 


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