From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by sourceware.org (Postfix) with ESMTPS id 605E8385842C for ; Wed, 14 Jun 2023 16:30:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 605E8385842C 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-xd29.google.com with SMTP id ca18e2360f4ac-777ac169033so265982539f.0 for ; Wed, 14 Jun 2023 09:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1686760249; x=1689352249; 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=jahDK0RdHCUUOGXDXgfAHBVjJUHx3L8DaWa7Og7bIVx53qP9x/njzyjsVHUHs4NsAP 5U7x8pKvtDEs2Dn5QsVODXvZ7v/OHeIHgP7JwoZgOpBLXleBgMAG3qVnetagxdBFbTUb MUH196nptNqBa273/9ClDCjSScOGLUuehLRgbWy+10fmX2qjYR0QmD53aTCe/1m9LoF9 Hk87FlmpRgjRu2ggtID1sg2UsD3ynhfLwx7iRytvgkdWtawcQzoqA06RGMTRO3IwCcUY DBbM0nWDhU+FFgq2mvXfp7GVFZru1RhyqmJD2FjFyHigQo7VG7j8ym+PbZJj10mLKOHQ yDbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686760249; x=1689352249; 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=jpggl8a+oJ5b5EQ5T3K+3m3yScLZc/7dSgFv9gcCqQRX+HOc0PMlkKCvkXZAC0XIAy gcoJDTV68KHC8152yU8/8ILcGCxAdlL6kuQjXheJFzNrf2j8kxiUvLBmwaiAucETuWFr 2NIMmMLysHdsNDu5w+Fz/QqXx8eYQ5TLW3EN3iV9WCllffYK9uB31e8PPNCmKuWs5Dyd qKMKCRWjboZsV2OQIo4NuVnT27iOLGkvAzJ6WcN1ONqcStoyw4VtWQkpbLID88EW39ql L9VsitFH7QuPmLp0TNvgGOQeX+c8nKnAXaDIsz0vAxhkJ4nghNxabYVJfooB+3eWi7iN E3og== X-Gm-Message-State: AC+VfDyIFWkKlTxH3siCfFdMbcLHYWBWuHd6g3YqAxCi4XEqjHFUBqJ4 eMldFDxsTRmhAyOl1Sz0H3meRl1j1QP1lWiUWPl8cQ== X-Google-Smtp-Source: ACHHUZ6FJFe2WS/SUcmHUHfq6f3VUbetPvID5nHe+ScHh6OlodH0sia9uTtV70x+4uaT0pLu+sLRyQ== X-Received: by 2002:a92:d850:0:b0:340:b8a8:cf68 with SMTP id h16-20020a92d850000000b00340b8a8cf68mr1035052ilq.11.1686760249310; Wed, 14 Jun 2023 09:30:49 -0700 (PDT) Received: from localhost.localdomain (75-166-136-83.hlrn.qwest.net. [75.166.136.83]) by smtp.gmail.com with ESMTPSA id t5-20020a028785000000b0040fa5258658sm5020983jai.77.2023.06.14.09.30.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 09:30:48 -0700 (PDT) From: Tom Tromey Date: Wed, 14 Jun 2023 10:30:48 -0600 Subject: [PATCH 2/5] 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-v1-2-af87db6467b2@adacore.com> References: <20230614-dap-frame-decor-v1-0-af87db6467b2@adacore.com> In-Reply-To: <20230614-dap-frame-decor-v1-0-af87db6467b2@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.3 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