From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by sourceware.org (Postfix) with ESMTPS id 706223858D35 for ; Thu, 22 Jun 2023 16:19:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 706223858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-780bd47ef93so66508839f.2 for ; Thu, 22 Jun 2023 09:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1687450769; x=1690042769; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9NIQkAkqnE4Xuai72YHaokjaL3CvmWJpq6YCDM6XcCw=; b=ItcbO0noNeGc++MUGB15HpTMYfWwrcqH791pXT2SZncbZonct2Ud3ZwyFTwh7wQGwJ jMMQBqH542kr3F4YFvTYqVGvQnu9BQcbDhPOdONHLxvWmxFkgHQ0OknvvYmMJ8IHZfht hxLyFHKF0tAtmY3e9Z9c38LdLTQBqfzsM5PusC8DOtw5H+knzuRq6qUH9CGn6+2ofHFm VU7/l/txziusGwVhFt0KtpyqDuJv4T0pW46gBTxalKt/JC+1aoeVA1KhfA6y/qIhGjm9 RQXeWsiJBgNvcThLlIGvxw+TwPUjM7C241YycmoopOg1jJge8tz7Nr2o8bAybOMe8HEt I73A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687450769; x=1690042769; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9NIQkAkqnE4Xuai72YHaokjaL3CvmWJpq6YCDM6XcCw=; b=JJq3vkDwpeDs2ikGZbYbIiw8xRKJrGZw6G3LL2Xg7E1jiRVgxLeYSgIhoZoAeni1Na 7Hod2oqcsBIIJ4OcBgm2XW9ze9n/GZOnFUxdOUkLBvkqC6RpPPKD85RDKiQ5xNpu08L0 fMQck72Qd0qaJGQvy6jsXlXiPFRBZxGM6kOX91jQaWo1dqapkWNcoGu/bvECeig/LkDa +4u5/m1zpFB2OTAIcG82C8i49dwipywHKshX0WzLkrp76pHVgexKb9PijOD2PPsMg+uD tA0dIds/bMVQdljve6FPtAO4Hdng9QJxtlJMYQtP8Z/8NTLwXgMB8SLimaeYEMUAmSc+ bn2g== X-Gm-Message-State: AC+VfDxiXCLCMvljf+O7fcaQ27rKvTFaz4Iqh6TGZBmuyQQVdzQRt9ex rFDDX2zhUfXo8AHzwNFiuUXDBanVU4yr/TP572Bx/A== X-Google-Smtp-Source: ACHHUZ4iUnfnG9eC/nymY7FWyPCNn4qhZt7RbQoepHhupUXwI3IgY3lIJwzCOUVbDs3BfKv6SwXuNg== X-Received: by 2002:a5e:db05:0:b0:770:28ee:fee1 with SMTP id q5-20020a5edb05000000b0077028eefee1mr15121584iop.7.1687450769587; Thu, 22 Jun 2023 09:19:29 -0700 (PDT) Received: from localhost.localdomain (75-166-136-83.hlrn.qwest.net. [75.166.136.83]) by smtp.gmail.com with ESMTPSA id y8-20020a6bd808000000b0077ac2261248sm2201987iob.5.2023.06.22.09.19.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 09:19:29 -0700 (PDT) From: Tom Tromey Date: Thu, 22 Jun 2023 10:19:28 -0600 Subject: [PATCH v2 2/7] Add new interface to frame filter iteration MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230614-dap-frame-decor-v2-2-10628dfa6b60@adacore.com> References: <20230614-dap-frame-decor-v2-0-10628dfa6b60@adacore.com> In-Reply-To: <20230614-dap-frame-decor-v2-0-10628dfa6b60@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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: This patch adds a new function, frame_iterator, that wraps the existing code to find and execute the frame filters. However, unlike execute_frame_filters, it will always return an iterator -- whereas execute_frame_filters will return None if no frame filters apply. Nothing uses this new function yet, but it will used by a subsequent DAP patch. --- gdb/python/lib/gdb/frames.py | 85 ++++++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 26 deletions(-) diff --git a/gdb/python/lib/gdb/frames.py b/gdb/python/lib/gdb/frames.py index 52f4191a8e8..01e7cff6c70 100644 --- a/gdb/python/lib/gdb/frames.py +++ b/gdb/python/lib/gdb/frames.py @@ -156,37 +156,16 @@ def _sort_list(): return sorted_frame_filters -def execute_frame_filters(frame, frame_low, frame_high): - """Internal function called from GDB that will execute the chain - of frame filters. Each filter is executed in priority order. - After the execution completes, slice the iterator to frame_low - - frame_high range. - - Arguments: - frame: The initial frame. - - frame_low: The low range of the slice, counting from 0. If - this is a negative integer then it indicates a backward slice - (ie bt -4) which counts backward from the last frame in the - backtrace. - - frame_high: The high range of the slice, inclusive. If this - is -1 then it indicates all frames until the end of the stack - from frame_low. - - Returns: - frame_iterator: The sliced iterator after all frame - filters have had a chance to execute, or None if no frame - filters are registered. - - """ - +# Internal function that implements frame_iterator and +# execute_frame_filters. If ALWAYS is True, then this will always +# return an iterator. +def _frame_iterator(frame, frame_low, frame_high, always): # Get a sorted list of frame filters. sorted_list = list(_sort_list()) # Check to see if there are any frame-filters. If not, just # return None and let default backtrace printing occur. - if len(sorted_list) == 0: + if not always and len(sorted_list) == 0: return None frame_iterator = FrameIterator(frame) @@ -233,3 +212,57 @@ def execute_frame_filters(frame, frame_low, frame_high): sliced = itertools.islice(frame_iterator, frame_low, frame_high) return sliced + + +def frame_iterator(frame, frame_low, frame_high): + """Helper function that will execute the chain of frame filters. + Each filter is executed in priority order. After the execution + completes, slice the iterator to frame_low - frame_high range. An + iterator is always returned. + + Arguments: + frame: The initial frame. + + frame_low: The low range of the slice, counting from 0. If + this is a negative integer then it indicates a backward slice + (ie bt -4) which counts backward from the last frame in the + backtrace. + + frame_high: The high range of the slice, inclusive. If this + is -1 then it indicates all frames until the end of the stack + from frame_low. + + Returns: + frame_iterator: The sliced iterator after all frame + filters have had a chance to execute. + """ + + return _frame_iterator(frame, frame_low, frame_high, True) + + +def execute_frame_filters(frame, frame_low, frame_high): + """Internal function called from GDB that will execute the chain + of frame filters. Each filter is executed in priority order. + After the execution completes, slice the iterator to frame_low - + frame_high range. + + Arguments: + frame: The initial frame. + + frame_low: The low range of the slice, counting from 0. If + this is a negative integer then it indicates a backward slice + (ie bt -4) which counts backward from the last frame in the + backtrace. + + frame_high: The high range of the slice, inclusive. If this + is -1 then it indicates all frames until the end of the stack + from frame_low. + + Returns: + frame_iterator: The sliced iterator after all frame + filters have had a chance to execute, or None if no frame + filters are registered. + + """ + + return _frame_iterator(frame, frame_low, frame_high, False) -- 2.40.1