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)