diff mbox series

[v3,1/2] gdb/testsuite: Add libc_has_debug_info require helper

Message ID 20240422230700.1173173-2-thiago.bauermann@linaro.org
State New
Headers show
Series Add testcase for libc memory operations | expand

Commit Message

Thiago Jung Bauermann April 22, 2024, 11:06 p.m. UTC
Factor the test for libc debug info out of gdb.base/relativedebug.exp to
a new procedure.

Also, change the "info sharedlibrary" test to explicitly detect when
libc has debug info.
---

As mentioned in the cover letter, the new testcase doesn't use this helper
procedure anymore so this is an optional patch.  I think it's a nice
cleanup, though I didn't find any other testcase that need it so perhaps
the new helper is not as useful as I imagine it to be. I'm fine with not
committing this patch.

Changes in v3:
- Include <stdio.h> in test program to avoid error when using clang
  (suggested by Kevin).

 gdb/testsuite/gdb.base/relativedebug.exp | 13 +-----
 gdb/testsuite/lib/gdb.exp                | 56 ++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 12 deletions(-)

Comments

Kevin Buettner April 23, 2024, 5:09 p.m. UTC | #1
On Mon, 22 Apr 2024 20:06:59 -0300
Thiago Jung Bauermann <thiago.bauermann@linaro.org> wrote:

> Factor the test for libc debug info out of gdb.base/relativedebug.exp to
> a new procedure.
> 
> Also, change the "info sharedlibrary" test to explicitly detect when
> libc has debug info.
> ---
> 
> As mentioned in the cover letter, the new testcase doesn't use this helper
> procedure anymore so this is an optional patch.  I think it's a nice
> cleanup, though I didn't find any other testcase that need it so perhaps
> the new helper is not as useful as I imagine it to be. I'm fine with not
> committing this patch.
> 
> Changes in v3:
> - Include <stdio.h> in test program to avoid error when using clang
>   (suggested by Kevin).

I agree that it's a nice cleanup and I think that it should go in.

I've retested with CC_FOR_TARGET set to clang and also gcc.  It works
for both.

Approved-by: Kevin Buettner <kevinb@redhat.com>
Thiago Jung Bauermann April 24, 2024, 4:25 p.m. UTC | #2
Hello Kevin,

Kevin Buettner <kevinb@redhat.com> writes:

> On Mon, 22 Apr 2024 20:06:59 -0300
> Thiago Jung Bauermann <thiago.bauermann@linaro.org> wrote:
>
>> Factor the test for libc debug info out of gdb.base/relativedebug.exp to
>> a new procedure.
>> 
>> Also, change the "info sharedlibrary" test to explicitly detect when
>> libc has debug info.
>> ---
>> 
>> As mentioned in the cover letter, the new testcase doesn't use this helper
>> procedure anymore so this is an optional patch.  I think it's a nice
>> cleanup, though I didn't find any other testcase that need it so perhaps
>> the new helper is not as useful as I imagine it to be. I'm fine with not
>> committing this patch.
>> 
>> Changes in v3:
>> - Include <stdio.h> in test program to avoid error when using clang
>>   (suggested by Kevin).
>
> I agree that it's a nice cleanup and I think that it should go in.
>
> I've retested with CC_FOR_TARGET set to clang and also gcc.  It works
> for both.
>
> Approved-by: Kevin Buettner <kevinb@redhat.com>

Thank you! Pushed as commit f5ef12c3f1af.
Bernd Edlinger April 25, 2024, 7:39 p.m. UTC | #3
Hi Thiago,

On 4/24/24 18:25, Thiago Jung Bauermann wrote:
> 
> Hello Kevin,
> 
> Kevin Buettner <kevinb@redhat.com> writes:
> 
>> On Mon, 22 Apr 2024 20:06:59 -0300
>> Thiago Jung Bauermann <thiago.bauermann@linaro.org> wrote:
>>
>>> Factor the test for libc debug info out of gdb.base/relativedebug.exp to
>>> a new procedure.
>>>
>>> Also, change the "info sharedlibrary" test to explicitly detect when
>>> libc has debug info.
>>> ---
>>>
>>> As mentioned in the cover letter, the new testcase doesn't use this helper
>>> procedure anymore so this is an optional patch.  I think it's a nice
>>> cleanup, though I didn't find any other testcase that need it so perhaps
>>> the new helper is not as useful as I imagine it to be. I'm fine with not
>>> committing this patch.
>>>
>>> Changes in v3:
>>> - Include <stdio.h> in test program to avoid error when using clang
>>>   (suggested by Kevin).
>>
>> I agree that it's a nice cleanup and I think that it should go in.
>>
>> I've retested with CC_FOR_TARGET set to clang and also gcc.  It works
>> for both.
>>
>> Approved-by: Kevin Buettner <kevinb@redhat.com>
> 
> Thank you! Pushed as commit f5ef12c3f1af.
> 

I think I have an issue with this commmit.
I use a self-built riscv-unknown-elf toolchain with newlib,
so there is no libc at all, regardless of debug info.
since today, I see messages like:
Running /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.exp ...
FAIL: gdb.base/relativedebug.exp: info sharedlibrary libc.so
ERROR: tcl error sourcing /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.exp.
ERROR: tcl error code TCL READ VARNAME
ERROR: can't read "libc_has_debug_info": no such variable
    while executing
"verbose "$me: returning $libc_has_debug_info" 2"
    (procedure "gdb_real__libc_has_debug_info" line 47)
    invoked from within
"gdb_real__libc_has_debug_info"
    ("uplevel" body line 1)
    invoked from within
"uplevel 2 [list $real_name {*}$args]"
    invoked from within
"gdb_do_cache_wrap $real_name {*}$args"
    (procedure "gdb_do_cache" line 48)
    invoked from within
"gdb_do_cache libc_has_debug_info"
    (procedure "libc_has_debug_info" line 1)
    invoked from within
"libc_has_debug_info"
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 $fn"
    (procedure "require" line 11)
    invoked from within
"require {!target_info exists gdb,nosignals} libc_has_debug_info"
    (file "/home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.exp" line 16)
    invoked from within
"source /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.exp"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 source /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.exp"
    invoked from within
"catch "uplevel #0 source $test_file_name" msg"
UNRESOLVED: gdb.base/relativedebug.exp: testcase '/home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.exp' aborted due to Tcl error
PATH: gdb.base/relativedebug.exp: testcase '/home/ed/gnu/

while previously that looked like:

gdb compile failed, /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld: /tmp/ccjr19GC.o: in function `main':
/home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:30:(.text+0x28): undefined reference to `alarm'
/home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld: /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:31:(.text+0x30): undefined reference to `pause'
/home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld: /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:31:(.text+0x38): undefined reference to `pause'
collect2: error: ld returned 1 exit status
UNTESTED: gdb.base/relativedebug.exp: failed to compile

so not very noisy, newlib does apparently not have alarm, pause, sleep, and similar,
but much easier to understand the output...


Regards,
Bernd.
Thiago Jung Bauermann April 26, 2024, 3 a.m. UTC | #4
Hello Bernd,

Bernd Edlinger <bernd.edlinger@hotmail.de> writes:

> Hi Thiago,
>
> On 4/24/24 18:25, Thiago Jung Bauermann wrote:
>>>
>> Thank you! Pushed as commit f5ef12c3f1af.
>
> I think I have an issue with this commmit.
> I use a self-built riscv-unknown-elf toolchain with newlib,
> so there is no libc at all, regardless of debug info.
> since today, I see messages like:
> Running /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.exp ...
> FAIL: gdb.base/relativedebug.exp: info sharedlibrary libc.so
> ERROR: tcl error sourcing /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.exp.
> ERROR: tcl error code TCL READ VARNAME
> ERROR: can't read "libc_has_debug_info": no such variable
>     while executing
> "verbose "$me: returning $libc_has_debug_info" 2"
>     (procedure "gdb_real__libc_has_debug_info" line 47)
>     invoked from within
> "gdb_real__libc_has_debug_info"

<snip>

Sorry for the trouble. I should have simulated a situation where GDB
can't find libc.so in the inferior. I was able to reproduce the error
above when I did.

Could you please test the patch that I just sent?

> while previously that looked like:
>
> gdb compile failed, /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld: /tmp/ccjr19GC.o: in function `main':
> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:30:(.text+0x28): undefined reference to `alarm'
> /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld:
> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:31:(.text+0x30):
> undefined reference to `pause'
> /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld:
> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:31:(.text+0x38):
> undefined reference to `pause'
> collect2: error: ld returned 1 exit status
> UNTESTED: gdb.base/relativedebug.exp: failed to compile
>
> so not very noisy, newlib does apparently not have alarm, pause, sleep, and similar,
> but much easier to understand the output...

On the plus side, with this problem fixed gdb.base/relativedebug.exp
should exit early with:

(gdb) info sharedlibrary libc.so
No shared libraries matched.
(gdb) UNSUPPORTED: gdb.base/relativedebug.exp: require failed: libc_has_debug_info (libc not found in the inferior)

Which will be even easier to understand the output. :-)
Bernd Edlinger April 26, 2024, 5:06 a.m. UTC | #5
Hello Thiago,

On 4/26/24 05:00, Thiago Jung Bauermann wrote:
> Sorry for the trouble. I should have simulated a situation where GDB
> can't find libc.so in the inferior. I was able to reproduce the error
> above when I did.
> 
> Could you please test the patch that I just sent?
> 

Yeah it works.  Thanks a lot for the quick response.

>> while previously that looked like:
>>
>> gdb compile failed, /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld: /tmp/ccjr19GC.o: in function `main':
>> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:30:(.text+0x28): undefined reference to `alarm'
>> /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld:
>> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:31:(.text+0x30):
>> undefined reference to `pause'
>> /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld:
>> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:31:(.text+0x38):
>> undefined reference to `pause'
>> collect2: error: ld returned 1 exit status
>> UNTESTED: gdb.base/relativedebug.exp: failed to compile
>>
>> so not very noisy, newlib does apparently not have alarm, pause, sleep, and similar,
>> but much easier to understand the output...
> 
> On the plus side, with this problem fixed gdb.base/relativedebug.exp
> should exit early with:
> 
> (gdb) info sharedlibrary libc.so
> No shared libraries matched.
> (gdb) UNSUPPORTED: gdb.base/relativedebug.exp: require failed: libc_has_debug_info (libc not found in the inferior)
> 
> Which will be even easier to understand the output. :-)
> 

Yes, indeed.

If I had one wish free, I would like to have
these lines not mention the random /tmp/*.o file name:

gdb compile failed, /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld: /tmp/ccjr19GC.o: in function `main':

... at least in the gdb.sum file.

Thanks
Bernd.
Pedro Alves April 26, 2024, 4:35 p.m. UTC | #6
On 2024-04-26 04:00, Thiago Jung Bauermann wrote:
> 
> Hello Bernd,
> 
> Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
> 
>> Hi Thiago,
>>
>> On 4/24/24 18:25, Thiago Jung Bauermann wrote:
>>>>
>>> Thank you! Pushed as commit f5ef12c3f1af.
>>
>> I think I have an issue with this commmit.
>> I use a self-built riscv-unknown-elf toolchain with newlib,
>> so there is no libc at all, regardless of debug info.
>> since today, I see messages like:
>> Running /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.exp ...
>> FAIL: gdb.base/relativedebug.exp: info sharedlibrary libc.so
>> ERROR: tcl error sourcing /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.exp.
>> ERROR: tcl error code TCL READ VARNAME
>> ERROR: can't read "libc_has_debug_info": no such variable
>>     while executing
>> "verbose "$me: returning $libc_has_debug_info" 2"
>>     (procedure "gdb_real__libc_has_debug_info" line 47)
>>     invoked from within
>> "gdb_real__libc_has_debug_info"
> 
> <snip>
> 
> Sorry for the trouble. I should have simulated a situation where GDB
> can't find libc.so in the inferior. I was able to reproduce the error
> above when I did.
> 
> Could you please test the patch that I just sent?
> 
>> while previously that looked like:
>>
>> gdb compile failed, /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld: /tmp/ccjr19GC.o: in function `main':
>> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:30:(.text+0x28): undefined reference to `alarm'
>> /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld:
>> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:31:(.text+0x30):
>> undefined reference to `pause'
>> /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld:
>> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:31:(.text+0x38):
>> undefined reference to `pause'
>> collect2: error: ld returned 1 exit status
>> UNTESTED: gdb.base/relativedebug.exp: failed to compile
>>
>> so not very noisy, newlib does apparently not have alarm, pause, sleep, and similar,
>> but much easier to understand the output...
> 
> On the plus side, with this problem fixed gdb.base/relativedebug.exp
> should exit early with:
> 
> (gdb) info sharedlibrary libc.so
> No shared libraries matched.
> (gdb) UNSUPPORTED: gdb.base/relativedebug.exp: require failed: libc_has_debug_info (libc not found in the inferior)
> 
> Which will be even easier to understand the output. :-)
> 

I don't think that's a good outcome, actually.  It'll disable the testcase on systems that link
with their libc statically (even if has debug info), or systems that name their libc something else.
And I worry that the require predicate will start being used more with that particularity.

The original check only returned early if a library called "*libc*" was found, and, it didn't
have debug info.  If those conditions didn't match, the testcase proceeded.  That seems a
lot safer.  As in, only if we know for sure we have a libc without debug info, do we return early.
Thiago Jung Bauermann April 26, 2024, 5:18 p.m. UTC | #7
Hello Pedro,

Pedro Alves <pedro@palves.net> writes:

> On 2024-04-26 04:00, Thiago Jung Bauermann wrote:
>> 
>> Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
>> 
>>> while previously that looked like:
>>>
>>> gdb compile failed,
>>> /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld:
>>> /tmp/ccjr19GC.o: in function `main':
>>> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:30:(.text+0x28):
>>> undefined reference to `alarm'
>>> /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld:
>>> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:31:(.text+0x30):
>>> undefined reference to `pause'
>>> /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld:
>>> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:31:(.text+0x38):
>>> undefined reference to `pause'
>>> collect2: error: ld returned 1 exit status
>>> UNTESTED: gdb.base/relativedebug.exp: failed to compile
>>>
>>> so not very noisy, newlib does apparently not have alarm, pause, sleep, and similar,
>>> but much easier to understand the output...
>> 
>> On the plus side, with this problem fixed gdb.base/relativedebug.exp
>> should exit early with:
>> 
>> (gdb) info sharedlibrary libc.so
>> No shared libraries matched.
>> (gdb) UNSUPPORTED: gdb.base/relativedebug.exp: require failed: libc_has_debug_info (libc
>> not found in the inferior)
>> 
>> Which will be even easier to understand the output. :-)
>> 
>
> I don't think that's a good outcome, actually.  It'll disable the testcase on systems that
> link
> with their libc statically (even if has debug info), or systems that name their libc
> something else.
> And I worry that the require predicate will start being used more with that particularity.
>
> The original check only returned early if a library called "*libc*" was found, and, it
> didn't
> have debug info.  If those conditions didn't match, the testcase proceeded.  That seems a
> lot safer.  As in, only if we know for sure we have a libc without debug info, do we
> return early.

Ok, makes sense. I'll submit a patch for the libc_has_debug_info that
makes it behave like the original check in gdb.base/relativedebug.exp
did.
Thiago Jung Bauermann April 30, 2024, 1:57 a.m. UTC | #8
Hello Pedro,

Thiago Jung Bauermann <thiago.bauermann@linaro.org> writes:

> Pedro Alves <pedro@palves.net> writes:
>
>> On 2024-04-26 04:00, Thiago Jung Bauermann wrote:
>>> 
>>> Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
>>> 
>>>> while previously that looked like:
>>>>
>>>> gdb compile failed,
>>>> /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld:
>>>> /tmp/ccjr19GC.o: in function `main':
>>>> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:30:(.text+0x28):
>>>> undefined reference to `alarm'
>>>> /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld:
>>>> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:31:(.text+0x30):
>>>> undefined reference to `pause'
>>>> /home/ed/gnu/riscv64-unknown-elf/lib/gcc/riscv64-unknown-elf/14.0.1/../../../../riscv64-unknown-elf/bin/ld:
>>>> /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:31:(.text+0x38):
>>>> undefined reference to `pause'
>>>> collect2: error: ld returned 1 exit status
>>>> UNTESTED: gdb.base/relativedebug.exp: failed to compile
>>>>
>>>> so not very noisy, newlib does apparently not have alarm, pause, sleep, and similar,
>>>> but much easier to understand the output...
>>> 
>>> On the plus side, with this problem fixed gdb.base/relativedebug.exp
>>> should exit early with:
>>> 
>>> (gdb) info sharedlibrary libc.so
>>> No shared libraries matched.
>>> (gdb) UNSUPPORTED: gdb.base/relativedebug.exp: require failed: libc_has_debug_info (libc
>>> not found in the inferior)
>>> 
>>> Which will be even easier to understand the output. :-)
>>> 
>>
>> I don't think that's a good outcome, actually.  It'll disable the testcase on systems that
>> link
>> with their libc statically (even if has debug info), or systems that name their libc
>> something else.
>> And I worry that the require predicate will start being used more with that particularity.
>>
>> The original check only returned early if a library called "*libc*" was found, and, it
>> didn't
>> have debug info.  If those conditions didn't match, the testcase proceeded.  That seems a
>> lot safer.  As in, only if we know for sure we have a libc without debug info, do we
>> return early.
>
> Ok, makes sense. I'll submit a patch for the libc_has_debug_info that
> makes it behave like the original check in gdb.base/relativedebug.exp
> did.

Here it is:

https://inbox.sourceware.org/gdb-patches/20240430015325.89780-1-thiago.bauermann@linaro.org/
diff mbox series

Patch

diff --git a/gdb/testsuite/gdb.base/relativedebug.exp b/gdb/testsuite/gdb.base/relativedebug.exp
index bf8d76887122..f882a5cf1676 100644
--- a/gdb/testsuite/gdb.base/relativedebug.exp
+++ b/gdb/testsuite/gdb.base/relativedebug.exp
@@ -13,7 +13,7 @@ 
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-require {!target_info exists gdb,nosignals}
+require {!target_info exists gdb,nosignals} libc_has_debug_info
 
 standard_testfile .c
 
@@ -28,17 +28,6 @@  clean_restart ${binfile}
 
 runto_main
 
-set test "info sharedlibrary"
-gdb_test_multiple $test $test {
-    -re ".*\(\\*\)\[^\r\n\]*/libc\.so.*$gdb_prompt $" {
-	# Skip the test below if libc doesn't have debug info.
-	unsupported "libc doesn't have debug info"
-	return -1
-    }
-    -re ".*$gdb_prompt $" {
-    }
-}
-
 # pause () -> SIGALRM -> handler () -> abort ()
 gdb_test "continue" "Program received signal SIGABRT.*"
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index cbd37fd30947..1e26937c0dcf 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3699,6 +3699,62 @@  proc support_displaced_stepping {} {
     return 0
 }
 
+# Return 1 if GDB can find the libc debug info, or 0 and a reason string if it
+# can't.  This procedure is meant to be called by the require procedure.
+gdb_caching_proc libc_has_debug_info {} {
+    global srcdir subdir gdb_prompt inferior_exited_re
+
+    set me "libc_has_debug_info"
+
+    # Compile a test program.
+    set src {
+	#include <stdio.h>
+
+	int main (void) {
+	    printf ("Hello, world!\n");
+	    return 0;
+	}
+    }
+    if {![gdb_simple_compile $me $src executable {debug}]} {
+	return [list 0 "failed to compile test program"]
+    }
+
+    # No error message, compilation succeeded so now run it via gdb.
+
+    gdb_exit
+    gdb_start
+    gdb_reinitialize_dir $srcdir/$subdir
+    gdb_load "$obj"
+    runto_main
+    set test "info sharedlibrary libc.so"
+    gdb_test_multiple $test $test {
+	-re ".*\(\\*\)\[^\r\n\]*/libc\.so.*$gdb_prompt $" {
+	    # Matched the "(*)" in the "Syms Read" columns which means:
+	    # "(*): Shared library is missing debugging information."
+	    verbose -log "$me: libc doesn't have debug info"
+	    set libc_has_debug_info 0
+	    set message "libc doesn't have debug info"
+	}
+	-re ".*Yes\[ \t\]+\[^\r\n\]*/libc\.so.*$gdb_prompt $" {
+	    verbose -log "$me: libc has debug info"
+	    set libc_has_debug_info 1
+	}
+	default {
+	    set libc_has_debug_info 0
+	    set message "libc not found in the inferior"
+	}
+    }
+    gdb_exit
+    remote_file build delete $obj
+
+    verbose "$me: returning $libc_has_debug_info" 2
+    if { $libc_has_debug_info } {
+	return $libc_has_debug_info
+    } else {
+	return [list $libc_has_debug_info $message]
+    }
+}
+
 # Run a test on the target to see if it supports vmx hardware.  Return 1 if so, 
 # 0 if it does not.  Based on 'check_vmx_hw_available' from the GCC testsuite.