From patchwork Fri Feb 28 18:57:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: oltolm X-Patchwork-Id: 107241 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 84EBD3858D37 for ; Fri, 28 Feb 2025 18:59:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84EBD3858D37 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=IgA/8pa0 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id A63013858D26 for ; Fri, 28 Feb 2025 18:58:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A63013858D26 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 A63013858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::530 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1740769102; cv=none; b=F2QxnJPZeApuRsXo/na1sl8/DeTpgF5H9sP5rtGJlYISzZHVwg2lIFNIXnvyMqCu1+qhVEkMW1hTF/McrCU0epGPaiFWVNKpPWa/Cr5RSAP9WRDF8bwQzQodXhnao0rwdXOqwGJqJ5peDbaA8SuvGFnP3KifISGgWAI0NI6WrA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1740769102; c=relaxed/simple; bh=odWefJW3vUkQztdg8re1WDDxlog75zKuB9wKkH9lkE4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dKrsGrz4OHxkGPKtsGV6zT9DML1QZhEjAL6XPQbWngVvjFaVtLOuUF2IKabEaSbOYz0OQGBKc3/3D2CHGQROqk/DBZsO0HnqDgsGqDZmVjo49SzfOFLVL/dZ+nvGgtihjhPd/oBGvMpA1gc7FthvOd22WSwRe2Z68saKdOMMHfk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A63013858D26 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5e095d47a25so4167611a12.0 for ; Fri, 28 Feb 2025 10:58:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740769101; x=1741373901; 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=5qbNL7eAQpMugVDUsUfV8DP1iM05WI88JO8SkmGimRg=; b=IgA/8pa0Sfwwf3qpI2XYTKypV90N3lQYltUY4v9bnXTNCla1omF/XhcEpUdiPRszdv w3LzcubRULgq0TpnSRHOQGTddt8GsGOsDz4/jydmSUdliieUmtWP6Cky04N6nNScR+2e B3D6SgrHCZiPBy3AnjhZXezxEc21nR+jkC4BbQ3Mc4RWcwOLBIAjRqDpSIo6ergBdQm6 GCimRn223EWQ37KqXpB7G6Uh3oxymaB6TXjJPVK5NRNPkgrE8+qCtWN/EAY9N8YDC7hn UJw4DDi3r1UTq/V/BUblKXIWDhvR052ByHS5rR3lqdcBvXPVbPWx7IX+QC/65KUgUeSd 5tGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740769101; x=1741373901; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5qbNL7eAQpMugVDUsUfV8DP1iM05WI88JO8SkmGimRg=; b=VR6OfUedIHyoX5hlJnu3Jt4MCoie6PXmKOX0wcJK/+przEKanHGw1qWCxl7VT/ks3/ T5tcbmZ4P4wQobplVq7r0tyk82ubXLKknybCNaB1NwcFtfVRFP0GABms7NCSAYWWwzuj cVUBkhc1VLg/mp9JNsv8ufOYxTwWSCGaqrN2eQZJb28F5bmwivKGtexfDSnCtnMgbGVT nTjN7PlyB/qqGCdKsb62Z3udSTscLzSmXoyrqdEmv1N+iNAlRSM+0t5TAhP4MnfNBSFM QDCRHVjxudZKIoyElrDkPPV5VqjHpiYrR/grO0HMu1NSeTEAGAc1gZmnPbyYZg/MOiFj HATQ== X-Gm-Message-State: AOJu0YxOjqjdYq5fOwARF7CE9HmxkYHhCdWmDlEw9ns2X2pDEI5i8sC5 F6oUP86olurJpB/loH0P5hWADKYSy6eNw24zK4rceWGHGk6Vv8IDBSKrbdXs X-Gm-Gg: ASbGnctr9wZy+AVkzai0FLb4lnBqMj8KZy21R1ZXN0Ba15jE8Zejdmcs7pNdiJBz5Qi 9rNc/q+uzGE+eT915SzMp0vKjj3NwVODIdw2Ghyz4IBycw0q7fM8dI4r8cE/8fatOlQkQzzCj8t bh9TXVR4KVBv5SuTV3Ag8Bg4CWyh5LPkdtRA0ILcFUq/NYSEKg3/OTE5uVYPvsqdZw8szS09DkF OVwK1+GJxUgrBJsZVhG1uZOtCc+MeYCok8p7JmerEnJkqgj9ntRa6ZBeMxlTgKe3jW3mcrDXgWD +OejQdjulEu1YAPcDs1V4/sDrzIuGrosRnsOwDS7gpGC/28RT8jbjmXtM5zGiBiiXKfWCoF3EQH bSXQv6n/4OmyTh14IxTKX54OsK6xLpWhREZl/4a06 X-Google-Smtp-Source: AGHT+IEpB33hSC0ZcF6VekNwjkIDe2TJJt0HvT67OHOGMvPj0hqRd7tDmeJt04RSYUcaXc9ZYUoIdA== X-Received: by 2002:a17:906:d142:b0:abf:4701:2bf5 with SMTP id a640c23a62f3a-abf47013487mr134188166b.16.1740769100957; Fri, 28 Feb 2025 10:58:20 -0800 (PST) Received: from localhost.localdomain (p200300ed8f11d50030d7f5a86869f160.dip0.t-ipconnect.de. [2003:ed:8f11:d500:30d7:f5a8:6869:f160]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0dbc7dsm329434566b.39.2025.02.28.10.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 10:58:20 -0800 (PST) From: oltolm To: gdb-patches@sourceware.org Cc: oltolm , Simon Farre Subject: [PATCH v4] gdb/dap - Add CompletionsRequest Date: Fri, 28 Feb 2025 19:57:39 +0100 Message-ID: <20250228185751.673-2-oleg.tolmatcev@gmail.com> X-Mailer: git-send-email 2.48.1.windows.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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 Use GDB/MI command "-complete" to implement. Co-authored-by: Simon Farre Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31140 Reviewed-By: Eli Zaretskii --- gdb/NEWS | 4 ++ gdb/data-directory/Makefile.in | 1 + gdb/python/lib/gdb/dap/__init__.py | 1 + gdb/python/lib/gdb/dap/completions.py | 60 +++++++++++++++++++++++++++ gdb/python/lib/gdb/dap/server.py | 21 +++++++++- 5 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 gdb/python/lib/gdb/dap/completions.py diff --git a/gdb/NEWS b/gdb/NEWS index f5dbf5c335..b6c8241ea4 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -3,6 +3,10 @@ *** Changes since GDB 16 +* Debugger Adapter Protocol changes + + ** GDB now supports the "completions" request. + * "set style" commands now supports numeric format for basic colors from 0 to 255 and #RRGGBB format for TrueColor. diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in index 287dc7ff73..c08a68d16d 100644 --- a/gdb/data-directory/Makefile.in +++ b/gdb/data-directory/Makefile.in @@ -97,6 +97,7 @@ PYTHON_FILE_LIST = \ gdb/command/xmethods.py \ gdb/dap/breakpoint.py \ gdb/dap/bt.py \ + gdb/dap/completions.py \ gdb/dap/disassemble.py \ gdb/dap/evaluate.py \ gdb/dap/events.py \ diff --git a/gdb/python/lib/gdb/dap/__init__.py b/gdb/python/lib/gdb/dap/__init__.py index 145aeb611f..08ca33f5f6 100644 --- a/gdb/python/lib/gdb/dap/__init__.py +++ b/gdb/python/lib/gdb/dap/__init__.py @@ -26,6 +26,7 @@ from . import startup # server object. "F401" is the flake8 "imported but unused" code. from . import breakpoint # noqa: F401 from . import bt # noqa: F401 +from . import completions # noqa: F401 from . import disassemble # noqa: F401 from . import evaluate # noqa: F401 from . import launch # noqa: F401 diff --git a/gdb/python/lib/gdb/dap/completions.py b/gdb/python/lib/gdb/dap/completions.py new file mode 100644 index 0000000000..85acc43dc8 --- /dev/null +++ b/gdb/python/lib/gdb/dap/completions.py @@ -0,0 +1,60 @@ +# Copyright 2025 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from typing import Optional + +from .frames import select_frame +from .server import capability, import_column, import_line, request +from .startup import exec_mi_and_log + + +@request("completions") +@capability("supportsCompletionsRequest") +@capability("completionTriggerCharacters", [" ", "."]) +def completions( + *, + frameId: Optional[int] = None, + text: str, + column: int, + line: Optional[int] = None, + **extra, +): + if frameId is not None: + select_frame(frameId) + + column = import_column(column) + if line is None: + line = 1 + else: + line = import_line(line) + text = text.splitlines()[line - 1] + text = text[: column - 1] + 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)}) + # If `-complete' finds one match then `completion' and `matches' + # will contain the same one match. + if ( + completion is not None + and len(mi_result["matches"]) == 1 + and completion == mi_result["matches"][0] + ): + return {"targets": result} + for match in mi_result["matches"]: + result.append({"label": match, "length": len(match)}) + return {"targets": result} diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 8fdf0299d5..7139c798af 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -49,6 +49,7 @@ _server = None # This is set by the initialize request and is used when rewriting # line numbers. _lines_start_at_1 = False +_columns_start_at_1 = False class DeferredRequest: @@ -593,6 +594,8 @@ def initialize(**args): _server.send_event_later("initialized") global _lines_start_at_1 _lines_start_at_1 = client_bool_capability("linesStartAt1", True) + global _columns_start_at_1 + _columns_start_at_1 = client_bool_capability("columnsStartAt1", True) return _capabilities.copy() @@ -698,7 +701,7 @@ def send_gdb_with_response(fn): return val -def export_line(line): +def export_line(line: int) -> int: """Rewrite LINE according to client capability. This applies the linesStartAt1 capability as needed, when sending a line number from gdb to the client.""" @@ -710,7 +713,7 @@ def export_line(line): return line -def import_line(line): +def import_line(line: int) -> int: """Rewrite LINE according to client capability. This applies the linesStartAt1 capability as needed, when the client sends a line number to gdb.""" @@ -720,3 +723,17 @@ def import_line(line): # the client starts at 0. line = line + 1 return line + + +def export_column(column: int) -> int: + """Rewrite COLUMN according to client capability. + This applies the columnsStartAt1 capability as needed, + when sending a column number from gdb to the client.""" + return column if _columns_start_at_1 else column - 1 + + +def import_column(column: int) -> int: + """Rewrite COLUMN according to client capability. + This applies the columnsStartAt1 capability as needed, + when the client sends a column number to gdb.""" + return column if _columns_start_at_1 else column + 1