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]

[PATCH] Add DW_FORM_strp support


Hi!

This patch adds support for DW_FORM_strp and .debug_str section into (old)
dwarf2 reader.
This is needed e.g. for gcc built with
http://gcc.gnu.org/ml/gcc-patches/2001-11/msg00324.html.
Ok to commit?

2001-11-07  Jakub Jelinek  <jakub@redhat.com>

	* dwarf2read.c (dwarf_str_buffer): New.
	(struct dwarf2_pinfo): Add dwarf_str_buffer and dwarf_str_size.
	(DWARF_STR_BUFFER, DWARF_STR_SIZE): Define.
	(dwarf2_has_info): Clear dwarf_str_offset.
	(dwarf2_build_psymtabs): Read .debug_str section if present.
	(dwarf2_build_psymtabs_hard): Save DWARF_STR_BUFFER and
	DWARF_STR_SIZE.
	(psymtab_to_symtab_1): Restore DWARF_STR_BUFFER and DWARF_STR_SIZE.
	(read_attribute): Handle DW_FORM_strp.
	(read_indirect_string): New.
	(dump_die): Handle DW_FORM_strp.

--- gdb/dwarf2read.c.jj	Wed Nov  7 00:38:14 2001
+++ gdb/dwarf2read.c	Wed Nov  7 12:57:58 2001
@@ -302,6 +302,7 @@ static const struct language_defn *cu_la
 static char *dwarf_info_buffer;
 static char *dwarf_abbrev_buffer;
 static char *dwarf_line_buffer;
+static char *dwarf_str_buffer;
 
 /* A zeroed version of a partial die for initialization purposes.  */
 static struct partial_die_info zeroed_partial_die;
@@ -383,6 +384,14 @@ struct dwarf2_pinfo
     /* Pointer to start of dwarf line buffer for the objfile.  */
 
     char *dwarf_line_buffer;
+
+    /* Pointer to start of dwarf string buffer for the objfile.  */
+
+    char *dwarf_str_buffer;
+
+    /* Size of dwarf string section for the objfile.  */
+
+    unsigned int dwarf_str_size;
   };
 
 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
@@ -391,6 +400,8 @@ struct dwarf2_pinfo
 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
+#define DWARF_STR_BUFFER(p)  (PST_PRIVATE(p)->dwarf_str_buffer)
+#define DWARF_STR_SIZE(p)    (PST_PRIVATE(p)->dwarf_str_size)
 
 /* Maintain an array of referenced fundamental types for the current
    compilation unit being read.  For DWARF version 1, we have to construct
@@ -616,6 +627,9 @@ static char *read_n_bytes (bfd *, char *
 
 static char *read_string (bfd *, char *, unsigned int *);
 
+static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *,
+				   unsigned int *);
+
 static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *);
 
 static long read_signed_leb128 (bfd *, char *, unsigned int *);
@@ -788,6 +802,7 @@ int
 dwarf2_has_info (bfd *abfd)
 {
   dwarf_info_offset = dwarf_abbrev_offset = dwarf_line_offset = 0;
+  dwarf_str_offset = 0;
   bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL);
   if (dwarf_info_offset && dwarf_abbrev_offset)
     {
@@ -866,6 +881,13 @@ dwarf2_build_psymtabs (struct objfile *o
 					   dwarf_line_offset,
 					   dwarf_line_size);
 
+  if (dwarf_str_offset)
+    dwarf_str_buffer = dwarf2_read_section (objfile,
+					    dwarf_str_offset,
+					    dwarf_str_size);
+  else
+    dwarf_str_buffer = NULL;
+
   if (mainline
       || (objfile->global_psymbols.size == 0
 	  && objfile->static_psymbols.size == 0))
@@ -1071,6 +1093,8 @@ dwarf2_build_psymtabs_hard (struct objfi
       DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer;
       DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size;
       DWARF_LINE_BUFFER (pst) = dwarf_line_buffer;
+      DWARF_STR_BUFFER (pst) = dwarf_str_buffer;
+      DWARF_STR_SIZE (pst) = dwarf_str_size;
       baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 
       /* Store the function that reads in the rest of the symbol table */
@@ -1370,6 +1394,8 @@ psymtab_to_symtab_1 (struct partial_symt
   dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst);
   dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst);
   dwarf_line_buffer = DWARF_LINE_BUFFER (pst);
+  dwarf_str_buffer = DWARF_STR_BUFFER (pst);
+  dwarf_str_size = DWARF_STR_SIZE (pst);
   baseaddr = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (objfile));
   cu_header_offset = offset;
   info_ptr = dwarf_info_buffer + offset;
@@ -3384,6 +3410,11 @@ read_attribute (struct attribute *attr, 
       DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read);
       info_ptr += bytes_read;
       break;
+    case DW_FORM_strp:
+      DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header,
+					       &bytes_read);
+      info_ptr += bytes_read;
+      break;
     case DW_FORM_block:
       blk = dwarf_alloc_block ();
       blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
@@ -3436,7 +3467,6 @@ read_attribute (struct attribute *attr, 
       DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
       info_ptr += bytes_read;
       break;
-    case DW_FORM_strp:
     case DW_FORM_indirect:
     default:
       error ("Dwarf Error: Cannot handle %s in DWARF reader.",
@@ -3677,6 +3707,37 @@ read_string (bfd *abfd, char *buf, unsig
 #endif
 }
 
+static char *
+read_indirect_string (bfd *abfd, char *buf,
+		      const struct comp_unit_head *cu_header,
+		      unsigned int *bytes_read_ptr)
+{
+  LONGEST str_offset = read_offset (abfd, buf, cu_header,
+				    (int *) bytes_read_ptr);
+
+  if (dwarf_str_buffer == NULL)
+    {
+      error ("DW_FORM_strp used without .debug_str section");
+      return NULL;
+    }
+  if (str_offset >= dwarf_str_size)
+    {
+      error ("DW_FORM_strp pointing outside of .debug_str section");
+      return NULL;
+    }
+#if HOST_CHAR_BIT == 8
+  if (dwarf_str_buffer[str_offset] == '\0')
+    return NULL;
+  return dwarf_str_buffer + str_offset;
+#else
+  {
+    unsigned int len;
+
+    return read_string (abfd, dwarf_str_buffer + str_offset, &len);
+  }
+#endif
+}
+
 static unsigned long
 read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr)
 {
@@ -5578,6 +5639,7 @@ dump_die (struct die_info *die)
 	  fprintf (stderr, "constant: %ld", DW_UNSND (&die->attrs[i]));
 	  break;
 	case DW_FORM_string:
+	case DW_FORM_strp:
 	  fprintf (stderr, "string: \"%s\"",
 		   DW_STRING (&die->attrs[i])
 		   ? DW_STRING (&die->attrs[i]) : "");
@@ -5588,8 +5650,6 @@ dump_die (struct die_info *die)
 	  else
 	    fprintf (stderr, "flag: FALSE");
 	  break;
-	case DW_FORM_strp:	/* we do not support separate string
-				   section yet */
 	case DW_FORM_indirect:	/* we do not handle indirect yet */
 	default:
 	  fprintf (stderr, "unsupported attribute form: %d.",

	Jakub


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