From patchwork Tue Dec 12 17:44:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 81993 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 82907385B51F for ; Tue, 12 Dec 2023 17:45:01 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id E59BA3858C2A for ; Tue, 12 Dec 2023 17:44:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E59BA3858C2A Authentication-Results: sourceware.org; dmarc=pass (p=none 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 E59BA3858C2A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702403087; cv=none; b=jOYoiwZzA5QKqHAsXSxSBOX5zxfllH+Zbyuny9OXkmlHYvstkWyzS82HfYXW1sep92so8cscNkNr18V+y4PU6gVNtm/HOVbyOozXDAvZzLW3dfAtYiWm4VJSOe1a7zPweg7RrCq3lk9sxV/hjhNO4IQOPAazwlhC8g6Xg+ihsDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702403087; c=relaxed/simple; bh=0T4oB+uxB+DNZQEgzhTC0VlIrKG6jrehcv/EnJC9NOk=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=XNr7GOW3ELlnzWkQ6if/6xOoqXKTGr0fG59GjtzNQlcP3PUl3uhfu7PCDUXM5klToXUi9ghWljw8L7sj+fGgepj5+W7+TyAZ2wcqRXaidN36ayu+P8uxjwzP44LBYaxbjeX5E3zJClH8YxzKw+bJoM6mZs/TyGn0dEdjDT6S5p4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-35d74cf427cso23430175ab.1 for ; Tue, 12 Dec 2023 09:44:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702403084; x=1703007884; darn=sourceware.org; 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=cc4h28pQyTSMdG7L9KCN+/83VrbA2cdDWNuKbiKWFbw=; b=Tx7+IajNcrOyVxUyNddxUAQB8cidazWW6J73f+Ecs5V/qi3kgSxP+BkHdZzGythoXd Ct5ZK/uHHipU83cyxbO7V5sUgrXmcNVhq4XsBa4vZgpH1+7U4RHuBKeiAqZ74+hJJeoK wT6fhvjlX4vCmmPlLipn8K9iSXBztW2zLjFRjbCFrdQOq/SW9+a8FaGyZHL3jABnowD8 mYLN8MNnEUGtP8KlDoDLnnoe3Xa2ivOuww9uR6n/2MXhfoDCWlI48MhFLMBAWLvfHwLF XTnRPROeh0DFa4PXyfQT8wtGXWIlMF6csr9h55QhKQ+lA0OqMQXbq+UwVjemruTXbBES k1eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702403084; x=1703007884; 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=cc4h28pQyTSMdG7L9KCN+/83VrbA2cdDWNuKbiKWFbw=; b=Hmqv5tF3FsuPm+rk/iYLrZwkKFGc6crJphlAMlCzHvDLJSXDwz5mfAv2z8Pi3wTBx9 xiXq1fKI94xR9tIhPcpG1wZ0XM1N2WeUHMlfs7lY0yoKxMrv69KSd6T1h86vemdzOB+T 99OAUY8gsPLZIiXSUeATfgzIl1znY3CNMYsDn1nSheYUFjRTkjZHFQoBqPQ9S2pb8wTQ +4KYwuWBTE35vS9X6lvEJQe0Rib0Oz3neSE4vz25MN/E4n0/slLZqgNGqZAS0EiLfurP hz2dkGz3JQFQy5Gvo2ITbBJaz8jSSlj5VFy7hcwNJySMuXU4l8XHVUDTOikao6TUm60p xZGQ== X-Gm-Message-State: AOJu0YysUbnMfIRfZYrz/rChv+Ej7/DbDLkwFXBFp7WXoi9Rirg/OnLb R/svxdKQavoY2fZTYgRn3Og05amBK7ceHQ30Hn4= X-Google-Smtp-Source: AGHT+IHdzHwKxIOlbK35506zpte49RegANQOXYpillm+9I/92jdzphnXP1XZtRRJp2hqRG9VtP3wqg== X-Received: by 2002:a05:6e02:17cf:b0:35d:a8d0:6e31 with SMTP id z15-20020a056e0217cf00b0035da8d06e31mr8889440ilu.26.1702403084083; Tue, 12 Dec 2023 09:44:44 -0800 (PST) Received: from localhost.localdomain (71-211-161-25.hlrn.qwest.net. [71.211.161.25]) by smtp.gmail.com with ESMTPSA id u26-20020a02aa9a000000b004693a30f295sm2479819jai.170.2023.12.12.09.44.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 09:44:43 -0800 (PST) From: Tom Tromey Date: Tue, 12 Dec 2023 10:44:42 -0700 Subject: [PATCH 1/4] Introduce and use DAPException MIME-Version: 1.0 Message-Id: <20231212-dap-no-test-exceptions-v1-1-af0e33f10093@adacore.com> References: <20231212-dap-no-test-exceptions-v1-0-af0e33f10093@adacore.com> In-Reply-To: <20231212-dap-no-test-exceptions-v1-0-af0e33f10093@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 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, 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 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 This introduces a new DAPException class, and then changes various spots in the DAP implementation to wrap "expected" exceptions in this. This class will help detect rogue exceptions caused by bugs in the implementation. --- gdb/python/lib/gdb/dap/breakpoint.py | 8 +++++--- gdb/python/lib/gdb/dap/evaluate.py | 12 ++++++------ gdb/python/lib/gdb/dap/launch.py | 4 ++-- gdb/python/lib/gdb/dap/sources.py | 6 +++--- gdb/python/lib/gdb/dap/startup.py | 18 ++++++++++++++++++ gdb/python/lib/gdb/dap/varref.py | 6 +++--- 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index 33aa18e65bc..c67bb471daf 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -24,7 +24,7 @@ from typing import Optional, Sequence from .server import request, capability, send_event from .sources import make_source -from .startup import in_gdb_thread, log_stack +from .startup import in_gdb_thread, log_stack, parse_and_eval, DAPException from .typecheck import type_check @@ -168,7 +168,7 @@ def _set_breakpoints_callback(kind, specs, creator): bp.ignore_count = 0 else: bp.ignore_count = int( - gdb.parse_and_eval(hit_condition, global_context=True) + parse_and_eval(hit_condition, global_context=True) ) # Reaching this spot means success. @@ -212,6 +212,7 @@ class _PrintBreakpoint(gdb.Breakpoint): # have already been stripped by the placement of the # regex capture in the 'split' call. try: + # No real need to use the DAP parse_and_eval here. val = gdb.parse_and_eval(item) output += str(val) except Exception as e: @@ -360,12 +361,13 @@ def _catch_exception(filterId, **args): if filterId in ("assert", "exception", "throw", "rethrow", "catch"): cmd = "-catch-" + filterId else: - raise Exception("Invalid exception filterID: " + str(filterId)) + raise DAPException("Invalid exception filterID: " + str(filterId)) result = gdb.execute_mi(cmd) # A little lame that there's no more direct way. for bp in gdb.breakpoints(): if bp.number == result["bkptno"]: return bp + # Not a DAPException because this is definitely unexpected. raise Exception("Could not find catchpoint after creating") diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index d39e7879205..eb38baf3973 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -20,7 +20,7 @@ from typing import Optional from .frames import select_frame from .server import capability, request, client_bool_capability -from .startup import in_gdb_thread +from .startup import in_gdb_thread, parse_and_eval, DAPException from .varref import find_variable, VariableReference, apply_format @@ -37,7 +37,7 @@ def _evaluate(expr, frame_id, value_format): if frame_id is not None: select_frame(frame_id) global_context = False - val = gdb.parse_and_eval(expr, global_context=global_context) + val = parse_and_eval(expr, global_context=global_context) ref = EvaluateResult(val) return ref.to_object() @@ -89,7 +89,7 @@ def eval_request( # Ignore the format for repl evaluation. return _repl(expression, frameId) else: - raise Exception('unknown evaluate context "' + context + '"') + raise DAPException('unknown evaluate context "' + context + '"') @request("variables") @@ -119,8 +119,8 @@ def set_expression( if frameId is not None: select_frame(frameId) global_context = False - lhs = gdb.parse_and_eval(expression, global_context=global_context) - rhs = gdb.parse_and_eval(value, global_context=global_context) + lhs = parse_and_eval(expression, global_context=global_context) + rhs = parse_and_eval(value, global_context=global_context) lhs.assign(rhs) return _SetResult(lhs).to_object() @@ -133,6 +133,6 @@ def set_variable( with apply_format(format): var = find_variable(variablesReference) lhs = var.find_child_by_name(name) - rhs = gdb.parse_and_eval(value) + rhs = parse_and_eval(value) lhs.assign(rhs) return lhs.to_object() diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index 7014047ff51..a8adb125707 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -20,7 +20,7 @@ from typing import Mapping, Optional, Sequence from .events import exec_and_expect_stop, expect_process from .server import request, capability -from .startup import exec_and_log +from .startup import exec_and_log, DAPException # The program being launched, or None. This should only be accessed @@ -69,7 +69,7 @@ def attach(*, pid: Optional[int] = None, target: Optional[str] = None, **args): elif target is not None: cmd = "target remote " + target else: - raise Exception("attach requires either 'pid' or 'target'") + raise DAPException("attach requires either 'pid' or 'target'") expect_process("attach") exec_and_log(cmd) diff --git a/gdb/python/lib/gdb/dap/sources.py b/gdb/python/lib/gdb/dap/sources.py index 821205cedd1..d73a3f8c5b1 100644 --- a/gdb/python/lib/gdb/dap/sources.py +++ b/gdb/python/lib/gdb/dap/sources.py @@ -18,7 +18,7 @@ import os import gdb from .server import request, capability -from .startup import in_gdb_thread +from .startup import in_gdb_thread, DAPException # The next available source reference ID. Must be greater than 0. @@ -68,11 +68,11 @@ def decode_source(source): if "path" in source: return source["path"] if "sourceReference" not in source: - raise Exception("either 'path' or 'sourceReference' must appear in Source") + raise DAPException("either 'path' or 'sourceReference' must appear in Source") ref = source["sourceReference"] global _id_map if ref not in _id_map: - raise Exception("no sourceReference " + str(ref)) + raise DAPException("no sourceReference " + str(ref)) return _id_map[ref]["path"] diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py index 1d3b94762a6..64a46597bf4 100644 --- a/gdb/python/lib/gdb/dap/startup.py +++ b/gdb/python/lib/gdb/dap/startup.py @@ -39,6 +39,24 @@ _gdb_thread = threading.current_thread() _dap_thread = None +# "Known" exceptions are wrapped in a DAP exception, so that, by +# default, only rogue exceptions are logged -- this is then used by +# the test suite. +class DAPException(Exception): + pass + + +# Wrapper for gdb.parse_and_eval that turns exceptions into +# DAPException. +def parse_and_eval(expression, global_context=False): + try: + return gdb.parse_and_eval(expression, global_context=global_context) + except Exception as e: + # Be sure to preserve the summary, as this can propagate to + # the client. + raise DAPException(str(e)) from e + + def start_thread(name, target, args=()): """Start a new thread, invoking TARGET with *ARGS there. This is a helper function that ensures that any GDB signals are diff --git a/gdb/python/lib/gdb/dap/varref.py b/gdb/python/lib/gdb/dap/varref.py index 8f0a070498c..c75afe3848e 100644 --- a/gdb/python/lib/gdb/dap/varref.py +++ b/gdb/python/lib/gdb/dap/varref.py @@ -14,7 +14,7 @@ # along with this program. If not, see . import gdb -from .startup import in_gdb_thread +from .startup import in_gdb_thread, DAPException from .server import client_bool_capability from abc import ABC, abstractmethod from collections import defaultdict @@ -165,7 +165,7 @@ class BaseReference(ABC): # map here. if name in self.by_name: return self.by_name[name] - raise Exception("no variable named '" + name + "'") + raise DAPException("no variable named '" + name + "'") class VariableReference(BaseReference): @@ -271,5 +271,5 @@ def find_variable(ref): # Variable references are offset by 1. ref = ref - 1 if ref < 0 or ref > len(all_variables): - raise Exception("invalid variablesReference") + raise DAPException("invalid variablesReference") return all_variables[ref] From patchwork Tue Dec 12 17:44:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 81996 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 C1EF4385841A for ; Tue, 12 Dec 2023 17:45:17 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by sourceware.org (Postfix) with ESMTPS id A70AC3858C2F for ; Tue, 12 Dec 2023 17:44:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A70AC3858C2F Authentication-Results: sourceware.org; dmarc=pass (p=none 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 A70AC3858C2F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d2d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702403089; cv=none; b=Mh+MGZNHvdLNSnQEtJAd48YoEE7l5tOYXmCHVcEJ6GL4wpFMV4uA/px+OZ/URysES36yc2FYDOy1xpwdZsbH3dv8oTnKuvKig6M5qlXSCImaFr0jzlo400lrj7dgUN/GAZ+r0ppOEnL/H5yTrgoK0sRGSFUrD1IJWptfOIcwjcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702403089; c=relaxed/simple; bh=zVRY/206c/hI28p4BRZIwbwZSk0OG0PG/zcFYmPAwVY=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=ECmGHR1cS6oD3yUhNtC2aAOh+URv79K+nrx64mNjzcI6XLwrEuRJW5AScTUnVIzOq1xqOItuZ1Rkd/WmwEdgSbVVSYSR/anBW0EPiPYkCsv+MmlEpArqgeO2OZzPPnMMEfN+jpahNxwjjGM6uAz4rSRywmE9Vmuw4Qb722TxCZo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-7b37405f64aso240451739f.2 for ; Tue, 12 Dec 2023 09:44:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702403085; x=1703007885; darn=sourceware.org; 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=thsQUeaUpa+RzleIp13zhN8+c+jkvmTmUEu21dzDyzA=; b=gKZB+zv8mYhuWfDOVYvmTYhWSPAyRywOW7nhDlvKmRuUVAqhQJNUebs1eK4rF5lJrw tz9UYt3gf+21blaY/sKaUs6OJ1XMFyAqlUXJCzU6lYKEK0evrpezBuHrGBMZNFZm74al HACRqtYQcEx7DxtWJhJnoiDfuYwbGCCfQyfwUZb36ft7nxvz4vejwDh3LyPQjGzbnKP9 NlIAn2pBunxkW+fV/hphL9fpmrF+/++Ma+0ajLqU6YO6RpwSAzKpmQkCYRRcNWneErCe UKfwTKSDDF76CYsS68OeDw8XRQ8CQoYEWWQIfzL+qM/GFy73p9Rej3uE4fGauU2Az2Du NXGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702403085; x=1703007885; 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=thsQUeaUpa+RzleIp13zhN8+c+jkvmTmUEu21dzDyzA=; b=haFEkuZT+USEVm6QIAfhPEXpcG/AtGOEl0DoQkr1IJJUQaI1BRzcedV/PuEkgQXj6l KhFtcBR0HiZxUM7Z9qfQ6UEc4j5tkKntNLvkvBYzjvyrPietD9EHklOazmBWsVNZ3RRT FVKjB/BOOFB56wW3Q6RiQN5ejVP3lzyLGO32LaLoAJXJbFuqm3mVmNib88fuapFxoHRZ WDZtTp8rUi2eN91W/bdVmkIX/yvfT6XbIR9jWZ13ASfpxwb8UL9S9De/Dcay2+KbDxIm XZaoGV+Brw3LHpfP/bSGFtqyw6sxDsdtFsu2itz4lo/2hmcZz9Hq1wGFjCwmBjnV6VpB n1qQ== X-Gm-Message-State: AOJu0YzghDappyrz6ZZaPP+b+mLDNirG/TF7iCnEJXIPjZOOGRcDIh6M GDHlBcTiKHEnT6d0I4op+xbPx4vD3hKPQKZB9VM= X-Google-Smtp-Source: AGHT+IGGVJsk5OJDpjPFGLuo/jnCTEQ04bStaaiw3Uh5nhTeM4ylRoBe4gOfXDQzo/FYSBUiemtKNA== X-Received: by 2002:a5e:8c04:0:b0:7b6:cbfc:9f3f with SMTP id n4-20020a5e8c04000000b007b6cbfc9f3fmr9218408ioj.8.1702403084743; Tue, 12 Dec 2023 09:44:44 -0800 (PST) Received: from localhost.localdomain (71-211-161-25.hlrn.qwest.net. [71.211.161.25]) by smtp.gmail.com with ESMTPSA id u26-20020a02aa9a000000b004693a30f295sm2479819jai.170.2023.12.12.09.44.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 09:44:44 -0800 (PST) From: Tom Tromey Date: Tue, 12 Dec 2023 10:44:43 -0700 Subject: [PATCH 2/4] Add DAP log level parameter MIME-Version: 1.0 Message-Id: <20231212-dap-no-test-exceptions-v1-2-af0e33f10093@adacore.com> References: <20231212-dap-no-test-exceptions-v1-0-af0e33f10093@adacore.com> In-Reply-To: <20231212-dap-no-test-exceptions-v1-0-af0e33f10093@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 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 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 This adds a new parameter to control the DAP logging level. By default, "expected" exceptions are not logged, but the parameter lets the user change this when more logging is desired. This also changes a couple of spots to avoid logging the stack trace for a DAPException. This patch also documents the existing DAP logging parameter. I forgot to document this before. Reviewed-By: Eli Zaretskii Reviewed-By: Kévin Le Gouguec --- gdb/NEWS | 5 +++++ gdb/doc/gdb.texinfo | 18 ++++++++++++++++++ gdb/python/lib/gdb/dap/breakpoint.py | 6 ++++-- gdb/python/lib/gdb/dap/server.py | 10 ++++++++++ gdb/python/lib/gdb/dap/startup.py | 29 +++++++++++++++++++++++++---- 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 534e2e7f364..6d35722cc23 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -88,6 +88,11 @@ show remote thread-options-packet ** GDB now supports the "cancel" request. + ** New command "set debug dap-log-level" controls DAP logging. + + ** The "set debug dap-log-file" command is now documented. This + command was available in GDB 14 but not documented. + * New remote packets New stop reason: clone diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 6e4adf512ee..fd60e41091a 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -39611,6 +39611,24 @@ Evaluations like this can be interrupted using the DAP @code{cancel} request. (In fact, @code{cancel} should work for any request, but it is unlikely to be useful for most of them.) +@value{GDBN} provides a couple of logging settings that can be used in +DAP mode. These can be set on the command line using the @code{-iex} +option (@pxref{File Options}). + +@table @code +@item set debug dap-log-file @r{[}@var{filename}@r{]} +Enable DAP logging. Logs are written to the specified file. If no +file is given, logging is stopped. + +@item set debug dap-log-level @var{level} +Set the DAP logging level. The default is @samp{1}, which logs the +DAP protocol, whatever debug messages the developers thought were +useful, and unexpected exceptions. Level @samp{2} can be used to log +all exceptions, including ones that are considered to be expected. +For example, a failure to parse an expression would be considered a +normal exception and not normally be logged. +@end table + @node JIT Interface @chapter JIT Compilation Interface @cindex just-in-time compilation diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index c67bb471daf..cef3df910f0 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -24,7 +24,7 @@ from typing import Optional, Sequence from .server import request, capability, send_event from .sources import make_source -from .startup import in_gdb_thread, log_stack, parse_and_eval, DAPException +from .startup import in_gdb_thread, log_stack, parse_and_eval, LOG_FULL, DAPException from .typecheck import type_check @@ -176,7 +176,9 @@ def _set_breakpoints_callback(kind, specs, creator): result.append(_breakpoint_descriptor(bp)) # Exceptions other than gdb.error are possible here. except Exception as e: - log_stack() + # Don't normally want to see this, as it interferes with + # the test suite. + log_stack(LOG_FULL) # Maybe the breakpoint was made but setting an attribute # failed. We still want this to fail. if bp is not None: diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 44dffb1b809..e682c0faf84 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -23,6 +23,7 @@ import threading from .io import start_json_writer, read_json from .startup import ( exec_and_log, + DAPException, DAPQueue, in_dap_thread, in_gdb_thread, @@ -31,6 +32,7 @@ from .startup import ( start_thread, log, log_stack, + LOG_FULL, ) from .typecheck import type_check @@ -139,12 +141,20 @@ class Server: result["body"] = body result["success"] = True except NotStoppedException: + # This is an expected exception, and the result is clearly + # visible in the log, so do not log it. result["success"] = False result["message"] = "notStopped" except KeyboardInterrupt: # This can only happen when a request has been canceled. result["success"] = False result["message"] = "cancelled" + except DAPException as e: + # Don't normally want to see this, as it interferes with + # the test suite. + log_stack(LOG_FULL) + result["success"] = False + result["message"] = str(e) except BaseException as e: log_stack() result["success"] = False diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py index 64a46597bf4..548fedf4ac9 100644 --- a/gdb/python/lib/gdb/dap/startup.py +++ b/gdb/python/lib/gdb/dap/startup.py @@ -101,6 +101,27 @@ def in_dap_thread(func): return ensure_dap_thread +# Logging levels. +LOG_DEFAULT = 1 +LOG_FULL = 2 + + +class LogLevel(gdb.Parameter): + """DAP logging level.""" + + set_doc = "Set the DAP logging level." + show_doc = "Show the DAP logging level." + + def __init__(self): + super().__init__( + "debug dap-log-level", gdb.COMMAND_MAINTENANCE, gdb.PARAM_ZUINTEGER + ) + self.value = LOG_DEFAULT + + +_log_level = LogLevel() + + class LoggingParam(gdb.Parameter): """Whether DAP logging is enabled.""" @@ -128,16 +149,16 @@ class LoggingParam(gdb.Parameter): dap_log = LoggingParam() -def log(something): +def log(something, level=LOG_DEFAULT): """Log SOMETHING to the log file, if logging is enabled.""" - if dap_log.log_file is not None: + if dap_log.log_file is not None and level <= _log_level.value: print(something, file=dap_log.log_file) dap_log.log_file.flush() -def log_stack(): +def log_stack(level=LOG_DEFAULT): """Log a stack trace to the log file, if logging is enabled.""" - if dap_log.log_file is not None: + if dap_log.log_file is not None and level <= _log_level.value: traceback.print_exc(file=dap_log.log_file) From patchwork Tue Dec 12 17:44:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 81994 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 36250385B836 for ; Tue, 12 Dec 2023 17:45:02 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 46EF3385841A for ; Tue, 12 Dec 2023 17:44:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 46EF3385841A Authentication-Results: sourceware.org; dmarc=pass (p=none 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 46EF3385841A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702403087; cv=none; b=l6KjOJuQAUMATzud5HDcJBbTmGSIddyEh0NbNOMG6d3HIH73UOFxTg+FH42Fd990+1Fgo8PQHVinx12Umdr4kGC9pf9ut/cVx96eHIFA3R/6nIKNBlxEQ4VYP3ySppD2S0dR6WWpm5Fjx92FoyWWfEstW69zhOPkmN2Gv6Ihm5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702403087; c=relaxed/simple; bh=hoDEA6sxfW1je5mpL8IUfqEC0wjCcV0PTIPHINmON+o=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=DAFXne7STq87iZXldBSr9s1220w6B3TVlI4RFmevUo/1ZIJL4EfcFDu0aZ7CI2tu9SIiCEhbN3qrHR9BZAflIq4oOGYf7iZGuG0DcP4lOJE3Qya8lMf6fqJhslDZt62l8+n4xOGp734X3eO0y9/LPqTsN0/TRZ9HStpXF0V6o/A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7b75f681237so62459139f.0 for ; Tue, 12 Dec 2023 09:44:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702403085; x=1703007885; darn=sourceware.org; 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=cXGhii8N9wgVqvm+mdeAlYmIg3VUoPaCmU8xRnuHZTY=; b=TghZaVlcmJ7bt/emE1sDMtA3HebY79uRrwbEsYgfMzjiLffXWrQr2pJ+3yxk0/Cwu9 bgFxD/chRdY/dAD5QrZRxw/+/Cu0oWJ1w1VYo2GJFhyDQ89XponGItYgCyPR/1UNdxiX Sl3ldiCOrjdyxLNsmPsV8sbgXEN7CJlbpkJ8ZTWPnxbC/30odDfl/1TQzY1CF4iGW98k 3CxQAEoGQb1IXxaiG/1hBfidCiCwOnvG9x9kX68xjcCZhUNDHtcjZxDHlAuNEWgWaYX0 Jk0TOCVk4rKRQp/nM65mCxmNLn59zDqg0UPjGgs6y30RQ4PpqtNGwI4VKCEA5oYClKUq vlow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702403085; x=1703007885; 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=cXGhii8N9wgVqvm+mdeAlYmIg3VUoPaCmU8xRnuHZTY=; b=X9Lt6gY501CN86KH11MeTmlrRSPCgaY404XePBjIIBq1hyTcwJ5hup/vx+EXJfehhi yGz/wtCwr3AEyvXAt4lsSYEksCW0eZ4MPc30mlbWxHuqV/IiTOEbDdqACfGyLw89z0c/ ADZzOE6JZDF4pjYoyyzffd8GfIlwuHagiCz8XH02dG9OKwahqY5u/elXAdRW8JL9HETN x+diq1xGYMhrZ24EgUUTNUb69iQeoaDQfjlSRpiiahurWx9/Us2gobgw/dOidDcXfXbm zRcnNkTDIMGogwvyK+qmOQ+8YPvtTVwPKpBgxFkTuElJ7UUfKAYw2/IVbxcwD0yymEyJ SOQA== X-Gm-Message-State: AOJu0YyR0arZyWQixBDWlK0wpzgkU/WwmR7ejJ/yv2+iehqGTlFl5x/m 7A4dLQ/f7zKHxSe0/ZT5OlJ2rJz6avmCeINNycA= X-Google-Smtp-Source: AGHT+IEJz3w29kARwNjGsWLp2/vxhHU5nyuBKDNAR6o604AMdUe39HvPkhBJwDkGg9T/TBMbjKggTQ== X-Received: by 2002:a05:6e02:148a:b0:35d:5128:d379 with SMTP id n10-20020a056e02148a00b0035d5128d379mr8457100ilk.24.1702403085512; Tue, 12 Dec 2023 09:44:45 -0800 (PST) Received: from localhost.localdomain (71-211-161-25.hlrn.qwest.net. [71.211.161.25]) by smtp.gmail.com with ESMTPSA id u26-20020a02aa9a000000b004693a30f295sm2479819jai.170.2023.12.12.09.44.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 09:44:45 -0800 (PST) From: Tom Tromey Date: Tue, 12 Dec 2023 10:44:44 -0700 Subject: [PATCH 3/4] Avoid exception from attach in DAP MIME-Version: 1.0 Message-Id: <20231212-dap-no-test-exceptions-v1-3-af0e33f10093@adacore.com> References: <20231212-dap-no-test-exceptions-v1-0-af0e33f10093@adacore.com> In-Reply-To: <20231212-dap-no-test-exceptions-v1-0-af0e33f10093@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 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 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 I noticed that the DAP attach test case (and similarly remoted-dap.exp) had a rogue exception stack trace in the log. It turns out that an attach will generate a stop that does not have a reason. This patch fixes the problem in the _on_stop event listener by making it a bit more careful when examining the event reason. It also adds some machinery so that attach stops can be suppressed, which I think is the right thing to do. Reviewed-By: Kévin Le Gouguec --- gdb/python/lib/gdb/dap/events.py | 43 +++++++++++++++++++++++++++++++--------- gdb/python/lib/gdb/dap/launch.py | 3 ++- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py index cbefe90e4ca..82fe99632d5 100644 --- a/gdb/python/lib/gdb/dap/events.py +++ b/gdb/python/lib/gdb/dap/events.py @@ -147,6 +147,16 @@ def _cont(event): ) +_suppress_stop = False + + +@in_gdb_thread +def suppress_stop(): + """Indicate that the next stop should not emit an event.""" + global _suppress_stop + _suppress_stop = True + + _expected_pause = False @@ -198,6 +208,13 @@ stop_reason_map = { def _on_stop(event): global inferior_running inferior_running = False + + global _suppress_stop + if _suppress_stop: + _suppress_stop = False + log("suppressing stop in _on_stop") + return + log("entering _on_stop: " + repr(event)) log(" details: " + repr(event.details)) obj = { @@ -206,17 +223,25 @@ def _on_stop(event): } if isinstance(event, gdb.BreakpointEvent): obj["hitBreakpointIds"] = [x.number for x in event.breakpoints] - global stop_reason_map - reason = event.details["reason"] global _expected_pause - if ( - _expected_pause - and reason == "signal-received" - and event.details["signal-name"] in ("SIGINT", "SIGSTOP") - ): - obj["reason"] = "pause" + # Some stop events still do not emit details. For example, + # 'attach' causes a reason-less stop. + if "reason" not in event.details: + # This can only really happen via a "repl" evaluation of + # something like "attach". In this case just emit a generic + # stop. + obj["reason"] = "stopped" else: - obj["reason"] = stop_reason_map[reason] + reason = event.details["reason"] + if ( + _expected_pause + and reason == "signal-received" + and event.details["signal-name"] in ("SIGINT", "SIGSTOP") + ): + obj["reason"] = "pause" + else: + global stop_reason_map + obj["reason"] = stop_reason_map[reason] _expected_pause = False send_event("stopped", obj) diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index a8adb125707..a20009c190d 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -18,7 +18,7 @@ import gdb # These are deprecated in 3.9, but required in older versions. from typing import Mapping, Optional, Sequence -from .events import exec_and_expect_stop, expect_process +from .events import exec_and_expect_stop, expect_process, suppress_stop from .server import request, capability from .startup import exec_and_log, DAPException @@ -71,6 +71,7 @@ def attach(*, pid: Optional[int] = None, target: Optional[str] = None, **args): else: raise DAPException("attach requires either 'pid' or 'target'") expect_process("attach") + suppress_stop() exec_and_log(cmd) From patchwork Tue Dec 12 17:44:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 81995 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 EC517385B525 for ; Tue, 12 Dec 2023 17:45:05 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by sourceware.org (Postfix) with ESMTPS id 1764E3858000 for ; Tue, 12 Dec 2023 17:44:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1764E3858000 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 1764E3858000 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702403088; cv=none; b=AVPSK1Q0pdIXcuKQ4g7hb84cog92H85iIXygOYhllgp4NHi1ovnRoHurfTTcep17RTwZWlRnh+6V+gLqmNWI9/MPJ7i4CdrEVir+l34o24CrEGg6oEMOnGiTUYRYckGrsLPOAN3Fo7hS+VbjRh5gQ7YJU/0+JfKsx07DwiO9TUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702403088; c=relaxed/simple; bh=/boCMQmQnA28aOjxMTmaAYVLNdn89tJzERiOJGBaYmw=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=wYc10Vn8qoLVdoT0ZKo5lLvATAXNngAoUZN0rsnr6ISb9ONQhqODqRz10q8Z96OOcMGNcwh/fJW0Z3t4yzsGsIidSoxJO2Jq+KZIbZWEb59VX3lMBQAeqiqOlFWrxi/aZBTWdq9BjxeMX/jy/YMCspXMZcCQfZaZa4mIbC+zym4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-35d699ec3caso19100415ab.3 for ; Tue, 12 Dec 2023 09:44:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702403086; x=1703007886; darn=sourceware.org; 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=0srrMohV6K9467myCFYLVFDClWwrEvy/wKJgX8gBKrc=; b=b0n+osQQjID+pOMkg6NbFg+9VkzpchW4Sj0u3lDQEozD77FMUkNfZATygz7jfCSpQQ 3VC/H5u6bFagJBQgNepl92oVHahlC9hnsOWNIdRWyt9K+mxUWQ+9G+0qcZj7WewIPsze TBDg8Nbvg4/y+rOCK+ua5IiU0C+R2KLUNdcY2T0EUV8FSkXzgTPZfTS+GD15I1MbiFHv /MartXT0n0XAtm2HeFKTI5GpANLixj61FPXw8JeWew+KHA6g5emukvV+3jLtnxKEJ2an yZmt8urmn4ZDMVDzHq2YuLu7JMVYIQNGTCa8ImfzMrXjWgnSHPiCj3uqY0WxbMuxyrC1 MMiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702403086; x=1703007886; 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=0srrMohV6K9467myCFYLVFDClWwrEvy/wKJgX8gBKrc=; b=kSIJcyZrQi5inA1Tqn5y55yzzc9eJqGMVqDv/uQqLOQMDLSyRnesv3Rn9qiFYfA6Lm IMO5A9fpE3dFdmTxbb1cl4uWUDTuatyiUGiAyZzGPwB7eL8Jr8W3e2ynWaqZm/F92SGO BnUIwffZEWXBuZU1uaQx8sdn6odzffs8dy3uKAv5fxiTuQproQUpZxkbTpUgy2b0o7mN w81wKWoabAfnB55fBhUjbMNH5LeNygLOzG1EfaDGTnNMY31eTt7p54Lle25fHFagMX6W lPd8EIG8ycdq72bSoId08+n9r8U9gcLT7szhO1Vn6lawPfOCw4Rw8cvWv6Fecf374xO+ VAdg== X-Gm-Message-State: AOJu0YzQBkRzmOeN/KSI49ZfrRtKgFOlmZUhTzb0Ea9PDgno4pJgePIf h91PJJ9A5iu8Z2GHp8gdwsfT8Stfxx9isptEcCQ= X-Google-Smtp-Source: AGHT+IHv8j6trqLNrxacdgalKqlCCfCSzw5EuruOsnMeP5AMozHzLq7DY/8VzPX+unWu0/8cCJ2yoQ== X-Received: by 2002:a05:6e02:1a0c:b0:35d:50a8:8e00 with SMTP id s12-20020a056e021a0c00b0035d50a88e00mr10833521ild.18.1702403086295; Tue, 12 Dec 2023 09:44:46 -0800 (PST) Received: from localhost.localdomain (71-211-161-25.hlrn.qwest.net. [71.211.161.25]) by smtp.gmail.com with ESMTPSA id u26-20020a02aa9a000000b004693a30f295sm2479819jai.170.2023.12.12.09.44.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 09:44:45 -0800 (PST) From: Tom Tromey Date: Tue, 12 Dec 2023 10:44:45 -0700 Subject: [PATCH 4/4] Check for rogue DAP exceptions in test suite MIME-Version: 1.0 Message-Id: <20231212-dap-no-test-exceptions-v1-4-af0e33f10093@adacore.com> References: <20231212-dap-no-test-exceptions-v1-0-af0e33f10093@adacore.com> In-Reply-To: <20231212-dap-no-test-exceptions-v1-0-af0e33f10093@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 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 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 This changes the test suite to look for rogue DAP exceptions in the log file, and issue a "fail" if one is found. --- gdb/testsuite/lib/dap-support.exp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp index b9ac314fee5..4aaae637c45 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -16,6 +16,11 @@ # The JSON parser. load_lib ton.tcl +# The sequence number for the currently-executing instance of gdb +# launched via dap_gdb_start. This is used for log-file checking +# after the run is complete. Zero means gdb hasn't started yet. +set dap_gdb_instance 0 + # The sequence number for the next DAP request. This is used by the # automatic sequence-counting code below. It is reset each time GDB # is restarted. @@ -29,10 +34,13 @@ proc dap_gdb_start {} { gdb_stdin_log_init + global dap_gdb_instance + incr dap_gdb_instance + global GDBFLAGS stty_init save_vars { GDBFLAGS stty_init } { set stty_init "-echo raw" - set logfile [standard_output_file "dap.log.$gdb_instances"] + set logfile [standard_output_file "dap.log.$dap_gdb_instance"] append GDBFLAGS " -iex \"set debug dap-log-file $logfile\" -q -i=dap" set res [gdb_spawn] if {$res != 0} { @@ -325,11 +333,35 @@ proc dap_target_remote {target} { [format {o target [s %s]} $target]] } +# Read the most recent DAP log file and check it for exceptions. +proc _dap_check_log_file {} { + global dap_gdb_instance + + set fd [open [standard_output_file "dap.log.$dap_gdb_instance"]] + set contents [read $fd] + close $fd + + set ok 1 + foreach line [split $contents "\n"] { + if {[regexp "^Traceback" $line]} { + set ok 0 + break + } + } + + if {$ok} { + pass "exceptions in log file" + } else { + fail "exceptions in log file" + } +} + # Cleanly shut down gdb. TERMINATE is passed as the terminateDebuggee # parameter to the request. proc dap_shutdown {{terminate false}} { dap_check_request_and_response "shutdown" disconnect \ [format {o terminateDebuggee [l %s]} $terminate] + _dap_check_log_file } # Search the event list EVENTS for an output event matching the regexp