From owner-freebsd-hackers@freebsd.org Fri Feb 22 04:43:59 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EEF6014FF512 for ; Fri, 22 Feb 2019 04:43:58 +0000 (UTC) (envelope-from robert.ayrapetyan@gmail.com) Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B799181253 for ; Fri, 22 Feb 2019 04:43:57 +0000 (UTC) (envelope-from robert.ayrapetyan@gmail.com) Received: by mail-oi1-x235.google.com with SMTP id b4so777106oif.6 for ; Thu, 21 Feb 2019 20:43:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=h+Y4hA9K4s8ww/YuGV5PnADgvCRN1pXMgNOkp77E+zM=; b=hRq38qFsmoNXmluoabZo8eFrYyfaFT7G3twU0CfCF2wZ4pZuDdYnHTo4x4yFcCg3Y0 9+IEIC+eqK1yWhSLJOBpEap7W38RyM9ESB86E7JiwEdjs5yfibARZs+SXTKWEUV7Br9F EUZtjGaXPbEdQurkCpceXJs6VzpflRTktzzf8TsDcE2qkzQcZxEPcJtfuYOx80D9ag3f T0u2hmvZfqtzEdIsifipney1t7spsOIUM5KxFNynTmVo1rpZGrSJB1MvZJh5XyB9zFUr iNezlWjodcTc68QpkFAMckTcEG2m7T+995OQXWCxveF7CIsXifeOzGkDM7qpLXgcviox xRjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=h+Y4hA9K4s8ww/YuGV5PnADgvCRN1pXMgNOkp77E+zM=; b=gtJbbSK8cXP7PP4LxB2jabl7HLsBqOwU91YBO96wQ1e6NOXXEn/TKE/odZ//bg6z26 hfGb6VwvKgfwNgQ54I5qaQix61+6QsXRoVTQhZqWYLtl5+ttoBeDrwxc+oCH3dG6dVJh zFotOKor5bQ6EGVenHCgYhvGA9NBT2lqL7S+JwSjhduhvZbuAN+/igEWVeLyH3FXck4K qrhyTCM9hlOuxdtY9GubMhdeY2a7c0o9yBemr7gzFuyNNIRm7Kh3kt/OlTC9a+0Mhdnq C4B3Z01rxNdoKiN8XBAV1SjAERnhRrA8QzXBrxhveyFwV2eOPxbPi8clsIRrZCqKAqbT 5DQQ== X-Gm-Message-State: AHQUAuYmmhUD4WazBNZMLukQnipVv8QBdIxbGH5Bwc663RyPjjwhoFDH LRg0HdzLWtd0KeCjE17rZF9X8WJGJAUF3QbQyZ69eDU= X-Google-Smtp-Source: AHgI3Ib8ro9gzqH+2dAHSVA96VWJpDFJZ4jsIELg6xsykEpXAjAuk3KF+hrDbqOXs5EE1aJXqPpsqjewzAmTMfde7Ns= X-Received: by 2002:aca:5c05:: with SMTP id q5mr1305091oib.146.1550810636438; Thu, 21 Feb 2019 20:43:56 -0800 (PST) MIME-Version: 1.0 From: Robert Ayrapetyan Date: Thu, 21 Feb 2019 20:43:20 -0800 Message-ID: Subject: ptrace: SIGTRAP and EXIT race To: FreeBSD X-Rspamd-Queue-Id: B799181253 X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=hRq38qFs; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of robertayrapetyan@gmail.com designates 2607:f8b0:4864:20::235 as permitted sender) smtp.mailfrom=robertayrapetyan@gmail.com X-Spamd-Result: default: False [-6.72 / 15.00]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; MX_GOOD(-0.01)[cached: alt3.gmail-smtp-in.l.google.com]; NEURAL_HAM_SHORT(-0.91)[-0.913,0]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+,1:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; TAGGED_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; IP_SCORE(-2.80)[ip: (-9.32), ipnet: 2607:f8b0::/32(-2.62), asn: 15169(-1.99), country: US(-0.07)]; RCVD_IN_DNSWL_NONE(0.00)[5.3.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; RCVD_COUNT_TWO(0.00)[2] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Feb 2019 04:43:59 -0000 Hello. Before creating a bug and providing some test code, would ask a community here. When tracing a process using ptrace and there are multiple threads in the tracing process hitting the same breakpoint, sometimes main thread exits (WIFEXITED(status) is TRUE) before last queued TRAP_BKPT signal(s) have been delivered to the tracing process. So a final breakpoint hits counter is less than it should be. So in the example below: #include #include #include static const int num_threads = 2; void foo() { for (int i = 0; i < 2; ++i) { printf("hi: %d (tid: %d)\n", i, pthread_getthreadid_np()); } } int main() { std::thread t[num_threads]; for (int i = 0; i < num_threads; ++i) { t[i] = std::thread(foo); } for (int i = 0; i < num_threads; ++i) { t[i].join(); } return 0; } If we set breakpoint to printf, it should be triggered 4 times (tracing process should receive TRAP_BKPT 4 times). However, in ~1 of 5 runs, it receives TRAP_BKPT just 2 or 3 times. Is this expected? Thanks.