public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix fail in gdb.server/wrapper.exp
@ 2015-07-14 12:38 Yao Qi
  2015-07-14 12:50 ` Pedro Alves
  0 siblings, 1 reply; 4+ messages in thread
From: Yao Qi @ 2015-07-14 12:38 UTC (permalink / raw)
  To: gdb-patches

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix fail in gdb.server/wrapper.exp
  2015-07-14 12:38 [PATCH] Fix fail in gdb.server/wrapper.exp Yao Qi
@ 2015-07-14 12:50 ` Pedro Alves
  2015-07-14 13:37   ` Yao Qi
  0 siblings, 1 reply; 4+ messages in thread
From: Pedro Alves @ 2015-07-14 12:50 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 07/14/2015 01:38 PM, Yao Qi wrote:
> 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.

But why is gdbserver trying to compute a target description for /usr/bin/env?
That's not the target process.  We shouldn't try to read registers,
memory, etc. out of it, just like native gdb doesn't read anything
out of the shell process, and I assume, of
the "set exec-wrapper" process.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix fail in gdb.server/wrapper.exp
  2015-07-14 12:50 ` Pedro Alves
@ 2015-07-14 13:37   ` Yao Qi
  2015-07-14 14:53     ` Pedro Alves
  0 siblings, 1 reply; 4+ messages in thread
From: Yao Qi @ 2015-07-14 13:37 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Yao Qi, gdb-patches

Pedro Alves <palves@redhat.com> writes:

> But why is gdbserver trying to compute a target description for /usr/bin/env?
> That's not the target process.  We shouldn't try to read registers,
> memory, etc. out of it, just like native gdb doesn't read anything
> out of the shell process, and I assume, of
> the "set exec-wrapper" process.

I see what you mean.  GDBserver creates target description when it is
still skipping the extra trap,

(gdb) bt
#0  x86_linux_read_description () at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-x86-low.c:1159
#1  0x0807ea77 in x86_arch_setup () at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-x86-low.c:1434
#2  0x080705a2 in linux_low_filter_event (lwpid=26024, wstat=1407) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:2114
#3  0x08070cee in linux_wait_for_event_filtered (wait_ptid=..., filter_ptid=..., wstatp=0xffffccdc, options=1073741824)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:2362
#4  0x08070fa4 in linux_wait_for_event (ptid=..., wstatp=0xffffccdc, options=1073741824) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:2456
#5  0x080715d7 in linux_wait_1 (ptid=..., ourstatus=0x80aba14 <last_status>, target_options=0)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:2778
#6  0x080728f3 in linux_wait (ptid=..., ourstatus=0x80aba14 <last_status>, target_options=0)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:3350
#7  0x0805a558 in mywait (ptid=..., ourstatus=0x80aba14 <last_status>, options=0, connected_wait=0)
    at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/target.c:107
#8  0x08051e38 in start_inferior (argv=0x80b4308) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/server.c:258

on frame #8, GDBserver resumes the inferior and waits for it to skip the
extra trap caused by exec-wrapper.  GDBserver creates target description
too early, and the fix should be creating target description after
GDBserver skips the extra trap and when the inferior stops at the target
process.  I'll give a new patch.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix fail in gdb.server/wrapper.exp
  2015-07-14 13:37   ` Yao Qi
@ 2015-07-14 14:53     ` Pedro Alves
  0 siblings, 0 replies; 4+ messages in thread
From: Pedro Alves @ 2015-07-14 14:53 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 07/14/2015 02:36 PM, Yao Qi wrote:

> on frame #8, GDBserver resumes the inferior and waits for it to skip the
> extra trap caused by exec-wrapper.  GDBserver creates target description
> too early, and the fix should be creating target description after
> GDBserver skips the extra trap and when the inferior stops at the target
> process.  I'll give a new patch.
> 

Exactly.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-07-14 14:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-14 12:38 [PATCH] Fix fail in gdb.server/wrapper.exp Yao Qi
2015-07-14 12:50 ` Pedro Alves
2015-07-14 13:37   ` Yao Qi
2015-07-14 14:53     ` Pedro Alves

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).