aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2
AgeCommit message (Collapse)AuthorFilesLines
2022-07-14[gdb/symtab] Make per_cu->m_lang atomicTom de Vries1-9/+13
When building gdb with -fsanitize=thread and running test-case gdb.dwarf2/inlined_subroutine-inheritance.exp, we run into a data race between: ... Read of size 1 at 0x7b2000003010 by thread T4: #0 packed<language, 1ul>::operator language() const packed.h:54 #1 dwarf2_per_cu_data::set_lang(language) read.h:363 ... and: ... Previous write of size 1 at 0x7b2000003010 by main thread: #0 dwarf2_per_cu_data::set_lang(language) read.h:365 ... Fix this by making per_cu->m_lang atomic. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29286
2022-07-14[gdb/symtab] Make per_cu->unit_type atomicTom de Vries1-9/+14
With gdb with -fsanitize=thread and test-case gdb.ada/array_bounds.exp, I run into a data race between: ... Read of size 1 at 0x7b2000025f0f by main thread: #0 packed<dwarf_unit_type, 1ul>::operator dwarf_unit_type() const packed.h:54 #1 dwarf2_per_cu_data::set_unit_type(dwarf_unit_type) read.h:339 ... and: ... Previous write of size 1 at 0x7b2000025f0f by thread T3: #0 dwarf2_per_cu_data::set_unit_type(dwarf_unit_type) read.h:341 ... Fix this by making per_cu->unit_type atomic. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29286
2022-07-13[gdb/symtab] Make per_cu->set_lang more strictTom de Vries2-23/+26
We have in per_cu->set_lang this comment: ... void set_lang (enum language lang) { /* We'd like to be more strict here, similar to what is done in set_unit_type, but currently a partial unit can go from unknown to minimal to ada to c. */ ... Fix this by not setting m_lang for partial units. This requires us to move the m_unit_type initialization to ensure that m_unit_type is initialized before per_cu->m_lang. Tested on x86_64-linux, with native and target board cc-with-dwz-m.
2022-07-12[gdb/symtab] Add dwarf2_cu::lang ()Tom de Vries3-100/+107
The cu->per_cu->lang field was added to carry information from the initial partial symtabs phase to the symtab expansion phase, for the benefit of a particular optimization in process_imported_unit_die. Other uses have been added, but since the first phase now has been parallelized, those have become problematic and sources of race conditions. Fix this by adding dwarf2_cu::lang () and using it where we can to replace cu->per_cu->lang () with cu->lang (). Also assert in dwarf2_cu::lang () that we're not returning language_unknown. Tested on x86_64-linux.
2022-07-12Fix -fsanitize=thread for per_cu fieldsTom de Vries1-9/+11
When building gdb with -fsanitize=thread and gcc 12, and running test-case gdb.dwarf2/dwz.exp, we run into a data race between: ... Read of size 1 at 0x7b200000300d by thread T2:^M #0 cutu_reader::cutu_reader(dwarf2_per_cu_data*, dwarf2_per_objfile*, \ abbrev_table*, dwarf2_cu*, bool, abbrev_cache*) gdb/dwarf2/read.c:6164 \ (gdb+0x82ec95)^M ... and: ... Previous write of size 1 at 0x7b200000300d by main thread:^M #0 prepare_one_comp_unit gdb/dwarf2/read.c:23588 (gdb+0x86f973)^M ... In other words, between: ... if (this_cu->reading_dwo_directly) ... and: ... cu->per_cu->lang = pretend_language; ... Likewise, we run into a data race between: ... Write of size 1 at 0x7b200000300e by thread T4: #0 process_psymtab_comp_unit gdb/dwarf2/read.c:6789 (gdb+0x830720) ... and: ... Previous read of size 1 at 0x7b200000300e by main thread: #0 cutu_reader::cutu_reader(dwarf2_per_cu_data*, dwarf2_per_objfile*, \ abbrev_table*, dwarf2_cu*, bool, abbrev_cache*) gdb/dwarf2/read.c:6164 \ (gdb+0x82edab) ... In other words, between: ... this_cu->unit_type = DW_UT_partial; ... and: ... if (this_cu->reading_dwo_directly) ... Likewise for the write to addresses_seen in cooked_indexer::check_bounds and a read from is_dwz in dwarf2_find_containing_comp_unit for test-case gdb.dwarf2/dw2-dir-file-name.exp and target board cc-with-dwz-m. The problem is that the written fields are part of the same memory location as the read fields, so executing a read and write in different threads is undefined behavour. Making the written fields separate memory locations, using the new struct packed template fixes this. The set of fields has been established experimentally to be the minimal set to get rid of this type of -fsanitize=thread errors, but more fields might require the same treatment. Looking at the properties of the lang field, unlike dwarf_version it's not available in the unit header, so it will be set the first time during the parallel cooked index reading. The same holds for unit_type, and likewise for addresses_seen. dwarf2_per_cu_data::addresses_seen is moved so that the bitfields that currently follow it can be merged in the same memory location as the bitfields that currently precede it, for better packing. Tested on x86_64-linux. Co-Authored-By: Pedro Alves <pedro@palves.net> Change-Id: Ifa94f0a2cebfae5e8f6ddc73265f05e7fd9e1532
2022-07-11[gdb/symtab] Fix data race in per_cu->lengthTom de Vries3-25/+41
With gdb build with -fsanitize=thread and test-case gdb.dwarf2/dw4-sig-types.exp and target board cc-with-dwz-m we run into a data race between: ... Write of size 4 at 0x7b2800002268 by thread T4:^M #0 cutu_reader::cutu_reader(dwarf2_per_cu_data*, dwarf2_per_objfile*, \ abbrev_table*, dwarf2_cu*, bool, abbrev_cache*) gdb/dwarf2/read.c:6236 \ (gdb+0x82f525)^M ... and this read: ... Previous read of size 4 at 0x7b2800002268 by thread T1:^M #0 dwarf2_find_containing_comp_unit gdb/dwarf2/read.c:23444 \ (gdb+0x86e22e)^M ... In other words, between this write: ... this_cu->length = cu->header.get_length (); ... and this read: ... && mid_cu->sect_off + mid_cu->length > sect_off)) ... of per_cu->length. Fix this similar to the per_cu->dwarf_version case, by only setting it if needed, and otherwise verifying that the same value is used. [ Note that the same code is already present in the other cutu_reader constructor. ] Move this logic into into a member function set_length to make sure it's used consistenly, and make the field private in order to enforce access through the member functions, and rename it to m_length. This exposes (running test-case gdb.dwarf2/fission-reread.exp) that in fill_in_sig_entry_from_dwo_entry, the m_length field is overwritten. For now, allow for that exception. While we're at it, make sure that the length is set before read. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29344
2022-07-11[gdb/symtab] Use comp_unit_head::get_lengthTom de Vries1-1/+1
There's a spot in read_comp_units_from_section where we explictly use initial_length_size to get the total length: ... this_cu->length = cu_header.length + cu_header.initial_length_size; ... Instead, just use cu_header.get_length (). Tested on x86_64-linux.
2022-07-08[gdb/symtab] Fix assert in process_imported_unit_dieTom de Vries2-7/+10
When running test-case gdb.dwarf2/dw2-symtab-includes.exp with target board cc-with-debug-names, I run into: ... (gdb) maint expand-symtab dw2-symtab-includes.h^M src/gdb/dwarf2/read.h:311: internal-error: unit_type: \ Assertion `m_unit_type != 0' failed.^M A problem internal to GDB has been detected,^M further debugging may prove unreliable.^M ----- Backtrace -----^M FAIL: gdb.dwarf2/dw2-symtab-includes.exp: maint expand-symtab \ dw2-symtab-includes.h (GDB internal error) ... The assert was recently added in commit 2c474c46943 ("[gdb/symtab] Add get/set functions for per_cu->lang/unit_type"). The assert is triggered here: ... /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit into another compilation unit, at root level. Regard this as a hint, and ignore it. */ if (die->parent && die->parent->parent == NULL && per_cu->unit_type () == DW_UT_compile && per_cu->lang () == language_cplus) return; ... We're trying to access unit_type / lang which hasn't been set yet. Normally, these are set during cooked index creation, but that's not the case when using an index (or using -readnow). In other words, this lto binary reading speed optimization only works in the normal use case. IWBN to have this working in all use cases, but for now, allow lang () and unit_type () to return language_unknown and 0 here. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29321
2022-07-08[gdb/symtab] Fix segfault in dwarf2_per_objfile::symtab_set_pTom de Vries1-1/+5
When running test-case gdb.cp/cpexprs-debug-types.exp with target board cc-with-debug-names, I run into: ... (gdb) print base::operator new^M ^M ^M Fatal signal: Segmentation fault^M ----- Backtrace -----^M 0x57ea46 gdb_internal_backtrace_1^M /home/vries/gdb_versions/devel/src/gdb/bt-utils.c:122^M 0x57eae9 _Z22gdb_internal_backtracev^M /home/vries/gdb_versions/devel/src/gdb/bt-utils.c:168^M 0x75b8ad handle_fatal_signal^M /home/vries/gdb_versions/devel/src/gdb/event-top.c:946^M 0x75ba19 handle_sigsegv^M /home/vries/gdb_versions/devel/src/gdb/event-top.c:1019^M 0x7f795f46a8bf ???^M 0x6d3cb1 _ZNK18dwarf2_per_objfile12symtab_set_pEPK18dwarf2_per_cu_data^M /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:1515^M ... The problem is in this piece of code in dw2_debug_names_iterator::next: ... case DW_IDX_type_unit: /* Don't crash on bad data. */ if (ull >= per_bfd->tu_stats.nr_tus) { complaint (_(".debug_names entry has bad TU index %s" " [in module %s]"), pulongest (ull), objfile_name (objfile)); continue; } per_cu = per_bfd->get_cu (ull + per_bfd->tu_stats.nr_tus); break; ... The all_comp_units vector (which get_cu accesses) contains both CUs and TUs, with CUs first. So to get the nth TU we need the element at "nr_cus + n", but the code uses "nr_tus + n" instead. Fix this by using "nr_cus + n". Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29334
2022-07-04[gdb/symtab] Add get/set functions for per_cu->lang/unit_typeTom de Vries5-121/+157
The dwarf2_per_cu_data fields lang and unit_type both have a dont-know initial value (respectively language_unknown and (dwarf_unit_type)0), which allows us to add certain checks, f.i. checking that that a field is not read before written. Add get/set member functions for the two fields as a convenient location to add such checks, make the fields private to enforce using the member functions, and add the m_ prefix. Tested on x86_64-linux.
2022-07-02[gdb/symtab] Fix data race on per_cu->dwarf_versionTom de Vries2-5/+23
When building gdb with -fsanitize=thread and gcc 12, and running test-case gdb.dwarf2/dwz.exp, we run into a data race between thread T2 and the main thread in the same write: ... Write of size 1 at 0x7b200000300c:^M #0 cutu_reader::cutu_reader(dwarf2_per_cu_data*, dwarf2_per_objfile*, \ abbrev_table*, dwarf2_cu*, bool, abbrev_cache*) gdb/dwarf2/read.c:6252 \ (gdb+0x82f3b3)^M ... which is here: ... this_cu->dwarf_version = cu->header.version; ... Both writes are called from the parallel for in dwarf2_build_psymtabs_hard, this one directly: ... #1 process_psymtab_comp_unit gdb/dwarf2/read.c:6774 (gdb+0x8304d7)^M #2 operator() gdb/dwarf2/read.c:7098 (gdb+0x8317be)^M #3 operator() gdbsupport/parallel-for.h:163 (gdb+0x872380)^M ... and this via the PU import: ... #1 cooked_indexer::ensure_cu_exists(cutu_reader*, dwarf2_per_objfile*, \ sect_offset, bool, bool) gdb/dwarf2/read.c:17964 (gdb+0x85c43b)^M #2 cooked_indexer::index_imported_unit(cutu_reader*, unsigned char const*, \ abbrev_info const*) gdb/dwarf2/read.c:18248 (gdb+0x85d8ff)^M #3 cooked_indexer::index_dies(cutu_reader*, unsigned char const*, \ cooked_index_entry const*, bool) gdb/dwarf2/read.c:18302 (gdb+0x85dcdb)^M #4 cooked_indexer::make_index(cutu_reader*) gdb/dwarf2/read.c:18443 \ (gdb+0x85e68a)^M #5 process_psymtab_comp_unit gdb/dwarf2/read.c:6812 (gdb+0x830879)^M #6 operator() gdb/dwarf2/read.c:7098 (gdb+0x8317be)^M #7 operator() gdbsupport/parallel-for.h:171 (gdb+0x8723e2)^M ... Fix this by setting the field earlier, in read_comp_units_from_section. The write in cutu_reader::cutu_reader() is still needed, in case read_comp_units_from_section is not used (run the test-case with say, target board cc-with-gdb-index). Make the write conditional, such that it doesn't trigger if the field is already set by read_comp_units_from_section. Instead, verify that the field already has the value that we're trying to set it to. Move this logic into into a member function set_version (in analogy to the already present member function version) to make sure it's used consistenly, and make the field private in order to enforce access through the member functions, and rename it to m_dwarf_version. While we're at it, make sure that the version is set before read, to avoid say returning true for "per_cu.version () < 5" if "per_cu.version () == 0". Tested on x86_64-linux.
2022-06-27[gdb/symtab] Fix parsing of .debug_str_offsets headerTom de Vries1-7/+57
When running test-case gdb.dwarf2/fission-mix.exp with target board dwarf64 and gcc-12 (defaulting to DWARF5), I run into: ... (gdb) break func2^M Offset from DW_FORM_GNU_str_index or DW_FORM_strx pointing outside of \ .debug_str.dwo section in CU at offset 0x0 [in module fission-mix]^M (gdb) FAIL: gdb.dwarf2/fission-mix.exp: break func2 ... The .debug_str_offsets section has version 5, so as per the standard it has it's own header, with initial length and version: ... Contents of the .debug_str_offsets.dwo section (loaded from fission-mix2.dwo): Length: 0x1c Version: 0x5 Index Offset [String] 0 0 build/gdb/testsuite 1 33 GNU C17 2 8f src/gdb/testsuite/gdb.dwarf2/fission-mix-2.c ... But when trying to read the string offset at index 0 in the table (which is 0), we start reading at offset 8, which points in the header, at the last 4 bytes of the initial length (it's 12 bytes because of 64-bit dwarf), as well at the 2-byte version field and 2 bytes of padding, so we get: ... (gdb) p /x str_offset $1 = 0x500000000 ... which indeed is an offset that doesn't fit in the .debug_str section. The offset 8 is based on reader->cu->header.addr_size: ... static const char * read_dwo_str_index (const struct die_reader_specs *reader, ULONGEST str_index) { ULONGEST str_offsets_base = reader->cu->header.version >= 5 ? reader->cu->header.addr_size : 0; ... which doesn't in look in agreement with the standard. Note that this happens to give the right answer for 32-bit dwarf and addr_size == 8, because then we have header size == (initial length (4) + version (2) + padding (2)) == 8. Conversely, for 32-bit dwarf and addr_size == 4 (target board unix/-m32) we run into a similar problem. It just happens to not trigger the warning, instead we get the wrong strings, like "func2" for DW_AT_producer and "build/gdb/testsuite" for DW_AT_name of the DW_TAG_compile_unit DIE. Fix this by parsing the .debug_str_offsets header in read_dwo_str_index. Add a FIXME that we should not parse this for every call. Tested on x86_64-linux.
2022-06-25Fix end of CU calculation in cooked_indexer::index_diesTom Tromey1-1/+3
cooked_indexer::index_dies incorrect computes the end of the current CU in the .debug_info. This isn't readily testable without writing intentionally corrupt DWARF, but it's apparent through observation: it is currently based on 'info_ptr', which does not always point to the start of the CU. This patch fixes the expression. Tested on x86-64 Fedora 34.
2022-06-14Debug support for global alias variableKavitha Natarajan1-21/+42
Starting with (future) Clang 15 (since https://reviews.llvm.org/D120989), Clang emits the DWARF information of global alias variables as DW_TAG_imported_declaration. However, GDB does not handle it. It incorrectly always reads this tag as C++/Fortran imported declaration (type alias, namespace alias and Fortran module). This commit adds support to handle this tag as an alias variable. This change fixes the failures in the gdb.base/symbol-alias.exp testcase with current git Clang. This testcase is also updated to test nested (recursive) aliases.
2022-06-12Remove psymtab_addrmapTom Tromey1-2/+2
While working on addrmaps, I noticed that psymtab_addrmap is no longer needed now. It was introduced in ancient times as an optimization for DWARF, but no other symbol reader was ever updated to use it. Now that DWARF does not use psymtabs, it can be deleted.
2022-06-12Use malloc for mutable addrmapsTom Tromey1-28/+15
Mutable addrmaps currently require an obstack. This was probably done to avoid having to call splay_tree_delete, but examination of the code shows that all mutable obstacks have a limited lifetime -- now it's simple to treat them as ordinary C++ objects, in some cases stack-allocating them, and have a destructor to make the needed call. This patch implements this change.
2022-06-12Remove addrmap::create_fixedTom Tromey2-4/+7
addrmap::create_fixed is just a simple wrapper for 'new', so remove it in favor of uses of 'new'.
2022-06-12Remove addrmap_create_mutableTom Tromey1-7/+8
This removes addrmap_create_mutable in favor of using 'new' at the spots where the addrmap is created.
2022-06-12Remove addrmap wrapper functionsTom Tromey3-21/+16
This removes the various addrmap wrapper functions in favor of simple method calls on the objects themselves.
2022-06-08Move CU queue to dwarf2_per_objfileTom Tromey2-14/+14
The CU queue is a member of dwarf2_per_bfd, but it is only used when expanding CUs. Also, the dwarf2_per_objfile destructor checks the queue -- however, if the per-BFD object is destroyed first, this will not work. This was pointed out Lancelot as fallout from the patch to rewrite the registry system. This patch avoids this problem by moving the queue to the per-objfile object.
2022-06-08Change allocation of m_dwarf2_cusTom Tromey2-16/+13
m_dwarf2_cus manually manages the 'dwarf2_cu' pointers it owns. This patch simplifies the code by changing it to use unique_ptr.
2022-05-31Clarify why we unit test matching symbol names with 0xff charactersPedro Alves1-4/+13
In the name matching unit tests in gdb/dwarf2/read.c, explain better why we test symbols with \377 / 0xff characters (Latin1 'ΓΏ'). Change-Id: I517f13adfff2e4d3cd783fec1d744e2b26e18b8e
2022-05-26Fix crash in new DWARF indexerTom Tromey1-39/+33
PR gdb/29128 points out a crash in the new DWARF index code. This happens if the aranges for a CU claims a PC, but the symtab that is created during CU expansion does not actually contain the PC. This can only occur due to bad debuginfo, but at the same time, gdb should not crash. This patch fixes the bug and further merges some code into dwarf2_base_index_functions. This merger helps prevent the same issue from arising from the other index implementations. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29128
2022-05-26Finalize each cooked index separatelyTom Tromey2-163/+192
After DWARF has been scanned, the cooked index code does a "finalization" step in a worker thread. This step combines all the index entries into a single master list, canonicalizes C++ names, and splits Ada names to synthesize package names. While this step is run in the background, gdb will wait for the results in some situations, and it turns out that this step can be slow. This is PR symtab/29105. This can be sped up by parallelizing, at a small memory cost. Now each index is finalized on its own, in a worker thread. The cost comes from name canonicalization: if a given non-canonical name is referred to by multiple indices, there will be N canonical copies (one per index) rather than just one. This requires changing the users of the index to iterate over multiple results. However, this is easily done by introducing a new "chained range" class. When run on gdb itself, the memory cost seems rather low -- on my current machine, "maint space 1" reports no change due to the patch. For performance testing, using "maint time 1" and "file" will not show correct results. That approach measures "time to next prompt", but because the patch only affects background work, this shouldn't (and doesn't) change. Instead, a simple way to make gdb wait for the results is to set a breakpoint. Before: $ /bin/time -f%e ~/gdb/install/bin/gdb -nx -q -batch \ -ex 'break main' /tmp/gdb Breakpoint 1 at 0x43ec30: file ../../binutils-gdb/gdb/gdb.c, line 28. 2.00 After: $ /bin/time -f%e ./gdb/gdb -nx -q -batch \ -ex 'break main' /tmp/gdb Breakpoint 1 at 0x43ec30: file ../../binutils-gdb/gdb/gdb.c, line 28. 0.65 Regression tested on x86-64 Fedora 34. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29105
2022-05-22Accept functions with DW_AT_linkage_name presentAlok Kumar Sharma1-1/+15
Currently GDB is not able to debug (Binary generated with Clang) variables present in shared/private clause of OpenMP Task construct. Please note that LLVM debugger LLDB is able to debug. In case of OpenMP, compilers generate artificial functions which are not present in actual program. This is done to apply parallelism to block of code. For non-artifical functions, DW_AT_name attribute should contains the name exactly as present in actual program. (Ref# http://wiki.dwarfstd.org/index.php?title=Best_Practices) Since artificial functions are not present in actual program they not having DW_AT_name and having DW_AT_linkage_name instead should be fine. Currently GDB is invalidating any function not havnig DW_AT_name which is why it is not able to debug OpenMP (Clang). It should be fair to fallback to check DW_AT_linkage_name in case DW_AT_name is absent.
2022-05-13Remove unused field cooked_index::m_startTom Tromey1-5/+0
cooked_index::m_start is unused and can be removed. I think this was a leftover from a previous approach in the index finalization code, and then when rewriting it I forgot to remove it. Tested by rebuilding.
2022-05-10Fix --disable-threading buildTom Tromey1-1/+1
PR build/29110 points out that GDB fails to build on mingw when the "win32" thread model is in use. It turns out that the Fedora cross tools using the "posix" thread model, which somehow manages to support std::future, whereas the win32 model does not. While looking into this, I found that the configuring with --disable-threading will also cause a build failure. This patch fixes this build by introducing a compatibility wrapper for std::future. I am not able to test the win32 thread model build, but I'm going to ask the reporter to try this patch. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29110
2022-05-04Fix crash when creating index from indexTom Tromey3-19/+27
My patches yesterday to unify the DWARF index base classes had a bug -- namely, I did the wholesale dynamic_cast-to-static_cast too hastily and introduced a crash. This can be seen by trying to add an index to a file that has an index, or by running a test like gdb-index-cxx.exp using the cc-with-debug-names.exp target board. This patch fixes the crash by introducing a new virtual method and removing some of the static casts.
2022-04-29De-duplicate .gdb_indexTom Tromey1-2/+23
This de-duplicates variables and types in .gdb_index, making the new index closer to what gdb generated before the new DWARF scanner series. Spot-checking the resulting index for gdb itself, it seems that the new scanner picks up some extra symbols not detected by the old one. I tested both the new and old versions of gdb on both new and old versions of the index, and startup time in all cases is roughly the same (it's worth noting that, for gdb itself, the index no longer provides any benefit over the DWARF scanner). So, I think this fixes the size issue with the new index writer. Regression tested on x86-64 Fedora 34.
2022-04-29Fix .debug_names regression with new indexerTom Tromey3-3/+85
At AdaCore, we run the internal gdb test suite in several modes, including one using the .debug_names index. This caught a regression caused by the new DWARF indexer. First, the psymtabs-based .debug_names generator was completely wrong. However, to avoid making the rewrite series even bigger (fixing the writer will also require rewriting the .debug_names reader), it attempted to preserve the weirdness. However, this was not done properly. For example the old writer did this: - case STRUCT_DOMAIN: - return DW_TAG_structure_type; The new code, instead, simply preserves the actual DWARF tag -- but this makes future lookups fail, because the .debug_names reader only looks for DW_TAG_structure_type. This patch attempts to revert to the old behavior in the writer.
2022-04-28Check OBJF_NOT_FILENAME in DWARF index codeTom Tromey2-6/+7
The DWARF index code currently uses 'stat' to see if an objfile represents a real file. However, I think it's more correct to check OBJF_NOT_FILENAME instead. Regression tested on x86-64 Fedora 34.
2022-04-27gdb: remove BLOCK_ENTRY_PC macroSimon Marchi1-2/+2
Replace with equivalent method. Change-Id: I0e033095e7358799930775e61028b48246971a7d
2022-04-27gdb: remove BLOCK_RANGES macroSimon Marchi1-1/+1
Replace with an equivalent method on struct block. Change-Id: I6dcf13e9464ba8a08ade85c89e7329c300fd6c2a
2022-04-25Do not put linkage names into .gdb_indexTom Tromey1-0/+8
This changes the .gdb_index writer to skip linkage names. This was always done historically (though somewhat implicitly).
2022-04-22Fix method naming bug in new DWARF indexerTom Tromey2-2/+16
Pedro pointed out that gdb-add-index is much slower with the new DWARF indexer. He also noticed that, in some cases, the generated .gdb_index would have the wrong fully-qualified name for a method. I tracked this down to a bug in the indexer. If a type could have methods but was marked as a declaration, the indexer was ignoring it. However, this meant that the internal map to find the qualified name was not updated for this container.
2022-04-21gdb/dwarf: remove line_header::header_length fieldSimon Marchi2-3/+4
This can be a local in dwarf_decode_line_header. Change-Id: I2ecf4616d1a3197bd1e81ded9f999a2da9a685af
2022-04-21gdb/dwarf: remove line_header::total_length fieldSimon Marchi2-6/+5
This doesn' have to be a field, it can simply be a local variable in dwarf_decode_line_header. Name the local variable "unit_length", since that's what the field in called in DWARF 4 and 5. It's always easier to follow the code with the standard on the side when we use the same terminology. Change-Id: I3ad1022afd9410b193ea11b9b5437686c1e4e633
2022-04-21Always use dwarf2_initialize_objfileTom Tromey2-13/+5
Internally we noticed that some tests would fail like so on Windows: warning: Section .debug_aranges in [...] has duplicate debug_info_offset 0x0, ignoring .debug_aranges. Debugging showed that, in fact, a second CU was being created at this offset. We tracked this down to the fact that, while the ELF reader is careful to re-use the per-BFD data, other readers are not, and could re-read the DWARF data multiple times. However, since the change to allow an objfile to have multiple "quick symbol" implementations, there's no reason for this approach -- it's safe and easy for all symbol readers to reuse the per-BFD data when reading DWARF. This patch implements this idea, simplifying dwarf2_build_psymtabs and making it private, and then switching to dwarf2_initialize_objfile as the sole way to start the DWARF reader. Note that, while I think the call to dwarf2_build_frame_info in machoread.c is also obsolete, I haven't attempted to remove it here.
2022-04-21gdbsupport: add path_join functionSimon Marchi2-24/+21
In this review [1], Eli pointed out that we should be careful when concatenating file names to avoid duplicated slashes. On Windows, a double slash at the beginning of a file path has a special meaning. So naively concatenating "/" and "foo/bar" would give "//foo/bar", which would not give the desired results. We already have a few spots doing: if (first_path ends with a slash) path = first_path + second_path else path = first_path + slash + second_path In general, I think it's nice to avoid superfluous slashes in file paths, since they might end up visible to the user and look a bit unprofessional. Introduce the path_join function that can be used to join multiple path components together (along with unit tests). I initially wanted to make it possible to join two absolute paths, to support the use case of prepending a sysroot path to a target file path, or the prepending the debug-file-directory to a target file path. But the code in solib_find_1 shows that it is more complex than this anyway (for example, when the right hand side is a Windows path with a drive letter). So I don't think we need to support that case in path_join. That also keeps the implementation simpler. Change a few spots to use path_join to show how it can be used. I believe that all the spots I changed are guarded by some checks that ensure the right hand side operand is not an absolute path. Regression-tested on Ubuntu 18.04. Built-tested on Windows, and I also ran the new unit-test there. [1] https://sourceware.org/pipermail/gdb-patches/2022-April/187559.html Change-Id: I0df889f7e3f644e045f42ff429277b732eb6c752
2022-04-20Replace symbol_symtab with symbol::symtabTom Tromey1-6/+6
This turns symbol_symtab into a method on symbol. It also replaces symbol_set_symtab with a method.
2022-04-20Add accessors for symbol's artificial fieldTom Tromey1-1/+1
For a series I'm experimenting with, it was handy to hide a symbol's "artificial" field behind accessors. This patch is the result.
2022-04-20Unify the DWARF index holdersTom Tromey3-73/+72
The dwarf2_per_bfd object has a separate field for each possible kind of index. Until an earlier patch in this series, two of these were even derived from a common base class, but still had separate slots. This patch unifies all the index fields using the common base class that was introduced earlier in this series. This makes it more obvious that only a single index can be active at a time, and also removes some code from dwarf2_initialize_objfile.
2022-04-20Add an ad hoc version check to dwarf_scanner_baseTom Tromey2-2/+15
Some generic code in the DWARF reader has a special case for older versions of .gdb_index. This patch adds an ad hoc version check method so that these spots can work without specific knowledge of which index is in use.
2022-04-20Simplify version check in dw2_symtab_iter_nextTom Tromey1-5/+5
This simplifies the index versio check in dw2_symtab_iter_next, by passing a reference to the index object to this function. This avoids an indirection via the per_bfd object.
2022-04-20Introduce and use dwarf_scanner_baseTom Tromey3-8/+26
This introduces dwarf_scanner_base, a base class for all the index readers in the DWARF code. Then, it changes both mapped_index_base and cooked_index_vector to derive from this new base class.
2022-04-20Introduce readnow_functionsTom Tromey1-53/+56
This introduces readnow_functions, a new subclass of dwarf2_base_index_functions, and changes the DWARF reader to use it. This lets us drop the "index is NULL" hack from the gdb index code.
2022-04-20Remove some "OBJF_READNOW" code from dwarf2_debug_names_indexTom Tromey1-16/+1
The dwarf2_debug_names_index code treats a NULL debug_names_table as if it were from OBJF_READNOW. However, this trick is only done for gdb_index, never for debug_names -- see dwarf2_initialize_objfile.
2022-04-20Let mapped index classes create the quick_symbol_functions objectTom Tromey2-7/+28
This changes the mapped index classes to create the quick_symbol_functions objects. This is a step toward having a more abstract interface to mapped indices.
2022-04-20Give mapped_index_base a virtual destructorTom Tromey1-4/+1
This changes mapped_index_base to have a virtual destructor, so it can be destroyed via its base class.
2022-04-20Move mapped_index_base to new header fileTom Tromey3-72/+98
This moves mapped_index_base and the helper struct name_component to a new header file in gdb/dwarf2/.