From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 75D023858412 for ; Thu, 14 Mar 2024 13:00:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 75D023858412 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 75D023858412 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710421245; cv=none; b=gVzKDK8HzTGZE3rb4ICYpUoO22kbnP33RmS00dkL+f9RYQAVLUeDZ0OXIHdnwUR5N86tshp9a76LrrdY6LD2FunOwt5mqhS4S0mRMuz62lXkthnnFs35DcAJC+aUKtK8NK/+zLpX4SnCnYhDjYVnc92+ymvLoEkM4s8W62sGJkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710421245; c=relaxed/simple; bh=qGOJEWluLgsBou2PLRPwDEpQC463ehcW5x0pMnK4E/0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=e9ku/k1D+UtjV4H2eP1SjAu2MrDxOlE1pLSbEEoc0IdlERhXt+brXZthd1U4rUIu+iPLbWabhoNInmBRNzwyDcDkS/otCw6Dvyrr2plcFPhTfgf+CL43i1sP/Z8Kt4iQwmeEcwVRFT31D1tTTda21GBLOQhwI52TMr7bDku8EYE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710421243; h=from:from:reply-to:subject:subject: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=WjeE8hbN/1wVzoR3vn9HXjk4G3SY0liu5pQu3zXtXyQ=; b=Jb6oXM3W+LexBjvnwNx9SuDoAF8ramOa55B9BtGDuViHcAxm3/laeivf35WPUbo9jSDOgM KU5YwSpjAyqHvTnnbA/oi1quCexg9Shtf5OTEaKZQKeviHCo7FN4EeRqg+mkmw7PkGPv+k XItuma55onu6UsHIwEKuJZXpnbaBoXE= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-LgULXtcXMtCp7jYlNzSUYw-1; Thu, 14 Mar 2024 09:00:41 -0400 X-MC-Unique: LgULXtcXMtCp7jYlNzSUYw-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-787c04e48a7so82947085a.1 for ; Thu, 14 Mar 2024 06:00:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710421240; x=1711026040; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WjeE8hbN/1wVzoR3vn9HXjk4G3SY0liu5pQu3zXtXyQ=; b=v492lAUuunWQE61btcCmj6JC+kHTS6SIXaFC9sGr49KTsaZpUS6DXDQuB6p/BiW7UF GGWHWPfV2WDn35lCn0MOuiffHdv3Rcp9NEP0uXbzNKpcUWGkLy8516TUtENuE95cz2W+ 0AFhHhUreV0dAa8TSePUmUx25Pl9QlnkGM16pT9DOfmNjBND6XSQpAPNn3efV4d2gW3P wmXQf1c6417essgmupKr4QHGdjhimET9R9XI4m3a9+yjwVs0bI2Mtw0CJwBKqShlyHwL p8bCEdvd0nyXIUPetrhoP8ipnQgRRFYRNPF/dENuogr6Mcg//NY/0ERBWNUeChS1vOKr TzIw== X-Forwarded-Encrypted: i=1; AJvYcCUXGN6qxRLwh3+Nh//e6V1uJyOY6LkroxTeOrtm8UbKCOlGoH1tMlDb52g2wbqAnPI10RgHf3di0Ys/IY/qZGQh/YBMRf3FUt4v0Q== X-Gm-Message-State: AOJu0Yw1Og2qiML9hyT2ie1nGiRiKkWrIqWKmUyqOq2+HGHEIbxjcLC0 t7FTcRsICXaenmqJK0kIpFhFmeJpztpDal8wuT/6e6WHriqXsjBksMmKbUfWXisI4NgTQWpHT5M /+xGyUL5MS/S2XXXQEuoVR6UhEUujkYDE9qIjiJWnIvcRcrXbvuRR6OTyPJT46iEDAI8= X-Received: by 2002:a05:6214:1650:b0:690:d295:a2f9 with SMTP id f16-20020a056214165000b00690d295a2f9mr1675340qvw.2.1710421240393; Thu, 14 Mar 2024 06:00:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHjF5GnxKysibcPJmOl3SQ+AamK5jyE2pkLrBo4nBzWRNInJiD2hkqoV3tClcMWmsZmwqf5g== X-Received: by 2002:a05:6214:1650:b0:690:d295:a2f9 with SMTP id f16-20020a056214165000b00690d295a2f9mr1675321qvw.2.1710421239992; Thu, 14 Mar 2024 06:00:39 -0700 (PDT) Received: from [10.202.149.221] (nat-pool-brq-u.redhat.com. [213.175.37.12]) by smtp.gmail.com with ESMTPSA id kk23-20020a056214509700b00691281bf661sm419181qvb.5.2024.03.14.06.00.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Mar 2024 06:00:39 -0700 (PDT) Message-ID: <3d80a22b-3ccf-4da7-9c40-59a3c74ccaa8@redhat.com> Date: Thu, 14 Mar 2024 14:00:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb/python: Allow SIGTRAMP_FRAME python unwinders to be created. To: =?UTF-8?Q?R=C3=A9mi_Bernon?= , gdb-patches@sourceware.org References: <20240214215916.2655301-1-rbernon@codeweavers.com> From: Guinevere Larsen In-Reply-To: <20240214215916.2655301-1-rbernon@codeweavers.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 14/02/2024 22:58, RĂ©mi Bernon wrote: > Wine now executes Win32 code on a separate stack for its Unix code. It > switches from one stack to another on through specific functions, and > without any custom unwinders, debugging Wine in Gdb will only let you > see the frames of either the Win32 side, or the Unix side. > > The Win32 and Unix call stacks are actually interleaved, with Unix code > sometimes calling back into Win32. Using a custom Python frame unwinder > we can provide Gdb with the information it needs to join both toghether > and show a complete interleaved call stack. However, Gdb will often stop > unwinding as it will see the frames from one stack as inner the frames > from the other stack. > > This allows to write custom unwinders to produce SIGTRAMP_FRAME typed > frames, which bypasses this restriction and will show the Win32 / Unix > gate as a signal frame. Hi! Sorry for taking a long time for to review. This looks like a good improvement. It would be nice if you could provide a test, but I'm not sure if you are able to manufacture a trampoline frame for a test. If it isn't possible to make a test patch LGTM: Reviewed-By: Guinevere Larsen I hope a responsible maintainer is able to approve this soon (or explain how to make a faux trampoline frame to test). -- Cheers, Guinevere Larsen She/Her/Hers > --- > gdb/python/lib/gdb/__init__.py | 8 ++++---- > gdb/python/lib/gdb/unwinder.py | 7 ++++++- > gdb/python/py-unwind.c | 16 +++++++++++++++- > 3 files changed, 25 insertions(+), 6 deletions(-) > > diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py > index b3124369fe8..d9226440cbc 100644 > --- a/gdb/python/lib/gdb/__init__.py > +++ b/gdb/python/lib/gdb/__init__.py > @@ -86,7 +86,7 @@ frame_filters = {} > frame_unwinders = [] > > > -def _execute_unwinders(pending_frame): > +def _execute_unwinders(pending_frame, frame_type): > """Internal function called from GDB to execute all unwinders. > > Runs each currently enabled unwinder until it finds the one that > @@ -105,19 +105,19 @@ def _execute_unwinders(pending_frame): > """ > for objfile in objfiles(): > for unwinder in objfile.frame_unwinders: > - if unwinder.enabled: > + if unwinder.enabled and unwinder.frame_type == frame_type: > unwind_info = unwinder(pending_frame) > if unwind_info is not None: > return (unwind_info, unwinder.name) > > for unwinder in current_progspace().frame_unwinders: > - if unwinder.enabled: > + if unwinder.enabled and unwinder.frame_type == frame_type: > unwind_info = unwinder(pending_frame) > if unwind_info is not None: > return (unwind_info, unwinder.name) > > for unwinder in frame_unwinders: > - if unwinder.enabled: > + if unwinder.enabled and unwinder.frame_type == frame_type: > unwind_info = unwinder(pending_frame) > if unwind_info is not None: > return (unwind_info, unwinder.name) > diff --git a/gdb/python/lib/gdb/unwinder.py b/gdb/python/lib/gdb/unwinder.py > index 140b84d3374..7e23a662a32 100644 > --- a/gdb/python/lib/gdb/unwinder.py > +++ b/gdb/python/lib/gdb/unwinder.py > @@ -29,7 +29,7 @@ class Unwinder(object): > enabled: A boolean indicating whether the unwinder is enabled. > """ > > - def __init__(self, name): > + def __init__(self, name, frame_type=gdb.NORMAL_FRAME): > """Constructor. > > Args: > @@ -39,9 +39,14 @@ class Unwinder(object): > if not isinstance(name, str): > raise TypeError("incorrect type for name: %s" % type(name)) > > + self._frame_type = frame_type > self._name = name > self._enabled = True > > + @property > + def frame_type(self): > + return self._frame_type > + > @property > def name(self): > return self._name > diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c > index 1856e41e2a1..2d36c43d342 100644 > --- a/gdb/python/py-unwind.c > +++ b/gdb/python/py-unwind.c > @@ -844,7 +844,8 @@ pyuw_sniffer (const struct frame_unwind *self, frame_info_ptr this_frame, > /* A (gdb.UnwindInfo, str) tuple, or None. */ > gdbpy_ref<> pyo_execute_ret > (PyObject_CallFunctionObjArgs (pyo_execute.get (), > - pyo_pending_frame.get (), NULL)); > + pyo_pending_frame.get (), > + PyLong_FromLong(self->type), NULL)); > if (pyo_execute_ret == nullptr) > { > /* If the unwinder is cancelled due to a Ctrl-C, then propagate > @@ -965,6 +966,19 @@ pyuw_on_new_gdbarch (struct gdbarch *newarch) > unwinder->sniffer = pyuw_sniffer; > unwinder->dealloc_cache = pyuw_dealloc_cache; > frame_unwind_prepend_unwinder (newarch, unwinder); > + > + struct frame_unwind *unwinder_signals > + = GDBARCH_OBSTACK_ZALLOC (newarch, struct frame_unwind); > + > + unwinder_signals->name = "python-sigtramp"; > + unwinder_signals->type = SIGTRAMP_FRAME; > + unwinder_signals->stop_reason = default_frame_unwind_stop_reason; > + unwinder_signals->this_id = pyuw_this_id; > + unwinder_signals->prev_register = pyuw_prev_register; > + unwinder_signals->unwind_data = (const struct frame_data *) newarch; > + unwinder_signals->sniffer = pyuw_sniffer; > + unwinder_signals->dealloc_cache = pyuw_dealloc_cache; > + frame_unwind_prepend_unwinder (newarch, unwinder_signals); > data->unwinder_registered = 1; > } > }