From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wP/LLXJsnWGmOwAAWB0awg (envelope-from ) for ; Tue, 23 Nov 2021 17:34:26 -0500 Received: by simark.ca (Postfix, from userid 112) id B7E481F0CE; Tue, 23 Nov 2021 17:34:26 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_DYNAMIC autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D6E121EDF0 for ; Tue, 23 Nov 2021 17:34:25 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2187D385801F for ; Tue, 23 Nov 2021 22:34:25 +0000 (GMT) Received: from mx2.freebsd.org (mx2.freebsd.org [IPv6:2610:1c1:1:606c::19:2]) by sourceware.org (Postfix) with ESMTPS id 3EF113858D28 for ; Tue, 23 Nov 2021 22:34:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3EF113858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id B75EE7636A; Tue, 23 Nov 2021 22:34:10 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HzJpV2k4mz3hw4; Tue, 23 Nov 2021 22:34:10 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from [10.0.1.4] (ralph.baldwin.cx [66.234.199.215]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id C1822272A7; Tue, 23 Nov 2021 22:34:09 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: Date: Tue, 23 Nov 2021 14:34:08 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: [PATCH] gdb fix for catch-syscall.exp Content-Language: en-US To: Simon Marchi , Carl Love , gdb-patches@sourceware.org References: <3b8e450b9fb4f4bec97a6bfbe6e6a4816be780ee.camel@us.ibm.com> <4d51616392553dd308672f65f18909ebf0513fc0.camel@us.ibm.com> <95fbffc3-8d30-6e75-4f52-f6e534a13b20@FreeBSD.org> From: John Baldwin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637706850; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q4KNzS8zIkHpQI3utLt7I6PhJB2XFdw8w/X0v/Hxnws=; b=X8Py9dey0/H29TE4q4Ap04zxeU6DdpxlJKMrYQfkyGYIBh/woHRQdTaPPC02bEpS2RFYYB 7tGry5cpm5ZQAZNAhCxQcKHMBx31xxFHUiWJ3uNqqLtBI/bOwADfEqLHyBImxmtpJugyHY G6lG5W0EPfWg/KkGi9SIZk/xwNbEnUSLcCSHQrw9ZD3Rij77mtDO63yRyjN4kA/sSaTejw MjSvIsAVEfuZTB9a6R1HhADbg4fKogyWBs8uummCs15wEQ/wz5kfFuFnN3jvFjmUM0z4wY hKX/kvu6oYOUDduGttxgbzl7g12qdFQxtN49qcuni9I++c3zp/W51DRkOvQ/bA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637706850; a=rsa-sha256; cv=none; b=PvAztTu9EA0TZVePL7WBJKuC1vZmsTbE9qSvs+TODTWL4TxDUmiucxc0i0Koq8IrZO4XD9 PunTY0GB+A2A1FxaEq95aqlg0negZH3Vk8xYzznLV/sphupuLbTS8/XEsmOnC9I3cax0rC IwJNiTAXLPRWnZMdEVmFbup2tENj9Yleocs803t2sijK9iWPypcSrBGNNEwZZihtd++gAZ JXIk5xD1RYtli8TIFq1RcxVdwCGQzLv4novmBtWCWsZM2Fpuo+aa7dYzt6m5+L9z47WIRk i/ENEqKSZOZ+4wPd9bO/+93xLXTFrnUfvrsEpJXaXj9cwKHPWVrBs2LDfcatNg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rogerio Alves Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 11/23/21 12:34 PM, Simon Marchi wrote: >> Note that the thread/process that calls execve() does still "return" >> from the kernel, it just returns to the entry point of the executable >> with the contents of the user address space wiped. I'm not quite sure >> how Linux treats this, but on FreeBSD at least this "return" is treated >> as a successful return from the execve system call. In fact, I think >> Linux on at least amd64 reports two events: one for an "execve" event and >> one for the system call return event judging by a commit made in FreeBSD >> to emulate ptrace() for Linux binaries: >> >> https://cgit.freebsd.org/src/commit/?id=6e66030c4c05331f9b0adf87c31f2f233dd3ae1f > > Yes, that's what I see on Linux too. With an x86-64 binary: > > > $ ./gdb -q --data-directory=data-directory m64 > Reading symbols from m64... > (gdb) catch syscall execve > Catchpoint 1 (syscall 'execve' [59]) > (gdb) r > Starting program: /home/smarchi/build/binutils-gdb-all-targets/gdb/m64 > > Catchpoint 1 (call to syscall execve), 0x00007ffff7ea92fb in execve () at ../sysdeps/unix/syscall-template.S:78 > 78 ../sysdeps/unix/syscall-template.S: No such file or directory. > (gdb) c > Continuing. > process 3592054 is executing new program: /home/smarchi/build/binutils-gdb-all-targets/gdb/m64 > > Catchpoint 1 (returned from syscall execve), 0x00007ffff7fd0100 in _start () from /lib64/ld-linux-x86-64.so.2 > > and an x86 binary (on an actual x86 kernel, not on top of an x86-64 > kernel): > > > $ ./gdb -q -nx --data-directory=data-directory ./a.out > Reading symbols from ./a.out... > (gdb) catch syscall execve > Catchpoint 1 (syscall 'execve' [11]) > (gdb) r > Starting program: /home/simark/build/binutils-gdb/gdb/a.out > > Catchpoint 1 (call to syscall execve), 0xb7fddcb0 in __kernel_vsyscall () > (gdb) c > Continuing. > process 3734 is executing new program: /home/simark/build/binutils-gdb/gdb/a.out > > Catchpoint 1 (returned from syscall execve), 0xb7fdec60 in ?? () from /lib/ld-linux.so.2 > > In both cases, we see the execve syscall return at the entry point of > the dynamic linker/loader. I tested on aarch64 too, same thing. > > I indeed see that on powerpc we don't get the return: > > $ ./gdb -q -nx --data-directory=data-directory ./a.out > Reading symbols from ./a.out... > (gdb) catch syscall execve > Catchpoint 1 (syscall 'execve' [11]) > (gdb) r > Starting program: /home/simark/build/binutils-gdb/gdb/a.out > > Catchpoint 1 (call to syscall execve), 0x00007ffff7e6f18c in execve () from /lib64/libc.so.6 > (gdb) c > Continuing. > process 98693 is executing new program: /home/simark/build/binutils-gdb/gdb/a.out > > Catchpoint 1 (call to syscall execve), 0x00007ffff7e6f18c in execve () from /lib64/libc.so.6 > > The behavior on powerpc sounds like a bug to me, and adjusting the test > like this patch did just covers it up. It doesn't make sense for that > behavior to be different per arch, for the same OS. > > If you all agree that it's a bug, I would suggest reverting this patch > and making a patch that kfails the test when on powerpc. And ideally, > someone should dig to understand why we don't see the return on powerpc > (and fix it), but I'm not here to tell what other people should work on > :). I do think this is likely a kernel bug. In FreeBSD's case we report a single event for both the syscall exit and exec event (but set flags to indicate that both events are present.. in practice for GDB I think this means that on FreeBSD we only report the exec event. Not sure if it would be more correct to report two events to the core in that case.) I do think that a given OS should probably be consistent here across architectures. -- John Baldwin