From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id NGzGJGzfGWkHOwkAWB0awg (envelope-from ) for ; Sun, 16 Nov 2025 09:27:56 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=AVduCrYY; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 835371E048; Sun, 16 Nov 2025 09:27:56 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A2C2D1E048 for ; Sun, 16 Nov 2025 09:27:55 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 21C783858D21 for ; Sun, 16 Nov 2025 14:27:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 21C783858D21 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=AVduCrYY Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 8E3D23858D21 for ; Sun, 16 Nov 2025 14:27:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E3D23858D21 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8E3D23858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::329 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763303238; cv=none; b=FfskwFrDp4YVb/1Cw4hPsRPP5EHzACGS14d0KpuPlc9pxAr7alipkKJmoChTmekXJ6nmvbEaHO/vnGWMKs23Kzq10Ne2fzpjinHo4X/fqvxLFluM5g3RD5ifij9mnWsyvbuumeTWGZu3IknEyf873RoihzkPRWIAbucNLRsu0J8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763303238; c=relaxed/simple; bh=LYG/hZkrJvUX362yDMT9ckmkFzFwKQIv/IhNlPbbI44=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=m5X4OAeXBXWOrIx9BX30aSQVN6ma9zJRbIFtsyC2Cf8gvxqIE4myA9A6qfUdc4nNK8VwxVK3s9OzS0+ZYtW55fJKbs1c10QzQOKBnbS2AYXogJ6xmwDdR4/mIfEqKXNmQBQkb8adshJedJEj6jYysyEZ2g8wGt/UA4XNVGwBI38= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E3D23858D21 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4779cc419b2so9171675e9.3 for ; Sun, 16 Nov 2025 06:27:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763303237; x=1763908037; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tKf2HULR7aFbMruPfOKj7QebdJza8hqW3IiltjvS0XE=; b=AVduCrYYBXXhT7bcgj2vgs7VjYamsc3BXVtH23lIPqsfNh2DO2KQO+xdR+Xi+/ArIE ZmN8x8/QC7Xn9qCERpGVBls0flettSN3DBfukYSCBgW2y3rMNcCdVI2xXxD40dacejAN KLRE43CwT5wM9TMm6yO/eVcC8X9B2NVS0aDQwjr5Re66W4n7PP9xqJwHOpCAbY086XV+ bnUKnKvv1nzx4pIyb+03mXcjjd9JK7j22H83NylQ8yIpzuxKuZF5bzR7bXeUa3FwFCit aZVI9pkyM9yDaiaEQjGlajZ7k+f9WnI2C3kBmYpZXwdmE02bFb2H0qANYZMb9Qz9Onnd t6LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763303237; x=1763908037; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tKf2HULR7aFbMruPfOKj7QebdJza8hqW3IiltjvS0XE=; b=BG8x+ibfoKh9mjpqgwBHzSSU/TV6RFrvahxMS7TKHrLXnxnZeWhooMv9ZY7kN/UMLm 48uaVWIMg5xyEFMzW3hvjVGXixvnj9z9Z+pEr3TiEMFlI2mJCJo0C8ixal0HixWEiy8N 7O1iT748BEbFlNci83ouTGfO22j9CQqV4tjN9GN4Y4F3HtKnbmWKZ8i1NpBP9/hLB5Gq N52RuH+8UKd1cVNoVDCy8XRSBobYdCjgmBClxCMkg2yP+hg1i1VZNZtTgd/Aux5FeA1n huxs1lyL7+Ol+8vpVvoDxzi1KeUVD7XMPZpOEDYdhmw4Pf3bh4dKxlOPZ35jnf6wkZqa wOLw== X-Gm-Message-State: AOJu0Ywfdwpb9Y/cwnw6iqHvyOoB2ryfcdY2R09IAxRXBRgoUgXV32Ue tkIJxIhqKj4FOmsNvKbNb/VBYYi/l/YJPzTEEEEBBZKMUNb4+1WFjKlqvN9JJw== X-Gm-Gg: ASbGncst3CIUoru3tVKT0aWNv0hPchWSGpIk1mgQX7OIt2P/ZQS1PvoRbLf3QLOiwpw lC2k9bHTmRv6HeCLfTioA4YqrpPKhhqwjR4CGN47sG//E5zRslIhOOnvP3Oh8RzpKAjOU144tVn JG6H5/ETuOEEZ7EgOSKyhC9CjVFaRyXgTjg2cnjZohwIIMIldgbB+FMnPFnHr+PDjX3pqZw4WMQ Kl8La4lHFRvIGuoKC14UsAaZdl13RwcLBWn/knEPD9y+YFDC00k8m6qcT2CSjoTDLe+FnHc1vfD S4WzOa0KOMDcEnZFaIz73FUVdJezhtHan0c5FCSy+fVIKh3ZexfX2h2reSZO36NLTjTfXLIiDRW a99Pu37dZNOCK/KOAKw8Jt/U8tr+o4TA1OVBigl/AYBMieW8ldmiK7hMdK6UVkCSUnLGirxOwLU VrGLDqL89lXim2euNXgP511YVww86z2Tx2ygJfowU8WhXDLQNKK0Jzhq1272Bb0terXqo/49OTS /pAEj5Do5U4dy/iymdvSL4= X-Google-Smtp-Source: AGHT+IEIBzDkwaivMTj+T6v4M3nU5PgfgMPiMGAG47T9cDwrfb7q5+LlUIPreLm7ejA/HCfYY3L08A== X-Received: by 2002:a05:6000:2504:b0:429:b8f9:a887 with SMTP id ffacd0b85a97d-42b5935e272mr7761660f8f.6.1763303236860; Sun, 16 Nov 2025 06:27:16 -0800 (PST) Received: from B450M-PRO-VDH-MAX (p200300ed8f1cb70068203b86cf7ef818.dip0.t-ipconnect.de. [2003:ed:8f1c:b700:6820:3b86:cf7e:f818]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53e7ae5bsm21008458f8f.8.2025.11.16.06.27.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Nov 2025 06:27:16 -0800 (PST) From: oltolm To: gdb-patches@sourceware.org Cc: oltolm Subject: [PATCH v4] gdb/dap: add option commandEscapePrefix Date: Sun, 16 Nov 2025 15:26:14 +0100 Message-ID: <20251116142613.1736-2-oleg.tolmatcev@gmail.com> X-Mailer: git-send-email 2.51.2.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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~public-inbox=simark.ca@sourceware.org The escape prefix to use for executing regular GDB commands in the Debug Console, instead of printing variables. Defaults to an empty string. If it's an empty string, then all expressions in the Debug Console are treated as regular GDB commands. Signed-off-by: oltolm --- gdb/doc/gdb.texinfo | 6 ++++++ gdb/python/lib/gdb/dap/completions.py | 15 ++++++++++++--- gdb/python/lib/gdb/dap/evaluate.py | 15 ++++++++++++--- gdb/python/lib/gdb/dap/launch.py | 5 +++++ gdb/python/lib/gdb/dap/server.py | 14 ++++++++++++++ 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index b52fd7f880d..bad8eede578 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -40155,6 +40155,12 @@ the same approach as the @code{start} command. @xref{Starting}. If provided, this must be a boolean. When @samp{True}, @value{GDBN} will set a temporary breakpoint at the program's first instruction, using the same approach as the @code{starti} command. @xref{Starting}. + +@item commandEscapePrefix +The escape prefix to use for executing regular @value{GDBN} commands in the +Debug Console, instead of printing variables. Defaults to an empty string. If it's +an empty string, then all expressions in the Debug Console are treated as +regular @value{GDBN} commands. @end table @value{GDBN} defines some parameters that can be passed to the diff --git a/gdb/python/lib/gdb/dap/completions.py b/gdb/python/lib/gdb/dap/completions.py index e5003fff96d..a9c4d12bbdb 100644 --- a/gdb/python/lib/gdb/dap/completions.py +++ b/gdb/python/lib/gdb/dap/completions.py @@ -16,7 +16,13 @@ from typing import Optional from .frames import select_frame -from .server import capability, import_column, import_line, request +from .server import ( + capability, + get_command_escape_prefix, + import_column, + import_line, + request, +) from .startup import exec_mi_and_log @@ -44,12 +50,15 @@ def completions( text = text[: column - 1] else: text = "" + if not text.startswith(get_command_escape_prefix()): + return {"targets": []} + text = text[len(get_command_escape_prefix()):] mi_result = exec_mi_and_log("-complete", text) result = [] completion = None if "completion" in mi_result: completion = mi_result["completion"] - result.append({"label": completion, "length": len(completion)}) + result.append({"label": get_command_escape_prefix() + completion, "length": len(completion)}) # If `-complete' finds one match then `completion' and `matches' # will contain the same one match. if ( @@ -59,5 +68,5 @@ def completions( ): return {"targets": result} for match in mi_result["matches"]: - result.append({"label": match, "length": len(match)}) + result.append({"label": get_command_escape_prefix() + match, "length": len(match)}) return {"targets": result} diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index fcbcc99acfc..985cad88db7 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -19,7 +19,12 @@ from typing import Optional import gdb from .frames import select_frame -from .server import capability, client_bool_capability, request +from .server import ( + capability, + client_bool_capability, + get_command_escape_prefix, + request, +) from .startup import DAPException, in_gdb_thread, parse_and_eval from .varref import VariableReference, apply_format, find_variable @@ -86,8 +91,12 @@ def eval_request( elif context == "hover": return _eval_for_hover(expression, frameId, format) elif context == "repl": - # Ignore the format for repl evaluation. - return _repl(expression, frameId) + if expression.startswith(get_command_escape_prefix()): + expression = expression[len(get_command_escape_prefix()):] + # Ignore the format for repl evaluation. + return _repl(expression, frameId) + else: + return _evaluate(expression, frameId, format) else: raise DAPException('unknown evaluate context "' + context + '"') diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index 8ac4c7750c6..00676c3d75c 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -28,6 +28,7 @@ from .server import ( request, send_gdb, send_gdb_with_response, + set_command_escape_prefix, ) from .startup import DAPException, exec_and_log, in_dap_thread, in_gdb_thread @@ -80,6 +81,7 @@ def launch( env: Optional[Mapping[str, str]] = None, stopAtBeginningOfMainSubprogram: bool = False, stopOnEntry: bool = False, + commandEscapePrefix: str = "", **extra, ): # Launch setup is handled here. This is done synchronously so @@ -123,6 +125,7 @@ def launch( # The launch itself is deferred until the configurationDone # request. + set_command_escape_prefix(commandEscapePrefix) return _LaunchOrAttachDeferredRequest(_launch_impl) @@ -132,6 +135,7 @@ def attach( program: Optional[str] = None, pid: Optional[int] = None, target: Optional[str] = None, + commandEscapePrefix: str = "", **args, ): # The actual attach is handled by this function. @@ -157,6 +161,7 @@ def attach( # The attach itself is deferred until the configurationDone # request. + set_command_escape_prefix(commandEscapePrefix) return _LaunchOrAttachDeferredRequest(_attach_impl) diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 98a80842633..b983a0a38d0 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -51,6 +51,20 @@ _server = None _lines_start_at_1 = False _columns_start_at_1 = False +# The escape prefix to use for executing regular GDB commands in the +# Debug Console. +_command_escape_prefix: str = "" + +def get_command_escape_prefix() -> str: + """Return the command escape prefix. + """ + return _command_escape_prefix + +def set_command_escape_prefix(command_escape_prefix: str) -> None: + """Set the command escape prefix to COMMAND_ESCAPE_PREFIX. + """ + global _command_escape_prefix + _command_escape_prefix = command_escape_prefix class DeferredRequest: """If a DAP request function returns a deferred request, no -- 2.51.2.windows.1