Files
binutils-gdb/gdb/dwarf2/stringify.c
Tom Tromey 486bc5ac81 Rewrite the .gdb_index reader
This patch rewrites the .gdb_index reader to create the same data
structures that are created by the cooked indexer and the .debug_names
reader.

This is done in support of this series; but also because, from what I
can tell, the "templates.exp" change didn't really work properly with
this reader.

In addition to fixing that problem, this patch removes a lot of code.

Implementing this required a couple of hacks, as .gdb_index does not
contain all the information that's used by the cooked index
implementation.

* The index-searching code likes to differentiate between the various
  DWARF tags when matching, but .gdb_index lumps many things into a
  single "other" category.  To handle this, we introduce a phony tag
  that's used so that the match method can match on multiple domains.

* Similarly, .gdb_index doesn't distinguish between the type and
  struct domains, so another phony tag is used for this.

* The reader must attempt to guess the language of various symbols.
  This is somewhat finicky.  "Plain" (unqualified) symbols are marked
  as language_unknown and then a couple of hacks are used to handle
  these -- one in expand_symtabs_matching and another when recognizing
  "main".

For what it's worth, I consider .gdb_index to be near the end of its
life.  While .debug_names is not perfect -- we found a number of bugs
in the standard while implementing it -- it is better than .gdb_index
and also better documented.

After this patch, we could conceivably remove dwarf_scanner_base.
However, I have not done this.

Finally, this patch also changes this reader to dump the content of
the index, as the other DWARF readers do.  This can be handy when
debugging gdb.

Acked-By: Simon Marchi <simon.marchi@efficios.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33316
2025-09-10 16:05:28 -06:00

133 lines
3.0 KiB
C

/* DWARF stringify code
Copyright (C) 1994-2025 Free Software Foundation, Inc.
Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
Inc. with support from Florida State University (under contract
with the Ada Joint Program Office), and Silicon Graphics, Inc.
Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
based on Fred Fish's (Cygnus Support) implementation of DWARF 1
support.
This file is part of GDB.
This program 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.
This program 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/>. */
#include "dwarf2.h"
#include "dwarf2/read-gdb-index.h"
#include "dwarf2/stringify.h"
/* A convenience function that returns an "unknown" DWARF name,
including the value of V. STR is the name of the entity being
printed, e.g., "TAG". */
static const char *
dwarf_unknown (const char *str, unsigned v)
{
char *cell = get_print_cell ();
xsnprintf (cell, PRINT_CELL_SIZE, "DW_%s_<unknown: %u>", str, v);
return cell;
}
/* See stringify.h. */
const char *
dwarf_tag_name (unsigned tag)
{
if (tag == DW_TAG_GDB_INDEX_OTHER)
return "DW_TAG_GDB_INDEX_OTHER";
else if (tag == DW_TAG_GDB_INDEX_TYPE)
return "DW_TAG_GDB_INDEX_TYPE";
const char *name = get_DW_TAG_name (tag);
if (name == NULL)
return dwarf_unknown ("TAG", tag);
return name;
}
/* See stringify.h. */
const char *
dwarf_attr_name (unsigned attr)
{
const char *name;
#ifdef MIPS /* collides with DW_AT_HP_block_index */
if (attr == DW_AT_MIPS_fde)
return "DW_AT_MIPS_fde";
#else
if (attr == DW_AT_HP_block_index)
return "DW_AT_HP_block_index";
#endif
name = get_DW_AT_name (attr);
if (name == NULL)
return dwarf_unknown ("AT", attr);
return name;
}
/* See stringify.h. */
const char *
dwarf_form_name (unsigned form)
{
const char *name = get_DW_FORM_name (form);
if (name == NULL)
return dwarf_unknown ("FORM", form);
return name;
}
/* See stringify.h. */
const char *
dwarf_bool_name (unsigned mybool)
{
if (mybool)
return "TRUE";
else
return "FALSE";
}
/* See stringify.h. */
const char *
dwarf_type_encoding_name (unsigned enc)
{
const char *name = get_DW_ATE_name (enc);
if (name == NULL)
return dwarf_unknown ("ATE", enc);
return name;
}
/* See stringify.h. */
const char *
dwarf_unit_type_name (int unit_type)
{
const char *name = get_DW_UT_name (unit_type);
if (name == nullptr)
return dwarf_unknown ("UT", unit_type);
return name;
}