* binutils-all/objcopy.exp: Always treat objcopy_test as XFAIL on cygwin.
[deliverable/binutils-gdb.git] / binutils / dwarf.c
index 983a3c76a5f093c40795446f41ed19166fa180a5..1a01e009a5ea7fc73d69c2b6e8c24ce54723fcd6 100644 (file)
@@ -44,7 +44,6 @@ int eh_addr_size;
 int do_debug_info;
 int do_debug_abbrevs;
 int do_debug_lines;
-int do_debug_lines_decoded;
 int do_debug_pubnames;
 int do_debug_aranges;
 int do_debug_ranges;
@@ -55,6 +54,10 @@ int do_debug_str;
 int do_debug_loc;
 int do_wide;
 
+/* Values for do_debug_lines.  */
+#define FLAG_DEBUG_LINES_RAW    1
+#define FLAG_DEBUG_LINES_DECODED 2
+
 dwarf_vma (*byte_get) (unsigned char *, int);
 
 dwarf_vma
@@ -325,36 +328,41 @@ process_extended_line_op (unsigned char *data, int is_stmt)
       printf (_("%s\n\n"), name);
       break;
 
+    case DW_LNE_set_discriminator:
+      printf (_("set Discriminator to %lu\n"),
+              read_leb128 (data, & bytes_read, 0));
+      break;
+
     /* HP extensions.  */
     case DW_LNE_HP_negate_is_UV_update:
-      printf ("DW_LNE_HP_negate_is_UV_update");
+      printf ("DW_LNE_HP_negate_is_UV_update\n");
       break;
     case DW_LNE_HP_push_context:
-      printf ("DW_LNE_HP_push_context");
+      printf ("DW_LNE_HP_push_context\n");
       break;
     case DW_LNE_HP_pop_context:
-      printf ("DW_LNE_HP_pop_context");
+      printf ("DW_LNE_HP_pop_context\n");
       break;
     case DW_LNE_HP_set_file_line_column:
-      printf ("DW_LNE_HP_set_file_line_column");
+      printf ("DW_LNE_HP_set_file_line_column\n");
       break;
     case DW_LNE_HP_set_routine_name:
-      printf ("DW_LNE_HP_set_routine_name");
+      printf ("DW_LNE_HP_set_routine_name\n");
       break;
     case DW_LNE_HP_set_sequence:
-      printf ("DW_LNE_HP_set_sequence");
+      printf ("DW_LNE_HP_set_sequence\n");
       break;
     case DW_LNE_HP_negate_post_semantics:
-      printf ("DW_LNE_HP_negate_post_semantics");
+      printf ("DW_LNE_HP_negate_post_semantics\n");
       break;
     case DW_LNE_HP_negate_function_exit:
-      printf ("DW_LNE_HP_negate_function_exit");
+      printf ("DW_LNE_HP_negate_function_exit\n");
       break;
     case DW_LNE_HP_negate_front_end_logical:
-      printf ("DW_LNE_HP_negate_front_end_logical");
+      printf ("DW_LNE_HP_negate_front_end_logical\n");
       break;
     case DW_LNE_HP_define_proc:
-      printf ("DW_LNE_HP_define_proc");
+      printf ("DW_LNE_HP_define_proc\n");
       break;
 
     default:
@@ -1839,7 +1847,7 @@ process_debug_info (struct dwarf_section *section,
 
   if (!do_loc)
     {
-      printf (_("The section %s contains:\n\n"), section->name);
+      printf (_("Contents of the %s section:\n\n"), section->name);
 
       load_debug_section (str, file);
     }
@@ -2137,7 +2145,8 @@ display_debug_lines_raw (struct dwarf_section *section,
       if (info.li_length + initial_length_size > section->size)
        {
          warn
-           (_("The line info appears to be corrupt - the section is too small\n"));
+           (_("The information in section %s appears to be corrupt - the section is too small\n"),
+            section->name);
          return 0;
        }
 
@@ -2781,8 +2790,8 @@ display_debug_lines (struct dwarf_section *section, void *file)
 {
   unsigned char *data = section->start;
   unsigned char *end = data + section->size;
-  int retValRaw = 0;
-  int retValDecoded = 0;
+  int retValRaw = 1;
+  int retValDecoded = 1;
 
   if (load_debug_info (file) == 0)
     {
@@ -2791,14 +2800,13 @@ display_debug_lines (struct dwarf_section *section, void *file)
       return 0;
     }
 
-  if (do_debug_lines)
+  if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
     retValRaw = display_debug_lines_raw (section, data, end);
 
-  if (do_debug_lines_decoded)
+  if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
     retValDecoded = display_debug_lines_decoded (section, data, end);
 
-  if ((do_debug_lines && !retValRaw)
-      || (do_debug_lines_decoded && !retValDecoded))
+  if (!retValRaw || !retValDecoded)
     return 0;
 
   return 1;
@@ -2904,7 +2912,7 @@ display_debug_pubnames (struct dwarf_section *section,
          if (offset != 0)
            {
              data += offset_size;
-             printf ("    %-6ld\t\t%s\n", offset, data);
+             printf ("    %-6lx\t%s\n", offset, data);
              data += strlen ((char *) data) + 1;
            }
        }
@@ -3247,6 +3255,7 @@ display_debug_loc (struct dwarf_section *section, void *file)
   if (start < section_end)
     warn (_("There are %ld unused bytes at the end of section %s\n"),
          (long) (section_end - start), section->name);
+  putchar ('\n');
   return 1;
 }
 
@@ -3322,7 +3331,7 @@ display_debug_aranges (struct dwarf_section *section,
   unsigned char *start = section->start;
   unsigned char *end = start + section->size;
 
-  printf (_("The section %s contains:\n\n"), section->name);
+  printf (_("Contents of the %s section:\n\n"), section->name);
 
   /* It does not matter if this load fails,
      we test for that later on.  */
@@ -3423,6 +3432,7 @@ display_debug_aranges (struct dwarf_section *section,
 
          ranges += address_size;
 
+         printf ("    ");
          print_dwarf_vma (address, address_size);
          print_dwarf_vma (length, address_size);
          putchar ('\n');
@@ -3573,17 +3583,19 @@ display_debug_ranges (struct dwarf_section *section,
                  break;
                }
 
-             print_dwarf_vma (begin, pointer_size);
-             print_dwarf_vma (end, pointer_size);
-
              /* Check base address specifiers.  */
              if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
                {
                  base_address = end;
+                 print_dwarf_vma (begin, pointer_size);
+                 print_dwarf_vma (end, pointer_size);
                  printf ("(base address)\n");
                  continue;
                }
 
+             print_dwarf_vma (begin + base_address, pointer_size);
+             print_dwarf_vma (end + base_address, pointer_size);
+
              if (begin == end)
                fputs (_("(start == end)"), stdout);
              else if (begin > end)
@@ -3618,17 +3630,27 @@ typedef struct Frame_Chunk
 }
 Frame_Chunk;
 
+static const char *const *dwarf_regnames;
+static unsigned int dwarf_regnames_count;
+
 /* A marker for a col_type that means this column was never referenced
    in the frame info.  */
 #define DW_CFA_unreferenced (-1)
 
-static void
-frame_need_space (Frame_Chunk *fc, int reg)
+/* Return 0 if not more space is needed, 1 if more space is needed,
+   -1 for invalid reg.  */
+
+static int
+frame_need_space (Frame_Chunk *fc, unsigned int reg)
 {
   int prev = fc->ncols;
 
-  if (reg < fc->ncols)
-    return;
+  if (reg < (unsigned int) fc->ncols)
+    return 0;
+
+  if (dwarf_regnames_count
+      && reg > dwarf_regnames_count)
+    return -1;
 
   fc->ncols = reg + 1;
   fc->col_type = xcrealloc (fc->col_type, fc->ncols, sizeof (short int));
@@ -3640,6 +3662,7 @@ frame_need_space (Frame_Chunk *fc, int reg)
       fc->col_offset[prev] = 0;
       prev++;
     }
+  return 1;
 }
 
 static const char *const dwarf_regnames_i386[] =
@@ -3681,9 +3704,6 @@ static const char *const dwarf_regnames_x86_64[] =
   "mxcsr", "fcw", "fsw"
 };
 
-static const char *const *dwarf_regnames;
-static unsigned int dwarf_regnames_count;
-
 void
 init_dwarf_regnames (unsigned int e_machine)
 {
@@ -3813,8 +3833,9 @@ display_debug_frames (struct dwarf_section *section,
   int is_eh = strcmp (section->name, ".eh_frame") == 0;
   unsigned int length_return;
   int max_regs = 0;
+  const char *bad_reg = _("bad register: ");
 
-  printf (_("The section %s contains:\n"), section->name);
+  printf (_("Contents of the %s section:\n"), section->name);
 
   while (start < end)
     {
@@ -4086,12 +4107,12 @@ display_debug_frames (struct dwarf_section *section,
                  break;
                case DW_CFA_offset:
                  LEB ();
-                 frame_need_space (fc, opa);
-                 fc->col_type[opa] = DW_CFA_undefined;
+                 if (frame_need_space (fc, opa) >= 0)
+                   fc->col_type[opa] = DW_CFA_undefined;
                  break;
                case DW_CFA_restore:
-                 frame_need_space (fc, opa);
-                 fc->col_type[opa] = DW_CFA_undefined;
+                 if (frame_need_space (fc, opa) >= 0)
+                   fc->col_type[opa] = DW_CFA_undefined;
                  break;
                case DW_CFA_set_loc:
                  start += encoded_ptr_size;
@@ -4108,28 +4129,29 @@ display_debug_frames (struct dwarf_section *section,
                case DW_CFA_offset_extended:
                case DW_CFA_val_offset:
                  reg = LEB (); LEB ();
-                 frame_need_space (fc, reg);
-                 fc->col_type[reg] = DW_CFA_undefined;
+                 if (frame_need_space (fc, reg) >= 0)
+                   fc->col_type[reg] = DW_CFA_undefined;
                  break;
                case DW_CFA_restore_extended:
                  reg = LEB ();
                  frame_need_space (fc, reg);
-                 fc->col_type[reg] = DW_CFA_undefined;
+                 if (frame_need_space (fc, reg) >= 0)
+                   fc->col_type[reg] = DW_CFA_undefined;
                  break;
                case DW_CFA_undefined:
                  reg = LEB ();
-                 frame_need_space (fc, reg);
-                 fc->col_type[reg] = DW_CFA_undefined;
+                 if (frame_need_space (fc, reg) >= 0)
+                   fc->col_type[reg] = DW_CFA_undefined;
                  break;
                case DW_CFA_same_value:
                  reg = LEB ();
-                 frame_need_space (fc, reg);
-                 fc->col_type[reg] = DW_CFA_undefined;
+                 if (frame_need_space (fc, reg) >= 0)
+                   fc->col_type[reg] = DW_CFA_undefined;
                  break;
                case DW_CFA_register:
                  reg = LEB (); LEB ();
-                 frame_need_space (fc, reg);
-                 fc->col_type[reg] = DW_CFA_undefined;
+                 if (frame_need_space (fc, reg) >= 0)
+                   fc->col_type[reg] = DW_CFA_undefined;
                  break;
                case DW_CFA_def_cfa:
                  LEB (); LEB ();
@@ -4149,14 +4171,14 @@ display_debug_frames (struct dwarf_section *section,
                  reg = LEB ();
                  tmp = LEB ();
                  start += tmp;
-                 frame_need_space (fc, reg);
-                 fc->col_type[reg] = DW_CFA_undefined;
+                 if (frame_need_space (fc, reg) >= 0)
+                   fc->col_type[reg] = DW_CFA_undefined;
                  break;
                case DW_CFA_offset_extended_sf:
                case DW_CFA_val_offset_sf:
                  reg = LEB (); SLEB ();
-                 frame_need_space (fc, reg);
-                 fc->col_type[reg] = DW_CFA_undefined;
+                 if (frame_need_space (fc, reg) >= 0)
+                   fc->col_type[reg] = DW_CFA_undefined;
                  break;
                case DW_CFA_def_cfa_sf:
                  LEB (); SLEB ();
@@ -4172,9 +4194,9 @@ display_debug_frames (struct dwarf_section *section,
                  break;
                case DW_CFA_GNU_negative_offset_extended:
                  reg = LEB (); LEB ();
-                 frame_need_space (fc, reg);
-                 fc->col_type[reg] = DW_CFA_undefined;
-
+                 if (frame_need_space (fc, reg) >= 0)
+                   fc->col_type[reg] = DW_CFA_undefined;
+                 break;
                default:
                  break;
                }
@@ -4191,6 +4213,7 @@ display_debug_frames (struct dwarf_section *section,
          unsigned long ul, reg, roffs;
          long l, ofs;
          dwarf_vma vma;
+         const char *reg_prefix = "";
 
          op = *start++;
          opa = op & 0x3f;
@@ -4213,18 +4236,31 @@ display_debug_frames (struct dwarf_section *section,
 
            case DW_CFA_offset:
              roffs = LEB ();
-             if (! do_debug_frames_interp)
-               printf ("  DW_CFA_offset: %s at cfa%+ld\n",
-                       regname (opa, 0), roffs * fc->data_factor);
-             fc->col_type[opa] = DW_CFA_offset;
-             fc->col_offset[opa] = roffs * fc->data_factor;
+             if (opa >= (unsigned int) fc->ncols)
+               reg_prefix = bad_reg;
+             if (! do_debug_frames_interp || *reg_prefix != '\0')
+               printf ("  DW_CFA_offset: %s%s at cfa%+ld\n",
+                       reg_prefix, regname (opa, 0),
+                       roffs * fc->data_factor);
+             if (*reg_prefix == '\0')
+               {
+                 fc->col_type[opa] = DW_CFA_offset;
+                 fc->col_offset[opa] = roffs * fc->data_factor;
+               }
              break;
 
            case DW_CFA_restore:
-             if (! do_debug_frames_interp)
-               printf ("  DW_CFA_restore: %s\n", regname (opa, 0));
-             fc->col_type[opa] = cie->col_type[opa];
-             fc->col_offset[opa] = cie->col_offset[opa];
+             if (opa >= (unsigned int) cie->ncols
+                 || opa >= (unsigned int) fc->ncols)
+               reg_prefix = bad_reg;
+             if (! do_debug_frames_interp || *reg_prefix != '\0')
+               printf ("  DW_CFA_restore: %s%s\n",
+                       reg_prefix, regname (opa, 0));
+             if (*reg_prefix == '\0')
+               {
+                 fc->col_type[opa] = cie->col_type[opa];
+                 fc->col_offset[opa] = cie->col_offset[opa];
+               }
              break;
 
            case DW_CFA_set_loc:
@@ -4275,59 +4311,94 @@ display_debug_frames (struct dwarf_section *section,
            case DW_CFA_offset_extended:
              reg = LEB ();
              roffs = LEB ();
-             if (! do_debug_frames_interp)
-               printf ("  DW_CFA_offset_extended: %s at cfa%+ld\n",
-                       regname (reg, 0), roffs * fc->data_factor);
-             fc->col_type[reg] = DW_CFA_offset;
-             fc->col_offset[reg] = roffs * fc->data_factor;
+             if (reg >= (unsigned int) fc->ncols)
+               reg_prefix = bad_reg;
+             if (! do_debug_frames_interp || *reg_prefix != '\0')
+               printf ("  DW_CFA_offset_extended: %s%s at cfa%+ld\n",
+                       reg_prefix, regname (reg, 0),
+                       roffs * fc->data_factor);
+             if (*reg_prefix == '\0')
+               {
+                 fc->col_type[reg] = DW_CFA_offset;
+                 fc->col_offset[reg] = roffs * fc->data_factor;
+               }
              break;
 
            case DW_CFA_val_offset:
              reg = LEB ();
              roffs = LEB ();
-             if (! do_debug_frames_interp)
-               printf ("  DW_CFA_val_offset: %s at cfa%+ld\n",
-                       regname (reg, 0), roffs * fc->data_factor);
-             fc->col_type[reg] = DW_CFA_val_offset;
-             fc->col_offset[reg] = roffs * fc->data_factor;
+             if (reg >= (unsigned int) fc->ncols)
+               reg_prefix = bad_reg;
+             if (! do_debug_frames_interp || *reg_prefix != '\0')
+               printf ("  DW_CFA_val_offset: %s%s at cfa%+ld\n",
+                       reg_prefix, regname (reg, 0),
+                       roffs * fc->data_factor);
+             if (*reg_prefix == '\0')
+               {
+                 fc->col_type[reg] = DW_CFA_val_offset;
+                 fc->col_offset[reg] = roffs * fc->data_factor;
+               }
              break;
 
            case DW_CFA_restore_extended:
              reg = LEB ();
-             if (! do_debug_frames_interp)
-               printf ("  DW_CFA_restore_extended: %s\n",
-                       regname (reg, 0));
-             fc->col_type[reg] = cie->col_type[reg];
-             fc->col_offset[reg] = cie->col_offset[reg];
+             if (reg >= (unsigned int) cie->ncols
+                 || reg >= (unsigned int) fc->ncols)
+               reg_prefix = bad_reg;
+             if (! do_debug_frames_interp || *reg_prefix != '\0')
+               printf ("  DW_CFA_restore_extended: %s%s\n",
+                       reg_prefix, regname (reg, 0));
+             if (*reg_prefix == '\0')
+               {
+                 fc->col_type[reg] = cie->col_type[reg];
+                 fc->col_offset[reg] = cie->col_offset[reg];
+               }
              break;
 
            case DW_CFA_undefined:
              reg = LEB ();
-             if (! do_debug_frames_interp)
-               printf ("  DW_CFA_undefined: %s\n", regname (reg, 0));
-             fc->col_type[reg] = DW_CFA_undefined;
-             fc->col_offset[reg] = 0;
+             if (reg >= (unsigned int) fc->ncols)
+               reg_prefix = bad_reg;
+             if (! do_debug_frames_interp || *reg_prefix != '\0')
+               printf ("  DW_CFA_undefined: %s%s\n",
+                       reg_prefix, regname (reg, 0));
+             if (*reg_prefix == '\0')
+               {
+                 fc->col_type[reg] = DW_CFA_undefined;
+                 fc->col_offset[reg] = 0;
+               }
              break;
 
            case DW_CFA_same_value:
              reg = LEB ();
-             if (! do_debug_frames_interp)
-               printf ("  DW_CFA_same_value: %s\n", regname (reg, 0));
-             fc->col_type[reg] = DW_CFA_same_value;
-             fc->col_offset[reg] = 0;
+             if (reg >= (unsigned int) fc->ncols)
+               reg_prefix = bad_reg;
+             if (! do_debug_frames_interp || *reg_prefix != '\0')
+               printf ("  DW_CFA_same_value: %s%s\n",
+                       reg_prefix, regname (reg, 0));
+             if (*reg_prefix == '\0')
+               {
+                 fc->col_type[reg] = DW_CFA_same_value;
+                 fc->col_offset[reg] = 0;
+               }
              break;
 
            case DW_CFA_register:
              reg = LEB ();
              roffs = LEB ();
-             if (! do_debug_frames_interp)
+             if (reg >= (unsigned int) fc->ncols)
+               reg_prefix = bad_reg;
+             if (! do_debug_frames_interp || *reg_prefix != '\0')
                {
-                 printf ("  DW_CFA_register: %s in ",
-                         regname (reg, 0));
+                 printf ("  DW_CFA_register: %s%s in ",
+                         reg_prefix, regname (reg, 0));
                  puts (regname (roffs, 0));
                }
-             fc->col_type[reg] = DW_CFA_register;
-             fc->col_offset[reg] = roffs;
+             if (*reg_prefix == '\0')
+               {
+                 fc->col_type[reg] = DW_CFA_register;
+                 fc->col_offset[reg] = roffs;
+               }
              break;
 
            case DW_CFA_remember_state:
@@ -4406,53 +4477,69 @@ display_debug_frames (struct dwarf_section *section,
            case DW_CFA_expression:
              reg = LEB ();
              ul = LEB ();
-             if (! do_debug_frames_interp)
+             if (reg >= (unsigned int) fc->ncols)
+               reg_prefix = bad_reg;
+             if (! do_debug_frames_interp || *reg_prefix != '\0')
                {
-                 printf ("  DW_CFA_expression: %s (",
-                         regname (reg, 0));
+                 printf ("  DW_CFA_expression: %s%s (",
+                         reg_prefix, regname (reg, 0));
                  decode_location_expression (start, eh_addr_size,
                                              ul, 0, section);
                  printf (")\n");
                }
-             fc->col_type[reg] = DW_CFA_expression;
+             if (*reg_prefix == '\0')
+               fc->col_type[reg] = DW_CFA_expression;
              start += ul;
              break;
 
            case DW_CFA_val_expression:
              reg = LEB ();
              ul = LEB ();
-             if (! do_debug_frames_interp)
+             if (reg >= (unsigned int) fc->ncols)
+               reg_prefix = bad_reg;
+             if (! do_debug_frames_interp || *reg_prefix != '\0')
                {
-                 printf ("  DW_CFA_val_expression: %s (",
-                         regname (reg, 0));
+                 printf ("  DW_CFA_val_expression: %s%s (",
+                         reg_prefix, regname (reg, 0));
                  decode_location_expression (start, eh_addr_size, ul, 0,
                                              section);
                  printf (")\n");
                }
-             fc->col_type[reg] = DW_CFA_val_expression;
+             if (*reg_prefix == '\0')
+               fc->col_type[reg] = DW_CFA_val_expression;
              start += ul;
              break;
 
            case DW_CFA_offset_extended_sf:
              reg = LEB ();
              l = SLEB ();
-             frame_need_space (fc, reg);
-             if (! do_debug_frames_interp)
-               printf ("  DW_CFA_offset_extended_sf: %s at cfa%+ld\n",
-                       regname (reg, 0), l * fc->data_factor);
-             fc->col_type[reg] = DW_CFA_offset;
-             fc->col_offset[reg] = l * fc->data_factor;
+             if (frame_need_space (fc, reg) < 0)
+               reg_prefix = bad_reg;
+             if (! do_debug_frames_interp || *reg_prefix != '\0')
+               printf ("  DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
+                       reg_prefix, regname (reg, 0),
+                       l * fc->data_factor);
+             if (*reg_prefix == '\0')
+               {
+                 fc->col_type[reg] = DW_CFA_offset;
+                 fc->col_offset[reg] = l * fc->data_factor;
+               }
              break;
 
            case DW_CFA_val_offset_sf:
              reg = LEB ();
              l = SLEB ();
-             frame_need_space (fc, reg);
-             if (! do_debug_frames_interp)
-               printf ("  DW_CFA_val_offset_sf: %s at cfa%+ld\n",
-                       regname (reg, 0), l * fc->data_factor);
-             fc->col_type[reg] = DW_CFA_val_offset;
-             fc->col_offset[reg] = l * fc->data_factor;
+             if (frame_need_space (fc, reg) < 0)
+               reg_prefix = bad_reg;
+             if (! do_debug_frames_interp || *reg_prefix != '\0')
+               printf ("  DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
+                       reg_prefix, regname (reg, 0),
+                       l * fc->data_factor);
+             if (*reg_prefix == '\0')
+               {
+                 fc->col_type[reg] = DW_CFA_val_offset;
+                 fc->col_offset[reg] = l * fc->data_factor;
+               }
              break;
 
            case DW_CFA_def_cfa_sf:
@@ -4497,12 +4584,17 @@ display_debug_frames (struct dwarf_section *section,
            case DW_CFA_GNU_negative_offset_extended:
              reg = LEB ();
              l = - LEB ();
-             frame_need_space (fc, reg);
-             if (! do_debug_frames_interp)
-               printf ("  DW_CFA_GNU_negative_offset_extended: %s at cfa%+ld\n",
-                       regname (reg, 0), l * fc->data_factor);
-             fc->col_type[reg] = DW_CFA_offset;
-             fc->col_offset[reg] = l * fc->data_factor;
+             if (frame_need_space (fc, reg) < 0)
+               reg_prefix = bad_reg;
+             if (! do_debug_frames_interp || *reg_prefix != '\0')
+               printf ("  DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
+                       reg_prefix, regname (reg, 0),
+                       l * fc->data_factor);
+             if (*reg_prefix == '\0')
+               {
+                 fc->col_type[reg] = DW_CFA_offset;
+                 fc->col_offset[reg] = l * fc->data_factor;
+               }
              break;
 
            default:
@@ -4623,38 +4715,185 @@ free_debug_memory (void)
     }
 }
 
+void
+dwarf_select_sections_by_names (const char *names)
+{
+  typedef struct
+  {
+    const char * option;
+    int *        variable;
+    int val;
+  }
+  debug_dump_long_opts;
+
+  static const debug_dump_long_opts opts_table [] =
+    {
+      /* Please keep this table alpha- sorted.  */
+      { "Ranges", & do_debug_ranges, 1 },
+      { "abbrev", & do_debug_abbrevs, 1 },
+      { "aranges", & do_debug_aranges, 1 },
+      { "frames", & do_debug_frames, 1 },
+      { "frames-interp", & do_debug_frames_interp, 1 },
+      { "info", & do_debug_info, 1 },
+      { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility.  */
+      { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
+      { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
+      { "loc",  & do_debug_loc, 1 },
+      { "macro", & do_debug_macinfo, 1 },
+      { "pubnames", & do_debug_pubnames, 1 },
+      /* This entry is for compatability
+        with earlier versions of readelf.  */
+      { "ranges", & do_debug_aranges, 1 },
+      { "str", & do_debug_str, 1 },
+      { NULL, NULL, 0 }
+    };
+
+  const char *p;
+  
+  p = names;
+  while (*p)
+    {
+      const debug_dump_long_opts * entry;
+      
+      for (entry = opts_table; entry->option; entry++)
+       {
+         size_t len = strlen (entry->option);
+         
+         if (strncmp (p, entry->option, len) == 0
+             && (p[len] == ',' || p[len] == '\0'))
+           {
+             * entry->variable |= entry->val;
+             
+             /* The --debug-dump=frames-interp option also
+                enables the --debug-dump=frames option.  */
+             if (do_debug_frames_interp)
+               do_debug_frames = 1;
+
+             p += len;
+             break;
+           }
+       }
+      
+      if (entry->option == NULL)
+       {
+         warn (_("Unrecognized debug option '%s'\n"), p);
+         p = strchr (p, ',');
+         if (p == NULL)
+           break;
+       }
+      
+      if (*p == ',')
+       p++;
+    }
+}
+
+void
+dwarf_select_sections_by_letters (const char *letters)
+{
+  unsigned int index = 0;
+
+  while (letters[index])
+    switch (letters[index++])
+      {
+      case 'i':
+       do_debug_info = 1;
+       break;
+       
+      case 'a':
+       do_debug_abbrevs = 1;
+       break;
+       
+      case 'l':
+       do_debug_lines |= FLAG_DEBUG_LINES_RAW;
+       break;
+       
+      case 'L':
+       do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
+       break;
+       
+      case 'p':
+       do_debug_pubnames = 1;
+       break;
+       
+      case 'r':
+       do_debug_aranges = 1;
+       break;
+       
+      case 'R':
+       do_debug_ranges = 1;
+       break;
+       
+      case 'F':
+       do_debug_frames_interp = 1;
+      case 'f':
+       do_debug_frames = 1;
+       break;
+       
+      case 'm':
+       do_debug_macinfo = 1;
+       break;
+       
+      case 's':
+       do_debug_str = 1;
+       break;
+       
+      case 'o':
+       do_debug_loc = 1;
+       break;
+       
+      default:
+       warn (_("Unrecognized debug option '%s'\n"), optarg);
+       break;
+      }
+}
+
+void
+dwarf_select_sections_all (void)
+{
+  do_debug_info = 1;
+  do_debug_abbrevs = 1;
+  do_debug_lines = FLAG_DEBUG_LINES_RAW;
+  do_debug_pubnames = 1;
+  do_debug_aranges = 1;
+  do_debug_ranges = 1;
+  do_debug_frames = 1;
+  do_debug_macinfo = 1;
+  do_debug_str = 1;
+  do_debug_loc = 1;
+}
+
 struct dwarf_section_display debug_displays[] =
 {
   { { ".debug_abbrev",         ".zdebug_abbrev",       NULL,   NULL,   0,      0 },
-    display_debug_abbrev,              0,      0 },
+    display_debug_abbrev,              &do_debug_abbrevs,      0,      0 },
   { { ".debug_aranges",                ".zdebug_aranges",      NULL,   NULL,   0,      0 },
-    display_debug_aranges,             0,      0 },
+    display_debug_aranges,             &do_debug_aranges,      1,      0 },
   { { ".debug_frame",          ".zdebug_frame",        NULL,   NULL,   0,      0 },
-    display_debug_frames,              1,      0 },
+    display_debug_frames,              &do_debug_frames,       1,      0 },
   { { ".debug_info",           ".zdebug_info",         NULL,   NULL,   0,      0 },
-    display_debug_info,                        1,      0 },
+    display_debug_info,                        &do_debug_info,         1,      0 },
   { { ".debug_line",           ".zdebug_line",         NULL,   NULL,   0,      0 },
-    display_debug_lines,               0,      0 },
+    display_debug_lines,               &do_debug_lines,        1,      0 },
   { { ".debug_pubnames",       ".zdebug_pubnames",     NULL,   NULL,   0,      0 },
-    display_debug_pubnames,            0,      0 },
+    display_debug_pubnames,            &do_debug_pubnames,     0,      0 },
   { { ".eh_frame",             "",                     NULL,   NULL,   0,      0 },
-    display_debug_frames,              1,      1 },
+    display_debug_frames,              &do_debug_frames,       1,      1 },
   { { ".debug_macinfo",                ".zdebug_macinfo",      NULL,   NULL,   0,      0 },
-    display_debug_macinfo,             0,      0 },
+    display_debug_macinfo,             &do_debug_macinfo,      0,      0 },
   { { ".debug_str",            ".zdebug_str",          NULL,   NULL,   0,      0 },
-    display_debug_str,                 0,      0 },
+    display_debug_str,                 &do_debug_str,          0,      0 },
   { { ".debug_loc",            ".zdebug_loc",          NULL,   NULL,   0,      0 },
-    display_debug_loc,                 0,      0 },
+    display_debug_loc,                 &do_debug_loc,          1,      0 },
   { { ".debug_pubtypes",       ".zdebug_pubtypes",     NULL,   NULL,   0,      0 },
-    display_debug_pubnames,            0,      0 },
+    display_debug_pubnames,            &do_debug_pubnames,     0,      0 },
   { { ".debug_ranges",         ".zdebug_ranges",       NULL,   NULL,   0,      0 },
-    display_debug_ranges,              0,      0 },
+    display_debug_ranges,              &do_debug_ranges,       1,      0 },
   { { ".debug_static_func",    ".zdebug_static_func",  NULL,   NULL,   0,      0 },
-    display_debug_not_supported,       0,      0 },
+    display_debug_not_supported,       NULL,                   0,      0 },
   { { ".debug_static_vars",    ".zdebug_static_vars",  NULL,   NULL,   0,      0 },
-    display_debug_not_supported,       0,      0 },
-  { { ".debug_types",  ".zdebug_types",                NULL,   NULL,   0,      0 },
-    display_debug_not_supported,       0,      0 },
+    display_debug_not_supported,       NULL,                   0,      0 },
+  { { ".debug_types",          ".zdebug_types",        NULL,   NULL,   0,      0 },
+    display_debug_not_supported,       NULL,                   0,      0 },
   { { ".debug_weaknames",      ".zdebug_weaknames",    NULL,   NULL,   0,      0 },
-    display_debug_not_supported,       0,      0 }
+    display_debug_not_supported,       NULL,                   0,      0 }
 };
This page took 0.033778 seconds and 4 git commands to generate.