aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2
AgeCommit message (Collapse)AuthorFilesLines
2024-01-28Fix latent bug in DW_TAG_entry_point handlingTom Tromey1-0/+7
A DW_TAG_entry_point symbol inherits its extern/static property from the enclosing subroutine. This is encoded in new_symbol -- but the cooked indexer does not agree.
2024-01-28Small cleanup in DWARF readerTom Tromey1-2/+2
I noticed a couple of spots in dwarf/read.c:new_symbol that call add_symbol_to_list. However, this function is generally written to set list_to_add, and then have a single call to add_symbol_to_list at the end. This patch cleans up this discrepancy. Note that new_symbol is overlong and should probably be split up.
2024-01-28Fix bug in cooked index scannerTom Tromey1-0/+6
Testing this entire series pointed out that the cooked index scanner disagrees with new_symbol about certain symbols. In particular, new_symbol has this comment: Ada and Fortran subprograms, whether marked external or not, are always stored as a global symbol, because we want This patch updates the scanner to match. I don't know why the current code does not cause failures. It's maybe worth noting that incremental CU expansion -- creating symtabs directly from the index -- would eliminate this sort of bug.
2024-01-24Handle DW_AT_endianity on enumeration typesTom Tromey1-23/+43
A user found that gdb would not correctly print a field from an Ada record using the scalar storage order feature. We tracked this down to a combination of problems. First, GCC did not emit DW_AT_endianity on the enumeration type. DWARF does not specify this, but it is an obvious and harmless extension. This was fixed in GCC recently: https://gcc.gnu.org/pipermail/gcc-patches/2024-January/642347.html https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=5d8b60effc7268448a94fbbbad923ab6871252cd Second, GDB did not handle this attribute on enumeration types. This patch makes this change and adds a test case that will pass with the patched GCC. So far, the GCC patch isn't on the gcc-13 branch; but if it ever goes in, the test case in this patch can be updated to reflect that. Reviewed-By: Keith Seitz <keiths@redhat.com>
2024-01-22Fix handling of DW_OP_GNU_push_tls_addressTom Tromey1-1/+1
In one spot, DW_OP_GNU_push_tls_address is handled differently from DW_OP_form_tls_address. However, I think they should always be treated identically. Approved-by: Kevin Buettner <kevinb@redhat.com>
2024-01-19gdb: remove SYMBOL_*_OPS macrosSimon Marchi2-13/+12
Remove SYMBOL_BLOCK_OPS, SYMBOL_COMPUTED_OPS and SYMBOL_REGISTER_OPS, in favor of methods on struct symbol. More changes could be done here to improve the design and make things safer, but I just wanted to do a straightforward change to remove the macros for now. Change-Id: I27adb74a28ea3c0dc9a85c2953413437cd95ad21 Reviewed-by: Kevin Buettner <kevinb@redhat.com>
2024-01-19Simplify DWARF symtab inclusion handlingTom Tromey2-66/+16
In the past, dwarf2_per_cu_data was allocated using malloc, so special handling was needed for the vector used for symtab handling. We changed this to use 'new' a while back, so this code can now be greatly simplified. Regression tested on x86-64 Fedora 38. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-01-18Rewrite .debug_names writerTom Tromey1-239/+156
This rewrites GDB's .debug_names writer. It is now closer to the form imagined in the DWARF spec. In particular, names are emitted exactly as they appear in the original DWARF. In order to make the reader work nicely, some extensions were needed. These were all documented in an earlier patch. Note that in particular this writer solves the "main name" problem by putting a flag into the table. GDB does not use the .debug_names hash table, so it also does not write one. I consider this hash table to be essentially useless in general, due to the name canonicalization problem -- while DWARF says that writers should use the system demangling style, (1) this style varies across systems, so it can't truly be relied on; and (2) at least GCC and one other compiler don't actually follow this part of the spec anyway. It's important to note, though, that even if the hash was somehow useful, GDB probably still would not use it -- a sorted list of names is needed for completion and performs reasonably well for other lookups, so a hash table is just overhead, IMO. String emission is also simplified. There's no need in this writer to ingest the contents of .debug_str. A couple of tests are updated to reflect the fact that they now "fail" because the tests don't include .debug_aranges in the .S file. Arguably the .debug_names writer should also create this section; but I did not implement that in this series, and there is a separate bug about it. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24820 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24549
2024-01-18Export dwarf5_augmentationTom Tromey2-2/+3
I don't know why gdb had the .debug_names augmentation string in two separate places; this patch exports it in one spot, to be used in another.
2024-01-18Rewrite .debug_names readerTom Tromey1-583/+371
This rewrites the .debug_names reader to follow the spec. Since it was first written, gdb's .debug_names writer has been incorrect -- while the form of the section has been ok, the contents have been very gdb-specific. This patch fixes the reader side of this equation, rewriting the reader to create a cooked index internally -- an important detail because it allows for the deletion of a lot of code, and it means the various readers will agree more often. This reader checks for a new augmentation string. For the time being, all other producers are ignored -- the old GDB ones because they are wrong, and clang because it does not emit DW_IDX_parent. (If there are any other producers, I'm unaware of them.) While the new reader mostly runs in a worker thread, it does not try to distribute its work. This could be done by partitioning the name table. The parent computations could also be done in parallel after all names have been read. I haven't attempted this. Note that this patch temporarily regresses gdb.base/gdb-index-err.exp. This test writes an index using gdb -- but at this particular stage, gdb cannot read the indexes it creates. Rather than merge the patches into a mega-patch, I've chosen to just accept this temporary regression. In v1 of this patch, I made the new reader more strict about requiring .debug_aranges. In v2, I've backed this out and kept the previous logic. This solved a few test failures, though it's arguably not the right approach. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25950
2024-01-18Empty hash table fix in .debug_names readerTom Tromey1-1/+2
The handling of an empty hash table in the .debug_names reader is slightly wrong. Currently the code assumes there is always an array of hashes. However, section 6.1.1.4.5 Hash Lookup Table says: The optional hash lookup table immediately follows the list of type signatures. and then: The hash lookup table is actually two separate arrays: an array of buckets, followed immediately by an array of hashes. My reading of this is that the hash table as a whole is optional, and so the hashes will not exist in this case. (This also makes sense because the hashes are not useful without the buckets anyway.) Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25950
2024-01-18Remove cooked_index_worker::start_readingTom Tromey2-30/+17
I noticed that cooked_index_worker::start_reading isn't really needed. This patch removes it, and also removes the SCOPED_EXIT, in favor of a direct call.
2024-01-18Change cooked_index_worker to abstract base classTom Tromey3-161/+204
This changes cooked_index_worker to be an abstract base class. The base class implementation is moved to cooked-index.c, and a concrete subclass is added to read.c. This change is preparation for the new .debug_names reader, which will supply its own concrete implementation of the worker.
2024-01-18Do not write the index cache from an indexTom Tromey3-5/+8
The new .debug_names reader will work by creating a cooked index from .debug_names. This patch updates cooked_index::maybe_write_index to avoid writing the index in this case. However, in order to do this in a clean way, the readers are changed so that a nullptr result from index_for_writing means "cannot be done", and then the error message is moved into write_dwarf_index (where it historically lived).
2024-01-18Move cooked_index_functions to cooked-index.hTom Tromey3-100/+100
This moves the declaration of cooked_index_functions to cooked-index.h. This makes it visible for use by the rewritten .debug_names reader, and it also lets us move the implementation of make_quick_functions into cooked-index.c, where it really belongs.
2024-01-18Add language to cooked_index_entryTom Tromey3-17/+23
This adds a new 'lang' member to cooked_index_entry. This holds the language of the symbol. This is primarily useful for the new .debug_names reader, which will not scan the CUs for languages up front. This also changes cooked_index_shard::add to return a non-const pointer. This doesn't impact the current code, but is needed for the new reader.
2024-01-18Remove IS_ENUM_CLASS from cooked_index_flagTom Tromey3-12/+11
I noticed that cooked_index_flag::IS_ENUM_CLASS is not needed. This patch removes it.
2024-01-18Refactor quick-function installation in DWARF readerTom Tromey1-24/+14
While working on the previous patch, I saw that the handling of quick-function installation could be unified dwarf2_initialize_objfile. In particular, at the end of the function, if there is an index table, then it can be used to create the quick function object. This cleanup will be useful when rewriting the .debug_names reader.
2024-01-18Refactor 'maint set dwarf synchronous' handlingTom Tromey1-3/+4
The new .debug_names reader will reuse the background reading infrastructure of the cooked index code. In order to share the handling of 'maint set dwarf synchronous' -- and to avoid having to export this global -- this patch refactors this to be handled directly in dwarf2_initialize_objfile.
2024-01-17Fix crash in struct-with-sig-2.exp with debug-names target boardTom Tromey1-0/+2
When I run the struct-with-sig-2.exp test with the .debug_names-using target board, I see a gdb crash. This happens because the reader throws an exception without calling finalize_all_units. This causes an assertion failure later because the number of CUs and TUs doesn't match. The fix is to clear 'all_units' on failure. Approved-By: Tom de Vries <tdevries@suse.de>
2024-01-15Remove addrmap_fixed::set_entryTom Tromey3-7/+7
It occurred to me that there is no reason for addrmap_fixed::set_entry to exist. This patch removes it and removes the abstract virtual function from the base class. This then required a few minor changes in the DWARF reader. I consider this a type-safety improvement. Tested by rebuilding. Reviewed-By: Tom de Vries <tdevries@suse.de>
2024-01-12Update copyright year range in header of all files managed by GDBAndrew Burgess56-56/+56
This commit is the result of the following actions: - Running gdb/copyright.py to update all of the copyright headers to include 2024, - Manually updating a few files the copyright.py script told me to update, these files had copyright headers embedded within the file, - Regenerating gdbsupport/Makefile.in to refresh it's copyright date, - Using grep to find other files that still mentioned 2023. If these files were updated last year from 2022 to 2023 then I've updated them this year to 2024. I'm sure I've probably missed some dates. Feel free to fix them up as you spot them.
2024-01-10gdb/symtab: Eliminate deferred_entryTom de Vries3-31/+68
Currently cooked_index entry creation is either: - done immediately if the parent_entry is known, or - deferred if the parent_entry is not yet known, and done later while resolving the deferred entries. Instead, create all cooked_index entries immediately, and keep track of which entries have a parent_entry that needs resolving later using the new IS_PARENT_DEFERRED flag. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-01-10gdb/symtab: Make cooked_index_entry::parent_entry privateTom de Vries3-16/+29
Make cooked_index_entry::parent_entry private, and add member functions to access it. Tested on x86_64-linux and ppc64le-linux. Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com> Approved-By: Tom Tromey <tom@tromey.com>
2024-01-10gdb/symtab: Allow changing of added cooked_index entriesTom de Vries2-11/+11
Make cooked_index_storage::add and cooked_index_entry::add return a "cooked_index_entry *" instead of a "const cooked_index_entry *". Tested on x86_64-linux and ppc64le-linux. Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com> Approved-By: Tom Tromey <tom@tromey.com>
2024-01-09Fix ASAN failure in DWO codeTom Tromey1-8/+23
Simon pointed out that my recent change to the DWO code caused a failure in ASAN testing. The bug here was I updated the code to use a different search type in the hash table; but then did not change the search code to use htab_find_slot_with_hash. Note that this bug would not be possible with my type-safe hash table series, hint, hint. Approved-By: Simon Marchi <simon.marchi@efficios.com>
2024-01-09Fix thread-less buildTom Tromey1-4/+4
A user pointed out that the recent background DWARF reader series broke the build when --disable-threading is in use. This patch fixes the problem. I am checking it in. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31223
2024-01-09Use unrelocated_addr in dwarf2_base_index_functions::find_per_cuTom Tromey4-12/+14
dwarf2_base_index_functions::find_per_cu is documented as using an unrelocated address. This patch changes the interface to use the unrelocated_addr type, just to be a bit more type-safe. Regression tested on x86-64 Fedora 38.
2024-01-08Simplify the public DWARF APITom Tromey2-34/+33
dwarf2_has_info and dwarf2_initialize_objfile are only separate because the DWARF reader implemented lazy psymtab reading. However, now that this is gone, we can simplify the public DWARF API again.
2024-01-08Do more DWARF reading in the backgroundTom Tromey4-298/+638
This patch rearranges the DWARF reader so that more work is done in the background. This is PR symtab/29942. The idea here is that there is only a small amount of work that must be done on the main thread when scanning DWARF -- before the main scan, the only part is mapping the section data. Currently, the DWARF reader uses the quick_symbol_functions "lazy" functionality to defer even starting to read. This patch instead changes the reader to start reading immediately, but doing more in worker tasks. Before this patch, "file" on my machine: (gdb) file /tmp/gdb 2023-10-23 12:29:56.885 - command started Reading symbols from /tmp/gdb... 2023-10-23 12:29:58.047 - command finished Command execution time: 5.867228 (cpu), 1.162444 (wall) After the patch, more work is done in the background and so this takes a bit less time: (gdb) file /tmp/gdb 2023-10-23 13:25:51.391 - command started Reading symbols from /tmp/gdb... 2023-10-23 13:25:51.712 - command finished Command execution time: 1.894500 (cpu), 0.320306 (wall) I think this could be further sped up by using the shared library load map to avoid objfile loops like the one in expand_symtab_containing_pc -- it seems like the correct objfile could be chosen more directly. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29942 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30174
2024-01-08Change how cooked index waits for threadsTom Tromey2-3/+2
This changes the cooked index code to wait for threads in its public-facing API. That is, the waits are done in cooked_index now, and never in the cooked_index_shard. Centralizing this decision makes it easier to wait for other events here as well.
2024-01-08Add "maint set dwarf synchronous"Tom Tromey1-0/+27
For testing, it's sometimes convenient to be able to request that DWARF reading be done synchronously. This patch adds a new "maint" setting for this purpose. Reviewed-By: Eli Zaretskii <eliz@gnu.org>
2024-01-08Move cooked_index_storage to cooked-index.hTom Tromey2-94/+111
This moves cooked_index_storage to cooked-index.h. This is needed by a subsequent patch.
2024-01-08Add deferred_warnings parameter to read_addrmap_from_arangesTom Tromey4-41/+53
When DWARF reading is done in the background, read_addrmap_from_aranges will be called from a worker thread. Because warnings can't be emitted from these threads, this patch adds a new deferred_warnings parameter to the function, letting the caller control exactly how the warnings are emitted.
2024-01-08Refactor complaint thread-safety approachTom Tromey1-13/+18
This patch changes the way complaint works in a background thread. The new approach requires installing a complaint interceptor in each worker, and then the resulting complaints are treated as one of the results of the computation. This change is needed for a subsequent patch, where installing a complaint interceptor around a parallel-for is no longer a viable approach.
2024-01-08Add thread-safety to gdb's BFD wrappersTom Tromey1-2/+1
This changes gdb to ensure that gdb's BFD cache is guarded by a lock. This avoids any races when multiple threads might open a BFD (and thus use the BFD cache) at the same time. Currently, this change is not needed because the the main thread waits for some DWARF scanning to be completed before returning. The only locking that's required is when opening DWO files, and there's a local lock to this end in dwarf2/read.c. However, in the coming patches, the DWARF reader will begin its work earlier, in the background. This means there is the potential for the DWARF reader and other code on the main thread to both attempt to open BFDs at the same time.
2024-01-08Add a couple of bfd_cache_close callsTom Tromey1-0/+4
This adds a couple of calls to bfd_cache_close at points where a BFD isn't actively needed by gdb. Normally at these points, all the needed section data is already mapped, so we can simply close the file descriptor. This is harmless at worst, because if this is needed after all, the BFD file descriptor cache will reopen it.
2024-01-08Pre-read DWZ section dataTom Tromey6-67/+56
This changes the DWZ code to pre-read the section data and somewhat simplify the DWZ API. This makes it easier to add the bfd_cache_close call to the new dwarf2_read_dwz_file function -- after this is done, there shouldn't be a reason to keep the BFD's file descriptor open.
2024-01-08Don't use objfile::intern in DWO codeTom Tromey1-10/+21
The DWO code in the DWARF reader currently uses objfile::intern. This accesses a shared data structure and so would be racy when used from multiple threads. I don't believe this can happen right now, but background reading could provoke this, and in any case it's better to avoid this, just to be sure. This patch changes this code to just use a std::string. A new type is introduced to do hash table lookups, to avoid unnecessary copies.
2024-01-02gdb/dwarf2: Add support for DW_LNS_set_epilogue_begin in line-tableGuinevere Larsen1-1/+13
This commit adds a mechanism for GDB to detect the linetable opcode DW_LNS_set_epilogue_begin. This opcode is set by compilers to indicate that a certain instruction marks the point where the frame is destroyed. While the standard allows for multiple points marked with epilogue_begin in the same function, for performance reasons, the function that searches for the epilogue address will only find the last address that sets this flag for a given block. This commit also changes amd64_stack_frame_destroyed_p_1 to attempt to use the epilogue begin directly, and only if an epilogue can't be found will it attempt heuristics based on the current instruction. Finally, this commit also changes the dwarf assembler to be able to emit epilogue-begin instructions, to make it easier to test this patch Approved-By: Tom Tromey <tom@tromey.com>
2023-12-29dwarf, fortran: add support for DW_TAG_entry_pointNils-Christian Kempke4-5/+72
Fortran provides additional entry points for subroutines and functions. These entry points may use only a subset (or a different set) of the parameters of the original subroutine. The entry points may be described via the DWARF tag DW_TAG_entry_point. This commit adds support for parsing the DW_TAG_entry_point DWARF tag. Currently, between ifx/ifort/gfortran, only ifort is actually emitting this tag. Both, ifx and gfortran use the DW_TAG_subprogram tag as workaround/alternative. Thus, this patch really only adds more ifort support. Even so, some of the attached tests still fail for ifort, due to some wrong line info generated for the entry points in ifort. After this patch it is possible to set a breakpoint in gdb with the ifort compiled example at the entry points 'foo' and 'foobar', which was not possible before. As gcc and ifx do not emit the tag I also added a test to gdb.dwarf2 which uses some underlying c compiled code and adds some Fortran style DWARF to it emitting the DW_TAG_entry_point. Before this patch it was not possible to actually define breakpoint at the entry point tags. For gfortran there actually exists a bug on bugzilla, asking for the use of DW_TAG_entry_point over DW_TAG_subprogram: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37134 This patch was originally posted here https://sourceware.org/legacy-ml/gdb-patches/2017-07/msg00317.html but its review/pinging got lost after a while. I reworked it to fit the current GDB. Co-authored-by: Bernhard Heckel <bernhard.heckel@intel.com> Co-authored-by: Tim Wiederhake <tim.wiederhake@intel.com> Approved-by: Tom Tromey <tom@tromey.com>
2023-12-29gdb, dwarf: add assert to dwarf2_get_pc_boundsNils-Christian Kempke1-0/+1
In dwarf2_get_pc_bounds we were writing unchecked to *lowpc. This commit adds a gdb_assert to first check that lowpc != nullptr. Approved-by: Tom Tromey <tom@tromey.com>
2023-12-29gdb, dwarf: move part of dwarf2_get_pc_bounds into separate functionNils-Christian Kempke1-21/+50
This commit is in preparation of the next commit. There, we will add a second variation to retrieve the pc bounds for DIEs tagged with DW_TAG_entry_point. Instead of dwarf_get_pc_bounds_ranges_or_highlow_pc we will call a separate method for entry points. As the validity checks at the endo f dwarf2_get_pc_bounds are the same for both variants, we introduced the new dwarf_get_pc_bounds_ranges_or_highlow_pc method, outsourcing part of dwarf2_get_pc_bounds. This commit should have no functional impact on GDB. Approved-by: Tom Tromey <tom@tromey.com>
2023-12-16Use function entry point record only for entry valuesHannes Domani2-4/+6
PR28987 notes that optimized code sometimes shows the wrong value of variables at the entry point of a function, if some code was optimized away and the variable has multiple values stored in the debug info for this location. In this example: ``` void foo() { int l_3 = 5, i = 0; for (; i < 8; i++) ; test(l_3, i); } ``` When compiled with optimization, the entry point of foo is at the test() function call, since everything else is optimized away. The debug info of i looks like this: ``` (gdb) info address i Symbol "i" is multi-location: Base address 0x140001600 Range 0x13fd41600-0x13fd41600: the constant 0 Range 0x13fd41600-0x13fd41600: the constant 1 Range 0x13fd41600-0x13fd41600: the constant 2 Range 0x13fd41600-0x13fd41600: the constant 3 Range 0x13fd41600-0x13fd41600: the constant 4 Range 0x13fd41600-0x13fd41600: the constant 5 Range 0x13fd41600-0x13fd41600: the constant 6 Range 0x13fd41600-0x13fd41600: the constant 7 Range 0x13fd41600-0x13fd4160f: the constant 8 (gdb) p i $1 = 0 ``` Currently, when at the entry point of a function, it will always show the initial value (here 0), while the user would expect the last value (here 8). This logic was introduced for showing the entry-values of function arguments if they are available, but for some reason this was added for non-entry-values as well. One of the tests of amd64-entry-value.exp shows the same problem for function arguments, if you "break stacktest" in the following example, you stop at this line: ``` 124 static void __attribute__((noinline, noclone)) 125 stacktest (int r1, int r2, int r3, int r4, int r5, int r6, int s1, int s2, 126 double d1, double d2, double d3, double d4, double d5, double d6, 127 double d7, double d8, double d9, double da) 128 { 129 s1 = 3; 130 s2 = 4; 131 d9 = 3.5; 132 da = 4.5; 133 -> e (v, v); 134 asm ("breakhere_stacktest:"); 135 e (v, v); 136 } ``` But `bt` still shows the entry values: ``` s1=s1@entry=11, s2=s2@entry=12, ..., d9=d9@entry=11.5, da=da@entry=12.5 ``` I've fixed this by only using the initial values when explicitely looking for entry values. Now the local variable of the first example is as expected: ``` (gdb) p i $1 = 8 ``` And the test of amd64-entry-value.exp shows the expected current and entry values of the function arguments: ``` s1=3, s1@entry=11, s2=4, s2@entry=12, ..., d9=3.5, d9@entry=11.5, da=4.5, da@entry=12.5 ``` Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28987 Tested-By: Guinevere Larsen <blarsen@redhat.com> Approved-By: Tom Tromey <tom@tromey.com>
2023-12-14gdb: read pseudo register through frameSimon Marchi1-1/+4
Change gdbarch_pseudo_register_read_value to take a frame instead of a regcache. The frame (and formerly the regcache) is used to read raw registers needed to make up the pseudo register value. The problem with using the regcache is that it always provides raw register values for the current frame (frame 0). Let's say the user wants to read the ebx register on amd64. ebx is a pseudo register, obtained by reading the bottom half (bottom 4 bytes) of the rbx register, which is a raw register. If the currently selected frame is frame 0, it works fine: (gdb) frame 0 #0 break_here_asm () at /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.arch/amd64-pseudo-unwind-asm.S:36 36 in /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.arch/amd64-pseudo-unwind-asm.S (gdb) p/x $ebx $1 = 0x24252627 (gdb) p/x $rbx $2 = 0x2021222324252627 But if the user is looking at another frame, and the raw register behind the pseudo register has been saved at some point in the call stack, then we get a wrong answer: (gdb) frame 1 #1 0x000055555555517d in caller () at /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.arch/amd64-pseudo-unwind-asm.S:56 56 in /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.arch/amd64-pseudo-unwind-asm.S (gdb) p/x $ebx $3 = 0x24252627 (gdb) p/x $rbx $4 = 0x1011121314151617 Here, the value of ebx was computed using the value of rbx in frame 0 (through the regcache), it should have been computed using the value of rbx in frame 1. In other to make this work properly, make the following changes: - Make dwarf2_frame_prev_register return nullptr if it doesn't know how to unwind a register and that register is a pseudo register. Previously, it returned `frame_unwind_got_register`, meaning, in our example, "the value of ebx in frame 1 is the same as the value of ebx in frame 0", which is obviously false. Return nullptr as a way to say "I don't know". - In frame_unwind_register_value, when prev_register (for instance dwarf2_frame_prev_register) returns nullptr, and we are trying to read a pseudo register, try to get the register value through gdbarch_pseudo_register_read_value or gdbarch_pseudo_register_read. If using gdbarch_pseudo_register_read, the behavior is known to be broken. Implementations should be migrated to use gdbarch_pseudo_register_read_value to fix that. - Change gdbarch_pseudo_register_read_value to take a frame_info instead of a regcache, update implementations (aarch64, amd64, i386). In i386-tdep.c, I made a copy of i386_mmx_regnum_to_fp_regnum that uses a frame instead of a regcache. The version using the regcache is still used by i386_pseudo_register_write. It will get removed in a subsequent patch. - Add some helpers in value.{c,h} to implement the common cases of pseudo registers: taking part of a raw register and concatenating multiple raw registers. - Update readable_regcache::{cooked_read,cooked_read_value} to pass the current frame to gdbarch_pseudo_register_read_value. Passing the current frame will give the same behavior as before: for frame 0, raw registers will be read from the current thread's regcache. Notes: - I do not plan on changing gdbarch_pseudo_register_read to receive a frame instead of a regcache. That method is considered deprecated. Instead, we should be working on migrating implementations to use gdbarch_pseudo_register_read_value instead. - In frame_unwind_register_value, we still ask the unwinder to try to unwind pseudo register values. It's apparently possible for the debug info to provide information about [1] pseudo registers, so we want to try that first, before falling back to computing them ourselves. [1] https://inbox.sourceware.org/gdb-patches/20180528174715.A954AD804AD@oc3748833570.ibm.com/ Change-Id: Id6ef1c64e19090a183dec050e4034d8c2394e7ca Reviewed-by: John Baldwin <jhb@FreeBSD.org>
2023-12-14gdb: make get_frame_register_bytes take the next frameSimon Marchi1-11/+11
Similar to the previous patches, change get_frame_register_bytes to take the "next frame" instead of "this frame". Change-Id: Ie8f35042bfa6e93565fcefaee71b6b3903f0fe9f Reviewed-By: John Baldwin <jhb@FreeBSD.org>
2023-12-14gdb: make put_frame_register_bytes take the next frameSimon Marchi1-3/+3
Similar to the previous patches, change put_frame_register_bytes to take the "next frame" instead of "this frame". Change-Id: I27bcb26573686d99b231230823cff8db6405a788 Reviewed-By: John Baldwin <jhb@FreeBSD.org>
2023-12-13gdb: improve error reporting for 'save gdb-index'Andrew Burgess1-1/+9
While making recent changes to 'save gdb-index' command I triggered some errors -- of the kind a user might be expected to trigger if they do something wrong -- and I didn't find GDB's output as helpful as it might be. For example: $ gdb -q /tmp/hello.x ... (gdb) save gdb-index /non_existing_dir Error while writing index for `/tmp/hello': mkstemp: No such file or directory. That the error message mentions '/tmp/hello', which does exist, but doesn't mention '/non_existing_dir', which doesn't is, I think, confusing. Also, I find the 'mkstemp' in the error message confusing for a user facing error. A user might not know what mkstemp means, and even if they do, that it appears in the error message is an internal GDB detail. The user doesn't care what function failed, but wants to know what was wrong with their input, and what they should do to fix things. Similarly, for a directory that does exist, but can't be written to: (gdb) save gdb-index /no_access_dir Error while writing index for `/tmp/hello': mkstemp: Permission denied. In this case, the 'Permission denied' might make the user thing there is a permissions issue with '/tmp/hello', which is not the case. After this patch, the new errors are: (gdb) save gdb-index /non_existing_dir Error while writing index for `/tmp/hello': `/non_existing_dir': No such file or directory. and: (gdb) save gdb-index /no_access_dir Error while writing index for `/tmp/hello': `/no_access_dir': Permission denied. we also have: (gdb) save gdb-index /tmp/not_a_directory Error while writing index for `/tmp/hello': `/tmp/not_a_directory': Is not a directory. I think these do a better job of guiding the user towards fixing the problem. I've added a new test that exercises all of these cases, and also checks the case where a user tries to use an executable that already contains an index in order to generate an index. As part of the new test I've factored out some code from ensure_gdb_index (lib/gdb.exp) into a new proc (get_index_type), which I've then used in the new test. I've confirmed that all the tests that use ensure_gdb_index still pass. During review it was pointed out that the testsuite proc have_index (lib/gdb.exp) is similar to the new get_index_type proc, so I've rewritten have_index to also use get_index_type, I've confirmed that all the tests that use have_index still pass. Nothing that worked correctly before this patch should give an error after this patch; I've only changed the output when the user was going to get an error anyway. Reviewed-By: Tom de Vries <tdevries@suse.de> Reviewed-By: Tom Tromey <tom@tromey.com> Approved-By: Tom Tromey <tom@tromey.com>
2023-12-06Remove quick_symbol_functions::expand_matching_symbolsTom Tromey3-290/+0
The only caller of quick_symbol_functions::expand_matching_symbols was removed, so now this method and all implementations of it can be removed.
2023-12-06Always use expand_symtabs_matching in ada-lang.cTom Tromey1-1/+5
The previous patch fixed the immediate performance problem with Ada name matching, by having a subset of matches call expand_symtabs_matching rather than expand_matching_symbols. However, it seemed to me that expand_matching_symbols should not be needed at all. To achieve this, this patch changes ada_lookup_name_info::split_name to use the decoded name, rather than the encoded name. In order to make this work correctly, a new decoded form is used: one that does not decode operators (this is already done) and also does not decode wide characters. The latter change is done so that changes to the Ada source charset don't affect the DWARF index. With this in place, we can change ada-lang.c to always use expand_symtabs_matching rather than expand_matching_symbols.