drgn/libdrgn
Omar Sandoval 26291647eb libdrgn: dwarf_index: handle DW_AT_specification DIEs with two passes
We currently handle DIEs with a DW_AT_specification attribute by parsing
the corresponding declaration to get the name and inserting the DIE as
usual. This has a couple of problems:

1. It only works if DW_AT_specification refers to the same compilation
   unit, which is true for DW_FORM_ref{1,2,4,8,_udata}, but not
   DW_FORM_ref_addr. As a result, drgn doesn't support the latter.
2. It assumes that the DIE with DW_AT_specification is in the correct
   "scope". Unfortunately, this is not true for g++: for a variable
   definition in a C++ namespace, it generates a DIE with
   DW_AT_declaration as a child of the DW_TAG_namespace DIE and a DIE
   which refers to the declaration with DW_AT_specification _outside_ of
   the DW_TAG_namespace as a child of the DW_TAG_compilation_unit DIE.

Supporting both of these cases requires reworking how we handle
DW_AT_specification. This commit takes an approach of parsing the DWARF
data in two passes: the first pass reads the abbrevation and file name
tables and builds a map of instances of DW_AT_specification; the second
pass indexes DIEs as before, but ignores DIEs with DW_AT_specification
and handles DIEs with DW_AT_declaration by looking them up in the map
built by the first pass.

This approach is a 10-20% regression in indexing time in the benchmarks
I ran. Thankfully, it is not 100% slower for a couple of reasons. The
first is that the two passes are simpler than the original combined
pass. The second is that a decent part of the indexing time is spent
faulting in the mapped debugging information, which only needs to happen
once (even if the file is cached, minor page faults add non-negligible
overhead).

This doesn't handle DW_AT_specification "chains" yet, but neither did
the original code. If it is necessary, it shouldn't be too difficult to
add.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2020-09-02 17:13:16 -07:00
..
build-aux libdrgn/python: add Qualifiers.NONE and stop using Optional[Qualifiers] 2020-08-27 11:31:29 -07:00
elfutils Update elfutils and revert activation frame patch 2020-05-20 13:38:49 -07:00
examples libdrgn: add load_debug_info example program 2020-07-10 16:18:58 -07:00
include Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
m4 libdrgn: build with bundled elfutils 2019-09-19 11:07:12 -07:00
python helpers: translate task_state_to_char() to Python 2020-08-27 13:54:39 -07:00
.gitignore Document with Sphinx 2019-04-11 12:48:15 -07:00
arch_x86_64.c.in libdrgn: remove struct drgn_object::prog 2020-08-27 11:31:21 -07:00
binary_search_tree.h Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
cityhash.h Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
configure.ac drgn 0.0.7 2020-07-27 23:32:32 -07:00
Doxyfile Rewrite drgn core in C 2019-04-02 14:12:07 -07:00
drgn.h.in libdrgn: remove struct drgn_object::prog 2020-08-27 11:31:21 -07:00
dwarf_index.c libdrgn: dwarf_index: handle DW_AT_specification DIEs with two passes 2020-09-02 17:13:16 -07:00
dwarf_index.h libdrgn: dwarf_index: handle DW_AT_specification DIEs with two passes 2020-09-02 17:13:16 -07:00
dwarf_info_cache.c Associate types with program 2020-08-26 17:41:09 -07:00
dwarf_info_cache.h Associate types with program 2020-08-26 17:41:09 -07:00
error.c Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
error.h Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
hash_table.c Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
hash_table.h libdrgn: hash_table: clean up coding style 2020-07-18 11:53:05 -07:00
helpers.h helpers: translate task_state_to_char() to Python 2020-08-27 13:54:39 -07:00
internal.c Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
internal.h libdrgn: dwarf_info_cache: handle DW_AT_endianity 2020-07-13 14:26:58 -07:00
kdump.c libdrgn: fix _page_offset() helper and move to object finder 2020-04-10 15:33:27 -07:00
language_c.c libdrgn: remove struct drgn_object::prog 2020-08-27 11:31:21 -07:00
language.c Associate types with program 2020-08-26 17:41:09 -07:00
language.h Associate types with program 2020-08-26 17:41:09 -07:00
lexer.c Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
lexer.h Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
linux_kernel_helpers.c helpers: translate task_state_to_char() to Python 2020-08-27 13:54:39 -07:00
linux_kernel.c Associate types with program 2020-08-26 17:41:09 -07:00
linux_kernel.h libdrgn: make Linux kernel stack unwinding more robust 2020-05-20 12:03:00 -07:00
Makefile.am libdrgn: fold drgn_type_index into drgn_program 2020-08-26 17:36:35 -07:00
memory_reader.c Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
memory_reader.h Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
object_index.c libdrgn: fold drgn_type_index into drgn_program 2020-08-26 17:36:35 -07:00
object_index.h libdrgn: fold drgn_type_index into drgn_program 2020-08-26 17:36:35 -07:00
object.c libdrgn: remove struct drgn_object::prog 2020-08-27 11:31:21 -07:00
object.h libdrgn: dwarf_info_cache: handle variables DW_AT_const_value 2020-07-13 15:23:51 -07:00
path.c Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
platform.c Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
platform.h libdrgn: go back to trusting PRSTATUS PID 2020-07-08 18:34:16 -07:00
program.c helpers: translate task_state_to_char() to Python 2020-08-27 13:54:39 -07:00
program.h helpers: translate task_state_to_char() to Python 2020-08-27 13:54:39 -07:00
read.h Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
serialize.c Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
serialize.h Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
siphash.h Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
splay_tree.c Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
stack_trace.c libdrgn: remove struct drgn_object::prog 2020-08-27 11:31:21 -07:00
string_builder.c Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
string_builder.h Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
symbol.c Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
symbol.h Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
type.c Associate types with program 2020-08-26 17:41:09 -07:00
type.h Associate types with program 2020-08-26 17:41:09 -07:00
util.h Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
vector.c Update copyright headers to Facebook and add missing headers 2020-05-15 15:13:02 -07:00
vector.h libdrgn: add vector/hash table initializers and update coding style 2020-07-01 12:48:24 -07:00