From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id BNKNKFThhWW41ScAWB0awg (envelope-from ) for ; Fri, 22 Dec 2023 14:19:48 -0500 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=pGXV5p7I; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 996CB1E0D0; Fri, 22 Dec 2023 14:19:48 -0500 (EST) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 8678C1E0AC for ; Fri, 22 Dec 2023 14:19:46 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E0D733858427 for ; Fri, 22 Dec 2023 19:19:45 +0000 (GMT) Received: from omta036.useast.a.cloudfilter.net (omta036.useast.a.cloudfilter.net [44.202.169.35]) by sourceware.org (Postfix) with ESMTPS id D8EA83858D28 for ; Fri, 22 Dec 2023 19:19:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8EA83858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D8EA83858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703272770; cv=none; b=JgqXCmy46KhayySS/qS1a5St7cBjNcOVpUMThCC60tA5LRLSHkWolh0h6i6VWTS8llg+4C63137STcPjdbHrK8rnTFvLfBFuw3PsscJWTIMbyCOGqzyROeuVHv37GAhzAkDOn0VHZi6hA71ACGTx+KZFByRC02iNcwTUUW+lCDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703272770; c=relaxed/simple; bh=rVJiF3ajgFotBdNu+/bP3gl4EHe6ewweLymQWM5Jv+A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vJXFAoRsgTmd00G4mO3WNtFchyeQrLMAISI3TDGz9v8d/aoHMiJcVLSGFcclV5+Bwtz0cb9JJQ0BO2elDQBIKAB+gu+0tvJXLyG3nWChD5YnQCgcRXj/8DQztVPkbBzkgNUzGRQGkW2Yqnq/RJoSkAVnJsgSECAkNt/ZGVYMw3M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6005a.ext.cloudfilter.net ([10.0.30.201]) by cmsmtp with ESMTPS id Gf8GrpsZ8gpyEGl3QrtytT; Fri, 22 Dec 2023 19:19:28 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id Gl3Pr4hvu8KNvGl3QrGgss; Fri, 22 Dec 2023 19:19:28 +0000 X-Authority-Analysis: v=2.4 cv=dp3Itns4 c=1 sm=1 tr=0 ts=6585e140 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=e2cXIFwxEfEA:10 a=Qbun_eYptAEA:10 a=cCyiE7Yyhlx3RdpVpu0A:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References :Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=qJDfVI9+27/rQ6VvnsZ5+Tw53FDxlL5z2L1TABwWbnI=; b=pGXV5p7IsaY9V/G6rmVDkY6N1h Cq4HJw1VJYk4t3RLsNe2go8CImQvcUGrfUQ1HnHk7cxkZLo0AcLtI5ioVmtlVqKNK5NY+ytcPWq2L QLcR9t8uoGFKBzbfiW87tLnXX; Received: from 71-211-161-25.hlrn.qwest.net ([71.211.161.25]:35278 helo=prentzel) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rGl3P-000hTb-28; Fri, 22 Dec 2023 12:19:27 -0700 From: Tom Tromey To: Tom Tromey Cc: Andrey Turkin , Andrey Turkin via Gdb Subject: Re: "previous frame inner to this frame" error when unwinding fibers References: <874jgp7ksd.fsf@tromey.com> <87plzceio4.fsf@tromey.com> <87msu3dqp4.fsf@tromey.com> X-Attribution: Tom Date: Fri, 22 Dec 2023 12:19:26 -0700 In-Reply-To: <87msu3dqp4.fsf@tromey.com> (Tom Tromey's message of "Thu, 21 Dec 2023 17:30:15 -0700") Message-ID: <87edfedozl.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.161.25 X-Source-L: No X-Exim-ID: 1rGl3P-000hTb-28 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-161-25.hlrn.qwest.net (prentzel) [71.211.161.25]:35278 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfP5ArEsSxTI4DM9aOJ+H4NCM2I9advbBK5ThgkxO1LoxjlUwlRKxPkGF95SLzoPS4UjrDT4L18jGmpmGSveE7TvIl+7K5Gr1EUzXvbxSIEX1ieIibY57 wr4DPHXHudN5hgtEYnLNXtlGSlP0FPTzzeu42+6GajBcLp2FQ9Gr+PCEG3TeYEf9G1RSqnzGgU9Rrg== X-Spam-Status: No, score=-3016.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb" Tom> Yeah, the API on the branch is very simple. I made a new branch and reworked it a bit, dropping a few stale parts. It's in my github as "green-threads-v2"; you can try it if you want. I've appended a sample .py that works with the "vireo" user-space threads package so you can see how it works. I still haven't implemented a way for green threads to know when to stop unwinding. And, I haven't added a way to indicate that the "inner than" requirement should be lifted. If you have ideas for how those ought to work, that would be good to hear. We talked about doing this in an unwinder but it seems kind of heavy to require an unwinder to supplement green threads; though maybe in your case that's ok. One thought I had was to have a callback on the green thread object that could be passed a frame to see if it is the outermost frame. This way green threads, at least, could stop unwinding at their scheduler; and users wanting to debug a scheduler could switch to a "real" thread to see that. Maybe inner-than could just be an optional flag passed to create_green_thread. Tom import gdb thread_map = {} main_thread = None # From glibc/sysdeps/unix/sysv/linux/x86/sys/ucontext.h x8664_regs = [ 'r8', 'r9', 'r10', 'r11', 'r12', 'r13', 'r14', 'r15', 'rdi', 'rsi', 'rbp', 'rbx', 'rdx', 'rax', 'rcx', 'rsp', 'rip', 'efl', 'csgsfs', 'err', 'trapno', 'oldmask', 'cr2' ] def vireo_current(): return int(gdb.parse_and_eval('curenv')) + 1 class VireoGreenThread: def __init__(self, tid): self.tid = tid def _get_state(self): return gdb.parse_and_eval('envs')[self.tid]['state'] def fetch(self, reg): """Fetch REG from memory.""" global x8664_regs global thread_map thread = thread[self.tid] state = self._get_state() gregs = state['uc_mcontext']['gregs'] for i in range(0, len(x8664_regs)): if reg is None or reg == x8664_regs[i]: thread.write_register(x8664_regs[i], gregs[i]) def store(self, reg): global x8664_regs global thread_map thread = thread[self.tid] state = self._get_state() gregs = state['uc_mcontext']['gregs'] for i in range(0, len(x8664_regs)): if reg is None or reg == x8664_regs[i]: gregs[i] = thread.read_register(x8664_regs[i]) def name(self): return "Vireo Thread " + str(self.tid) def underlying_thread(self): if vireo_current() == self.tid: global main_thread return main_thread return None class VFinish(gdb.FinishBreakpoint): def stop(self): tid = int(self.return_value) + 1 global thread_map thread_map[tid] = gdb.create_green_thread(tid, VireoGreenThread(tid)) return False class VCreate(gdb.Breakpoint): def stop(self): VFinish(gdb.newest_frame(), True) return False class VExit(gdb.Breakpoint): def stop(self): global main_thread if main_thread is None: main_thread = gdb.selected_thread() global thread_map tid = vireo_current() if tid in thread_map: thread_map[tid].set_exited() del thread_map[tid] VCreate('vireo_create', internal=True) VExit('vireo_exit', internal=True)