From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 8B1F33858D33 for ; Tue, 21 Nov 2023 10:24:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B1F33858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8B1F33858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.220.29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700562270; cv=none; b=U+xxArXwlTBf2yQ14fVgcSLdZCbTpIFe0Z2jg+EXSW1YNCPx6n9XhYcMOLkhtul7Eqthrm8cx/LMfi8SYyylH8VsDScokp6eCZYJRvAsvrjg/76qH2ZbCUtzJ9yGiFGLBXBp9lxkCXQhsYM4SJhVImRcpqWMno+HKcDJnqtM6hM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700562270; c=relaxed/simple; bh=26y+7urJxMivWdpH58/KN9kdXLLE3+4/lLfYCrobj4E=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version: Subject:To:From; b=jMEH+mO7g1GtFHRWLMBAuBszbnIHQgWL3PiqvF5baOi9QwRGw1EXjmILViSgcRng0E+xQe4D6IDqL4y6J9aIIW2OxBnJiB055964SW7OwCnaXP9W74QErJdzfNZiN7Xf61WwwU83gbApe4ghQyaLJyhXP9rwH5PhjCejMwomskA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 86B521F8B4; Tue, 21 Nov 2023 10:24:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1700562265; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MAwJm6JlTx4C7U4Di0JLVSDrKjZRgjR9LjIa1Ughcyo=; b=G5nK4zWieH0U1V/1QZrr4FQnWtRCawEyKGAXDvC0OuqgW10aARPrQ4cSe8uE7Mn8w/tqWi 7lPcBu6idwoblmERl6WXOVNsvjziKcEx9ov12Cd/pSHd6rFd2TZyiOItfOBz3BwCSgPSxX Y12D4+G79YXZulwvQq6wuxztmOQKIKY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1700562265; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MAwJm6JlTx4C7U4Di0JLVSDrKjZRgjR9LjIa1Ughcyo=; b=m9paP3V5GN8gUioa10RIsHuLENlV9DdgXkwL01+yp4DlDiGQ34Fe0Lqzgl+PgszbWUdptY Tjeb0/lQFKyBpNAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 76882139FD; Tue, 21 Nov 2023 10:24:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Ud3kG1mFXGWMRwAAMHmgww (envelope-from ); Tue, 21 Nov 2023 10:24:25 +0000 Message-ID: Date: Tue, 21 Nov 2023 11:26:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC 1/3] [gdb] Call gdbarch_get_syscall_number less often Content-Language: en-US To: John Baldwin , Simon Marchi , gdb-patches@sourceware.org References: <20231120153749.11072-1-tdevries@suse.de> <63c7905b-784f-4b18-9875-45fc2e3bd3f5@FreeBSD.org> From: Tom de Vries In-Reply-To: <63c7905b-784f-4b18-9875-45fc2e3bd3f5@FreeBSD.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -4.29 X-Spamd-Result: default: False [-4.29 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; XM_UA_NO_VERSION(0.01)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; BAYES_HAM(-3.00)[100.00%]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 11/21/23 01:29, John Baldwin wrote: > On 11/20/23 8:12 AM, Simon Marchi wrote: >> On 11/20/23 10:37, Tom de Vries wrote: >>> When running test-case gdb.base/catch-syscall.exp on >>> powerpc64le-linux, we run >>> into an xfail: >>> ... >>> (gdb) catch syscall execve^M >>> Catchpoint 18 (syscall 'execve' [11])^M >>> (gdb) PASS: gdb.base/catch-syscall.exp: execve: \ >>>    catch syscall with arguments (execve) >>>    ... >>> continue^M >>> Continuing.^M >>> ^M >>> Catchpoint 18 (call to syscall execve), 0x00007ffff7d7f18c in execve >>> () from \ >>>    /lib64/libc.so.6^M >>> (gdb) PASS: gdb.base/catch-syscall.exp: execve: program has called >>> execve >>> continue^M >>> Continuing.^M >>> process 60484 is executing new program: catch-syscall^M >>> ^M >>> Breakpoint 17, main (argc=1, argv=0x7fffffffe618) at >>> catch-syscall.c:54^M >>> 54              char buf1[2] = "a";^M >>> (gdb) XFAIL: gdb.base/catch-syscall.exp: execve: syscall execve has >>> returned >>> ... >>> >>> The problem is that the catchpoint "(return from syscall execve)" >>> doesn't >>> trigger. >>> >>> This is caused by ppc_linux_get_syscall_number returning 0 at execve >>> syscall-exit-stop, while it should return 11. >>> >>> This is a problem that was fixed in linux kernel version v5.19, by >>> commit >>> ec6d0dde71d7 ("powerpc: Enable execve syscall exit tracepoint"), but the >>> machine I'm running the tests on has v4.18.0. >>> >>> An approach was discussed in the PR where >>> ppc_linux_get_syscall_number would >>> try to detect an execve syscall-exit-stop based on the register >>> state, but >>> that was considered too fragile. >>> >>> Fix this by caching the syscall number at syscall-enter-stop, and >>> reusing it >>> at syscall-exit-stop. >>> >>> This is sufficient to stop triggering the xfail, so remove it. >>> >>> It's good to point out that this doesn't always eliminate the need to >>> get the >>> syscall number at a syscall-exit-stop. >>> >>> The test-case has an example called mid-vfork, where we do: >>> - catch vfork >>> - continue >>> - catch syscall >>> - continue. >>> >>> The following things happen: >>> - the "catch vfork" specifies that we capture the PTRACE_EVENT_VFORK >>> event. >>> - the first continue runs into the event >>> - the "catch syscall" specifies that we capture syscall-enter-stop and >>>    syscall-exit-stop events. >>> - the second continue runs into the syscall-exit-stop.  At that point >>> there's >>>    no syscall number value cached, because no corresponding >>> syscall-enter-stop >>>    was observed. >> >> Thanks for this example, it answers a question I had in the PR. >> >>> We can address this issue somewhat by translating events into >>> syscalls.  A >>> followup patch in this series use this approach (though not for vfork). >>> >>> This is an RFC at this point. >>> >>> I think there's an open issue with this patch: the cache needs to be >>> invalidated when we stop tracking syscalls.  I wonder if a >>> generation_counter >>> scheme would be a good approach here. >>> >>> Perhaps we can do a per-thread approach where when continuing a >>> thread we >>> reset the cached value unless PTRACE_SYSCALL is used to continue the >>> thread. >> >> I think that last idea makes sense.  I am not sure I undertsand the >> generation_counter idea. > > Regarding the generation counter, my understanding is that the native Linux > target never disables syscall tracing once it is enabled, or at least > that is > what the comment in linux-nat.c implies to me: > > int > linux_nat_target::set_syscall_catchpoint (int pid, bool needed, int > any_count, >                       gdb::array_view syscall_counts) > { >   /* On GNU/Linux, we ignore the arguments.  It means that we only >      enable the syscall catchpoints, but do not disable them. > >      Also, we do not use the `syscall_counts' information because we do > not >      filter system calls here.  We let GDB do the logic for us.  */ >   return 0; > } > I made a simple example, with gdb.in: ... catch syscall continue delete breakpoints continue ... In this case, I run into one PTRACE_SYSCALL (observed using strace). If I comment out "delete breakpoint", I run into two. So I think it's possible to disable syscall tracing. AFAIU the logic is in inf_ptrace_target::resume, were we choose between PT_SYSCALL and PT_CONTINUE. Thanks, - Tom