]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add DAP log level parameter
authorTom Tromey <tromey@adacore.com>
Tue, 12 Dec 2023 16:30:41 +0000 (09:30 -0700)
committerTom Tromey <tromey@adacore.com>
Fri, 22 Dec 2023 16:57:48 +0000 (09:57 -0700)
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 <eliz@gnu.org>
Reviewed-By: Kévin Le Gouguec <legouguec@adacore.com>
gdb/NEWS
gdb/doc/gdb.texinfo
gdb/python/lib/gdb/dap/breakpoint.py
gdb/python/lib/gdb/dap/server.py
gdb/python/lib/gdb/dap/startup.py

index 3c17d09203d8a6711cf2a7e6d76c0928454520b6..4358494a6b64666ea4d41632c476f7c7912f4ac0 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -90,6 +90,11 @@ show remote thread-options-packet
 
   ** The "attach" request now supports specifying the program.
 
+  ** 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
index 3cb7682cdb517f3f51c6da62e96c0a31bdfde53b..42a9123566187a1c1732e5a638e74921d23dfba0 100644 (file)
@@ -39644,6 +39644,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 @var{filename}.  If no
+@var{filename} 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
index c67bb471dafb0a4e2e3d5b4d9915e6ea6cc97383..6741420e7a39ae17bc990b16b144fc7d7d8f6348 100644 (file)
@@ -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, LogLevel, 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(LogLevel.FULL)
             # Maybe the breakpoint was made but setting an attribute
             # failed.  We still want this to fail.
             if bp is not None:
index 44dffb1b8093bfc025a0605f1824758331d9b54a..59fad59d8e656935f648a8f2d5465a1e6439f666 100644 (file)
@@ -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,
+    LogLevel,
 )
 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(LogLevel.FULL)
+            result["success"] = False
+            result["message"] = str(e)
         except BaseException as e:
             log_stack()
             result["success"] = False
index 64a46597bf46ffc2bcccb74bce222d3859139ec4..761b2928b40d132238021adbc9d7b7ed748d5e5e 100644 (file)
@@ -22,6 +22,7 @@ import threading
 import traceback
 import sys
 
+from enum import IntEnum, auto
 
 # Adapt to different Queue types.  This is exported for use in other
 # modules as well.
@@ -101,6 +102,28 @@ def in_dap_thread(func):
     return ensure_dap_thread
 
 
+# Logging levels.
+class LogLevel(IntEnum):
+    DEFAULT = auto()
+    FULL = auto()
+
+
+class LogLevelParam(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 = LogLevel.DEFAULT
+
+
+_log_level = LogLevelParam()
+
+
 class LoggingParam(gdb.Parameter):
     """Whether DAP logging is enabled."""
 
@@ -128,16 +151,16 @@ class LoggingParam(gdb.Parameter):
 dap_log = LoggingParam()
 
 
-def log(something):
+def log(something, level=LogLevel.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=LogLevel.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)