From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 3178A3858D33 for ; Mon, 11 Dec 2023 07:45:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3178A3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3178A3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::529 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702280709; cv=none; b=S7Vmc2aMNTo38W4yvNwSrx4c/ZE+VCYp0oOaygHhb1GDQcs0K12rIVIzVUTcCYgaHYbDRcI0uxkfyYixyZJasHPanYKI1R5haAumhbCMhiCsyJlbqMa4E6QOQmAmbAcD9lPOzA+4Y6kzg4s3MCF4QiWZMFnb/Jm1G+6LlQX2BT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702280709; c=relaxed/simple; bh=+XcbQmqxo5xTt2cM/1ffRn8CB2xoLISV/D6SXdqOHEw=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=hJFPtChlZmsVl8jCDdWL0pMKO3xFbf4XhGtCMqsvPnYczAcuAauDCDr1Gdn5zX9Yn69kh+XhA7ot3WF22UxNFnXsj2NkC4as34daSiKso1feCAYExxNL+inIQYGvNfYbRgfYpRYLBDpZ7V6dREP0/WhLbW6otE/J1PD4QVNYpvg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-54dcfca54e0so5120942a12.1 for ; Sun, 10 Dec 2023 23:45:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702280706; x=1702885506; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4GbS0gdRAVBSbji5+zL0U8IA5YXfSoFkiZdophZaI5M=; b=m4cmi2gsWmASK6Oe/t+ZL0kowWcNVF7b/fgjFCt1DEXcKkGqW68eoEC7wmPDV0XK8P /W0YSRJu5Phh3tzZ71Gw89KgzscG109HSWE0tycUEbYD4CdhCvR/TxrmA5VjPH45Hf9g bR6+qIqGj2M0PN574ldJ0Jsr9F82E5lSYKDKPcIux3nUAiZr7GtDxFTv9tuxah11u2nq LTknxJ/L0Z4MV8ZJX9QOGOO/dkytBeYK0sE4hwRhsYMz/hGKDo+sBFh6pDTuobFYGHTq tAQuGSH4ha3KH9dBHertXqKX83uR+XSJPnklb+ggbtQjUTUOynXsik3lq2R4obfa5Gqu RPtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702280706; x=1702885506; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4GbS0gdRAVBSbji5+zL0U8IA5YXfSoFkiZdophZaI5M=; b=OxnCsKLeBOj/TIHowShIYtSSb5GzUCguNdksCVEuweRENcBTkdrOunEcamc/9r4zfW +KwS2Ji1pgveR+3yqTIV9dMjEax9vU3gXCplkNbXOzDCY2AI58pWrALKc+hPuWSkc3Mm oNdyb+dmzLsgKiln5FvIL9AQVPDY7wjZUW/m2lYHHYUMR5TfOjms162VkgXqVp7Ce2K+ 2fMhmCnDcwF2rCt3EwFyh9mSCfoS5bKqeRx6ZLAxuZ3GUd+95t4+KXTixFjJeaDiXXgW lke9YuzbjuYeY/n9rlQ794gJsi+TI/uhU3RGKVNVupTaLUTLcgCrhxN+UJG22KV4IZzt 2nIw== X-Gm-Message-State: AOJu0YwwQiEATCXA01UbejeoFJnpsuZ0pioQjtrKVKdUIJpLYNEMPrcA RJITiqVGKA0PhdVsxW0ylIXBehdMM5t/h2E9WSl7wmANGKM= X-Google-Smtp-Source: AGHT+IG75t/t/Ag3rpaiGT6gwVAqcRSRj889LRGBzb9aQK3BpcnOktcH0CnoYAaX8k1QXI10fbgzQBehZjpBsu3emR0= X-Received: by 2002:a17:907:7f87:b0:a17:8181:4f3 with SMTP id qk7-20020a1709077f8700b00a17818104f3mr2160864ejc.49.1702280705597; Sun, 10 Dec 2023 23:45:05 -0800 (PST) MIME-Version: 1.0 References: <874jgp7ksd.fsf@tromey.com> In-Reply-To: <874jgp7ksd.fsf@tromey.com> From: Andrey Turkin Date: Mon, 11 Dec 2023 10:44:54 +0300 Message-ID: Subject: Re: "previous frame inner to this frame" error when unwinding fibers To: Tom Tromey Cc: gdb@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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: =D0=BF=D0=BD, 11 =D0=B4=D0=B5=D0=BA. 2023=E2=80=AF=D0=B3. =D0=B2 01:30, Tom= Tromey : > > >>>>> "Andrey" =3D=3D Andrey Turkin via Gdb writes: > > Andrey> I'm trying to write a custom unwinder in Python to unwind through > Andrey> boost coroutine (so, follow coroutine stack with its caller's sta= ck). > Andrey> It generally works pretty well except for occasional errors about= the > Andrey> inner frame. Obviously, coroutine switches stack so comparing fra= me > Andrey> pointers makes no sense; so, when caller stack happens to be allo= cated > Andrey> above coroutine's, the bogus error occurs. > Andrey> I can see in gdb sources that it knows about gcc's split-stacks a= nd > Andrey> apparently arch-specific frames, however I found no way for the > Andrey> unwinder to do anything about it. Is there any way to fix this er= ror > Andrey> with the current gdb, or do I need to patch the sources? > > You'll need to patch gdb. The current code for handling this sort of > thing is totally ad hoc and can't be tweaked by the user or from Python. > > Letting Python unwinders affect this seems like a nice feature. Like > maybe a method on gdb.UnwindInfo that sets a flag, then pipe this > through to the check in get_prev_frame_always_1. > > Maybe some other way is better, I don't know. I'm definitely open to > ideas and I think this is worth solving -- I feel it's been asked for > before. > > Tom One possible solution that comes to my mind is to allow unwinders to specify the type of the frame (ideally that would be the frame being unwinded, i.e. one from PendingFrame; UnwindInfo I think is all about the next frame though). This would be enough to solve this issue since the inner-frame checking code only works with normal caller-callee pairs. Not sure which type it would be; sigtrap is the one most closely resembling it I think but not quite it. PS: One other thing that is needed for the fiber/coroutine use case is an ability to perform backtraces from a random starting point. Backtrace through the switch point is what's needed for active asymmetric coroutines like generators and such; however it would be nice to be able to see the current stack of suspended asymmetric coroutines, or to see the state of symmetric coroutines. This is something that can be done currently through the abuse of the backtrace/unwind system, and it sort of works fine, ca. inner frame thing (see e.g. folly's fiber gdb helper for an example of this). Gdb can show basic frame information for any frame given sp/ip but I don't think it is possible to do the unwinding. Would be great if that was possible to do in some semi-clean manner (to start at any given sp/ip, or maybe to start from the dummy frame with some registers filled in).