From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) by sourceware.org (Postfix) with ESMTPS id D38973858CDA for ; Thu, 29 Feb 2024 08:17:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D38973858CDA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=codeweavers.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D38973858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709194662; cv=none; b=WJZt4FNswmjK8l91ebvCkJV/q/1Pan0uv65i3C5foG3u97CsViVfqfVqHCqtjALHevSgW4LU96oXUFOahG3So3vp8PAcuHZJ3NzIpoKbKngDUtZNDlAMVR2ffq9JQMKQNDJDX7XIlzqqfUn8U9O0o9GqzChovU+zxzDRko5AZZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709194662; c=relaxed/simple; bh=J/MOtANfFuScktRBC3cqQ8pPUWsrkAXc7RWuYYwxXHo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=JUioZo1hPpvxq3T1BCVll8/cVXKEVBENVIVMBRtwkXtUEhlHjD/wYSTR99j4zATnK7mAxvv2Po443aER2D0QyRPECK1iEkSO+GARVBspajSC007u+bLiz+9G6uJaTleWhPFMtZpbfpPbJx2X6OjE9cPFZdbjjJFyiS4kAke5j7c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=From:To:Subject:Date:Message-ID:Cc:Sender; bh=DC7xsfzTu7wZ4CWuZjX8vbf1mtrGGkQv+OFVOv/iReU=; b=B7kNqF387QjaSSxHhtO/VLccdt 3A34x1iJYUsByfP9bOUHjPa45Kw6nUx9xDTnfdb8L4K1pZrr8jvHICIXfhZrSvCdPr13JzG88lYcS Owv79D3Gt8oWiiqADTXA0AJZJCgK6tndo70KyTKeofmi4CypK3Rtw/o3wjxX/SGVOh1qDOMPH++X/ fc47kloXcRmqk6hRqFLE6vJ++uIUnEk+0znjTGAZTha2T4603PUoM1Ax/uzMqYa06P3LW/418B/Pa xCeksTPT1BYKD/dNF52+U+U1/FhBSwNvqvlxds5JK9HnzaCMXMBBKMhhlB0KWWo0pa7yczqy2qyCp R2nLVPRw==; Received: from cw141ip122.vpn.codeweavers.com ([10.69.141.122]) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1rfbbb-00BKjS-23 for gdb-patches@sourceware.org; Thu, 29 Feb 2024 02:17:28 -0600 Message-ID: Date: Thu, 29 Feb 2024 09:17:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PING][PATCH] gdb/python: Allow SIGTRAMP_FRAME python unwinders to be created. Content-Language: en-US To: gdb-patches@sourceware.org References: <20240214215916.2655301-1-rbernon@codeweavers.com> From: =?UTF-8?Q?R=C3=A9mi_Bernon?= In-Reply-To: <20240214215916.2655301-1-rbernon@codeweavers.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,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: Ping, Thanks, On 2/14/24 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. > --- > 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; > } > } -- Rémi Bernon