Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Josh Stone <jistone@redhat.com>
To: Yao Qi <qiyaoltc@gmail.com>
Cc: Pedro Alves <palves@redhat.com>,
	gdb-patches@sourceware.org,        philippe.waroquiers@skynet.be,
	sergiodj@redhat.com, eliz@gnu.org,        xdje42@gmail.com,
	scox@redhat.com
Subject: Re: [PATCH v4] Implement 'catch syscall' for gdbserver
Date: Thu, 31 Mar 2016 01:10:00 -0000	[thread overview]
Message-ID: <56FC78E3.6020300@redhat.com> (raw)
In-Reply-To: <86io04rw7k.fsf@gmail.com>

On 03/30/2016 05:23 AM, Yao Qi wrote:
> Josh Stone <jistone@redhat.com> writes:
> 
> Hi Josh,
> Thanks for the looking into this...
> 
>> So, it seems those architectures don't preserve their original syscall
>> numbers across an execve.
>>
>> $ gdb -ex 'catch syscall execve' -ex 'run' -ex 'catch syscall' \
>>   -ex 'continue' --args sh -c /bin/true
>>
>> PPC64 and Aarch64 both read their syscall numbers from registers, and
>> here they both get 0 ("restart_syscall" and "io_setup" respectively).
>> S390X tries to decode it from the SVC instruction at PC-2, which will
>> definitely fail after an execve -- gdb reports syscall -1.
> 
> I think it reveals a bug on getting syscall number.  If the register
> having syscall number isn't preserved across the syscall, GDB should
> read syscall number somewhere else.

Well, sure, but I have no idea where that somewhere else could be.

Note these architectures do work for other syscall returns.  It's just
that execve is a bit special by switching the whole process out.

I suppose we could try to save the number on syscall entry, and just
report that again when it returns.  But it's not 100% sure that we'll
see every entry first.  For instance, one could 'catch execve' first,
which will continue until PTRACE_EVENT_EXEC mid-syscall, then turn on
'catch syscall' and see what returns.
(This is similar to what test_catch_syscall_mid_vfork checks.)


BTW, even x86 is a little suspect if you cross compat modes.  The number
is preserved in orig_rax, but if you exec'ed from a 64-bit process to
32-bit, that number would still be the 64-bit NR_execve.  It happens to
still apparently work in that case because gdb isn't reloading its
syscall mapping.  But continue and it next gets:

Catchpoint 2 (call to syscall recvfrom), 0xf7ff29b9 in brk () from
/lib/ld-linux.so.2

i.e. 32-bit syscall brk is incorrectly called recvfrom.

>> So when the catchpoint is only for execve, they continue past this one
>> since the number doesn't look like execve.
>>
>> The good news is that all three do call it a syscall *return*, which was
>> the main point of this particular test.  If there's no objection, I can
>> try to update the test to work more like my command above, matching any
>> syscall at all on the return side of execve.
> 


  reply	other threads:[~2016-03-31  1:10 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-30 11:02 [PATCH] " Josh Stone
2015-10-30 13:26 ` Eli Zaretskii
2015-11-01 22:15 ` Doug Evans
2015-11-02 18:24   ` Josh Stone
2015-11-21 10:29     ` Philippe Waroquiers
2015-11-23  4:20       ` Doug Evans
2015-11-23  4:20 ` Doug Evans
2015-11-25  2:37   ` Josh Stone
2015-11-26  2:53 ` [PATCH v2 1/2] gdbserver: Set Linux ptrace options ASAP Josh Stone
2015-11-26  2:54   ` [PATCH v2 2/2] Implement 'catch syscall' for gdbserver Josh Stone
2015-11-26 10:34   ` [PATCH v2 1/2] gdbserver: Set Linux ptrace options ASAP Pedro Alves
2015-11-30 18:50     ` Josh Stone
2015-12-01 20:17       ` Josh Stone
2015-12-02 14:01         ` Pedro Alves
2015-12-04  2:26   ` [PATCH v3 1/2] gdbserver: set ptrace flags after creating inferiors Josh Stone
2015-12-04  2:27     ` [PATCH v3 2/2] Implement 'catch syscall' for gdbserver Josh Stone
2015-12-04  8:45       ` Eli Zaretskii
2015-12-05  2:14         ` Josh Stone
2015-12-05  8:02           ` Eli Zaretskii
2015-12-07 16:50             ` Josh Stone
2015-12-07 17:15               ` Eli Zaretskii
2015-12-04 13:18       ` Pedro Alves
2015-12-05  2:16         ` Josh Stone
2015-12-08 13:31           ` Pedro Alves
2015-12-08 19:02             ` Josh Stone
2015-12-08 13:37           ` Pedro Alves
2015-12-11 21:19           ` Josh Stone
2015-12-16 15:42             ` Pedro Alves
2016-01-09  3:09       ` [PATCH v4] " Josh Stone
2016-01-09  7:37         ` Eli Zaretskii
2016-01-11 17:44         ` Philippe Waroquiers
2016-01-12 12:05         ` Pedro Alves
2016-01-12 19:10           ` Josh Stone
2016-01-12 19:22             ` Pedro Alves
2016-01-12 20:01               ` Josh Stone
2016-03-29 14:27                 ` Yao Qi
2016-03-29 18:12                   ` Josh Stone
2016-03-29 23:49                     ` Josh Stone
2016-03-30 12:23                       ` Yao Qi
2016-03-31  1:10                         ` Josh Stone [this message]
2016-04-01 13:05                           ` Yao Qi
2016-04-01 16:38                             ` Josh Stone
2016-05-29 16:47         ` [doc] NEWS: QCatchSyscalls: simplify Jan Kratochvil
2016-05-29 17:29           ` Eli Zaretskii
2016-05-29 17:50             ` Jan Kratochvil
2016-05-29 18:19               ` Eli Zaretskii
2016-05-29 18:47                 ` [commit] " Jan Kratochvil
2015-12-04 12:16     ` [PATCH v3 1/2] gdbserver: set ptrace flags after creating inferiors Pedro Alves
2015-12-05  2:14       ` Josh Stone

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56FC78E3.6020300@redhat.com \
    --to=jistone@redhat.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=philippe.waroquiers@skynet.be \
    --cc=qiyaoltc@gmail.com \
    --cc=scox@redhat.com \
    --cc=sergiodj@redhat.com \
    --cc=xdje42@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox