[PATCH] Fix fail in gdb.server/wrapper.exp

Yao Qi qiyaoltc@gmail.com
Tue Jul 14 12:38:00 GMT 2015


We are testing i686-linux GDB (Fedora-i686) on an x86_64-linux box
(fedora-x86-64-4) in buildbot, such configuration causes fails in
gdb.server/wrapper.exp like this:

spawn /home/gdb-buildbot-2/fedora-x86-64-4/fedora-i686/build/gdb/testsuite/../../gdb/gdbserver/gdbserver --once --wrapper env TEST=1 -- :2346 /home/gdb-buildbot-2/fedora-x86-64-4/fedora-i686/build/gdb/testsuite/outputs/gdb.server/wrapper/wrapper
Process /home/gdb-buildbot-2/fedora-x86-64-4/fedora-i686/build/gdb/testsuite/outputs/gdb.server/wrapper/wrapper created; pid = 8795
Can't debug 64-bit process with 32-bit GDBserver
Exiting
target remote localhost:2346
localhost:2346: Connection timed out.
(gdb) FAIL: gdb.server/wrapper.exp: setting breakpoint at marker

See https://sourceware.org/ml/gdb-testers/2015-q3/msg01541.html

I can reproduce this fail on my ubuntu box as well.  "wrapper" is
32-bit, but when GDBserver option --wrapper is used, the wrapper
program is executed to launch the program, and the wrapper is
/usr/bin/env in this case.  In
gdbserver/linux-x86-low.c:x86_linux_read_description, GDBserver
checks whether the executable is 64-bit or not by means of
/proc/PID/exe, which is the symbol-link to the wrapper, instead
of the test program.  Since 32-bit GDBserver is being used, it
refuse to debug 64-bit process (/usr/bin/env) and exit.

The fix to this problem is to write a simple "env" in c and it is
compiled to 32-bit mode together with wrapper.c.  So gdbserver,
env and wrapper are all 32-bit.

gdb/testsuite:

2015-07-14  Yao Qi  <yao.qi@linaro.org>

	* gdb.server/wrapper.exp: Compile env.c.
	* gdb.server/env.c: New file.
---
 gdb/testsuite/gdb.server/env.c       | 30 ++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.server/wrapper.exp |  8 ++++++--
 2 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 gdb/testsuite/gdb.server/env.c

diff --git a/gdb/testsuite/gdb.server/env.c b/gdb/testsuite/gdb.server/env.c
new file mode 100644
index 0000000..5659f37
--- /dev/null
+++ b/gdb/testsuite/gdb.server/env.c
@@ -0,0 +1,30 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2015 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>
+#include <unistd.h>
+
+int
+main (int argc, char **argv)
+{
+  char *new_argv[] = { argv[2], NULL };
+  char *new_envp[] = { argv[1], NULL };
+
+  execve (new_argv[0], &new_argv[0], new_envp);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.server/wrapper.exp b/gdb/testsuite/gdb.server/wrapper.exp
index 17d5abb..44265f6 100644
--- a/gdb/testsuite/gdb.server/wrapper.exp
+++ b/gdb/testsuite/gdb.server/wrapper.exp
@@ -19,7 +19,7 @@
 
 load_lib gdbserver-support.exp
 
-standard_testfile
+standard_testfile .c env.c
 
 if { [skip_gdbserver_tests] } {
     return 0
@@ -31,6 +31,10 @@ if { [istarget *-*-mingw*]
     return -1
 }
 
+set binfile2 [standard_output_file "env"]
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
+    return -1
+}
 if { [prepare_for_testing $testfile.exp $testfile $srcfile debug] } {
     return -1
 }
@@ -41,7 +45,7 @@ gdb_test "disconnect" ".*"
 
 set target_exec [gdbserver_download_current_prog]
 # Start GDBserver with option '--wrapper'.
-set res [gdbserver_start "--wrapper env TEST=1 --" $target_exec]
+set res [gdbserver_start "--wrapper ${binfile2} TEST=1 --" $target_exec]
 
 set gdbserver_protocol [lindex $res 0]
 set gdbserver_gdbport [lindex $res 1]
-- 
1.9.1



More information about the Gdb-patches mailing list