This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA 7/7] Linker-debugger interface tests


On Thu, 16 May 2013 16:48:57 +0200, Gary Benson wrote:
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/break-probes.exp
> @@ -0,0 +1,77 @@
> +# Copyright 2013 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +if { [skip_shlib_tests] } {
> +    return 0
> +}
> +
> +standard_testfile
> +
> +set libname $testfile-solib
> +set srcfile_lib $srcdir/$subdir/$libname.c
> +set binfile_lib [standard_output_file $libname.so]
> +
> +set normal_bp "_dl_debug_state"
> +set probes_bp "dl_main"
> +
> +if { [gdb_compile_shlib $srcfile_lib $binfile_lib \
> +	  [list additional_flags=-fPIC]] != "" } {
> +    untested "Could not compile $binfile_lib."
> +    return -1
> +}
> +
> +if { [prepare_for_testing $testfile.exp $testfile $srcfile \

> +	  [list additional_flags=-DSHLIB_NAME\=\"$binfile_lib\" libs=-ldl]] } {

There is an excessive backslash at the '=' sign:
	  [list additional_flags=-DSHLIB_NAME=\"$binfile_lib\" libs=-ldl]] } {


> +    return -1
> +}
> +
> +# Enable stop-on-solib-events
> +gdb_test_no_output "set stop-on-solib-events 1"
> +
> +# Start the inferior and run to the first stop
> +gdb_run_cmd
> +gdb_test "" ".*Stopped due to shared library event.*"
> +
> +# XFAIL if we are not using probes
> +set test "ensure using probes"
> +set using_probes 0
> +gdb_test_multiple "bt" $test {
> +    -re "#0 +\[^\r\n\]*\\m(__GI_)?$normal_bp\\M.*$gdb_prompt $" {
> +	xfail $test

One should also call: untested "probes not present on this system"

or: xfail "$test (probes not present on this system)"


> +    }
> +    -re "#0 +\[^\r\n\]*\\m(__GI_)?$probes_bp\\M.*$gdb_prompt $" {
> +	pass $test
> +	set using_probes 1
> +    }
> +}
> +
> +if { $using_probes } {
> +    # Run til it loads our library
> +    set test "run til our library loads"
> +    set loaded_library 0
> +    while { !$loaded_library } {
> +	gdb_test_multiple "c" $test {
> +	    -re "Inferior loaded $binfile_lib\\M.*$gdb_prompt $" {
> +		pass $test
> +		set loaded_library 1
> +	    }
> +	    -re "Stopped due to shared library event\\M.*$gdb_prompt $" {
> +	    }
> +	}
> +    }

If for some reason the 'pass $test' part never happens the testcase deadlocks:
	FAIL: gdb.base/break-probes.exp: run til our library loads (the program is no longer running)
	FAIL: gdb.base/break-probes.exp: run til our library loads (the program is no longer running)
	FAIL: gdb.base/break-probes.exp: run til our library loads (the program is no longer running)
	[... ad infinitum ]


One of the solutions would be for example:

    set not_loaded_library 1
    while { $not_loaded_library } {
	set not_loaded_library 0
	gdb_test_multiple "c" $test {
	    -re "Inferior loaded $binfile_lib\\M.*$gdb_prompt $" {
		pass $test
	    }
	    -re "Stopped due to shared library event\\M.*$gdb_prompt $" {
		set not_loaded_library 1
	    }
	}
    }


> +
> +    # Call something to ensure that relocation occurred
> +    gdb_test "call foo(23)" "\\\$.* = 31.*\\\M.*"
> +}
> diff --git a/gdb/testsuite/gdb.base/break-probes.c b/gdb/testsuite/gdb.base/break-probes.c
> new file mode 100644
> index 0000000..a778099
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/break-probes.c
> @@ -0,0 +1,26 @@
> +/* Copyright 2013 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +#include <dlfcn.h>
> +
> +int
> +main ()
> +{
> +  void *handle = dlopen (SHLIB_NAME, RTLD_LAZY);
> +
> +  dlclose (handle);
> +
> +  return 0;
> +}
> diff --git a/gdb/testsuite/gdb.base/break-probes-solib.c b/gdb/testsuite/gdb.base/break-probes-solib.c
> new file mode 100644
> index 0000000..bdde2db
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/break-probes-solib.c
> @@ -0,0 +1,22 @@
> +/* Copyright 2013 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +#include <stdio.h>
> +
> +int
> +foo (int n)
> +{
> +  return n * n / 17;
> +}
> diff --git a/gdb/testsuite/gdb.base/info-shared.exp b/gdb/testsuite/gdb.base/info-shared.exp
> new file mode 100644
> index 0000000..1dabb9f
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/info-shared.exp
> @@ -0,0 +1,145 @@
> +# Copyright 2013 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +if { [skip_shlib_tests] } {
> +    return 0
> +}
> +
> +standard_testfile
> +
> +set lib1name $testfile-solib1
> +set srcfile_lib1 $srcdir/$subdir/$lib1name.c
> +set binfile_lib1 [standard_output_file $lib1name.so]
> +set define1 -DSHLIB1_NAME\=\"$binfile_lib1\"

Again an excessive backslash before '=', what reason do you see there for it?

> +
> +set lib2name $testfile-solib2
> +set srcfile_lib2 $srcdir/$subdir/$lib2name.c
> +set binfile_lib2 [standard_output_file $lib2name.so]
> +set define2 -DSHLIB2_NAME\=\"$binfile_lib2\"

Again an excessive backslash before '=', what reason do you see there for it?


> +
> +if { [gdb_compile_shlib $srcfile_lib1 $binfile_lib1 \
> +	  [list additional_flags=-fPIC]] != "" } {
> +    untested "Could not compile $binfile_lib1."
> +    return -1
> +}
> +
> +if { [gdb_compile_shlib $srcfile_lib2 $binfile_lib2 \
> +	  [list additional_flags=-fPIC]] != "" } {
> +    untested "Could not compile $binfile_lib2."
> +    return -1
> +}
> +
> +set cflags "$define1 $define2"
> +if { [prepare_for_testing $testfile.exp $testfile $srcfile \
> +	  [list additional_flags=$cflags libs=-ldl]] } {
> +    return -1
> +}
> +
> +# Run "info sharedlibrary" and check for the presence or absence of
> +# our libraries.
> +proc check_info_shared { test expect1 expect2 } {
> +    global lib1name
> +    global lib2name
> +    global gdb_prompt
> +
> +    set actual1 0
> +    set actual2 0
> +
> +    gdb_test_multiple "info sharedlibrary" $test {
> +	-re $lib1name {
> +	    set actual1 1
> +	    exp_continue
> +	}
> +	-re $lib2name {
> +	    set actual2 1
> +	    exp_continue
> +	}
> +	-re "\r\n$gdb_prompt $" {
> +	    if { $actual1 == $expect1 && $actual2 == $expect2 } {
> +		pass $test
> +	    } else {
> +		fail $test
> +	    }
> +	}
> +    }
> +}
> +
> +# Start the inferior, and check neither of the libraries are loaded at
> +# the start.
> +runto_main

if ![runto_main] {
    return 0
}


> +check_info_shared "info sharedlibrary #1" 0 0
> +
> +# Set up breakpoints.
> +gdb_test "break stop" {Breakpoint [0-9]+ at .*}

gdb_breakpoint ...

More cases below.


> +gdb_test_no_output "set breakpoint pending on"

gdb_breakpoint XXX allow-pending


> +gdb_test "break foo" {Breakpoint [0-9]+ \(foo\) pending\.}
> +gdb_test "break bar" {Breakpoint [0-9]+ \(bar\) pending\.}
> +
> +# Run to the first stop and check that only the first library is loaded.
> +gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}

gdb_continue_to_breakpoint

More cases below.


> +check_info_shared "info sharedlibrary #2" 1 0
> +
> +# Run to the second stop and check that both libraries are loaded.
> +gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
> +check_info_shared "info sharedlibrary #3" 1 1
> +
> +# Check that the next stop is in foo.
> +gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
> +
> +# Check that the next stop is in bar.
> +gdb_test "c" {Breakpoint [0-9]+, .* in bar \(\) from .*}
> +
> +# Restart the inferior and make sure there are no breakpoint reset
> +# errors.  These can happen with the probes-based runtime linker
> +# interface if the cache is not cleared correctly.
> +set test "restart"
> +gdb_run_cmd
> +gdb_test_multiple "" $test {
> +    -re {Start it from the beginning\? \(y or n\) } {

trailing '$':
       -re {Start it from the beginning\? \(y or n\) $} {


> +	send_gdb "y\n"
> +	exp_continue
> +    }
> +    -re {Error in re-setting breakpoint} {
> +	fail $test
> +    }
> +    -re "\r\n$gdb_prompt $" {
> +	pass $test
> +    }
> +}
> +
> +# Check that neither library is loaded.
> +check_info_shared "info sharedlibrary #4" 0 0
> +
> +# Run to the first stop and check that only the first library is loaded.
> +gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
> +check_info_shared "info sharedlibrary #5" 1 0
> +
> +# Run to the second stop and check that both libraries are loaded.
> +gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
> +check_info_shared "info sharedlibrary #6" 1 1
> +
> +# Check that the next stop is in foo.
> +gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
> +
> +# Check that the next stop is in bar.
> +gdb_test "c" {Breakpoint [0-9]+, .* in bar \(\) from .*}
> +
> +# Run to the next stop and check that the first library has been unloaded.
> +gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
> +check_info_shared "info sharedlibrary #7" 0 1
> +
> +# Run to the last stop and check that both libraries are gone.
> +gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
> +check_info_shared "info sharedlibrary #8" 0 0
> diff --git a/gdb/testsuite/gdb.base/info-shared.c b/gdb/testsuite/gdb.base/info-shared.c
> new file mode 100644
> index 0000000..d699a11
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/info-shared.c
> @@ -0,0 +1,48 @@
> +/* Copyright 2013 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +#include <dlfcn.h>
> +
> +void
> +stop ()

stop (void)

> +{
> +}
> +
> +int
> +main ()

main (void)

> +{
> +  void *handle1, *handle2;
> +  void (*func)(int);
> +
> +  handle1 = dlopen (SHLIB1_NAME, RTLD_LAZY);

I believe here could be:
    assert (handle1 != NULL);

etc. below, if it fails the troubleshooting is easier then.


> +  stop ();
> +
> +  handle2 = dlopen (SHLIB2_NAME, RTLD_LAZY);
> +  stop ();
> +
> +  func = (void (*)(int)) dlsym (handle1, "foo");
> +  func (1);
> +
> +  func = (void (*)(int)) dlsym (handle2, "bar");
> +  func (2);
> +
> +  dlclose (handle1);
> +  stop ();
> +
> +  dlclose (handle2);
> +  stop ();
> +
> +  return 0;
> +}
> diff --git a/gdb/testsuite/gdb.base/info-shared-solib1.c b/gdb/testsuite/gdb.base/info-shared-solib1.c
> new file mode 100644
> index 0000000..9979ee7
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/info-shared-solib1.c
> @@ -0,0 +1,24 @@
> +/* Copyright 2013 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +#include <stdio.h>
> +
> +int
> +foo (int n)
> +{
> +  printf ("foo %d\n", n);
> +
> +  return 0;
> +}
> diff --git a/gdb/testsuite/gdb.base/info-shared-solib2.c b/gdb/testsuite/gdb.base/info-shared-solib2.c
> new file mode 100644
> index 0000000..d4ed1e6
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/info-shared-solib2.c
> @@ -0,0 +1,24 @@
> +/* Copyright 2013 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +#include <stdio.h>
> +
> +int
> +bar (int n)
> +{
> +  printf ("bar %d\n", n);
> +
> +  return 0;
> +}



Thanks,
Jan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]