binutils-gdb/gdb/dwarf-index-write.c

1710 lines
52 KiB
C
Raw Normal View History

Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
/* DWARF index writing support for GDB.
Copyright (C) 1994-2019 Free Software Foundation, Inc.
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
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 "defs.h"
#include "addrmap.h"
#include "cli/cli-decode.h"
#include "common/byte-vector.h"
#include "common/filestuff.h"
#include "common/gdb_unlinker.h"
#include "common/pathstuff.h"
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
#include "common/scoped_fd.h"
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
#include "complaints.h"
#include "dwarf-index-common.h"
#include "dwarf2.h"
#include "dwarf2read.h"
#include "gdb/gdb-index.h"
#include "gdbcmd.h"
#include "objfiles.h"
#include "psympriv.h"
#include <algorithm>
#include <cmath>
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
#include <set>
#include <unordered_map>
#include <unordered_set>
/* Ensure only legit values are used. */
#define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
do { \
gdb_assert ((unsigned int) (value) <= 1); \
GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
} while (0)
/* Ensure only legit values are used. */
#define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
do { \
gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
&& (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
} while (0)
/* Ensure we don't use more than the alloted nuber of bits for the CU. */
#define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
do { \
gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
} while (0)
/* The "save gdb-index" command. */
/* Write SIZE bytes from the buffer pointed to by DATA to FILE, with
error checking. */
static void
file_write (FILE *file, const void *data, size_t size)
{
if (fwrite (data, 1, size, file) != size)
error (_("couldn't data write to file"));
}
/* Write the contents of VEC to FILE, with error checking. */
template<typename Elem, typename Alloc>
static void
file_write (FILE *file, const std::vector<Elem, Alloc> &vec)
{
if (!vec.empty ())
file_write (file, vec.data (), vec.size () * sizeof (vec[0]));
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
}
/* In-memory buffer to prepare data to be written later to a file. */
class data_buf
{
public:
/* Copy DATA to the end of the buffer. */
template<typename T>
void append_data (const T &data)
{
std::copy (reinterpret_cast<const gdb_byte *> (&data),
reinterpret_cast<const gdb_byte *> (&data + 1),
grow (sizeof (data)));
}
/* Copy CSTR (a zero-terminated string) to the end of buffer. The
terminating zero is appended too. */
void append_cstr0 (const char *cstr)
{
const size_t size = strlen (cstr) + 1;
std::copy (cstr, cstr + size, grow (size));
}
/* Store INPUT as ULEB128 to the end of buffer. */
void append_unsigned_leb128 (ULONGEST input)
{
for (;;)
{
gdb_byte output = input & 0x7f;
input >>= 7;
if (input)
output |= 0x80;
append_data (output);
if (input == 0)
break;
}
}
/* Accept a host-format integer in VAL and append it to the buffer
as a target-format integer which is LEN bytes long. */
void append_uint (size_t len, bfd_endian byte_order, ULONGEST val)
{
::store_unsigned_integer (grow (len), len, byte_order, val);
}
/* Return the size of the buffer. */
size_t size () const
{
return m_vec.size ();
}
/* Return true iff the buffer is empty. */
bool empty () const
{
return m_vec.empty ();
}
/* Write the buffer to FILE. */
void file_write (FILE *file) const
{
::file_write (file, m_vec);
}
private:
/* Grow SIZE bytes at the end of the buffer. Returns a pointer to
the start of the new block. */
gdb_byte *grow (size_t size)
{
m_vec.resize (m_vec.size () + size);
Fix -D_GLIBCXX_DEBUG gdb-add-index regression Fedora Rawhide started to use -D_GLIBCXX_DEBUG which made gdb-add-index failing: gdb: Out-of-bounds vector access while running gdb-add-index https://bugzilla.redhat.com/show_bug.cgi?id=1540559 /usr/include/c++/7/debug/safe_iterator.h:270: Error: attempt to dereference a past-the-end iterator. Objects involved in the operation: iterator "this" @ 0x0x7fffffffcb90 { type = __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<unsigned char*, std::__cxx1998::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > >, std::__debug::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > (mutable iterator); state = past-the-end; references sequence with type 'std::__debug::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > >' @ 0x0x7fffffffcc50 } /usr/include/c++/7/debug/vector:417: Error: attempt to subscript container with out-of-bounds index 556, but container only holds 556 elements. Objects involved in the operation: sequence "this" @ 0x0x2e87af8 { type = std::__debug::vector<partial_symbol*, std::allocator<partial_symbol*> >; } The two -D_GLIBCXX_DEBUG regressions were made by: commit bc8f2430e08cc2a520db49a42686e0529be4a3bc Author: Jan Kratochvil <jan.kratochvil@redhat.com> Date: Mon Jun 12 16:29:53 2017 +0100 Code cleanup: C++ify .gdb_index producer commit af5bf4ada48ff65b6658be1fab8f9c8f8ab5f319 Author: Simon Marchi <simon.marchi@ericsson.com> Date: Sat Oct 14 08:06:29 2017 -0400 Replace psymbol_allocation_list with std::vector gdb/ChangeLog 2018-04-12 Jan Kratochvil <jan.kratochvil@redhat.com> PR gdb/23053 * dwarf-index-write.c (data_buf::grow) (write_one_signatured_type) (recursively_write_psymbols) (debug_names::recursively_write_psymbols) (debug_names::write_one_signatured_type): Fix -D_GLIBCXX_DEBUG regression.
2018-04-12 22:31:39 +02:00
return &*(m_vec.end () - size);
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
}
gdb::byte_vector m_vec;
};
/* An entry in the symbol table. */
struct symtab_index_entry
{
/* The name of the symbol. */
const char *name;
/* The offset of the name in the constant pool. */
offset_type index_offset;
/* A sorted vector of the indices of all the CUs that hold an object
of this name. */
std::vector<offset_type> cu_indices;
};
/* The symbol table. This is a power-of-2-sized hash table. */
struct mapped_symtab
{
mapped_symtab ()
{
data.resize (1024);
}
offset_type n_elements = 0;
std::vector<symtab_index_entry> data;
};
/* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
the slot.
Function is used only during write_hash_table so no index format backward
compatibility is needed. */
static symtab_index_entry &
find_slot (struct mapped_symtab *symtab, const char *name)
{
offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name);
index = hash & (symtab->data.size () - 1);
step = ((hash * 17) & (symtab->data.size () - 1)) | 1;
for (;;)
{
if (symtab->data[index].name == NULL
|| strcmp (name, symtab->data[index].name) == 0)
return symtab->data[index];
index = (index + step) & (symtab->data.size () - 1);
}
}
/* Expand SYMTAB's hash table. */
static void
hash_expand (struct mapped_symtab *symtab)
{
auto old_entries = std::move (symtab->data);
symtab->data.clear ();
symtab->data.resize (old_entries.size () * 2);
for (auto &it : old_entries)
if (it.name != NULL)
{
auto &ref = find_slot (symtab, it.name);
ref = std::move (it);
}
}
/* Add an entry to SYMTAB. NAME is the name of the symbol.
CU_INDEX is the index of the CU in which the symbol appears.
IS_STATIC is one if the symbol is static, otherwise zero (global). */
static void
add_index_entry (struct mapped_symtab *symtab, const char *name,
int is_static, gdb_index_symbol_kind kind,
offset_type cu_index)
{
offset_type cu_index_and_attrs;
++symtab->n_elements;
if (4 * symtab->n_elements / 3 >= symtab->data.size ())
hash_expand (symtab);
symtab_index_entry &slot = find_slot (symtab, name);
if (slot.name == NULL)
{
slot.name = name;
/* index_offset is set later. */
}
cu_index_and_attrs = 0;
DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs, cu_index);
DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs, is_static);
DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs, kind);
/* We don't want to record an index value twice as we want to avoid the
duplication.
We process all global symbols and then all static symbols
(which would allow us to avoid the duplication by only having to check
the last entry pushed), but a symbol could have multiple kinds in one CU.
To keep things simple we don't worry about the duplication here and
sort and uniqufy the list after we've processed all symbols. */
slot.cu_indices.push_back (cu_index_and_attrs);
}
/* Sort and remove duplicates of all symbols' cu_indices lists. */
static void
uniquify_cu_indices (struct mapped_symtab *symtab)
{
for (auto &entry : symtab->data)
{
if (entry.name != NULL && !entry.cu_indices.empty ())
{
auto &cu_indices = entry.cu_indices;
std::sort (cu_indices.begin (), cu_indices.end ());
auto from = std::unique (cu_indices.begin (), cu_indices.end ());
cu_indices.erase (from, cu_indices.end ());
}
}
}
/* A form of 'const char *' suitable for container keys. Only the
pointer is stored. The strings themselves are compared, not the
pointers. */
class c_str_view
{
public:
c_str_view (const char *cstr)
: m_cstr (cstr)
{}
bool operator== (const c_str_view &other) const
{
return strcmp (m_cstr, other.m_cstr) == 0;
}
/* Return the underlying C string. Note, the returned string is
only a reference with lifetime of this object. */
const char *c_str () const
{
return m_cstr;
}
private:
friend class c_str_view_hasher;
const char *const m_cstr;
};
/* A std::unordered_map::hasher for c_str_view that uses the right
hash function for strings in a mapped index. */
class c_str_view_hasher
{
public:
size_t operator () (const c_str_view &x) const
{
return mapped_index_string_hash (INT_MAX, x.m_cstr);
}
};
/* A std::unordered_map::hasher for std::vector<>. */
template<typename T>
class vector_hasher
{
public:
size_t operator () (const std::vector<T> &key) const
{
return iterative_hash (key.data (),
sizeof (key.front ()) * key.size (), 0);
}
};
/* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with
constant pool entries going into the data buffer CPOOL. */
static void
write_hash_table (mapped_symtab *symtab, data_buf &output, data_buf &cpool)
{
{
/* Elements are sorted vectors of the indices of all the CUs that
hold an object of this name. */
std::unordered_map<std::vector<offset_type>, offset_type,
vector_hasher<offset_type>>
symbol_hash_table;
/* We add all the index vectors to the constant pool first, to
ensure alignment is ok. */
for (symtab_index_entry &entry : symtab->data)
{
if (entry.name == NULL)
continue;
gdb_assert (entry.index_offset == 0);
/* Finding before inserting is faster than always trying to
insert, because inserting always allocates a node, does the
lookup, and then destroys the new node if another node
already had the same key. C++17 try_emplace will avoid
this. */
const auto found
= symbol_hash_table.find (entry.cu_indices);
if (found != symbol_hash_table.end ())
{
entry.index_offset = found->second;
continue;
}
symbol_hash_table.emplace (entry.cu_indices, cpool.size ());
entry.index_offset = cpool.size ();
cpool.append_data (MAYBE_SWAP (entry.cu_indices.size ()));
for (const auto index : entry.cu_indices)
cpool.append_data (MAYBE_SWAP (index));
}
}
/* Now write out the hash table. */
std::unordered_map<c_str_view, offset_type, c_str_view_hasher> str_table;
for (const auto &entry : symtab->data)
{
offset_type str_off, vec_off;
if (entry.name != NULL)
{
const auto insertpair = str_table.emplace (entry.name, cpool.size ());
if (insertpair.second)
cpool.append_cstr0 (entry.name);
str_off = insertpair.first->second;
vec_off = entry.index_offset;
}
else
{
/* While 0 is a valid constant pool index, it is not valid
to have 0 for both offsets. */
str_off = 0;
vec_off = 0;
}
output.append_data (MAYBE_SWAP (str_off));
output.append_data (MAYBE_SWAP (vec_off));
}
}
typedef std::unordered_map<partial_symtab *, unsigned int> psym_index_map;
/* Helper struct for building the address table. */
struct addrmap_index_data
{
addrmap_index_data (data_buf &addr_vec_, psym_index_map &cu_index_htab_)
: addr_vec (addr_vec_), cu_index_htab (cu_index_htab_)
{}
struct objfile *objfile;
data_buf &addr_vec;
psym_index_map &cu_index_htab;
/* Non-zero if the previous_* fields are valid.
We can't write an entry until we see the next entry (since it is only then
that we know the end of the entry). */
int previous_valid;
/* Index of the CU in the table of all CUs in the index file. */
unsigned int previous_cu_index;
/* Start address of the CU. */
CORE_ADDR previous_cu_start;
};
/* Write an address entry to ADDR_VEC. */
static void
add_address_entry (struct objfile *objfile, data_buf &addr_vec,
CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
{
Make psymbols and psymtabs independent of the program space This patch finally makes partial symbols and partial symtabs independent of the program space. Specifically: It changes add_psymbol_to_list to accept a section index, and changes the psymbol readers to pass this. At the same time it removes the code to add the objfile's section offset to the psymbol. It adds an objfile argument to the psymtab textlow and texthigh accessors and changes some code to use the raw variants instead. It removes the "relocate" method from struct quick_symbol_functions, as it is no longer needed any more. It changes partial_symbol::address so that the relevant offset is now applied at the point of use. gdb/ChangeLog 2018-07-26 Tom Tromey <tom@tromey.com> * dwarf-index-write.c (add_address_entry): Don't add objfile offsets. * dbxread.c (find_stab_function): Rename from find_stab_function_addr. Return a bound_minimal_symbol. (read_dbx_symtab): Use raw_text_low, raw_text_high. Don't add objfile offsets. (end_psymtab): Use raw_text_low, raw_text_high, MSYMBOL_VALUE_RAW_ADDRESS. (read_ofile_symtab): Update. (process_one_symbol): Update. * dwarf2read.c (create_addrmap_from_index): Don't add objfile offsets. (dw2_relocate): Remove. (dw2_find_pc_sect_symtab): Bias PC by the text offset before searching addrmap. (dwarf2_gdb_index_functions, dwarf2_debug_names_functions): Update. (process_psymtab_comp_unit_reader, add_partial_symbol) (add_partial_subprogram, dwarf2_ranges_read): Update. (load_partial_dies): Update. (add_address_entry): Don't add objfile offsets. (dwarf2_build_include_psymtabs): Update. (create_addrmap_from_aranges): Don't add objfile offsets. (dw2_find_pc_sect_compunit_symtab): Update. * mdebugread.c (parse_symbol): Don't add objfile offsets. (parse_lines): Remove 'pst' parameter, replace with 'textlow'. Update. (parse_partial_symbols): Don't add objfile offsets. Use raw_text_low, raw_text_high. Update. (handle_psymbol_enumerators, psymtab_to_symtab_1): Update. * objfiles.c (objfile_relocate1): Don't relocate psymtabs_addrmap or call 'relocate' quick function. Clear psymbol_map. * psympriv.h (struct partial_symbol) <address>: Add section offset. <set_unrelocated_address>: Rename from set_address. <raw_text_low, raw_text_high>: New methods. <text_low, text_high>: Add objfile parameter. (add_psymbol_to_bcache): Add 'section' parameter. Call set_unrelocated_address. * psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymtab) (find_pc_psymbol): Update. (fixup_psymbol_section, relocate_psymtabs): Remove. (dump_psymtab, psym_functions): Update. (add_psymbol_to_bcache, add_psymbol_to_list): Add 'section' parameter. (maintenance_info_psymtabs, maintenance_check_psymtabs): Update. (start_psymtab_common): Update. * symfile-debug.c (debug_qf_relocate): Remove. (debug_sym_quick_functions): Update. * symfile.h (struct quick_symbol_functions) <relocate>: Remove. * xcoffread.c (scan_xcoff_symtab): Don't add objfile offsets. Update.
2018-05-04 00:36:21 +02:00
addr_vec.append_uint (8, BFD_ENDIAN_LITTLE, start);
addr_vec.append_uint (8, BFD_ENDIAN_LITTLE, end);
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
addr_vec.append_data (MAYBE_SWAP (cu_index));
}
/* Worker function for traversing an addrmap to build the address table. */
static int
add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
{
struct addrmap_index_data *data = (struct addrmap_index_data *) datap;
struct partial_symtab *pst = (struct partial_symtab *) obj;
if (data->previous_valid)
add_address_entry (data->objfile, data->addr_vec,
data->previous_cu_start, start_addr,
data->previous_cu_index);
data->previous_cu_start = start_addr;
if (pst != NULL)
{
const auto it = data->cu_index_htab.find (pst);
gdb_assert (it != data->cu_index_htab.cend ());
data->previous_cu_index = it->second;
data->previous_valid = 1;
}
else
data->previous_valid = 0;
return 0;
}
/* Write OBJFILE's address map to ADDR_VEC.
CU_INDEX_HTAB is used to map addrmap entries to their CU indices
in the index file. */
static void
write_address_map (struct objfile *objfile, data_buf &addr_vec,
psym_index_map &cu_index_htab)
{
struct addrmap_index_data addrmap_index_data (addr_vec, cu_index_htab);
/* When writing the address table, we have to cope with the fact that
the addrmap iterator only provides the start of a region; we have to
wait until the next invocation to get the start of the next region. */
addrmap_index_data.objfile = objfile;
addrmap_index_data.previous_valid = 0;
Introduce class psymtab_storage This introduces a new psymtab_storage class, which holds all psymbol-related objects that are independent of the objfile. (This latter contraint explains why psymbol_map was not moved; though this could still be done with some work.) This patch does not yet change where psymtab allocation is done -- that comes later. This just wraps everything in a single object to make further transformations simpler. Note that a shared_ptr is used to link from the objfile to the psymtab_storage object. The end goal here is to allow a given symbol reader to simply attach to the psymtab_storage object to the BFD, then reuse it in later invocations; shared_ptr makes this simple to reason about. gdb/ChangeLog 2019-01-10 Tom Tromey <tom@tromey.com> * symmisc.c (print_symbol_bcache_statistics): Update. (print_objfile_statistics): Update. * symfile.c (reread_symbols): Update. * psymtab.h (class psymtab_storage): New. * psymtab.c (psymtab_storage): New constructor. (~psymtab_storage): New destructor. (require_partial_symbols): Update. (ALL_OBJFILE_PSYMTABS_REQUIRED): Rewrite. (find_pc_sect_psymtab, find_pc_sect_psymbol) (match_partial_symbol, lookup_partial_symbol, dump_psymtab) (psym_dump, recursively_search_psymtabs, psym_has_symbols) (psym_find_compunit_symtab_by_address, sort_pst_symbols) (start_psymtab_common, end_psymtab_common) (add_psymbol_to_bcache, add_psymbol_to_list, init_psymbol_list) (allocate_psymtab): Update. (psymtab_storage::discard_psymtab): Rename from discard_psymtab. Update. (dump_psymtab_addrmap, maintenance_print_psymbols) (maintenance_check_psymtabs): Update. (class objfile_psymtabs): Move to objfiles.h. * psympriv.h (discard_psymtab): Now inline. (psymtab_discarder::psymtab_discarder): Update. (psymtab_discarder::~psymtab_discarder): Update. (ALL_OBJFILE_PSYMTABS): Rewrite. * objfiles.h (struct objfile) <psymtabs, psymtabs_addrmap, free_psymtabs, psymbol_cache, global_psymbols, static_psymbols>: Remove fields. <partial_symtabs>: New field. (class objfile_psymtabs): Move from psymtab.h. Update. * objfiles.c (objfile::objfile): Initialize partial_symtabs, not psymbol_cache. (objfile::~objfile): Don't destroy psymbol_cache. * mdebugread.c (parse_partial_symbols): Update. * dwarf2read.c (create_addrmap_from_index) (create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab) (process_psymtab_comp_unit_reader, dwarf2_build_psymtabs_hard) (add_partial_subprogram, dwarf2_ranges_read): Update. * dwarf-index-write.c (write_address_map) (write_one_signatured_type, recursively_write_psymbols) (class debug_names, class debug_names, write_psymtabs_to_index): Update.
2018-05-11 00:23:51 +02:00
addrmap_foreach (objfile->partial_symtabs->psymtabs_addrmap,
add_address_entry_worker, &addrmap_index_data);
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
/* It's highly unlikely the last entry (end address = 0xff...ff)
is valid, but we should still handle it.
The end address is recorded as the start of the next region, but that
doesn't work here. To cope we pass 0xff...ff, this is a rare situation
anyway. */
if (addrmap_index_data.previous_valid)
add_address_entry (objfile, addr_vec,
addrmap_index_data.previous_cu_start, (CORE_ADDR) -1,
addrmap_index_data.previous_cu_index);
}
/* Return the symbol kind of PSYM. */
static gdb_index_symbol_kind
symbol_kind (struct partial_symbol *psym)
{
Change representation of psymbol to flush out accessors This is the psymbol analog to the patch to change the representation of minimal symbols: https://sourceware.org/ml/gdb-patches/2013-10/msg00524.html It has the same rationale: namely, that we're going to change the code to apply psymbol offsets at runtime. This will be done by adding an argument to the SYMBOL_VALUE_ADDRESS macro -- but since we can't convert all the symbol types at once, we need a new approach. Because gdb now is in C++, this patch changes partial_symbol to inherit from general_symbol_info, rather than renaming the field. This simplifies code in some places. Also, as noted before, these macros implement a kind of "phony polymorphism" that is not actually useful in practice; so this patch removes the macros in favor of simply referring directly to members. In a few cases -- obj_section in this patch and the symbol address in the future -- methods will be used instead. Note that this removes the blanket memset from add_psymbol_to_bcache. This hasn't really been needed since bcache was modified to allow holes in objects and since psymtab took advantage of that. This deletion was required due to changing partial_symbol to derive from general_symbol_info. gdb/ChangeLog 2018-07-26 Tom Tromey <tom@tromey.com> * dwarf-index-write.c (write_psymbols, debug_names::insert) (debug_names::write_psymbols): Update. * psympriv.h (struct partial_symbol): Derive from general_symbol_info. <obj_section>: New method. (PSYMBOL_DOMAIN, PSYMBOL_CLASS): Remove.n * psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymtab) (find_pc_sect_psymbol, fixup_psymbol_section) (match_partial_symbol, lookup_partial_symbol, relocate_psymtabs) (print_partial_symbols, recursively_search_psymtabs) (compare_psymbols, psymbol_hash, psymbol_compare) (add_psymbol_to_bcache, maintenance_check_psymtabs) (psymbol_name_matches, psym_fill_psymbol_map): Update.
2018-05-04 00:36:17 +02:00
domain_enum domain = psym->domain;
enum address_class aclass = psym->aclass;
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
switch (domain)
{
case VAR_DOMAIN:
switch (aclass)
{
case LOC_BLOCK:
return GDB_INDEX_SYMBOL_KIND_FUNCTION;
case LOC_TYPEDEF:
return GDB_INDEX_SYMBOL_KIND_TYPE;
case LOC_COMPUTED:
case LOC_CONST_BYTES:
case LOC_OPTIMIZED_OUT:
case LOC_STATIC:
return GDB_INDEX_SYMBOL_KIND_VARIABLE;
case LOC_CONST:
/* Note: It's currently impossible to recognize psyms as enum values
short of reading the type info. For now punt. */
return GDB_INDEX_SYMBOL_KIND_VARIABLE;
default:
/* There are other LOC_FOO values that one might want to classify
as variables, but dwarf2read.c doesn't currently use them. */
return GDB_INDEX_SYMBOL_KIND_OTHER;
}
case STRUCT_DOMAIN:
return GDB_INDEX_SYMBOL_KIND_TYPE;
default:
return GDB_INDEX_SYMBOL_KIND_OTHER;
}
}
/* Add a list of partial symbols to SYMTAB. */
static void
write_psymbols (struct mapped_symtab *symtab,
std::unordered_set<partial_symbol *> &psyms_seen,
struct partial_symbol **psymp,
int count,
offset_type cu_index,
int is_static)
{
for (; count-- > 0; ++psymp)
{
struct partial_symbol *psym = *psymp;
Change representation of psymbol to flush out accessors This is the psymbol analog to the patch to change the representation of minimal symbols: https://sourceware.org/ml/gdb-patches/2013-10/msg00524.html It has the same rationale: namely, that we're going to change the code to apply psymbol offsets at runtime. This will be done by adding an argument to the SYMBOL_VALUE_ADDRESS macro -- but since we can't convert all the symbol types at once, we need a new approach. Because gdb now is in C++, this patch changes partial_symbol to inherit from general_symbol_info, rather than renaming the field. This simplifies code in some places. Also, as noted before, these macros implement a kind of "phony polymorphism" that is not actually useful in practice; so this patch removes the macros in favor of simply referring directly to members. In a few cases -- obj_section in this patch and the symbol address in the future -- methods will be used instead. Note that this removes the blanket memset from add_psymbol_to_bcache. This hasn't really been needed since bcache was modified to allow holes in objects and since psymtab took advantage of that. This deletion was required due to changing partial_symbol to derive from general_symbol_info. gdb/ChangeLog 2018-07-26 Tom Tromey <tom@tromey.com> * dwarf-index-write.c (write_psymbols, debug_names::insert) (debug_names::write_psymbols): Update. * psympriv.h (struct partial_symbol): Derive from general_symbol_info. <obj_section>: New method. (PSYMBOL_DOMAIN, PSYMBOL_CLASS): Remove.n * psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymtab) (find_pc_sect_psymbol, fixup_psymbol_section) (match_partial_symbol, lookup_partial_symbol, relocate_psymtabs) (print_partial_symbols, recursively_search_psymtabs) (compare_psymbols, psymbol_hash, psymbol_compare) (add_psymbol_to_bcache, maintenance_check_psymtabs) (psymbol_name_matches, psym_fill_psymbol_map): Update.
2018-05-04 00:36:17 +02:00
if (psym->language == language_ada)
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
error (_("Ada is not currently supported by the index"));
/* Only add a given psymbol once. */
if (psyms_seen.insert (psym).second)
{
gdb_index_symbol_kind kind = symbol_kind (psym);
Change representation of psymbol to flush out accessors This is the psymbol analog to the patch to change the representation of minimal symbols: https://sourceware.org/ml/gdb-patches/2013-10/msg00524.html It has the same rationale: namely, that we're going to change the code to apply psymbol offsets at runtime. This will be done by adding an argument to the SYMBOL_VALUE_ADDRESS macro -- but since we can't convert all the symbol types at once, we need a new approach. Because gdb now is in C++, this patch changes partial_symbol to inherit from general_symbol_info, rather than renaming the field. This simplifies code in some places. Also, as noted before, these macros implement a kind of "phony polymorphism" that is not actually useful in practice; so this patch removes the macros in favor of simply referring directly to members. In a few cases -- obj_section in this patch and the symbol address in the future -- methods will be used instead. Note that this removes the blanket memset from add_psymbol_to_bcache. This hasn't really been needed since bcache was modified to allow holes in objects and since psymtab took advantage of that. This deletion was required due to changing partial_symbol to derive from general_symbol_info. gdb/ChangeLog 2018-07-26 Tom Tromey <tom@tromey.com> * dwarf-index-write.c (write_psymbols, debug_names::insert) (debug_names::write_psymbols): Update. * psympriv.h (struct partial_symbol): Derive from general_symbol_info. <obj_section>: New method. (PSYMBOL_DOMAIN, PSYMBOL_CLASS): Remove.n * psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymtab) (find_pc_sect_psymbol, fixup_psymbol_section) (match_partial_symbol, lookup_partial_symbol, relocate_psymtabs) (print_partial_symbols, recursively_search_psymtabs) (compare_psymbols, psymbol_hash, psymbol_compare) (add_psymbol_to_bcache, maintenance_check_psymtabs) (psymbol_name_matches, psym_fill_psymbol_map): Update.
2018-05-04 00:36:17 +02:00
add_index_entry (symtab, symbol_search_name (psym),
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
is_static, kind, cu_index);
}
}
}
/* A helper struct used when iterating over debug_types. */
struct signatured_type_index_data
{
signatured_type_index_data (data_buf &types_list_,
std::unordered_set<partial_symbol *> &psyms_seen_)
: types_list (types_list_), psyms_seen (psyms_seen_)
{}
struct objfile *objfile;
struct mapped_symtab *symtab;
data_buf &types_list;
std::unordered_set<partial_symbol *> &psyms_seen;
int cu_index;
};
/* A helper function that writes a single signatured_type to an
obstack. */
static int
write_one_signatured_type (void **slot, void *d)
{
struct signatured_type_index_data *info
= (struct signatured_type_index_data *) d;
struct signatured_type *entry = (struct signatured_type *) *slot;
struct partial_symtab *psymtab = entry->per_cu.v.psymtab;
write_psymbols (info->symtab,
info->psyms_seen,
Introduce class psymtab_storage This introduces a new psymtab_storage class, which holds all psymbol-related objects that are independent of the objfile. (This latter contraint explains why psymbol_map was not moved; though this could still be done with some work.) This patch does not yet change where psymtab allocation is done -- that comes later. This just wraps everything in a single object to make further transformations simpler. Note that a shared_ptr is used to link from the objfile to the psymtab_storage object. The end goal here is to allow a given symbol reader to simply attach to the psymtab_storage object to the BFD, then reuse it in later invocations; shared_ptr makes this simple to reason about. gdb/ChangeLog 2019-01-10 Tom Tromey <tom@tromey.com> * symmisc.c (print_symbol_bcache_statistics): Update. (print_objfile_statistics): Update. * symfile.c (reread_symbols): Update. * psymtab.h (class psymtab_storage): New. * psymtab.c (psymtab_storage): New constructor. (~psymtab_storage): New destructor. (require_partial_symbols): Update. (ALL_OBJFILE_PSYMTABS_REQUIRED): Rewrite. (find_pc_sect_psymtab, find_pc_sect_psymbol) (match_partial_symbol, lookup_partial_symbol, dump_psymtab) (psym_dump, recursively_search_psymtabs, psym_has_symbols) (psym_find_compunit_symtab_by_address, sort_pst_symbols) (start_psymtab_common, end_psymtab_common) (add_psymbol_to_bcache, add_psymbol_to_list, init_psymbol_list) (allocate_psymtab): Update. (psymtab_storage::discard_psymtab): Rename from discard_psymtab. Update. (dump_psymtab_addrmap, maintenance_print_psymbols) (maintenance_check_psymtabs): Update. (class objfile_psymtabs): Move to objfiles.h. * psympriv.h (discard_psymtab): Now inline. (psymtab_discarder::psymtab_discarder): Update. (psymtab_discarder::~psymtab_discarder): Update. (ALL_OBJFILE_PSYMTABS): Rewrite. * objfiles.h (struct objfile) <psymtabs, psymtabs_addrmap, free_psymtabs, psymbol_cache, global_psymbols, static_psymbols>: Remove fields. <partial_symtabs>: New field. (class objfile_psymtabs): Move from psymtab.h. Update. * objfiles.c (objfile::objfile): Initialize partial_symtabs, not psymbol_cache. (objfile::~objfile): Don't destroy psymbol_cache. * mdebugread.c (parse_partial_symbols): Update. * dwarf2read.c (create_addrmap_from_index) (create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab) (process_psymtab_comp_unit_reader, dwarf2_build_psymtabs_hard) (add_partial_subprogram, dwarf2_ranges_read): Update. * dwarf-index-write.c (write_address_map) (write_one_signatured_type, recursively_write_psymbols) (class debug_names, class debug_names, write_psymtabs_to_index): Update.
2018-05-11 00:23:51 +02:00
(info->objfile->partial_symtabs->global_psymbols.data ()
Fix -D_GLIBCXX_DEBUG gdb-add-index regression Fedora Rawhide started to use -D_GLIBCXX_DEBUG which made gdb-add-index failing: gdb: Out-of-bounds vector access while running gdb-add-index https://bugzilla.redhat.com/show_bug.cgi?id=1540559 /usr/include/c++/7/debug/safe_iterator.h:270: Error: attempt to dereference a past-the-end iterator. Objects involved in the operation: iterator "this" @ 0x0x7fffffffcb90 { type = __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<unsigned char*, std::__cxx1998::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > >, std::__debug::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > (mutable iterator); state = past-the-end; references sequence with type 'std::__debug::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > >' @ 0x0x7fffffffcc50 } /usr/include/c++/7/debug/vector:417: Error: attempt to subscript container with out-of-bounds index 556, but container only holds 556 elements. Objects involved in the operation: sequence "this" @ 0x0x2e87af8 { type = std::__debug::vector<partial_symbol*, std::allocator<partial_symbol*> >; } The two -D_GLIBCXX_DEBUG regressions were made by: commit bc8f2430e08cc2a520db49a42686e0529be4a3bc Author: Jan Kratochvil <jan.kratochvil@redhat.com> Date: Mon Jun 12 16:29:53 2017 +0100 Code cleanup: C++ify .gdb_index producer commit af5bf4ada48ff65b6658be1fab8f9c8f8ab5f319 Author: Simon Marchi <simon.marchi@ericsson.com> Date: Sat Oct 14 08:06:29 2017 -0400 Replace psymbol_allocation_list with std::vector gdb/ChangeLog 2018-04-12 Jan Kratochvil <jan.kratochvil@redhat.com> PR gdb/23053 * dwarf-index-write.c (data_buf::grow) (write_one_signatured_type) (recursively_write_psymbols) (debug_names::recursively_write_psymbols) (debug_names::write_one_signatured_type): Fix -D_GLIBCXX_DEBUG regression.
2018-04-12 22:31:39 +02:00
+ psymtab->globals_offset),
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
psymtab->n_global_syms, info->cu_index,
0);
write_psymbols (info->symtab,
info->psyms_seen,
Introduce class psymtab_storage This introduces a new psymtab_storage class, which holds all psymbol-related objects that are independent of the objfile. (This latter contraint explains why psymbol_map was not moved; though this could still be done with some work.) This patch does not yet change where psymtab allocation is done -- that comes later. This just wraps everything in a single object to make further transformations simpler. Note that a shared_ptr is used to link from the objfile to the psymtab_storage object. The end goal here is to allow a given symbol reader to simply attach to the psymtab_storage object to the BFD, then reuse it in later invocations; shared_ptr makes this simple to reason about. gdb/ChangeLog 2019-01-10 Tom Tromey <tom@tromey.com> * symmisc.c (print_symbol_bcache_statistics): Update. (print_objfile_statistics): Update. * symfile.c (reread_symbols): Update. * psymtab.h (class psymtab_storage): New. * psymtab.c (psymtab_storage): New constructor. (~psymtab_storage): New destructor. (require_partial_symbols): Update. (ALL_OBJFILE_PSYMTABS_REQUIRED): Rewrite. (find_pc_sect_psymtab, find_pc_sect_psymbol) (match_partial_symbol, lookup_partial_symbol, dump_psymtab) (psym_dump, recursively_search_psymtabs, psym_has_symbols) (psym_find_compunit_symtab_by_address, sort_pst_symbols) (start_psymtab_common, end_psymtab_common) (add_psymbol_to_bcache, add_psymbol_to_list, init_psymbol_list) (allocate_psymtab): Update. (psymtab_storage::discard_psymtab): Rename from discard_psymtab. Update. (dump_psymtab_addrmap, maintenance_print_psymbols) (maintenance_check_psymtabs): Update. (class objfile_psymtabs): Move to objfiles.h. * psympriv.h (discard_psymtab): Now inline. (psymtab_discarder::psymtab_discarder): Update. (psymtab_discarder::~psymtab_discarder): Update. (ALL_OBJFILE_PSYMTABS): Rewrite. * objfiles.h (struct objfile) <psymtabs, psymtabs_addrmap, free_psymtabs, psymbol_cache, global_psymbols, static_psymbols>: Remove fields. <partial_symtabs>: New field. (class objfile_psymtabs): Move from psymtab.h. Update. * objfiles.c (objfile::objfile): Initialize partial_symtabs, not psymbol_cache. (objfile::~objfile): Don't destroy psymbol_cache. * mdebugread.c (parse_partial_symbols): Update. * dwarf2read.c (create_addrmap_from_index) (create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab) (process_psymtab_comp_unit_reader, dwarf2_build_psymtabs_hard) (add_partial_subprogram, dwarf2_ranges_read): Update. * dwarf-index-write.c (write_address_map) (write_one_signatured_type, recursively_write_psymbols) (class debug_names, class debug_names, write_psymtabs_to_index): Update.
2018-05-11 00:23:51 +02:00
(info->objfile->partial_symtabs->static_psymbols.data ()
Fix -D_GLIBCXX_DEBUG gdb-add-index regression Fedora Rawhide started to use -D_GLIBCXX_DEBUG which made gdb-add-index failing: gdb: Out-of-bounds vector access while running gdb-add-index https://bugzilla.redhat.com/show_bug.cgi?id=1540559 /usr/include/c++/7/debug/safe_iterator.h:270: Error: attempt to dereference a past-the-end iterator. Objects involved in the operation: iterator "this" @ 0x0x7fffffffcb90 { type = __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<unsigned char*, std::__cxx1998::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > >, std::__debug::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > (mutable iterator); state = past-the-end; references sequence with type 'std::__debug::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > >' @ 0x0x7fffffffcc50 } /usr/include/c++/7/debug/vector:417: Error: attempt to subscript container with out-of-bounds index 556, but container only holds 556 elements. Objects involved in the operation: sequence "this" @ 0x0x2e87af8 { type = std::__debug::vector<partial_symbol*, std::allocator<partial_symbol*> >; } The two -D_GLIBCXX_DEBUG regressions were made by: commit bc8f2430e08cc2a520db49a42686e0529be4a3bc Author: Jan Kratochvil <jan.kratochvil@redhat.com> Date: Mon Jun 12 16:29:53 2017 +0100 Code cleanup: C++ify .gdb_index producer commit af5bf4ada48ff65b6658be1fab8f9c8f8ab5f319 Author: Simon Marchi <simon.marchi@ericsson.com> Date: Sat Oct 14 08:06:29 2017 -0400 Replace psymbol_allocation_list with std::vector gdb/ChangeLog 2018-04-12 Jan Kratochvil <jan.kratochvil@redhat.com> PR gdb/23053 * dwarf-index-write.c (data_buf::grow) (write_one_signatured_type) (recursively_write_psymbols) (debug_names::recursively_write_psymbols) (debug_names::write_one_signatured_type): Fix -D_GLIBCXX_DEBUG regression.
2018-04-12 22:31:39 +02:00
+ psymtab->statics_offset),
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
psymtab->n_static_syms, info->cu_index,
1);
info->types_list.append_uint (8, BFD_ENDIAN_LITTLE,
to_underlying (entry->per_cu.sect_off));
info->types_list.append_uint (8, BFD_ENDIAN_LITTLE,
to_underlying (entry->type_offset_in_tu));
info->types_list.append_uint (8, BFD_ENDIAN_LITTLE, entry->signature);
++info->cu_index;
return 1;
}
/* Recurse into all "included" dependencies and count their symbols as
if they appeared in this psymtab. */
static void
recursively_count_psymbols (struct partial_symtab *psymtab,
size_t &psyms_seen)
{
for (int i = 0; i < psymtab->number_of_dependencies; ++i)
if (psymtab->dependencies[i]->user != NULL)
recursively_count_psymbols (psymtab->dependencies[i],
psyms_seen);
psyms_seen += psymtab->n_global_syms;
psyms_seen += psymtab->n_static_syms;
}
/* Recurse into all "included" dependencies and write their symbols as
if they appeared in this psymtab. */
static void
recursively_write_psymbols (struct objfile *objfile,
struct partial_symtab *psymtab,
struct mapped_symtab *symtab,
std::unordered_set<partial_symbol *> &psyms_seen,
offset_type cu_index)
{
int i;
for (i = 0; i < psymtab->number_of_dependencies; ++i)
if (psymtab->dependencies[i]->user != NULL)
recursively_write_psymbols (objfile, psymtab->dependencies[i],
symtab, psyms_seen, cu_index);
write_psymbols (symtab,
psyms_seen,
Introduce class psymtab_storage This introduces a new psymtab_storage class, which holds all psymbol-related objects that are independent of the objfile. (This latter contraint explains why psymbol_map was not moved; though this could still be done with some work.) This patch does not yet change where psymtab allocation is done -- that comes later. This just wraps everything in a single object to make further transformations simpler. Note that a shared_ptr is used to link from the objfile to the psymtab_storage object. The end goal here is to allow a given symbol reader to simply attach to the psymtab_storage object to the BFD, then reuse it in later invocations; shared_ptr makes this simple to reason about. gdb/ChangeLog 2019-01-10 Tom Tromey <tom@tromey.com> * symmisc.c (print_symbol_bcache_statistics): Update. (print_objfile_statistics): Update. * symfile.c (reread_symbols): Update. * psymtab.h (class psymtab_storage): New. * psymtab.c (psymtab_storage): New constructor. (~psymtab_storage): New destructor. (require_partial_symbols): Update. (ALL_OBJFILE_PSYMTABS_REQUIRED): Rewrite. (find_pc_sect_psymtab, find_pc_sect_psymbol) (match_partial_symbol, lookup_partial_symbol, dump_psymtab) (psym_dump, recursively_search_psymtabs, psym_has_symbols) (psym_find_compunit_symtab_by_address, sort_pst_symbols) (start_psymtab_common, end_psymtab_common) (add_psymbol_to_bcache, add_psymbol_to_list, init_psymbol_list) (allocate_psymtab): Update. (psymtab_storage::discard_psymtab): Rename from discard_psymtab. Update. (dump_psymtab_addrmap, maintenance_print_psymbols) (maintenance_check_psymtabs): Update. (class objfile_psymtabs): Move to objfiles.h. * psympriv.h (discard_psymtab): Now inline. (psymtab_discarder::psymtab_discarder): Update. (psymtab_discarder::~psymtab_discarder): Update. (ALL_OBJFILE_PSYMTABS): Rewrite. * objfiles.h (struct objfile) <psymtabs, psymtabs_addrmap, free_psymtabs, psymbol_cache, global_psymbols, static_psymbols>: Remove fields. <partial_symtabs>: New field. (class objfile_psymtabs): Move from psymtab.h. Update. * objfiles.c (objfile::objfile): Initialize partial_symtabs, not psymbol_cache. (objfile::~objfile): Don't destroy psymbol_cache. * mdebugread.c (parse_partial_symbols): Update. * dwarf2read.c (create_addrmap_from_index) (create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab) (process_psymtab_comp_unit_reader, dwarf2_build_psymtabs_hard) (add_partial_subprogram, dwarf2_ranges_read): Update. * dwarf-index-write.c (write_address_map) (write_one_signatured_type, recursively_write_psymbols) (class debug_names, class debug_names, write_psymtabs_to_index): Update.
2018-05-11 00:23:51 +02:00
(objfile->partial_symtabs->global_psymbols.data ()
+ psymtab->globals_offset),
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
psymtab->n_global_syms, cu_index,
0);
write_psymbols (symtab,
psyms_seen,
Introduce class psymtab_storage This introduces a new psymtab_storage class, which holds all psymbol-related objects that are independent of the objfile. (This latter contraint explains why psymbol_map was not moved; though this could still be done with some work.) This patch does not yet change where psymtab allocation is done -- that comes later. This just wraps everything in a single object to make further transformations simpler. Note that a shared_ptr is used to link from the objfile to the psymtab_storage object. The end goal here is to allow a given symbol reader to simply attach to the psymtab_storage object to the BFD, then reuse it in later invocations; shared_ptr makes this simple to reason about. gdb/ChangeLog 2019-01-10 Tom Tromey <tom@tromey.com> * symmisc.c (print_symbol_bcache_statistics): Update. (print_objfile_statistics): Update. * symfile.c (reread_symbols): Update. * psymtab.h (class psymtab_storage): New. * psymtab.c (psymtab_storage): New constructor. (~psymtab_storage): New destructor. (require_partial_symbols): Update. (ALL_OBJFILE_PSYMTABS_REQUIRED): Rewrite. (find_pc_sect_psymtab, find_pc_sect_psymbol) (match_partial_symbol, lookup_partial_symbol, dump_psymtab) (psym_dump, recursively_search_psymtabs, psym_has_symbols) (psym_find_compunit_symtab_by_address, sort_pst_symbols) (start_psymtab_common, end_psymtab_common) (add_psymbol_to_bcache, add_psymbol_to_list, init_psymbol_list) (allocate_psymtab): Update. (psymtab_storage::discard_psymtab): Rename from discard_psymtab. Update. (dump_psymtab_addrmap, maintenance_print_psymbols) (maintenance_check_psymtabs): Update. (class objfile_psymtabs): Move to objfiles.h. * psympriv.h (discard_psymtab): Now inline. (psymtab_discarder::psymtab_discarder): Update. (psymtab_discarder::~psymtab_discarder): Update. (ALL_OBJFILE_PSYMTABS): Rewrite. * objfiles.h (struct objfile) <psymtabs, psymtabs_addrmap, free_psymtabs, psymbol_cache, global_psymbols, static_psymbols>: Remove fields. <partial_symtabs>: New field. (class objfile_psymtabs): Move from psymtab.h. Update. * objfiles.c (objfile::objfile): Initialize partial_symtabs, not psymbol_cache. (objfile::~objfile): Don't destroy psymbol_cache. * mdebugread.c (parse_partial_symbols): Update. * dwarf2read.c (create_addrmap_from_index) (create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab) (process_psymtab_comp_unit_reader, dwarf2_build_psymtabs_hard) (add_partial_subprogram, dwarf2_ranges_read): Update. * dwarf-index-write.c (write_address_map) (write_one_signatured_type, recursively_write_psymbols) (class debug_names, class debug_names, write_psymtabs_to_index): Update.
2018-05-11 00:23:51 +02:00
(objfile->partial_symtabs->static_psymbols.data ()
+ psymtab->statics_offset),
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
psymtab->n_static_syms, cu_index,
1);
}
/* DWARF-5 .debug_names builder. */
class debug_names
{
public:
debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile, bool is_dwarf64,
bfd_endian dwarf5_byte_order)
: m_dwarf5_byte_order (dwarf5_byte_order),
m_dwarf32 (dwarf5_byte_order),
m_dwarf64 (dwarf5_byte_order),
m_dwarf (is_dwarf64
? static_cast<dwarf &> (m_dwarf64)
: static_cast<dwarf &> (m_dwarf32)),
m_name_table_string_offs (m_dwarf.name_table_string_offs),
m_name_table_entry_offs (m_dwarf.name_table_entry_offs),
m_debugstrlookup (dwarf2_per_objfile)
{}
int dwarf5_offset_size () const
{
const bool dwarf5_is_dwarf64 = &m_dwarf == &m_dwarf64;
return dwarf5_is_dwarf64 ? 8 : 4;
}
/* Is this symbol from DW_TAG_compile_unit or DW_TAG_type_unit? */
enum class unit_kind { cu, tu };
/* Insert one symbol. */
void insert (const partial_symbol *psym, int cu_index, bool is_static,
unit_kind kind)
{
const int dwarf_tag = psymbol_tag (psym);
if (dwarf_tag == 0)
return;
Change representation of psymbol to flush out accessors This is the psymbol analog to the patch to change the representation of minimal symbols: https://sourceware.org/ml/gdb-patches/2013-10/msg00524.html It has the same rationale: namely, that we're going to change the code to apply psymbol offsets at runtime. This will be done by adding an argument to the SYMBOL_VALUE_ADDRESS macro -- but since we can't convert all the symbol types at once, we need a new approach. Because gdb now is in C++, this patch changes partial_symbol to inherit from general_symbol_info, rather than renaming the field. This simplifies code in some places. Also, as noted before, these macros implement a kind of "phony polymorphism" that is not actually useful in practice; so this patch removes the macros in favor of simply referring directly to members. In a few cases -- obj_section in this patch and the symbol address in the future -- methods will be used instead. Note that this removes the blanket memset from add_psymbol_to_bcache. This hasn't really been needed since bcache was modified to allow holes in objects and since psymtab took advantage of that. This deletion was required due to changing partial_symbol to derive from general_symbol_info. gdb/ChangeLog 2018-07-26 Tom Tromey <tom@tromey.com> * dwarf-index-write.c (write_psymbols, debug_names::insert) (debug_names::write_psymbols): Update. * psympriv.h (struct partial_symbol): Derive from general_symbol_info. <obj_section>: New method. (PSYMBOL_DOMAIN, PSYMBOL_CLASS): Remove.n * psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymtab) (find_pc_sect_psymbol, fixup_psymbol_section) (match_partial_symbol, lookup_partial_symbol, relocate_psymtabs) (print_partial_symbols, recursively_search_psymtabs) (compare_psymbols, psymbol_hash, psymbol_compare) (add_psymbol_to_bcache, maintenance_check_psymtabs) (psymbol_name_matches, psym_fill_psymbol_map): Update.
2018-05-04 00:36:17 +02:00
const char *const name = symbol_search_name (psym);
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
const auto insertpair
= m_name_to_value_set.emplace (c_str_view (name),
std::set<symbol_value> ());
std::set<symbol_value> &value_set = insertpair.first->second;
value_set.emplace (symbol_value (dwarf_tag, cu_index, is_static, kind));
}
/* Build all the tables. All symbols must be already inserted.
This function does not call file_write, caller has to do it
afterwards. */
void build ()
{
/* Verify the build method has not be called twice. */
gdb_assert (m_abbrev_table.empty ());
const size_t name_count = m_name_to_value_set.size ();
m_bucket_table.resize
(std::pow (2, std::ceil (std::log2 (name_count * 4 / 3))));
m_hash_table.reserve (name_count);
m_name_table_string_offs.reserve (name_count);
m_name_table_entry_offs.reserve (name_count);
/* Map each hash of symbol to its name and value. */
struct hash_it_pair
{
uint32_t hash;
decltype (m_name_to_value_set)::const_iterator it;
};
std::vector<std::forward_list<hash_it_pair>> bucket_hash;
bucket_hash.resize (m_bucket_table.size ());
for (decltype (m_name_to_value_set)::const_iterator it
= m_name_to_value_set.cbegin ();
it != m_name_to_value_set.cend ();
++it)
{
const char *const name = it->first.c_str ();
const uint32_t hash = dwarf5_djb_hash (name);
hash_it_pair hashitpair;
hashitpair.hash = hash;
hashitpair.it = it;
auto &slot = bucket_hash[hash % bucket_hash.size()];
slot.push_front (std::move (hashitpair));
}
for (size_t bucket_ix = 0; bucket_ix < bucket_hash.size (); ++bucket_ix)
{
const std::forward_list<hash_it_pair> &hashitlist
= bucket_hash[bucket_ix];
if (hashitlist.empty ())
continue;
uint32_t &bucket_slot = m_bucket_table[bucket_ix];
/* The hashes array is indexed starting at 1. */
store_unsigned_integer (reinterpret_cast<gdb_byte *> (&bucket_slot),
sizeof (bucket_slot), m_dwarf5_byte_order,
m_hash_table.size () + 1);
for (const hash_it_pair &hashitpair : hashitlist)
{
m_hash_table.push_back (0);
store_unsigned_integer (reinterpret_cast<gdb_byte *>
(&m_hash_table.back ()),
sizeof (m_hash_table.back ()),
m_dwarf5_byte_order, hashitpair.hash);
const c_str_view &name = hashitpair.it->first;
const std::set<symbol_value> &value_set = hashitpair.it->second;
m_name_table_string_offs.push_back_reorder
(m_debugstrlookup.lookup (name.c_str ()));
m_name_table_entry_offs.push_back_reorder (m_entry_pool.size ());
gdb_assert (!value_set.empty ());
for (const symbol_value &value : value_set)
{
int &idx = m_indexkey_to_idx[index_key (value.dwarf_tag,
value.is_static,
value.kind)];
if (idx == 0)
{
idx = m_idx_next++;
m_abbrev_table.append_unsigned_leb128 (idx);
m_abbrev_table.append_unsigned_leb128 (value.dwarf_tag);
m_abbrev_table.append_unsigned_leb128
(value.kind == unit_kind::cu ? DW_IDX_compile_unit
: DW_IDX_type_unit);
m_abbrev_table.append_unsigned_leb128 (DW_FORM_udata);
m_abbrev_table.append_unsigned_leb128 (value.is_static
? DW_IDX_GNU_internal
: DW_IDX_GNU_external);
m_abbrev_table.append_unsigned_leb128 (DW_FORM_flag_present);
/* Terminate attributes list. */
m_abbrev_table.append_unsigned_leb128 (0);
m_abbrev_table.append_unsigned_leb128 (0);
}
m_entry_pool.append_unsigned_leb128 (idx);
m_entry_pool.append_unsigned_leb128 (value.cu_index);
}
/* Terminate the list of CUs. */
m_entry_pool.append_unsigned_leb128 (0);
}
}
gdb_assert (m_hash_table.size () == name_count);
/* Terminate tags list. */
m_abbrev_table.append_unsigned_leb128 (0);
}
/* Return .debug_names bucket count. This must be called only after
calling the build method. */
uint32_t bucket_count () const
{
/* Verify the build method has been already called. */
gdb_assert (!m_abbrev_table.empty ());
const uint32_t retval = m_bucket_table.size ();
/* Check for overflow. */
gdb_assert (retval == m_bucket_table.size ());
return retval;
}
/* Return .debug_names names count. This must be called only after
calling the build method. */
uint32_t name_count () const
{
/* Verify the build method has been already called. */
gdb_assert (!m_abbrev_table.empty ());
const uint32_t retval = m_hash_table.size ();
/* Check for overflow. */
gdb_assert (retval == m_hash_table.size ());
return retval;
}
/* Return number of bytes of .debug_names abbreviation table. This
must be called only after calling the build method. */
uint32_t abbrev_table_bytes () const
{
gdb_assert (!m_abbrev_table.empty ());
return m_abbrev_table.size ();
}
/* Recurse into all "included" dependencies and store their symbols
as if they appeared in this psymtab. */
void recursively_write_psymbols
(struct objfile *objfile,
struct partial_symtab *psymtab,
std::unordered_set<partial_symbol *> &psyms_seen,
int cu_index)
{
for (int i = 0; i < psymtab->number_of_dependencies; ++i)
if (psymtab->dependencies[i]->user != NULL)
recursively_write_psymbols (objfile, psymtab->dependencies[i],
psyms_seen, cu_index);
write_psymbols (psyms_seen,
Introduce class psymtab_storage This introduces a new psymtab_storage class, which holds all psymbol-related objects that are independent of the objfile. (This latter contraint explains why psymbol_map was not moved; though this could still be done with some work.) This patch does not yet change where psymtab allocation is done -- that comes later. This just wraps everything in a single object to make further transformations simpler. Note that a shared_ptr is used to link from the objfile to the psymtab_storage object. The end goal here is to allow a given symbol reader to simply attach to the psymtab_storage object to the BFD, then reuse it in later invocations; shared_ptr makes this simple to reason about. gdb/ChangeLog 2019-01-10 Tom Tromey <tom@tromey.com> * symmisc.c (print_symbol_bcache_statistics): Update. (print_objfile_statistics): Update. * symfile.c (reread_symbols): Update. * psymtab.h (class psymtab_storage): New. * psymtab.c (psymtab_storage): New constructor. (~psymtab_storage): New destructor. (require_partial_symbols): Update. (ALL_OBJFILE_PSYMTABS_REQUIRED): Rewrite. (find_pc_sect_psymtab, find_pc_sect_psymbol) (match_partial_symbol, lookup_partial_symbol, dump_psymtab) (psym_dump, recursively_search_psymtabs, psym_has_symbols) (psym_find_compunit_symtab_by_address, sort_pst_symbols) (start_psymtab_common, end_psymtab_common) (add_psymbol_to_bcache, add_psymbol_to_list, init_psymbol_list) (allocate_psymtab): Update. (psymtab_storage::discard_psymtab): Rename from discard_psymtab. Update. (dump_psymtab_addrmap, maintenance_print_psymbols) (maintenance_check_psymtabs): Update. (class objfile_psymtabs): Move to objfiles.h. * psympriv.h (discard_psymtab): Now inline. (psymtab_discarder::psymtab_discarder): Update. (psymtab_discarder::~psymtab_discarder): Update. (ALL_OBJFILE_PSYMTABS): Rewrite. * objfiles.h (struct objfile) <psymtabs, psymtabs_addrmap, free_psymtabs, psymbol_cache, global_psymbols, static_psymbols>: Remove fields. <partial_symtabs>: New field. (class objfile_psymtabs): Move from psymtab.h. Update. * objfiles.c (objfile::objfile): Initialize partial_symtabs, not psymbol_cache. (objfile::~objfile): Don't destroy psymbol_cache. * mdebugread.c (parse_partial_symbols): Update. * dwarf2read.c (create_addrmap_from_index) (create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab) (process_psymtab_comp_unit_reader, dwarf2_build_psymtabs_hard) (add_partial_subprogram, dwarf2_ranges_read): Update. * dwarf-index-write.c (write_address_map) (write_one_signatured_type, recursively_write_psymbols) (class debug_names, class debug_names, write_psymtabs_to_index): Update.
2018-05-11 00:23:51 +02:00
(objfile->partial_symtabs->global_psymbols.data ()
+ psymtab->globals_offset),
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
psymtab->n_global_syms, cu_index, false, unit_kind::cu);
write_psymbols (psyms_seen,
Introduce class psymtab_storage This introduces a new psymtab_storage class, which holds all psymbol-related objects that are independent of the objfile. (This latter contraint explains why psymbol_map was not moved; though this could still be done with some work.) This patch does not yet change where psymtab allocation is done -- that comes later. This just wraps everything in a single object to make further transformations simpler. Note that a shared_ptr is used to link from the objfile to the psymtab_storage object. The end goal here is to allow a given symbol reader to simply attach to the psymtab_storage object to the BFD, then reuse it in later invocations; shared_ptr makes this simple to reason about. gdb/ChangeLog 2019-01-10 Tom Tromey <tom@tromey.com> * symmisc.c (print_symbol_bcache_statistics): Update. (print_objfile_statistics): Update. * symfile.c (reread_symbols): Update. * psymtab.h (class psymtab_storage): New. * psymtab.c (psymtab_storage): New constructor. (~psymtab_storage): New destructor. (require_partial_symbols): Update. (ALL_OBJFILE_PSYMTABS_REQUIRED): Rewrite. (find_pc_sect_psymtab, find_pc_sect_psymbol) (match_partial_symbol, lookup_partial_symbol, dump_psymtab) (psym_dump, recursively_search_psymtabs, psym_has_symbols) (psym_find_compunit_symtab_by_address, sort_pst_symbols) (start_psymtab_common, end_psymtab_common) (add_psymbol_to_bcache, add_psymbol_to_list, init_psymbol_list) (allocate_psymtab): Update. (psymtab_storage::discard_psymtab): Rename from discard_psymtab. Update. (dump_psymtab_addrmap, maintenance_print_psymbols) (maintenance_check_psymtabs): Update. (class objfile_psymtabs): Move to objfiles.h. * psympriv.h (discard_psymtab): Now inline. (psymtab_discarder::psymtab_discarder): Update. (psymtab_discarder::~psymtab_discarder): Update. (ALL_OBJFILE_PSYMTABS): Rewrite. * objfiles.h (struct objfile) <psymtabs, psymtabs_addrmap, free_psymtabs, psymbol_cache, global_psymbols, static_psymbols>: Remove fields. <partial_symtabs>: New field. (class objfile_psymtabs): Move from psymtab.h. Update. * objfiles.c (objfile::objfile): Initialize partial_symtabs, not psymbol_cache. (objfile::~objfile): Don't destroy psymbol_cache. * mdebugread.c (parse_partial_symbols): Update. * dwarf2read.c (create_addrmap_from_index) (create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab) (process_psymtab_comp_unit_reader, dwarf2_build_psymtabs_hard) (add_partial_subprogram, dwarf2_ranges_read): Update. * dwarf-index-write.c (write_address_map) (write_one_signatured_type, recursively_write_psymbols) (class debug_names, class debug_names, write_psymtabs_to_index): Update.
2018-05-11 00:23:51 +02:00
(objfile->partial_symtabs->static_psymbols.data ()
+ psymtab->statics_offset),
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
psymtab->n_static_syms, cu_index, true, unit_kind::cu);
}
/* Return number of bytes the .debug_names section will have. This
must be called only after calling the build method. */
size_t bytes () const
{
/* Verify the build method has been already called. */
gdb_assert (!m_abbrev_table.empty ());
size_t expected_bytes = 0;
expected_bytes += m_bucket_table.size () * sizeof (m_bucket_table[0]);
expected_bytes += m_hash_table.size () * sizeof (m_hash_table[0]);
expected_bytes += m_name_table_string_offs.bytes ();
expected_bytes += m_name_table_entry_offs.bytes ();
expected_bytes += m_abbrev_table.size ();
expected_bytes += m_entry_pool.size ();
return expected_bytes;
}
/* Write .debug_names to FILE_NAMES and .debug_str addition to
FILE_STR. This must be called only after calling the build
method. */
void file_write (FILE *file_names, FILE *file_str) const
{
/* Verify the build method has been already called. */
gdb_assert (!m_abbrev_table.empty ());
::file_write (file_names, m_bucket_table);
::file_write (file_names, m_hash_table);
m_name_table_string_offs.file_write (file_names);
m_name_table_entry_offs.file_write (file_names);
m_abbrev_table.file_write (file_names);
m_entry_pool.file_write (file_names);
m_debugstrlookup.file_write (file_str);
}
/* A helper user data for write_one_signatured_type. */
class write_one_signatured_type_data
{
public:
write_one_signatured_type_data (debug_names &nametable_,
signatured_type_index_data &&info_)
: nametable (nametable_), info (std::move (info_))
{}
debug_names &nametable;
struct signatured_type_index_data info;
};
/* A helper function to pass write_one_signatured_type to
htab_traverse_noresize. */
static int
write_one_signatured_type (void **slot, void *d)
{
write_one_signatured_type_data *data = (write_one_signatured_type_data *) d;
struct signatured_type_index_data *info = &data->info;
struct signatured_type *entry = (struct signatured_type *) *slot;
data->nametable.write_one_signatured_type (entry, info);
return 1;
}
private:
/* Storage for symbol names mapping them to their .debug_str section
offsets. */
class debug_str_lookup
{
public:
/* Object costructor to be called for current DWARF2_PER_OBJFILE.
All .debug_str section strings are automatically stored. */
debug_str_lookup (struct dwarf2_per_objfile *dwarf2_per_objfile)
: m_abfd (dwarf2_per_objfile->objfile->obfd),
m_dwarf2_per_objfile (dwarf2_per_objfile)
{
dwarf2_read_section (dwarf2_per_objfile->objfile,
&dwarf2_per_objfile->str);
if (dwarf2_per_objfile->str.buffer == NULL)
return;
for (const gdb_byte *data = dwarf2_per_objfile->str.buffer;
data < (dwarf2_per_objfile->str.buffer
+ dwarf2_per_objfile->str.size);)
{
const char *const s = reinterpret_cast<const char *> (data);
const auto insertpair
= m_str_table.emplace (c_str_view (s),
data - dwarf2_per_objfile->str.buffer);
if (!insertpair.second)
Remove symfile_complaints The complaint system seems to allow for multiple different complaint topics. However, in practice only symfile_complaints has ever been defined. Seeing that complaints.c dates to 1992, and that no new complaints have been added in the intervening years, I think it is reasonable to admit that complaints are specifically related to debuginfo reading. This patch removes symfile_complaints and updates all the callers. Some of these spots should perhaps be calls to warning instead, but I did not make that change. gdb/ChangeLog 2018-05-23 Tom Tromey <tom@tromey.com> * complaints.c (symfile_complaints): Remove. (complaint_internal): Remove "complaints" parameter. (clear_complaints, vcomplaint): Remove "c" parameter. (get_complaints): Remove. * dwarf2read.c (dwarf2_statement_list_fits_in_line_number_section_complaint) (dwarf2_debug_line_missing_file_complaint) (dwarf2_debug_line_missing_end_sequence_complaint) (dwarf2_complex_location_expr_complaint) (dwarf2_const_value_length_mismatch_complaint) (dwarf2_section_buffer_overflow_complaint) (dwarf2_macro_malformed_definition_complaint) (dwarf2_invalid_attrib_class_complaint) (create_addrmap_from_index, dw2_symtab_iter_next) (dw2_expand_marked_cus) (dw2_debug_names_iterator::find_vec_in_debug_names) (dw2_debug_names_iterator::next, dw2_debug_names_iterator::next) (create_debug_type_hash_table, init_cutu_and_read_dies) (partial_die_parent_scope, add_partial_enumeration) (skip_one_die, fixup_go_packaging, quirk_rust_enum, process_die) (dwarf2_compute_name, dwarf2_physname, read_namespace_alias) (read_import_statement, read_file_scope, create_dwo_cu_reader) (create_cus_hash_table, create_dwp_hash_table) (inherit_abstract_dies, read_func_scope, read_call_site_scope) (dwarf2_rnglists_process, dwarf2_ranges_process) (dwarf2_add_type_defn, dwarf2_attach_fields_to_type) (dwarf2_add_member_fn, get_alignment, maybe_set_alignment) (handle_struct_member_die, process_structure_scope) (read_array_type, read_common_block, read_module_type) (read_tag_pointer_type, read_typedef, read_base_type) (read_subrange_type, load_partial_dies, partial_die_info::read) (partial_die_info::read, partial_die_info::read) (partial_die_info::read, read_checked_initial_length_and_offset) (dwarf2_string_attr, read_formatted_entries) (dwarf_decode_line_header) (lnp_state_machine::check_line_address, dwarf_decode_lines_1) (new_symbol, dwarf2_const_value_attr, lookup_die_type) (read_type_die_1, determine_prefix, dwarf2_get_ref_die_offset) (dwarf2_get_attr_constant_value, dwarf2_fetch_constant_bytes) (get_signatured_type, get_DW_AT_signature_type) (decode_locdesc, file_file_name, consume_improper_spaces) (skip_form_bytes, skip_unknown_opcode, dwarf_parse_macro_header) (dwarf_decode_macro_bytes, dwarf_decode_macros) (dwarf2_symbol_mark_computed, set_die_type) (read_attribute_value): Update. * stap-probe.c (handle_stap_probe, get_stap_base_address): Update. * dbxread.c (unknown_symtype_complaint) (lbrac_mismatch_complaint, repeated_header_complaint) (set_namestring, function_outside_compilation_unit_complaint) (read_dbx_symtab, process_one_symbol): Update. * gdbtypes.c (stub_noname_complaint): Update. * windows-nat.c (handle_unload_dll): Update. * coffread.c (coff_symtab_read, enter_linenos, decode_type) (decode_base_type): Update. * xcoffread.c (bf_notfound_complaint, ef_complaint) (eb_complaint, record_include_begin, record_include_end) (enter_line_range, xcoff_next_symbol_text, read_xcoff_symtab) (process_xcoff_symbol, read_symbol) (function_outside_compilation_unit_complaint) (scan_xcoff_symtab): Update. * machoread.c (macho_symtab_read, macho_add_oso_symfile): Update. * buildsym.c (finish_block_internal, make_blockvector) (end_symtab_get_static_block, augment_type_symtab): Update. * dtrace-probe.c (dtrace_process_dof) (dtrace_static_probe_ops::get_probes): Update. * complaints.h (struct complaint): Don't declare. (symfile_complaints): Remove. (complaint_internal): Remove "complaints" parameter. (complaint): Likewise. (clear_complaints): Likewise. * symfile.c (syms_from_objfile_1, finish_new_objfile) (reread_symbols): Update. * dwarf2-frame.c (dwarf2_restore_rule, execute_cfa_program) (dwarf2_frame_cache, decode_frame_entry): Update. * dwarf2loc.c (dwarf_reg_to_regnum): Update. * objc-lang.c (lookup_objc_class, lookup_child_selector) (info_selectors_command): Update. * macrotab.c (macro_include, check_for_redefinition) (macro_undef): Update. * objfiles.c (filter_overlapping_sections): Update. * stabsread.c (invalid_cpp_abbrev_complaint) (reg_value_complaint, stabs_general_complaint, dbx_lookup_type) (define_symbol, error_type, read_type, rs6000_builtin_type) (stabs_method_name_from_physname, read_member_functions) (read_cpp_abbrev, read_baseclasses, read_tilde_fields) (attach_fields_to_type, complain_about_struct_wipeout) (read_range_type, read_args, common_block_start) (common_block_end, cleanup_undefined_types_1, scan_file_globals): Update. * mdebugread.c (index_complaint, unknown_ext_complaint) (basic_type_complaint, bad_tag_guess_complaint) (bad_rfd_entry_complaint, unexpected_type_code_complaint) (reg_value_complaint, parse_symbol, parse_type, upgrade_type) (parse_procedure, parse_lines) (function_outside_compilation_unit_complaint) (parse_partial_symbols, psymtab_to_symtab_1, cross_ref) (bad_tag_guess_complaint, reg_value_complaint): Update. * cp-support.c (demangled_name_complaint): Update. * macroscope.c (sal_macro_scope): Update. * dwarf-index-write.c (class debug_names): Update. gdb/testsuite/ChangeLog 2018-05-23 Tom Tromey <tom@tromey.com> * gdb.gdb/complaints.exp (test_initial_complaints): Don't mention symfile_complaints. (test_short_complaints): Likewise. (test_empty_complaints): Likewise. (test_initial_complaints): Update.
2018-05-17 06:54:44 +02:00
complaint (_("Duplicate string \"%s\" in "
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
".debug_str section [in module %s]"),
s, bfd_get_filename (m_abfd));
data += strlen (s) + 1;
}
}
/* Return offset of symbol name S in the .debug_str section. Add
such symbol to the section's end if it does not exist there
yet. */
size_t lookup (const char *s)
{
const auto it = m_str_table.find (c_str_view (s));
if (it != m_str_table.end ())
return it->second;
const size_t offset = (m_dwarf2_per_objfile->str.size
+ m_str_add_buf.size ());
m_str_table.emplace (c_str_view (s), offset);
m_str_add_buf.append_cstr0 (s);
return offset;
}
/* Append the end of the .debug_str section to FILE. */
void file_write (FILE *file) const
{
m_str_add_buf.file_write (file);
}
private:
std::unordered_map<c_str_view, size_t, c_str_view_hasher> m_str_table;
bfd *const m_abfd;
struct dwarf2_per_objfile *m_dwarf2_per_objfile;
/* Data to add at the end of .debug_str for new needed symbol names. */
data_buf m_str_add_buf;
};
/* Container to map used DWARF tags to their .debug_names abbreviation
tags. */
class index_key
{
public:
index_key (int dwarf_tag_, bool is_static_, unit_kind kind_)
: dwarf_tag (dwarf_tag_), is_static (is_static_), kind (kind_)
{
}
bool
operator== (const index_key &other) const
{
return (dwarf_tag == other.dwarf_tag && is_static == other.is_static
&& kind == other.kind);
}
const int dwarf_tag;
const bool is_static;
const unit_kind kind;
};
/* Provide std::unordered_map::hasher for index_key. */
class index_key_hasher
{
public:
size_t
operator () (const index_key &key) const
{
return (std::hash<int>() (key.dwarf_tag) << 1) | key.is_static;
}
};
/* Parameters of one symbol entry. */
class symbol_value
{
public:
const int dwarf_tag, cu_index;
const bool is_static;
const unit_kind kind;
symbol_value (int dwarf_tag_, int cu_index_, bool is_static_,
unit_kind kind_)
: dwarf_tag (dwarf_tag_), cu_index (cu_index_), is_static (is_static_),
kind (kind_)
{}
bool
operator< (const symbol_value &other) const
{
#define X(n) \
do \
{ \
if (n < other.n) \
return true; \
if (n > other.n) \
return false; \
} \
while (0)
X (dwarf_tag);
X (is_static);
X (kind);
X (cu_index);
#undef X
return false;
}
};
/* Abstract base class to unify DWARF-32 and DWARF-64 name table
output. */
class offset_vec
{
protected:
const bfd_endian dwarf5_byte_order;
public:
explicit offset_vec (bfd_endian dwarf5_byte_order_)
: dwarf5_byte_order (dwarf5_byte_order_)
{}
/* Call std::vector::reserve for NELEM elements. */
virtual void reserve (size_t nelem) = 0;
/* Call std::vector::push_back with store_unsigned_integer byte
reordering for ELEM. */
virtual void push_back_reorder (size_t elem) = 0;
/* Return expected output size in bytes. */
virtual size_t bytes () const = 0;
/* Write name table to FILE. */
virtual void file_write (FILE *file) const = 0;
};
/* Template to unify DWARF-32 and DWARF-64 output. */
template<typename OffsetSize>
class offset_vec_tmpl : public offset_vec
{
public:
explicit offset_vec_tmpl (bfd_endian dwarf5_byte_order_)
: offset_vec (dwarf5_byte_order_)
{}
/* Implement offset_vec::reserve. */
void reserve (size_t nelem) override
{
m_vec.reserve (nelem);
}
/* Implement offset_vec::push_back_reorder. */
void push_back_reorder (size_t elem) override
{
m_vec.push_back (elem);
/* Check for overflow. */
gdb_assert (m_vec.back () == elem);
store_unsigned_integer (reinterpret_cast<gdb_byte *> (&m_vec.back ()),
sizeof (m_vec.back ()), dwarf5_byte_order, elem);
}
/* Implement offset_vec::bytes. */
size_t bytes () const override
{
return m_vec.size () * sizeof (m_vec[0]);
}
/* Implement offset_vec::file_write. */
void file_write (FILE *file) const override
{
::file_write (file, m_vec);
}
private:
std::vector<OffsetSize> m_vec;
};
/* Base class to unify DWARF-32 and DWARF-64 .debug_names output
respecting name table width. */
class dwarf
{
public:
offset_vec &name_table_string_offs, &name_table_entry_offs;
dwarf (offset_vec &name_table_string_offs_,
offset_vec &name_table_entry_offs_)
: name_table_string_offs (name_table_string_offs_),
name_table_entry_offs (name_table_entry_offs_)
{
}
};
/* Template to unify DWARF-32 and DWARF-64 .debug_names output
respecting name table width. */
template<typename OffsetSize>
class dwarf_tmpl : public dwarf
{
public:
explicit dwarf_tmpl (bfd_endian dwarf5_byte_order_)
: dwarf (m_name_table_string_offs, m_name_table_entry_offs),
m_name_table_string_offs (dwarf5_byte_order_),
m_name_table_entry_offs (dwarf5_byte_order_)
{}
private:
offset_vec_tmpl<OffsetSize> m_name_table_string_offs;
offset_vec_tmpl<OffsetSize> m_name_table_entry_offs;
};
/* Try to reconstruct original DWARF tag for given partial_symbol.
This function is not DWARF-5 compliant but it is sufficient for
GDB as a DWARF-5 index consumer. */
static int psymbol_tag (const struct partial_symbol *psym)
{
Change representation of psymbol to flush out accessors This is the psymbol analog to the patch to change the representation of minimal symbols: https://sourceware.org/ml/gdb-patches/2013-10/msg00524.html It has the same rationale: namely, that we're going to change the code to apply psymbol offsets at runtime. This will be done by adding an argument to the SYMBOL_VALUE_ADDRESS macro -- but since we can't convert all the symbol types at once, we need a new approach. Because gdb now is in C++, this patch changes partial_symbol to inherit from general_symbol_info, rather than renaming the field. This simplifies code in some places. Also, as noted before, these macros implement a kind of "phony polymorphism" that is not actually useful in practice; so this patch removes the macros in favor of simply referring directly to members. In a few cases -- obj_section in this patch and the symbol address in the future -- methods will be used instead. Note that this removes the blanket memset from add_psymbol_to_bcache. This hasn't really been needed since bcache was modified to allow holes in objects and since psymtab took advantage of that. This deletion was required due to changing partial_symbol to derive from general_symbol_info. gdb/ChangeLog 2018-07-26 Tom Tromey <tom@tromey.com> * dwarf-index-write.c (write_psymbols, debug_names::insert) (debug_names::write_psymbols): Update. * psympriv.h (struct partial_symbol): Derive from general_symbol_info. <obj_section>: New method. (PSYMBOL_DOMAIN, PSYMBOL_CLASS): Remove.n * psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymtab) (find_pc_sect_psymbol, fixup_psymbol_section) (match_partial_symbol, lookup_partial_symbol, relocate_psymtabs) (print_partial_symbols, recursively_search_psymtabs) (compare_psymbols, psymbol_hash, psymbol_compare) (add_psymbol_to_bcache, maintenance_check_psymtabs) (psymbol_name_matches, psym_fill_psymbol_map): Update.
2018-05-04 00:36:17 +02:00
domain_enum domain = psym->domain;
enum address_class aclass = psym->aclass;
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
switch (domain)
{
case VAR_DOMAIN:
switch (aclass)
{
case LOC_BLOCK:
return DW_TAG_subprogram;
case LOC_TYPEDEF:
return DW_TAG_typedef;
case LOC_COMPUTED:
case LOC_CONST_BYTES:
case LOC_OPTIMIZED_OUT:
case LOC_STATIC:
return DW_TAG_variable;
case LOC_CONST:
/* Note: It's currently impossible to recognize psyms as enum values
short of reading the type info. For now punt. */
return DW_TAG_variable;
default:
/* There are other LOC_FOO values that one might want to classify
as variables, but dwarf2read.c doesn't currently use them. */
return DW_TAG_variable;
}
case STRUCT_DOMAIN:
return DW_TAG_structure_type;
default:
return 0;
}
}
/* Call insert for all partial symbols and mark them in PSYMS_SEEN. */
void write_psymbols (std::unordered_set<partial_symbol *> &psyms_seen,
struct partial_symbol **psymp, int count, int cu_index,
bool is_static, unit_kind kind)
{
for (; count-- > 0; ++psymp)
{
struct partial_symbol *psym = *psymp;
Change representation of psymbol to flush out accessors This is the psymbol analog to the patch to change the representation of minimal symbols: https://sourceware.org/ml/gdb-patches/2013-10/msg00524.html It has the same rationale: namely, that we're going to change the code to apply psymbol offsets at runtime. This will be done by adding an argument to the SYMBOL_VALUE_ADDRESS macro -- but since we can't convert all the symbol types at once, we need a new approach. Because gdb now is in C++, this patch changes partial_symbol to inherit from general_symbol_info, rather than renaming the field. This simplifies code in some places. Also, as noted before, these macros implement a kind of "phony polymorphism" that is not actually useful in practice; so this patch removes the macros in favor of simply referring directly to members. In a few cases -- obj_section in this patch and the symbol address in the future -- methods will be used instead. Note that this removes the blanket memset from add_psymbol_to_bcache. This hasn't really been needed since bcache was modified to allow holes in objects and since psymtab took advantage of that. This deletion was required due to changing partial_symbol to derive from general_symbol_info. gdb/ChangeLog 2018-07-26 Tom Tromey <tom@tromey.com> * dwarf-index-write.c (write_psymbols, debug_names::insert) (debug_names::write_psymbols): Update. * psympriv.h (struct partial_symbol): Derive from general_symbol_info. <obj_section>: New method. (PSYMBOL_DOMAIN, PSYMBOL_CLASS): Remove.n * psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymtab) (find_pc_sect_psymbol, fixup_psymbol_section) (match_partial_symbol, lookup_partial_symbol, relocate_psymtabs) (print_partial_symbols, recursively_search_psymtabs) (compare_psymbols, psymbol_hash, psymbol_compare) (add_psymbol_to_bcache, maintenance_check_psymtabs) (psymbol_name_matches, psym_fill_psymbol_map): Update.
2018-05-04 00:36:17 +02:00
if (psym->language == language_ada)
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
error (_("Ada is not currently supported by the index"));
/* Only add a given psymbol once. */
if (psyms_seen.insert (psym).second)
insert (psym, cu_index, is_static, kind);
}
}
/* A helper function that writes a single signatured_type
to a debug_names. */
void
write_one_signatured_type (struct signatured_type *entry,
struct signatured_type_index_data *info)
{
struct partial_symtab *psymtab = entry->per_cu.v.psymtab;
write_psymbols (info->psyms_seen,
Introduce class psymtab_storage This introduces a new psymtab_storage class, which holds all psymbol-related objects that are independent of the objfile. (This latter contraint explains why psymbol_map was not moved; though this could still be done with some work.) This patch does not yet change where psymtab allocation is done -- that comes later. This just wraps everything in a single object to make further transformations simpler. Note that a shared_ptr is used to link from the objfile to the psymtab_storage object. The end goal here is to allow a given symbol reader to simply attach to the psymtab_storage object to the BFD, then reuse it in later invocations; shared_ptr makes this simple to reason about. gdb/ChangeLog 2019-01-10 Tom Tromey <tom@tromey.com> * symmisc.c (print_symbol_bcache_statistics): Update. (print_objfile_statistics): Update. * symfile.c (reread_symbols): Update. * psymtab.h (class psymtab_storage): New. * psymtab.c (psymtab_storage): New constructor. (~psymtab_storage): New destructor. (require_partial_symbols): Update. (ALL_OBJFILE_PSYMTABS_REQUIRED): Rewrite. (find_pc_sect_psymtab, find_pc_sect_psymbol) (match_partial_symbol, lookup_partial_symbol, dump_psymtab) (psym_dump, recursively_search_psymtabs, psym_has_symbols) (psym_find_compunit_symtab_by_address, sort_pst_symbols) (start_psymtab_common, end_psymtab_common) (add_psymbol_to_bcache, add_psymbol_to_list, init_psymbol_list) (allocate_psymtab): Update. (psymtab_storage::discard_psymtab): Rename from discard_psymtab. Update. (dump_psymtab_addrmap, maintenance_print_psymbols) (maintenance_check_psymtabs): Update. (class objfile_psymtabs): Move to objfiles.h. * psympriv.h (discard_psymtab): Now inline. (psymtab_discarder::psymtab_discarder): Update. (psymtab_discarder::~psymtab_discarder): Update. (ALL_OBJFILE_PSYMTABS): Rewrite. * objfiles.h (struct objfile) <psymtabs, psymtabs_addrmap, free_psymtabs, psymbol_cache, global_psymbols, static_psymbols>: Remove fields. <partial_symtabs>: New field. (class objfile_psymtabs): Move from psymtab.h. Update. * objfiles.c (objfile::objfile): Initialize partial_symtabs, not psymbol_cache. (objfile::~objfile): Don't destroy psymbol_cache. * mdebugread.c (parse_partial_symbols): Update. * dwarf2read.c (create_addrmap_from_index) (create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab) (process_psymtab_comp_unit_reader, dwarf2_build_psymtabs_hard) (add_partial_subprogram, dwarf2_ranges_read): Update. * dwarf-index-write.c (write_address_map) (write_one_signatured_type, recursively_write_psymbols) (class debug_names, class debug_names, write_psymtabs_to_index): Update.
2018-05-11 00:23:51 +02:00
(info->objfile->partial_symtabs->global_psymbols.data ()
Fix -D_GLIBCXX_DEBUG gdb-add-index regression Fedora Rawhide started to use -D_GLIBCXX_DEBUG which made gdb-add-index failing: gdb: Out-of-bounds vector access while running gdb-add-index https://bugzilla.redhat.com/show_bug.cgi?id=1540559 /usr/include/c++/7/debug/safe_iterator.h:270: Error: attempt to dereference a past-the-end iterator. Objects involved in the operation: iterator "this" @ 0x0x7fffffffcb90 { type = __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<unsigned char*, std::__cxx1998::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > >, std::__debug::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > (mutable iterator); state = past-the-end; references sequence with type 'std::__debug::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > >' @ 0x0x7fffffffcc50 } /usr/include/c++/7/debug/vector:417: Error: attempt to subscript container with out-of-bounds index 556, but container only holds 556 elements. Objects involved in the operation: sequence "this" @ 0x0x2e87af8 { type = std::__debug::vector<partial_symbol*, std::allocator<partial_symbol*> >; } The two -D_GLIBCXX_DEBUG regressions were made by: commit bc8f2430e08cc2a520db49a42686e0529be4a3bc Author: Jan Kratochvil <jan.kratochvil@redhat.com> Date: Mon Jun 12 16:29:53 2017 +0100 Code cleanup: C++ify .gdb_index producer commit af5bf4ada48ff65b6658be1fab8f9c8f8ab5f319 Author: Simon Marchi <simon.marchi@ericsson.com> Date: Sat Oct 14 08:06:29 2017 -0400 Replace psymbol_allocation_list with std::vector gdb/ChangeLog 2018-04-12 Jan Kratochvil <jan.kratochvil@redhat.com> PR gdb/23053 * dwarf-index-write.c (data_buf::grow) (write_one_signatured_type) (recursively_write_psymbols) (debug_names::recursively_write_psymbols) (debug_names::write_one_signatured_type): Fix -D_GLIBCXX_DEBUG regression.
2018-04-12 22:31:39 +02:00
+ psymtab->globals_offset),
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
psymtab->n_global_syms, info->cu_index, false,
unit_kind::tu);
write_psymbols (info->psyms_seen,
Introduce class psymtab_storage This introduces a new psymtab_storage class, which holds all psymbol-related objects that are independent of the objfile. (This latter contraint explains why psymbol_map was not moved; though this could still be done with some work.) This patch does not yet change where psymtab allocation is done -- that comes later. This just wraps everything in a single object to make further transformations simpler. Note that a shared_ptr is used to link from the objfile to the psymtab_storage object. The end goal here is to allow a given symbol reader to simply attach to the psymtab_storage object to the BFD, then reuse it in later invocations; shared_ptr makes this simple to reason about. gdb/ChangeLog 2019-01-10 Tom Tromey <tom@tromey.com> * symmisc.c (print_symbol_bcache_statistics): Update. (print_objfile_statistics): Update. * symfile.c (reread_symbols): Update. * psymtab.h (class psymtab_storage): New. * psymtab.c (psymtab_storage): New constructor. (~psymtab_storage): New destructor. (require_partial_symbols): Update. (ALL_OBJFILE_PSYMTABS_REQUIRED): Rewrite. (find_pc_sect_psymtab, find_pc_sect_psymbol) (match_partial_symbol, lookup_partial_symbol, dump_psymtab) (psym_dump, recursively_search_psymtabs, psym_has_symbols) (psym_find_compunit_symtab_by_address, sort_pst_symbols) (start_psymtab_common, end_psymtab_common) (add_psymbol_to_bcache, add_psymbol_to_list, init_psymbol_list) (allocate_psymtab): Update. (psymtab_storage::discard_psymtab): Rename from discard_psymtab. Update. (dump_psymtab_addrmap, maintenance_print_psymbols) (maintenance_check_psymtabs): Update. (class objfile_psymtabs): Move to objfiles.h. * psympriv.h (discard_psymtab): Now inline. (psymtab_discarder::psymtab_discarder): Update. (psymtab_discarder::~psymtab_discarder): Update. (ALL_OBJFILE_PSYMTABS): Rewrite. * objfiles.h (struct objfile) <psymtabs, psymtabs_addrmap, free_psymtabs, psymbol_cache, global_psymbols, static_psymbols>: Remove fields. <partial_symtabs>: New field. (class objfile_psymtabs): Move from psymtab.h. Update. * objfiles.c (objfile::objfile): Initialize partial_symtabs, not psymbol_cache. (objfile::~objfile): Don't destroy psymbol_cache. * mdebugread.c (parse_partial_symbols): Update. * dwarf2read.c (create_addrmap_from_index) (create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab) (process_psymtab_comp_unit_reader, dwarf2_build_psymtabs_hard) (add_partial_subprogram, dwarf2_ranges_read): Update. * dwarf-index-write.c (write_address_map) (write_one_signatured_type, recursively_write_psymbols) (class debug_names, class debug_names, write_psymtabs_to_index): Update.
2018-05-11 00:23:51 +02:00
(info->objfile->partial_symtabs->static_psymbols.data ()
Fix -D_GLIBCXX_DEBUG gdb-add-index regression Fedora Rawhide started to use -D_GLIBCXX_DEBUG which made gdb-add-index failing: gdb: Out-of-bounds vector access while running gdb-add-index https://bugzilla.redhat.com/show_bug.cgi?id=1540559 /usr/include/c++/7/debug/safe_iterator.h:270: Error: attempt to dereference a past-the-end iterator. Objects involved in the operation: iterator "this" @ 0x0x7fffffffcb90 { type = __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<unsigned char*, std::__cxx1998::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > >, std::__debug::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > (mutable iterator); state = past-the-end; references sequence with type 'std::__debug::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > >' @ 0x0x7fffffffcc50 } /usr/include/c++/7/debug/vector:417: Error: attempt to subscript container with out-of-bounds index 556, but container only holds 556 elements. Objects involved in the operation: sequence "this" @ 0x0x2e87af8 { type = std::__debug::vector<partial_symbol*, std::allocator<partial_symbol*> >; } The two -D_GLIBCXX_DEBUG regressions were made by: commit bc8f2430e08cc2a520db49a42686e0529be4a3bc Author: Jan Kratochvil <jan.kratochvil@redhat.com> Date: Mon Jun 12 16:29:53 2017 +0100 Code cleanup: C++ify .gdb_index producer commit af5bf4ada48ff65b6658be1fab8f9c8f8ab5f319 Author: Simon Marchi <simon.marchi@ericsson.com> Date: Sat Oct 14 08:06:29 2017 -0400 Replace psymbol_allocation_list with std::vector gdb/ChangeLog 2018-04-12 Jan Kratochvil <jan.kratochvil@redhat.com> PR gdb/23053 * dwarf-index-write.c (data_buf::grow) (write_one_signatured_type) (recursively_write_psymbols) (debug_names::recursively_write_psymbols) (debug_names::write_one_signatured_type): Fix -D_GLIBCXX_DEBUG regression.
2018-04-12 22:31:39 +02:00
+ psymtab->statics_offset),
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
psymtab->n_static_syms, info->cu_index, true,
unit_kind::tu);
info->types_list.append_uint (dwarf5_offset_size (), m_dwarf5_byte_order,
to_underlying (entry->per_cu.sect_off));
++info->cu_index;
}
/* Store value of each symbol. */
std::unordered_map<c_str_view, std::set<symbol_value>, c_str_view_hasher>
m_name_to_value_set;
/* Tables of DWARF-5 .debug_names. They are in object file byte
order. */
std::vector<uint32_t> m_bucket_table;
std::vector<uint32_t> m_hash_table;
const bfd_endian m_dwarf5_byte_order;
dwarf_tmpl<uint32_t> m_dwarf32;
dwarf_tmpl<uint64_t> m_dwarf64;
dwarf &m_dwarf;
offset_vec &m_name_table_string_offs, &m_name_table_entry_offs;
debug_str_lookup m_debugstrlookup;
/* Map each used .debug_names abbreviation tag parameter to its
index value. */
std::unordered_map<index_key, int, index_key_hasher> m_indexkey_to_idx;
/* Next unused .debug_names abbreviation tag for
m_indexkey_to_idx. */
int m_idx_next = 1;
/* .debug_names abbreviation table. */
data_buf m_abbrev_table;
/* .debug_names entry pool. */
data_buf m_entry_pool;
};
/* Return iff any of the needed offsets does not fit into 32-bit
.debug_names section. */
static bool
check_dwarf64_offsets (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
Make dwarf2_per_objfile::all_comp_units an std::vector Make all_comp_units an std::vector, remove n_comp_units and some manual memory management. gdb/ChangeLog: * dwarf2read.h (struct dwarf2_per_objfile) <all_comp_units>: Likewise. Make an std::vector. <n_comp_units>: Remove. * dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust to std::vector change. (dwarf2_per_objfile::get_cutu): Likewise. (dwarf2_per_objfile::get_cu): Likewise. (create_cus_from_index): Likewise. (create_addrmap_from_index): Likewise. (create_addrmap_from_aranges): Likewise. (dwarf2_read_index): Likewise. (dw2_find_last_source_symtab): Likewise. (dw2_map_symtabs_matching_filename): Likewise. (dw2_symtab_iter_next): Likewise. (dw2_print_stats): Likewise. (dw2_expand_all_symtabs): Likewise. (dw2_expand_symtabs_with_fullname): Likewise. (dw2_expand_marked_cus): Likewise. (dw2_map_symbol_filenames): Likewise. (create_cus_from_debug_names): Likewise. (dwarf2_read_debug_names): Likewise. (dw2_debug_names_iterator::next): Likewise. (dwarf2_initialize_objfile): Likewise. (set_partial_user): Likewise. (dwarf2_build_psymtabs_hard): Likewise. (read_comp_units_from_section): Remove arguments, adjust to std::vector change. (create_all_comp_units): Adjust to std::vector and read_comp_units_from_section changes. (dwarf2_find_containing_comp_unit): Adjust to std::vector change. * dwarf-index-write.c (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise.
2018-04-07 19:53:43 +02:00
for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
{
Make dwarf2_per_objfile::all_comp_units an std::vector Make all_comp_units an std::vector, remove n_comp_units and some manual memory management. gdb/ChangeLog: * dwarf2read.h (struct dwarf2_per_objfile) <all_comp_units>: Likewise. Make an std::vector. <n_comp_units>: Remove. * dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust to std::vector change. (dwarf2_per_objfile::get_cutu): Likewise. (dwarf2_per_objfile::get_cu): Likewise. (create_cus_from_index): Likewise. (create_addrmap_from_index): Likewise. (create_addrmap_from_aranges): Likewise. (dwarf2_read_index): Likewise. (dw2_find_last_source_symtab): Likewise. (dw2_map_symtabs_matching_filename): Likewise. (dw2_symtab_iter_next): Likewise. (dw2_print_stats): Likewise. (dw2_expand_all_symtabs): Likewise. (dw2_expand_symtabs_with_fullname): Likewise. (dw2_expand_marked_cus): Likewise. (dw2_map_symbol_filenames): Likewise. (create_cus_from_debug_names): Likewise. (dwarf2_read_debug_names): Likewise. (dw2_debug_names_iterator::next): Likewise. (dwarf2_initialize_objfile): Likewise. (set_partial_user): Likewise. (dwarf2_build_psymtabs_hard): Likewise. (read_comp_units_from_section): Remove arguments, adjust to std::vector change. (create_all_comp_units): Adjust to std::vector and read_comp_units_from_section changes. (dwarf2_find_containing_comp_unit): Adjust to std::vector change. * dwarf-index-write.c (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise.
2018-04-07 19:53:43 +02:00
if (to_underlying (per_cu->sect_off) >= (static_cast<uint64_t> (1) << 32))
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
return true;
}
for (const signatured_type *sigtype : dwarf2_per_objfile->all_type_units)
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
{
const dwarf2_per_cu_data &per_cu = sigtype->per_cu;
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
if (to_underlying (per_cu.sect_off) >= (static_cast<uint64_t> (1) << 32))
return true;
}
return false;
}
/* The psyms_seen set is potentially going to be largish (~40k
elements when indexing a -g3 build of GDB itself). Estimate the
number of elements in order to avoid too many rehashes, which
require rebuilding buckets and thus many trips to
malloc/free. */
static size_t
psyms_seen_size (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
size_t psyms_count = 0;
Make dwarf2_per_objfile::all_comp_units an std::vector Make all_comp_units an std::vector, remove n_comp_units and some manual memory management. gdb/ChangeLog: * dwarf2read.h (struct dwarf2_per_objfile) <all_comp_units>: Likewise. Make an std::vector. <n_comp_units>: Remove. * dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust to std::vector change. (dwarf2_per_objfile::get_cutu): Likewise. (dwarf2_per_objfile::get_cu): Likewise. (create_cus_from_index): Likewise. (create_addrmap_from_index): Likewise. (create_addrmap_from_aranges): Likewise. (dwarf2_read_index): Likewise. (dw2_find_last_source_symtab): Likewise. (dw2_map_symtabs_matching_filename): Likewise. (dw2_symtab_iter_next): Likewise. (dw2_print_stats): Likewise. (dw2_expand_all_symtabs): Likewise. (dw2_expand_symtabs_with_fullname): Likewise. (dw2_expand_marked_cus): Likewise. (dw2_map_symbol_filenames): Likewise. (create_cus_from_debug_names): Likewise. (dwarf2_read_debug_names): Likewise. (dw2_debug_names_iterator::next): Likewise. (dwarf2_initialize_objfile): Likewise. (set_partial_user): Likewise. (dwarf2_build_psymtabs_hard): Likewise. (read_comp_units_from_section): Remove arguments, adjust to std::vector change. (create_all_comp_units): Adjust to std::vector and read_comp_units_from_section changes. (dwarf2_find_containing_comp_unit): Adjust to std::vector change. * dwarf-index-write.c (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise.
2018-04-07 19:53:43 +02:00
for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
{
struct partial_symtab *psymtab = per_cu->v.psymtab;
if (psymtab != NULL && psymtab->user == NULL)
recursively_count_psymbols (psymtab, psyms_count);
}
/* Generating an index for gdb itself shows a ratio of
TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */
return psyms_count / 4;
}
/* Write new .gdb_index section for OBJFILE into OUT_FILE.
Return how many bytes were expected to be written into OUT_FILE. */
static size_t
write_gdbindex (struct dwarf2_per_objfile *dwarf2_per_objfile, FILE *out_file)
{
struct objfile *objfile = dwarf2_per_objfile->objfile;
mapped_symtab symtab;
data_buf cu_list;
/* While we're scanning CU's create a table that maps a psymtab pointer
(which is what addrmap records) to its index (which is what is recorded
in the index file). This will later be needed to write the address
table. */
psym_index_map cu_index_htab;
Make dwarf2_per_objfile::all_comp_units an std::vector Make all_comp_units an std::vector, remove n_comp_units and some manual memory management. gdb/ChangeLog: * dwarf2read.h (struct dwarf2_per_objfile) <all_comp_units>: Likewise. Make an std::vector. <n_comp_units>: Remove. * dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust to std::vector change. (dwarf2_per_objfile::get_cutu): Likewise. (dwarf2_per_objfile::get_cu): Likewise. (create_cus_from_index): Likewise. (create_addrmap_from_index): Likewise. (create_addrmap_from_aranges): Likewise. (dwarf2_read_index): Likewise. (dw2_find_last_source_symtab): Likewise. (dw2_map_symtabs_matching_filename): Likewise. (dw2_symtab_iter_next): Likewise. (dw2_print_stats): Likewise. (dw2_expand_all_symtabs): Likewise. (dw2_expand_symtabs_with_fullname): Likewise. (dw2_expand_marked_cus): Likewise. (dw2_map_symbol_filenames): Likewise. (create_cus_from_debug_names): Likewise. (dwarf2_read_debug_names): Likewise. (dw2_debug_names_iterator::next): Likewise. (dwarf2_initialize_objfile): Likewise. (set_partial_user): Likewise. (dwarf2_build_psymtabs_hard): Likewise. (read_comp_units_from_section): Remove arguments, adjust to std::vector change. (create_all_comp_units): Adjust to std::vector and read_comp_units_from_section changes. (dwarf2_find_containing_comp_unit): Adjust to std::vector change. * dwarf-index-write.c (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise.
2018-04-07 19:53:43 +02:00
cu_index_htab.reserve (dwarf2_per_objfile->all_comp_units.size ());
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
/* The CU list is already sorted, so we don't need to do additional
work here. Also, the debug_types entries do not appear in
all_comp_units, but only in their own hash table. */
std::unordered_set<partial_symbol *> psyms_seen
(psyms_seen_size (dwarf2_per_objfile));
Make dwarf2_per_objfile::all_comp_units an std::vector Make all_comp_units an std::vector, remove n_comp_units and some manual memory management. gdb/ChangeLog: * dwarf2read.h (struct dwarf2_per_objfile) <all_comp_units>: Likewise. Make an std::vector. <n_comp_units>: Remove. * dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust to std::vector change. (dwarf2_per_objfile::get_cutu): Likewise. (dwarf2_per_objfile::get_cu): Likewise. (create_cus_from_index): Likewise. (create_addrmap_from_index): Likewise. (create_addrmap_from_aranges): Likewise. (dwarf2_read_index): Likewise. (dw2_find_last_source_symtab): Likewise. (dw2_map_symtabs_matching_filename): Likewise. (dw2_symtab_iter_next): Likewise. (dw2_print_stats): Likewise. (dw2_expand_all_symtabs): Likewise. (dw2_expand_symtabs_with_fullname): Likewise. (dw2_expand_marked_cus): Likewise. (dw2_map_symbol_filenames): Likewise. (create_cus_from_debug_names): Likewise. (dwarf2_read_debug_names): Likewise. (dw2_debug_names_iterator::next): Likewise. (dwarf2_initialize_objfile): Likewise. (set_partial_user): Likewise. (dwarf2_build_psymtabs_hard): Likewise. (read_comp_units_from_section): Remove arguments, adjust to std::vector change. (create_all_comp_units): Adjust to std::vector and read_comp_units_from_section changes. (dwarf2_find_containing_comp_unit): Adjust to std::vector change. * dwarf-index-write.c (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise.
2018-04-07 19:53:43 +02:00
for (int i = 0; i < dwarf2_per_objfile->all_comp_units.size (); ++i)
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
{
struct dwarf2_per_cu_data *per_cu
= dwarf2_per_objfile->all_comp_units[i];
struct partial_symtab *psymtab = per_cu->v.psymtab;
/* CU of a shared file from 'dwz -m' may be unused by this main file.
It may be referenced from a local scope but in such case it does not
need to be present in .gdb_index. */
if (psymtab == NULL)
continue;
if (psymtab->user == NULL)
recursively_write_psymbols (objfile, psymtab, &symtab,
psyms_seen, i);
const auto insertpair = cu_index_htab.emplace (psymtab, i);
gdb_assert (insertpair.second);
cu_list.append_uint (8, BFD_ENDIAN_LITTLE,
to_underlying (per_cu->sect_off));
cu_list.append_uint (8, BFD_ENDIAN_LITTLE, per_cu->length);
}
/* Dump the address map. */
data_buf addr_vec;
write_address_map (objfile, addr_vec, cu_index_htab);
/* Write out the .debug_type entries, if any. */
data_buf types_cu_list;
if (dwarf2_per_objfile->signatured_types)
{
signatured_type_index_data sig_data (types_cu_list,
psyms_seen);
sig_data.objfile = objfile;
sig_data.symtab = &symtab;
Make dwarf2_per_objfile::all_comp_units an std::vector Make all_comp_units an std::vector, remove n_comp_units and some manual memory management. gdb/ChangeLog: * dwarf2read.h (struct dwarf2_per_objfile) <all_comp_units>: Likewise. Make an std::vector. <n_comp_units>: Remove. * dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust to std::vector change. (dwarf2_per_objfile::get_cutu): Likewise. (dwarf2_per_objfile::get_cu): Likewise. (create_cus_from_index): Likewise. (create_addrmap_from_index): Likewise. (create_addrmap_from_aranges): Likewise. (dwarf2_read_index): Likewise. (dw2_find_last_source_symtab): Likewise. (dw2_map_symtabs_matching_filename): Likewise. (dw2_symtab_iter_next): Likewise. (dw2_print_stats): Likewise. (dw2_expand_all_symtabs): Likewise. (dw2_expand_symtabs_with_fullname): Likewise. (dw2_expand_marked_cus): Likewise. (dw2_map_symbol_filenames): Likewise. (create_cus_from_debug_names): Likewise. (dwarf2_read_debug_names): Likewise. (dw2_debug_names_iterator::next): Likewise. (dwarf2_initialize_objfile): Likewise. (set_partial_user): Likewise. (dwarf2_build_psymtabs_hard): Likewise. (read_comp_units_from_section): Remove arguments, adjust to std::vector change. (create_all_comp_units): Adjust to std::vector and read_comp_units_from_section changes. (dwarf2_find_containing_comp_unit): Adjust to std::vector change. * dwarf-index-write.c (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise.
2018-04-07 19:53:43 +02:00
sig_data.cu_index = dwarf2_per_objfile->all_comp_units.size ();
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
write_one_signatured_type, &sig_data);
}
/* Now that we've processed all symbols we can shrink their cu_indices
lists. */
uniquify_cu_indices (&symtab);
data_buf symtab_vec, constant_pool;
write_hash_table (&symtab, symtab_vec, constant_pool);
data_buf contents;
const offset_type size_of_contents = 6 * sizeof (offset_type);
offset_type total_len = size_of_contents;
/* The version number. */
contents.append_data (MAYBE_SWAP (8));
/* The offset of the CU list from the start of the file. */
contents.append_data (MAYBE_SWAP (total_len));
total_len += cu_list.size ();
/* The offset of the types CU list from the start of the file. */
contents.append_data (MAYBE_SWAP (total_len));
total_len += types_cu_list.size ();
/* The offset of the address table from the start of the file. */
contents.append_data (MAYBE_SWAP (total_len));
total_len += addr_vec.size ();
/* The offset of the symbol table from the start of the file. */
contents.append_data (MAYBE_SWAP (total_len));
total_len += symtab_vec.size ();
/* The offset of the constant pool from the start of the file. */
contents.append_data (MAYBE_SWAP (total_len));
total_len += constant_pool.size ();
gdb_assert (contents.size () == size_of_contents);
contents.file_write (out_file);
cu_list.file_write (out_file);
types_cu_list.file_write (out_file);
addr_vec.file_write (out_file);
symtab_vec.file_write (out_file);
constant_pool.file_write (out_file);
return total_len;
}
/* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
static const gdb_byte dwarf5_gdb_augmentation[] = { 'G', 'D', 'B', 0 };
/* Write a new .debug_names section for OBJFILE into OUT_FILE, write
needed addition to .debug_str section to OUT_FILE_STR. Return how
many bytes were expected to be written into OUT_FILE. */
static size_t
write_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
FILE *out_file, FILE *out_file_str)
{
const bool dwarf5_is_dwarf64 = check_dwarf64_offsets (dwarf2_per_objfile);
struct objfile *objfile = dwarf2_per_objfile->objfile;
const enum bfd_endian dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile));
/* The CU list is already sorted, so we don't need to do additional
work here. Also, the debug_types entries do not appear in
all_comp_units, but only in their own hash table. */
data_buf cu_list;
debug_names nametable (dwarf2_per_objfile, dwarf5_is_dwarf64,
dwarf5_byte_order);
std::unordered_set<partial_symbol *>
psyms_seen (psyms_seen_size (dwarf2_per_objfile));
Make dwarf2_per_objfile::all_comp_units an std::vector Make all_comp_units an std::vector, remove n_comp_units and some manual memory management. gdb/ChangeLog: * dwarf2read.h (struct dwarf2_per_objfile) <all_comp_units>: Likewise. Make an std::vector. <n_comp_units>: Remove. * dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust to std::vector change. (dwarf2_per_objfile::get_cutu): Likewise. (dwarf2_per_objfile::get_cu): Likewise. (create_cus_from_index): Likewise. (create_addrmap_from_index): Likewise. (create_addrmap_from_aranges): Likewise. (dwarf2_read_index): Likewise. (dw2_find_last_source_symtab): Likewise. (dw2_map_symtabs_matching_filename): Likewise. (dw2_symtab_iter_next): Likewise. (dw2_print_stats): Likewise. (dw2_expand_all_symtabs): Likewise. (dw2_expand_symtabs_with_fullname): Likewise. (dw2_expand_marked_cus): Likewise. (dw2_map_symbol_filenames): Likewise. (create_cus_from_debug_names): Likewise. (dwarf2_read_debug_names): Likewise. (dw2_debug_names_iterator::next): Likewise. (dwarf2_initialize_objfile): Likewise. (set_partial_user): Likewise. (dwarf2_build_psymtabs_hard): Likewise. (read_comp_units_from_section): Remove arguments, adjust to std::vector change. (create_all_comp_units): Adjust to std::vector and read_comp_units_from_section changes. (dwarf2_find_containing_comp_unit): Adjust to std::vector change. * dwarf-index-write.c (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise.
2018-04-07 19:53:43 +02:00
for (int i = 0; i < dwarf2_per_objfile->all_comp_units.size (); ++i)
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
{
const dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->all_comp_units[i];
partial_symtab *psymtab = per_cu->v.psymtab;
/* CU of a shared file from 'dwz -m' may be unused by this main
file. It may be referenced from a local scope but in such
case it does not need to be present in .debug_names. */
if (psymtab == NULL)
continue;
if (psymtab->user == NULL)
nametable.recursively_write_psymbols (objfile, psymtab, psyms_seen, i);
cu_list.append_uint (nametable.dwarf5_offset_size (), dwarf5_byte_order,
to_underlying (per_cu->sect_off));
}
/* Write out the .debug_type entries, if any. */
data_buf types_cu_list;
if (dwarf2_per_objfile->signatured_types)
{
debug_names::write_one_signatured_type_data sig_data (nametable,
signatured_type_index_data (types_cu_list, psyms_seen));
sig_data.info.objfile = objfile;
/* It is used only for gdb_index. */
sig_data.info.symtab = nullptr;
sig_data.info.cu_index = 0;
htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
debug_names::write_one_signatured_type,
&sig_data);
}
nametable.build ();
/* No addr_vec - DWARF-5 uses .debug_aranges generated by GCC. */
const offset_type bytes_of_header
= ((dwarf5_is_dwarf64 ? 12 : 4)
+ 2 + 2 + 7 * 4
+ sizeof (dwarf5_gdb_augmentation));
size_t expected_bytes = 0;
expected_bytes += bytes_of_header;
expected_bytes += cu_list.size ();
expected_bytes += types_cu_list.size ();
expected_bytes += nametable.bytes ();
data_buf header;
if (!dwarf5_is_dwarf64)
{
const uint64_t size64 = expected_bytes - 4;
gdb_assert (size64 < 0xfffffff0);
header.append_uint (4, dwarf5_byte_order, size64);
}
else
{
header.append_uint (4, dwarf5_byte_order, 0xffffffff);
header.append_uint (8, dwarf5_byte_order, expected_bytes - 12);
}
/* The version number. */
header.append_uint (2, dwarf5_byte_order, 5);
/* Padding. */
header.append_uint (2, dwarf5_byte_order, 0);
/* comp_unit_count - The number of CUs in the CU list. */
Make dwarf2_per_objfile::all_comp_units an std::vector Make all_comp_units an std::vector, remove n_comp_units and some manual memory management. gdb/ChangeLog: * dwarf2read.h (struct dwarf2_per_objfile) <all_comp_units>: Likewise. Make an std::vector. <n_comp_units>: Remove. * dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Adjust to std::vector change. (dwarf2_per_objfile::get_cutu): Likewise. (dwarf2_per_objfile::get_cu): Likewise. (create_cus_from_index): Likewise. (create_addrmap_from_index): Likewise. (create_addrmap_from_aranges): Likewise. (dwarf2_read_index): Likewise. (dw2_find_last_source_symtab): Likewise. (dw2_map_symtabs_matching_filename): Likewise. (dw2_symtab_iter_next): Likewise. (dw2_print_stats): Likewise. (dw2_expand_all_symtabs): Likewise. (dw2_expand_symtabs_with_fullname): Likewise. (dw2_expand_marked_cus): Likewise. (dw2_map_symbol_filenames): Likewise. (create_cus_from_debug_names): Likewise. (dwarf2_read_debug_names): Likewise. (dw2_debug_names_iterator::next): Likewise. (dwarf2_initialize_objfile): Likewise. (set_partial_user): Likewise. (dwarf2_build_psymtabs_hard): Likewise. (read_comp_units_from_section): Remove arguments, adjust to std::vector change. (create_all_comp_units): Adjust to std::vector and read_comp_units_from_section changes. (dwarf2_find_containing_comp_unit): Adjust to std::vector change. * dwarf-index-write.c (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise.
2018-04-07 19:53:43 +02:00
header.append_uint (4, dwarf5_byte_order,
dwarf2_per_objfile->all_comp_units.size ());
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
/* local_type_unit_count - The number of TUs in the local TU
list. */
header.append_uint (4, dwarf5_byte_order,
dwarf2_per_objfile->all_type_units.size ());
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
/* foreign_type_unit_count - The number of TUs in the foreign TU
list. */
header.append_uint (4, dwarf5_byte_order, 0);
/* bucket_count - The number of hash buckets in the hash lookup
table. */
header.append_uint (4, dwarf5_byte_order, nametable.bucket_count ());
/* name_count - The number of unique names in the index. */
header.append_uint (4, dwarf5_byte_order, nametable.name_count ());
/* abbrev_table_size - The size in bytes of the abbreviations
table. */
header.append_uint (4, dwarf5_byte_order, nametable.abbrev_table_bytes ());
/* augmentation_string_size - The size in bytes of the augmentation
string. This value is rounded up to a multiple of 4. */
static_assert (sizeof (dwarf5_gdb_augmentation) % 4 == 0, "");
header.append_uint (4, dwarf5_byte_order, sizeof (dwarf5_gdb_augmentation));
header.append_data (dwarf5_gdb_augmentation);
gdb_assert (header.size () == bytes_of_header);
header.file_write (out_file);
cu_list.file_write (out_file);
types_cu_list.file_write (out_file);
nametable.file_write (out_file, out_file_str);
return expected_bytes;
}
/* Assert that FILE's size is EXPECTED_SIZE. Assumes file's seek
position is at the end of the file. */
static void
assert_file_size (FILE *file, const char *filename, size_t expected_size)
{
const auto file_size = ftell (file);
if (file_size == -1)
error (_("Can't get `%s' size"), filename);
gdb_assert (file_size == expected_size);
}
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
/* See dwarf-index-write.h. */
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
void
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
write_psymtabs_to_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
const char *dir, const char *basename,
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
dw_index_kind index_kind)
{
struct objfile *objfile = dwarf2_per_objfile->objfile;
if (dwarf2_per_objfile->using_index)
error (_("Cannot use an index to create the index"));
if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
error (_("Cannot make an index when the file has multiple .debug_types sections"));
Introduce class psymtab_storage This introduces a new psymtab_storage class, which holds all psymbol-related objects that are independent of the objfile. (This latter contraint explains why psymbol_map was not moved; though this could still be done with some work.) This patch does not yet change where psymtab allocation is done -- that comes later. This just wraps everything in a single object to make further transformations simpler. Note that a shared_ptr is used to link from the objfile to the psymtab_storage object. The end goal here is to allow a given symbol reader to simply attach to the psymtab_storage object to the BFD, then reuse it in later invocations; shared_ptr makes this simple to reason about. gdb/ChangeLog 2019-01-10 Tom Tromey <tom@tromey.com> * symmisc.c (print_symbol_bcache_statistics): Update. (print_objfile_statistics): Update. * symfile.c (reread_symbols): Update. * psymtab.h (class psymtab_storage): New. * psymtab.c (psymtab_storage): New constructor. (~psymtab_storage): New destructor. (require_partial_symbols): Update. (ALL_OBJFILE_PSYMTABS_REQUIRED): Rewrite. (find_pc_sect_psymtab, find_pc_sect_psymbol) (match_partial_symbol, lookup_partial_symbol, dump_psymtab) (psym_dump, recursively_search_psymtabs, psym_has_symbols) (psym_find_compunit_symtab_by_address, sort_pst_symbols) (start_psymtab_common, end_psymtab_common) (add_psymbol_to_bcache, add_psymbol_to_list, init_psymbol_list) (allocate_psymtab): Update. (psymtab_storage::discard_psymtab): Rename from discard_psymtab. Update. (dump_psymtab_addrmap, maintenance_print_psymbols) (maintenance_check_psymtabs): Update. (class objfile_psymtabs): Move to objfiles.h. * psympriv.h (discard_psymtab): Now inline. (psymtab_discarder::psymtab_discarder): Update. (psymtab_discarder::~psymtab_discarder): Update. (ALL_OBJFILE_PSYMTABS): Rewrite. * objfiles.h (struct objfile) <psymtabs, psymtabs_addrmap, free_psymtabs, psymbol_cache, global_psymbols, static_psymbols>: Remove fields. <partial_symtabs>: New field. (class objfile_psymtabs): Move from psymtab.h. Update. * objfiles.c (objfile::objfile): Initialize partial_symtabs, not psymbol_cache. (objfile::~objfile): Don't destroy psymbol_cache. * mdebugread.c (parse_partial_symbols): Update. * dwarf2read.c (create_addrmap_from_index) (create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab) (process_psymtab_comp_unit_reader, dwarf2_build_psymtabs_hard) (add_partial_subprogram, dwarf2_ranges_read): Update. * dwarf-index-write.c (write_address_map) (write_one_signatured_type, recursively_write_psymbols) (class debug_names, class debug_names, write_psymtabs_to_index): Update.
2018-05-11 00:23:51 +02:00
if (!objfile->partial_symtabs->psymtabs
|| !objfile->partial_symtabs->psymtabs_addrmap)
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
return;
struct stat st;
if (stat (objfile_name (objfile), &st) < 0)
perror_with_name (objfile_name (objfile));
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
std::string filename (std::string (dir) + SLASH_STRING + basename
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
+ (index_kind == dw_index_kind::DEBUG_NAMES
? INDEX5_SUFFIX : INDEX4_SUFFIX));
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
gdb::char_vector filename_temp = make_temp_filename (filename);
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
/* Order matters here; we want FILE to be closed before
FILENAME_TEMP is unlinked, because on MS-Windows one cannot
delete a file that is still open. So, we wrap the unlinker in an
optional and emplace it once we know the file name. */
gdb::optional<gdb::unlinker> unlink_file;
scoped_fd out_file_fd (gdb_mkostemp_cloexec (filename_temp.data (),
O_BINARY));
if (out_file_fd.get () == -1)
perror_with_name (("mkstemp"));
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
gdb_file_up out_file = out_file_fd.to_file ("wb");
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
if (out_file == nullptr)
error (_("Can't open `%s' for writing"), filename_temp.data ());
unlink_file.emplace (filename_temp.data ());
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
if (index_kind == dw_index_kind::DEBUG_NAMES)
{
std::string filename_str (std::string (dir) + SLASH_STRING
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
+ basename + DEBUG_STR_SUFFIX);
gdb::char_vector filename_str_temp = make_temp_filename (filename_str);
/* As above, arrange to unlink the file only after the file
descriptor has been closed. */
gdb::optional<gdb::unlinker> unlink_file_str;
scoped_fd out_file_str_fd
(gdb_mkostemp_cloexec (filename_str_temp.data (), O_BINARY));
if (out_file_str_fd.get () == -1)
perror_with_name (("mkstemp"));
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
gdb_file_up out_file_str = out_file_str_fd.to_file ("wb");
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
if (out_file_str == nullptr)
error (_("Can't open `%s' for writing"), filename_str_temp.data ());
unlink_file_str.emplace (filename_str_temp.data ());
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
const size_t total_len
= write_debug_names (dwarf2_per_objfile, out_file.get (),
out_file_str.get ());
assert_file_size (out_file.get (), filename_temp.data (), total_len);
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
/* We want to keep the file .debug_str file too. */
unlink_file_str->keep ();
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
/* Close and move the str file in place. */
out_file_str.reset ();
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
if (rename (filename_str_temp.data (), filename_str.c_str ()) != 0)
perror_with_name (("rename"));
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
}
else
{
const size_t total_len
= write_gdbindex (dwarf2_per_objfile, out_file.get ());
assert_file_size (out_file.get (), filename_temp.data (), total_len);
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
}
/* We want to keep the file. */
unlink_file->keep ();
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
/* Close and move the file in place. */
out_file.reset ();
Add DWARF index cache New in v3: - Remove things related to the dwarf-5 format. - Fix compilation on mingw (scoped_mmap.c). GDB can generate indexes for DWARF debug information, which, when integrated in the original binary, can speed up loading object files. This can be done using the gdb-add-index script or directly by the linker itself. However, not many people know about this. And even among those who do, because it requires additional steps, I don't know a lot of people who actually go through that trouble. To help make using the DWARF index more transparent, this patch introduces a DWARF index cache. When enabled, loading an index-less binary in GDB will automatically save an index file in ~/.cache/gdb. When loading that same object file again, the index file will be looked up and used to load the DWARF index. You therefore get the benefit of the DWARF index without having to do additional manual steps or modifying your build system. When an index section is already present in the file, GDB will prefer that one over looking up the cache. When doing my edit-compile-debug cycle, I often debug multiple times the same build, so the cache helps reducing the load time of the debug sessions after the first one. - The saved index file is exactly the same as the output of the "save gdb-index" command. It is therefore the exact same content that would be found in the .gdb_index or .debug_names section. We just leave it as a standalone file instead of merging it in the binary. - The cache is just a directory with files named after the object file's build-id. It is not possible to save/load the index for an object file without build-id in the cache. - The cache uses the gdb index format. The problem with the dwarf-5 format is that we can generate an addendum to the .debug_str section that you're supposed to integrate to the original binary. This complicates a little bit loading the data from the cached index files, so I would leave this for later. - The size taken up by ~/.cache/gdb is not limited. I was thinking we could add configurable limit (like ccache does), but that would come after. Also, maybe a command to flush the cache. - The cache is disabled by default. I think once it's been out there and tested for a while, it could be turned on by default, so that everybody can enjoy it. - The code was made to follow the XDG specification: if the XDG_CACHE_HOME environment variable, it is used, otherwise it falls back to ~/.cache/gdb. It is possible to change it using "set index-cache directory". On other OSes than GNU/Linux, ~/.cache may not be the best place to put such data. On macOS it should probably default to ~/Library/Caches/... On Windows, %LocalAppData%/... I don't intend to do this part, but further patches are welcome. - I think that we need to be careful that multiple instances of GDB don't interfere with each other (not far fetched at all if you run GDB in some automated script) and the cache is always coherent (either the file is not found, or it is found and entirely valid). Writing the file directly to its final location seems like a recipe for failure. One GDB could read a file in the index while it is being written by another GDB. To mitigate this, I made write_psymtabs_to_index write to temporary files and rename them once it's done. Two GDB instances writing the index for the same file should not step on each other's toes (the last file to be renamed will stay). A GDB looking up a file will only see a complete file or no file. Also, if GDB crashes while generating the index file, it will leave a work-in-progress file, but it won't be picked up by other instances looking up in the cache. gdb/ChangeLog: * common/pathstuff.h (get_standard_cache_dir): New. * common/pathstuff.c (get_standard_cache_dir): New. * build-id.h (build_id_to_string): New. * dwarf-index-common.h (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move to here. * dwarf-index-write.c (INDEX4_SUFFIX, INDEX5_SUFFIX, DEBUG_STR_SUFFIX): Move from there. (write_psymtabs_to_index): Make non-static, add basename parameter. Write to temporary files, rename when done. (save_gdb_index_command): Adjust call to write_psymtabs_to_index. * dwarf2read.h (dwarf2_per_objfile) <index_cache_res>: New field. * dwarf2read.c (dwz_file) <index_cache_res>: New field. (get_gdb_index_contents_from_cache): New. (get_gdb_index_contents_from_cache_dwz): New. (dwarf2_initialize_objfile): Read index from cache. (dwarf2_build_psymtabs): Save to index. * dwarf-index-cache.h: New file. * dwarf-index-cache.c: New file. * dwarf-index-write.h: New file. gdb/testsuite/ChangeLog: * boards/index-cache-gdb.exp: New file. * gdb.dwarf2/index-cache.exp: New file. * gdb.dwarf2/index-cache.c: New file. * gdb.base/maint.exp: Check if we are using the index cache.
2018-08-08 00:14:20 +02:00
if (rename (filename_temp.data (), filename.c_str ()) != 0)
perror_with_name (("rename"));
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
}
/* Implementation of the `save gdb-index' command.
Note that the .gdb_index file format used by this command is
documented in the GDB manual. Any changes here must be documented
there. */
static void
save_gdb_index_command (const char *arg, int from_tty)
{
const char dwarf5space[] = "-dwarf-5 ";
dw_index_kind index_kind = dw_index_kind::GDB_INDEX;
if (!arg)
arg = "";
arg = skip_spaces (arg);
if (strncmp (arg, dwarf5space, strlen (dwarf5space)) == 0)
{
index_kind = dw_index_kind::DEBUG_NAMES;
arg += strlen (dwarf5space);
arg = skip_spaces (arg);
}
if (!*arg)
error (_("usage: save gdb-index [-dwarf-5] DIRECTORY"));
Change all_objfiles adapter to be a method on program_space This changes the all_objfiles range adapter to be a method on the program space, and fixes up all the users. gdb/ChangeLog 2019-01-17 Tom Tromey <tom@tromey.com> * progspace.h (program_space) <objfiles_range>: New typedef. <objfiles>: New method. <objfiles_head>: Rename from objfiles. (object_files): Update. * guile/scm-progspace.c (gdbscm_progspace_objfiles): Update. * guile/scm-pretty-print.c (ppscm_find_pretty_printer_from_objfiles): Update. * guile/scm-objfile.c (gdbscm_objfiles): Update. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Update. * python/py-progspace.c (pspy_get_objfiles): Update. * python/py-prettyprint.c (find_pretty_printer_from_objfiles): Update. * python/py-objfile.c (objfpy_lookup_objfile_by_name) (objfpy_lookup_objfile_by_build_id): Update. * mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Update. * windows-tdep.c (windows_iterate_over_objfiles_in_search_order): Update. * symtab.c (iterate_over_symtabs, matching_obj_sections) (expand_symtab_containing_pc, lookup_objfile_from_block) (lookup_static_symbol, basic_lookup_transparent_type) (find_pc_sect_compunit_symtab, find_symbol_at_address) (find_line_symtab, info_sources_command) (default_collect_symbol_completion_matches_break_on) (make_source_files_completion_list, find_main_name): Update. * symmisc.c (print_symbol_bcache_statistics) (print_objfile_statistics, maintenance_print_symbols) (maintenance_print_msymbols, maintenance_print_objfiles) (maintenance_info_symtabs, maintenance_check_symtabs) (maintenance_expand_symtabs, maintenance_info_line_tables): Update. * symfile.c (remove_symbol_file_command, overlay_invalidate_all) (find_pc_overlay, find_pc_mapped_section, list_overlays_command) (map_overlay_command, unmap_overlay_command) (simple_overlay_update, expand_symtabs_matching) (map_symbol_filenames): Update. * symfile-debug.c (set_debug_symfile): Update. * spu-tdep.c (spu_overlay_update, spu_objfile_from_frame): Update. * source.c (select_source_symtab, forget_cached_source_info): Update. * solib.c (solib_read_symbols): Update. * solib-spu.c (append_ocl_sos): Update. * psymtab.c (maintenance_print_psymbols) (maintenance_info_psymtabs, maintenance_check_psymtabs): Update. * probe.c (parse_probes_in_pspace, find_probe_by_pc): Update. * printcmd.c (info_symbol_command): Update. * ppc-linux-tdep.c (ppc_linux_spe_context_inferior_created): Update. * objfiles.h (class all_objfiles): Remove. * objfiles.c (have_partial_symbols, have_full_symbols) (have_minimal_symbols, qsort_cmp, update_section_map) (shared_objfile_contains_address_p) (default_iterate_over_objfiles_in_search_order): Update. * objc-lang.c (info_selectors_command, info_classes_command) (find_methods): Update. * minsyms.c (find_solib_trampoline_target): Update. * maint.c (maintenance_info_sections) (maintenance_translate_address, count_symtabs_and_blocks): Update. * main.c (captured_main_1): Update. * linux-thread-db.c (try_thread_db_load_from_pdir) (has_libpthread): Update. * linespec.c (iterate_over_all_matching_symtabs) (search_minsyms_for_name): Update. * jit.c (jit_find_objf_with_entry_addr): Update. * hppa-tdep.c (find_unwind_entry) (hppa_lookup_stub_minimal_symbol): Update. * gcore.c (gcore_create_callback, objfile_find_memory_regions): Update. * elfread.c (elf_gnu_ifunc_resolve_by_cache) (elf_gnu_ifunc_resolve_by_got): Update. * dwarf2-frame.c (dwarf2_frame_find_fde): Update. * dwarf-index-write.c (save_gdb_index_command): Update. * cp-support.c (add_symbol_overload_list_qualified): Update. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Update. * blockframe.c (find_pc_partial_function): Update. * ada-lang.c (ada_lookup_simple_minsym, add_nonlocal_symbols) (ada_collect_symbol_completion_matches) (ada_add_global_exceptions): Update.
2019-01-16 00:55:05 +01:00
for (objfile *objfile : current_program_space->objfiles ())
Remove most uses of ALL_OBJFILES This removes most uses of ALL_OBJFILES, replacing them with ranged for loops. The remaining uses are all in macros, and will be removed in subsequent patches. gdb/ChangeLog 2019-01-09 Tom Tromey <tom@tromey.com> * symtab.c (iterate_over_symtabs, matching_obj_sections) (expand_symtab_containing_pc, lookup_static_symbol) (basic_lookup_transparent_type, find_pc_sect_compunit_symtab) (find_symbol_at_address, find_line_symtab, find_main_name): Use all_objfiles. * probe.c (find_probe_by_pc, collect_probes): Use all_objfiles. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Use all_objfiles. * linux-thread-db.c (try_thread_db_load_from_pdir) (has_libpthread): Use all_objfiles. * ada-lang.c (add_nonlocal_symbols): Use all_objfiles. * linespec.c (iterate_over_all_matching_symtabs) (search_minsyms_for_name): Use all_objfiles. * maint.c (maintenance_info_sections): Use all_objfiles. * main.c (captured_main_1): Use all_objfiles. * spu-tdep.c (spu_objfile_from_frame): Use all_objfiles. * guile/scm-objfile.c (gdbscm_objfiles): Use all_objfiles. * guile/scm-pretty-print.c (ppscm_find_pretty_printer_from_objfiles): Use all_objfiles. * solib-spu.c (append_ocl_sos): Use all_objfiles. * symmisc.c (maintenance_print_symbols): Use all_objfiles. (maintenance_print_msymbols): Use all_objfiles. * source.c (select_source_symtab): Use all_objfiles. * jit.c (jit_find_objf_with_entry_addr): Use all_objfiles. * symfile.c (remove_symbol_file_command) (expand_symtabs_matching, map_symbol_filenames): Use all_objfiles. * ppc-linux-tdep.c (ppc_linux_spe_context_inferior_created): Use all_objfiles. * dwarf2-frame.c (dwarf2_frame_find_fde): Use all_objfiles. * objc-lang.c (find_methods): Use all_objfiles. * objfiles.c (have_partial_symbols, have_full_symbols) (have_minimal_symbols, qsort_cmp) (default_iterate_over_objfiles_in_search_order): Use all_objfiles. * hppa-tdep.c (find_unwind_entry): Use all_objfiles. * psymtab.c (maintenance_print_psymbols): Use all_objfiles. (maintenance_check_psymtabs): Use all_objfiles. (ALL_PSYMTABS): Remove. * compile/compile-object-run.c (do_module_cleanup): Use all_objfiles. * blockframe.c (find_pc_partial_function): Use all_objfiles. * cp-support.c (add_symbol_overload_list_qualified): Use all_objfiles. * windows-tdep.c (windows_iterate_over_objfiles_in_search_order): Use all_objfiles. * dwarf-index-write.c (save_gdb_index_command): Use all_objfiles. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Use all_objfiles. * python/py-objfile.c (objfpy_lookup_objfile_by_name) (objfpy_lookup_objfile_by_build_id): Use all_objfiles. * python/py-prettyprint.c (find_pretty_printer_from_objfiles): Uses all_objfiles. * solib.c (solib_read_symbols): Use all_objfiles
2018-11-23 20:20:05 +01:00
{
struct stat st;
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
Remove most uses of ALL_OBJFILES This removes most uses of ALL_OBJFILES, replacing them with ranged for loops. The remaining uses are all in macros, and will be removed in subsequent patches. gdb/ChangeLog 2019-01-09 Tom Tromey <tom@tromey.com> * symtab.c (iterate_over_symtabs, matching_obj_sections) (expand_symtab_containing_pc, lookup_static_symbol) (basic_lookup_transparent_type, find_pc_sect_compunit_symtab) (find_symbol_at_address, find_line_symtab, find_main_name): Use all_objfiles. * probe.c (find_probe_by_pc, collect_probes): Use all_objfiles. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Use all_objfiles. * linux-thread-db.c (try_thread_db_load_from_pdir) (has_libpthread): Use all_objfiles. * ada-lang.c (add_nonlocal_symbols): Use all_objfiles. * linespec.c (iterate_over_all_matching_symtabs) (search_minsyms_for_name): Use all_objfiles. * maint.c (maintenance_info_sections): Use all_objfiles. * main.c (captured_main_1): Use all_objfiles. * spu-tdep.c (spu_objfile_from_frame): Use all_objfiles. * guile/scm-objfile.c (gdbscm_objfiles): Use all_objfiles. * guile/scm-pretty-print.c (ppscm_find_pretty_printer_from_objfiles): Use all_objfiles. * solib-spu.c (append_ocl_sos): Use all_objfiles. * symmisc.c (maintenance_print_symbols): Use all_objfiles. (maintenance_print_msymbols): Use all_objfiles. * source.c (select_source_symtab): Use all_objfiles. * jit.c (jit_find_objf_with_entry_addr): Use all_objfiles. * symfile.c (remove_symbol_file_command) (expand_symtabs_matching, map_symbol_filenames): Use all_objfiles. * ppc-linux-tdep.c (ppc_linux_spe_context_inferior_created): Use all_objfiles. * dwarf2-frame.c (dwarf2_frame_find_fde): Use all_objfiles. * objc-lang.c (find_methods): Use all_objfiles. * objfiles.c (have_partial_symbols, have_full_symbols) (have_minimal_symbols, qsort_cmp) (default_iterate_over_objfiles_in_search_order): Use all_objfiles. * hppa-tdep.c (find_unwind_entry): Use all_objfiles. * psymtab.c (maintenance_print_psymbols): Use all_objfiles. (maintenance_check_psymtabs): Use all_objfiles. (ALL_PSYMTABS): Remove. * compile/compile-object-run.c (do_module_cleanup): Use all_objfiles. * blockframe.c (find_pc_partial_function): Use all_objfiles. * cp-support.c (add_symbol_overload_list_qualified): Use all_objfiles. * windows-tdep.c (windows_iterate_over_objfiles_in_search_order): Use all_objfiles. * dwarf-index-write.c (save_gdb_index_command): Use all_objfiles. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Use all_objfiles. * python/py-objfile.c (objfpy_lookup_objfile_by_name) (objfpy_lookup_objfile_by_build_id): Use all_objfiles. * python/py-prettyprint.c (find_pretty_printer_from_objfiles): Uses all_objfiles. * solib.c (solib_read_symbols): Use all_objfiles
2018-11-23 20:20:05 +01:00
/* If the objfile does not correspond to an actual file, skip it. */
if (stat (objfile_name (objfile), &st) < 0)
continue;
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
Remove most uses of ALL_OBJFILES This removes most uses of ALL_OBJFILES, replacing them with ranged for loops. The remaining uses are all in macros, and will be removed in subsequent patches. gdb/ChangeLog 2019-01-09 Tom Tromey <tom@tromey.com> * symtab.c (iterate_over_symtabs, matching_obj_sections) (expand_symtab_containing_pc, lookup_static_symbol) (basic_lookup_transparent_type, find_pc_sect_compunit_symtab) (find_symbol_at_address, find_line_symtab, find_main_name): Use all_objfiles. * probe.c (find_probe_by_pc, collect_probes): Use all_objfiles. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Use all_objfiles. * linux-thread-db.c (try_thread_db_load_from_pdir) (has_libpthread): Use all_objfiles. * ada-lang.c (add_nonlocal_symbols): Use all_objfiles. * linespec.c (iterate_over_all_matching_symtabs) (search_minsyms_for_name): Use all_objfiles. * maint.c (maintenance_info_sections): Use all_objfiles. * main.c (captured_main_1): Use all_objfiles. * spu-tdep.c (spu_objfile_from_frame): Use all_objfiles. * guile/scm-objfile.c (gdbscm_objfiles): Use all_objfiles. * guile/scm-pretty-print.c (ppscm_find_pretty_printer_from_objfiles): Use all_objfiles. * solib-spu.c (append_ocl_sos): Use all_objfiles. * symmisc.c (maintenance_print_symbols): Use all_objfiles. (maintenance_print_msymbols): Use all_objfiles. * source.c (select_source_symtab): Use all_objfiles. * jit.c (jit_find_objf_with_entry_addr): Use all_objfiles. * symfile.c (remove_symbol_file_command) (expand_symtabs_matching, map_symbol_filenames): Use all_objfiles. * ppc-linux-tdep.c (ppc_linux_spe_context_inferior_created): Use all_objfiles. * dwarf2-frame.c (dwarf2_frame_find_fde): Use all_objfiles. * objc-lang.c (find_methods): Use all_objfiles. * objfiles.c (have_partial_symbols, have_full_symbols) (have_minimal_symbols, qsort_cmp) (default_iterate_over_objfiles_in_search_order): Use all_objfiles. * hppa-tdep.c (find_unwind_entry): Use all_objfiles. * psymtab.c (maintenance_print_psymbols): Use all_objfiles. (maintenance_check_psymtabs): Use all_objfiles. (ALL_PSYMTABS): Remove. * compile/compile-object-run.c (do_module_cleanup): Use all_objfiles. * blockframe.c (find_pc_partial_function): Use all_objfiles. * cp-support.c (add_symbol_overload_list_qualified): Use all_objfiles. * windows-tdep.c (windows_iterate_over_objfiles_in_search_order): Use all_objfiles. * dwarf-index-write.c (save_gdb_index_command): Use all_objfiles. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Use all_objfiles. * python/py-objfile.c (objfpy_lookup_objfile_by_name) (objfpy_lookup_objfile_by_build_id): Use all_objfiles. * python/py-prettyprint.c (find_pretty_printer_from_objfiles): Uses all_objfiles. * solib.c (solib_read_symbols): Use all_objfiles
2018-11-23 20:20:05 +01:00
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
Remove most uses of ALL_OBJFILES This removes most uses of ALL_OBJFILES, replacing them with ranged for loops. The remaining uses are all in macros, and will be removed in subsequent patches. gdb/ChangeLog 2019-01-09 Tom Tromey <tom@tromey.com> * symtab.c (iterate_over_symtabs, matching_obj_sections) (expand_symtab_containing_pc, lookup_static_symbol) (basic_lookup_transparent_type, find_pc_sect_compunit_symtab) (find_symbol_at_address, find_line_symtab, find_main_name): Use all_objfiles. * probe.c (find_probe_by_pc, collect_probes): Use all_objfiles. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Use all_objfiles. * linux-thread-db.c (try_thread_db_load_from_pdir) (has_libpthread): Use all_objfiles. * ada-lang.c (add_nonlocal_symbols): Use all_objfiles. * linespec.c (iterate_over_all_matching_symtabs) (search_minsyms_for_name): Use all_objfiles. * maint.c (maintenance_info_sections): Use all_objfiles. * main.c (captured_main_1): Use all_objfiles. * spu-tdep.c (spu_objfile_from_frame): Use all_objfiles. * guile/scm-objfile.c (gdbscm_objfiles): Use all_objfiles. * guile/scm-pretty-print.c (ppscm_find_pretty_printer_from_objfiles): Use all_objfiles. * solib-spu.c (append_ocl_sos): Use all_objfiles. * symmisc.c (maintenance_print_symbols): Use all_objfiles. (maintenance_print_msymbols): Use all_objfiles. * source.c (select_source_symtab): Use all_objfiles. * jit.c (jit_find_objf_with_entry_addr): Use all_objfiles. * symfile.c (remove_symbol_file_command) (expand_symtabs_matching, map_symbol_filenames): Use all_objfiles. * ppc-linux-tdep.c (ppc_linux_spe_context_inferior_created): Use all_objfiles. * dwarf2-frame.c (dwarf2_frame_find_fde): Use all_objfiles. * objc-lang.c (find_methods): Use all_objfiles. * objfiles.c (have_partial_symbols, have_full_symbols) (have_minimal_symbols, qsort_cmp) (default_iterate_over_objfiles_in_search_order): Use all_objfiles. * hppa-tdep.c (find_unwind_entry): Use all_objfiles. * psymtab.c (maintenance_print_psymbols): Use all_objfiles. (maintenance_check_psymtabs): Use all_objfiles. (ALL_PSYMTABS): Remove. * compile/compile-object-run.c (do_module_cleanup): Use all_objfiles. * blockframe.c (find_pc_partial_function): Use all_objfiles. * cp-support.c (add_symbol_overload_list_qualified): Use all_objfiles. * windows-tdep.c (windows_iterate_over_objfiles_in_search_order): Use all_objfiles. * dwarf-index-write.c (save_gdb_index_command): Use all_objfiles. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Use all_objfiles. * python/py-objfile.c (objfpy_lookup_objfile_by_name) (objfpy_lookup_objfile_by_build_id): Use all_objfiles. * python/py-prettyprint.c (find_pretty_printer_from_objfiles): Uses all_objfiles. * solib.c (solib_read_symbols): Use all_objfiles
2018-11-23 20:20:05 +01:00
if (dwarf2_per_objfile != NULL)
{
TRY
{
const char *basename = lbasename (objfile_name (objfile));
write_psymtabs_to_index (dwarf2_per_objfile, arg, basename,
index_kind);
}
CATCH (except, RETURN_MASK_ERROR)
{
exception_fprintf (gdb_stderr, except,
_("Error while writing index for `%s': "),
objfile_name (objfile));
}
END_CATCH
}
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
Remove most uses of ALL_OBJFILES This removes most uses of ALL_OBJFILES, replacing them with ranged for loops. The remaining uses are all in macros, and will be removed in subsequent patches. gdb/ChangeLog 2019-01-09 Tom Tromey <tom@tromey.com> * symtab.c (iterate_over_symtabs, matching_obj_sections) (expand_symtab_containing_pc, lookup_static_symbol) (basic_lookup_transparent_type, find_pc_sect_compunit_symtab) (find_symbol_at_address, find_line_symtab, find_main_name): Use all_objfiles. * probe.c (find_probe_by_pc, collect_probes): Use all_objfiles. * breakpoint.c (create_overlay_event_breakpoint) (create_longjmp_master_breakpoint) (create_std_terminate_master_breakpoint) (create_exception_master_breakpoint): Use all_objfiles. * linux-thread-db.c (try_thread_db_load_from_pdir) (has_libpthread): Use all_objfiles. * ada-lang.c (add_nonlocal_symbols): Use all_objfiles. * linespec.c (iterate_over_all_matching_symtabs) (search_minsyms_for_name): Use all_objfiles. * maint.c (maintenance_info_sections): Use all_objfiles. * main.c (captured_main_1): Use all_objfiles. * spu-tdep.c (spu_objfile_from_frame): Use all_objfiles. * guile/scm-objfile.c (gdbscm_objfiles): Use all_objfiles. * guile/scm-pretty-print.c (ppscm_find_pretty_printer_from_objfiles): Use all_objfiles. * solib-spu.c (append_ocl_sos): Use all_objfiles. * symmisc.c (maintenance_print_symbols): Use all_objfiles. (maintenance_print_msymbols): Use all_objfiles. * source.c (select_source_symtab): Use all_objfiles. * jit.c (jit_find_objf_with_entry_addr): Use all_objfiles. * symfile.c (remove_symbol_file_command) (expand_symtabs_matching, map_symbol_filenames): Use all_objfiles. * ppc-linux-tdep.c (ppc_linux_spe_context_inferior_created): Use all_objfiles. * dwarf2-frame.c (dwarf2_frame_find_fde): Use all_objfiles. * objc-lang.c (find_methods): Use all_objfiles. * objfiles.c (have_partial_symbols, have_full_symbols) (have_minimal_symbols, qsort_cmp) (default_iterate_over_objfiles_in_search_order): Use all_objfiles. * hppa-tdep.c (find_unwind_entry): Use all_objfiles. * psymtab.c (maintenance_print_psymbols): Use all_objfiles. (maintenance_check_psymtabs): Use all_objfiles. (ALL_PSYMTABS): Remove. * compile/compile-object-run.c (do_module_cleanup): Use all_objfiles. * blockframe.c (find_pc_partial_function): Use all_objfiles. * cp-support.c (add_symbol_overload_list_qualified): Use all_objfiles. * windows-tdep.c (windows_iterate_over_objfiles_in_search_order): Use all_objfiles. * dwarf-index-write.c (save_gdb_index_command): Use all_objfiles. * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): Use all_objfiles. * python/py-objfile.c (objfpy_lookup_objfile_by_name) (objfpy_lookup_objfile_by_build_id): Use all_objfiles. * python/py-prettyprint.c (find_pretty_printer_from_objfiles): Uses all_objfiles. * solib.c (solib_read_symbols): Use all_objfiles
2018-11-23 20:20:05 +01:00
}
Move DWARF index-related things to a separate file I want to add a DWARF index-related feature (automatically produce index files when loading objfiles in GDB), but I don't want to add many hundred lines to the already too big dwarf2read.c. I thought it would be a logical split to move everything related to the DWARF index to its own file. I first tried to move everything that reads and writes DWARF indices to a separate file, but found that the "read" part is a little bit entangled with the rest of dwarf2read.c, so the line is hard to draw about where to split. The write part is quite isolated though, so I moved this part to a new file, dwarf-index-write.c. Some things are necessary to both reading and writing indices, so I placed them in dwarf-index-common.{c,h}. The idea would be to have a dwarf-index-read.c eventually that would use it too (for now that code is still in dwarf2read.c). This required moving some things to a new dwarf2read.h header, so they can be read by the code that writes the index. The patch is big in number of lines, but it's all existing code being moved around. The only changes are that some functions are not static anymore, a declaration is added in a .h file, and therefore the comment is moved there. I built-tested it with a little and big endian target. This patch is also available on the users/simark/split-dwarf2read branch. gdb/ChangeLog: * Makefile.in (COMMON_SFILES): Add dwarf-index-common.c and dwarf-index-write.c (HFILES_NO_SRCDIR): Add dwarf-index-common.h and dwarf2read.h. * dwarf-index-common.c: New file. * dwarf-index-common.h: New file. * dwarf-index-write.c: New file. * dwarf2read.c: Include dwarf2read.h and dwarf-index-common.h. (struct dwarf2_section_info): Move from here. (dwarf2_section_info_def): Likewise. (DEF_VEC_O (dwarf2_section_info_def)): Likewise. (offset_type): Likewise. (DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE): Likewise. (DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE): Likewise. (DW2_GDB_INDEX_CU_SET_VALUE): Likewise. (byte_swap): Likewise. (MAYBE_SWAP): Likewise. (dwarf2_per_cu_ptr): Likewise. (DEF_VEC_P (dwarf2_per_cu_ptr)): Likewise. (struct tu_stats): Likewise. (struct dwarf2_per_objfile): Likewise. (struct dwarf2_per_cu_data): Likewise. (struct signatured_type): Likewise. (sig_type_ptr): Likewise. (DEF_VEC_P (sig_type_ptr)): Likewise. (INDEX4_SUFFIX): Likewise. (INDEX5_SUFFIX): Likewise. (DEBUG_STR_SUFFIX): Likewise. (dwarf2_read_section): Make non-static. (mapped_index_string_hash): Move from here. (dwarf5_djb_hash): Likewise. (file_write): Likewise. (class data_buf): Likewise. (struct symtab_index_entry): Likewise. (struct mapped_symtab): Likewise. (find_slot): Likewise. (hash_expand): Likewise. (add_index_entry): Likewise. (uniquify_cu_indices): Likewise. (class c_str_view): Likewise. (class c_str_view_hasher): Likewise. (class vector_hasher): Likewise. (write_hash_table): Likewise. (psym_index_map): Likewise. (struct addrmap_index_data): Likewise. (add_address_entry): Likewise. (add_address_entry_worker): Likewise. (write_address_map): Likewise. (symbol_kind): Likewise. (write_psymbols): Likewise. (struct signatured_type_index_data): Likewise. (write_one_signatured_type): Likewise. (recursively_count_psymbols): Likewise. (recursively_write_psymbols): Likewise. (class debug_names): Likewise. (check_dwarf64_offsets): Likewise. (psyms_seen_size): Likewise. (write_gdbindex): Likewise. (write_debug_names): Likewise. (assert_file_size): Likewise. (write_psymtabs_to_index): Likewise. (save_gdb_index_command): Likewise. (_initialize_dwarf2_read): Don't register the "save gdb-index" command. * dwarf2read.h: New file.
2018-03-27 16:07:44 +02:00
}
void
_initialize_dwarf_index_write ()
{
cmd_list_element *c = add_cmd ("gdb-index", class_files,
save_gdb_index_command, _("\
Save a gdb-index file.\n\
Usage: save gdb-index [-dwarf-5] DIRECTORY\n\
\n\
No options create one file with .gdb-index extension for pre-DWARF-5\n\
compatible .gdb_index section. With -dwarf-5 creates two files with\n\
extension .debug_names and .debug_str for DWARF-5 .debug_names section."),
&save_cmdlist);
set_cmd_completer (c, filename_completer);
}