[PATCH] Support DW_FORM_strx1, _strx2, _strx3, _strx4 forms.

Ali Tamur via gdb-patches gdb-patches@sourceware.org
Fri Apr 26 19:16:00 GMT 2019


Dwarf5 defines DW_FORM_strx1 and others, which are similar
to DW_FORM_strx but uses 1-4 bytes unsigned integers. This is
a small step towards supporting dwarf5 in gdb.

gdb/ChangeLog:
2019-04-26  Ali Tamur  <tamur@google.com>

* gdb/dwarf2read.c (read_3_bytes): New declaration.
(read_attribute_value): Added DW_FORM_strx1-4 cases.
(read_3_bytes): New function.
* gdb/testsuite/lib/dwarf.exp(): Added DW_FORM_strx1-4.
---
 gdb/dwarf2read.c            | 49
+++++++++++++++++++++++++++++++++++++++++----
 gdb/testsuite/lib/dwarf.exp |  4 ++++
 2 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 4259c386b9..be7cc9ccbb 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1531,6 +1531,8 @@ static int read_1_signed_byte (bfd *, const gdb_byte
*);

 static unsigned int read_2_bytes (bfd *, const gdb_byte *);

+static unsigned int read_3_bytes (bfd *, const gdb_byte *);
+
 static unsigned int read_4_bytes (bfd *, const gdb_byte *);

 static ULONGEST read_8_bytes (bfd *, const gdb_byte *);
@@ -19289,6 +19291,10 @@ read_attribute_value (const struct
die_reader_specs *reader,
       info_ptr += bytes_read;
       break;
     case DW_FORM_strx:
+    case DW_FORM_strx1:
+    case DW_FORM_strx2:
+    case DW_FORM_strx3:
+    case DW_FORM_strx4:
     case DW_FORM_GNU_str_index:
       if (reader->dwo_file == NULL)
  {
@@ -19299,12 +19305,34 @@ read_attribute_value (const struct
die_reader_specs *reader,
  bfd_get_filename (abfd));
  }
       {
- ULONGEST str_index =
-   read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
-
+ ULONGEST str_index;
+ if (form == DW_FORM_strx1)
+   {
+     str_index = read_1_byte (abfd, info_ptr);
+     info_ptr += 1;
+   }
+ else if (form == DW_FORM_strx2)
+   {
+     str_index = read_2_bytes (abfd, info_ptr);
+     info_ptr += 2;
+   }
+ else if (form == DW_FORM_strx3)
+   {
+     str_index = read_3_bytes (abfd, info_ptr);
+     info_ptr += 3;
+   }
+ else if (form == DW_FORM_strx4)
+   {
+     str_index = read_4_bytes (abfd, info_ptr);
+     info_ptr += 4;
+   }
+ else
+   {
+     str_index = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
+     info_ptr += bytes_read;
+   }
  DW_STRING (attr) = read_str_index (reader, str_index);
  DW_STRING_IS_CANONICAL (attr) = 0;
- info_ptr += bytes_read;
       }
       break;
     default:
@@ -19374,6 +19402,19 @@ read_2_signed_bytes (bfd *abfd, const gdb_byte
*buf)
   return bfd_get_signed_16 (abfd, buf);
 }

+static unsigned int
+read_3_bytes (bfd *abfd, const gdb_byte *buf)
+{
+  unsigned int result = 0;
+  for (int i = 0; i < 3; ++i)
+    {
+      unsigned char byte = bfd_get_8 (abfd, buf);
+      buf++;
+      result |= ((unsigned int) byte << (i * 8));
+    }
+  return result;
+}
+
 static unsigned int
 read_4_bytes (bfd *abfd, const gdb_byte *buf)
 {
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 3a430fcd96..3cc592890c 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -528,6 +528,10 @@ namespace eval Dwarf {
      DW_FORM_exprloc -

      DW_FORM_strx -
+     DW_FORM_strx1 -
+     DW_FORM_strx2 -
+     DW_FORM_strx3 -
+     DW_FORM_strx4 -

      DW_FORM_GNU_addr_index -



More information about the Gdb-patches mailing list