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