+2021-07-10  Alan Modra  <amodra@gmail.com>
+
+       PR 28069
+       * dwarf.c (display_discr_list): Remove assertions.  Delete "end"
+       parameter, use initial "data" pointer as the end.  Formatting.
+       Don't count down bytes as they are read.
+       (read_and_display_attr_value): Adjust display_discr_list call.
+       (read_and_print_leb128): Don't pass __FILE__ and __LINE__ to
+       report_leb_status.
+       * dwarf.h (report_leb_status): Don't report file and line
+       numbers.  Delete file and lnum parameters,
+       (READ_ULEB, READ_SLEB): Adjust.
+
 2021-07-07  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        * configure.ac: Check for strnlen declaration.
 
   int status;
   dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status);
   if (status != 0)
-    report_leb_status (status, __FILE__, __LINE__);
+    report_leb_status (status);
   else
     printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val));
 }
 display_discr_list (unsigned long          form,
                    dwarf_vma              uvalue,
                    unsigned char *        data,
-                   unsigned const char *  end,
                    int                    level)
 {
+  unsigned char *end = data;
+
   if (uvalue == 0)
     {
       printf ("[default]");
       return;
     }
 
-  bool is_signed =
-    (level > 0 && level <= MAX_CU_NESTING)
-    ? level_type_signed [level - 1] : false;
+  bool is_signed = (level > 0 && level <= MAX_CU_NESTING
+                   ? level_type_signed [level - 1] : false);
 
   printf ("(");
-  while (uvalue)
+  while (data < end)
     {
       unsigned char     discriminant;
       unsigned int      bytes_read;
 
       SAFE_BYTE_GET_AND_INC (discriminant, data, 1, end);
-      -- uvalue;
 
-      assert (uvalue > 0);
       switch (discriminant)
        {
        case DW_DSC_label:
          printf ("label ");
          read_and_print_leb128 (data, & bytes_read, end, is_signed);
-         assert (bytes_read <= uvalue && bytes_read > 0);
-         uvalue -= bytes_read;
          data += bytes_read;
          break;
 
        case DW_DSC_range:
          printf ("range ");
          read_and_print_leb128 (data, & bytes_read, end, is_signed);
-         assert (bytes_read <= uvalue && bytes_read > 0);
-         uvalue -= bytes_read;
          data += bytes_read;
 
          printf ("..");
          read_and_print_leb128 (data, & bytes_read, end, is_signed);
-         assert (bytes_read <= uvalue && bytes_read > 0);
-         uvalue -= bytes_read;
          data += bytes_read;
          break;
 
          return;
        }
 
-      if (uvalue)
+      if (data < end)
        printf (", ");
     }
 
 
     case DW_AT_discr_list:
       printf ("\t");
-      display_discr_list (form, uvalue, data, end, level);
+      display_discr_list (form, uvalue, data, level);
       break;
 
     case DW_AT_frame_base:
 
 #endif
 
 static inline void
-report_leb_status (int status, const char *file, unsigned long lnum)
+report_leb_status (int status)
 {
   if ((status & 1) != 0)
-    error (_("%s:%lu: end of data encountered whilst reading LEB\n"), file, lnum);
+    error (_("end of data encountered whilst reading LEB\n"));
   else if ((status & 2) != 0)
-    error (_("%s:%lu: read LEB value is too large to store in destination variable\n"), file, lnum);
+    error (_("read LEB value is too large to store in destination variable\n"));
 }
 
 #define SKIP_ULEB(start, end)                                  \
       (var) = _val;                                            \
       if ((var) != _val)                                       \
        _status |= 2;                                           \
-      report_leb_status (_status, __FILE__, __LINE__);         \
+      report_leb_status (_status);                             \
     }                                                          \
   while (0)
 
       (var) = _val;                                            \
       if ((var) != _val)                                       \
        _status |= 2;                                           \
-      report_leb_status (_status, __FILE__, __LINE__);         \
+      report_leb_status (_status);                             \
     }                                                          \
   while (0)