binutils-gdb/gdb/dwarf2read.h

486 lines
17 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 2 debugging format support for GDB.
Copyright (C) 1994-2020 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/>. */
#ifndef DWARF2READ_H
#define DWARF2READ_H
[gdb/exp] Handle DW_OP_GNU_variable_value refs to abstract dies Consider a vla variable 'a' in function f1: ... <2><1a7>: Abbrev Number: 11 (DW_TAG_variable) <1a8> DW_AT_description : a <1aa> DW_AT_abstract_origin: <0x311> ... with abstract origin 'a': ... <2><311>: Abbrev Number: 3 (DW_TAG_variable) <312> DW_AT_name : a <317> DW_AT_type : <0x325> ... and inherited abstract vla type: ... <1><325>: Abbrev Number: 9 (DW_TAG_array_type) <326> DW_AT_type : <0x33a> <2><32e>: Abbrev Number: 10 (DW_TAG_subrange_type) <32f> DW_AT_type : <0x2ea> <333> DW_AT_upper_bound : 5 byte block: fd 1b 3 0 0 (DW_OP_GNU_variable_value: <0x31b>) ... where the upper bound refers to this artificial variable D.1922 without location attribute: ... <2><31b>: Abbrev Number: 8 (DW_TAG_variable) <31c> DW_AT_description : (indirect string, offset: 0x39a): D.1922 <320> DW_AT_type : <0x2ea> <324> DW_AT_artificial : 1 ... Currently, when we execute "p sizeof (a)" in f1, the upper bound is calculated by evaluating the DW_OP_GNU_variable_value expression referring to D.1922, but since that die doesn't have a location attribute, we get: ... value has been optimized out ... However, there's also artificial variable D.4283 that is sibling of vla variable 'a', has artificial variable D.1922 as abstract origin, and has a location attribute: ... <2><1ae>: Abbrev Number: 12 (DW_TAG_variable) <1af> DW_AT_description : (indirect string, offset: 0x1f8): D.4283 <1b3> DW_AT_abstract_origin: <0x31b> <1b7> DW_AT_location : 11 byte block: 75 1 8 20 24 8 20 26 31 1c 9f (DW_OP_breg5 (rdi):1; DW_OP_const1u: 32; DW_OP_shl; DW_OP_const1u: 32; DW_OP_shra; DW_OP_lit1; DW_OP_minus; DW_OP_stack_value) ... The intended behaviour for DW_OP_GNU_variable_value is to find a die that refers to D.1922 as abstract origin, has a location attribute and is 'in scope', so the expected behaviour is: ... $1 = 6 ... The 'in scope' concept can be thought of as variable D.1922 having name attribute "D.1922", and variable D.4283 inheriting that attribute, resulting in D.4283 being declared with name "D.1922" alongside vla a in f1, and when we lookup "DW_OP_GNU_variable_value D.1922", it should work as if we try to find the value of a variable named "D.1922" on the gdb command line using "p D.1922", and we should return the value of D.4283. This patch fixes the case described above, by: - adding a field abstract_to_concrete to struct dwarf2_per_objfile, - using that field to keep track of which concrete dies are instances of an abstract die, and - using that information when getting the value DW_OP_GNU_variable_value. Build and reg-tested on x86_64-linux. 2018-09-05 Tom de Vries <tdevries@suse.de> * dwarf2loc.c (sect_variable_value): Call indirect_synthetic_pointer with resolve_abstract_p == true. (indirect_synthetic_pointer): Add resolve_abstract_p parameter, defaulting to false. Propagate resolve_abstract_p to dwarf2_fetch_die_loc_sect_off. * dwarf2loc.h (dwarf2_fetch_die_loc_sect_off): Add resolve_abstract_p parameter, defaulting to false. * dwarf2read.c (read_variable): Add variable to abstract_to_concrete. (dwarf2_fetch_die_loc_sect_off): Add and handle resolve_abstract_p parameter. * dwarf2read.h (struct die_info): Forward-declare. (die_info_ptr): New typedef. (struct dwarf2_per_objfile): Add abstract_to_concrete field. * gdb.dwarf2/varval.exp: Add test.
2018-08-24 12:01:10 +02:00
#include <unordered_map>
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 "dwarf-index-cache.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 "filename-seen-cache.h"
#include "gdb_obstack.h"
Rename common to gdbsupport This is the next patch in the ongoing series to move gdbsever to the top level. This patch just renames the "common" directory. The idea is to do this move in two parts: first rename the directory (this patch), then move the directory to the top. This approach makes the patches a bit more tractable. I chose the name "gdbsupport" for the directory. However, as this patch was largely written by sed, we could pick a new name without too much difficulty. Tested by the buildbot. gdb/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * contrib/ari/gdb_ari.sh: Change common to gdbsupport. * configure: Rebuild. * configure.ac: Change common to gdbsupport. * gdbsupport: Rename from common. * acinclude.m4: Change common to gdbsupport. * Makefile.in (CONFIG_SRC_SUBDIR, COMMON_SFILES) (HFILES_NO_SRCDIR, stamp-version, ALLDEPFILES): Change common to gdbsupport. * aarch64-tdep.c, ada-lang.c, ada-lang.h, agent.c, alloc.c, amd64-darwin-tdep.c, amd64-dicos-tdep.c, amd64-fbsd-nat.c, amd64-fbsd-tdep.c, amd64-linux-nat.c, amd64-linux-tdep.c, amd64-nbsd-tdep.c, amd64-obsd-tdep.c, amd64-sol2-tdep.c, amd64-tdep.c, amd64-windows-tdep.c, arch-utils.c, arch/aarch64-insn.c, arch/aarch64.c, arch/aarch64.h, arch/amd64.c, arch/amd64.h, arch/arm-get-next-pcs.c, arch/arm-linux.c, arch/arm.c, arch/i386.c, arch/i386.h, arch/ppc-linux-common.c, arch/riscv.c, arch/riscv.h, arch/tic6x.c, arm-tdep.c, auto-load.c, auxv.c, ax-gdb.c, ax-general.c, ax.h, breakpoint.c, breakpoint.h, btrace.c, btrace.h, build-id.c, build-id.h, c-lang.h, charset.c, charset.h, cli/cli-cmds.c, cli/cli-cmds.h, cli/cli-decode.c, cli/cli-dump.c, cli/cli-option.h, cli/cli-script.c, coff-pe-read.c, command.h, compile/compile-c-support.c, compile/compile-c.h, compile/compile-cplus-symbols.c, compile/compile-cplus-types.c, compile/compile-cplus.h, compile/compile-loc2c.c, compile/compile.c, completer.c, completer.h, contrib/ari/gdb_ari.sh, corefile.c, corelow.c, cp-support.c, cp-support.h, cp-valprint.c, csky-tdep.c, ctf.c, darwin-nat.c, debug.c, defs.h, disasm-selftests.c, disasm.c, disasm.h, dtrace-probe.c, dwarf-index-cache.c, dwarf-index-cache.h, dwarf-index-write.c, dwarf2-frame.c, dwarf2expr.c, dwarf2loc.c, dwarf2read.c, event-loop.c, event-top.c, exceptions.c, exec.c, extension.h, fbsd-nat.c, features/aarch64-core.c, features/aarch64-fpu.c, features/aarch64-pauth.c, features/aarch64-sve.c, features/i386/32bit-avx.c, features/i386/32bit-avx512.c, features/i386/32bit-core.c, features/i386/32bit-linux.c, features/i386/32bit-mpx.c, features/i386/32bit-pkeys.c, features/i386/32bit-segments.c, features/i386/32bit-sse.c, features/i386/64bit-avx.c, features/i386/64bit-avx512.c, features/i386/64bit-core.c, features/i386/64bit-linux.c, features/i386/64bit-mpx.c, features/i386/64bit-pkeys.c, features/i386/64bit-segments.c, features/i386/64bit-sse.c, features/i386/x32-core.c, features/riscv/32bit-cpu.c, features/riscv/32bit-csr.c, features/riscv/32bit-fpu.c, features/riscv/64bit-cpu.c, features/riscv/64bit-csr.c, features/riscv/64bit-fpu.c, features/tic6x-c6xp.c, features/tic6x-core.c, features/tic6x-gp.c, filename-seen-cache.h, findcmd.c, findvar.c, fork-child.c, gcore.c, gdb_bfd.c, gdb_bfd.h, gdb_proc_service.h, gdb_regex.c, gdb_select.h, gdb_usleep.c, gdbarch-selftests.c, gdbthread.h, gdbtypes.h, gnu-nat.c, go32-nat.c, guile/guile.c, guile/scm-ports.c, guile/scm-safe-call.c, guile/scm-type.c, i386-fbsd-nat.c, i386-fbsd-tdep.c, i386-go32-tdep.c, i386-linux-nat.c, i386-linux-tdep.c, i386-tdep.c, i387-tdep.c, ia64-libunwind-tdep.c, ia64-linux-nat.c, inf-child.c, inf-ptrace.c, infcall.c, infcall.h, infcmd.c, inferior-iter.h, inferior.c, inferior.h, inflow.c, inflow.h, infrun.c, infrun.h, inline-frame.c, language.h, linespec.c, linux-fork.c, linux-nat.c, linux-tdep.c, linux-thread-db.c, location.c, machoread.c, macrotab.h, main.c, maint.c, maint.h, memattr.c, memrange.h, mi/mi-cmd-break.h, mi/mi-cmd-env.c, mi/mi-cmd-stack.c, mi/mi-cmd-var.c, mi/mi-interp.c, mi/mi-main.c, mi/mi-parse.h, minsyms.c, mips-linux-tdep.c, namespace.h, nat/aarch64-linux-hw-point.c, nat/aarch64-linux-hw-point.h, nat/aarch64-linux.c, nat/aarch64-sve-linux-ptrace.c, nat/amd64-linux-siginfo.c, nat/fork-inferior.c, nat/linux-btrace.c, nat/linux-btrace.h, nat/linux-namespaces.c, nat/linux-nat.h, nat/linux-osdata.c, nat/linux-personality.c, nat/linux-procfs.c, nat/linux-ptrace.c, nat/linux-ptrace.h, nat/linux-waitpid.c, nat/mips-linux-watch.c, nat/mips-linux-watch.h, nat/ppc-linux.c, nat/x86-dregs.c, nat/x86-dregs.h, nat/x86-linux-dregs.c, nat/x86-linux.c, nto-procfs.c, nto-tdep.c, objfile-flags.h, objfiles.c, objfiles.h, obsd-nat.c, observable.h, osdata.c, p-valprint.c, parse.c, parser-defs.h, ppc-linux-nat.c, printcmd.c, probe.c, proc-api.c, procfs.c, producer.c, progspace.h, psymtab.h, python/py-framefilter.c, python/py-inferior.c, python/py-ref.h, python/py-type.c, python/python.c, record-btrace.c, record-full.c, record.c, record.h, regcache-dump.c, regcache.c, regcache.h, remote-fileio.c, remote-fileio.h, remote-sim.c, remote.c, riscv-tdep.c, rs6000-aix-tdep.c, rust-exp.y, s12z-tdep.c, selftest-arch.c, ser-base.c, ser-event.c, ser-pipe.c, ser-tcp.c, ser-unix.c, skip.c, solib-aix.c, solib-target.c, solib.c, source-cache.c, source.c, source.h, sparc-nat.c, spu-linux-nat.c, stack.c, stap-probe.c, symfile-add-flags.h, symfile.c, symfile.h, symtab.c, symtab.h, target-descriptions.c, target-descriptions.h, target-memory.c, target.c, target.h, target/waitstatus.c, target/waitstatus.h, thread-iter.h, thread.c, tilegx-tdep.c, top.c, top.h, tracefile-tfile.c, tracefile.c, tracepoint.c, tracepoint.h, tui/tui-io.c, ui-file.c, ui-out.h, unittests/array-view-selftests.c, unittests/child-path-selftests.c, unittests/cli-utils-selftests.c, unittests/common-utils-selftests.c, unittests/copy_bitwise-selftests.c, unittests/environ-selftests.c, unittests/format_pieces-selftests.c, unittests/function-view-selftests.c, unittests/lookup_name_info-selftests.c, unittests/memory-map-selftests.c, unittests/memrange-selftests.c, unittests/mkdir-recursive-selftests.c, unittests/observable-selftests.c, unittests/offset-type-selftests.c, unittests/optional-selftests.c, unittests/parse-connection-spec-selftests.c, unittests/ptid-selftests.c, unittests/rsp-low-selftests.c, unittests/scoped_fd-selftests.c, unittests/scoped_mmap-selftests.c, unittests/scoped_restore-selftests.c, unittests/string_view-selftests.c, unittests/style-selftests.c, unittests/tracepoint-selftests.c, unittests/unpack-selftests.c, unittests/utils-selftests.c, unittests/xml-utils-selftests.c, utils.c, utils.h, valarith.c, valops.c, valprint.c, value.c, value.h, varobj.c, varobj.h, windows-nat.c, x86-linux-nat.c, xml-support.c, xml-support.h, xml-tdesc.h, xstormy16-tdep.c, xtensa-linux-nat.c, dwarf2read.h: Change common to gdbsupport. gdb/gdbserver/ChangeLog 2019-07-09 Tom Tromey <tom@tromey.com> * configure: Rebuild. * configure.ac: Change common to gdbsupport. * acinclude.m4: Change common to gdbsupport. * Makefile.in (SFILES, OBS, GDBREPLAY_OBS, IPA_OBJS) (version-generated.c, gdbsupport/%-ipa.o, gdbsupport/%.o): Change common to gdbsupport. * ax.c, event-loop.c, fork-child.c, gdb_proc_service.h, gdbreplay.c, gdbthread.h, hostio-errno.c, hostio.c, i387-fp.c, inferiors.c, inferiors.h, linux-aarch64-tdesc-selftest.c, linux-amd64-ipa.c, linux-i386-ipa.c, linux-low.c, linux-tic6x-low.c, linux-x86-low.c, linux-x86-tdesc-selftest.c, linux-x86-tdesc.c, lynx-i386-low.c, lynx-low.c, mem-break.h, nto-x86-low.c, regcache.c, regcache.h, remote-utils.c, server.c, server.h, spu-low.c, symbol.c, target.h, tdesc.c, tdesc.h, thread-db.c, tracepoint.c, win32-i386-low.c, win32-low.c: Change common to gdbsupport.
2019-05-06 04:29:24 +02:00
#include "gdbsupport/hash_enum.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
gdb: Add switch to disable DWARF stack unwinders Add a maintenance command to disable the DWARF stack unwinders. Normal users would not need this feature, but it is useful to allow extended testing of fallback stack unwinding strategies, for example, prologue scanners. This is a partial implementation of the idea discussed in pr gdb/8434, which talks about a generic ability to disable any frame unwinder. Being able to arbitrarily disable any frame unwinder would be a more complex patch, and I was unsure how useful such a feature would really be, however, I can see (and have) a real need to disable DWARF unwinders. That's why this patch only targets that specific set of unwinders. If in the future we find ourselves adding more switches to disable different unwinders, then we should probably move to a more generic solution, and remove this patch. gdb/ChangeLog: * dwarf2-frame-tailcall.c (tailcall_frame_sniffer): Exit early if DWARF unwinders are disabled. * dwarf2-frame.c: Add dwarf2read.h include. (dwarf2_frame_sniffer): Exit early if DWARF unwinders are disabled. (dwarf2_frame_unwinders_enabled_p): Define. (show_dwarf_unwinders_enabled_p): New function. (_initialize_dwarf2_frame): Register switch to control DWARF unwinder use. * dwarf2-frame.h (dwarf2_frame_unwinders_enabled_p): Declare. * dwarf2read.c (set_dwarf_cmdlist): Remove static keyword. (show_dwarf_cmdlist): Remove static keyword. * dwarf2read.h (set_dwarf_cmdlist): Declare. (show_dwarf_cmdlist): Declare. * NEWS: Document new feature. gdb/doc/ChangeLog: * gdb.texinfo (Maintenance Commands): Add description of maintenance command to control dwarf unwinders. gdb/testsuite/ChangeLog: * gdb.base/maint.exp: Add check that dwarf unwinders control flag is visible.
2018-07-13 13:01:16 +02:00
/* Hold 'maintenance (set|show) dwarf' commands. */
extern struct cmd_list_element *set_dwarf_cmdlist;
extern struct cmd_list_element *show_dwarf_cmdlist;
extern bool dwarf_always_disassemble;
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
/* A descriptor for dwarf sections.
S.ASECTION, SIZE are typically initialized when the objfile is first
scanned. BUFFER, READIN are filled in later when the section is read.
If the section contained compressed data then SIZE is updated to record
the uncompressed size of the section.
DWP file format V2 introduces a wrinkle that is easiest to handle by
creating the concept of virtual sections contained within a real section.
In DWP V2 the sections of the input DWO files are concatenated together
into one section, but section offsets are kept relative to the original
input section.
If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
the real section this "virtual" section is contained in, and BUFFER,SIZE
describe the virtual section. */
struct dwarf2_section_info
{
union
{
/* If this is a real section, the bfd section. */
asection *section;
/* If this is a virtual section, pointer to the containing ("real")
section. */
struct dwarf2_section_info *containing_section;
} s;
/* Pointer to section data, only valid if readin. */
const gdb_byte *buffer;
/* The size of the section, real or virtual. */
bfd_size_type size;
/* If this is a virtual section, the offset in the real section.
Only valid if is_virtual. */
bfd_size_type virtual_offset;
/* True if we have tried to read this section. */
bool readin;
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
/* True if this is a virtual section, False otherwise.
This specifies which of s.section and s.containing_section to use. */
bool is_virtual;
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
};
/* Read the contents of the section INFO.
OBJFILE is the main object file, but not necessarily the file where
the section comes from. E.g., for DWO files the bfd of INFO is the bfd
of the DWO file.
If the section is compressed, uncompress it before returning. */
void dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info);
struct tu_stats
{
int nr_uniq_abbrev_tables;
int nr_symtabs;
int nr_symtab_sharers;
int nr_stmt_less_type_units;
int nr_all_type_units_reallocs;
};
struct dwarf2_debug_sections;
struct mapped_index;
struct mapped_debug_names;
struct signatured_type;
[gdb/exp] Handle DW_OP_GNU_variable_value refs to abstract dies Consider a vla variable 'a' in function f1: ... <2><1a7>: Abbrev Number: 11 (DW_TAG_variable) <1a8> DW_AT_description : a <1aa> DW_AT_abstract_origin: <0x311> ... with abstract origin 'a': ... <2><311>: Abbrev Number: 3 (DW_TAG_variable) <312> DW_AT_name : a <317> DW_AT_type : <0x325> ... and inherited abstract vla type: ... <1><325>: Abbrev Number: 9 (DW_TAG_array_type) <326> DW_AT_type : <0x33a> <2><32e>: Abbrev Number: 10 (DW_TAG_subrange_type) <32f> DW_AT_type : <0x2ea> <333> DW_AT_upper_bound : 5 byte block: fd 1b 3 0 0 (DW_OP_GNU_variable_value: <0x31b>) ... where the upper bound refers to this artificial variable D.1922 without location attribute: ... <2><31b>: Abbrev Number: 8 (DW_TAG_variable) <31c> DW_AT_description : (indirect string, offset: 0x39a): D.1922 <320> DW_AT_type : <0x2ea> <324> DW_AT_artificial : 1 ... Currently, when we execute "p sizeof (a)" in f1, the upper bound is calculated by evaluating the DW_OP_GNU_variable_value expression referring to D.1922, but since that die doesn't have a location attribute, we get: ... value has been optimized out ... However, there's also artificial variable D.4283 that is sibling of vla variable 'a', has artificial variable D.1922 as abstract origin, and has a location attribute: ... <2><1ae>: Abbrev Number: 12 (DW_TAG_variable) <1af> DW_AT_description : (indirect string, offset: 0x1f8): D.4283 <1b3> DW_AT_abstract_origin: <0x31b> <1b7> DW_AT_location : 11 byte block: 75 1 8 20 24 8 20 26 31 1c 9f (DW_OP_breg5 (rdi):1; DW_OP_const1u: 32; DW_OP_shl; DW_OP_const1u: 32; DW_OP_shra; DW_OP_lit1; DW_OP_minus; DW_OP_stack_value) ... The intended behaviour for DW_OP_GNU_variable_value is to find a die that refers to D.1922 as abstract origin, has a location attribute and is 'in scope', so the expected behaviour is: ... $1 = 6 ... The 'in scope' concept can be thought of as variable D.1922 having name attribute "D.1922", and variable D.4283 inheriting that attribute, resulting in D.4283 being declared with name "D.1922" alongside vla a in f1, and when we lookup "DW_OP_GNU_variable_value D.1922", it should work as if we try to find the value of a variable named "D.1922" on the gdb command line using "p D.1922", and we should return the value of D.4283. This patch fixes the case described above, by: - adding a field abstract_to_concrete to struct dwarf2_per_objfile, - using that field to keep track of which concrete dies are instances of an abstract die, and - using that information when getting the value DW_OP_GNU_variable_value. Build and reg-tested on x86_64-linux. 2018-09-05 Tom de Vries <tdevries@suse.de> * dwarf2loc.c (sect_variable_value): Call indirect_synthetic_pointer with resolve_abstract_p == true. (indirect_synthetic_pointer): Add resolve_abstract_p parameter, defaulting to false. Propagate resolve_abstract_p to dwarf2_fetch_die_loc_sect_off. * dwarf2loc.h (dwarf2_fetch_die_loc_sect_off): Add resolve_abstract_p parameter, defaulting to false. * dwarf2read.c (read_variable): Add variable to abstract_to_concrete. (dwarf2_fetch_die_loc_sect_off): Add and handle resolve_abstract_p parameter. * dwarf2read.h (struct die_info): Forward-declare. (die_info_ptr): New typedef. (struct dwarf2_per_objfile): Add abstract_to_concrete field. * gdb.dwarf2/varval.exp: Add test.
2018-08-24 12:01:10 +02:00
struct die_info;
typedef struct die_info *die_info_ptr;
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
/* Collection of data recorded per objfile.
This hangs off of dwarf2_objfile_data_key. */
struct dwarf2_per_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
{
/* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
dwarf2 section names, or is NULL if the standard ELF names are
Handle copy relocations In ELF, if a data symbol is defined in a shared library and used by the main program, it will be subject to a "copy relocation". In this scenario, the main program has a copy of the symbol in question, and a relocation that tells ld.so to copy the data from the shared library. Then the symbol in the main program is used to satisfy all references. This patch changes gdb to handle this scenario. Data symbols coming from ELF shared libraries get a special flag that indicates that the symbol's address may be subject to copy relocation. I looked briefly into handling copy relocations by looking at the actual relocations in the main program, but this seemed difficult to do with BFD. Note that no caching is done here. Perhaps this could be changed if need be; I wanted to avoid possible problems with either objfile lifetimes and changes, or conflicts with the long-term (vapor-ware) objfile splitting project. gdb/ChangeLog 2019-10-02 Tom Tromey <tromey@adacore.com> * symmisc.c (dump_msymbols): Don't use MSYMBOL_VALUE_ADDRESS. * ada-lang.c (lesseq_defined_than): Handle LOC_STATIC. * dwarf2read.c (dwarf2_per_objfile): Add can_copy parameter. (dwarf2_has_info): Likewise. (new_symbol): Set maybe_copied on symbol when appropriate. * dwarf2read.h (dwarf2_per_objfile): Add can_copy parameter. <can_copy>: New member. * elfread.c (record_minimal_symbol): Set maybe_copied on symbol when appropriate. (elf_symfile_read): Update call to dwarf2_has_info. * minsyms.c (lookup_minimal_symbol_linkage): New function. * minsyms.h (lookup_minimal_symbol_linkage): Declare. * symtab.c (get_symbol_address, get_msymbol_address): New functions. * symtab.h (get_symbol_address, get_msymbol_address): Declare. (SYMBOL_VALUE_ADDRESS, MSYMBOL_VALUE_ADDRESS): Handle maybe_copied. (struct symbol, struct minimal_symbol) <maybe_copied>: New member.
2019-06-25 20:50:45 +02:00
used. CAN_COPY is true for formats where symbol
interposition is possible and so symbol values must follow copy
relocation rules. */
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
dwarf2_per_objfile (struct objfile *objfile,
Handle copy relocations In ELF, if a data symbol is defined in a shared library and used by the main program, it will be subject to a "copy relocation". In this scenario, the main program has a copy of the symbol in question, and a relocation that tells ld.so to copy the data from the shared library. Then the symbol in the main program is used to satisfy all references. This patch changes gdb to handle this scenario. Data symbols coming from ELF shared libraries get a special flag that indicates that the symbol's address may be subject to copy relocation. I looked briefly into handling copy relocations by looking at the actual relocations in the main program, but this seemed difficult to do with BFD. Note that no caching is done here. Perhaps this could be changed if need be; I wanted to avoid possible problems with either objfile lifetimes and changes, or conflicts with the long-term (vapor-ware) objfile splitting project. gdb/ChangeLog 2019-10-02 Tom Tromey <tromey@adacore.com> * symmisc.c (dump_msymbols): Don't use MSYMBOL_VALUE_ADDRESS. * ada-lang.c (lesseq_defined_than): Handle LOC_STATIC. * dwarf2read.c (dwarf2_per_objfile): Add can_copy parameter. (dwarf2_has_info): Likewise. (new_symbol): Set maybe_copied on symbol when appropriate. * dwarf2read.h (dwarf2_per_objfile): Add can_copy parameter. <can_copy>: New member. * elfread.c (record_minimal_symbol): Set maybe_copied on symbol when appropriate. (elf_symfile_read): Update call to dwarf2_has_info. * minsyms.c (lookup_minimal_symbol_linkage): New function. * minsyms.h (lookup_minimal_symbol_linkage): Declare. * symtab.c (get_symbol_address, get_msymbol_address): New functions. * symtab.h (get_symbol_address, get_msymbol_address): Declare. (SYMBOL_VALUE_ADDRESS, MSYMBOL_VALUE_ADDRESS): Handle maybe_copied. (struct symbol, struct minimal_symbol) <maybe_copied>: New member.
2019-06-25 20:50:45 +02:00
const dwarf2_debug_sections *names,
bool can_copy);
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
~dwarf2_per_objfile ();
DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile);
/* Return the CU/TU given its index.
This is intended for loops like:
for (i = 0; i < (dwarf2_per_objfile->n_comp_units
+ dwarf2_per_objfile->n_type_units); ++i)
{
dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i);
...;
}
*/
dwarf2_per_cu_data *get_cutu (int index);
/* Return the CU given its index.
This differs from get_cutu in that it's for when you know INDEX refers to a
CU. */
dwarf2_per_cu_data *get_cu (int index);
/* Return the TU given its index.
This differs from get_cutu in that it's for when you know INDEX refers to a
TU. */
signatured_type *get_tu (int index);
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
/* Free all cached compilation units. */
void free_cached_comp_units ();
private:
/* This function is mapped across the sections and remembers the
offset and size of each of the debugging sections we are
interested in. */
void locate_sections (bfd *abfd, asection *sectp,
const dwarf2_debug_sections &names);
public:
dwarf2_section_info info {};
dwarf2_section_info abbrev {};
dwarf2_section_info line {};
dwarf2_section_info loc {};
dwarf2_section_info loclists {};
dwarf2_section_info macinfo {};
dwarf2_section_info macro {};
dwarf2_section_info str {};
2019-12-24 04:31:24 +01:00
dwarf2_section_info str_offsets {};
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
dwarf2_section_info line_str {};
dwarf2_section_info ranges {};
dwarf2_section_info rnglists {};
dwarf2_section_info addr {};
dwarf2_section_info frame {};
dwarf2_section_info eh_frame {};
dwarf2_section_info gdb_index {};
dwarf2_section_info debug_names {};
dwarf2_section_info debug_aranges {};
std::vector<dwarf2_section_info> types;
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
/* Back link. */
struct objfile *objfile = NULL;
/* Table of all the compilation units. This is used to locate
the target compilation unit of a particular reference. */
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
std::vector<dwarf2_per_cu_data *> 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
/* The .debug_types-related CUs (TUs). */
std::vector<signatured_type *> 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
/* Table of struct type_unit_group objects.
The hash key is the DW_AT_stmt_list value. */
htab_t type_unit_groups {};
/* A table mapping .debug_types signatures to its signatured_type entry.
This is NULL if the .debug_types section hasn't been read in yet. */
htab_t signatured_types {};
/* Type unit statistics, to see how well the scaling improvements
are doing. */
struct tu_stats tu_stats {};
/* A chain of compilation units that are currently read in, so that
they can be freed later. */
dwarf2_per_cu_data *read_in_chain = NULL;
/* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
This is NULL if the table hasn't been allocated yet. */
htab_up dwo_files;
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
/* True if we've checked for whether there is a DWP file. */
bool dwp_checked = false;
/* The DWP file if there is one, or NULL. */
std::unique_ptr<struct dwp_file> dwp_file;
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 shared '.dwz' file, if one exists. This is used when the
original data was compressed using 'dwz -m'. */
std::unique_ptr<struct dwz_file> dwz_file;
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
Handle copy relocations In ELF, if a data symbol is defined in a shared library and used by the main program, it will be subject to a "copy relocation". In this scenario, the main program has a copy of the symbol in question, and a relocation that tells ld.so to copy the data from the shared library. Then the symbol in the main program is used to satisfy all references. This patch changes gdb to handle this scenario. Data symbols coming from ELF shared libraries get a special flag that indicates that the symbol's address may be subject to copy relocation. I looked briefly into handling copy relocations by looking at the actual relocations in the main program, but this seemed difficult to do with BFD. Note that no caching is done here. Perhaps this could be changed if need be; I wanted to avoid possible problems with either objfile lifetimes and changes, or conflicts with the long-term (vapor-ware) objfile splitting project. gdb/ChangeLog 2019-10-02 Tom Tromey <tromey@adacore.com> * symmisc.c (dump_msymbols): Don't use MSYMBOL_VALUE_ADDRESS. * ada-lang.c (lesseq_defined_than): Handle LOC_STATIC. * dwarf2read.c (dwarf2_per_objfile): Add can_copy parameter. (dwarf2_has_info): Likewise. (new_symbol): Set maybe_copied on symbol when appropriate. * dwarf2read.h (dwarf2_per_objfile): Add can_copy parameter. <can_copy>: New member. * elfread.c (record_minimal_symbol): Set maybe_copied on symbol when appropriate. (elf_symfile_read): Update call to dwarf2_has_info. * minsyms.c (lookup_minimal_symbol_linkage): New function. * minsyms.h (lookup_minimal_symbol_linkage): Declare. * symtab.c (get_symbol_address, get_msymbol_address): New functions. * symtab.h (get_symbol_address, get_msymbol_address): Declare. (SYMBOL_VALUE_ADDRESS, MSYMBOL_VALUE_ADDRESS): Handle maybe_copied. (struct symbol, struct minimal_symbol) <maybe_copied>: New member.
2019-06-25 20:50:45 +02:00
/* Whether copy relocations are supported by this object format. */
bool can_copy;
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
/* A flag indicating whether this objfile has a section loaded at a
VMA of 0. */
bool has_section_at_zero = false;
/* True if we are using the mapped index,
or we are faking it for OBJF_READNOW's sake. */
bool using_index = false;
/* The mapped index, or NULL if .gdb_index is missing or not being used. */
std::unique_ptr<mapped_index> index_table;
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 mapped index, or NULL if .debug_names is missing or not being used. */
std::unique_ptr<mapped_debug_names> debug_names_table;
/* When using index_table, this keeps track of all quick_file_names entries.
TUs typically share line table entries with a CU, so we maintain a
separate table of all line table entries to support the sharing.
Note that while there can be way more TUs than CUs, we've already
sorted all the TUs into "type unit groups", grouped by their
DW_AT_stmt_list value. Therefore the only sharing done here is with a
CU and its associated TU group if there is one. */
htab_t quick_file_names_table {};
/* Set during partial symbol reading, to prevent queueing of full
symbols. */
bool reading_partial_symbols = false;
/* Table mapping type DIEs to their struct type *.
This is NULL if not allocated yet.
The mapping is done via (CU/TU + DIE offset) -> type. */
htab_t die_type_hash {};
/* The CUs we recently read. */
std::vector<dwarf2_per_cu_data *> just_read_cus;
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
/* Table containing line_header indexed by offset and offset_in_dwz. */
htab_t line_header_hash {};
/* Table containing all filenames. This is an optional because the
table is lazily constructed on first access. */
gdb::optional<filename_seen_cache> filenames_cache;
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 we loaded the index from an external file, this contains the
resources associated to the open file, memory mapping, etc. */
std::unique_ptr<index_cache_resource> index_cache_res;
[gdb/exp] Handle DW_OP_GNU_variable_value refs to abstract dies Consider a vla variable 'a' in function f1: ... <2><1a7>: Abbrev Number: 11 (DW_TAG_variable) <1a8> DW_AT_description : a <1aa> DW_AT_abstract_origin: <0x311> ... with abstract origin 'a': ... <2><311>: Abbrev Number: 3 (DW_TAG_variable) <312> DW_AT_name : a <317> DW_AT_type : <0x325> ... and inherited abstract vla type: ... <1><325>: Abbrev Number: 9 (DW_TAG_array_type) <326> DW_AT_type : <0x33a> <2><32e>: Abbrev Number: 10 (DW_TAG_subrange_type) <32f> DW_AT_type : <0x2ea> <333> DW_AT_upper_bound : 5 byte block: fd 1b 3 0 0 (DW_OP_GNU_variable_value: <0x31b>) ... where the upper bound refers to this artificial variable D.1922 without location attribute: ... <2><31b>: Abbrev Number: 8 (DW_TAG_variable) <31c> DW_AT_description : (indirect string, offset: 0x39a): D.1922 <320> DW_AT_type : <0x2ea> <324> DW_AT_artificial : 1 ... Currently, when we execute "p sizeof (a)" in f1, the upper bound is calculated by evaluating the DW_OP_GNU_variable_value expression referring to D.1922, but since that die doesn't have a location attribute, we get: ... value has been optimized out ... However, there's also artificial variable D.4283 that is sibling of vla variable 'a', has artificial variable D.1922 as abstract origin, and has a location attribute: ... <2><1ae>: Abbrev Number: 12 (DW_TAG_variable) <1af> DW_AT_description : (indirect string, offset: 0x1f8): D.4283 <1b3> DW_AT_abstract_origin: <0x31b> <1b7> DW_AT_location : 11 byte block: 75 1 8 20 24 8 20 26 31 1c 9f (DW_OP_breg5 (rdi):1; DW_OP_const1u: 32; DW_OP_shl; DW_OP_const1u: 32; DW_OP_shra; DW_OP_lit1; DW_OP_minus; DW_OP_stack_value) ... The intended behaviour for DW_OP_GNU_variable_value is to find a die that refers to D.1922 as abstract origin, has a location attribute and is 'in scope', so the expected behaviour is: ... $1 = 6 ... The 'in scope' concept can be thought of as variable D.1922 having name attribute "D.1922", and variable D.4283 inheriting that attribute, resulting in D.4283 being declared with name "D.1922" alongside vla a in f1, and when we lookup "DW_OP_GNU_variable_value D.1922", it should work as if we try to find the value of a variable named "D.1922" on the gdb command line using "p D.1922", and we should return the value of D.4283. This patch fixes the case described above, by: - adding a field abstract_to_concrete to struct dwarf2_per_objfile, - using that field to keep track of which concrete dies are instances of an abstract die, and - using that information when getting the value DW_OP_GNU_variable_value. Build and reg-tested on x86_64-linux. 2018-09-05 Tom de Vries <tdevries@suse.de> * dwarf2loc.c (sect_variable_value): Call indirect_synthetic_pointer with resolve_abstract_p == true. (indirect_synthetic_pointer): Add resolve_abstract_p parameter, defaulting to false. Propagate resolve_abstract_p to dwarf2_fetch_die_loc_sect_off. * dwarf2loc.h (dwarf2_fetch_die_loc_sect_off): Add resolve_abstract_p parameter, defaulting to false. * dwarf2read.c (read_variable): Add variable to abstract_to_concrete. (dwarf2_fetch_die_loc_sect_off): Add and handle resolve_abstract_p parameter. * dwarf2read.h (struct die_info): Forward-declare. (die_info_ptr): New typedef. (struct dwarf2_per_objfile): Add abstract_to_concrete field. * gdb.dwarf2/varval.exp: Add test.
2018-08-24 12:01:10 +02:00
/* Mapping from abstract origin DIE to concrete DIEs that reference it as
DW_AT_abstract_origin. */
std::unordered_map<sect_offset, std::vector<sect_offset>,
gdb::hash_enum<sect_offset>>
[gdb/exp] Handle DW_OP_GNU_variable_value refs to abstract dies Consider a vla variable 'a' in function f1: ... <2><1a7>: Abbrev Number: 11 (DW_TAG_variable) <1a8> DW_AT_description : a <1aa> DW_AT_abstract_origin: <0x311> ... with abstract origin 'a': ... <2><311>: Abbrev Number: 3 (DW_TAG_variable) <312> DW_AT_name : a <317> DW_AT_type : <0x325> ... and inherited abstract vla type: ... <1><325>: Abbrev Number: 9 (DW_TAG_array_type) <326> DW_AT_type : <0x33a> <2><32e>: Abbrev Number: 10 (DW_TAG_subrange_type) <32f> DW_AT_type : <0x2ea> <333> DW_AT_upper_bound : 5 byte block: fd 1b 3 0 0 (DW_OP_GNU_variable_value: <0x31b>) ... where the upper bound refers to this artificial variable D.1922 without location attribute: ... <2><31b>: Abbrev Number: 8 (DW_TAG_variable) <31c> DW_AT_description : (indirect string, offset: 0x39a): D.1922 <320> DW_AT_type : <0x2ea> <324> DW_AT_artificial : 1 ... Currently, when we execute "p sizeof (a)" in f1, the upper bound is calculated by evaluating the DW_OP_GNU_variable_value expression referring to D.1922, but since that die doesn't have a location attribute, we get: ... value has been optimized out ... However, there's also artificial variable D.4283 that is sibling of vla variable 'a', has artificial variable D.1922 as abstract origin, and has a location attribute: ... <2><1ae>: Abbrev Number: 12 (DW_TAG_variable) <1af> DW_AT_description : (indirect string, offset: 0x1f8): D.4283 <1b3> DW_AT_abstract_origin: <0x31b> <1b7> DW_AT_location : 11 byte block: 75 1 8 20 24 8 20 26 31 1c 9f (DW_OP_breg5 (rdi):1; DW_OP_const1u: 32; DW_OP_shl; DW_OP_const1u: 32; DW_OP_shra; DW_OP_lit1; DW_OP_minus; DW_OP_stack_value) ... The intended behaviour for DW_OP_GNU_variable_value is to find a die that refers to D.1922 as abstract origin, has a location attribute and is 'in scope', so the expected behaviour is: ... $1 = 6 ... The 'in scope' concept can be thought of as variable D.1922 having name attribute "D.1922", and variable D.4283 inheriting that attribute, resulting in D.4283 being declared with name "D.1922" alongside vla a in f1, and when we lookup "DW_OP_GNU_variable_value D.1922", it should work as if we try to find the value of a variable named "D.1922" on the gdb command line using "p D.1922", and we should return the value of D.4283. This patch fixes the case described above, by: - adding a field abstract_to_concrete to struct dwarf2_per_objfile, - using that field to keep track of which concrete dies are instances of an abstract die, and - using that information when getting the value DW_OP_GNU_variable_value. Build and reg-tested on x86_64-linux. 2018-09-05 Tom de Vries <tdevries@suse.de> * dwarf2loc.c (sect_variable_value): Call indirect_synthetic_pointer with resolve_abstract_p == true. (indirect_synthetic_pointer): Add resolve_abstract_p parameter, defaulting to false. Propagate resolve_abstract_p to dwarf2_fetch_die_loc_sect_off. * dwarf2loc.h (dwarf2_fetch_die_loc_sect_off): Add resolve_abstract_p parameter, defaulting to false. * dwarf2read.c (read_variable): Add variable to abstract_to_concrete. (dwarf2_fetch_die_loc_sect_off): Add and handle resolve_abstract_p parameter. * dwarf2read.h (struct die_info): Forward-declare. (die_info_ptr): New typedef. (struct dwarf2_per_objfile): Add abstract_to_concrete field. * gdb.dwarf2/varval.exp: Add test.
2018-08-24 12:01:10 +02:00
abstract_to_concrete;
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
};
/* Get the dwarf2_per_objfile associated to OBJFILE. */
dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile);
/* Persistent data held for a compilation unit, even when not
processing it. We put a pointer to this structure in the
read_symtab_private field of the psymtab. */
struct dwarf2_per_cu_data
{
/* The start offset and length of this compilation unit.
NOTE: Unlike comp_unit_head.length, this length includes
initial_length_size.
If the DIE refers to a DWO file, this is always of the original die,
not the DWO file. */
sect_offset sect_off;
unsigned int length;
/* DWARF standard version this data has been read from (such as 4 or 5). */
short dwarf_version;
/* Flag indicating this compilation unit will be read in before
any of the current compilation units are processed. */
unsigned int queued : 1;
/* This flag will be set when reading partial DIEs if we need to load
absolutely all DIEs for this compilation unit, instead of just the ones
we think are interesting. It gets set if we look for a DIE in the
hash table and don't find it. */
unsigned int load_all_dies : 1;
/* Non-zero if this CU is from .debug_types.
Struct dwarf2_per_cu_data is contained in struct signatured_type iff
this is non-zero. */
unsigned int is_debug_types : 1;
/* Non-zero if this CU is from the .dwz file. */
unsigned int is_dwz : 1;
/* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
This flag is only valid if is_debug_types is true.
We can't read a CU directly from a DWO file: There are required
attributes in the stub. */
unsigned int reading_dwo_directly : 1;
/* Non-zero if the TU has been read.
This is used to assist the "Stay in DWO Optimization" for Fission:
When reading a DWO, it's faster to read TUs from the DWO instead of
fetching them from random other DWOs (due to comdat folding).
If the TU has already been read, the optimization is unnecessary
(and unwise - we don't want to change where gdb thinks the TU lives
"midflight").
This flag is only valid if is_debug_types is true. */
unsigned int tu_read : 1;
/* The section this CU/TU lives in.
If the DIE refers to a DWO file, this is always the original die,
not the DWO file. */
struct dwarf2_section_info *section;
/* Set to non-NULL iff this CU is currently loaded. When it gets freed out
of the CU cache it gets reset to NULL again. This is left as NULL for
dummy CUs (a CU header, but nothing else). */
struct dwarf2_cu *cu;
/* The corresponding dwarf2_per_objfile. */
struct dwarf2_per_objfile *dwarf2_per_objfile;
/* When dwarf2_per_objfile->using_index is true, the 'quick' field
is active. Otherwise, the 'psymtab' field is active. */
union
{
/* The partial symbol table associated with this compilation unit,
or NULL for unread partial units. */
struct partial_symtab *psymtab;
/* Data needed by the "quick" functions. */
struct dwarf2_per_cu_quick_data *quick;
} v;
gdb: Remove use of VEC from dwarf2read.c This removes a use of VEC from GDB, from dwarf2read.c. This removal is not very clean, and would probably benefit from additional refactoring in the future. The problem here is that the VEC is contained within struct dwarf2_per_cu_data, which is treated as POD in dwarf2read.c. As such it is actually a VEC pointer. When converting this to a std::vector in an ideal world we would not use a std::vector pointer, and use the std::vector directly. Sadly, to do that would require some rewriting in dwarf2read.c - my concern would be introducing bugs during this rewrite. If we move to a std::vector pointer then we need to take care to handle the case where the pointer is null. The old VEC library would handle null for us, making the VEC interface very clean. With std::vector we need to handle the null pointer case ourselves. The achieve this then I've added a small number of function that wrap up access to the std::vector, hopefully hiding the null pointer management. The final ugliness with this conversion is that, ideally, when wrapping a data member behind an interface I would make the data member private, however, treating the structure as POD once again prevents this, so we are left with the data member being public, but access (ideally) being through the published interface functions. There should be no user visible changes after this commit. gdb/ChangeLog: * gdb/dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Update for new std::vector based implementation. (process_psymtab_comp_unit_reader): Likewise. (scan_partial_symbols): Likewise. (recursively_compute_inclusions): Likewise. (compute_compunit_symtab_includes): Likewise. (process_imported_unit_die): Likewise. (queue_and_load_dwo_tu): Likewise. (follow_die_sig_1): Likewise. * gdb/dwarf2read.h: Remove DEF_VEC_P. (typedef dwarf2_per_cu_ptr): Remove. (struct dwarf2_per_cu_data) <imported_symtabs_empty>: New function. (struct dwarf2_per_cu_data) <imported_symtabs_push>: New function. (struct dwarf2_per_cu_data) <imported_symtabs_size>: New function. (struct dwarf2_per_cu_data) <imported_symtabs_free>: New function. (struct dwarf2_per_cu_data) <imported_symtabs>: Change to std::vector. Change-Id: Id0f4bda977c9dd83b0ba3d7fb42f7e5e2b6869c8
2019-10-02 16:38:51 +02:00
/* Return true of IMPORTED_SYMTABS is empty or not yet allocated. */
bool imported_symtabs_empty () const
{
return (imported_symtabs == nullptr || imported_symtabs->empty ());
}
/* Push P to the back of IMPORTED_SYMTABS, allocated IMPORTED_SYMTABS
first if required. */
void imported_symtabs_push (dwarf2_per_cu_data *p)
{
if (imported_symtabs == nullptr)
imported_symtabs = new std::vector <dwarf2_per_cu_data *>;
imported_symtabs->push_back (p);
}
/* Return the size of IMPORTED_SYMTABS if it is allocated, otherwise
return 0. */
size_t imported_symtabs_size () const
{
if (imported_symtabs == nullptr)
return 0;
return imported_symtabs->size ();
}
/* Delete IMPORTED_SYMTABS and set the pointer back to nullptr. */
void imported_symtabs_free ()
{
delete imported_symtabs;
imported_symtabs = nullptr;
}
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 CUs we import using DW_TAG_imported_unit. This is filled in
while reading psymtabs, used to compute the psymtab dependencies,
and then cleared. Then it is filled in again while reading full
symbols, and only deleted when the objfile is destroyed.
This is also used to work around a difference between the way gold
generates .gdb_index version <=7 and the way gdb does. Arguably this
is a gold bug. For symbols coming from TUs, gold records in the index
the CU that includes the TU instead of the TU itself. This breaks
dw2_lookup_symbol: It assumes that if the index says symbol X lives
in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
will find X. Alas TUs live in their own symtab, so after expanding CU Y
we need to look in TU Z to find X. Fortunately, this is akin to
DW_TAG_imported_unit, so we just use the same mechanism: For
.gdb_index version <=7 this also records the TUs that the CU referred
to. Concurrently with this change gdb was modified to emit version 8
indices so we only pay a price for gold generated indices.
gdb: Remove use of VEC from dwarf2read.c This removes a use of VEC from GDB, from dwarf2read.c. This removal is not very clean, and would probably benefit from additional refactoring in the future. The problem here is that the VEC is contained within struct dwarf2_per_cu_data, which is treated as POD in dwarf2read.c. As such it is actually a VEC pointer. When converting this to a std::vector in an ideal world we would not use a std::vector pointer, and use the std::vector directly. Sadly, to do that would require some rewriting in dwarf2read.c - my concern would be introducing bugs during this rewrite. If we move to a std::vector pointer then we need to take care to handle the case where the pointer is null. The old VEC library would handle null for us, making the VEC interface very clean. With std::vector we need to handle the null pointer case ourselves. The achieve this then I've added a small number of function that wrap up access to the std::vector, hopefully hiding the null pointer management. The final ugliness with this conversion is that, ideally, when wrapping a data member behind an interface I would make the data member private, however, treating the structure as POD once again prevents this, so we are left with the data member being public, but access (ideally) being through the published interface functions. There should be no user visible changes after this commit. gdb/ChangeLog: * gdb/dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Update for new std::vector based implementation. (process_psymtab_comp_unit_reader): Likewise. (scan_partial_symbols): Likewise. (recursively_compute_inclusions): Likewise. (compute_compunit_symtab_includes): Likewise. (process_imported_unit_die): Likewise. (queue_and_load_dwo_tu): Likewise. (follow_die_sig_1): Likewise. * gdb/dwarf2read.h: Remove DEF_VEC_P. (typedef dwarf2_per_cu_ptr): Remove. (struct dwarf2_per_cu_data) <imported_symtabs_empty>: New function. (struct dwarf2_per_cu_data) <imported_symtabs_push>: New function. (struct dwarf2_per_cu_data) <imported_symtabs_size>: New function. (struct dwarf2_per_cu_data) <imported_symtabs_free>: New function. (struct dwarf2_per_cu_data) <imported_symtabs>: Change to std::vector. Change-Id: Id0f4bda977c9dd83b0ba3d7fb42f7e5e2b6869c8
2019-10-02 16:38:51 +02:00
http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
This currently needs to be a public member due to how
dwarf2_per_cu_data is allocated and used. Ideally in future things
could be refactored to make this private. Until then please try to
avoid direct access to this member, and instead use the helper
functions above. */
std::vector <dwarf2_per_cu_data *> *imported_symtabs;
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
};
/* Entry in the signatured_types hash table. */
struct signatured_type
{
/* The "per_cu" object of this type.
This struct is used iff per_cu.is_debug_types.
N.B.: This is the first member so that it's easy to convert pointers
between them. */
struct dwarf2_per_cu_data per_cu;
/* The type's signature. */
ULONGEST signature;
/* Offset in the TU of the type's DIE, as read from the TU header.
If this TU is a DWO stub and the definition lives in a DWO file
(specified by DW_AT_GNU_dwo_name), this value is unusable. */
cu_offset type_offset_in_tu;
/* Offset in the section of the type's DIE.
If the definition lives in a DWO file, this is the offset in the
.debug_types.dwo section.
The value is zero until the actual value is known.
Zero is otherwise not a valid section offset. */
sect_offset type_offset_in_section;
/* Type units are grouped by their DW_AT_stmt_list entry so that they
can share them. This points to the containing symtab. */
struct type_unit_group *type_unit_group;
/* The type.
The first time we encounter this type we fully read it in and install it
in the symbol tables. Subsequent times we only need the type. */
struct type *type;
/* Containing DWO unit.
This field is valid iff per_cu.reading_dwo_directly. */
struct dwo_unit *dwo_unit;
};
ULONGEST read_unsigned_leb128 (bfd *, const gdb_byte *, unsigned int *);
Write index for dwz -m file PR 24445 ("dwz multifile index not written to index cache") exposed the fact that we are not doing things right when we generate an index for an object file that has is linked to a dwz file. The same happens whether the index is generated with the intent of populating the index cache or using the save gdb-index command. The problem can be observed when running these tests with the cc-with-dwz-m board: FAIL: gdb.base/index-cache.exp: test_cache_enabled_hit: check index-cache stats FAIL: gdb.dwarf2/gdb-index.exp: index used FAIL: gdb.dwarf2/gdb-index.exp: index used after symbol reloading When generating the index for such file and inspecting the CU list of the resulting index (with readelf --debug-dump=gdb_index), we can see something like: CU table: [ 0] 0x0 - 0xb9 [ 1] 0x0 - 0x44 This is supposed to be a sorted list of the ranges of all CUs in the file this index represents, so already having some overlap is a red flag. It turns out that we save the ranges of CUs coming from both the main file and the dwz file in the same index. After digging a little bit, it became quite obvious that the index in the main file should only list the CUs present in the main file, and a separate index should be generated for the dwz file, listing the CUs present in that file. First, that's what happens if you run dwz on a file that already has a GDB index embedded. Second, dwarf2read.c has code to read an index from a dwz file. The index in the dwz file is actually required to be present, if the main file has an index. So this patch changes write_psymtabs_to_index to generate an index for the dwz file, if present. That index only contains a CU list, just like what the dwz tool does when processing a file that already contains an index. Some notes about the implementation: - The file management (creating a temp file, make sure it's close/removed on error - in the right order) is a bit heavy in write_psymtabs_to_index, and I needed to add a third file. I factored this pattern in a separate class, index_wip_file. - It became a bit tedious to keep the call to assert_file_size in write_psymtabs_to_index, write_gdbindex would have had to return two sizes. Instead, I moved the calls to assert_file_size where the file is written. The downside is that we lose the filename at this point, but it was only used for the very improbable case of ftell failing, so I think it's not a problem. - The actual writing of the index file is factored out to write_gdbindex_1, so it can be re-used for both index files. - While the "save gdb-index" command will now write two .gdb-index files, this patch does not update the gdb-add-index.sh script, this will come in a later patch. gdb/ChangeLog: YYYY-MM-DD Simon Marchi <simon.marchi@efficios.com> PR gdb/24445 * dwarf-index-write.h (write_psymtabs_to_index): Add dwz_basename parameter. * dwarf-index-write.c (write_gdbindex): Move file writing to write_gdbindex_1. Change return type void. (assert_file_size): Move up, remove filename parameter. (write_gdbindex_1): New function. (write_debug_names): Change return type to void, call assert_file_size. (struct index_wip_file): New struct. (write_psymtabs_to_index): Add dwz_basename parameter. Move file logic to index_wip_file. Write index for dwz file if needed. (save_gdb_index_command): Pass basename of dwz file, if present. * dwarf-index-cache.c (index_cache::store): Obtain and pass build-id of dwz file, if present. * dwarf2read.c (struct dwz_file): Move to dwarf2read.h. (dwarf2_get_dwz_file): Likewise. * dwarf2read.h (struct dwz_file): Move from dwarf2read.c. (dwarf2_get_dwz_file): Likewise. gdb/testsuite/ChangeLog: YYYY-MM-DD Tom de Vries <tdevries@suse.de> PR gdb/24445 * gdb.dwarf2/gdb-index.exp (add_gdb_index): Update dwz file with generated index.
2019-06-16 16:13:56 +02:00
/* This represents a '.dwz' file. */
struct dwz_file
{
dwz_file (gdb_bfd_ref_ptr &&bfd)
: dwz_bfd (std::move (bfd))
{
}
const char *filename () const
{
bfd macro conversion to inline functions This converts some of the macros that access struct bfd fields to inline functions. bfd/ * archive.c (bfd_generic_archive_p): Use bfd_set_thin_archive. * bfd-in.h (bfd_get_filename, bfd_get_cacheable, bfd_get_format), (bfd_get_target, bfd_get_flavour, bfd_family_coff, bfd_big_endian), (bfd_little_endian, bfd_header_big_endian, bfd_header_little_endian), (bfd_get_file_flags, bfd_applicable_file_flags), (bfd_applicable_section_flags, bfd_has_map, bfd_is_thin_archive), (bfd_valid_reloc_types, bfd_usrdata, bfd_get_start_address), (bfd_get_symcount, bfd_get_outsymbols, bfd_count_sections), (bfd_get_dynamic_symcount, bfd_get_symbol_leading_char): Delete. * bfd/bfd.c (bfd_get_filename, bfd_get_cacheable, bfd_get_format), (bfd_get_file_flags, bfd_get_start_address, bfd_get_symcount), (bfd_get_dynamic_symcount, bfd_get_outsymbols, bfd_count_sections), (bfd_has_map, bfd_is_thin_archive, bfd_set_thin_archive), (bfd_usrdata, bfd_set_usrdata): New inline functions. * targets.c (bfd_get_target, bfd_get_flavour), (bfd_applicable_file_flags, bfd_family_coff, bfd_big_endian), (bfd_little_endian, bfd_header_big_endian), (bfd_header_little_endian, bfd_applicable_section_flags), (bfd_get_symbol_leading_char): New inline functions. * bfd-in2.h: Regenerate. binutils/ * ar.c (write_archive): Use bfd_set_thin_archive. gdb/ * gdb_bfd.c (gdb_bfd_ref, gdb_bfd_unref): Use bfd_set_usrdata. * dwarf2read.c (dwarf2_read_gdb_index, dwarf2_read_debug_names), (read_indirect_string_from_dwz): Use bfd accessor. * dwarf2read.h (struct dwz_file <filename>): Likewise. * machoread.c (macho_symfile_read_all_oso): Likewise. * solib.c (solib_bfd_open): Likewise. ld/ * ldelf.c (ldelf_after_open, ldelf_place_orphan * ldlang.c (walk_wild_file, lang_process): Use bfd_usrdata. (load_symbols, ldlang_add_file): Use bfd_set_usrdata. * ldmain.c (add_archive_element): Use bfd_usrdata. * ldlang.h (bfd_input_just_syms): New inline function. * emultempl/aarch64elf.em (build_section_lists): Use it. * emultempl/mmo.em (mmo_place_orphan): Likewise. * emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise. * emultempl/pep.em (gld_${EMULATION_NAME}_place_orphan): Likewise. * emultempl/ppc64elf.em (build_section_lists): Likewise. sim/ * ppc/emul_generic.c (emul_add_tree_options): Delete old bfd code.
2019-09-19 04:21:04 +02:00
return bfd_get_filename (this->dwz_bfd.get ());
Write index for dwz -m file PR 24445 ("dwz multifile index not written to index cache") exposed the fact that we are not doing things right when we generate an index for an object file that has is linked to a dwz file. The same happens whether the index is generated with the intent of populating the index cache or using the save gdb-index command. The problem can be observed when running these tests with the cc-with-dwz-m board: FAIL: gdb.base/index-cache.exp: test_cache_enabled_hit: check index-cache stats FAIL: gdb.dwarf2/gdb-index.exp: index used FAIL: gdb.dwarf2/gdb-index.exp: index used after symbol reloading When generating the index for such file and inspecting the CU list of the resulting index (with readelf --debug-dump=gdb_index), we can see something like: CU table: [ 0] 0x0 - 0xb9 [ 1] 0x0 - 0x44 This is supposed to be a sorted list of the ranges of all CUs in the file this index represents, so already having some overlap is a red flag. It turns out that we save the ranges of CUs coming from both the main file and the dwz file in the same index. After digging a little bit, it became quite obvious that the index in the main file should only list the CUs present in the main file, and a separate index should be generated for the dwz file, listing the CUs present in that file. First, that's what happens if you run dwz on a file that already has a GDB index embedded. Second, dwarf2read.c has code to read an index from a dwz file. The index in the dwz file is actually required to be present, if the main file has an index. So this patch changes write_psymtabs_to_index to generate an index for the dwz file, if present. That index only contains a CU list, just like what the dwz tool does when processing a file that already contains an index. Some notes about the implementation: - The file management (creating a temp file, make sure it's close/removed on error - in the right order) is a bit heavy in write_psymtabs_to_index, and I needed to add a third file. I factored this pattern in a separate class, index_wip_file. - It became a bit tedious to keep the call to assert_file_size in write_psymtabs_to_index, write_gdbindex would have had to return two sizes. Instead, I moved the calls to assert_file_size where the file is written. The downside is that we lose the filename at this point, but it was only used for the very improbable case of ftell failing, so I think it's not a problem. - The actual writing of the index file is factored out to write_gdbindex_1, so it can be re-used for both index files. - While the "save gdb-index" command will now write two .gdb-index files, this patch does not update the gdb-add-index.sh script, this will come in a later patch. gdb/ChangeLog: YYYY-MM-DD Simon Marchi <simon.marchi@efficios.com> PR gdb/24445 * dwarf-index-write.h (write_psymtabs_to_index): Add dwz_basename parameter. * dwarf-index-write.c (write_gdbindex): Move file writing to write_gdbindex_1. Change return type void. (assert_file_size): Move up, remove filename parameter. (write_gdbindex_1): New function. (write_debug_names): Change return type to void, call assert_file_size. (struct index_wip_file): New struct. (write_psymtabs_to_index): Add dwz_basename parameter. Move file logic to index_wip_file. Write index for dwz file if needed. (save_gdb_index_command): Pass basename of dwz file, if present. * dwarf-index-cache.c (index_cache::store): Obtain and pass build-id of dwz file, if present. * dwarf2read.c (struct dwz_file): Move to dwarf2read.h. (dwarf2_get_dwz_file): Likewise. * dwarf2read.h (struct dwz_file): Move from dwarf2read.c. (dwarf2_get_dwz_file): Likewise. gdb/testsuite/ChangeLog: YYYY-MM-DD Tom de Vries <tdevries@suse.de> PR gdb/24445 * gdb.dwarf2/gdb-index.exp (add_gdb_index): Update dwz file with generated index.
2019-06-16 16:13:56 +02:00
}
/* A dwz file can only contain a few sections. */
struct dwarf2_section_info abbrev {};
struct dwarf2_section_info info {};
struct dwarf2_section_info str {};
struct dwarf2_section_info line {};
struct dwarf2_section_info macro {};
struct dwarf2_section_info gdb_index {};
struct dwarf2_section_info debug_names {};
/* The dwz's BFD. */
gdb_bfd_ref_ptr dwz_bfd;
/* If we loaded the index from an external file, this contains the
resources associated to the open file, memory mapping, etc. */
std::unique_ptr<index_cache_resource> index_cache_res;
};
/* Open the separate '.dwz' debug file, if needed. Return NULL if
there is no .gnu_debugaltlink section in the file. Error if there
is such a section but the file cannot be found. */
extern struct dwz_file *dwarf2_get_dwz_file
(struct dwarf2_per_objfile *dwarf2_per_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
#endif /* DWARF2READ_H */