aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/lib
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-12-12 09:30:41 -0700
committerTom Tromey <tromey@adacore.com>2023-12-22 09:57:48 -0700
commitdfc4bd461b46d62f9eea3adda571da01cb3d6605 (patch)
treead57c396d3f0c3006744bd17023d88f5f67bbc90 /gdb/python/lib
parent2a89c9508eac42395ff622492b2653e1b833cb9a (diff)
downloadbinutils-dfc4bd461b46d62f9eea3adda571da01cb3d6605.zip
binutils-dfc4bd461b46d62f9eea3adda571da01cb3d6605.tar.gz
binutils-dfc4bd461b46d62f9eea3adda571da01cb3d6605.tar.bz2
Add DAP log level parameter
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>
Diffstat (limited to 'gdb/python/lib')
-rw-r--r--gdb/python/lib/gdb/dap/breakpoint.py6
-rw-r--r--gdb/python/lib/gdb/dap/server.py10
-rw-r--r--gdb/python/lib/gdb/dap/startup.py31
3 files changed, 41 insertions, 6 deletions
diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py
index c67bb47..6741420 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, 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:
diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py
index 44dffb1..59fad59 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,
+ 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
diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py
index 64a4659..761b292 100644
--- a/gdb/python/lib/gdb/dap/startup.py
+++ b/gdb/python/lib/gdb/dap/startup.py
@@ -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)