From patchwork Thu Apr 25 18:09:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 89011 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 34623384AB54 for ; Thu, 25 Apr 2024 18:11:26 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by sourceware.org (Postfix) with ESMTPS id 8C20E3858D38 for ; Thu, 25 Apr 2024 18:10:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C20E3858D38 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8C20E3858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714068653; cv=none; b=TDeJfW48RvD4CheNPNXJkiY6Ge8+2KeLGlgfhbFXp7a6/tqGuZyLi/0uiKAWkhBi/fTSDGW2wD9fCeX06OPH75JQtTg5efmtVKzQGcUScy1GhEFEllBtr2M0NBLE3AfMhaYDg88Zo/NXXDV1S5ceE210Wu3oL0wZC+JSYQjVBWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714068653; c=relaxed/simple; bh=0djhzF8lZ59PN7AX90Z397JFL9rLD9aXrJW6ZLvDqXE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=k76SxMB8Vj/Cj27oWCIT+BwI/2sX2RxAVxIMazRfLmVVmwEjBrF2R5vsOY7QmfzT6rEwsnZGXcBnINDxJOUBer9Fo94zeP84Z9FmfjkSFr0o+TYjYYPyHOg+wTpLMMIPB6T/PVFl/qNPdn77qUWrdSoz2sbHrgn/OUisJHrwDZk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-7d9480d96bdso61971439f.1 for ; Thu, 25 Apr 2024 11:10:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1714068650; x=1714673450; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6R4t75WmgWD30B9WU7uAV7dSe2KQjWV/L1LqEadlQjA=; b=YAVNLcsuqRp1DpqYK/TwRpaxGpzfMrqEoAAFK+kdRJ7aMl+C1SQUVwwrvcmt+doiQ1 LBMNPN7yCpdkk856qo0N24vkm2b05R0ZqvphTQCgOvLSGRWCBBG3NAcZx6sTrkcroWS/ UsOFfltszbJZr40gPI8BWAdReB//0CMqMJTRAFlFSibwsfF6hOJsBfkK1FcocEhi9Fov j9HqSP5cADrlFAyMfp4ZUOkwd7qc3jJHzglswLlEPPuVFHkQ6PDt7/S1sNB/bIwf9q97 Sx5mTayym2pE2lGmVSGjxjxeNNNHBpv4lovIpqsWbQ7wn+qZI7fwaGOKjEMXLLOrkrX2 NCBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714068650; x=1714673450; 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=6R4t75WmgWD30B9WU7uAV7dSe2KQjWV/L1LqEadlQjA=; b=f3UDnHcLqtY8+3tLNRpjULLeSzjvehpDTfb7i9ShVHuXWOJDJbo1L37mpnHf8gLOkT gdBY2h86+jSb2gUhMe0VWdbjwtVKuhV0mJuI1r8VWWfhX9sL6x7oBXjxp/pJD6nI3F3R HZVQuQJKtKToVPMCe12PnWl5ZiKadmyqFf15LpmAePrYa0V8MHmSy5meHXaxcrcF6M4W awFY3S5x3nG7oB9DpP+/4jz8OndBMLTc3sDKD3hSywgI0dkI4LFNodZxsngXEgq0wdkK 7yibKwGz0644mt36NerA47sW+jb7IvJsGtHooQMKPcJFs93HOPWT3q2eJyzBMx28pCG1 +ArA== X-Gm-Message-State: AOJu0YxxXV9t69z2aoK1RQ0A++gQ3M+uoFNbovO/nKHQoBU/iPbTUKI2 FZa7rIWMzQ5slTWhc+/AhWy6Nui2LJ25ZRNk7x4NBG5cNhGqqCa/WPr0q+pDL05hGThui/SJSP4 = X-Google-Smtp-Source: AGHT+IHr43augWHEl4MWpNUccckiY3ZM/dpqyyO5owpDt3oMqK5S2STifmCD/Qr3HhW5XZlfu4LLOQ== X-Received: by 2002:a5d:9b07:0:b0:7d5:f3d4:2023 with SMTP id y7-20020a5d9b07000000b007d5f3d42023mr558651ion.18.1714068649443; Thu, 25 Apr 2024 11:10:49 -0700 (PDT) Received: from localhost.localdomain (97-122-86-252.hlrn.qwest.net. [97.122.86.252]) by smtp.gmail.com with ESMTPSA id jm1-20020a0566388c8100b004852136a4dfsm3146550jab.4.2024.04.25.11.10.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 11:10:49 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/3] Simplify DAP make_source callers Date: Thu, 25 Apr 2024 12:09:57 -0600 Message-ID: <20240425181032.80275-2-tromey@adacore.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240425181032.80275-1-tromey@adacore.com> References: <20240425181032.80275-1-tromey@adacore.com> MIME-Version: 1.0 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, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org A couple callers of make_source call basename by hand. Rather than add another caller like this, I thought it would be better to put this ability into make_source itself. --- gdb/python/lib/gdb/dap/breakpoint.py | 3 +-- gdb/python/lib/gdb/dap/bt.py | 4 +--- gdb/python/lib/gdb/dap/sources.py | 8 ++++++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index b2e74277ebd..1380f7decd4 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -13,7 +13,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import os import re from contextlib import contextmanager @@ -116,7 +115,7 @@ def _breakpoint_descriptor(bp): result.update( { - "source": make_source(filename, os.path.basename(filename)), + "source": make_source(filename), "line": line, } ) diff --git a/gdb/python/lib/gdb/dap/bt.py b/gdb/python/lib/gdb/dap/bt.py index e0c2e2a1751..668bcc7ce23 100644 --- a/gdb/python/lib/gdb/dap/bt.py +++ b/gdb/python/lib/gdb/dap/bt.py @@ -13,8 +13,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import os - # This is deprecated in 3.9, but required in older versions. from typing import Optional @@ -98,7 +96,7 @@ def _backtrace(thread_id, levels, startFrame, stack_format): name += ", module " + objfile.username filename = current_frame.filename() if filename is not None: - newframe["source"] = make_source(filename, os.path.basename(filename)) + newframe["source"] = make_source(filename) newframe["name"] = name frames.append(newframe) # Note that we do not calculate totalFrames here. Its absence diff --git a/gdb/python/lib/gdb/dap/sources.py b/gdb/python/lib/gdb/dap/sources.py index ee3464db679..ad0c913c8c1 100644 --- a/gdb/python/lib/gdb/dap/sources.py +++ b/gdb/python/lib/gdb/dap/sources.py @@ -32,16 +32,20 @@ _id_map = {} @in_gdb_thread -def make_source(fullname, filename): +def make_source(fullname, filename=None): """Return the Source for a given file name. FULLNAME is the full name. This is used as the key. - FILENAME is the base name. + FILENAME is the base name; if None (the default), then it is + computed from FULLNAME. """ global _source_map if fullname in _source_map: result = _source_map[fullname] else: + if filename is None: + filename = os.path.basename(fullname) + result = { "name": filename, "path": fullname,