From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id LdvfDzqB7WpRniUAWB0awg (envelope-from ) for ; Fri, 06 Nov 2026 02:26:50 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=LOBYdKPq; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 134E6378002; Fri, 06 Nov 2026 02:26:50 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 5C9EB1E023 for ; Fri, 06 Nov 2026 02:26:43 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 567EA4BA2E29 for ; Fri, 6 Nov 2026 07:26:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 567EA4BA2E29 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=LOBYdKPq Received: from framsgout02.his.huawei.com (framsgout02.his.huawei.com [14.137.139.54]) by sourceware.org (Postfix) with ESMTPS id A37DC4BA2E05 for ; Fri, 6 Nov 2026 07:26:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A37DC4BA2E05 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=huawei.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A37DC4BA2E05 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=14.137.139.54 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793949978; cv=none; b=cK+737kn676Qg+zZBwLYAnC9xLadnBulHY6Wg01v20Z2cum0ftztJTcSAM7tkyd5kRM6GhmWS15PVDcJX0C5ve9czb5x0dhpDNyqCZ/GYVtU4ESTOkXBdpgLN96fJiP2QbaswEDRvOqj+k1sanm2o0sQ/MTTr72gdouXYVaYPHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793949978; c=relaxed/simple; bh=kkz0O8jHjDF1pGvI9ki5+64iBVDSOhJd8tPy/SeH/z8=; h=dkim-signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MNMXPkTCUeLRjl3AGk9nOsk6l2xdXMTr4Wzume+yy6y6KHEbd3vdzEBujBrhiSXJEhDPNQzjTM4FCfvS2/V7+WWG7zEhsjzCgknMsSxhhCPI1E2vyvyI1uxINobu1B6kLg+s+uVfpRpOPodrlwMFH0aR25ClHJJ1wlikV4VXPDs= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=LOBYdKPq DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A37DC4BA2E05 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=ACM46OOtaJeHX66984KUnJk1Ii+vJaR8y6wBGtO+aos=; b=LOBYdKPqR/tjPG36xjkKYBGlqBXcejyn7LAv1RAB9t7gPS1AR2KWxGoV4ao7xiZLRfotuf7gH crn4rKA98T9HrN3N8sQzvyo4CX5RBDC2xKUJdrbj9c+hO3pxzB46ui7MNCocf7N7R26wfiwFLj6 MTgnUsRxXA2OYEZPQzxURSU= Received: from mail.maildlp.com (unknown [172.18.224.107]) by framsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4jLW1Z1fb9zLlXc; Fri, 6 Nov 2026 15:25:54 +0800 (CST) Received: from frapema100005.china.huawei.com (unknown [7.182.19.229]) by mail.maildlp.com (Postfix) with ESMTPS id 1E89740584; Fri, 6 Nov 2026 15:26:13 +0800 (CST) Received: from huawei.com (10.224.106.75) by frapema100005.china.huawei.com (7.182.19.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Fri, 6 Nov 2026 08:26:10 +0100 From: Dmitry Ivanov To: CC: Subject: [PATCH v2] gdb/python: Handle unnamed frames in caller-matching functions git commit --amend gdb.Frame.name() can return None when GDB cannot determine a frame's function name. and currently pass that value directly to Python's regular expression functions, causing a TypeError. Date: Fri, 6 Nov 2026 07:25:53 +0000 Message-ID: <20261106072553.210018-1-dmitry.ivanov1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <8733u846b4.fsf@tromey.com> References: <8733u846b4.fsf@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.224.106.75] X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To frapema100005.china.huawei.com (7.182.19.229) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Treat unnamed frames as having empty names. Add regression tests for both convenience functions. --- Hi Tom, Thanks for the review. I've updated the patch to treat unnamed frame names as empty strings, as suggested, and adjusted the documentation and tests accordingly. Changes in v2: - Treat unnamed frame names as empty strings instead of non-matches, as suggested by Tom. - Update documentation and regression tests accordingly. gdb/doc/gdb.texinfo | 8 +++++-- gdb/python/lib/gdb/function/caller_is.py | 6 +++-- gdb/testsuite/gdb.python/py-caller-is.exp | 28 +++++++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 6d7fce4a8c2..6ea51df225e 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -13673,7 +13673,9 @@ $1 = 1 @findex $_caller_matches@r{, convenience function} @item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]}) Returns one if the calling function's name matches the regular expression -@var{regexp}. Otherwise it returns zero. +@var{regexp}. Otherwise it returns zero. If the function's name cannot be +determined, it is treated as an empty string, which can be matched using +@code{^$}. If the optional argument @var{number_of_frames} is provided, it is the number of frames up in the stack to look. @@ -13696,7 +13698,9 @@ frame specified by @var{number_of_frames}. @findex $_any_caller_matches@r{, convenience function} @item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]}) Returns one if any calling function's name matches the regular expression -@var{regexp}. Otherwise it returns zero. +@var{regexp}. Otherwise it returns zero. If the function's name cannot be +determined, it is treated as an empty string, which can be matched using +@code{^$}. If the optional argument @var{number_of_frames} is provided, it is the number of frames up in the stack to look. diff --git a/gdb/python/lib/gdb/function/caller_is.py b/gdb/python/lib/gdb/function/caller_is.py index bca09590811..65613aabdf1 100644 --- a/gdb/python/lib/gdb/function/caller_is.py +++ b/gdb/python/lib/gdb/function/caller_is.py @@ -80,7 +80,8 @@ class CallerMatches(gdb.Function): if frame is None: return False nframes = nframes - 1 - return re.match(name.string(), frame.name()) is not None + frame_name = frame.name() or "" + return re.match(name.string(), frame_name) is not None class AnyCallerIs(gdb.Function): @@ -143,7 +144,8 @@ class AnyCallerMatches(gdb.Function): frame = gdb.selected_frame() name_re = re.compile(name.string()) while nframes >= 0: - if name_re.match(frame.name()) is not None: + frame_name = frame.name() or "" + if name_re.match(frame_name) is not None: return True frame = frame.older() if frame is None: diff --git a/gdb/testsuite/gdb.python/py-caller-is.exp b/gdb/testsuite/gdb.python/py-caller-is.exp index d9b826cb6a2..09b0bfb1f8e 100644 --- a/gdb/testsuite/gdb.python/py-caller-is.exp +++ b/gdb/testsuite/gdb.python/py-caller-is.exp @@ -70,3 +70,31 @@ proc test_all_caller_is_fns { } { } test_all_caller_is_fns + +# Prepend an unnamed frame to the current stack without depending on +# missing symbols in the host's runtime libraries. +gdb_test_multiline "define unnamed frame helper" \ + "python" "" \ + "from unittest.mock import Mock, patch" "" \ + "def check_unnamed_frame(expr):" "" \ + " frame = Mock()" "" \ + " frame.name.return_value = None" "" \ + " frame.older.return_value = gdb.selected_frame()" "" \ + " with patch.object(gdb, 'selected_frame', return_value=frame):" "" \ + " print(int(gdb.parse_and_eval(expr)))" "" \ + "end" "" + +gdb_test {python check_unnamed_frame('$_caller_matches("^$", 0)')} \ + "1" "caller_matches detects unnamed frame" + +gdb_test {python check_unnamed_frame('$_caller_matches("^.+$", 0)')} \ + "0" "caller_matches rejects unnamed frame for nonempty name" + +gdb_test {python check_unnamed_frame('$_any_caller_matches("^$", 0)')} \ + "1" "any_caller_matches detects unnamed frame" + +gdb_test {python check_unnamed_frame('$_any_caller_matches("^.+$", 0)')} \ + "0" "any_caller_matches rejects unnamed frame for nonempty name" + +gdb_test {python check_unnamed_frame('$_any_caller_matches("^bottom_func$", 1)')} \ + "1" "any_caller_matches continues past unnamed frame" -- 2.34.1