diff --git a/gprofng/src/envsets.cc b/gprofng/src/envsets.cc
index 1ca39ed9ac1..9cef7452df7 100644
--- a/gprofng/src/envsets.cc
+++ b/gprofng/src/envsets.cc
@@ -146,20 +146,42 @@ collect::putenv_libcollector_ld_misc ()
// so that -agentlib:gp-collector works
// and so that collect -F works with 32/64-bit mix of processes
- // Set GPROFNG_PRELOAD_LIBDIRS
+ StringBuilder sb;
+ sb.append ("SP_COLLECTOR_LIBRARY_PATH=");
+ int len = sb.length ();
+ int cnt = 0;
+ char *fname;
char *ev = getenv (GPROFNG_PRELOAD_LIBDIRS);
char *libpath_list = NULL;
- if (ev == NULL && settings->preload_libdirs == NULL)
+ if (ev)
+ { /* GPROFNG_PRELOAD_LIBDIRS is used only in the gprofng testing.
+ * Use these directories first. */
+ ev = strdup (ev);
+ for (char *s = ev; s;)
+ {
+ char *s1 = strchr (s, ':');
+ if (s1)
+ *(s1++) = 0;
+ fname = dbe_sprintf ("%s/%s", s, LIBGP_COLLECTOR);
+ if (access (fname, R_OK | F_OK) == 0)
+ {
+ if (++cnt != 1)
+ sb.append (':');
+ sb.append (s);
+ }
+ free (fname);
+ s = s1;
+ }
+ free (ev);
+ ev = NULL;
+ }
+ if (settings->preload_libdirs == NULL)
{
settings->read_rc (false);
ev = settings->preload_libdirs;
}
ev = dbe_strdup (ev);
- StringBuilder sb;
- sb.appendf ("%s=", "SP_COLLECTOR_LIBRARY_PATH");
- int len = sb.length ();
- int cnt = 0;
- char *fname = dbe_sprintf ("%s/%s/%s", LIBDIR, PACKAGE, LIBGP_COLLECTOR);
+ fname = dbe_sprintf ("%s/%s/%s", LIBDIR, PACKAGE, LIBGP_COLLECTOR);
if (access (fname, R_OK | F_OK) == 0)
{
++cnt;
diff --git a/gprofng/testsuite/config/default.exp 
b/gprofng/testsuite/config/default.exp
index e22d99bc422..6b51d578d9f 100644
--- a/gprofng/testsuite/config/default.exp
+++ b/gprofng/testsuite/config/default.exp
@@ -19,6 +19,7 @@
# MA 02110-1301, USA.
#
+
# The "make check" target in the Makefile passes in
# "CC=$(CC_FOR_TARGET)". But, if the user invokes runtest directly,
# these flags may not be set.
@@ -36,18 +37,32 @@ remote_exec host "sh -c \"rm -rf tmpdir; mkdir -p 
tmpdir\""
if { "$CHECK_TARGET" == "check-install" } {
set ::env(GPROFNG) "$PREFIX/bin/gprofng"
} else {
- # Make a temporary install dir to run gprofng from, and point at it
- remote_exec host "sh -c \"$MAKE -C .. install-gprofng 
MAKEFLAGS=program_transform_name= DESTDIR=$BUILDDIR/tmpdir/root\""
- set ::env(GPROFNG) [exec find $BUILDDIR/tmpdir -type f -name gprofng 
-perm -u+x | head -1]
-
- set x [exec find $BUILDDIR/tmpdir -type d -name gprofng | head -1]
- set ::env(LD_LIBRARY_PATH) "$x:$x/.."
-
- set x [exec find $BUILDDIR/tmpdir -type f -name gprofng.rc | head -1]
- set ::env(GPROFNG_SYSCONFDIR) [exec dirname $x]
+ set ld_library_path "${BUILDDIR}/src/.libs:${BUILDDIR}/libcollector/.libs"
+ set orig_ld_library_path ""
+ catch { set orig_ld_library_path $::env(LD_LIBRARY_PATH) }
+ if [file exists "${BUILDDIR}/../bfd/.libs/libbfd.a"] {
+ append ld_library_path ":${BUILDDIR}/../bfd/.libs"
+ }
+ if [file exists "${BUILDDIR}/../opcodes/.libs/libopcodes.a"] {
+ append ld_library_path ":${BUILDDIR}/../opcodes/.libs"
+ }
+ if [file exists "${BUILDDIR}/../libsframe/.libs/libsframe.a"] {
+ append ld_library_path ":${BUILDDIR}/../libsframe/.libs"
+ }
+ if [file exists "${BUILDDIR}/../libiberty/libiberty.a"] {
+ append ld_library_path ":${BUILDDIR}/../libiberty"
+ }
- puts "### LD_LIBRARY_PATH: $env(LD_LIBRARY_PATH)"
- puts "### GPROFNG_SYSCONFDIR: $env(GPROFNG_SYSCONFDIR)"
+ set f [open "gprofng_wraper" w+]
+ puts $f "#!/usr/bin/bash"
+ puts $f "LD_LIBRARY_PATH=$ld_library_path:$orig_ld_library_path"
+ puts $f "GPROFNG_SYSCONFDIR=$env(srcroot)/src"
+ puts $f "GPROFNG_PRELOAD_LIBDIRS=$BUILDDIR/libcollector/.libs"
+ puts $f "export LD_LIBRARY_PATH GPROFNG_SYSCONFDIR 
GPROFNG_PRELOAD_LIBDIRS"
+ puts $f "${BUILDDIR}/src/gprofng \"\$@\""
+ close $f
+ file attributes gprofng_wraper -permissions +rx
+ set ::env(GPROFNG) "$BUILDDIR/gprofng_wraper"
}
puts "### GPROFNG: $env(GPROFNG)"
diff --git a/gprofng/testsuite/lib/display-lib.exp 
b/gprofng/testsuite/lib/display-lib.exp
index 4843c3678bf..32e8ce5dd73 100644
--- a/gprofng/testsuite/lib/display-lib.exp
+++ b/gprofng/testsuite/lib/display-lib.exp
@@ -26,8 +26,8 @@ proc run_native_host_cmd { command } {
verbose -log "$command"
set run_output ""
try {
- send_log "% timeout $TEST_TIMEOUT sh -c '$command' 2>&1\n"
- set run_output [exec "timeout" $TEST_TIMEOUT "sh" "-c" "$command" "2>&1"]
+ send_log "% timeout $TEST_TIMEOUT sh -c '$command' 2>@1\n"
+ set run_output [exec "timeout" $TEST_TIMEOUT "sh" "-c" "$command" "2>@1"]
set status 0
} trap CHILDSTATUS {results options} {
set status [lindex [dict get $options -errorcode] 2]
