public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* Some easy DWARF5 extensions
@ 2017-07-26 22:07 Mark Wielaard
  2017-07-26 22:08 ` [PATCH 6/9] libdw: DWARF5 Add DW_CC_pass_by_reference and DW_CC_pass_by_reference Mark Wielaard
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Mark Wielaard @ 2017-07-26 22:07 UTC (permalink / raw)
  To: elfutils-devel

Hi,

The following are all the easy DWARF5 extensions that a compiler might
emit in "non-strict" DWARF mode (when it uses tags, attributes or other
constants from a later version of DWARF).

[PATCH 1/9] libdw: Add DWARF5 attributes.
[PATCH 2/9] libdw: Add new DWARF5 tag constants.
[PATCH 3/9] libdw: Add new DWARF5 character encodings.
[PATCH 4/9] libdw: DWARF5 Add new DW_LANG codes and default lower
[PATCH 5/9] libdw: Add dwarf_default_lower_bound.
[PATCH 6/9] libdw: DWARF5 Add DW_CC_pass_by_reference and
[PATCH 7/9] Handle DWARF5 defaulted member function encodings.
[PATCH 8/9] libdw: Handle DWARF5 immutable, packed and shared in
[PATCH 9/9] libdw: Add DW_MACRO constants and DW_MACRO_GNU

This doesn't include the "hard" parts of handling the new DWARF5
unit headers, forms, expression operations, line tables and the
new debug_names, etc. Some of that work can be found here:
https://code.wildebeest.org/git/user/mjw/elfutils/commit/?h=mjw/DWARF5_UT_FORM
but that is still very much a work in progress.

I believe the above patches however are ready and I would like to include
them in the next release. It has been 3 months since the last one, so it
is time to do a new one soon. It would be nice to at least handle these
easy parts of DWARF5 with elfutils 0.170.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 9/9] libdw: Add DW_MACRO constants and DW_MACRO_GNU compatibility defines.
  2017-07-26 22:07 Some easy DWARF5 extensions Mark Wielaard
                   ` (3 preceding siblings ...)
  2017-07-26 22:08 ` [PATCH 2/9] libdw: Add new DWARF5 tag constants Mark Wielaard
@ 2017-07-26 22:08 ` Mark Wielaard
  2017-07-26 22:08 ` [PATCH 3/9] libdw: Add new DWARF5 character encodings Mark Wielaard
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Mark Wielaard @ 2017-07-26 22:08 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Accept version 5 .debug_macro format, which is identical to the GNU
version 4 format. No real support yet for the new supplementary object
file (sup) and indirect string references (strx).  GCC doesn't generate
them yet. readelf does recognize them, but doesn't try to decode them.
dwarf_getmacros currently rejects the new formats.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 ChangeLog               |  4 +++
 NEWS                    |  4 ++-
 libdw/ChangeLog         |  7 ++++
 libdw/dwarf.h           | 38 ++++++++++++++------
 libdw/dwarf_getmacros.c | 27 +++++++-------
 src/ChangeLog           |  7 ++++
 src/readelf.c           | 95 ++++++++++++++++++++++++++++++++++++++++---------
 tests/ChangeLog         |  4 +++
 tests/dwarf-getmacros.c | 10 +++---
 9 files changed, 152 insertions(+), 44 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b7efc84..8748ab8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
+	* NEWS: Mention dwarf_getmacros handling version 5 .debug_macro.
+
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
 	* NEWS: Mention dwarf_peel_type DWARF5 tags improvement.
 
 2017-07-26  Mark Wielaard  <mark@klomp.org>
diff --git a/NEWS b/NEWS
index 054ac95..5c2d8ad 100644
--- a/NEWS
+++ b/NEWS
@@ -1,9 +1,11 @@
 Version 0.170
 
 libdw: Added new DWARF5 attribute, tag, character encoding, language code,
-       calling convention and defaulted member function constants to dwarf.h.
+       calling convention, defaulted member function and macro constants
+       to dwarf.h.
        New function dwarf_default_lower_bound.
        dwarf_peel_type now handles DWARF5 immutable, packed and shared tags.
+       dwarf_getmacros now handles DWARF5 .debug_macro sections.
 
 strip: Add -R, --remove-section=SECTION and --keep-section=SECTION.
 
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index d0b3f4c..6533eb5 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,12 @@
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
+	* dwarf.h: Add DW_MACRO_* and compat defines for DW_MACRO_GNU_*.
+	* dwarf_getmacros.c (get_table_for_offset): Accept either version
+	4 or 5. Use DW_MACRO names instead of DW_MACRO_GNU names.
+	(read_macros): Use table version for fake_cu.
+
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
 	* dwarf_peel_type.c (dwarf_peel_type): Handle DW_TAG_immutable_type,
 	DW_TAG_packed_type and DW_TAG_shared_type.
 	* libdw.h (dwarf_peel_type): Extend documentation.
diff --git a/libdw/dwarf.h b/libdw/dwarf.h
index 82a68f2..902d261 100644
--- a/libdw/dwarf.h
+++ b/libdw/dwarf.h
@@ -780,20 +780,38 @@ enum
   };
 
 
-/* DWARF debug_macro type encodings.  GNU/DWARF5 extension.  */
+/* DWARF debug_macro type encodings.  */
 enum
   {
-    DW_MACRO_GNU_define = 0x01,
-    DW_MACRO_GNU_undef = 0x02,
-    DW_MACRO_GNU_start_file = 0x03,
-    DW_MACRO_GNU_end_file = 0x04,
-    DW_MACRO_GNU_define_indirect = 0x05,
-    DW_MACRO_GNU_undef_indirect = 0x06,
-    DW_MACRO_GNU_transparent_include = 0x07,
-    DW_MACRO_GNU_lo_user = 0xe0,
-    DW_MACRO_GNU_hi_user = 0xff
+    DW_MACRO_define = 0x01,
+    DW_MACRO_undef = 0x02,
+    DW_MACRO_start_file = 0x03,
+    DW_MACRO_end_file = 0x04,
+    DW_MACRO_define_strp = 0x05,
+    DW_MACRO_undef_strp = 0x06,
+    DW_MACRO_import = 0x07,
+    DW_MACRO_define_sup = 0x08,
+    DW_MACRO_undef_sup = 0x09,
+    DW_MACRO_import_sup = 0x0a,
+    DW_MACRO_define_strx = 0x0b,
+    DW_MACRO_undef_strx = 0x0c,
+    DW_MACRO_lo_user = 0xe0,
+    DW_MACRO_hi_user = 0xff
   };
 
+/* Old GNU extension names for DWARF5 debug_macro type encodings.
+   There are no equivalents for the supplementary object file (sup)
+   and indirect string references (strx).  */
+#define DW_MACRO_GNU_define		 DW_MACRO_define
+#define DW_MACRO_GNU_undef		 DW_MACRO_undef
+#define DW_MACRO_GNU_start_file		 DW_MACRO_start_file
+#define DW_MACRO_GNU_end_file		 DW_MACRO_end_file
+#define DW_MACRO_GNU_define_indirect	 DW_MACRO_define_strp
+#define DW_MACRO_GNU_undef_indirect	 DW_MACRO_undef_strp
+#define DW_MACRO_GNU_transparent_include DW_MACRO_import
+#define DW_MACRO_GNU_lo_user		 DW_MACRO_lo_user
+#define DW_MACRO_GNU_hi_user		 DW_MACRO_hi_user
+
 
 /* DWARF call frame instruction encodings.  */
 enum
diff --git a/libdw/dwarf_getmacros.c b/libdw/dwarf_getmacros.c
index eb50508..db6582b 100644
--- a/libdw/dwarf_getmacros.c
+++ b/libdw/dwarf_getmacros.c
@@ -158,7 +158,7 @@ get_table_for_offset (Dwarf *dbg, Dwarf_Word macoff,
     }
 
   uint16_t version = read_2ubyte_unaligned_inc (dbg, readp);
-  if (version != 4)
+  if (version != 4 && version != 5)
     {
       __libdw_seterrno (DWARF_E_INVALID_VERSION);
       return NULL;
@@ -198,15 +198,17 @@ get_table_for_offset (Dwarf *dbg, Dwarf_Word macoff,
 
   Dwarf_Macro_Op_Proto op_protos[255] =
     {
-      [DW_MACRO_GNU_define - 1] = p_udata_str,
-      [DW_MACRO_GNU_undef - 1] = p_udata_str,
-      [DW_MACRO_GNU_define_indirect - 1] = p_udata_strp,
-      [DW_MACRO_GNU_undef_indirect - 1] = p_udata_strp,
-      [DW_MACRO_GNU_start_file - 1] = p_udata_udata,
-      [DW_MACRO_GNU_end_file - 1] = p_none,
-      [DW_MACRO_GNU_transparent_include - 1] = p_secoffset,
-      /* N.B. DW_MACRO_undef_indirectx, DW_MACRO_define_indirectx
-	 should be added when 130313.1 is supported.  */
+      [DW_MACRO_define - 1] = p_udata_str,
+      [DW_MACRO_undef - 1] = p_udata_str,
+      [DW_MACRO_define_strp - 1] = p_udata_strp,
+      [DW_MACRO_undef_strp - 1] = p_udata_strp,
+      [DW_MACRO_start_file - 1] = p_udata_udata,
+      [DW_MACRO_end_file - 1] = p_none,
+      [DW_MACRO_import - 1] = p_secoffset,
+      /* When adding support for DWARF5 supplementary object files and
+	 indirect string tables also add support for DW_MACRO_define_sup,
+	 DW_MACRO_undef_sup, DW_MACRO_import_sup, DW_MACRO_define_strx
+	 and DW_MACRO_undef_strx.  */
     };
 
   if ((flags & 0x4) != 0)
@@ -354,10 +356,11 @@ read_macros (Dwarf *dbg, int sec_index,
 
       /* A fake CU with bare minimum data to fool dwarf_formX into
 	 doing the right thing with the attributes that we put out.
-	 We arbitrarily pretend it's version 4.  */
+	 We pretend it is the same version as the actual table.
+	 Version 4 for the old GNU extension, version 5 for DWARF5.  */
       Dwarf_CU fake_cu = {
 	.dbg = dbg,
-	.version = 4,
+	.version = table->version,
 	.offset_size = table->is_64bit ? 8 : 4,
 	.startp = (void *) startp + offset,
 	.endp = (void *) endp,
diff --git a/src/ChangeLog b/src/ChangeLog
index 3ebc704..54ba767 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,12 @@
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
+	* readelf.c (print_debug_macro_section): Accept either version 4 or
+	version 5. Use DW_MACRO names instead of DW_MACRO_GNU names. Add
+	minimal support for DW_MACRO_define_sup, DW_MACRO_undef_sup,
+	DW_MACRO_import_sup, DW_MACRO_define_strx and DW_MACRO_undef_strx.
+
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
 	* readelf.c (dwarf_defaulted_string): New function.
 	(dwarf_defaulted_name): Likewise.
 	(attr_callback): Use dwarf_defaulted_name to get value of
diff --git a/src/readelf.c b/src/readelf.c
index 5e1685d..73be474 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -7394,7 +7394,7 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
 
       // Version 4 is the GNU extension for DWARF4.  DWARF5 will use version
       // 5 when it gets standardized.
-      if (vers != 4)
+      if (vers != 4 && vers != 5)
 	{
 	  printf (gettext ("  unknown version, cannot parse section\n"));
 	  return;
@@ -7418,7 +7418,7 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
 		  line_offset);
 	}
 
-      const unsigned char *vendor[DW_MACRO_GNU_hi_user - DW_MACRO_GNU_lo_user];
+      const unsigned char *vendor[DW_MACRO_hi_user - DW_MACRO_lo_user];
       memset (vendor, 0, sizeof vendor);
       if (flag & 0x04)
 	{
@@ -7435,12 +7435,12 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
 		goto invalid_data;
 	      unsigned int opcode = *readp++;
 	      printf (gettext ("    [%" PRIx8 "]"), opcode);
-	      if (opcode < DW_MACRO_GNU_lo_user
-		  || opcode > DW_MACRO_GNU_hi_user)
+	      if (opcode < DW_MACRO_lo_user
+		  || opcode > DW_MACRO_hi_user)
 		goto invalid_data;
 	      // Record the start of description for this vendor opcode.
 	      // uleb128 nr args, 1 byte per arg form.
-	      vendor[opcode - DW_MACRO_GNU_lo_user] = readp;
+	      vendor[opcode - DW_MACRO_lo_user] = readp;
 	      if (readp + 1 > readendp)
 		goto invalid_data;
 	      unsigned int args = *readp++;
@@ -7493,7 +7493,7 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
 
           switch (opcode)
             {
-            case DW_MACRO_GNU_start_file:
+            case DW_MACRO_start_file:
 	      get_uleb128 (u128, readp, readendp);
 	      if (readp >= readendp)
 		goto invalid_data;
@@ -7523,12 +7523,12 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
 	      ++level;
 	      break;
 
-	    case DW_MACRO_GNU_end_file:
+	    case DW_MACRO_end_file:
 	      --level;
 	      printf ("%*send_file\n", level, "");
 	      break;
 
-	    case DW_MACRO_GNU_define:
+	    case DW_MACRO_define:
 	      get_uleb128 (u128, readp, readendp);
 	      endp = memchr (readp, '\0', readendp - readp);
 	      if (endp == NULL)
@@ -7538,7 +7538,7 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
 	      readp = endp + 1;
 	      break;
 
-	    case DW_MACRO_GNU_undef:
+	    case DW_MACRO_undef:
 	      get_uleb128 (u128, readp, readendp);
 	      endp = memchr (readp, '\0', readendp - readp);
 	      if (endp == NULL)
@@ -7548,7 +7548,7 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
 	      readp = endp + 1;
 	      break;
 
-	    case DW_MACRO_GNU_define_indirect:
+	    case DW_MACRO_define_strp:
 	      get_uleb128 (u128, readp, readendp);
 	      if (readp + offset_len > readendp)
 		goto invalid_data;
@@ -7560,7 +7560,7 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
 		      level, "", dwarf_getstring (dbg, off, NULL), u128);
 	      break;
 
-	    case DW_MACRO_GNU_undef_indirect:
+	    case DW_MACRO_undef_strp:
 	      get_uleb128 (u128, readp, readendp);
 	      if (readp + offset_len > readendp)
 		goto invalid_data;
@@ -7572,7 +7572,7 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
 		      level, "", dwarf_getstring (dbg, off, NULL), u128);
 	      break;
 
-	    case DW_MACRO_GNU_transparent_include:
+	    case DW_MACRO_import:
 	      if (readp + offset_len > readendp)
 		goto invalid_data;
 	      if (offset_len == 8)
@@ -7583,15 +7583,78 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
 		      level, "", off);
 	      break;
 
+	    case DW_MACRO_define_sup:
+	      get_uleb128 (u128, readp, readendp);
+	      if (readp + offset_len > readendp)
+		goto invalid_data;
+	      if (offset_len == 8)
+		off = read_8ubyte_unaligned_inc (dbg, readp);
+	      else
+		off = read_4ubyte_unaligned_inc (dbg, readp);
+	      // Needs support for reading from supplementary object file.
+	      printf ("%*s#define <str-at-0x%" PRIx64 ">, line %u (sup)\n",
+		      level, "", off, u128);
+	      break;
+
+	    case DW_MACRO_undef_sup:
+	      get_uleb128 (u128, readp, readendp);
+	      if (readp + offset_len > readendp)
+		goto invalid_data;
+	      if (offset_len == 8)
+		off = read_8ubyte_unaligned_inc (dbg, readp);
+	      else
+		off = read_4ubyte_unaligned_inc (dbg, readp);
+	      // Needs support for reading from supplementary object file.
+	      printf ("%*s#undef <str-at-0x%" PRIx64 ">, line %u (sup)\n",
+		      level, "", off, u128);
+	      break;
+
+	    case DW_MACRO_import_sup:
+	      if (readp + offset_len > readendp)
+		goto invalid_data;
+	      if (offset_len == 8)
+		off = read_8ubyte_unaligned_inc (dbg, readp);
+	      else
+		off = read_4ubyte_unaligned_inc (dbg, readp);
+	      printf ("%*s#include offset 0x%" PRIx64 " (sup)\n",
+		      level, "", off);
+	      break;
+
+	    case DW_MACRO_define_strx:
+	      get_uleb128 (u128, readp, readendp);
+	      if (readp + offset_len > readendp)
+		goto invalid_data;
+	      if (offset_len == 8)
+		off = read_8ubyte_unaligned_inc (dbg, readp);
+	      else
+		off = read_4ubyte_unaligned_inc (dbg, readp);
+	      // Needs support for reading indirect string offset table
+	      printf ("%*s#define <str-at-0x%" PRIx64 ">, line %u (strx)\n",
+		      level, "", off, u128);
+	      break;
+
+	    case DW_MACRO_undef_strx:
+	      get_uleb128 (u128, readp, readendp);
+	      if (readp + offset_len > readendp)
+		goto invalid_data;
+	      if (offset_len == 8)
+		off = read_8ubyte_unaligned_inc (dbg, readp);
+	      else
+		off = read_4ubyte_unaligned_inc (dbg, readp);
+	      // Needs support for reading indirect string offset table.
+	      printf ("%*s#undef <str-at-0x%" PRIx64 ">, line %u (strx)\n",
+		      level, "", off, u128);
+	      break;
+
 	    default:
 	      printf ("%*svendor opcode 0x%" PRIx8, level, "", opcode);
-	      if (opcode < DW_MACRO_GNU_lo_user
-		  || opcode > DW_MACRO_GNU_lo_user
-		  || vendor[opcode - DW_MACRO_GNU_lo_user] == NULL)
+	      if (opcode < DW_MACRO_lo_user
+		  || opcode > DW_MACRO_lo_user
+		  || vendor[opcode - DW_MACRO_lo_user] == NULL)
 		goto invalid_data;
 
 	      const unsigned char *op_desc;
-	      op_desc = vendor[opcode - DW_MACRO_GNU_lo_user];
+	      op_desc = vendor[opcode - DW_MACRO_lo_user];
 
 	      // Just skip the arguments, we cannot really interpret them,
 	      // but print as much as we can.
diff --git a/tests/ChangeLog b/tests/ChangeLog
index fa3f94e..04efdc8 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,9 @@
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
+	* dwarf-getmacros.c (mac): Use DW_MACRO names instead of DW_MACRO_GNU.
+
+2016-10-27  Mark Wielaard  <mjw@redhat.com>
+
 	* dwarf_default_lower_bound.c: New test.
 	* Makefile.am (check_PROGRAMS): Add dwarf_default_lower_bound.
 	(TESTS): Likewise.
diff --git a/tests/dwarf-getmacros.c b/tests/dwarf-getmacros.c
index 92e093c..ac70248 100644
--- a/tests/dwarf-getmacros.c
+++ b/tests/dwarf-getmacros.c
@@ -38,7 +38,7 @@ mac (Dwarf_Macro *macro, void *dbg)
   dwarf_macro_opcode (macro, &opcode);
   switch (opcode)
     {
-    case DW_MACRO_GNU_transparent_include:
+    case DW_MACRO_import:
       {
 	Dwarf_Attribute at;
 	int r = dwarf_macro_param (macro, 0, &at);
@@ -56,7 +56,7 @@ mac (Dwarf_Macro *macro, void *dbg)
 	break;
       }
 
-    case DW_MACRO_GNU_start_file:
+    case DW_MACRO_start_file:
       {
 	Dwarf_Files *files;
 	size_t nfiles;
@@ -73,7 +73,7 @@ mac (Dwarf_Macro *macro, void *dbg)
 	break;
       }
 
-    case DW_MACRO_GNU_end_file:
+    case DW_MACRO_end_file:
       {
 	--level;
 	printf ("%*s/file\n", level, "");
@@ -81,7 +81,7 @@ mac (Dwarf_Macro *macro, void *dbg)
       }
 
     case DW_MACINFO_define:
-    case DW_MACRO_GNU_define_indirect:
+    case DW_MACRO_define_strp:
       {
 	const char *value;
 	dwarf_macro_param2 (macro, NULL, &value);
@@ -90,7 +90,7 @@ mac (Dwarf_Macro *macro, void *dbg)
       }
 
     case DW_MACINFO_undef:
-    case DW_MACRO_GNU_undef_indirect:
+    case DW_MACRO_undef_strp:
       break;
 
     default:
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 6/9] libdw: DWARF5 Add DW_CC_pass_by_reference and DW_CC_pass_by_reference.
  2017-07-26 22:07 Some easy DWARF5 extensions Mark Wielaard
@ 2017-07-26 22:08 ` Mark Wielaard
  2017-07-26 22:08 ` [PATCH 1/9] libdw: Add DWARF5 attributes Mark Wielaard
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Mark Wielaard @ 2017-07-26 22:08 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 ChangeLog       | 4 ++++
 NEWS            | 4 ++--
 libdw/ChangeLog | 4 ++++
 libdw/dwarf.h   | 7 ++++++-
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 25944f0..7748f13 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
+	* NEWS: Mention new DWARF5 calling conventions.
+
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
 	* NEWS: Mention new dwarf_default_lower_bound function.
 
 2017-07-25  Mark Wielaard  <mark@klomp.org>
diff --git a/NEWS b/NEWS
index 5bf0a4d..409805e 100644
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,7 @@
 Version 0.170
 
-libdw: Added new DWARF5 attribute, tag, character encodings constants and
-       language codes to dwarf.h.
+libdw: Added new DWARF5 attribute, tag, character encoding, language code
+       and calling convention constants to dwarf.h.
        New function dwarf_default_lower_bound.
 
 strip: Add -R, --remove-section=SECTION and --keep-section=SECTION.
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index ee7dc92..1c4eb36 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,9 @@
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
+	* dwarf.h: Add DW_CC_pass_by_reference and DW_CC_pass_by_reference.
+
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
 	* dwarf_default_lower_bound.c: New file.
 	* Makefile.am (libdw_a_SOURCES): Add dwarf_default_lower_bound.c.
 	* dwarf_aggregate_size.c (array_size): Use dwarf_default_lower_bound.
diff --git a/libdw/dwarf.h b/libdw/dwarf.h
index dd4384f..de8f7e5 100644
--- a/libdw/dwarf.h
+++ b/libdw/dwarf.h
@@ -688,12 +688,17 @@ enum
   };
 
 
-/* DWARF calling conventions encodings.  */
+/* DWARF calling conventions encodings.
+   Used as values of DW_AT_calling_convention for subroutines
+   (normal, program or nocall) or structures, unions and class types
+   (normal, reference or value).  */
 enum
   {
     DW_CC_normal = 0x1,
     DW_CC_program = 0x2,
     DW_CC_nocall = 0x3,
+    DW_CC_pass_by_reference = 0x4,
+    DW_CC_pass_by_value = 0x5,
     DW_CC_lo_user = 0x40,
     DW_CC_hi_user = 0xff
   };
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/9] libdw: Add DWARF5 attributes.
  2017-07-26 22:07 Some easy DWARF5 extensions Mark Wielaard
  2017-07-26 22:08 ` [PATCH 6/9] libdw: DWARF5 Add DW_CC_pass_by_reference and DW_CC_pass_by_reference Mark Wielaard
@ 2017-07-26 22:08 ` Mark Wielaard
  2017-07-26 22:08 ` [PATCH 4/9] libdw: DWARF5 Add new DW_LANG codes and default lower array bound Mark Wielaard
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Mark Wielaard @ 2017-07-26 22:08 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Add new DWARF5 attribute constant names to the attributes enum.
Also add reserved comments between non-consecutive (reserved) numbers.

Remove DW_AT_subscr_data, DW_AT_element_list and DW_AT_member from the
enum list and turn them into compatibility defines because they are
not part of DWARF2+. That way code that directly references them still
compiles but they won't show up in known-dwarf.h.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 ChangeLog       |  4 ++++
 NEWS            |  2 ++
 libdw/ChangeLog |  6 ++++++
 libdw/dwarf.h   | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 4 files changed, 71 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b5f7095..f787f76 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-07-25  Mark Wielaard  <mark@klomp.org>
+
+	* NEWS: Mention new DWARF5 attributes in dwarf.h.
+
 2017-07-18  Mark Wielaard  <mark@klomp.org>
 
 	* configure.ac: Don't check for linux/bpf.h.
diff --git a/NEWS b/NEWS
index 045d579..a97dd04 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,7 @@
 Version 0.170
 
+libdw: Added new DWARF5 attribute constants to dwarf.h.
+
 strip: Add -R, --remove-section=SECTION and --keep-section=SECTION.
 
 backends: The bpf disassembler is now always build on all platforms.
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 8b2ef75..a9a0a6b 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,9 @@
+2017-07-25  Mark Wielaard  <mark@klomp.org>
+
+	* dwarf.h (DWARF attributes enum): Remove DW_AT_subscr_data,
+	DW_AT_element_list and DW_AT_member. Add DWARF5 attribute constants.
+	(DW_AT_subscr_data, DW_AT_element_list, DW_AT_member): New defines.
+
 2017-07-21  Mark Wielaard  <mark@klomp.org>
 
 	* dwarf_line_file.c: New file.
diff --git a/libdw/dwarf.h b/libdw/dwarf.h
index 169b53e..de84423 100644
--- a/libdw/dwarf.h
+++ b/libdw/dwarf.h
@@ -1,5 +1,5 @@
 /* This file defines standard DWARF types, structures, and macros.
-   Copyright (C) 2000-2011, 2014, 2016 Red Hat, Inc.
+   Copyright (C) 2000-2011, 2014, 2016, 2017 Red Hat, Inc.
    This file is part of elfutils.
 
    This file is free software; you can redistribute it and/or modify
@@ -131,17 +131,23 @@ enum
     DW_AT_sibling = 0x01,
     DW_AT_location = 0x02,
     DW_AT_name = 0x03,
+    /* 0x04 reserved.  */
+    /* 0x05 reserved.  */
+    /* 0x06 reserved.  */
+    /* 0x07 reserved.  */
+    /* 0x08 reserved.  */
     DW_AT_ordering = 0x09,
-    DW_AT_subscr_data = 0x0a,
+    /* 0x0a reserved.  */
     DW_AT_byte_size = 0x0b,
-    DW_AT_bit_offset = 0x0c,
+    DW_AT_bit_offset = 0x0c,  /* Deprecated in DWARF4.  */
     DW_AT_bit_size = 0x0d,
-    DW_AT_element_list = 0x0f,
+    /* 0x0e reserved.  */
+    /* 0x0f reserved.  */
     DW_AT_stmt_list = 0x10,
     DW_AT_low_pc = 0x11,
     DW_AT_high_pc = 0x12,
     DW_AT_language = 0x13,
-    DW_AT_member = 0x14,
+    /* 0x14 reserved.  */
     DW_AT_discr = 0x15,
     DW_AT_discr_value = 0x16,
     DW_AT_visibility = 0x17,
@@ -152,15 +158,24 @@ enum
     DW_AT_const_value = 0x1c,
     DW_AT_containing_type = 0x1d,
     DW_AT_default_value = 0x1e,
+    /* 0x1f reserved.  */
     DW_AT_inline = 0x20,
     DW_AT_is_optional = 0x21,
     DW_AT_lower_bound = 0x22,
+    /* 0x23 reserved.  */
+    /* 0x24 reserved.  */
     DW_AT_producer = 0x25,
+    /* 0x26 reserved.  */
     DW_AT_prototyped = 0x27,
+    /* 0x28 reserved.  */
+    /* 0x29 reserved.  */
     DW_AT_return_addr = 0x2a,
+    /* 0x2b reserved.  */
     DW_AT_start_scope = 0x2c,
+    /* 0x2d reserved.  */
     DW_AT_bit_stride = 0x2e,
     DW_AT_upper_bound = 0x2f,
+    /* 0x30 reserved.  */
     DW_AT_abstract_origin = 0x31,
     DW_AT_accessibility = 0x32,
     DW_AT_address_class = 0x33,
@@ -179,7 +194,7 @@ enum
     DW_AT_frame_base = 0x40,
     DW_AT_friend = 0x41,
     DW_AT_identifier_case = 0x42,
-    DW_AT_macro_info = 0x43,
+    DW_AT_macro_info = 0x43, /* Deprecated in DWARF5.  */
     DW_AT_namelist_item = 0x44,
     DW_AT_priority = 0x45,
     DW_AT_segment = 0x46,
@@ -223,9 +238,36 @@ enum
     DW_AT_const_expr = 0x6c,
     DW_AT_enum_class = 0x6d,
     DW_AT_linkage_name = 0x6e,
-
-    /* DWARF5 attribute values.  */
+    DW_AT_string_length_bit_size = 0x6f,
+    DW_AT_string_length_byte_size = 0x70,
+    DW_AT_rank = 0x71,
+    DW_AT_str_offsets_base = 0x72,
+    DW_AT_addr_base = 0x73,
+    DW_AT_rnglists_base = 0x74,
+    /* 0x75 reserved.  */
+    DW_AT_dwo_name = 0x76,
+    DW_AT_reference = 0x77,
+    DW_AT_rvalue_reference = 0x78,
+    DW_AT_macros = 0x79,
+    DW_AT_call_all_calls = 0x7a,
+    DW_AT_call_all_source_calls = 0x7b,
+    DW_AT_call_all_tail_calls = 0x7c,
+    DW_AT_call_return_pc = 0x7d,
+    DW_AT_call_value = 0x7e,
+    DW_AT_call_origin = 0x7f,
+    DW_AT_call_parameter = 0x80,
+    DW_AT_call_pc = 0x81,
+    DW_AT_call_tail_call = 0x82,
+    DW_AT_call_target = 0x83,
+    DW_AT_call_target_clobbered = 0x84,
+    DW_AT_call_data_location = 0x85,
+    DW_AT_call_data_value = 0x86,
     DW_AT_noreturn = 0x87,
+    DW_AT_alignment = 0x88,
+    DW_AT_export_symbols = 0x89,
+    DW_AT_deleted = 0x8a,
+    DW_AT_defaulted = 0x8b,
+    DW_AT_loclists_base = 0x8c,
 
     DW_AT_lo_user = 0x2000,
 
@@ -278,6 +320,15 @@ enum
     DW_AT_hi_user = 0x3fff
   };
 
+/* Old unofficially attribute names.  Should not be used.
+   Will not appear in known-dwarf.h  */
+
+/* DWARF1 array subscripts and element data types.  */
+#define DW_AT_subscr_data	0x0a
+/* DWARF1 enumeration literals.  */
+#define DW_AT_element_list	0x0f
+/* DWARF1 reference for variable to member structure, class or union.  */
+#define DW_AT_member		0x14
 
 /* DWARF form encodings.  */
 enum
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 5/9] libdw: Add dwarf_default_lower_bound.
  2017-07-26 22:07 Some easy DWARF5 extensions Mark Wielaard
                   ` (7 preceding siblings ...)
  2017-07-26 22:08 ` [PATCH 8/9] libdw: Handle DWARF5 immutable, packed and shared in dwarf_peel_type Mark Wielaard
@ 2017-07-26 22:08 ` Mark Wielaard
  2017-08-02 12:03 ` Some easy DWARF5 extensions Mark Wielaard
  9 siblings, 0 replies; 11+ messages in thread
From: Mark Wielaard @ 2017-07-26 22:08 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Add dwarf_default_lower_bound to get the default lower bound for a language
when not given as attribute for an subrange type. Implementation extracted
from dwarf_aggregate_size.

Add a test to check all known language codes are handled.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 ChangeLog                         |  4 ++
 NEWS                              |  1 +
 libdw/ChangeLog                   | 11 +++++
 libdw/Makefile.am                 |  4 +-
 libdw/dwarf_aggregate_size.c      | 54 ++---------------------
 libdw/dwarf_default_lower_bound.c | 91 +++++++++++++++++++++++++++++++++++++++
 libdw/dwarf_error.c               |  1 +
 libdw/libdw.h                     |  6 +++
 libdw/libdw.map                   |  1 +
 libdw/libdwP.h                    |  4 +-
 tests/ChangeLog                   |  7 +++
 tests/Makefile.am                 |  5 ++-
 tests/dwarf_default_lower_bound.c | 83 +++++++++++++++++++++++++++++++++++
 13 files changed, 217 insertions(+), 55 deletions(-)
 create mode 100644 libdw/dwarf_default_lower_bound.c
 create mode 100644 tests/dwarf_default_lower_bound.c

diff --git a/ChangeLog b/ChangeLog
index d133061..25944f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
+	* NEWS: Mention new dwarf_default_lower_bound function.
+
 2017-07-25  Mark Wielaard  <mark@klomp.org>
 
 	* NEWS: Mention new DWARF5 attributes, tags, character encodings
diff --git a/NEWS b/NEWS
index 2039cfe..5bf0a4d 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ Version 0.170
 
 libdw: Added new DWARF5 attribute, tag, character encodings constants and
        language codes to dwarf.h.
+       New function dwarf_default_lower_bound.
 
 strip: Add -R, --remove-section=SECTION and --keep-section=SECTION.
 
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 39a9c1d..ee7dc92 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,16 @@
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
+	* dwarf_default_lower_bound.c: New file.
+	* Makefile.am (libdw_a_SOURCES): Add dwarf_default_lower_bound.c.
+	* dwarf_aggregate_size.c (array_size): Use dwarf_default_lower_bound.
+	* dwarf_error.c (errmsgs): Add DWARF_E_UNKNOWN_LANGUAGE.
+	* libdw.h: Add dwarf_default_lower_bound.
+	* libdw.map (ELFUTILS_0.170): Add dwarf_default_lower_bound.
+	* libdwP.h: Add DWARF_E_UNKNOWN_LANGUAGE and
+	dwarf_default_lower_bound INTDECL.
+
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
 	* dwarf.h: Add DW_LANG_OpenCL, DW_LANG_Modula3,
 	DW_LANG_C_plus_plus_03, DW_LANG_OCaml, DW_LANG_Rust, DW_LANG_Swift,
 	DW_LANG_Julia, DW_LANG_Dylan, DW_LANG_RenderScript, DW_LANG_BLISS.
diff --git a/libdw/Makefile.am b/libdw/Makefile.am
index ad031b1..ff8c291 100644
--- a/libdw/Makefile.am
+++ b/libdw/Makefile.am
@@ -1,6 +1,6 @@
 ## Process this file with automake to create Makefile.in
 ##
-## Copyright (C) 2002-2010, 2012, 2014 Red Hat, Inc.
+## Copyright (C) 2002-2010, 2012, 2014, 2016 Red Hat, Inc.
 ## This file is part of elfutils.
 ##
 ## This file is free software; you can redistribute it and/or modify
@@ -89,7 +89,7 @@ libdw_a_SOURCES = dwarf_begin.c dwarf_begin_elf.c dwarf_end.c dwarf_getelf.c \
 		  dwarf_aggregate_size.c dwarf_getlocation_implicit_pointer.c \
 		  dwarf_getlocation_die.c dwarf_getlocation_attr.c \
 		  dwarf_getalt.c dwarf_setalt.c dwarf_cu_getdwarf.c \
-		  dwarf_cu_die.c dwarf_peel_type.c
+		  dwarf_cu_die.c dwarf_peel_type.c dwarf_default_lower_bound.c
 
 if MAINTAINER_MODE
 BUILT_SOURCES = $(srcdir)/known-dwarf.h
diff --git a/libdw/dwarf_aggregate_size.c b/libdw/dwarf_aggregate_size.c
index 0472a9b..838468d 100644
--- a/libdw/dwarf_aggregate_size.c
+++ b/libdw/dwarf_aggregate_size.c
@@ -95,57 +95,11 @@ array_size (Dwarf_Die *die, Dwarf_Word *size,
 		}
 	      else
 		{
-		  /* Determine default lower bound from language,
-		     as per "4.12 Subrange Type Entries".  */
 		  Dwarf_Die cu = CUDIE (die->cu);
-		  switch (INTUSE(dwarf_srclang) (&cu))
-		    {
-		    case DW_LANG_C:
-		    case DW_LANG_C89:
-		    case DW_LANG_C99:
-		    case DW_LANG_C11:
-		    case DW_LANG_C_plus_plus:
-		    case DW_LANG_C_plus_plus_03:
-		    case DW_LANG_C_plus_plus_11:
-		    case DW_LANG_C_plus_plus_14:
-		    case DW_LANG_ObjC:
-		    case DW_LANG_ObjC_plus_plus:
-		    case DW_LANG_Java:
-		    case DW_LANG_D:
-		    case DW_LANG_Python:
-		    case DW_LANG_UPC:
-		    case DW_LANG_OpenCL:
-		    case DW_LANG_Go:
-		    case DW_LANG_Haskell:
-		    case DW_LANG_OCaml:
-		    case DW_LANG_Rust:
-		    case DW_LANG_Swift:
-		    case DW_LANG_Dylan:
-		    case DW_LANG_RenderScript:
-		    case DW_LANG_BLISS:
-		      lower = 0;
-		      break;
-
-		    case DW_LANG_Ada83:
-		    case DW_LANG_Ada95:
-		    case DW_LANG_Cobol74:
-		    case DW_LANG_Cobol85:
-		    case DW_LANG_Fortran77:
-		    case DW_LANG_Fortran90:
-		    case DW_LANG_Fortran95:
-		    case DW_LANG_Fortran03:
-		    case DW_LANG_Fortran08:
-		    case DW_LANG_Pascal83:
-		    case DW_LANG_Modula2:
-		    case DW_LANG_Modula3:
-		    case DW_LANG_PLI:
-		    case DW_LANG_Julia:
-		      lower = 1;
-		      break;
-
-		    default:
-		      return -1;
-		    }
+		  int lang = INTUSE(dwarf_srclang) (&cu);
+		  if (lang == -1
+		      || INTUSE(dwarf_default_lower_bound) (lang, &lower) != 0)
+		    return -1;
 		}
 	      if (unlikely (lower > upper))
 		return -1;
diff --git a/libdw/dwarf_default_lower_bound.c b/libdw/dwarf_default_lower_bound.c
new file mode 100644
index 0000000..a33a343
--- /dev/null
+++ b/libdw/dwarf_default_lower_bound.c
@@ -0,0 +1,91 @@
+/* Get the default subrange lower bound for a given language.
+   Copyright (C) 2016 Red Hat, Inc.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <dwarf.h>
+#include "libdwP.h"
+
+/* Determine default lower bound from language, as per the DWARF5
+   "Subrange Type Entries" table.  */
+int
+dwarf_default_lower_bound (int lang, Dwarf_Sword *result)
+{
+  switch (lang)
+    {
+    case DW_LANG_C:
+    case DW_LANG_C89:
+    case DW_LANG_C99:
+    case DW_LANG_C11:
+    case DW_LANG_C_plus_plus:
+    case DW_LANG_C_plus_plus_03:
+    case DW_LANG_C_plus_plus_11:
+    case DW_LANG_C_plus_plus_14:
+    case DW_LANG_ObjC:
+    case DW_LANG_ObjC_plus_plus:
+    case DW_LANG_Java:
+    case DW_LANG_D:
+    case DW_LANG_Python:
+    case DW_LANG_UPC:
+    case DW_LANG_OpenCL:
+    case DW_LANG_Go:
+    case DW_LANG_Haskell:
+    case DW_LANG_OCaml:
+    case DW_LANG_Rust:
+    case DW_LANG_Swift:
+    case DW_LANG_Dylan:
+    case DW_LANG_RenderScript:
+    case DW_LANG_BLISS:
+      *result = 0;
+      return 0;
+
+    case DW_LANG_Ada83:
+    case DW_LANG_Ada95:
+    case DW_LANG_Cobol74:
+    case DW_LANG_Cobol85:
+    case DW_LANG_Fortran77:
+    case DW_LANG_Fortran90:
+    case DW_LANG_Fortran95:
+    case DW_LANG_Fortran03:
+    case DW_LANG_Fortran08:
+    case DW_LANG_Pascal83:
+    case DW_LANG_Modula2:
+    case DW_LANG_Modula3:
+    case DW_LANG_PLI:
+    case DW_LANG_Julia:
+      *result = 1;
+      return 0;
+
+    default:
+      __libdw_seterrno (DWARF_E_UNKNOWN_LANGUAGE);
+      return -1;
+    }
+}
+INTDEF (dwarf_default_lower_bound)
diff --git a/libdw/dwarf_error.c b/libdw/dwarf_error.c
index 66fdc81..939ec04 100644
--- a/libdw/dwarf_error.c
+++ b/libdw/dwarf_error.c
@@ -95,6 +95,7 @@ static const char *errmsgs[] =
     [DWARF_E_NO_ALT_DEBUGLINK] = N_("no alternative debug link found"),
     [DWARF_E_INVALID_OPCODE] = N_("invalid opcode"),
     [DWARF_E_NOT_CUDIE] = N_("not a CU (unit) DIE"),
+    [DWARF_E_UNKNOWN_LANGUAGE] = N_("unknown language code")
   };
 #define nerrmsgs (sizeof (errmsgs) / sizeof (errmsgs[0]))
 
diff --git a/libdw/libdw.h b/libdw/libdw.h
index 4903b55..49c4ebb 100644
--- a/libdw/libdw.h
+++ b/libdw/libdw.h
@@ -733,6 +733,12 @@ extern int dwarf_getlocation_attr (Dwarf_Attribute *attr,
    For DW_TAG_array_type it can apply much more complex rules.  */
 extern int dwarf_aggregate_size (Dwarf_Die *die, Dwarf_Word *size);
 
+/* Given a language code, as returned by dwarf_srclan, get the default
+   lower bound for a subrange type without a lower bound attribute.
+   Returns zero on success or -1 on failure when the given language
+   wasn't recognized.  */
+extern int dwarf_default_lower_bound (int lang, Dwarf_Sword *result)
+  __nonnull_attribute__ (2);
 
 /* Return scope DIEs containing PC address.
    Sets *SCOPES to a malloc'd array of Dwarf_Die structures,
diff --git a/libdw/libdw.map b/libdw/libdw.map
index 44e096a..1430705 100644
--- a/libdw/libdw.map
+++ b/libdw/libdw.map
@@ -341,5 +341,6 @@ ELFUTILS_0.167 {
 
 ELFUTILS_0.170 {
   global:
+    dwarf_default_lower_bound;
     dwarf_line_file;
 } ELFUTILS_0.167;
diff --git a/libdw/libdwP.h b/libdw/libdwP.h
index 5d095a7..6ad322c 100644
--- a/libdw/libdwP.h
+++ b/libdw/libdwP.h
@@ -1,5 +1,5 @@
 /* Internal definitions for libdwarf.
-   Copyright (C) 2002-2011, 2013-2015 Red Hat, Inc.
+   Copyright (C) 2002-2011, 2013-2016 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -130,6 +130,7 @@ enum
   DWARF_E_NO_ALT_DEBUGLINK,
   DWARF_E_INVALID_OPCODE,
   DWARF_E_NOT_CUDIE,
+  DWARF_E_UNKNOWN_LANGUAGE,
 };
 
 
@@ -764,6 +765,7 @@ INTDECL (dwarf_attr_integrate)
 INTDECL (dwarf_begin)
 INTDECL (dwarf_begin_elf)
 INTDECL (dwarf_child)
+INTDECL (dwarf_default_lower_bound)
 INTDECL (dwarf_dieoffset)
 INTDECL (dwarf_diename)
 INTDECL (dwarf_end)
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 519f25a..fa3f94e 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
+	* dwarf_default_lower_bound.c: New test.
+	* Makefile.am (check_PROGRAMS): Add dwarf_default_lower_bound.
+	(TESTS): Likewise.
+	(dwarf_default_lower_bound_LDADD): New variable.
+
 2017-07-21  Mark Wielaard  <mark@klomp.org>
 
 	* get-lines.c (main): Add dwarf_line_file test.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 407c051..3735084 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -55,7 +55,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
 		  getsrc_die strptr newdata elfstrtab dwfl-proc-attach \
 		  elfshphehdr elfstrmerge dwelfgnucompressed elfgetchdr \
 		  elfgetzdata elfputzdata zstrptr emptyfile vendorelf \
-		  fillfile
+		  fillfile dwarf_default_lower_bound
 
 asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
 	    asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -135,7 +135,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
 	run-elfgetzdata.sh run-elfputzdata.sh run-zstrptr.sh \
 	run-compress-test.sh \
 	run-readelf-zdebug.sh run-readelf-zdebug-rel.sh \
-	emptyfile vendorelf fillfile
+	emptyfile vendorelf fillfile dwarf_default_lower_bound
 
 if !BIARCH
 export ELFUTILS_DISABLE_BIARCH = 1
@@ -505,6 +505,7 @@ zstrptr_LDADD = $(libelf)
 emptyfile_LDADD = $(libelf)
 vendorelf_LDADD = $(libelf)
 fillfile_LDADD = $(libelf)
+dwarf_default_lower_bound_LDADD = $(libdw)
 
 # We want to test the libelf header against the system elf.h header.
 # Don't include any -I CPPFLAGS.
diff --git a/tests/dwarf_default_lower_bound.c b/tests/dwarf_default_lower_bound.c
new file mode 100644
index 0000000..d57424f
--- /dev/null
+++ b/tests/dwarf_default_lower_bound.c
@@ -0,0 +1,83 @@
+/* Test all DW_LANG constants are handled by dwarf_default_lower_bound.
+
+   Copyright (C) 2016 Red Hat, Inc.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <dwarf.h>
+#include ELFUTILS_HEADER(dw)
+#include "../libdw/known-dwarf.h"
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static void
+test_lang (const char *name, int lang)
+{
+  Dwarf_Sword low;
+  int res = dwarf_default_lower_bound (lang, &low);
+
+  /* Assembler is special, it doesn't really have arrays.  */
+  if (lang == DW_LANG_Mips_Assembler)
+    {
+      if (res == 0)
+	{
+	  printf ("%s shouldn't have a known lower bound\n", name);
+	  exit (-1);
+	}
+      printf ("%s: <unknown>\n", name);
+      return;
+    }
+
+  if (res != 0)
+    {
+      printf ("dwarf_default_lower_bound failed (%d) for %s\n", res, name);
+      exit (-1);
+    }
+
+  /* All currently known lower bounds are either zero or one, but
+     they don't have to.  Update test once one is a different value.  */
+  if (low != 0 && low != 1)
+    {
+      printf ("unexpected lower bound %" PRId64 " for %s\n", low, name);
+      exit (-1);
+    }
+
+  printf ("%s: %" PRId64 "\n", name, low);
+}
+
+int
+main (int argc __attribute__ ((unused)), char *argv[] __attribute__ ((unused)))
+{
+  Dwarf_Sword low;
+  /* Bad language code must fail.  */
+  if (dwarf_default_lower_bound (-1, &low) == 0)
+    {
+      printf ("Bad lang code -1 succeeded (%" PRId64 ")\n", low);
+      exit (-1);
+    }
+
+  /* Test all known language codes.  */
+#define DWARF_ONE_KNOWN_DW_LANG(NAME, CODE) test_lang (#NAME, CODE);
+  DWARF_ALL_KNOWN_DW_LANG
+#undef DWARF_ONE_KNOWN_DW_LANG
+
+  return 0;
+}
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 4/9] libdw: DWARF5 Add new DW_LANG codes and default lower array bound.
  2017-07-26 22:07 Some easy DWARF5 extensions Mark Wielaard
  2017-07-26 22:08 ` [PATCH 6/9] libdw: DWARF5 Add DW_CC_pass_by_reference and DW_CC_pass_by_reference Mark Wielaard
  2017-07-26 22:08 ` [PATCH 1/9] libdw: Add DWARF5 attributes Mark Wielaard
@ 2017-07-26 22:08 ` Mark Wielaard
  2017-07-26 22:08 ` [PATCH 2/9] libdw: Add new DWARF5 tag constants Mark Wielaard
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Mark Wielaard @ 2017-07-26 22:08 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Add DW_LANG_OpenCL, DW_LANG_Modula3, DW_LANG_C_plus_plus_03,
DW_LANG_OCaml, DW_LANG_Rust, DW_LANG_Swift, DW_LANG_Julia,
DW_LANG_Dylan, DW_LANG_RenderScript and DW_LANG_BLISS to dwarf.h.

Update default language array lower bounds in dwarf_aggregate_size.c.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 ChangeLog                    |  4 ++--
 NEWS                         |  4 ++--
 libdw/ChangeLog              | 11 +++++++++++
 libdw/dwarf.h                | 11 ++++++++++-
 libdw/dwarf_aggregate_size.c | 12 ++++++++++++
 5 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cd91c5a..d133061 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,7 @@
 2017-07-25  Mark Wielaard  <mark@klomp.org>
 
-	* NEWS: Mention new DWARF5 attributes, tags and character encodings
-	in dwarf.h.
+	* NEWS: Mention new DWARF5 attributes, tags, character encodings
+	and language codes in dwarf.h.
 
 2017-07-18  Mark Wielaard  <mark@klomp.org>
 
diff --git a/NEWS b/NEWS
index 9437061..2039cfe 100644
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,7 @@
 Version 0.170
 
-libdw: Added new DWARF5 attribute, tag and character encodings constants
-       to dwarf.h.
+libdw: Added new DWARF5 attribute, tag, character encodings constants and
+       language codes to dwarf.h.
 
 strip: Add -R, --remove-section=SECTION and --keep-section=SECTION.
 
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 25a9648..39a9c1d 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,16 @@
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
+	* dwarf.h: Add DW_LANG_OpenCL, DW_LANG_Modula3,
+	DW_LANG_C_plus_plus_03, DW_LANG_OCaml, DW_LANG_Rust, DW_LANG_Swift,
+	DW_LANG_Julia, DW_LANG_Dylan, DW_LANG_RenderScript, DW_LANG_BLISS.
+	* dwarf_aggregate_size.c (array_size): Add lower bound for
+	DW_LANG_C_plus_plus_03, DW_LANG_Python, DW_LANG_OpenCL,
+	DW_LANG_Haskell, DW_LANG_OCaml, DW_LANG_Rust, DW_LANG_Swift,
+	DW_LANG_Dylan, DW_LANG_RenderScript, DW_LANG_Modula3,
+	DW_LANG_Julia and DW_LANG_BLISS.
+
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
 	* dwarf.h: Add DW_ATE_UCS and DW_ATE_ASCII.
 
 2017-07-25  Mark Wielaard  <mark@klomp.org>
diff --git a/libdw/dwarf.h b/libdw/dwarf.h
index 4072272..dd4384f 100644
--- a/libdw/dwarf.h
+++ b/libdw/dwarf.h
@@ -652,14 +652,23 @@ enum
     DW_LANG_UPC = 0x0012,	     /* Unified Parallel C */
     DW_LANG_D = 0x0013,		     /* D */
     DW_LANG_Python = 0x0014,	     /* Python */
+    DW_LANG_OpenCL = 0x0015,	     /* OpenCL */
     DW_LANG_Go = 0x0016,	     /* Go */
+    DW_LANG_Modula3 = 0x0017,	     /* Modula-3 */
     DW_LANG_Haskell = 0x0018,	     /* Haskell */
+    DW_LANG_C_plus_plus_03 = 0x0019, /* ISO C++:2003 */
     DW_LANG_C_plus_plus_11 = 0x001a, /* ISO C++:2011 */
+    DW_LANG_OCaml = 0x001b,	     /* OCaml */
+    DW_LANG_Rust = 0x001c,	     /* Rust */
     DW_LANG_C11 = 0x001d,	     /* ISO C:2011 */
+    DW_LANG_Swift = 0x001e,	     /* Swift */
+    DW_LANG_Julia = 0x001f,	     /* Julia */
+    DW_LANG_Dylan = 0x0020,	     /* Dylan */
     DW_LANG_C_plus_plus_14 = 0x0021, /* ISO C++:2014 */
     DW_LANG_Fortran03 = 0x0022,	     /* ISO/IEC 1539-1:2004 */
     DW_LANG_Fortran08 = 0x0023,	     /* ISO/IEC 1539-1:2010 */
-
+    DW_LANG_RenderScript = 0x0024,   /* RenderScript Kernal Language */
+    DW_LANG_BLISS = 0x0025,	     /* BLISS */
 
     DW_LANG_lo_user = 0x8000,
     DW_LANG_Mips_Assembler = 0x8001, /* Assembler */
diff --git a/libdw/dwarf_aggregate_size.c b/libdw/dwarf_aggregate_size.c
index 52ef006..0472a9b 100644
--- a/libdw/dwarf_aggregate_size.c
+++ b/libdw/dwarf_aggregate_size.c
@@ -105,14 +105,24 @@ array_size (Dwarf_Die *die, Dwarf_Word *size,
 		    case DW_LANG_C99:
 		    case DW_LANG_C11:
 		    case DW_LANG_C_plus_plus:
+		    case DW_LANG_C_plus_plus_03:
 		    case DW_LANG_C_plus_plus_11:
 		    case DW_LANG_C_plus_plus_14:
 		    case DW_LANG_ObjC:
 		    case DW_LANG_ObjC_plus_plus:
 		    case DW_LANG_Java:
 		    case DW_LANG_D:
+		    case DW_LANG_Python:
 		    case DW_LANG_UPC:
+		    case DW_LANG_OpenCL:
 		    case DW_LANG_Go:
+		    case DW_LANG_Haskell:
+		    case DW_LANG_OCaml:
+		    case DW_LANG_Rust:
+		    case DW_LANG_Swift:
+		    case DW_LANG_Dylan:
+		    case DW_LANG_RenderScript:
+		    case DW_LANG_BLISS:
 		      lower = 0;
 		      break;
 
@@ -127,7 +137,9 @@ array_size (Dwarf_Die *die, Dwarf_Word *size,
 		    case DW_LANG_Fortran08:
 		    case DW_LANG_Pascal83:
 		    case DW_LANG_Modula2:
+		    case DW_LANG_Modula3:
 		    case DW_LANG_PLI:
+		    case DW_LANG_Julia:
 		      lower = 1;
 		      break;
 
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/9] libdw: Add new DWARF5 tag constants.
  2017-07-26 22:07 Some easy DWARF5 extensions Mark Wielaard
                   ` (2 preceding siblings ...)
  2017-07-26 22:08 ` [PATCH 4/9] libdw: DWARF5 Add new DW_LANG codes and default lower array bound Mark Wielaard
@ 2017-07-26 22:08 ` Mark Wielaard
  2017-07-26 22:08 ` [PATCH 9/9] libdw: Add DW_MACRO constants and DW_MACRO_GNU compatibility defines Mark Wielaard
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Mark Wielaard @ 2017-07-26 22:08 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Add DW_TAG_coarray_type, DW_TAG_generic_subrange, DW_TAG_dynamic_type,
DW_TAG_call_site, DW_TAG_call_site_parameter, DW_TAG_skeleton_unit,
DW_TAG_immutable_type.

Just the constants, no further interpretion yet.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 ChangeLog       |  2 +-
 NEWS            |  2 +-
 libdw/ChangeLog |  7 +++++++
 libdw/dwarf.h   | 17 ++++++++++++++---
 4 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f787f76..09c8d14 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,6 @@
 2017-07-25  Mark Wielaard  <mark@klomp.org>
 
-	* NEWS: Mention new DWARF5 attributes in dwarf.h.
+	* NEWS: Mention new DWARF5 attributes and tags in dwarf.h.
 
 2017-07-18  Mark Wielaard  <mark@klomp.org>
 
diff --git a/NEWS b/NEWS
index a97dd04..6a5ee0d 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,6 @@
 Version 0.170
 
-libdw: Added new DWARF5 attribute constants to dwarf.h.
+libdw: Added new DWARF5 attribute and tag constants to dwarf.h.
 
 strip: Add -R, --remove-section=SECTION and --keep-section=SECTION.
 
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index a9a0a6b..4bf46c0 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,12 @@
 2017-07-25  Mark Wielaard  <mark@klomp.org>
 
+	* dwarf.h: Add DW_TAG_coarray_type, DW_TAG_generic_subrange,
+	DW_TAG_dynamic_type, DW_TAG_call_site, DW_TAG_call_site_parameter,
+	DW_TAG_skeleton_unit, DW_TAG_immutable_type. Add reserved comments
+	for currently unused numbers.
+
+2017-07-25  Mark Wielaard  <mark@klomp.org>
+
 	* dwarf.h (DWARF attributes enum): Remove DW_AT_subscr_data,
 	DW_AT_element_list and DW_AT_member. Add DWARF5 attribute constants.
 	(DW_AT_subscr_data, DW_AT_element_list, DW_AT_member): New defines.
diff --git a/libdw/dwarf.h b/libdw/dwarf.h
index de84423..c998784 100644
--- a/libdw/dwarf.h
+++ b/libdw/dwarf.h
@@ -37,15 +37,21 @@ enum
     DW_TAG_entry_point = 0x03,
     DW_TAG_enumeration_type = 0x04,
     DW_TAG_formal_parameter = 0x05,
+    /* 0x06 reserved.  */
+    /* 0x07 reserved.  */
     DW_TAG_imported_declaration = 0x08,
+    /* 0x09 reserved.  */
     DW_TAG_label = 0x0a,
     DW_TAG_lexical_block = 0x0b,
+    /* 0x0c reserved.  */
     DW_TAG_member = 0x0d,
+    /* 0x0e reserved.  */
     DW_TAG_pointer_type = 0x0f,
     DW_TAG_reference_type = 0x10,
     DW_TAG_compile_unit = 0x11,
     DW_TAG_string_type = 0x12,
     DW_TAG_structure_type = 0x13,
+    /* 0x14 reserved.  */
     DW_TAG_subroutine_type = 0x15,
     DW_TAG_typedef = 0x16,
     DW_TAG_union_type = 0x17,
@@ -87,15 +93,20 @@ enum
     DW_TAG_unspecified_type = 0x3b,
     DW_TAG_partial_unit = 0x3c,
     DW_TAG_imported_unit = 0x3d,
-    /* 0x3e reserved.  */
+    /* 0x3e reserved.  Was DW_TAG_mutable_type.  */
     DW_TAG_condition = 0x3f,
     DW_TAG_shared_type = 0x40,
     DW_TAG_type_unit = 0x41,
     DW_TAG_rvalue_reference_type = 0x42,
     DW_TAG_template_alias = 0x43,
-
-    /* DWARF 5.  */
+    DW_TAG_coarray_type = 0x44,
+    DW_TAG_generic_subrange = 0x45,
+    DW_TAG_dynamic_type = 0x46,
     DW_TAG_atomic_type = 0x47,
+    DW_TAG_call_site = 0x48,
+    DW_TAG_call_site_parameter = 0x49,
+    DW_TAG_skeleton_unit = 0x4a,
+    DW_TAG_immutable_type = 0x4b,
 
     DW_TAG_lo_user = 0x4080,
 
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 3/9] libdw: Add new DWARF5 character encodings.
  2017-07-26 22:07 Some easy DWARF5 extensions Mark Wielaard
                   ` (4 preceding siblings ...)
  2017-07-26 22:08 ` [PATCH 9/9] libdw: Add DW_MACRO constants and DW_MACRO_GNU compatibility defines Mark Wielaard
@ 2017-07-26 22:08 ` Mark Wielaard
  2017-07-26 22:08 ` [PATCH 7/9] Handle DWARF5 defaulted member function encodings Mark Wielaard
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Mark Wielaard @ 2017-07-26 22:08 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Add DW_ATE_UCS and DW_ATE_ASCII for Fortran 2003 string kinds ASCII
(ISO/IEC 646:1991) and ISO_10646 (UCS-4 in ISO/IEC 10646:2000).

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 ChangeLog       | 3 ++-
 NEWS            | 3 ++-
 libdw/ChangeLog | 4 ++++
 libdw/dwarf.h   | 2 ++
 4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 09c8d14..cd91c5a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2017-07-25  Mark Wielaard  <mark@klomp.org>
 
-	* NEWS: Mention new DWARF5 attributes and tags in dwarf.h.
+	* NEWS: Mention new DWARF5 attributes, tags and character encodings
+	in dwarf.h.
 
 2017-07-18  Mark Wielaard  <mark@klomp.org>
 
diff --git a/NEWS b/NEWS
index 6a5ee0d..9437061 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 Version 0.170
 
-libdw: Added new DWARF5 attribute and tag constants to dwarf.h.
+libdw: Added new DWARF5 attribute, tag and character encodings constants
+       to dwarf.h.
 
 strip: Add -R, --remove-section=SECTION and --keep-section=SECTION.
 
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 4bf46c0..25a9648 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
+	* dwarf.h: Add DW_ATE_UCS and DW_ATE_ASCII.
+
 2017-07-25  Mark Wielaard  <mark@klomp.org>
 
 	* dwarf.h: Add DW_TAG_coarray_type, DW_TAG_generic_subrange,
diff --git a/libdw/dwarf.h b/libdw/dwarf.h
index c998784..4072272 100644
--- a/libdw/dwarf.h
+++ b/libdw/dwarf.h
@@ -571,6 +571,8 @@ enum
     DW_ATE_unsigned_fixed = 0xe,
     DW_ATE_decimal_float = 0xf,
     DW_ATE_UTF = 0x10,
+    DW_ATE_UCS = 0x11,
+    DW_ATE_ASCII = 0x12,
 
     DW_ATE_lo_user = 0x80,
     DW_ATE_hi_user = 0xff
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 7/9] Handle DWARF5 defaulted member function encodings.
  2017-07-26 22:07 Some easy DWARF5 extensions Mark Wielaard
                   ` (5 preceding siblings ...)
  2017-07-26 22:08 ` [PATCH 3/9] libdw: Add new DWARF5 character encodings Mark Wielaard
@ 2017-07-26 22:08 ` Mark Wielaard
  2017-07-26 22:08 ` [PATCH 8/9] libdw: Handle DWARF5 immutable, packed and shared in dwarf_peel_type Mark Wielaard
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Mark Wielaard @ 2017-07-26 22:08 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Add DW_DEFAULTED_no, DW_DEFAULTED_in_class and DW_DEFAULTED_out_of_class
to dwarf.h.

Print value (no, in_class or out_of_class) of DW_AT_defaulted in readelf.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 ChangeLog       |  3 ++-
 NEWS            |  4 ++--
 libdw/ChangeLog |  5 +++++
 libdw/dwarf.h   |  8 ++++++++
 src/ChangeLog   |  7 +++++++
 src/readelf.c   | 28 ++++++++++++++++++++++++++++
 6 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7748f13..b4722db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
-	* NEWS: Mention new DWARF5 calling conventions.
+	* NEWS: Mention new DWARF5 calling conventions and defaulted member
+	function.
 
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
diff --git a/NEWS b/NEWS
index 409805e..5f85fc2 100644
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,7 @@
 Version 0.170
 
-libdw: Added new DWARF5 attribute, tag, character encoding, language code
-       and calling convention constants to dwarf.h.
+libdw: Added new DWARF5 attribute, tag, character encoding, language code,
+       calling convention and defaulted member function constants to dwarf.h.
        New function dwarf_default_lower_bound.
 
 strip: Add -R, --remove-section=SECTION and --keep-section=SECTION.
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 1c4eb36..a74733c 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,10 @@
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
+	* dwarf.h: Add DW_DEFAULTED_no, DW_DEFAULTED_in_class and
+	DW_DEFAULTED_out_of_class.
+
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
 	* dwarf.h: Add DW_CC_pass_by_reference and DW_CC_pass_by_reference.
 
 2017-07-26  Mark Wielaard  <mark@klomp.org>
diff --git a/libdw/dwarf.h b/libdw/dwarf.h
index de8f7e5..82a68f2 100644
--- a/libdw/dwarf.h
+++ b/libdw/dwarf.h
@@ -729,6 +729,14 @@ enum
     DW_DSC_range = 1
   };
 
+/* DWARF defaulted member function encodings.  */
+enum
+  {
+    DW_DEFAULTED_no = 0,
+    DW_DEFAULTED_in_class = 1,
+    DW_DEFAULTED_out_of_class = 2
+  };
+
 
 /* DWARF standard opcode encodings.  */
 enum
diff --git a/src/ChangeLog b/src/ChangeLog
index f92f10d..3ebc704 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (dwarf_defaulted_string): New function.
+	(dwarf_defaulted_name): Likewise.
+	(attr_callback): Use dwarf_defaulted_name to get value of
+	DW_AT_defaulted.
+
 2017-07-20  Mark Wielaard  <mark@klomp.org>
 
 	* strip.c (handle_elf): Deal with data marker symbols pointing to
diff --git a/src/readelf.c b/src/readelf.c
index 40d4913..5e1685d 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -3797,6 +3797,23 @@ dwarf_access_string (unsigned int code)
 
 
 static const char *
+dwarf_defaulted_string (unsigned int code)
+{
+  static const char *const known[] =
+    {
+#define DWARF_ONE_KNOWN_DW_DEFAULTED(NAME, CODE) [CODE] = #NAME,
+      DWARF_ALL_KNOWN_DW_DEFAULTED
+#undef DWARF_ONE_KNOWN_DW_DEFAULTED
+    };
+
+  if (likely (code < sizeof (known) / sizeof (known[0])))
+    return known[code];
+
+  return NULL;
+}
+
+
+static const char *
 dwarf_visibility_string (unsigned int code)
 {
   static const char *const known[] =
@@ -4002,6 +4019,14 @@ dwarf_access_name (unsigned int code)
 
 
 static const char *
+dwarf_defaulted_name (unsigned int code)
+{
+  const char *ret = dwarf_defaulted_string (code);
+  return string_or_unknown (ret, code, 0, 0, false);
+}
+
+
+static const char *
 dwarf_visibility_name (unsigned int code)
 {
   const char *ret = dwarf_visibility_string (code);
@@ -6053,6 +6078,9 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
 	case DW_AT_accessibility:
 	  valuestr = dwarf_access_name (num);
 	  break;
+	case DW_AT_defaulted:
+	  valuestr = dwarf_defaulted_name (num);
+	  break;
 	case DW_AT_visibility:
 	  valuestr = dwarf_visibility_name (num);
 	  break;
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 8/9] libdw: Handle DWARF5 immutable, packed and shared in dwarf_peel_type.
  2017-07-26 22:07 Some easy DWARF5 extensions Mark Wielaard
                   ` (6 preceding siblings ...)
  2017-07-26 22:08 ` [PATCH 7/9] Handle DWARF5 defaulted member function encodings Mark Wielaard
@ 2017-07-26 22:08 ` Mark Wielaard
  2017-07-26 22:08 ` [PATCH 5/9] libdw: Add dwarf_default_lower_bound Mark Wielaard
  2017-08-02 12:03 ` Some easy DWARF5 extensions Mark Wielaard
  9 siblings, 0 replies; 11+ messages in thread
From: Mark Wielaard @ 2017-07-26 22:08 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Also update the documentation to explain that any type alias or modifier
that doesn't modify, change the structural layout or the way to access
the underlying type is peeled. Explicitly mention pointer and reference
types as examples of modifiers that don't obey that rule and so aren't
peeled.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 ChangeLog               |  4 ++++
 NEWS                    |  1 +
 libdw/ChangeLog         |  6 ++++++
 libdw/dwarf_peel_type.c |  7 +++++--
 libdw/libdw.h           | 28 ++++++++++++++++++----------
 5 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b4722db..b7efc84 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
+	* NEWS: Mention dwarf_peel_type DWARF5 tags improvement.
+
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
 	* NEWS: Mention new DWARF5 calling conventions and defaulted member
 	function.
 
diff --git a/NEWS b/NEWS
index 5f85fc2..054ac95 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ Version 0.170
 libdw: Added new DWARF5 attribute, tag, character encoding, language code,
        calling convention and defaulted member function constants to dwarf.h.
        New function dwarf_default_lower_bound.
+       dwarf_peel_type now handles DWARF5 immutable, packed and shared tags.
 
 strip: Add -R, --remove-section=SECTION and --keep-section=SECTION.
 
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index a74733c..d0b3f4c 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,11 @@
 2017-07-26  Mark Wielaard  <mark@klomp.org>
 
+	* dwarf_peel_type.c (dwarf_peel_type): Handle DW_TAG_immutable_type,
+	DW_TAG_packed_type and DW_TAG_shared_type.
+	* libdw.h (dwarf_peel_type): Extend documentation.
+
+2017-07-26  Mark Wielaard  <mark@klomp.org>
+
 	* dwarf.h: Add DW_DEFAULTED_no, DW_DEFAULTED_in_class and
 	DW_DEFAULTED_out_of_class.
 
diff --git a/libdw/dwarf_peel_type.c b/libdw/dwarf_peel_type.c
index 9735694..6bbfd42 100644
--- a/libdw/dwarf_peel_type.c
+++ b/libdw/dwarf_peel_type.c
@@ -1,5 +1,5 @@
 /* Peel type aliases and qualifier tags from a type DIE.
-   Copyright (C) 2014, 2015 Red Hat, Inc.
+   Copyright (C) 2014, 2015, 2016 Red Hat, Inc.
    This file is part of elfutils.
 
    This file is free software; you can redistribute it and/or modify
@@ -50,7 +50,10 @@ dwarf_peel_type (Dwarf_Die *die, Dwarf_Die *result)
 	 || tag == DW_TAG_const_type
 	 || tag == DW_TAG_volatile_type
 	 || tag == DW_TAG_restrict_type
-	 || tag == DW_TAG_atomic_type)
+	 || tag == DW_TAG_atomic_type
+	 || tag == DW_TAG_immutable_type
+	 || tag == DW_TAG_packed_type
+	 || tag == DW_TAG_shared_type)
     {
       Dwarf_Attribute attr_mem;
       Dwarf_Attribute *attr = INTUSE (dwarf_attr_integrate) (result, DW_AT_type,
diff --git a/libdw/libdw.h b/libdw/libdw.h
index 49c4ebb..63a38ff 100644
--- a/libdw/libdw.h
+++ b/libdw/libdw.h
@@ -1,5 +1,5 @@
 /* Interfaces for libdw.
-   Copyright (C) 2002-2010, 2013, 2014 Red Hat, Inc.
+   Copyright (C) 2002-2010, 2013, 2014, 2016 Red Hat, Inc.
    This file is part of elfutils.
 
    This file is free software; you can redistribute it and/or modify
@@ -378,8 +378,11 @@ extern int dwarf_child (Dwarf_Die *die, Dwarf_Die *result)
 extern int dwarf_siblingof (Dwarf_Die *die, Dwarf_Die *result)
      __nonnull_attribute__ (2);
 
-/* For type aliases and qualifier type DIEs follow the DW_AT_type
-   attribute (recursively) and return the underlying type Dwarf_Die.
+/* For type aliases and qualifier type DIEs, which don't modify or
+   change the structural layout of the underlying type, follow the
+   DW_AT_type attribute (recursively) and return the underlying type
+   Dwarf_Die.
+
    Returns 0 when RESULT contains a Dwarf_Die (possibly equal to the
    given DIE) that isn't a type alias or qualifier type.  Returns 1
    when RESULT contains a type alias or qualifier Dwarf_Die that
@@ -387,13 +390,18 @@ extern int dwarf_siblingof (Dwarf_Die *die, Dwarf_Die *result)
    attribute).  Returns -1 when an error occured.
 
    The current DWARF specification defines one type alias tag
-   (DW_TAG_typedef) and three qualifier type tags (DW_TAG_const_type,
-   DW_TAG_volatile_type, DW_TAG_restrict_type).  DWARF5 defines one
-   other qualifier type tag (DW_TAG_atomic_type).  A future version of
-   this function might peel other alias or qualifier type tags if a
-   future DWARF version or GNU extension defines other type aliases or
-   qualifier type tags that don't modify or change the structural
-   layout of the underlying type.  */
+   (DW_TAG_typedef) and seven modifier/qualifier type tags
+   (DW_TAG_const_type, DW_TAG_volatile_type, DW_TAG_restrict_type,
+   DW_TAG_atomic_type, DW_TAG_immutable_type, DW_TAG_packed_type and
+   DW_TAG_shared_type).  This function won't peel modifier type
+   tags that change the way the underlying type is accessed such
+   as the pointer or reference type tags (DW_TAG_pointer_type,
+   DW_TAG_reference_type or DW_TAG_rvalue_reference_type).
+
+   A future version of this function might peel other alias or
+   qualifier type tags if a future DWARF version or GNU extension
+   defines other type aliases or qualifier type tags that don't modify,
+   change the structural layout or the way to access the underlying type.  */
 extern int dwarf_peel_type (Dwarf_Die *die, Dwarf_Die *result)
     __nonnull_attribute__ (2);
 
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Some easy DWARF5 extensions
  2017-07-26 22:07 Some easy DWARF5 extensions Mark Wielaard
                   ` (8 preceding siblings ...)
  2017-07-26 22:08 ` [PATCH 5/9] libdw: Add dwarf_default_lower_bound Mark Wielaard
@ 2017-08-02 12:03 ` Mark Wielaard
  9 siblings, 0 replies; 11+ messages in thread
From: Mark Wielaard @ 2017-08-02 12:03 UTC (permalink / raw)
  To: elfutils-devel

On Thu, 2017-07-27 at 00:07 +0200, Mark Wielaard wrote:
> The following are all the easy DWARF5 extensions that a compiler might
> emit in "non-strict" DWARF mode (when it uses tags, attributes or other
> constants from a later version of DWARF).
> 
> [PATCH 1/9] libdw: Add DWARF5 attributes.
> [PATCH 2/9] libdw: Add new DWARF5 tag constants.
> [PATCH 3/9] libdw: Add new DWARF5 character encodings.
> [PATCH 4/9] libdw: DWARF5 Add new DW_LANG codes and default lower
> [PATCH 5/9] libdw: Add dwarf_default_lower_bound.
> [PATCH 6/9] libdw: DWARF5 Add DW_CC_pass_by_reference and
> [PATCH 7/9] Handle DWARF5 defaulted member function encodings.
> [PATCH 8/9] libdw: Handle DWARF5 immutable, packed and shared in
> [PATCH 9/9] libdw: Add DW_MACRO constants and DW_MACRO_GNU
> [...]
> I believe the above patches however are ready and I would like to include
> them in the next release. It has been 3 months since the last one, so it
> is time to do a new one soon. It would be nice to at least handle these
> easy parts of DWARF5 with elfutils 0.170.

I pushed these 9 patches to master now.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-08-02 12:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-26 22:07 Some easy DWARF5 extensions Mark Wielaard
2017-07-26 22:08 ` [PATCH 6/9] libdw: DWARF5 Add DW_CC_pass_by_reference and DW_CC_pass_by_reference Mark Wielaard
2017-07-26 22:08 ` [PATCH 1/9] libdw: Add DWARF5 attributes Mark Wielaard
2017-07-26 22:08 ` [PATCH 4/9] libdw: DWARF5 Add new DW_LANG codes and default lower array bound Mark Wielaard
2017-07-26 22:08 ` [PATCH 2/9] libdw: Add new DWARF5 tag constants Mark Wielaard
2017-07-26 22:08 ` [PATCH 9/9] libdw: Add DW_MACRO constants and DW_MACRO_GNU compatibility defines Mark Wielaard
2017-07-26 22:08 ` [PATCH 3/9] libdw: Add new DWARF5 character encodings Mark Wielaard
2017-07-26 22:08 ` [PATCH 7/9] Handle DWARF5 defaulted member function encodings Mark Wielaard
2017-07-26 22:08 ` [PATCH 8/9] libdw: Handle DWARF5 immutable, packed and shared in dwarf_peel_type Mark Wielaard
2017-07-26 22:08 ` [PATCH 5/9] libdw: Add dwarf_default_lower_bound Mark Wielaard
2017-08-02 12:03 ` Some easy DWARF5 extensions Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).