]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/symmisc.c
2.41 Release sources
[thirdparty/binutils-gdb.git] / gdb / symmisc.c
index 37ecc8064da57309f5785ba8f88a591b948a6d01..a65552aa2d22f744896c86f732a292b5a6a0340b 100644 (file)
@@ -1,6 +1,6 @@
 /* Do various things to symbol tables (other than lookup), for GDB.
 
-   Copyright (C) 1986-2022 Free Software Foundation, Inc.
+   Copyright (C) 1986-2023 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -116,7 +116,7 @@ dump_objfile (struct objfile *objfile)
   gdb_printf ("\nObject file %s:  ", objfile_name (objfile));
   gdb_printf ("Objfile at %s, bfd at %s, %d minsyms\n\n",
              host_address_to_string (objfile),
-             host_address_to_string (objfile->obfd),
+             host_address_to_string (objfile->obfd.get ()),
              objfile->per_bfd->minimal_symbol_count);
 
   objfile->dump ();
@@ -131,7 +131,7 @@ dump_objfile (struct objfile *objfile)
              gdb_printf ("%s at %s",
                          symtab_to_filename_for_display (symtab),
                          host_address_to_string (symtab));
-             if (symtab->objfile () != objfile)
+             if (symtab->compunit ()->objfile () != objfile)
                gdb_printf (", NOT ON CHAIN!");
              gdb_printf ("\n");
            }
@@ -160,7 +160,7 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
     {
       struct obj_section *section = msymbol->obj_section (objfile);
 
-      switch (MSYMBOL_TYPE (msymbol))
+      switch (msymbol->type ())
        {
        case mst_unknown:
          ms_type = 'u';
@@ -201,7 +201,7 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
 
       /* Use the relocated address as shown in the symbol here -- do
         not try to respect copy relocations.  */
-      CORE_ADDR addr = (msymbol->value.address
+      CORE_ADDR addr = (CORE_ADDR (msymbol->unrelocated_address ())
                        + objfile->section_offsets[msymbol->section_index ()]);
       gdb_puts (paddress (gdbarch, addr), outfile);
       gdb_printf (outfile, " %s", msymbol->linkage_name ());
@@ -212,7 +212,7 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
                        bfd_section_name (section->the_bfd_section));
          else
            gdb_printf (outfile, " spurious section %ld",
-                       (long) (section - objfile->sections));
+                       (long) (section - objfile->sections_start));
        }
       if (msymbol->demangled_name () != NULL)
        {
@@ -234,24 +234,18 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
 static void
 dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
 {
-  struct objfile *objfile = symtab->objfile ();
+  struct objfile *objfile = symtab->compunit ()->objfile ();
   struct gdbarch *gdbarch = objfile->arch ();
-  int i;
-  struct mdict_iterator miter;
-  int len;
-  struct linetable *l;
-  const struct blockvector *bv;
-  struct symbol *sym;
-  const struct block *b;
+  const struct linetable *l;
   int depth;
 
   gdb_printf (outfile, "\nSymtab for file %s at %s\n",
              symtab_to_filename_for_display (symtab),
              host_address_to_string (symtab));
 
-  if (symtab->dirname () != NULL)
+  if (symtab->compunit ()->dirname () != NULL)
     gdb_printf (outfile, "Compilation directory is %s\n",
-               symtab->dirname ());
+               symtab->compunit ()->dirname ());
   gdb_printf (outfile, "Read from object file %s (%s)\n",
              objfile_name (objfile),
              host_address_to_string (objfile));
@@ -263,11 +257,11 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
   if (l)
     {
       gdb_printf (outfile, "\nLine table:\n\n");
-      len = l->nitems;
-      for (i = 0; i < len; i++)
+      int len = l->nitems;
+      for (int i = 0; i < len; i++)
        {
          gdb_printf (outfile, " line %d at ", l->item[i].line);
-         gdb_puts (paddress (gdbarch, l->item[i].pc), outfile);
+         gdb_puts (paddress (gdbarch, l->item[i].pc (objfile)), outfile);
          if (l->item[i].is_stmt)
            gdb_printf (outfile, "\t(stmt)");
          gdb_printf (outfile, "\n");
@@ -278,41 +272,40 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
   if (is_main_symtab_of_compunit_symtab (symtab))
     {
       gdb_printf (outfile, "\nBlockvector:\n\n");
-      bv = symtab->blockvector ();
-      len = BLOCKVECTOR_NBLOCKS (bv);
-      for (i = 0; i < len; i++)
+      const blockvector *bv = symtab->compunit ()->blockvector ();
+      for (int i = 0; i < bv->num_blocks (); i++)
        {
-         b = BLOCKVECTOR_BLOCK (bv, i);
+         const block *b = bv->block (i);
          depth = block_depth (b) * 2;
          gdb_printf (outfile, "%*sblock #%03d, object at %s",
                      depth, "", i,
                      host_address_to_string (b));
-         if (BLOCK_SUPERBLOCK (b))
+         if (b->superblock ())
            gdb_printf (outfile, " under %s",
-                       host_address_to_string (BLOCK_SUPERBLOCK (b)));
+                       host_address_to_string (b->superblock ()));
          /* drow/2002-07-10: We could save the total symbols count
             even if we're using a hashtable, but nothing else but this message
             wants it.  */
-         gdb_printf (outfile, ", %d syms/buckets in ",
-                     mdict_size (BLOCK_MULTIDICT (b)));
-         gdb_puts (paddress (gdbarch, BLOCK_START (b)), outfile);
+         gdb_printf (outfile, ", %d symbols in ",
+                     mdict_size (b->multidict ()));
+         gdb_puts (paddress (gdbarch, b->start ()), outfile);
          gdb_printf (outfile, "..");
-         gdb_puts (paddress (gdbarch, BLOCK_END (b)), outfile);
-         if (BLOCK_FUNCTION (b))
+         gdb_puts (paddress (gdbarch, b->end ()), outfile);
+         if (b->function ())
            {
              gdb_printf (outfile, ", function %s",
-                         BLOCK_FUNCTION (b)->linkage_name ());
-             if (BLOCK_FUNCTION (b)->demangled_name () != NULL)
+                         b->function ()->linkage_name ());
+             if (b->function ()->demangled_name () != NULL)
                {
                  gdb_printf (outfile, ", %s",
-                             BLOCK_FUNCTION (b)->demangled_name ());
+                             b->function ()->demangled_name ());
                }
            }
          gdb_printf (outfile, "\n");
          /* Now print each symbol in this block (in no particular order, if
             we're using a hashtable).  Note that we only want this
             block, not any blocks from included symtabs.  */
-         ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (b), miter, sym)
+         for (struct symbol *sym : b->multidict_symbols ())
            {
              try
                {
@@ -351,7 +344,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
          gdb_printf (outfile, "Compunit user: %s\n", addr);
        }
       if (cust->includes != nullptr)
-       for (i = 0; ; ++i)
+       for (int i = 0; ; ++i)
          {
            struct compunit_symtab *include = cust->includes[i];
            if (include == nullptr)
@@ -370,8 +363,7 @@ dump_symtab (struct symtab *symtab, struct ui_file *outfile)
      because certain routines used during dump_symtab() use the current
      language to print an image of the symbol.  We'll restore it later.
      But use only real languages, not placeholders.  */
-  if (symtab->language () != language_unknown
-      && symtab->language () != language_auto)
+  if (symtab->language () != language_unknown)
     {
       scoped_restore_current_language save_lang;
       set_language (symtab->language ());
@@ -503,7 +495,7 @@ print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
   struct obj_section *section;
 
   if (symbol->is_objfile_owned ())
-    section = symbol->obj_section (symbol_objfile (symbol));
+    section = symbol->obj_section (symbol->objfile ());
   else
     section = NULL;
 
@@ -511,7 +503,7 @@ print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
   if (symbol->domain () == LABEL_DOMAIN)
     {
       gdb_printf (outfile, "label %s at ", symbol->print_name ());
-      gdb_puts (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
+      gdb_puts (paddress (gdbarch, symbol->value_address ()),
                outfile);
       if (section)
        gdb_printf (outfile, " section %s\n",
@@ -562,8 +554,8 @@ print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
        {
        case LOC_CONST:
          gdb_printf (outfile, "const %s (%s)",
-                     plongest (SYMBOL_VALUE (symbol)),
-                     hex_string (SYMBOL_VALUE (symbol)));
+                     plongest (symbol->value_longest ()),
+                     hex_string (symbol->value_longest ()));
          break;
 
        case LOC_CONST_BYTES:
@@ -572,17 +564,16 @@ print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
            struct type *type = check_typedef (symbol->type ());
 
            gdb_printf (outfile, "const %s hex bytes:",
-                       pulongest (TYPE_LENGTH (type)));
-           for (i = 0; i < TYPE_LENGTH (type); i++)
+                       pulongest (type->length ()));
+           for (i = 0; i < type->length (); i++)
              gdb_printf (outfile, " %02x",
-                         (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]);
+                         (unsigned) symbol->value_bytes ()[i]);
          }
          break;
 
        case LOC_STATIC:
          gdb_printf (outfile, "static at ");
-         gdb_puts (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
-                   outfile);
+         gdb_puts (paddress (gdbarch, symbol->value_address ()), outfile);
          if (section)
            gdb_printf (outfile, " section %s",
                        bfd_section_name (section->the_bfd_section));
@@ -591,30 +582,30 @@ print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
        case LOC_REGISTER:
          if (symbol->is_argument ())
            gdb_printf (outfile, "parameter register %s",
-                       plongest (SYMBOL_VALUE (symbol)));
+                       plongest (symbol->value_longest ()));
          else
            gdb_printf (outfile, "register %s",
-                       plongest (SYMBOL_VALUE (symbol)));
+                       plongest (symbol->value_longest ()));
          break;
 
        case LOC_ARG:
          gdb_printf (outfile, "arg at offset %s",
-                     hex_string (SYMBOL_VALUE (symbol)));
+                     hex_string (symbol->value_longest ()));
          break;
 
        case LOC_REF_ARG:
          gdb_printf (outfile, "reference arg at %s",
-                     hex_string (SYMBOL_VALUE (symbol)));
+                     hex_string (symbol->value_longest ()));
          break;
 
        case LOC_REGPARM_ADDR:
          gdb_printf (outfile, "address parameter register %s",
-                     plongest (SYMBOL_VALUE (symbol)));
+                     plongest (symbol->value_longest ()));
          break;
 
        case LOC_LOCAL:
          gdb_printf (outfile, "local at offset %s",
-                     hex_string (SYMBOL_VALUE (symbol)));
+                     hex_string (symbol->value_longest ()));
          break;
 
        case LOC_TYPEDEF:
@@ -622,8 +613,7 @@ print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
 
        case LOC_LABEL:
          gdb_printf (outfile, "label at ");
-         gdb_puts (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)),
-                   outfile);
+         gdb_puts (paddress (gdbarch, symbol->value_address ()), outfile);
          if (section)
            gdb_printf (outfile, " section %s",
                        bfd_section_name (section->the_bfd_section));
@@ -632,9 +622,9 @@ print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
        case LOC_BLOCK:
          gdb_printf
            (outfile, "block object %s, %s..%s",
-            host_address_to_string (SYMBOL_BLOCK_VALUE (symbol)),
-            paddress (gdbarch, BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))),
-            paddress (gdbarch, BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))));
+            host_address_to_string (symbol->value_block ()),
+            paddress (gdbarch, symbol->value_block()->start ()),
+            paddress (gdbarch, symbol->value_block()->end ()));
          if (section)
            gdb_printf (outfile, " section %s",
                        bfd_section_name (section->the_bfd_section));
@@ -781,6 +771,7 @@ maintenance_info_symtabs (const char *regexp, int from_tty)
                        gdb_printf ("    producer %s\n",
                                    (cust->producer () != nullptr
                                     ? cust->producer () : "(null)"));
+                       gdb_printf ("    name %s\n", cust->name);
                        gdb_printf ("    dirname %s\n",
                                    (cust->dirname () != NULL
                                     ? cust->dirname () : "(null)"));
@@ -940,7 +931,7 @@ block_depth (const struct block *block)
 {
   int i = 0;
 
-  while ((block = BLOCK_SUPERBLOCK (block)) != NULL)
+  while ((block = block->superblock ()) != NULL)
     {
       i++;
     }
@@ -954,7 +945,7 @@ block_depth (const struct block *block)
 static int
 maintenance_print_one_line_table (struct symtab *symtab, void *data)
 {
-  struct linetable *linetable;
+  const struct linetable *linetable;
   struct objfile *objfile;
 
   objfile = symtab->compunit ()->objfile ();
@@ -982,16 +973,18 @@ maintenance_print_one_line_table (struct symtab *symtab, void *data)
       /* Leave space for 6 digits of index and line number.  After that the
         tables will just not format as well.  */
       struct ui_out *uiout = current_uiout;
-      ui_out_emit_table table_emitter (uiout, 4, -1, "line-table");
+      ui_out_emit_table table_emitter (uiout, 6, -1, "line-table");
       uiout->table_header (6, ui_left, "index", _("INDEX"));
       uiout->table_header (6, ui_left, "line", _("LINE"));
-      uiout->table_header (18, ui_left, "address", _("ADDRESS"));
-      uiout->table_header (1, ui_left, "is-stmt", _("IS-STMT"));
+      uiout->table_header (18, ui_left, "rel-address", _("REL-ADDRESS"));
+      uiout->table_header (18, ui_left, "unrel-address", _("UNREL-ADDRESS"));
+      uiout->table_header (7, ui_left, "is-stmt", _("IS-STMT"));
+      uiout->table_header (12, ui_left, "prologue-end", _("PROLOGUE-END"));
       uiout->table_body ();
 
       for (int i = 0; i < linetable->nitems; ++i)
        {
-         struct linetable_entry *item;
+         const linetable_entry *item;
 
          item = &linetable->item [i];
          ui_out_emit_tuple tuple_emitter (uiout, nullptr);
@@ -1000,9 +993,12 @@ maintenance_print_one_line_table (struct symtab *symtab, void *data)
            uiout->field_signed ("line", item->line);
          else
            uiout->field_string ("line", _("END"));
-         uiout->field_core_addr ("address", objfile->arch (),
-                                 item->pc);
+         uiout->field_core_addr ("rel-address", objfile->arch (),
+                                 item->pc (objfile));
+         uiout->field_core_addr ("unrel-address", objfile->arch (),
+                                 CORE_ADDR (item->unrelocated_pc ()));
          uiout->field_string ("is-stmt", item->is_stmt ? "Y" : "");
+         uiout->field_string ("prologue-end", item->prologue_end ? "Y" : "");
          uiout->text ("\n");
        }
     }