aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2/index-write.c
diff options
context:
space:
mode:
authorMatheus Branco Borella <dark.ryu.550@gmail.com>2023-10-10 10:26:40 +0200
committerTom de Vries <tdevries@suse.de>2023-10-10 10:26:40 +0200
commit8b9c08eddac038663b8f5ede4b4d24e441a6d8a3 (patch)
tree828d9bed8c1ee0e66bec726788ce2c3fab520063 /gdb/dwarf2/index-write.c
parentd883c61283a547788292f94633799303fd34080c (diff)
downloadgdb-8b9c08eddac038663b8f5ede4b4d24e441a6d8a3.zip
gdb-8b9c08eddac038663b8f5ede4b4d24e441a6d8a3.tar.gz
gdb-8b9c08eddac038663b8f5ede4b4d24e441a6d8a3.tar.bz2
[gdb/symtab] Add name_of_main and language_of_main to the DWARF index
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 Approved-By: Tom de Vries <tdevries@suse.de>
Diffstat (limited to 'gdb/dwarf2/index-write.c')
-rw-r--r--gdb/dwarf2/index-write.c54
1 files changed, 46 insertions, 8 deletions
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 3acff26..6ea4217 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)
{