aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.dwarf2
AgeCommit message (Collapse)AuthorFilesLines
2025-03-10Revert past commitsSimon Marchi2-109/+1
I accidentally pushed my work-in-progress branch... revert that. Sorry for the noise :(. The list of commits reverted are: ae2a50a9ae15 attempt to revamp to the CU/TU list e9386435c94f gdb/dwarf: print DWARF CUs/TUs in "maint print objfiles" 6cbd64aa3eb0 gdb/dwarf: add dwarf_source_language_name 32a187da7622 libiberty: move DW_LANG_* definitions to dwarf2.def b3fa38aef59d gdb/dwarf: move index unit vectors to debug names reader and use them 30ba74418982 gdb/dwarf: track comp and type units count bedb4e09f292 gdb/dwarf: remove unnecessary braces b4f18de12c77 gdb/dwarf: use ranged for loop in some pots Change-Id: I80aed2847025f5b15c16c997680783b39858a703
2025-03-10attempt to revamp to the CU/TU listSimon Marchi2-1/+109
Change-Id: I1c8214413583d540c10c9a2322ef2a21f8bb54e7
2025-03-07Avoid excessive CU expansion on failed matchesTom Tromey1-0/+42
PR symtab/31010 points out that something like "ptype INT" will expand all CUs in a typical program. The OP further points out that the original patch for PR symtab/30520: https://sourceware.org/pipermail/gdb-patches/2024-January/205924.html ... did solve the problem, but the patch changed after (my) review and reintroduced the bug. In cooked_index_functions::expand_symtabs_matching, the final component of a split name is compared with the entry's name using the usual method of calling get_symbol_name_matcher. This code iterates over languages and tries to split the original name according to each style. But, the Ada splitter uses the decoded name -- "int". This causes every C or C++ CU to be expanded. Clearly this is wrong. And, it seems to me that looping over languages and trying to guess the splitting style for the input text is probably bad. However, fixing the problem is not so easy (again due to Ada). I've filed a follow-up bug, PR symtab/32733, for this. Meanwhile, this patch changes the code to be closer to the originally-submitted patch. This works because the comparison is now done between the full name and the "lookup_name_without_params" object, which is a less adulterated variant of the original input. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31010 Tested-By: Simon Marchi <simon.marchi@efficios.com>
2025-03-03Add language to type unit in debug-names-tu.exp.tclTom Tromey1-2/+3
I think debug-names-tu.exp.tcl only passes by accident -- the type unit does not have a language, which gdb essentially requires. This isn't noticeable right now because the type unit in question is expanded in one phase and then the symbol found in another. However, I'm working on a series that would regress this. This patch partially fixes the problem by correcting the test case, adding the language to the TU. Hoewver, it then goes a bit further and arranges for this information not to be written to .debug_names. Whether or not a type should be considered "static" seems like something that is purely internal to gdb, so this patch has the entry-creation function apply the appropriate transform. It also may make sense to change the "debug_names" proc in the test suite to process attributes more like the ordinary "cu" proc does.
2025-02-18[gdb] Fix some typosTom de Vries1-1/+1
Fix typos: ... overriden -> overridden reate -> create ... Tested on x86_64-linux. I
2025-02-14gdb: only update m_last_subfile after writing a line table entryAndrew Burgess2-0/+261
While working on another patch which changes how we parse the line DWARF line tables I noticed what I think is a minor bug in how we process the line tables. What I noticed is that my new line table parser was adding more END markers into the parsed table than GDB's current approach. This difference was observed when processing the debug information for libstdc++. Here is the line table from the new test, this is a reasonable reproduction of the problem case that I observed in the actual debug line table: Contents of the .debug_line section: dw2-skipped-line-entries-1.c: File name Line number Starting address View Stmt dw2-skipped-line-entries-1.c 101 0x40110a x /tmp/dw2-skipped-line-entries-2.c: dw2-skipped-line-entries-2.c 201 0x401114 x /tmp/dw2-skipped-line-entries-3.c: dw2-skipped-line-entries-3.c 301 0x40111e x /tmp/dw2-skipped-line-entries-1.c: dw2-skipped-line-entries-1.c 102 0x401128 x dw2-skipped-line-entries-1.c 103 0x401128 x dw2-skipped-line-entries-1.c 104 0x401128 x /tmp/dw2-skipped-line-entries-2.c: dw2-skipped-line-entries-2.c 211 0x401128 /tmp/dw2-skipped-line-entries-3.c: dw2-skipped-line-entries-3.c 311 0x401132 /tmp/dw2-skipped-line-entries-1.c: dw2-skipped-line-entries-1.c 104 0x40113c dw2-skipped-line-entries-1.c 105 0x401146 x dw2-skipped-line-entries-1.c - 0x401150 The problem is caused by the entry for line 211. Notice that this entry is at the same address as the previous entries. Further, the entry for 211 is a non-statement entry, while the previous entries are statement entries. As the entry for line 211 is a non-statement entry, and the previous entries at that address are statement entries in a different symtab, it is thought that it is better to prefer the earlier entries (in dw2-skipped-line-entries-1.c), and so the entry for line 211 will be discarded. As GDB parses the line table it switches between the 3 symtabs (based on source filename) adding the relevant entries to each symtab. Additionally, as GDB switches symtabs, it adds an END entry to the previous symtab. The problem then is that, for the line 211 entry, this is the only entry in dw2-skipped-line-entries-2.c before we switch symtab again. But the line 211 entry is discarded. This means that GDB switches from dw2-skipped-line-entries-1.c to dw2-skipped-line-entries-2.c, and then on to dw2-skipped-line-entries-3.c without ever adding an entry to dw2-skipped-line-entries-2.c. And here then is the bug. GDB updates its idea of the previous symtab not when an entry is written into a symtab, but every time we change symtab. In this case, when we switch to dw2-skipped-line-entries-3.c we add the END marker to dw2-skipped-line-entries-2.c, even though no entries were written to dw2-skipped-line-entries-2.c. At the same time, no END marker is ever written into dw2-skipped-line-entries-1.c as the dw2-skipped-line-entries-2.c entry (for line 211) was discarded. Here is the 'maint info line-table' for dw2-skipped-line-entries-1.c before this patch: INDEX LINE REL-ADDRESS UNREL-ADDRESS IS-STMT PROLOGUE-END EPILOGUE-BEGIN 0 101 0x000000000040110a 0x000000000040110a Y 1 END 0x0000000000401114 0x0000000000401114 Y 2 102 0x0000000000401128 0x0000000000401128 Y 3 103 0x0000000000401128 0x0000000000401128 Y 4 104 0x0000000000401128 0x0000000000401128 Y 5 104 0x000000000040113c 0x000000000040113c 6 105 0x0000000000401146 0x0000000000401146 Y 7 END 0x0000000000401150 0x0000000000401150 Y And after this patch: INDEX LINE REL-ADDRESS UNREL-ADDRESS IS-STMT PROLOGUE-END EPILOGUE-BEGIN 0 101 0x000000000040110a 0x000000000040110a Y 1 END 0x0000000000401114 0x0000000000401114 Y 2 102 0x0000000000401128 0x0000000000401128 Y 3 103 0x0000000000401128 0x0000000000401128 Y 4 104 0x0000000000401128 0x0000000000401128 Y 5 END 0x0000000000401132 0x0000000000401132 Y 6 104 0x000000000040113c 0x000000000040113c 7 105 0x0000000000401146 0x0000000000401146 Y 8 END 0x0000000000401150 0x0000000000401150 Y Notice that we gained an extra entry, the END marker that was added at position #5 in the table. Now, does this matter? I cannot find any bugs that trigger because of this behaviour. So why fix it? First, the current behaviour is inconsistent, as we switch symtabs, we usually get an END marker in the previous symtab. But occasionally we don't. I don't like things that are inconsistent for no good reason. And second, as I said, I want to change the line table parsing. To do this I want to check that my new parser creates an identical table to the current parser. But my new parser naturally "fixes" this inconsistency, so I have two choices, do extra work to make my new parser bug-compatible with the current one, or fix the current one. I'd prefer to just fix the current line table parser. There's a test that includes the above example and checks that the END markers are put in the correct place. But as I said, I've not been able to trigger any negative behaviour from the current solution, so there's no test that exposes any broken behaviour. Approved-By: Tom Tromey <tom@tromey.com>
2025-02-04[gdb/testsuite] Use c++ flag in c++ test-casesTom de Vries4-4/+17
In some cases, test-cases use c++, but don't add "c++" to the compilation flags. This can cause problems with some compilers. Fix this in some test-cases. Approved-By: Tom Tromey <tom@tromey.com> PR testsuite/30380 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30380
2025-02-02Avoid "text file busy" in dw2-using-debug-str.expTom Tromey1-0/+12
When I run: runtest dw2-using-debug-str.exp ... if I examine the gdb.log, I see: objcopy: unable to copy file '[...]/dw2-using-debug-str'; reason: Text file busy This happens because the inferior is still running, and objcopy -- despite the invocation seemingly not needing this -- tries to open it for writing. This patch works around the objcopy oddity by having gdb exit (killing the inferior) before the invocation. Fixing this points out that the test does not work in the --target_board=cc-with-gdb-index case. This patch also arranges to issue an "untested" here.
2025-01-30Use "require" a two gdb.dwarf2 test filesTom Tromey2-9/+3
A couple of ".tcl" files in gdb.dwarf2 escaped notice during the "require" refactoring. This patch fixes these to use "require" rather than if/return.
2025-01-16[gdb/testsuite] Fix gdb.dwarf2/implptr.exp regressionTom de Vries1-1/+1
When running test-case gdb.dwarf2/implptr.exp on target board unix/-m32, we get: ... (gdb) PASS: gdb.dwarf2/implptr.exp: print ***l in implptr:bar break implptr.c:34^M No compiled code for line 34 in file "implptr.c".^M Make breakpoint pending on future shared library load? (y or [n]) n^M (gdb) FAIL: $exp: set baz breakpoint for implptr (got interactive prompt) ... This is a regression since commit dcaa85e58c4 ("gdb: reject inserting breakpoints between functions"). The .debug_line info does not contain an entry with a line number lower than 36, so gdb cannot map it to an address. Fix this by setting a breakpoint at the function containing line 34 instead. Tested on x86_64-linux. PR testsuite/32477 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32477
2025-01-07Fix crash in DWARF indexerTom Tromey1-0/+62
Iain pointed out a crash in the DWARF indexer when run on a certain D program. The DWARF in this case has a nameless enum class; this causes an assertion failure. This patch arranges to simply ignore such types. The fact that an enum class is nameless in this case appears to be a compiler bug. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32518 Approved-By: Tom de Vries <tdevries@suse.de>
2025-01-06[gdb/cli] Show LOC_CONST_BYTES var for info localsTom de Vries1-1/+15
PR cli/32525 reports that a variable with this DWARF: .. <2><423>: Abbrev Number: 14 (DW_TAG_variable) <424> DW_AT_name : var1867 <42a> DW_AT_type : <0x2f8> <42e> DW_AT_const_value : 8 byte block: 0 0 0 0 0 0 0 0 ... is not shown by info locals. Fix this by handling LOC_CONST_BYTES in iterate_over_block_locals. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32525 Approved-By: Tom Tromey <tom@tromey.com>
2024-12-04gdb: fix parsing of DIEs with both low/high pc AND ranges attributesAndrew Burgess2-0/+357
After the commit: commit b9de07a5ff74663ff39bf03632d1b2ea417bf8d5 Date: Thu Oct 10 11:37:34 2024 +0100 gdb: fix handling of DW_AT_entry_pc of inlined subroutines GDB's buildbot CI testing highlighted this assertion failure: (gdb) c Continuing. ../../binutils-gdb/gdb/block.h:203: internal-error: set_entry_pc: Assertion `start >= this->start () && start < this->end ()' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ----- Backtrace ----- FAIL: gdb.base/break-probes.exp: run til our library loads (GDB internal error) This assertion was in the new function set_entry_pc and is asserting that the default_entry_pc() value is within the blocks start/end range. The default_entry_pc() is the value GDB will use as the entry-pc if the DWARF doesn't specifically override the entry-pc. This value is calculated as: 1. The start address of the first sub-range within the block, if the block has more than 1 range, or 2. The low address (from DW_AT_low_pc) for the block. If the block only has a single range then this means the block was defined with low/high pc attributes (case #2 above). These low/high pc values are what block::start() and block::end() return. This means that by definition, if the block is continuous, the above assert cannot trigger as 'start', the default_entry_pc() would be equivalent to block::start(). This means that, for the assert to trigger, the block must have multiple ranges, and the first address of the first range is not within the blocks low/high address range. This seems wrong. I inspected the state at the time the assert triggered and discovered the block's start() address. Then I removed the assert and restarted GDB. I was now able to inspect the blocks at the offending address: (gdb) maintenance info blocks 0x7ffff7dddaa4 Blocks at 0x7ffff7dddaa4: from objfile: [(objfile *) 0x44a37f0] /lib64/ld-linux-x86-64.so.2 [(block *) 0x46b30c0] 0x7ffff7ddd5a0..0x7ffff7dde8a6 entry pc: 0x7ffff7ddd5a0 is global block symbol count: 4 is contiguous [(block *) 0x46b3020] 0x7ffff7ddd5a0..0x7ffff7dde8a6 entry pc: 0x7ffff7ddd5a0 is static block symbol count: 9 is contiguous [(block *) 0x46b2f70] 0x7ffff7ddda00..0x7ffff7dddac3 entry pc: 0x7ffff7ddda00 function: __GI__dl_find_dso_for_object symbol count: 4 is contiguous [(block *) 0x46b2e10] 0x7ffff7dddaa4..0x7ffff7dddac3 entry pc: 0x7ffff7dddaa4 inline function: __GI__dl_find_dso_for_object symbol count: 5 is contiguous [(block *) 0x46b2a40] 0x7ffff7dddaa4..0x7ffff7dddac3 entry pc: 0x7ffff7dddaa4 symbol count: 1 is contiguous [(block *) 0x46b2970] 0x7ffff7dddaa4..0x7ffff7dddac3 entry pc: 0x7ffff7dddaa4 symbol count: 2 address ranges: 0x7ffff7ddda0e..0x7ffff7ddda77 0x7ffff7ddda90..0x7ffff7ddda96 I've left everything in for context, but the only really interesting bit is the very last block, it's low/high range is: 0x7ffff7dddaa4..0x7ffff7dddac3 but it has separate ranges: 0x7ffff7ddda0e..0x7ffff7ddda77 0x7ffff7ddda90..0x7ffff7ddda96 which are all outside the low/high range. This is what triggers the assert. But why does that block exist at all? What I believe is happening is that we're running into a bug in older versions of GCC. The buildbot failure was with an 8.5 gcc, and Tom de Vries also reported seeing failures when using version 7 and 8 gcc, but not with gcc 9 and onward. Looking at the DWARF I can see that the problematic block is created from this DIE: <4><15efb>: Abbrev Number: 83 (DW_TAG_lexical_block) <15efc> DW_AT_abstract_origin: <0x15e9f> <15efe> DW_AT_low_pc : 0x7ffff7dddaa4 <15f06> DW_AT_high_pc : 31 which links via DW_AT_abstract_origin to: <2><15e9f>: Abbrev Number: 80 (DW_TAG_lexical_block) <15ea0> DW_AT_ranges : 0x38e0 <15ea4> DW_AT_sibling : <0x15eca> And so we can see that <15efb> has got both low/high pc attributes and a ranges attribute. If I widen my checking to parents of DIE <15efb> then I see that they also have DW_AT_abstract_origin, however, there is something interesting going on, the parent DIEs are linking to a different DIE tree than <15efb>. What I believe is happening is this, we have an abstract instance tree, this is rooted at a DW_AT_subprogram, and contains all the blocks, variables, parameters, etc, that you would expect. As this is an abstract instance, then there are no low/high pc attributes, and no ranges attributes in this tree. This makes sense. Now elsewhere we have a DW_TAG_subprogram (not DW_TAG_inlined_subroutine) which links via DW_AT_abstract_origin to the abstract DW_AT_subprogram. This case is documented in the DWARF 5 spec in section 3.3.8.3, and describes an Out-of-Line Instance of an Inlined Subroutine. Within this out of line instance many of the DIE correctly link back, using DW_AT_abstract_origin to the abstract instance tree. This tree also includes the DIE <15e9f>, which is where our problem DIE references. Now, to really confuse things, within this out-of-line instance we have a DW_TAG_inlined_subroutine, which is another instance of the same abstract instance tree! This would seem to indicate a recursive call to the inline function, and the compiler, for some reason, needed to instantiate an out of line instance of this function. And it is within this nested, inlined subroutine, that the problem DIE exists. The problem DIE is referencing the corresponding DIE within the out of line instance tree, but I am convinced this must be a (long fixed) GCC bug, and that the problem DIE should be referencing the DIE within the abstract instance tree. I'm aware that the above is pretty confusing. The actual DWARF would be a around 200 lines long, so I'd like to avoid dumping it in here. But here's my attempt at representing what's going on in a minimal example. The numbers down the side represent the section offset, not the nesting level, and I've removed any attributes that are not relevant: <1> DW_TAG_subprogram <2> DW_TAG_lexical_block <3> DW_TAG_subprogram DW_AT_abstract_origin <1> <4> DW_TAG_lexical_block DW_AT_ranges ... <5> DW_TAG_inlined_subroutine DW_AT_abstract_origin <1> <6> DW_TAG_lexical_block DW_AT_abstract_origin <4> DW_AT_low_pc ... DW_AT_high_pc ... The lexical block at <6> is linking to <4> when it should be linking to <2>. There is one additional thing that we might wonder about, which is, when calculating the low/high pc range for a block, why does GDB not make use of the range information and expand the range beyond the defined low/high values? The answer to this is in dwarf_get_pc_bounds_ranges_or_highlow_pc in dwarf/read.c. This is where the low/high bounds are calculated. What we see is that GDB first checks for a low/high attribute pair, and if that is present, this defines the address range for the block. Only if there is no DW_AT_low_pc do we check for the DW_AT_ranges, and use that to define the extent of the block. And this makes sense, section 3.5 of the DWARF-5 spec says: The lexical block entry may have either a DW_AT_low_pc and DW_AT_high_pc pair of attributes or a DW_AT_ranges attribute whose values encode the contiguous or non-contiguous address ranges, respectively, of the machine instructions generated for the lexical block... Section 3.5 is specifically about lexical blocks, but the same wording, about it being either low/high OR ranges is repeated for other DW_TAG_ types. So this explains why GDB doesn't use the ranges to expand the problem blocks ranges; as the first DIE has low/high addresses, these are used, and the ranges is not consulted. It is only later in dwarf2_record_block_ranges that we create a range based off the low/high pc, and then also process the ranges data, this allows the problem block to exist with ranges that are outside the low/high range. To solve this I considered a number of options: 1. Prevent loading certain attributes from an abstract instance. Section 3.3.8.1 of the DWARF-5 spec talks about which attributes are appropriate to place in an abstract instance. Any attribute that might vary between instances should not appear in an abstract instance. DW_AT_ranges is included as an example in the non-exhaustive list of attributes that should not appear in an abstract instance. Currently in dwarf2_attr (dwarf2/read.c), when we see a DW_AT_abstract_origin attribute, we always follow this to try and find the attribute we are looking for. But we could change this function so that we prevent this following for attributes that we know should not be looked up in an abstract instance. This would solve the problem in this case by preventing us finding the DW_AT_ranges in the incorrect abstract instance. 2. Filter the ranges. Having established a blocks low/high address range in dwarf_get_pc_bounds_ranges_or_highlow_pc, we could allow dwarf2_record_block_ranges to parse the ranges, but we could reject any range that extends outside the blocks defined start and end addresses. For well behaved DWARF where we have either low/high or ranges, then the blocks start/end are defined from the range data, and so, by definition, every range would be acceptable. But in our problem case we would reject all of the invalid ranges. This is my least favourite solution as it feels like rejecting the ranges is tackling the problem too late on. 3. Don't try to parse ranges when we have low/high attributes. This option involves updating dwarf2_record_block_ranges to match the behaviour of dwarf_get_pc_bounds_ranges_or_highlow_pc, and, I believe, to match the DWARF spec: don't try to read range data from DW_AT_ranges if we have low/high pc attributes. In our case this solves the issue because the problematic DIE has the low/high attributes, and it then links to the wrong DIE which happens to have DW_AT_ranges. With this change in place we don't even look for the DW_AT_ranges. If the problem were reversed, and the initial DIE had DW_AT_ranges, but the incorrectly referenced DIE had the low/high pc attributes, we would pick up the wrong addresses, but this wouldn't trigger any asserts. The reason is that dwarf_get_pc_bounds_ranges_or_highlow_pc would also find the low/high addresses from the incorrectly referenced DIE, and so we would just end up with a block which had the wrong address ranges, but the block would be self consistent, which is different to the problem we hit here. In the end, in this commit I went with solution #3, having dwarf_get_pc_bounds_ranges_or_highlow_pc and dwarf2_record_block_ranges be consistent seems sensible. However, I do wonder if in the future we might want to explore solution #1 as an additional safety feature. With this patch in place I'm able to run the gdb.base/break-probes.exp without seeing the assert that CI testing highlighted. I see no regressions when testing on x86-64 GNU/Linux with gcc 9.3.1. Note: the diff in this commit looks big, but it's really just me indenting the code. Approved-By: Tom Tromey <tom@tromey.com>
2024-12-02gdb: handle DW_AT_entry_pc pointing at an empty sub-rangeAndrew Burgess2-0/+307
The test gdb.cp/step-and-next-inline.exp creates a test binary called step-and-next-inline-no-header. This test includes a function `tree_check` which is inlined 3 times. When testing with some older versions of gcc (I've tried 8.4.0, 9.3.1) we see the following DWARF representing one of the inline instances of tree_check: <2><8d9>: Abbrev Number: 38 (DW_TAG_inlined_subroutine) <8da> DW_AT_abstract_origin: <0x9ee> <8de> DW_AT_entry_pc : 0x401165 <8e6> DW_AT_GNU_entry_view: 0 <8e7> DW_AT_ranges : 0x30 <8eb> DW_AT_call_file : 1 <8ec> DW_AT_call_line : 52 <8ed> DW_AT_call_column : 10 <8ee> DW_AT_sibling : <0x92d> ... <1><9ee>: Abbrev Number: 46 (DW_TAG_subprogram) <9ef> DW_AT_external : 1 <9ef> DW_AT_name : (indirect string, offset: 0xe8): tree_check <9f3> DW_AT_decl_file : 1 <9f4> DW_AT_decl_line : 38 <9f5> DW_AT_decl_column : 1 <9f6> DW_AT_linkage_name: (indirect string, offset: 0x2f2): _Z10tree_checkP4treei <9fa> DW_AT_type : <0x9e8> <9fe> DW_AT_inline : 3 (declared as inline and inlined) <9ff> DW_AT_sibling : <0xa22> ... Contents of the .debug_ranges section: Offset Begin End ... 00000030 0000000000401165 0000000000401165 (start == end) 00000030 0000000000401169 0000000000401173 00000030 0000000000401040 0000000000401045 00000030 <End of list> ... Notice that one of the sub-ranges of tree-check is empty, this is the line marked 'start == end'. As the end address is the first address after the range, this range cover absolutely no code. But notice too that the DW_AT_entry_pc for the inline instance points at this empty range. Further, notice that despite the ordering of the sub-ranges, the empty range is actually in the middle of the region defined by the lowest address to the highest address. The ordering is not a problem, the DWARF spec doesn't require that ranges be in any particular order. However, this empty range is causing issues with GDB newly acquire DW_AT_entry_pc support. GDB already rejects, and has done for a long time, empty sub-ranges, after all, the DWARF spec is clear that such a range covers no code. The recent DW_AT_entry_pc patch also had GDB reject an entry-pc which was outside of the low/high bounds of a block. But in this case, the entry-pc value is within the bounds of a block, it's just not within any useful sub-range. As a consequence, GDB is storing the entry-pc value, and making use of it, but when GDB stops, and tries to work out which block the inferior is in, it fails to spot that the inferior is within tree_check, and instead reports the function into which tree_check was inlined. I've tested with newer versions of gcc (12.2.0 and 14.2.0) and with these versions gcc is still generating the empty sub-range, but now this empty sub-range is no longer the entry point. Here's the corresponding ranges table from gcc 14.2.0: Contents of the .debug_rnglists section: Table at Offset: 0: Length: 0x56 DWARF version: 5 Address size: 8 Segment size: 0 Offset entries: 0 Offset Begin End ... 00000021 0000000000401165 000000000040116f 0000002b 0000000000401040 (base address) 00000034 0000000000401040 0000000000401040 (start == end) 00000037 0000000000401041 0000000000401046 0000003a <End of list> ... The DW_AT_entry_pc is 0x401165, but this is not the empty sub-range, as a result, when GDB stops at the entry-pc, GDB will correctly spot that the inferior is in the tree_check function. The fix I propose here is, instead of rejecting entry-pc values that are outside the block's low/high range, instead reject entry-pc values that are not inside any of the block's sub-ranges. Now, GDB will ignore the prescribed entry-pc, and will instead select a suitable default entry-pc based on either the block's low-pc value, or the first address of the first range. I have extended the gdb.cp/step-and-next-inline.exp test to check this case, but this does depend on the compiler version being used (newer compilers will always pass, even without the fix). So I have also added a DWARF assembler test to cover this case. Reviewed-By: Kevin Buettner <kevinb@redhat.com>
2024-11-27[gdb/testsuite] Add gdb.dwarf2/dw2-tu-dwarf-4-5.expTom de Vries3-0/+173
Add a regression test for PR symtab/32225. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32225
2024-11-23[gdb/contrib] Add two rules in common-misspellings.txtTom de Vries5-6/+6
Eli mentioned [1] that given that we use US English spelling in our documentation, we should use "behavior" instead of "behaviour". In wikipedia-common-misspellings.txt there's a rule: ... behavour->behavior, behaviour ... which leaves this as a choice. Add an overriding rule to hardcode the choice to common-misspellings.txt: ... behavour->behavior ... and add a rule to rewrite behaviour into behavior: ... behaviour->behavior ... and re-run spellcheck.sh on gdb*. Tested on x86_64-linux. [1] https://sourceware.org/pipermail/gdb-patches/2024-November/213371.html
2024-11-21gdb/build-id: protect against weirdly short build-idsAndrew Burgess1-0/+119
While looking at build_id_to_bfd_suffix (in gdb/build-id.c) I realised that GDB would likely not do what we wanted if a build-id was ever a single byte. Right now, build-ids generated by the GNU linker are 32 bytes, but there's nothing that forces this to be the case, it's pretty easy to create a fake, single byte, build-id. Given that the build-id is an external input (read from the objfile), GDB should protect itself against these edge cases. The problem with build_id_to_bfd_suffix is that this function creates the path used to lookup either the debug information, or an executable, based on its build-id. So a 3-byte build-id 0xaabbcc will look in the path: `$DEBUG_FILE_DIRECTORY/.build-id/aa/bbcc.debug`. However, a single byte build-id 0xaa, will look in the file: `$DEBUG_FILE_DIRECTORY/.build-id/aa/.debug` which doesn't seem right. Worse, when looking for an objfile given a build-id GDB will look for a file called `$DEBUG_FILE_DIRECTORY/.build-id/aa/` with a trailing '/' character. I propose that, in build_id_to_bfd_suffix we just return early if the build-id is 1 byte (or less) with a return value that indicates no separate file was found. For testing I made use of the DWARF assembler. I needed to update the build-id creation proc, the existing code assumes that the build-id is a multiple of 4 bytes, so I added some additional padding to ensure that the generated note was a multiple of 4 bytes, even if the build-id was not. I added a test with a 1 byte build-id, and also for the case where the build-id has zero length. The zero length case already does what you'd expect (no debug is loaded) as the bfd library rejects the build-id when loading it from the objfile, but adding this additional test is pretty cheap. Approved-By: Kevin Buettner <kevinb@redhat.com>
2024-11-13[gdb/contrib] Add "doens't->doesn't" to common-misspellings.txtTom de Vries1-2/+2
Add "doens't->doesn't" to gdb/contrib/common-misspellings.txt, and run gdb/contrib/spellcheck.sh to fix this in a few files. Tested on x86_64-linux. Approved-by: Kevin Buettner <kevinb@redhat.com>
2024-11-13gdb: stepping between inline functions with multiple rangesBernd Edlinger4-0/+616
I (Andrew) have split this small change from a larger patch which was posted here: https://inbox.sourceware.org/gdb-patches/AS1PR01MB9465608EBD5D62642C51C428E4922@AS1PR01MB9465.eurprd01.prod.exchangelabs.com And I have written the stand alone test for this issue. The original patch included this paragraph to explain this change (I've fixed one typo in this text replacing 'program' with 'function'): ... it may happen that the infrun machinery steps from one inline range to another inline range of the same inline function. That can look like jumping back and forth from the calling function to the inline function, while really the inline function just jumps from a hot to a cold section of the code, i.e. error handling. The important thing that happens here is that both the outer function and the inline function must both have multiple ranges. When the inferior is within the inline function and moves from one range to another it is critical that the address we stop at is the start of a range in both the outer function and the inline function. The diagram below represents how the functions are split and aligned: (A) (B) bar: |------------| |---| foo: |------------------| |--------| The inferior is stepping through 'bar' and eventually reaches point (A) at which point control passes to point (B). Currently, when the inferior stops, GDB notices that both 'foo' and 'bar' start at address (B), and so GDB uses the inline frame mechanism to skip 'bar' and tells the user that the inferior is in 'foo'. However, as we were in 'bar' before the step then it makes sense that we should be in 'bar' after the step, and this is what the patch does. There are two tests using the DWARF assembler, the first checks the above situation and ensures that GDB reports 'bar' after the step. The second test is similar, but after the step we enter a new range where a different inline function starts, something like this: (A) (B) bar: |------------| baz: |---| foo: |------------------| |--------| In this case as we step at (A) and land at (B) we leave 'bar' and expect to stop in 'foo', GDB shouldn't automatically enter 'baz' as that is a completely different inline function. And this is, indeed, what we see. Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
2024-11-13gdb: fix handling of DW_AT_entry_pc of inlined subroutinesAndrew Burgess2-0/+534
The entry PC for a DIE, e.g. an inline function, might not be the base address of the DIE. Currently though, in block::entry_pc(), GDB always returns the base address (low-pc or the first address of the first range) as the entry PC. This commit extends the block class to carry the entry PC as a separate member variable. Then the DWARF reader is extended to read and set the entry PC for the block. Now in block::entry_pc(), if the entry PC has been set, this is the value returned. If the entry-pc has not been set to a specific value then the old behaviour of block::entry_pc() remains, GDB will use the block's base address. Not every DIE will set the entry-pc, but GDB still needs to have an entry-pc for every block, so the existing logic supplies the entry-pc for any block where the entry-pc was not set. The DWARF-5 spec for reading the entry PC is a super-set of the spec as found in DWARF-4. For example, if there is no DW_AT_entry_pc then DWARF-4 says to use DW_AT_low_pc while DWARF-5 says to use the base address, which is DW_AT_low_pc or the first address in the first range specified by DW_AT_ranges if there is no DW_AT_low_pc. I have taken the approach of just implementing the DWARF-5 spec for everyone. There doesn't seem to be any benefit to deliberately ignoring a ranges based entry PC value for DWARF-4. If some naughty compiler has emitted that, then lets use it. Similarly, DWARF-4 says that DW_AT_entry_pc is an address. DWARF-5 allows an address or a constant, where the constant is an offset from the base address. I allow both approaches for all DWARF versions. There doesn't seem to be any downsides to this approach. I ran into an issue when testing this patch where GCC would have the DW_AT_entry_pc point to an empty range. When GDB parses the ranges any empty ranges are ignored. As a consequence, the entry-pc appears to be outside the address range of a block. The empty range problem is certainly something that we can, and should address, but that is not the focus of this patch, so for now I'm ignoring that problem. What I have done is added a check: if the DW_AT_entry_pc is outside the range of a block then the entry-pc is ignored, GDB will then fall-back to its default algorithm for computing the entry-pc. If/when in the future we address the empty range problem, these DW_AT_entry_pc attributes will suddenly become valid and GDB will start using them. Until then, GDB continues to operate as it always has. An early version of this patch stored the entry-pc within the block like this: std::optional<CORE_ADDR> m_entry_pc; However, a concern was raised that this, on a 64-bit host, effectively increases the size of block by 16-bytes (8-bytes for the CORE_ADDR, and 8-bytes for the std::optional's bool plus padding). If we remove the std::optional part and just use a CORE_ADDR then we need to have a "special" address to indicate if m_entry_pc is in use or not. I don't really like using special addresses; different targets can access different address ranges, even zero is a valid address on some targets. However, Bernd Edlinger suggested storing the entry-pc as an offset, and I think that will resolve my concerns. So, we store the entry-pc as a signed offset from the block's base address (the first address of the first range, or the start() address value if there are now ranges). Remember, ranges can be out of order, in which case the first address of the first range might be greater than the entry-pc. When GDB needs to read the entry-pc we can add the offset onto the blocks base address to recalculate it. With this done, on a 64-bit host, block only needs to increase by 8-bytes. The inline-entry.exp test was originally contributed by Bernd here: https://inbox.sourceware.org/gdb-patches/AS1PR01MB94659E4D9B3F4A6006CC605FE4922@AS1PR01MB9465.eurprd01.prod.exchangelabs.com though I have made some edits, making more use of lib/gdb.exp functions, making the gdb_test output patterns a little tighter, and updating the test to run with Clang. I also moved the test to gdb.opt/ as that seemed like a better home for it. Co-Authored-By: Bernd Edlinger <bernd.edlinger@hotmail.de>
2024-11-11gdb/dwarf2/read.c: Handle empty CU nameLancelot SIX2-0/+70
I recently came across a case where a compiler would emit a CU with an empty name. In such case, the attribute object constructed by GDB will return nullptr when as_string is called. One place is not checking for this possibility. As a result, loading such binary results in a GDB crash: $ gdb -q a.out Reading symbols from a.out... Fatal signal: Segmentation fault ----- Backtrace ----- [...] 0x742f4dd8afab __strcmp_avx2 ../sysdeps/x86_64/multiarch/strcmp-avx2.S:283 0x58593704a0bc prepare_one_comp_unit ../../gdb/dwarf2/read.c:21842 0x585937053fd9 process_psymtab_comp_unit ../../gdb/dwarf2/read.c:4633 0x585937053fd9 _ZN23cooked_index_debug_info11process_cusEmN9__gnu_cxx17__normal_iteratorIPSt10unique_ptrI18dwarf2_per_cu_data26dwarf2_per_cu_data_deleterESt6vectorIS5_SaIS5_EEEESA_ ../../gdb/dwarf2/read.c:4943 [...] --------------------- A fatal error internal to GDB has been detected, further debugging is not possible. GDB will now terminate. This is a bug, please report it. For instructions, see: <https://www.gnu.org/software/gdb/bugs/>. Segmentation fault (core dumped) This seems to be a regression introduced by the following commit: commit 00105aa1c4d9933fe3cfe9bc1be0daefe9f8ca36 Date: Tue Sep 24 10:24:22 2024 +0200 [gdb/symtab] Don't expand non-Ada CUs for info exceptions This patch fixes this issue by checking if attr->as_string returns nullptr. Change-Id: I78fe7a090f0bd1045b8cb2f8d088a8d6cf57fe1c Approved-By: Andrew Burgess <aburgess@redhat.com> Approved-By: Tom Tromey <tom@tromey.com>
2024-11-08Add dw2-aranges.expAlexandra Hájková2-0/+64
This test checks that GDB is able to load DWARF information when .debug_aranges has a section address size that is set to 0. This test was originally written by Jan Kratochvil to test commit 927aa2e778d from 2017, titled "DWARF-5: .debug_names index consumer". This test was originally written using a static .S file and has been present in the Fedora tree for a long time. If dwarf2/aranges.c is modified to turn off the address_size check, GDB will crash with SIGFPE when loading the executable with address size set to zero. I modified the DWARF assembler to make it possible to set the address size to zero in a .debug_aranges section and used the DWARF assembler to produce the assembly file. Co-Authored-By: Jan Kratochvil <jan.kratochvil@redhat.com> Approved-by: Kevin Buettner <kevinb@redhat.com>
2024-10-29[gdb/symtab] Handle multiple .debug_info sectionsTom de Vries2-0/+76
When compiling dw2-multiple-debug-info.c using -gdwarf-5 -fdebug-types-section, we end with two .debug_info sections in the object file: ... $ g++ gdb.dwarf2/dw2-multiple-debug-info.c -c -g \ -gdwarf-5 \ -fdebug-types-section $ readelf -WS dw2-multiple-debug-info.o | grep -v RELA | grep .debug_info [10] .debug_info PROGBITS 0 000128 0000cd 00 GC 0 0 8 [12] .debug_info PROGBITS 0 0001f8 0000ad 00 C 0 0 8 ... One of them contains the CU for dw2-multiple-debug-info.c, the other contains the TU for the type of variable a. When trying to print the type of variable a, we get: ... $ gdb -q -batch dw2-multiple-debug-info.o -ex "ptype a" 'a' has unknown type; cast it to its declared type ... because the TU hasn't been read. Fix this by adding support for reading multiple .debug_info sections, similar to how that is done for multiple .debug_types sections, getting us instead: ... $ gdb -q -batch dw2-multiple-debug-info.o -ex "ptype a" type = class sp1::A { ... } ... Tested on x86_64-linux. PR symtab/32223 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32223
2024-10-26[gdb/testsuite] Fix gdb.dwarf2/dwp-symlink.exp with target board fission-dwpTom de Vries1-6/+11
There are two test-cases that only run when the target board produces .dwp files, gdb.dwarf2/dwp-sepdebug.exp and gdb.dwarf2/dwp-symlink.exp. When running those test-cases with target board fission-dwp, I run into: ... (gdb) ptype main^M warning: Could not find DWO CU dwp-symlink0.dwo(0x496f1a7405c37a61) \ referenced by CU at offset 0xa6 [in module dwp-symlink]^M type = <unknown return type> ()^M (gdb) FAIL: gdb.dwarf2/dwp-symlink.exp: binary default, dwp at symlink ... coming from: ... # This case cannot work. gdb_test "ptype main" {type = int \(\)} "binary default, dwp at symlink" ... I had a bit of difficulty understanding what the test-case does/tries to do, so to build some understanding I reproduced the behaviour outside of the test-case: ... $ cat start.c void _start (void) {} $ gcc -gsplit-dwarf start.c -nostdlib $ gdb -q -batch a.out -ex "print _start" $1 = {void (void)} 0x400144 <_start> $ dwp -e a.out $ rm start.dwo $ gdb -q -batch a.out -ex "print _start" $1 = {void (void)} 0x400144 <_start> $ ln -s a.out b.out $ gdb -q -batch b.out -ex "print _start" $1 = {void (void)} 0x400144 <_start> $ mv a.out.dwp b.out.dwp $ gdb -q -batch b.out -ex "print _start" $1 = {void (void)} 0x400144 <_start> $ gdb -q -batch a.out -ex "print _start" During symbol reading: Could not find DWO CU start.dwo(0x8bdfd613387aa145) \ referenced by CU at offset 0x0 [in module a.out] warning: Could not find DWO CU start.dwo(0x8bdfd613387aa145) \ referenced by CU at offset 0x0 [in module a.out] $1 = {<text variable, no debug info>} 0x400144 <_start> ... and agreed, that cannot work: the DWO CU required in a.out is in b.out.dwp, and there's no way to find b.out.dwp starting from a.out. The fact that a FAIL is produced is incorrect, gdb does nothing wrong. Fix this by checking for the warning text instead. While we're at it, fix this PATH as well: ... (gdb) cd /data/vries/gdb/leap-15-5/build/gdb/testsuite/outputs/gdb.dwarf2/dwp-symlink^M Working directory /data/vries/gdb/leap-15-5/build/gdb/testsuite/outputs/gdb.dwarf2/dwp-symlink.^M (gdb) PASS: gdb.dwarf2/dwp-symlink.exp: cd \ /data/vries/gdb/leap-15-5/build/gdb/testsuite/outputs/gdb.dwarf2/dwp-symlink PATH: gdb.dwarf2/dwp-symlink.exp: cd \ /data/vries/gdb/leap-15-5/build/gdb/testsuite/outputs/gdb.dwarf2/dwp-symlink ... While we're at it, use string_to_regexp to simplify the test-case. Tested on x86_64-linux, with target board fission-dwp.
2024-10-23gdb/testsuite: introduce dwarf5 option to gdb_compileGuinevere Larsen2-3/+2
A few tests on the testsuite require dwarf5 to work. Up until now, the way to do this was to explicitly add the command line flag -gdwarf-5. This isn't very portable, in case a compiler requires a different flag to emit dwarf5. This commit adds a new option to gdb_compile that would be able to add the correct flag (if known) or error out in case we are unable to tell which flag to use. It also changes the existing tests to use this general option instead of hard coding -gdwarf-5. Reviewed-by: Keith Seitz <keiths@redhat.com> Approved-By: Tom Tromey <tom@tromey.com>
2024-10-22[gdb/testsuite] Handle maint set dwarf synchronous off defaultTom de Vries2-2/+14
I ran the testsuite with a patch setting dwarf_synchronous to false by default, and ran into FAILs in test-cases gdb.dwarf2/dw2-inter-cu-error.exp and gdb.dwarf2/dw2-inter-cu-error-2.exp, because the expected DWARF errors did not show up as a result of the file command. Fix this by forcing "maint set dwarf synchronous on". Add the same in gdb.base/index-cache.exp, where this is also required. Tested on aarch64-linux.
2024-10-22[gdb/testsuite] Improve class name in gdb.dwarf2/self-spec.expTom de Vries1-3/+3
I ran into: ... (gdb) pipe maint print objfiles self-spec | grep c1^M name: c1^M canonical: c1^M qualified: c1^M [3] ((addrmap *) 0xfffedfc1f010)^M (gdb) FAIL: gdb.dwarf2/self-spec.exp: class c1 in cooked index ... Fix this by renaming the class from c1 to class1. Tested on aarch64-linux.
2024-10-21[gdb/symtab] Fix incorrect filenames with inter-CU refsTom de Vries1-0/+92
With target board unix we get: ... $ gdb -q -batch outputs/gdb.cp/cplusfuncs/cplusfuncs \ -ex "info function operator\*" All functions matching regular expression "operator\*": File /home/vries/gdb/src/gdb/testsuite/gdb.cp/cplusfuncs.cc: 72: void foo::operator*(foo&); 85: void foo::operator*=(foo&); ... but with target board cc-with-dwz-m: ... All functions matching regular expression "operator\*": File /usr/lib/gcc/aarch64-redhat-linux/14/include/stddef.h: 72: void foo::operator*(foo&); 85: void foo::operator*=(foo&); ... The first operator: ... $ c++filt _ZN3foomlERS_ foo::operator*(foo&) ... matches address 0x410250 which is defined here in the CU in the exec: ... <1><10f1>: Abbrev Number: 13 (DW_TAG_subprogram) <10f2> DW_AT_specification: <alt 0x93> <10f6> DW_AT_decl_line : 72 <10f7> DW_AT_decl_column : 7 <10f7> DW_AT_object_pointer: <0x1106> <10f9> DW_AT_low_pc : 0x410250 <1101> DW_AT_high_pc : 32 <1102> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa) <1104> DW_AT_call_all_calls: 1 ... and declared here in the PU in the .dwz file: ... <2><93>: Abbrev Number: 20 (DW_TAG_subprogram) <94> DW_AT_external : 1 <94> DW_AT_name : operator* <98> DW_AT_decl_file : 2 <98> DW_AT_decl_line : 10 <99> DW_AT_decl_column : 9 <9a> DW_AT_linkage_name: _ZN3foomlERS_ <9e> DW_AT_accessibility: 1 (public) <9e> DW_AT_declaration : 1 <9e> DW_AT_object_pointer: <0xa2> ... When creating a new symbol for the operator, the DW_AT_decl_file attribute is looked up, and found to be 2. The 2 is supposed to be mapped using the PU, which has this file name table: ... The File Name Table (offset 0x78, lines 3, columns 2): Entry Dir Name 0 0 <dwz> 1 1 stddef.h 2 2 cplusfuncs.cc ... Instead, it's mapped using the CU, which has this file name table: ... The File Name Table (offset 0x34, lines 3, columns 2): Entry Dir Name 0 1 cplusfuncs.cc 1 1 cplusfuncs.cc 2 2 stddef.h ... This is PR symtab/30814. There's a similar PR for lto, PR symtab/25771, where the same problem happens for two CUs. Fix this by using the correct file name table. Add a dwarf assembly test-case for PR25771. Tested on aarch64-linux. Reviewed-By: Tom Tromey <tom@tromey.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=25771 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30814
2024-10-19[gdb/symtab] Skip local variables in cooked indexTom de Vries2-0/+49
Consider test-case gdb.dwarf2/local-var.exp. The corresponding source contains a function with a local variable: ... program test logical :: local_var local_var = .TRUE. end ... Currently, the local variable shows up in the cooked index: ... [2] ((cooked_index_entry *) 0xfffec40063b0) name: local_var canonical: local_var qualified: local_var DWARF tag: DW_TAG_variable flags: 0x2 [IS_STATIC] DIE offset: 0xa3 parent: ((cooked_index_entry *) 0xfffec4006380) [test] ... making the cooked index larger than necessary. Fix this by skipping it in cooked_indexer::index_dies. Tested on aarch64-linux. PR symtab/32276 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32276
2024-10-10[gdb/testsuite] Fix gdb.dwarf2/enum-type-c++.exp with clangTom de Vries1-15/+28
When running test-case gdb.dwarf2/enum-type-c++.exp with clang, we get: ... FAIL: gdb.dwarf2/enum-type-c++.exp: val1 has a parent FAIL: gdb.dwarf2/enum-type-c++.exp: print ns::A::val1 FAIL: gdb.dwarf2/enum-type-c++.exp: val2 has correct parent FAIL: gdb.dwarf2/enum-type-c++.exp: print ns::ec::val2 ... The problem is that the debug info produced by clang does not contain any references to enumerators val1 and val2, or the corresponding enumeration types. Instead, the variables u1 and u2 are considered to be simply of type int: ... <1><fb>: Abbrev Number: 2 (DW_TAG_variable) <fc> DW_AT_name : u1 <fd> DW_AT_type : <0x106> <101> DW_AT_external : 1 <103> DW_AT_location : (DW_OP_addrx <0>) <1><106>: Abbrev Number: 3 (DW_TAG_base_type) <107> DW_AT_name : int <108> DW_AT_encoding : 5 (signed) <109> DW_AT_byte_size : 4 <1><10a>: Abbrev Number: 2 (DW_TAG_variable) <10b> DW_AT_name : u2 <10c> DW_AT_type : <0x106> <110> DW_AT_external : 1 <112> DW_AT_location : (DW_OP_addrx <0x1>) ... Fix this by checking whether val1 and val2 are present in the cooked index before checking whether they have the correct parent. This cannot be expressed efficiently with gdb_test_lines, so factor out gdb_get_lines and use that instead. The test-case still calls "maint print objfiles" twice, but the first time is for have_index. We should probably use a gdb_caching_proc for this. Tested on aarch64-linux. Reported-By: Guinevere Larsen <guinevere@redhat.com> Reviewed-By: Keith Seitz <keiths@redhat.com> Tested-By: Guinevere Larsen <guinevere@redhat.com>
2024-10-10[gdb/testsuite] Fix some gdb.dwarf2 test-cases for check-read1Tom de Vries5-6/+15
I ran the testsuite in an environment simulating a stressed system in combination with check-read1. This exposes a few more FAILs. Fix the gdb.dwarf2 ones by using pipe / grep to filter out unnecessary output. Tested on x86_64-linux.
2024-10-08[gdb/symtab] Fix parent of enumeratorTom de Vries1-0/+15
As mentioned in commit 489b82720f5 ('[gdb/symtab] Revert "Change handling of DW_TAG_enumeration_type in DWARF scanner"'), when doing "maint print objfiles" in test-case gdb.dwarf2/enum-type.exp, for val1 we get an entry without parent: ... [27] ((cooked_index_entry *) 0x7fbbb4002ef0) name: val1 canonical: val1 qualified: val1 DWARF tag: DW_TAG_enumerator flags: 0x0 [] DIE offset: 0x124 parent: ((cooked_index_entry *) 0) ... This happens here in cooked_indexer::index_dies: ... info_ptr = recurse (reader, info_ptr, is_enum_class ? this_entry : parent_entry, fully); ... when we're passing down a nullptr parent_entry, while the parent of this_entry is deferred. Fix this in cooked_indexer::index_dies by passing down a deffered parent instead, such that we get: ... [27] ((cooked_index_entry *) 0x7ff0e4002ef0)^M name: val1^M canonical: val1^M qualified: ns::val1^M DWARF tag: DW_TAG_enumerator^M flags: 0x0 []^M DIE offset: 0x124^M parent: ((cooked_index_entry *) 0x7ff0e4002f20) [ns]^M ... Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-10-08[gdb/contrib] Add more separators in spellcheck.shTom de Vries1-1/+1
Add two more separators in spellcheck.sh: colon and comma. Doing so triggers the "inbetween->between" rule, which gives an incorrect result. Override this with "inbetween->between, in between, in-between" [1], in a new file gdb/contrib/common-misspellings.txt. Fix the following common misspellings: ... everytime -> every time sucess -> success thru -> through transfered -> transferred inbetween -> between, in between, in-between ... Verified with spellcheck.sh. Tested on x86_64-linux. [1] https://www.grammarly.com/blog/commonly-confused-words/in-between-or-inbetween/
2024-10-06[gdb] Fix common misspellingsTom de Vries4-5/+5
Fix the following common misspellings: ... accidently -> accidentally additonal -> additional addresing -> addressing adress -> address agaisnt -> against albiet -> albeit arbitary -> arbitrary artifical -> artificial auxillary -> auxiliary auxilliary -> auxiliary bcak -> back begining -> beginning cannonical -> canonical compatiblity -> compatibility completetion -> completion diferent -> different emited -> emitted emiting -> emitting emmitted -> emitted everytime -> every time excercise -> exercise existance -> existence fucntion -> function funtion -> function guarentee -> guarantee htis -> this immediatly -> immediately layed -> laid noone -> no one occurances -> occurrences occured -> occurred originaly -> originally preceeded -> preceded preceeds -> precedes propogate -> propagate publically -> publicly refering -> referring substract -> subtract substracting -> subtracting substraction -> subtraction taht -> that targetting -> targeting teh -> the thier -> their thru -> through transfered -> transferred transfering -> transferring upto -> up to vincinity -> vicinity whcih -> which whereever -> wherever wierd -> weird withing -> within writen -> written wtih -> with doesnt -> doesn't ... Tested on x86_64-linux.
2024-09-24[gdb/symtab] Fix segfault on invalid debug infoTom de Vries1-0/+51
While looking at PR symtab/31478 (a problem in the cooked indexer with invalid dwarf) it occurred to me that I could trigger a similar problem using: ... Compilation Unit @ offset 0xb2: Length: 0x1f (32-bit) Version: 4 Abbrev Offset: 0x6c Pointer Size: 8 <0><bd>: Abbrev Number: 1 (DW_TAG_compile_unit) <be> DW_AT_language : 2 (non-ANSI C) <1><bf>: Abbrev Number: 2 (DW_TAG_subprogram) <c0> DW_AT_low_pc : 0x4004a7 <c8> DW_AT_high_pc : 0x4004b2 <d0> DW_AT_specification: <0xd5> <1><d4>: Abbrev Number: 0 Compilation Unit @ offset 0xd5: Length: 0x7 (32-bit) Version: 4 Abbrev Offset: 0x7f Pointer Size: 8 ... and indeed I get: ... $ gdb -q -batch outputs/gdb.dwarf2/dw2-inter-cu-error-2/dw2-inter-cu-error-2 Fatal signal: Segmentation fault ... The problem is that we're calling prepare_one_comp_unit with cu == nullptr and comp_unit_die == nullptr here in cooked_indexer::ensure_cu_exists: ... cutu_reader new_reader (per_cu, per_objfile, nullptr, nullptr, false, m_index_storage->get_abbrev_cache ()); prepare_one_comp_unit (new_reader.cu, new_reader.comp_unit_die, language_minimal); ... Fix this by bailing out for various types of dummy CUs: ... if (new_reader.dummy_p || new_reader.comp_unit_die == nullptr || !new_reader.comp_unit_die->has_children) return nullptr; ... Also make sure in scan_attributes that this triggers a dwarf error: ... $ gdb -q -batch dw2-inter-cu-error-2 DWARF Error: cannot follow reference to DIE at 0xd5 \ [in module dw2-inter-cu-error-2] ... With target board readnow, the test-case triggers an assertion failure in follow_die_offset, so fix this by throwing the same dwarf error. While we're at it, make the other check for dummy CUs in cooked_indexer::ensure_cu_exists more robust by adding an intermediate test for comp_unit_die: ... - if (result->dummy_p || !result->comp_unit_die->has_children) + if (result->dummy_p || result->comp_unit_die == nullptr + || !result->comp_unit_die->has_children) return nullptr; ... Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-24[gdb/testsuite] Add gdb.dwarf2/dwz-unused-pu.expTom de Vries1-0/+75
Add a new test-case gdb.dwarf2/dwz-unused-pu.exp that checks that a symbol from an unused PU is not accessible. Passes with the relevant target boards: - unix (using the cooked index), - readnow (using no index at all), - cc-with-gdb-index (using .gdb_index), and - cc-with-debug-names (using .debug_names). Tested on x86_64-linux.
2024-09-21[gdb/testsuite] Drop -readnow in three gdb.dwarf2 test-casesTom de Vries3-32/+4
When running the testsuite in an enviroment simulating a stressed system, I ran into timeouts in three test-cases in gdb.dwarf2: - gdb.dwarf2/count.exp, - gdb.dwarf2/implptrconst.exp, and - gdb.dwarf2/implptrpiece.exp. In all three cases, -readnow is used which results in symtabs being expanded for the executable, /lib64/libc.so.6 and /lib64/ld-linux-x86-64.so.2. We could address this by limiting the scope of -readnow to the executable, but after reviewing the test-cases there doesn't seem to be a clear reason to use -readnow. Fix this by dropping the -readnow. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
2024-09-14[gdb/symtab] Revert "Change handling of DW_TAG_enumeration_type in DWARF ↵Tom de Vries2-2/+35
scanner" After adding dwarf assembly to test-case gdb.dwarf2/enum-type.exp that adds this debug info: ... <1><11f>: Abbrev Number: 3 (DW_TAG_enumeration_type) <120> DW_AT_specification: <0x130> <2><124>: Abbrev Number: 4 (DW_TAG_enumerator) <125> DW_AT_name : val1 <12a> DW_AT_const_value : 1 <2><12b>: Abbrev Number: 0 <1><12c>: Abbrev Number: 5 (DW_TAG_namespace) <12d> DW_AT_name : ns <2><130>: Abbrev Number: 6 (DW_TAG_enumeration_type) <131> DW_AT_name : e <133> DW_AT_type : <0x118> <137> DW_AT_declaration : 1 ... I run into an assertion failure: ... (gdb) file enum-type^M Reading symbols from enum-type...^M cooked-index.h:214: internal-error: get_parent: \ Assertion `(flags & IS_PARENT_DEFERRED) == 0' failed.^M ... This was reported in PR32160 comment 1. This is a regression since commit 4e417d7bb1c ("Change handling of DW_TAG_enumeration_type in DWARF scanner"). Fix this by reverting the commit. [ Also drop the kfails for PR31900 and PR32158, which are regressions by that same commit. ] That allows us to look at the output of "maint print objfiles", and for val1 we get an entry without parent: ... [27] ((cooked_index_entry *) 0x7fbbb4002ef0) name: val1 canonical: val1 qualified: val1 DWARF tag: DW_TAG_enumerator flags: 0x0 [] DIE offset: 0x124 parent: ((cooked_index_entry *) 0) ... which is incorrect, as noted in that same comment, but an improvement over the assertion failure, and I don't think that ever worked. This is to be addressed in a follow-up patch. Reverting the commit begs the question: what was it trying to fix in the first place, and do we need a different fix? I've investigated this and filed PR32160 to track this. My guess is that the commit was based on a misunderstand of what we track in cooked_indexer::m_die_range_map. Each DIE has two types of parent DIEs: - a DIE that is the parent as indicated by the tree structure in which DIEs occur, and - a DIE that represent the parent scope. In most cases, these two are the same, but some times they're not. The debug info above demonstrates such a case. The DIE at 0x11f: - has a tree-parent: the DIE representing the CU, and - has a scope-parent: DIE 0x12c representing namespace ns. In cooked_indexer::m_die_range_map, we track scope-parents, and the commit tried to add a tree-parent instead. So, I don't think we need a different fix, and propose we backport the reversal for gdb 15.2. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31900 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32158 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32160
2024-09-14[gdb/testsuite] Add regression test for PR32158Tom de Vries2-0/+18
Consider test-case: ... namespace ns { enum class ec { val2 = 2 }; } int main () { return (int)ns::ec::val2; } ... compiled with debug info: ... $ g++ test.c -g ... When looking at the cooked index entry for val2 using "maint print objfiles", we get: ... [7] ((cooked_index_entry *) 0x7f8ecc002ef0) name: val2 canonical: val2 qualified: ns::val2 DWARF tag: DW_TAG_enumerator flags: 0x0 [] DIE offset: 0xe9 parent: ((cooked_index_entry *) 0x7f8ecc002e90) [ns] ... which is wrong, there is no source level entity ns::val2. This is PR symtab/32158. This is a regression since commit 4e417d7bb1c ("Change handling of DW_TAG_enumeration_type in DWARF scanner"). Reverting the commit on current trunk fixes the problem, and gets us instead: ... [7] ((cooked_index_entry *) 0x7fba70002ef0) name: val2 canonical: val2 qualified: ns::ec::val2 DWARF tag: DW_TAG_enumerator flags: 0x0 [] DIE offset: 0xe9 parent: ((cooked_index_entry *) 0x7fba70002ec0) [ec] ... Add a regression test for this PR in test-case gdb.dwarf2/enum-type-c++.exp. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32158
2024-09-14[gdb/testsuite] Add gdb.dwarf2/enum-type-c++.exp, regression test for PR31900.Tom de Vries2-0/+73
Consider the following test-case: ... $ cat a.h namespace ns { class A { public: enum { val1 = 1 }; }; } $ cat main.c ns::A a; int main (void) { return 0; } $ cat val1.c int u1 = ns::A::val1; ... compiled with debug info: ... $ g++ main.c val1.c -g ... When trying to print ns::A::val with current trunk and gdb 15.1 we get: ... $ gdb -q -batch a.out -ex "print ns::A::val1" There is no field named val1 ... This PR c++/31900. With gdb 14.2 we get the expected: ... $ gdb -q -batch a.out -ex "print ns::A::val1" $1 = ns::A::val1 ... This is a regression since commit 4e417d7bb1c ("Change handling of DW_TAG_enumeration_type in DWARF scanner"). Reverting the commit on current trunk fixes the problem. So how does this problem happen? First, let's consider the current trunk, with the commit reverted. Gdb looks for the entry ns::A::val1, and find this entry: ... [29] ((cooked_index_entry *) 0x7f7830002ef0) name: val1 canonical: val1 qualified: ns::A::val1 DWARF tag: DW_TAG_enumerator flags: 0x0 [] DIE offset: 0x15a parent: ((cooked_index_entry *) 0x7f7830002ec0) [A] ... and expands the corresponding CU val1.c containing this debug info: ... <2><14a>: Abbrev Number: 3 (DW_TAG_class_type) <14b> DW_AT_name : A <14d> DW_AT_byte_size : 1 <3><150>: Abbrev Number: 4 (DW_TAG_enumeration_type) <151> DW_AT_encoding : 7 (unsigned) <152> DW_AT_byte_size : 4 <153> DW_AT_type : <0x163> <159> DW_AT_accessibility: 1 (public) <4><15a>: Abbrev Number: 5 (DW_TAG_enumerator) <15b> DW_AT_name : val1 <15f> DW_AT_const_value : 1 <4><160>: Abbrev Number: 0 <3><161>: Abbrev Number: 0 <2><162>: Abbrev Number: 0 ... after which it finds ns::A::val1 in the expanded symtabs. Now let's consider the current trunk as is (so, with the commit present). Gdb looks for the entry ns::A::val1, but doesn't find it because the val1 entry is missing its parent: ... [29] ((cooked_index_entry *) 0x7f5240002ef0) name: val1 canonical: val1 qualified: val1 DWARF tag: DW_TAG_enumerator flags: 0x0 [] DIE offset: 0x15a parent: ((cooked_index_entry *) 0) ... Then gdb looks for the entry ns::A, and finds this entry: ... [3] ((cooked_index_entry *) 0x7f5248002ec0) name: A canonical: A qualified: ns::A DWARF tag: DW_TAG_class_type flags: 0x0 [] DIE offset: 0xdd parent: ((cooked_index_entry *) 0x7f5248002e90) [ns] ... which corresponds to this debug info, which doesn't contain val1 due to -fno-eliminate-unused-debug-types: ... <2><dd>: Abbrev Number: 3 (DW_TAG_class_type) <de> DW_AT_name : A <e0> DW_AT_byte_size : 1 <2><e3>: Abbrev Number: 0 ... Gdb expands the corresponding CU main.c, after which it doesn't find ns::A::val1 in the expanded symtabs. The root cause of the problem is the missing parent on the val1 cooked_index_entry, but this only becomes user-visible through the elaborate scenario above. Add a test-case gdb.dwarf2/enum-type-c++.exp that contains a regression test for this problem that doesn't rely on expansion state or -feliminate-unused-debug-types, but simply tests for the root cause by grepping for ns::A::val1 in the output of "maint print objfile". Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31900
2024-09-11[gdb/testsuite] Simplify gdb.dwarf2/forward-spec.expTom de Vries1-28/+12
Test-case gdb.dwarf2/forward-spec.exp contains a non-trivial gdb_test_multiple to parse this cooked_index_entry: ... [5] ((cooked_index_entry *) 0x7f01f0004040)^M name: v^M canonical: v^M qualified: ns::v^M DWARF tag: DW_TAG_variable^M flags: 0x2 [IS_STATIC]^M DIE offset: 0xcb^M parent: ((cooked_index_entry *) 0x7f01f00040a0) [ns]^M ... which allows us to verify that the entry has a parent. After commit 8f258a6c979 ("[gdb/symtab] Dump qualified name of cooked_index_entry") that's no longer necessary. Simplify this by checking for ns::v instead. While we're at it, also fix the test-case for target boards readnow, cc-with-gdb-index and cc-with-debug-names. Tested on x86_64-linux.
2024-09-04[gdb/testsuite] Fix gdb.dwarf2/dw2-lines.exp on arm-linuxTom de Vries3-1/+13
With test-case gdb.dwarf2/dw2-lines.exp on arm-linux, I run into: ... (gdb) break bar_label^M Breakpoint 2 at 0x4004f6: file dw2-lines.c, line 29.^M (gdb) continue^M Continuing.^M ^M Breakpoint 2, bar () at dw2-lines.c:29^M 29 foo (2);^M (gdb) PASS: $exp: cv=2: cdw=32: lv=2: ldw=32: continue to breakpoint: foo \(1\) ... The pass is incorrect because the continue lands at line 29 with "foo (2)" instead of line line 27 with "foo (1)". A minimal version is: ... $ gdb -q -batch dw2-lines.cv-2-cdw-32-lv-2-ldw-32 -ex "b bar_label" Breakpoint 1 at 0x4f6: file dw2-lines.c, line 29. ... where: ... 000004ec <bar>: 4ec: b580 push {r7, lr} 4ee: af00 add r7, sp, #0 000004f0 <bar_label>: 4f0: 2001 movs r0, #1 4f2: f7ff fff1 bl 4d8 <foo> 000004f6 <bar_label_2>: 4f6: 2002 movs r0, #2 4f8: f7ff ffee bl 4d8 <foo> ... So, how does this happen? In short: - skip_prologue_sal calls arm_skip_prologue with pc == 0x4ec, - thumb_analyze_prologue returns 0x4f2 (overshooting by 1 insn, PR tdep/31981), and - skip_prologue_sal decides that we're mid-line, and updates to 0x4f6. However, this is a test-case about .debug_line info, so why didn't arm_skip_prologue use the line info to skip the prologue? The answer is that the line info starts at bar_label, not at bar. Fixing that allows us to work around PR tdep/31981. Likewise in gdb.dwarf2/dw2-line-number-zero.exp. Instead, add a new test-case gdb.arch/skip-prologue.exp that is dedicated to checking quality of architecture-specific prologue analysis, without being written in an architecture-specific way. If fails on arm-linux for both marm and mthumb: ... FAIL: gdb.arch/skip-prologue.exp: f2: $bp_addr == $prologue_end_addr (skipped too much) FAIL: gdb.arch/skip-prologue.exp: f4: $bp_addr == $prologue_end_addr (skipped too much) ... and passes for: - x86_64-linux for {m64,m32}x{-fno-PIE/-no-pie,-fPIE/-pie} - aarch64-linux. Tested on arm-linux.
2024-08-27[gdb/testsuite] Fix regexp in gdb.dwarf2/dw2-inter-cu-error.expTom de Vries1-1/+1
In commit b5070480d74 ("[gdb/symtab] Change DWARF_ERROR from Dwarf Error to DWARF Error") I changed the dwarf error prefix, but failed to update test-case gdb.dwarf2/dw2-inter-cu-error.exp. Fix this by updating the corresponding regexp in the test-case. Tested on x86_64-linux.
2024-08-27[gdb/symtab] Change DWARF_ERROR from Dwarf Error to DWARF ErrorTom de Vries5-6/+6
It was suggested here [1] that the canonical prefix for dwarf errors should not be "Dwarf Error: ", given that the canonical spelling is DWARF instead of Dwarf. Fix this by using "DWARF Error: " instead. Given the use of DWARF_ERROR_PREFIX, that needs to be changed only in a single location. Tested on x86_64-linux. Suggested-By: Tom Tromey <tom@tromey.com> Approved-By: Tom Tromey <tom@tromey.com> [1] https://sourceware.org/pipermail/gdb-patches/2024-August/211258.html
2024-08-23gdb/dwarf2: Check for null abbrev_info ptrAaron Merey1-0/+51
A corrupt debuginfo file can result in a null abbrev_info pointer being passed to cooked_indexer::scan_attributes. This pointer is set to nullptr by peek_die_abbrev when an abbrev of 0 is found. There is no check for whether the abbrev pointer is null and SIGSEGV occurs when attempting to dereference the pointer. An abbrev of 0 normally indicates that the corresponding DIE is a null entry, but scan_attributes expects a non-null DIE. Fix this by throwing an error in cooked_indexer::scan_attributes when peek_die_abbrev returns a nullptr in order to avoid scan_attributes calling itself with a null abbrev. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31478 Co-authored-by: Tom de Vries <tdevries@suse.de> Approved-By: Tom Tromey <tom@tromey.com>
2024-08-22[gdb/symtab] Return correct reader for top-level CU in ↵Tom de Vries1-0/+60
cooked_indexer::ensure_cu_exists With the test-case included in this patch, we run into: ... $ gdb -q -batch $exec Dwarf Error: Could not find abbrev number 3 in CU at offset 0xdb \ [in module $exec] ... The debug info consists of two CUs: ... Compilation Unit @ offset 0xb2: Length: 0x25 (32-bit) Version: 4 Abbrev Offset: 0x6c Pointer Size: 8 <0><bd>: Abbrev Number: 1 (DW_TAG_compile_unit) <be> DW_AT_language : 2 (non-ANSI C) <1><bf>: Abbrev Number: 2 (DW_TAG_subprogram) <c0> DW_AT_low_pc : 0x4004a7 <c8> DW_AT_high_pc : 0x4004b2 <d0> DW_AT_specification: <0xe8> <1><d4>: Abbrev Number: 3 (DW_TAG_subprogram) <d5> DW_AT_name : main <1><da>: Abbrev Number: 0 Compilation Unit @ offset 0xdb: Length: 0xf (32-bit) Version: 4 Abbrev Offset: 0x86 Pointer Size: 8 <0><e6>: Abbrev Number: 1 (DW_TAG_compile_unit) <e7> DW_AT_language : 2 (non-ANSI C) <1><e8>: Abbrev Number: 2 (DW_TAG_subprogram) <e9> DW_AT_specification: <0xd4> <1><ed>: Abbrev Number: 0 ... where: - DIE 0xbf in CU@0xb2 contains an inter-CU reference to - DIE 0xe8 in CU@0xdb, which contains an inter-CU reference to - DIE 0xd4 back in CU@0xb2. The dwarf error is caused by this bit of code in cooked_indexer::ensure_cu_exists: ... if (per_cu == m_per_cu) return reader; ... The dwarf error happens as follows: - a cutu_reader A is created for CU@0xb2 - using cutu_reader A, the cooked index reader starts indexing dies, with m_per_cu set to CU@0xb2 - while indexing it scans the attributes of DIE 0xbf and encounters the inter-CU reference to DIE 0xe8 - it calls cooked_indexer::ensure_cu_exists, which creates a cutu_reader B for CU@0xdb and returns it - using cutu_reader B, it continues scanning attributes of DIE 0xe8 and encounters the inter-CU reference to DIE 0xd4 - it calls cooked_indexer::ensure_cu_exists, the problematic bit is triggered and cutu_reader B is returned - using cutu_reader B, it continues scanning attributes of DIE 0xd4 - this goes wrong because: - the attributes of the DIE are encoded using the abbreviation table at offset 0x6c, while - the decoding is done using cutu_reader B which uses the abbreviation table at offset 0x86. Fix this by removing the problematic if clause. Since cutu_reader A is not preserved in m_index_storage, cooked_indexer::ensure_cu_exists cannot find it there and creates a duplicate cutu_reader C for CU@0xb2. Fix this in process_psymtab_comp_unit by preserving the cutu_reader A as well in m_index_storage. Tested on x86_64-linux and aarch64-linux. PR symtab/32081 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32081 Approved-By: Tom Tromey <tom@tromey.com> Reported-By: Andreas Schwab <schwab@linux-m68k.org>
2024-08-16[gdb/testsuite] Fix gdb.dwarf2/dw2-fixed-point.exp on arm-linuxTom de Vries1-6/+0
With test-case gdb.dwarf2/dw2-fixed-point.exp on arm-linux I run into: ... (gdb) PASS: gdb.dwarf2/dw2-fixed-point.exp: set lang ada print pck.fp1_var^M $1 = 0.3125^M (gdb) FAIL: gdb.dwarf2/dw2-fixed-point.exp: print pck.fp1_var ... The problem is that the thumb prologue analyzer overshoot, setting the breakpoint for main after line 49: ... 46 int 47 main (void) 48 { 49 pck__fp1_var++; ... and consequently we see the value of pck.fp1_var after line 49 instead of before line 49. This is PR tdep/31981. Work around this by removing line 49 and all similar subsequent lines, which turn out to be dead code. Approved-By: Luis Machado <luis.machado@arm.com> Tested on arm-linux.
2024-07-31[gdb/testsuite] Fix trailing-text-in-parentheses duplicatesTom de Vries1-3/+3
Fix all trailing-text-in-parentheses duplicates exposed by previous patch. Tested on x86_64-linux and aarch64-linux.
2024-07-30[gdb/symtab] Emit malformed macro definition complaint onceTom de Vries1-0/+198
Add a test-case gdb.dwarf2/macro-complaints.exp, that checks complaints for the .debug_macro section. For one malformed macro definition, I get two identical complaints: ... During symbol reading: macro debug info contains a malformed macro definition:^M `M1_11_MALFORMED(ARG'^M During symbol reading: macro debug info contains a malformed macro definition:^M `M1_11_MALFORMED(ARG'^M ... Fix this by bailing out after the first one. Tested on aarch64-linux. Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
2024-07-26gdb/testsuite: fix build-id compile option when used with clangAndrew Burgess1-1/+1
It was pointed out in this message: https://inbox.sourceware.org/gdb-patches/5d7a514b-5dad-446f-a021-444ea88ecf07@redhat.com That the test gdb.base/build-id-seqno.exp I added recently was FAILing when using Clang as the compiler. The problem was that I had failed to add 'build-id' as a compile option in the call to build_executable within the test script. For GCC this is fine as build-ids are included by default. For Clang though this meant the build-id was not included and the test would fail. So I added build-id to the compiler options.... and the test still didn't pass! Now the test fails to compile and I see this error from the compiler: gdb compile failed, clang-15: warning: -Wl,--build-id: 'linker' \ input unused [-Wunused-command-line-argument] It turns out that the build-id compile option causes our gdb.exp to add the '-Wl,--build-id' option into the compiler flags, which means its used when building the object file AND during the final link. However this option is unnecessary when creating the object file and Clang warns about this, which causes the build to fail. The solution is to change gdb.exp, instead of adding the build-id flags like this: lappend new_options "additional_flags=-Wl,--build-id" we should instead add them like: lappend new_options "ldflags=-Wl,--build-id" Now the flag is only appended during the link phase and Clang is happy. The gdb.base/build-id-seqno.exp test now passes with Clang. The same problem (adding to additional_flags instead of ldflags) exists for the no-build-id compile option, so I've fixed that too. While investigating this I also spotted two test scripts, gdb.base/index-cache.exp and gdb.dwarf2/per-bfd-sharing.exp which were setting ldflag directly rather than using the build-id compile option so I've updated these two tests to use the compile option which I think is neater. I've checked that all these tests still pass with both GCC and Clang. There should be no changes in what is actually tested after this commit. Approved-By: Simon Marchi <simon.marchi@efficios.com>