[5/6] gdb/testsuite: fix gdb.debuginfod/fetch_src_and_symbols.exp with Clang
Commit Message
The gdb.debuginfod/fetch_src_and_symbols.exp test is showing a single
failure when run with some older versions of Clang, e.g. 9.0.1.
The problem appears to be with Clang's generated line table. The test
source looks like this:
int
main()
{
asm ("main_label: .globl main_label");
return 0;
}
In GDB, when we 'start', we expect to stop at the 'return 0;' line.
This is the behaviour when the compiler is gcc, or later versions of
Clang.
However, with Clang 9.0.2, I see GDB stop on the 'asm' line.
I propose adding some code to the test script to step GDB onto the
next line if we stop on the 'asm' line. With this change in place, I
now see the test fully passing with Clang 9.0.1 and 15.0.2, as well as
with gcc.
---
.../gdb.debuginfod/fetch_src_and_symbols.exp | 21 +++++++++++++++++++
1 file changed, 21 insertions(+)
Comments
>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:
Andrew> int
Andrew> main()
Andrew> {
Andrew> asm ("main_label: .globl main_label");
Andrew> return 0;
Andrew> }
Andrew> In GDB, when we 'start', we expect to stop at the 'return 0;' line.
Andrew> This is the behaviour when the compiler is gcc, or later versions of
Andrew> Clang.
Andrew> However, with Clang 9.0.2, I see GDB stop on the 'asm' line.
Andrew> I propose adding some code to the test script to step GDB onto the
Andrew> next line if we stop on the 'asm' line. With this change in place, I
Andrew> now see the test fully passing with Clang 9.0.1 and 15.0.2, as well as
Andrew> with gcc.
It seems to me that the usual approach of adding a "/* STOP */" comment
and then running to that point would be less reliant on compiler
decisions.
Tom
Andrew> Thanks for the feedback. I've updated the test inline with your suggestion.
Andrew> While making this change I wondered if there was any reason why the
Andrew> source file for this test is called 'main.c' rather than the expected
Andrew> fetch_src_and_symbols.c. I couldn't see any reason, so in the first
Andrew> patch below I rename the source file, then the second patch below is
Andrew> an improved version of my v1 patch.
These look good to me. Thank you.
Tom
@@ -161,6 +161,27 @@ proc_with_prefix no_url { } {
if ![runto_main] {
return -1
}
+
+ # Some older versions of Clang (e.g. 9.0.1) were observed stopped
+ # at the 'asm' line rather than the 'return' line in main.c. This
+ # messes up some of the expected patterns later in the test.
+ set rtn_lineno [gdb_get_line_number "return 0;"]
+ set prev_lineno [expr $rtn_lineno - 1]
+ gdb_test_multiple "info line" "" {
+ -wrap -re "\r\nLine ${prev_lineno} of .*" {
+ gdb_test "step"
+ pass $gdb_test_name
+ }
+ -wrap -re "\r\nLine ${rtn_lineno} of .*" {
+ pass $gdb_test_name
+ }
+ -wrap -re "\r\nLine ${::decimal} of .*" {
+ # Not sure what line this stopped on, but later tests are
+ # probably going to fail.
+ fail $gdb_test_name
+ }
+ }
+
gdb_test "generate-core-file $::corefile" "Saved corefile $::corefile" \
"file [file tail $::corefile] gen"
file rename -force ${binfile}2 $debugdir