From patchwork Fri Mar 10 14:55:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 66215 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01369385700E for ; Fri, 10 Mar 2023 14:56:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01369385700E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678460181; bh=c4STAhTEjZd8AfVjPljBP5zIqFnHloOcQxhK8IlfXb4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=IRCTiax2Tzj6xtOFWxbIX7KNYEg7pHpl2EGqH5cK6X03IciU9pG9AC7S7waKPSQJ8 iKSuKWwZ22Ce+xzZ4e98uFly7h3noapeba3w9H+StIU2UeWXb4BCvZKEwjH13qL4ZA 51JasfWkNDmBFbEukYV0m7Z0ZrpQLtGM543elG4c= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 8851D3858D38 for ; Fri, 10 Mar 2023 14:55:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8851D3858D38 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-253-6q_3S5_dO86xHIaEDcfLVg-1; Fri, 10 Mar 2023 09:55:53 -0500 X-MC-Unique: 6q_3S5_dO86xHIaEDcfLVg-1 Received: by mail-wm1-f72.google.com with SMTP id k26-20020a05600c0b5a00b003dfe4bae099so2085899wmr.0 for ; Fri, 10 Mar 2023 06:55:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678460152; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c4STAhTEjZd8AfVjPljBP5zIqFnHloOcQxhK8IlfXb4=; b=lFKYY+NHqUtFlbznbY1BQTzAljGGMQOuHYFtQl1Y++6pv614pEhheia6TboV2NDYHl DSNfYp3wjS9MIVq7r0jj+OCmoTDzyK+OA97MnTjK1XBgL5A9WFXP7UeZXirwIFD6HW4O kCc9UD8odAKrY3n63uhuH9Kf2OTfY03i5W1X+FdhqNyAdkt/k8a7x/hM7S7Pg91g3h6x 2tvDkY3PZ/Fs0FJNsuzexu7LGg/7/Z4+CaQfv3c7R6Y5/7p1J7lkz+pZ/IsfY9tT3Vfb owI+XN4v/17YCtraV5OpShJBy8tKK3he1DKrL6DLaai3QQXTIHCDM+zh0daK/aCOouzR 1Leg== X-Gm-Message-State: AO0yUKXziLlLxTqgjrLYVnDWj7OHSAID2/xl1dqwPsD7XZd2Ww3IYUFO HK0nkEw3KMVWYxX8JafB4wabQnbg/DsMoncjbSxOaKF+iUbTMmI/nDFXJXPzj75pq67qcKX4rQy /3V42pKEqErPSCHtxNBwKi0v16yPsZjf8qwxiBEhAuAe+brTU45Vtr91azhuXB+8NtDLiCMacdp 3PLVq+Dw== X-Received: by 2002:a05:600c:4f08:b0:3e2:20c7:6544 with SMTP id l8-20020a05600c4f0800b003e220c76544mr3010307wmq.19.1678460152583; Fri, 10 Mar 2023 06:55:52 -0800 (PST) X-Google-Smtp-Source: AK7set/58XTaL0D7NJ0fHfY4ZjLsnDkmaIv9Zq31YuODXSMV0ssgSv7UpG3X+XGyLvpa1Ct8TxAnxw== X-Received: by 2002:a05:600c:4f08:b0:3e2:20c7:6544 with SMTP id l8-20020a05600c4f0800b003e220c76544mr3010288wmq.19.1678460152233; Fri, 10 Mar 2023 06:55:52 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id p10-20020a1c544a000000b003eb2e685c7dsm154854wmi.9.2023.03.10.06.55.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 06:55:51 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 01/10] gdb/doc: spring clean the Python unwinders documentation Date: Fri, 10 Mar 2023 14:55:18 +0000 Message-Id: <3bad3bab1077f38d3f508e0cb4a071663e745b06.1678460067.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham 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-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The documentation for the Python Unwinders API could do with some improvement. The 'Unwinder Skeleton Code' has an error: it says 'unwinders' when it should say 'unwinder' in one case. Additionally, by placing the 'Unwinder Skeleton Code' before the section 'Registering an Unwinder' we have skipping including the registration line in the skeleton code. But this is confusion for users (I think) as the skeleton code is almost complete, except for one missing line which the user has to figure out for themselves. By reordering the sections, it is now obvious that the registration should be included in the skeleton code, and the example is therefore almost complete. Additionally, in the example skeleton code the way in which the frame-id was being built (using the current stack point and program counter is (a) not correct, and (b) counter to what is laid out in the 'Unwinder Input' section when describing building a frame-id. I've removed the incorrect code and replaced it with more generic comments indicating what needs to be done. As the actual actions that need to be performed are both architecture specific, and dependent on the function being unwound, it's almost impossible to include more exact code here, but I think what I'm proposing is less misleading than what we had before. I've also added more cross references. Reviewed-By: Eli Zaretskii --- gdb/doc/python.texi | 82 ++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index b04f1de2ddf..9ab0aca7d57 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -2784,9 +2784,10 @@ @defun PendingFrame.create_unwind_info (frame_id) Returns a new @code{gdb.UnwindInfo} instance identified by given -@var{frame_id}. The argument is used to build @value{GDBN}'s frame ID -using one of functions provided by @value{GDBN}. @var{frame_id}'s attributes -determine which function will be used, as follows: +@var{frame_id}. The @var{frame_id} is used internally by @value{GDBN} +to identify the frames within the current thread's stack. The +attributes of @var{frame_id} determine what type of frame ID is +created within @value{GDBN}: @table @code @item sp, pc @@ -2841,6 +2842,34 @@ @var{value} is a register value (a @code{gdb.Value} object). @end defun +@subheading Registering an Unwinder + +Object files and program spaces can have unwinders registered with +them. In addition, you can also register unwinders globally. + +The @code{gdb.unwinders} module provides the function to register an +unwinder: + +@defun gdb.unwinder.register_unwinder (locus, unwinder, replace=False) +@var{locus} specifies to which unwinder list to prepend the +@var{unwinder}. It can be either an object file (@pxref{Objfiles In +Python}), a program space (@pxref{Progspaces In Python}), or +@code{None}, in which case the unwinder is registered globally. The +newly added @var{unwinder} will be called before any other unwinder +from the same locus. Two unwinders in the same locus cannot have the +same name. An attempt to add an unwinder with an already existing +name raises an exception unless @var{replace} is @code{True}, in which +case the old unwinder is deleted and the new unwinder is registered in +its place. +@end defun + +@subheading Unwinder Precedence + +@value{GDBN} first calls the unwinders from all the object files in no +particular order, then the unwinders from the current program space, +then the globally registered unwinders, and finally the unwinders +builtin to @value{GDBN}. + @subheading Unwinder Skeleton Code @value{GDBN} comes with the module containing the base @code{Unwinder} @@ -2848,7 +2877,7 @@ follows: @smallexample -from gdb.unwinders import Unwinder +from gdb.unwinder import Unwinder class FrameId(object): def __init__(self, sp, pc): @@ -2857,53 +2886,30 @@ class MyUnwinder(Unwinder): - def __init__(....): - super(MyUnwinder, self).__init___() + def __init__(self): + super().__init___("MyUnwinder_Name") - def __call__(pending_frame): + def __call__(self, pending_frame): if not : return None - # Create UnwindInfo. Usually the frame is identified by the stack - # pointer and the program counter. - sp = pending_frame.read_register() - pc = pending_frame.read_register() + + # Create a FrameID. Usually the frame is identified by a + # stack pointer and the function address. + sp = ... compute a stack address ... + pc = ... compute function address ... unwind_info = pending_frame.create_unwind_info(FrameId(sp, pc)) - # Find the values of the registers in the caller's frame and + # Find the values of the registers in the caller's frame and # save them in the result: - unwind_info.add_saved_register(, ) + unwind_info.add_saved_register(, ) .... # Return the result: return unwind_info +gdb.unwinder.register_unwinder(, MyUnwinder(), ) @end smallexample -@subheading Registering an Unwinder - -Object files and program spaces can have unwinders registered with -them. In addition, you can also register unwinders globally. - -The @code{gdb.unwinders} module provides the function to register an -unwinder: - -@defun gdb.unwinder.register_unwinder (locus, unwinder, replace=False) -@var{locus} specifies to which unwinder list to prepend the -@var{unwinder}. It can be either an object file, a program space, or -@code{None}, in which case the unwinder is registered globally. The -newly added @var{unwinder} will be called before any other unwinder from the -same locus. Two unwinders in the same locus cannot have the same -name. An attempt to add an unwinder with an already existing name raises -an exception unless @var{replace} is @code{True}, in which case the -old unwinder is deleted. -@end defun - -@subheading Unwinder Precedence - -@value{GDBN} first calls the unwinders from all the object files in no -particular order, then the unwinders from the current program space, -and finally the unwinders from @value{GDBN}. - @node Xmethods In Python @subsubsection Xmethods In Python @cindex xmethods in Python