public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Bruno Larsen <blarsen@redhat.com>
To: Pedro Alves <pedro@palves.net>, gdb-patches@sourceware.org
Subject: Re: [PATCH 07/11] fix gdb.base/call-ar-st to work with clang
Date: Mon, 7 Mar 2022 17:39:55 -0300	[thread overview]
Message-ID: <f04234c0-6612-9d9b-eb92-b0315e5a7b3f@redhat.com> (raw)
In-Reply-To: <ac899375-afc5-1e6f-bd91-0ff243b10652@palves.net>

On 3/2/22 15:59, Pedro Alves wrote:
> On 2022-01-26 19:50, Bruno Larsen via Gdb-patches wrote:
>> When running this test with clang-compiled code, this test was failing
>> by producing an output like
>> array_i=<main.integer_array>, ...
>>
>> instead of
>>
>> array_i = <integer_array>, ...
>>
>> This commit changes the testcase to accept both outputs, as they are
>> functionally identical.
> 
> It would be useful to explain that the symbols in question are local static variables.
> "main" is the name of the function they are defined in, and Clang puts that in the elf/linkage name.
> GCC instead appends a sequence number to the linkage name:
> 
>   $ nm -A call-ar-st.gcc | grep integer_
>   call-ar-st/call-ar-st:00000000000061a0 b integer_array.3968
> 
>   $ nm -A call-ar-st.clang | grep integer_
>   call-ar-st:00000000004061a0 b main.integer_array
> 
> Note that for GCC, even though the ELF symbol is called "integer_array.3968", GDB still
> prints "integer_array", without the suffix.  I wonder how that happens?  Anyone knows offhand?
> It kind of looks like the testcase was expecting that the ".3968" suffix could appear in
> the output, given that it expects "array_i=<integer_array.*>" instead of "array_i=<integer_array>" ?

I tried to dig around for a bit, but couldn't find any obvious location. I can look some more if we ultimately decide it is a good idea to remove it, but personally, I think that knowing where the variable was declared could be helpful for debugging. Meanwhile, your patch looks good, I can add it to my tree for pushing at the end.

> 
>> ---
>>   gdb/testsuite/gdb.base/call-ar-st.exp | 13 ++++++++++---
>>   1 file changed, 10 insertions(+), 3 deletions(-)
>>
>> diff --git a/gdb/testsuite/gdb.base/call-ar-st.exp b/gdb/testsuite/gdb.base/call-ar-st.exp
>> index d1fb3ac9ec1..e447d3e231d 100644
>> --- a/gdb/testsuite/gdb.base/call-ar-st.exp
>> +++ b/gdb/testsuite/gdb.base/call-ar-st.exp
>> @@ -153,9 +153,16 @@ if {!$skip_float_test && \
>>   
>>   #step
>>   set stop_line [gdb_get_line_number "-step1-"]
>> -gdb_test "step" \
>> -    "print_all_arrays \\(array_i=<integer_array.*>, array_c=<char_array.*> .ZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZa., array_f=<float_array.*>, array_d=<double_array.*>\\) at .*$srcfile:$stop_line\[ \t\r\n\]+$stop_line.*print_int_array\\(array_i\\);.*" \
>> -    "step inside print_all_arrays"
>> +
>> +gdb_test_multiple "step" "" {
>> +
>> +    -re "print_all_arrays \\(array_i=<integer_array.*>, array_c=<char_array.*> .ZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZa., array_f=<float_array.*>, array_d=<double_array.*>\\) at .*$srcfile:$stop_line\[ \t\r\n\]+$stop_line.*print_int_array\\(array_i\\);.*" {
>> +	pass "step inside print_all_arrays"
>> +    }
>> +    -re "print_all_arrays \\(array_i=<main.integer_array>, array_c=<main.char_array> .ZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZa., array_f=<main.float_array>, array_d=<main.double_array>\\) at .*$srcfile:$stop_line\[ \t\r\n\]+$stop_line.*print_int_array\\(array_i\\);.*" {
>> +	pass "step inside print_all_arrays (clang)"
>> +    }
>> +}
>>   
> 
> If we end up taking the approach of accepting the current GDB output, then it would seem better
> to me to continue having a single expression.  Something like this:
> 
>  From d024950e743df1712f9adda759023e5ba07ee6e1 Mon Sep 17 00:00:00 2001
> From: Bruno Larsen <blarsen@redhat.com>
> Date: Wed, 2 Mar 2022 18:09:31 +0000
> Subject: [PATCH] Fix gdb.base/call-ar-st to work with Clang
> 
> When running gdb.base/call-ar-st.exp against Clang, we see one FAIL,
> like so:
> 
>   print_all_arrays (array_i=<main.integer_array>, array_c=<main.char_array> "ZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZa
>   ZaZaZaZaZaZaZaZaZaZaZaZa", array_f=<main.float_array>, array_d=<main.double_array>) at ../../../src/gdb/testsuite/gdb.base/call-ar-st.c:274
>   274       print_int_array(array_i);     /* -step1- */
>   (gdb) FAIL: gdb.base/call-ar-st.exp: step inside print_all_arrays
> 
> With GCC we instead see:
> 
>   print_all_arrays (array_i=<integer_array>, array_c=<char_array> "ZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZa", array_f=<float_array>, array_d=<double_array>) at /home/pedro/gdb/build/gdb/testsuite/../../../src/gdb/testsuite/gdb.base/call-ar-st.c:274
>   274       print_int_array(array_i);     /* -step1- */
>   (gdb) PASS: gdb.base/call-ar-st.exp: step inside print_all_arrays
> 
> The difference is that with Clang we get:
> 
>   array_i=<main.integer_array>, ...
> 
> instead of
> 
>   array_i = <integer_array>, ...
> 
> These symbols are local static variables, and "main" is the name of
> the function they are defined in.  GCC instead appends a sequence
> number to the linkage name:
> 
>   $ nm -A call-ar-st.gcc | grep integer_
>   call-ar-st/call-ar-st:00000000000061a0 b integer_array.3968
> 
>   $ nm -A call-ar-st.clang | grep integer_
>   call-ar-st:00000000004061a0 b main.integer_array
> 
> This commit changes the testcase to accept both outputs, as they are
> functionally identical.
> 
> Co-Authored-By: Pedro Alves <pedro@palves.net>
> Change-Id: Iaf2ccdb9d5996e0268ed12f595a6e04b368bfcb4
> ---
>   gdb/testsuite/gdb.base/call-ar-st.exp | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/testsuite/gdb.base/call-ar-st.exp b/gdb/testsuite/gdb.base/call-ar-st.exp
> index d1fb3ac9ec1..43fd6ff9f40 100644
> --- a/gdb/testsuite/gdb.base/call-ar-st.exp
> +++ b/gdb/testsuite/gdb.base/call-ar-st.exp
> @@ -151,10 +151,21 @@ if {!$skip_float_test && \
>       gdb_test "continue" ".*" ""
>   }
>   
> +# Return a regexp that matches the linkage name of SYM, assuming SYM
> +# is a local static variable inside the main function.
> +proc main_static_local_re {sym} {
> +    # Clang prepends the function name + '.'.
> +    return "(main\\.)?${sym}"
> +}
> +
>   #step
>   set stop_line [gdb_get_line_number "-step1-"]
>   gdb_test "step" \
> -    "print_all_arrays \\(array_i=<integer_array.*>, array_c=<char_array.*> .ZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZa., array_f=<float_array.*>, array_d=<double_array.*>\\) at .*$srcfile:$stop_line\[ \t\r\n\]+$stop_line.*print_int_array\\(array_i\\);.*" \
> +    "print_all_arrays \\(array_i=<[main_static_local_re integer_array]>,\
> +			 array_c=<[main_static_local_re char_array]> .ZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZa.,\
> +			 array_f=<[main_static_local_re float_array]>,\
> +			 array_d=<[main_static_local_re double_array]>\\)\
> +			 at .*$srcfile:$stop_line\[ \t\r\n\]+$stop_line.*print_int_array\\(array_i\\);.*" \
>       "step inside print_all_arrays"
>   
>   #step -over
> 


-- 
Cheers!
Bruno Larsen


  parent reply	other threads:[~2022-03-07 20:40 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-26 19:50 [PATCH 00/11] gdb/testsuite: Cleanup gdb.base for clang testing Bruno Larsen
2022-01-26 19:50 ` [PATCH 01/11] change gdb.base/skip.exp to use finish instead of step Bruno Larsen
2022-02-25 17:00   ` Andrew Burgess
2022-03-02 16:11   ` Pedro Alves
2022-03-02 16:39     ` Andrew Burgess
2022-03-07 19:59       ` Bruno Larsen
2022-01-26 19:50 ` [PATCH 02/11] change gdb.base/symbol-alias to xfail with clang Bruno Larsen
2022-01-26 19:50 ` [PATCH 03/11] Change gdb.base/skip-solib.exp deal with lack of epilogue information Bruno Larsen
2022-03-02 16:17   ` Pedro Alves
2022-03-07 19:53     ` Bruno Larsen
2022-01-26 19:50 ` [PATCH 04/11] change gdb.base/nodebug.c to not fail with clang Bruno Larsen
2022-01-26 19:50 ` [PATCH 05/11] update gdb.base/info-program.exp " Bruno Larsen
2022-01-26 19:50 ` [PATCH 06/11] fix gdb.base/access-mem-running.exp for clang testing Bruno Larsen
2022-01-26 19:50 ` [PATCH 07/11] fix gdb.base/call-ar-st to work with clang Bruno Larsen
2022-03-02 18:59   ` Pedro Alves
2022-03-04 14:14     ` Tom Tromey
2022-03-07 20:39     ` Bruno Larsen [this message]
2022-01-26 19:50 ` [PATCH 08/11] add xfails to gdb.base/complex-parts.exp when testing " Bruno Larsen
2022-03-02 19:10   ` Pedro Alves
2022-01-26 19:50 ` [PATCH 09/11] gdb/testsuite: don't test gdb.base/msym-bp-shl " Bruno Larsen
2022-03-02 19:33   ` Pedro Alves
2022-03-08 12:58     ` Bruno Larsen
2022-03-30 12:19     ` Bruno Larsen
2022-03-31 18:49       ` Pedro Alves
2022-03-31 19:13         ` Bruno Larsen
2022-01-26 19:50 ` [PATCH 10/11] make use of finish to leave function in gdb.base/skip-inline.exp Bruno Larsen
2022-01-26 19:50 ` [PATCH 11/11] explicitly test for stderr in gdb.base/dprintf.exp Bruno Larsen
2022-03-02 16:50   ` Pedro Alves
2022-03-31 13:44     ` Bruno Larsen
2022-03-31 14:31       ` Pedro Alves
2022-02-09 12:03 ` [PING][PATCH 00/11] gdb/testsuite: Cleanup gdb.base for clang testing Bruno Larsen
2022-02-21 12:53   ` [PINGv2][PATCH " Bruno Larsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f04234c0-6612-9d9b-eb92-b0315e5a7b3f@redhat.com \
    --to=blarsen@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).