public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Add name_of_main and language_of_main to the DWARF index
@ 2023-10-06 18:31 Tom de Vries
  2023-10-06 18:31 ` [PATCH 1/2] [gdb/symtab] " Tom de Vries
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Tom de Vries @ 2023-10-06 18:31 UTC (permalink / raw)
  To: gdb-patches

This is a patch series containing:
- a gdb patch introducing a new version of the .gdb_index section,
  adding a shortcut table.
- a readelf patch adding the capability to read the new version, as
  well print the shortcuts table.

This is v4 of the gdb patch.  The v3 was submitted here (
https://sourceware.org/pipermail/gdb-patches/2023-August/201568.html ).

Changes in v4:
- fixed a few whitespace issues.
- reformulated 'A 32-bit little-endian value' to 'An @code{offset_type} value'
  in the docs.
- mentioned PR symtab/30946 in the commit log.
- updated a pre-existing unit test.

I've already approved v3, and the v4 changes are trivial.

The readelf patch is new.

Tested on x86_64-linux.

Matheus Branco Borella (1):
  [gdb/symtab] Add name_of_main and language_of_main to the DWARF index

Tom de Vries (1):
  [readelf] Handle .gdb_index section version 9

 binutils/dwarf.c            | 176 +++++++++++++++++++++++-------------
 gdb/NEWS                    |   3 +
 gdb/doc/gdb.texinfo         |  23 ++++-
 gdb/dwarf2/index-write.c    |  54 +++++++++--
 gdb/dwarf2/read-gdb-index.c |  54 ++++++++++-
 gdb/dwarf2/read.c           |  13 ++-
 gdb/dwarf2/read.h           |  12 +++
 7 files changed, 259 insertions(+), 76 deletions(-)


base-commit: 9a896be33224654760c46d3698218241d0a1f354
-- 
2.35.3


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

* [PATCH 1/2] [gdb/symtab] Add name_of_main and language_of_main to the DWARF index
  2023-10-06 18:31 [PATCH 0/2] Add name_of_main and language_of_main to the DWARF index Tom de Vries
@ 2023-10-06 18:31 ` Tom de Vries
  2023-10-10 19:19   ` Tom Tromey
  2023-10-06 18:31 ` [PATCH 2/2] [readelf] Handle .gdb_index section version 9 Tom de Vries
  2023-10-06 18:33 ` [PATCH 0/2] Add name_of_main and language_of_main to the DWARF index Tom de Vries
  2 siblings, 1 reply; 12+ messages in thread
From: Tom de Vries @ 2023-10-06 18:31 UTC (permalink / raw)
  To: gdb-patches

From: Matheus Branco Borella <dark.ryu.550@gmail.com>

This patch adds a new section to the DWARF index containing the name
and the language of the main function symbol, gathered from
`cooked_index::get_main`, if available. Currently, for lack of a better name,
this section is called the "shortcut table". The way this name is both saved and
applied upon an index being loaded in mirrors how it is done in
`cooked_index_functions`, more specifically, the full name of the main function
symbol is saved and `set_objfile_main_name` is used to apply it after it is
loaded.

The main use case for this patch is in improving startup times when dealing with
large binaries. Currently, when an index is used, GDB has to expand symtabs
until it finds out what the language of the main function symbol is. For some
large executables, this may take a considerable amount of time to complete,
slowing down startup. This patch bypasses that operation by having both the name
and language of the main function symbol be provided ahead of time by the index.

In my testing (a binary with about 1.8GB worth of DWARF data) this change brings
startup time down from about 34 seconds to about 1.5 seconds.

When testing the patch with target board cc-with-gdb-index, test-case
gdb.fortran/nested-funcs-2.exp starts failing, but this is due to a
pre-existing issue, filed as PR symtab/30946.

Tested on x86_64-linux, with target board unix and cc-with-gdb-index.

PR symtab/24549
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24549
---
 gdb/NEWS                    |  3 +++
 gdb/doc/gdb.texinfo         | 23 ++++++++++++++--
 gdb/dwarf2/index-write.c    | 54 +++++++++++++++++++++++++++++++------
 gdb/dwarf2/read-gdb-index.c | 54 ++++++++++++++++++++++++++++++++++++-
 gdb/dwarf2/read.c           | 13 +++++++--
 gdb/dwarf2/read.h           | 12 +++++++++
 6 files changed, 146 insertions(+), 13 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 2f6378f9c7a..20f36d278bd 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -21,6 +21,9 @@
   styling according to the spec.  See https://no-color.org/.
   Styling can be re-enabled with "set style enabled on".
 
+* GDB index now contains information about the main function. This speeds up
+  startup when it is being used for some large binaries.
+
 * The AArch64 'org.gnu.gdb.aarch64.pauth' Pointer Authentication feature string
   has been deprecated in favor of the 'org.gnu.gdb.aarch64.pauth_v2' feature
   string.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 4932e49b758..db1a82ec838 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -49663,13 +49663,14 @@ unless otherwise noted:
 
 @enumerate
 @item
-The version number, currently 8.  Versions 1, 2 and 3 are obsolete.
+The version number, currently 9.  Versions 1, 2 and 3 are obsolete.
 Version 4 uses a different hashing function from versions 5 and 6.
 Version 6 includes symbols for inlined functions, whereas versions 4
 and 5 do not.  Version 7 adds attributes to the CU indices in the
 symbol table.  Version 8 specifies that symbols from DWARF type units
 (@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
-compilation unit (@samp{DW_TAG_comp_unit}) using the type.
+compilation unit (@samp{DW_TAG_comp_unit}) using the type.  Version 9 adds
+the name and the language of the main function to the index.
 
 @value{GDBN} will only read version 4, 5, or 6 indices
 by specifying @code{set use-deprecated-index-sections on}.
@@ -49690,6 +49691,9 @@ The offset, from the start of the file, of the address area.
 @item
 The offset, from the start of the file, of the symbol table.
 
+@item
+The offset, from the start of the file, of the shortcut table.
+
 @item
 The offset, from the start of the file, of the constant pool.
 @end enumerate
@@ -49766,6 +49770,21 @@ don't currently have a simple description of the canonicalization
 algorithm; if you intend to create new index sections, you must read
 the code.
 
+@item The shortcut table
+This is a data structure with the following fields:
+
+@table @asis
+@item Language of main
+An @code{offset_type} value indicating the language of the main function as a
+@code{DW_LANG_} constant.  This value will be zero if main function information
+is not present.
+
+@item Name of main
+An @code{offset_type} value indicating the offset of the main function's name
+in the constant pool.  This value must be ignored if the value for the language
+of main is zero.
+@end table
+
 @item
 The constant pool.  This is simply a bunch of bytes.  It is organized
 so that alignment is correct: CU vectors are stored first, followed by
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 3acff266ab3..6ea4217fb22 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1079,14 +1079,15 @@ write_gdbindex_1 (FILE *out_file,
 		  const data_buf &types_cu_list,
 		  const data_buf &addr_vec,
 		  const data_buf &symtab_vec,
-		  const data_buf &constant_pool)
+		  const data_buf &constant_pool,
+		  const data_buf &shortcuts)
 {
   data_buf contents;
-  const offset_type size_of_header = 6 * sizeof (offset_type);
+  const offset_type size_of_header = 7 * sizeof (offset_type);
   uint64_t total_len = size_of_header;
 
   /* The version number.  */
-  contents.append_offset (8);
+  contents.append_offset (9);
 
   /* The offset of the CU list from the start of the file.  */
   contents.append_offset (total_len);
@@ -1104,6 +1105,10 @@ write_gdbindex_1 (FILE *out_file,
   contents.append_offset (total_len);
   total_len += symtab_vec.size ();
 
+  /* The offset of the shortcut table from the start of the file.  */
+  contents.append_offset (total_len);
+  total_len += shortcuts.size ();
+
   /* The offset of the constant pool from the start of the file.  */
   contents.append_offset (total_len);
   total_len += constant_pool.size ();
@@ -1125,6 +1130,7 @@ write_gdbindex_1 (FILE *out_file,
   types_cu_list.file_write (out_file);
   addr_vec.file_write (out_file);
   symtab_vec.file_write (out_file);
+  shortcuts.file_write (out_file);
   constant_pool.file_write (out_file);
 
   assert_file_size (out_file, total_len);
@@ -1187,6 +1193,34 @@ write_cooked_index (cooked_index *table,
     }
 }
 
+/* Write shortcut information. */
+
+static void
+write_shortcuts_table (cooked_index *table, data_buf& shortcuts,
+		       data_buf& cpool)
+{
+  const auto main_info = table->get_main ();
+  size_t main_name_offset = 0;
+  dwarf_source_language dw_lang = (dwarf_source_language)0;
+
+  if (main_info != nullptr)
+    {
+      dw_lang = main_info->per_cu->dw_lang;
+
+      if (dw_lang != 0)
+	{
+	  auto_obstack obstack;
+	  const auto main_name = main_info->full_name (&obstack, true);
+
+	  main_name_offset = cpool.size ();
+	  cpool.append_cstr0 (main_name);
+	}
+    }
+
+  shortcuts.append_uint (4, BFD_ENDIAN_LITTLE, dw_lang);
+  shortcuts.append_offset (main_name_offset);
+}
+
 /* Write contents of a .gdb_index section for OBJFILE into OUT_FILE.
    If OBJFILE has an associated dwz file, write contents of a .gdb_index
    section for that dwz file into DWZ_OUT_FILE.  If OBJFILE does not have an
@@ -1263,11 +1297,14 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table,
 
   write_hash_table (&symtab, symtab_vec, constant_pool);
 
+  data_buf shortcuts;
+  write_shortcuts_table (table, shortcuts, constant_pool);
+
   write_gdbindex_1(out_file, objfile_cu_list, types_cu_list, addr_vec,
-		   symtab_vec, constant_pool);
+		   symtab_vec, constant_pool, shortcuts);
 
   if (dwz_out_file != NULL)
-    write_gdbindex_1 (dwz_out_file, dwz_cu_list, {}, {}, {}, {});
+    write_gdbindex_1 (dwz_out_file, dwz_cu_list, {}, {}, {}, {}, {});
   else
     gdb_assert (dwz_cu_list.empty ());
 }
@@ -1573,8 +1610,9 @@ gdb_index ()
   pretend_data_buf addr_vec;
   pretend_data_buf symtab_vec;
   pretend_data_buf constant_pool;
+  pretend_data_buf short_cuts;
 
-  const size_t size_of_header = 6 * sizeof (offset_type);
+  const size_t size_of_header = 7 * sizeof (offset_type);
 
   /* Test that an overly large index will throw an error.  */
   symtab_vec.set_pretend_size (~(offset_type)0 - size_of_header);
@@ -1584,7 +1622,7 @@ gdb_index ()
   try
     {
       write_gdbindex_1 (nullptr, cu_list, types_cu_list, addr_vec,
-			symtab_vec, constant_pool);
+			symtab_vec, constant_pool, short_cuts);
     }
   catch (const gdb_exception_error &e)
     {
@@ -1604,7 +1642,7 @@ gdb_index ()
   try
     {
       write_gdbindex_1 (nullptr, cu_list, types_cu_list, addr_vec,
-			symtab_vec, constant_pool);
+			symtab_vec, constant_pool, short_cuts);
     }
   catch (const gdb_exception_error &e)
     {
diff --git a/gdb/dwarf2/read-gdb-index.c b/gdb/dwarf2/read-gdb-index.c
index 9bfc5302b0e..b96eaa96e23 100644
--- a/gdb/dwarf2/read-gdb-index.c
+++ b/gdb/dwarf2/read-gdb-index.c
@@ -88,6 +88,9 @@ struct mapped_gdb_index final : public mapped_index_base
   /* A pointer to the constant pool.  */
   gdb::array_view<const gdb_byte> constant_pool;
 
+  /* The shortcut table data. */
+  gdb::array_view<const gdb_byte> shortcut_table;
+
   /* Return the index into the constant pool of the name of the IDXth
      symbol in the symbol table.  */
   offset_type symbol_name_index (offset_type idx) const
@@ -583,7 +586,7 @@ to use the section anyway."),
 
   /* Indexes with higher version than the one supported by GDB may be no
      longer backward compatible.  */
-  if (version > 8)
+  if (version > 9)
     return 0;
 
   map->version = version;
@@ -610,6 +613,16 @@ to use the section anyway."),
 						    symbol_table_end));
 
   ++i;
+
+  if (version >= 9)
+    {
+      const gdb_byte *shortcut_table = addr + metadata[i];
+      const gdb_byte *shortcut_table_end = addr + metadata[i + 1];
+      map->shortcut_table
+	= gdb::array_view<const gdb_byte> (shortcut_table, shortcut_table_end);
+      ++i;
+    }
+
   map->constant_pool = buffer.slice (metadata[i]);
 
   if (map->constant_pool.empty () && !map->symbol_table.empty ())
@@ -758,6 +771,43 @@ create_addrmap_from_gdb_index (dwarf2_per_objfile *per_objfile,
     = new (&per_bfd->obstack) addrmap_fixed (&per_bfd->obstack, &mutable_map);
 }
 
+/* Sets the name and language of the main function from the shortcut table. */
+
+static void
+set_main_name_from_gdb_index (dwarf2_per_objfile *per_objfile,
+			      mapped_gdb_index *index)
+{
+  const auto expected_size = 4 + sizeof (offset_type);
+  if (index->shortcut_table.size () < expected_size)
+    /* The data in the section is not present, is corrupted or is in a version
+     * we don't know about. Regardless, we can't make use of it. */
+    return;
+
+  auto ptr = index->shortcut_table.data ();
+  const auto dw_lang = extract_unsigned_integer (ptr, 4, BFD_ENDIAN_LITTLE);
+  if (dw_lang >= DW_LANG_hi_user)
+    {
+      complaint (_(".gdb_index shortcut table has invalid main language %u"),
+		   (unsigned) dw_lang);
+      return;
+    }
+  if (dw_lang == 0)
+    {
+      /* Don't bother if the language for the main symbol was not known or if
+       * there was no main symbol at all when the index was built. */
+      return;
+    }
+  ptr += 4;
+
+  const auto lang = dwarf_lang_to_enum_language (dw_lang);
+  const auto name_offset = extract_unsigned_integer (ptr,
+						     sizeof (offset_type),
+						     BFD_ENDIAN_LITTLE);
+  const auto name = (const char*) (index->constant_pool.data () + name_offset);
+
+  set_objfile_main_name (per_objfile->objfile, name, (enum language) lang);
+}
+
 /* See read-gdb-index.h.  */
 
 int
@@ -843,6 +893,8 @@ dwarf2_read_gdb_index
 
   create_addrmap_from_gdb_index (per_objfile, map.get ());
 
+  set_main_name_from_gdb_index (per_objfile, map.get ());
+
   per_bfd->index_table = std::move (map);
   per_bfd->quick_file_names_table =
     create_quick_file_names_table (per_bfd->all_units.size ());
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 5bbc8e24cf9..d4aec19d31d 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -17796,7 +17796,9 @@ leb128_size (const gdb_byte *buf)
     }
 }
 
-static enum language
+/* Converts DWARF language names to GDB language names. */
+
+enum language
 dwarf_lang_to_enum_language (unsigned int lang)
 {
   enum language language;
@@ -21725,6 +21727,7 @@ prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die,
   /* Set the language we're debugging.  */
   attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu);
   enum language lang;
+  dwarf_source_language dw_lang = (dwarf_source_language)0;
   if (cu->producer != nullptr
       && strstr (cu->producer, "IBM XL C for OpenCL") != NULL)
     {
@@ -21733,18 +21736,24 @@ prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die,
 	 language detection we fall back to the DW_AT_producer
 	 string.  */
       lang = language_opencl;
+      dw_lang = DW_LANG_OpenCL;
     }
   else if (cu->producer != nullptr
 	   && strstr (cu->producer, "GNU Go ") != NULL)
     {
       /* Similar hack for Go.  */
       lang = language_go;
+      dw_lang = DW_LANG_Go;
     }
   else if (attr != nullptr)
-    lang = dwarf_lang_to_enum_language (attr->constant_value (0));
+    {
+      lang = dwarf_lang_to_enum_language (attr->constant_value (0));
+      dw_lang = (dwarf_source_language)attr->constant_value (0);
+    }
   else
     lang = pretend_language;
 
+  cu->per_cu->dw_lang = dw_lang;
   cu->language_defn = language_def (lang);
 
   switch (comp_unit_die->tag)
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 9dfc435e861..1d9432c5c11 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -245,6 +245,14 @@ struct dwarf2_per_cu_data
      functions above.  */
   std::vector <dwarf2_per_cu_data *> *imported_symtabs = nullptr;
 
+  /* The original DW_LANG_* value of the CU, as provided to us by
+   * DW_AT_language. It is interesting to keep this value around in cases where
+   * we can't use the values from the language enum, as the mapping to them is
+   * lossy, and, while that is usually fine, things like the index have an
+   * understandable bias towards not exposing internal GDB structures to the
+   * outside world, and so prefer to use DWARF constants in their stead. */
+  dwarf_source_language dw_lang;
+
   /* Return true of IMPORTED_SYMTABS is empty or not yet allocated.  */
   bool imported_symtabs_empty () const
   {
@@ -764,6 +772,10 @@ struct dwarf2_per_objfile
 		     std::unique_ptr<dwarf2_cu>> m_dwarf2_cus;
 };
 
+/* Converts DWARF language names to GDB language names. */
+
+enum language dwarf_lang_to_enum_language (unsigned int lang);
+
 /* Get the dwarf2_per_objfile associated to OBJFILE.  */
 
 dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile);
-- 
2.35.3


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

* [PATCH 2/2] [readelf] Handle .gdb_index section version 9
  2023-10-06 18:31 [PATCH 0/2] Add name_of_main and language_of_main to the DWARF index Tom de Vries
  2023-10-06 18:31 ` [PATCH 1/2] [gdb/symtab] " Tom de Vries
@ 2023-10-06 18:31 ` Tom de Vries
  2023-10-06 18:33 ` [PATCH 0/2] Add name_of_main and language_of_main to the DWARF index Tom de Vries
  2 siblings, 0 replies; 12+ messages in thread
From: Tom de Vries @ 2023-10-06 18:31 UTC (permalink / raw)
  To: gdb-patches

Add the abilitity to print a v9 .gdb_index section.

The v9 section contains an extra table, which is printed as follows:
...
Shortcut table:
Language of main: Fortran 95
Name of main: contains_keyword
...

[ For the example, I used the exec of gdb test-case
gdb.fortran/nested-funcs-2-exp when running the test-case with target board
cc-with-gdb-index. ]

Tested on x86_64-linux.
---
 binutils/dwarf.c | 176 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 113 insertions(+), 63 deletions(-)

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 7a350cae50b..6adc37c9169 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -2342,6 +2342,72 @@ display_discr_list (unsigned long form,
     printf (")(unsigned)");
 }
 
+static void
+display_lang (uint64_t uvalue)
+{
+  switch (uvalue)
+    {
+      /* Ordered by the numeric value of these constants.  */
+    case DW_LANG_C89:			printf ("ANSI C"); break;
+    case DW_LANG_C:			printf ("non-ANSI C"); break;
+    case DW_LANG_Ada83:			printf ("Ada"); break;
+    case DW_LANG_C_plus_plus:		printf ("C++"); break;
+    case DW_LANG_Cobol74:		printf ("Cobol 74"); break;
+    case DW_LANG_Cobol85:		printf ("Cobol 85"); break;
+    case DW_LANG_Fortran77:		printf ("FORTRAN 77"); break;
+    case DW_LANG_Fortran90:		printf ("Fortran 90"); break;
+    case DW_LANG_Pascal83:		printf ("ANSI Pascal"); break;
+    case DW_LANG_Modula2:		printf ("Modula 2"); break;
+
+      /* DWARF 2.1 values.	*/
+    case DW_LANG_Java:			printf ("Java"); break;
+    case DW_LANG_C99:			printf ("ANSI C99"); break;
+    case DW_LANG_Ada95:			printf ("ADA 95"); break;
+    case DW_LANG_Fortran95:		printf ("Fortran 95"); break;
+
+      /* DWARF 3 values.  */
+    case DW_LANG_PLI:			printf ("PLI"); break;
+    case DW_LANG_ObjC:			printf ("Objective C"); break;
+    case DW_LANG_ObjC_plus_plus:	printf ("Objective C++"); break;
+    case DW_LANG_UPC:			printf ("Unified Parallel C"); break;
+    case DW_LANG_D:			printf ("D"); break;
+
+      /* DWARF 4 values.  */
+    case DW_LANG_Python:		printf ("Python"); break;
+
+      /* DWARF 5 values.  */
+    case DW_LANG_OpenCL:		printf ("OpenCL"); break;
+    case DW_LANG_Go:			printf ("Go"); break;
+    case DW_LANG_Modula3:		printf ("Modula 3"); break;
+    case DW_LANG_Haskell:		printf ("Haskell"); break;
+    case DW_LANG_C_plus_plus_03:	printf ("C++03"); break;
+    case DW_LANG_C_plus_plus_11:	printf ("C++11"); break;
+    case DW_LANG_OCaml:			printf ("OCaml"); break;
+    case DW_LANG_Rust:			printf ("Rust"); break;
+    case DW_LANG_C11:			printf ("C11"); break;
+    case DW_LANG_Swift:			printf ("Swift"); break;
+    case DW_LANG_Julia:			printf ("Julia"); break;
+    case DW_LANG_Dylan:			printf ("Dylan"); break;
+    case DW_LANG_C_plus_plus_14:	printf ("C++14"); break;
+    case DW_LANG_Fortran03:		printf ("Fortran 03"); break;
+    case DW_LANG_Fortran08:		printf ("Fortran 08"); break;
+    case DW_LANG_RenderScript:		printf ("RenderScript"); break;
+
+      /* MIPS extension.  */
+    case DW_LANG_Mips_Assembler:	printf ("MIPS assembler"); break;
+
+      /* UPC extension.  */
+    case DW_LANG_Upc:			printf ("Unified Parallel C"); break;
+
+    default:
+      if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
+	printf (_("implementation defined: %#" PRIx64 ""), uvalue);
+      else
+	printf (_("unknown: %#" PRIx64 ""), uvalue);
+      break;
+    }
+}
+
 static unsigned char *
 read_and_display_attr_value (unsigned long attribute,
 			     unsigned long form,
@@ -3110,61 +3176,9 @@ read_and_display_attr_value (unsigned long attribute,
       break;
 
     case DW_AT_language:
-      printf ("\t");
-      switch (uvalue)
-	{
-	  /* Ordered by the numeric value of these constants.  */
-	case DW_LANG_C89:		printf ("(ANSI C)"); break;
-	case DW_LANG_C:			printf ("(non-ANSI C)"); break;
-	case DW_LANG_Ada83:		printf ("(Ada)"); break;
-	case DW_LANG_C_plus_plus:	printf ("(C++)"); break;
-	case DW_LANG_Cobol74:		printf ("(Cobol 74)"); break;
-	case DW_LANG_Cobol85:		printf ("(Cobol 85)"); break;
-	case DW_LANG_Fortran77:		printf ("(FORTRAN 77)"); break;
-	case DW_LANG_Fortran90:		printf ("(Fortran 90)"); break;
-	case DW_LANG_Pascal83:		printf ("(ANSI Pascal)"); break;
-	case DW_LANG_Modula2:		printf ("(Modula 2)"); break;
-	  /* DWARF 2.1 values.	*/
-	case DW_LANG_Java:		printf ("(Java)"); break;
-	case DW_LANG_C99:		printf ("(ANSI C99)"); break;
-	case DW_LANG_Ada95:		printf ("(ADA 95)"); break;
-	case DW_LANG_Fortran95:		printf ("(Fortran 95)"); break;
-	  /* DWARF 3 values.  */
-	case DW_LANG_PLI:		printf ("(PLI)"); break;
-	case DW_LANG_ObjC:		printf ("(Objective C)"); break;
-	case DW_LANG_ObjC_plus_plus:	printf ("(Objective C++)"); break;
-	case DW_LANG_UPC:		printf ("(Unified Parallel C)"); break;
-	case DW_LANG_D:			printf ("(D)"); break;
-	  /* DWARF 4 values.  */
-	case DW_LANG_Python:		printf ("(Python)"); break;
-	  /* DWARF 5 values.  */
-	case DW_LANG_OpenCL:		printf ("(OpenCL)"); break;
-	case DW_LANG_Go:		printf ("(Go)"); break;
-	case DW_LANG_Modula3:		printf ("(Modula 3)"); break;
-	case DW_LANG_Haskell:		printf ("(Haskell)"); break;
-	case DW_LANG_C_plus_plus_03:	printf ("(C++03)"); break;
-	case DW_LANG_C_plus_plus_11:	printf ("(C++11)"); break;
-	case DW_LANG_OCaml:		printf ("(OCaml)"); break;
-	case DW_LANG_Rust:		printf ("(Rust)"); break;
-	case DW_LANG_C11:		printf ("(C11)"); break;
-	case DW_LANG_Swift:		printf ("(Swift)"); break;
-	case DW_LANG_Julia:		printf ("(Julia)"); break;
-	case DW_LANG_Dylan:		printf ("(Dylan)"); break;
-	case DW_LANG_C_plus_plus_14:	printf ("(C++14)"); break;
-	case DW_LANG_Fortran03:		printf ("(Fortran 03)"); break;
-	case DW_LANG_Fortran08:		printf ("(Fortran 08)"); break;
-	case DW_LANG_RenderScript:	printf ("(RenderScript)"); break;
-	  /* MIPS extension.  */
-	case DW_LANG_Mips_Assembler:	printf ("(MIPS assembler)"); break;
-	  /* UPC extension.  */
-	case DW_LANG_Upc:		printf ("(Unified Parallel C)"); break;
-	default:
-	  if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
-	    printf (_("(implementation defined: %#" PRIx64 ")"), uvalue);
-	  else
-	    printf (_("(unknown: %#" PRIx64 ")"), uvalue);
-	  break;
-	}
+      printf ("\t(");
+      display_lang (uvalue);
+      printf (")");
       break;
 
     case DW_AT_encoding:
@@ -10738,29 +10752,31 @@ display_gdb_index (struct dwarf_section *section,
   unsigned char *start = section->start;
   uint32_t version;
   uint32_t cu_list_offset, tu_list_offset;
-  uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
+  uint32_t address_table_offset, symbol_table_offset, constant_pool_offset,
+    shortcut_table_offset;
   unsigned int cu_list_elements, tu_list_elements;
   unsigned int address_table_elements, symbol_table_slots;
   unsigned char *cu_list, *tu_list;
-  unsigned char *address_table, *symbol_table, *constant_pool;
+  unsigned char *address_table, *symbol_table, *shortcut_table, *constant_pool;
   unsigned int i;
 
   /* The documentation for the format of this file is in gdb/dwarf2read.c.  */
 
   introduce (section, false);
 
-  if (section->size < 6 * sizeof (uint32_t))
+  version = section->size < 4 ? 0 : byte_get_little_endian (start, 4);
+  size_t header_size = (version < 9 ? 6 : 7) * sizeof (uint32_t);
+  if (section->size < header_size)
     {
       warn (_("Truncated header in the %s section.\n"), section->name);
       return 0;
     }
 
-  version = byte_get_little_endian (start, 4);
   printf (_("Version %lu\n"), (unsigned long) version);
 
   /* Prior versions are obsolete, and future versions may not be
      backwards compatible.  */
-  if (version < 3 || version > 8)
+  if (version < 3 || version > 9)
     {
       warn (_("Unsupported version %lu.\n"), (unsigned long) version);
       return 0;
@@ -10782,17 +10798,23 @@ display_gdb_index (struct dwarf_section *section,
   tu_list_offset = byte_get_little_endian (start + 8, 4);
   address_table_offset = byte_get_little_endian (start + 12, 4);
   symbol_table_offset = byte_get_little_endian (start + 16, 4);
-  constant_pool_offset = byte_get_little_endian (start + 20, 4);
+  shortcut_table_offset = byte_get_little_endian (start + 20, 4);
+  if (version < 9)
+    constant_pool_offset = shortcut_table_offset;
+  else
+    constant_pool_offset = byte_get_little_endian (start + 24, 4);
 
   if (cu_list_offset > section->size
       || tu_list_offset > section->size
       || address_table_offset > section->size
       || symbol_table_offset > section->size
+      || shortcut_table_offset > section->size
       || constant_pool_offset > section->size
       || tu_list_offset < cu_list_offset
       || address_table_offset < tu_list_offset
       || symbol_table_offset < address_table_offset
-      || constant_pool_offset < symbol_table_offset)
+      || shortcut_table_offset < symbol_table_offset
+      || constant_pool_offset < shortcut_table_offset)
     {
       warn (_("Corrupt header in the %s section.\n"), section->name);
       return 0;
@@ -10801,12 +10823,13 @@ display_gdb_index (struct dwarf_section *section,
   cu_list_elements = (tu_list_offset - cu_list_offset) / 16;
   tu_list_elements = (address_table_offset - tu_list_offset) / 24;
   address_table_elements = (symbol_table_offset - address_table_offset) / 20;
-  symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
+  symbol_table_slots = (shortcut_table_offset - symbol_table_offset) / 8;
 
   cu_list = start + cu_list_offset;
   tu_list = start + tu_list_offset;
   address_table = start + address_table_offset;
   symbol_table = start + symbol_table_offset;
+  shortcut_table = start + shortcut_table_offset;
   constant_pool = start + constant_pool_offset;
 
   printf (_("\nCU table:\n"));
@@ -10918,6 +10941,33 @@ display_gdb_index (struct dwarf_section *section,
 	}
     }
 
+  if (version > 9)
+    {
+      printf (_("\nShortcut table:\n"));
+
+      if (shortcut_table_offset + 8 > constant_pool_offset)
+	{
+	  warn (_("Corrupt shortcut table in the %s section.\n"), section->name);
+	  return 0;
+	}
+
+      uint32_t lang = byte_get_little_endian (shortcut_table, 4);
+      printf (_("Language of main: "));
+      display_lang (lang);
+      printf ("\n");
+
+      uint32_t name_offset = byte_get_little_endian (shortcut_table + 4, 4);
+      printf (_("Name of main: "));
+      if (name_offset >= section->size - constant_pool_offset)
+	{
+	  printf (_("<corrupt offset: %x>\n"), name_offset);
+	  warn (_("Corrupt name offset of 0x%x found for name of main\n"),
+		name_offset);
+	}
+      else
+	printf ("%s\n", constant_pool + name_offset);
+    }
+
   return 1;
 }
 
-- 
2.35.3


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

* Re: [PATCH 0/2] Add name_of_main and language_of_main to the DWARF index
  2023-10-06 18:31 [PATCH 0/2] Add name_of_main and language_of_main to the DWARF index Tom de Vries
  2023-10-06 18:31 ` [PATCH 1/2] [gdb/symtab] " Tom de Vries
  2023-10-06 18:31 ` [PATCH 2/2] [readelf] Handle .gdb_index section version 9 Tom de Vries
@ 2023-10-06 18:33 ` Tom de Vries
  2 siblings, 0 replies; 12+ messages in thread
From: Tom de Vries @ 2023-10-06 18:33 UTC (permalink / raw)
  To: gdb-patches

On 10/6/23 20:31, Tom de Vries via Gdb-patches wrote:
> This is a patch series containing:
> - a gdb patch introducing a new version of the .gdb_index section,
>    adding a shortcut table.
> - a readelf patch adding the capability to read the new version, as
>    well print the shortcuts table.
> 

FWIW, I had intended to send this series to both gdb-patches and 
binutils mailing list at the same time, but that seems to have gone 
wrong, so I've now posted it separately on each list.

Thanks,
- Tom



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

* Re: [PATCH 1/2] [gdb/symtab] Add name_of_main and language_of_main to the DWARF index
  2023-10-06 18:31 ` [PATCH 1/2] [gdb/symtab] " Tom de Vries
@ 2023-10-10 19:19   ` Tom Tromey
  2023-10-10 19:22     ` Tom Tromey
  2023-10-11 15:37     ` Tom de Vries
  0 siblings, 2 replies; 12+ messages in thread
From: Tom Tromey @ 2023-10-10 19:19 UTC (permalink / raw)
  To: Tom de Vries via Gdb-patches; +Cc: Tom de Vries

>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> From: Matheus Branco Borella <dark.ryu.550@gmail.com>
Tom> This patch adds a new section to the DWARF index containing the name
Tom> and the language of the main function symbol, gathered from
Tom> `cooked_index::get_main`, if available.

This patch has a bunch of formatting nits.  I think it's also a little
incorrect in its handling of unknown languages / its understanding of
its own idea of how the "0" case is handled.

Tom> +@item The shortcut table
Tom> +This is a data structure with the following fields:
Tom> +
Tom> +@table @asis
Tom> +@item Language of main
Tom> +An @code{offset_type} value indicating the language of the main function as a
Tom> +@code{DW_LANG_} constant.  This value will be zero if main function information
Tom> +is not present.
Tom> +
Tom> +@item Name of main
Tom> +An @code{offset_type} value indicating the offset of the main function's name
Tom> +in the constant pool.  This value must be ignored if the value for the language
Tom> +of main is zero.

This phrasing is a little strange.  The index-writing code seems to omit
the name field if the language is unknown.  However, the text here makes
it sound like the field is present but must be ignored.

If the writing code is correct, I would suggest changing this to say
"This field is not present if..."

Tom> +  dwarf_source_language dw_lang = (dwarf_source_language)0;

gdb style puts a space after the ")" of a cast.
There's a lot of cases like this.

Tom> +  shortcuts.append_uint (4, BFD_ENDIAN_LITTLE, dw_lang);
Tom> +  shortcuts.append_offset (main_name_offset);

The first ljne using append_uint seems confusing... it made me wonder
why it isn't using offset_type.  But in the end I don't think there's
any reason.  "offset_type" is used for all kinds of fields in the index,
it's better to just use that here.  It is 4 bytes anyway.

Tom> +/* Sets the name and language of the main function from the shortcut table. */
Tom> +
Tom> +static void
Tom> +set_main_name_from_gdb_index (dwarf2_per_objfile *per_objfile,
Tom> +			      mapped_gdb_index *index)
Tom> +{
Tom> +  const auto expected_size = 4 + sizeof (offset_type);

Better to use 2 * sizeof (offset_type) IMO.

Tom> +  if (index->shortcut_table.size () < expected_size)
Tom> +    /* The data in the section is not present, is corrupted or is in a version
Tom> +     * we don't know about. Regardless, we can't make use of it. */
Tom> +    return;

The leading "*" on comments is not gdb style.  Several cases of this.

This is where the reader seems to expect that both members are always
written.

Tom> +
Tom> +  auto ptr = index->shortcut_table.data ();
Tom> +  const auto dw_lang = extract_unsigned_integer (ptr, 4, BFD_ENDIAN_LITTLE);
Tom> +  if (dw_lang >= DW_LANG_hi_user)
Tom> +    {
Tom> +      complaint (_(".gdb_index shortcut table has invalid main language %u"),
Tom> +		   (unsigned) dw_lang);
Tom> +      return;
Tom> +    }

IMO it would be better for this check to happen in
dwarf_lang_to_enum_language.  Suppose gdb adds support for a new language.
That version of gdb may still emit index version 9, but the index
won't be directly usable by an older gdb.

Tom> +  const auto name = (const char*) (index->constant_pool.data () + name_offset);

Space before "*".  There were some with "&" as well but I didn't
remember to point them out before deleting the patch text.

Tom

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

* Re: [PATCH 1/2] [gdb/symtab] Add name_of_main and language_of_main to the DWARF index
  2023-10-10 19:19   ` Tom Tromey
@ 2023-10-10 19:22     ` Tom Tromey
  2023-10-11 15:37     ` Tom de Vries
  1 sibling, 0 replies; 12+ messages in thread
From: Tom Tromey @ 2023-10-10 19:22 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Tom de Vries via Gdb-patches, Tom de Vries

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> If the writing code is correct, I would suggest changing this to say
Tom> "This field is not present if..."

Well, I think I actually am the one who misunderstood the writing code.
Sorry about that.  I think the formatting nits still apply, but it's
fine if you want to just ignore those I guess.

Tom

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

* Re: [PATCH 1/2] [gdb/symtab] Add name_of_main and language_of_main to the DWARF index
  2023-10-10 19:19   ` Tom Tromey
  2023-10-10 19:22     ` Tom Tromey
@ 2023-10-11 15:37     ` Tom de Vries
  2023-10-23 16:26       ` Aaron Merey
  1 sibling, 1 reply; 12+ messages in thread
From: Tom de Vries @ 2023-10-11 15:37 UTC (permalink / raw)
  To: Tom Tromey, Tom de Vries via Gdb-patches

On 10/10/23 21:19, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Tom> From: Matheus Branco Borella <dark.ryu.550@gmail.com>
> Tom> This patch adds a new section to the DWARF index containing the name
> Tom> and the language of the main function symbol, gathered from
> Tom> `cooked_index::get_main`, if available.
> 
> This patch has a bunch of formatting nits.  I think it's also a little
> incorrect in its handling of unknown languages / its understanding of
> its own idea of how the "0" case is handled.
> 
> Tom> +@item The shortcut table
> Tom> +This is a data structure with the following fields:
> Tom> +
> Tom> +@table @asis
> Tom> +@item Language of main
> Tom> +An @code{offset_type} value indicating the language of the main function as a
> Tom> +@code{DW_LANG_} constant.  This value will be zero if main function information
> Tom> +is not present.
> Tom> +
> Tom> +@item Name of main
> Tom> +An @code{offset_type} value indicating the offset of the main function's name
> Tom> +in the constant pool.  This value must be ignored if the value for the language
> Tom> +of main is zero.
> 
> This phrasing is a little strange.  The index-writing code seems to omit
> the name field if the language is unknown.  However, the text here makes
> it sound like the field is present but must be ignored.
> 
> If the writing code is correct, I would suggest changing this to say
> "This field is not present if..."
> 
> Tom> +  dwarf_source_language dw_lang = (dwarf_source_language)0;
> 
> gdb style puts a space after the ")" of a cast.
> There's a lot of cases like this.
> 

Done.

> Tom> +  shortcuts.append_uint (4, BFD_ENDIAN_LITTLE, dw_lang);
> Tom> +  shortcuts.append_offset (main_name_offset);
> 
> The first ljne using append_uint seems confusing... it made me wonder
> why it isn't using offset_type.  But in the end I don't think there's
> any reason.  "offset_type" is used for all kinds of fields in the index,
> it's better to just use that here.  It is 4 bytes anyway.
> 

Done.

> Tom> +/* Sets the name and language of the main function from the shortcut table. */
> Tom> +
> Tom> +static void
> Tom> +set_main_name_from_gdb_index (dwarf2_per_objfile *per_objfile,
> Tom> +			      mapped_gdb_index *index)
> Tom> +{
> Tom> +  const auto expected_size = 4 + sizeof (offset_type);
> 
> Better to use 2 * sizeof (offset_type) IMO.
> 

Done.

> Tom> +  if (index->shortcut_table.size () < expected_size)
> Tom> +    /* The data in the section is not present, is corrupted or is in a version
> Tom> +     * we don't know about. Regardless, we can't make use of it. */
> Tom> +    return;
> 
> The leading "*" on comments is not gdb style.  Several cases of this.
> 

Done.

> This is where the reader seems to expect that both members are always
> written.
> 
> Tom> +
> Tom> +  auto ptr = index->shortcut_table.data ();
> Tom> +  const auto dw_lang = extract_unsigned_integer (ptr, 4, BFD_ENDIAN_LITTLE);
> Tom> +  if (dw_lang >= DW_LANG_hi_user)
> Tom> +    {
> Tom> +      complaint (_(".gdb_index shortcut table has invalid main language %u"),
> Tom> +		   (unsigned) dw_lang);
> Tom> +      return;
> Tom> +    }
> 
> IMO it would be better for this check to happen in
> dwarf_lang_to_enum_language.  Suppose gdb adds support for a new language.
> That version of gdb may still emit index version 9, but the index
> won't be directly usable by an older gdb.
> 

AFAIU the check is the usual: is the value we've just read in the valid 
range.  It makes no assumption about which language gdb supports.  So 
I'm not sure this needs to be moved.

> Tom> +  const auto name = (const char*) (index->constant_pool.data () + name_offset);
> 
> Space before "*".  There were some with "&" as well but I didn't
> remember to point them out before deleting the patch text.
> 

Done.  Submitted here ( 
https://sourceware.org/pipermail/gdb-patches/2023-October/203161.html ).

Thanks,
- Tom


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

* Re: [PATCH 1/2] [gdb/symtab] Add name_of_main and language_of_main to the DWARF index
  2023-10-11 15:37     ` Tom de Vries
@ 2023-10-23 16:26       ` Aaron Merey
  2023-10-24  7:43         ` Tom de Vries
  0 siblings, 1 reply; 12+ messages in thread
From: Aaron Merey @ 2023-10-23 16:26 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches

Hi Tom,

I tried to generate a v9 .gdb_index for a hello world C program and
for my local gdb build.  In both cases the name and language of the main
function are missing.  I looked into this and it seems that main
information is set in the index only when DW_AT_main_subprogram
is found or DW_AT_calling_convention == DW_CC_program.

From gcc/dwarf2out.cc:add_calling_convention_attribute it looks like
DW_AT_main_subprogram is only set for Fortran programs.  And as far as
I can tell DW_AT_calling_convention is not set for C/C++ programs.

Am I missing something or is the range of cases where a v9 index actually
contains the name and laguage of main quite limited?  When writing an index
maybe gdb should try to infer the main name and language from the current
progspace if this information isn't available in the debuginfo.

Aaron


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

* Re: [PATCH 1/2] [gdb/symtab] Add name_of_main and language_of_main to the DWARF index
  2023-10-23 16:26       ` Aaron Merey
@ 2023-10-24  7:43         ` Tom de Vries
  2023-10-24  8:04           ` Tom de Vries
                             ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Tom de Vries @ 2023-10-24  7:43 UTC (permalink / raw)
  To: Aaron Merey; +Cc: gdb-patches, Tom Tromey

On 10/23/23 18:26, Aaron Merey wrote:
> Hi Tom,
> 
> I tried to generate a v9 .gdb_index for a hello world C program and
> for my local gdb build.  In both cases the name and language of the main
> function are missing.  I looked into this and it seems that main
> information is set in the index only when DW_AT_main_subprogram
> is found or DW_AT_calling_convention == DW_CC_program.
> 
>  From gcc/dwarf2out.cc:add_calling_convention_attribute it looks like
> DW_AT_main_subprogram is only set for Fortran programs.  And as far as
> I can tell DW_AT_calling_convention is not set for C/C++ programs.
> 
> Am I missing something or is the range of cases where a v9 index actually
> contains the name and laguage of main quite limited?  When writing an index
> maybe gdb should try to infer the main name and language from the current
> progspace if this information isn't available in the debuginfo.

Hi,

the current approach is to store information in the dwarf index that is 
available in the dwarf (more concretely, found by the cooked-index's 
get_main).

The benefits are:
- correctness (fixing the case that main_subprogram is ignored when we
   have a .gdb_index, which was my main concern (PR24549))
- speed (in the cases that it covers).

I tried out the C hello world with .gdb_index added, and indeed we end 
up expanding the CU to get the name of main, which can be slow if the CU 
is large (as the author points out in the commit log).  So agreed, we 
can add more cases for speed.

Implementation-wise, that looks non-trivial.

There are two paths to writing a .gdb_index:
- the save gdb-index command
- the index-cache.

In the former case, it's probably fairly easy to infer the main name and 
language from the current progspace, as you suggest, since 
set_initial_language has been executed already.

In the latter case, writing the index-cache is executed asap in the 
background, and it only waits for the cooked-index to become available. 
So it would have to wait for the result of set_initial_language as well.

Also (for both cases) some thought will have to go into how to handle 
the case that the initial language is set by the user.  Is that the 
language we want to write into the .gdb_index?  Or do we skip writing it 
in that case?  Or do we try to get the auto-detected initial language by 
running set_initial_language on the main thread at the point that we 
need it?  Or do we try to get the auto-detected initial language in the 
background on a worker thread?

Thanks,
- Tom


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

* Re: [PATCH 1/2] [gdb/symtab] Add name_of_main and language_of_main to the DWARF index
  2023-10-24  7:43         ` Tom de Vries
@ 2023-10-24  8:04           ` Tom de Vries
  2023-10-24  8:20           ` Tom de Vries
  2023-10-24 22:04           ` Aaron Merey
  2 siblings, 0 replies; 12+ messages in thread
From: Tom de Vries @ 2023-10-24  8:04 UTC (permalink / raw)
  To: Aaron Merey; +Cc: gdb-patches, Tom Tromey

On 10/24/23 09:43, Tom de Vries wrote:
> I tried out the C hello world with .gdb_index added,

FWIW, I also noticed a problem in readelf printing the shortcut table 
for this example, I've submitted a patch for that here ( 
https://sourceware.org/pipermail/binutils/2023-October/130119.html ).

Thanks,
- Tom


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

* Re: [PATCH 1/2] [gdb/symtab] Add name_of_main and language_of_main to the DWARF index
  2023-10-24  7:43         ` Tom de Vries
  2023-10-24  8:04           ` Tom de Vries
@ 2023-10-24  8:20           ` Tom de Vries
  2023-10-24 22:04           ` Aaron Merey
  2 siblings, 0 replies; 12+ messages in thread
From: Tom de Vries @ 2023-10-24  8:20 UTC (permalink / raw)
  To: Aaron Merey; +Cc: gdb-patches, Tom Tromey

On 10/24/23 09:43, Tom de Vries wrote:
> I tried out the C hello world with .gdb_index added, and indeed we end 
> up expanding the CU to get the name of main, which can be slow if the CU 
> is large (as the author points out in the commit log).  So agreed, we 
> can add more cases for speed.

Filed as enhancement PR ( 
https://sourceware.org/bugzilla/show_bug.cgi?id=30996 ).

Thanks,
- Tom

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

* Re: [PATCH 1/2] [gdb/symtab] Add name_of_main and language_of_main to the DWARF index
  2023-10-24  7:43         ` Tom de Vries
  2023-10-24  8:04           ` Tom de Vries
  2023-10-24  8:20           ` Tom de Vries
@ 2023-10-24 22:04           ` Aaron Merey
  2 siblings, 0 replies; 12+ messages in thread
From: Aaron Merey @ 2023-10-24 22:04 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches, Tom Tromey

Hi Tom,

On Tue, Oct 24, 2023 at 3:43 AM Tom de Vries <tdevries@suse.de> wrote:
>
> There are two paths to writing a .gdb_index:
> - the save gdb-index command
> - the index-cache.
>
> In the former case, it's probably fairly easy to infer the main name and
> language from the current progspace, as you suggest, since
> set_initial_language has been executed already.
>
> In the latter case, writing the index-cache is executed asap in the
> background, and it only waits for the cooked-index to become available.
> So it would have to wait for the result of set_initial_language as well.

Given the possible speed up from having main info in the index,
maybe we are better off waiting for set_initial_language.  If we
are still worried about this delay, we could introduce a gdb command
to control this setting and note somewhere that if disabled the index
may lack main name and language info.

Another approach could be for gcc to emit DW_AT_main_subprogram
for C/C++. I'm not too familiar with that gcc code so I'm not sure how
feasible this is.

> Also (for both cases) some thought will have to go into how to handle
> the case that the initial language is set by the user.  Is that the
> language we want to write into the .gdb_index?  Or do we skip writing it
> in that case?  Or do we try to get the auto-detected initial language by
> running set_initial_language on the main thread at the point that we
> need it?  Or do we try to get the auto-detected initial language in the
> background on a worker thread?

Hmm I'm not sure here. I think we'd be justified in insisting that index
contents should be determined only by the contents of the relevant
binaries.

Aaron


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

end of thread, other threads:[~2023-10-24 22:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-06 18:31 [PATCH 0/2] Add name_of_main and language_of_main to the DWARF index Tom de Vries
2023-10-06 18:31 ` [PATCH 1/2] [gdb/symtab] " Tom de Vries
2023-10-10 19:19   ` Tom Tromey
2023-10-10 19:22     ` Tom Tromey
2023-10-11 15:37     ` Tom de Vries
2023-10-23 16:26       ` Aaron Merey
2023-10-24  7:43         ` Tom de Vries
2023-10-24  8:04           ` Tom de Vries
2023-10-24  8:20           ` Tom de Vries
2023-10-24 22:04           ` Aaron Merey
2023-10-06 18:31 ` [PATCH 2/2] [readelf] Handle .gdb_index section version 9 Tom de Vries
2023-10-06 18:33 ` [PATCH 0/2] Add name_of_main and language_of_main to the DWARF index Tom de Vries

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).