From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 9E17F3858D32 for ; Tue, 13 Jun 2023 12:06:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E17F3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4f6170b1486so6619183e87.0 for ; Tue, 13 Jun 2023 05:06:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686658001; x=1689250001; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Cx7Otyq5+1ZFhhM5gJd8v7N5wlGF54/NzuozTjQVMIw=; b=o4oQ/EYV0F6+juhlRk6wTndFimhzdU20eJ6KbeI6fgZkIJeIY3QE02IzQleixV4U3p sdweMXbLMSYInyHcnaK/oJenO5Me1AguZjv/a4bx4RV2LVuS4vuXpt2sW+83rBfTxvgG +J4GeePu3qT3cqYIKK9XsD19VegQrt/HGZzkNkcR+A/K1a0K/wUeA0duDhNMhjd3lfnU ELH5OZ/7iRYuMwqWmqUqCuKBtjyBNd0GqbdJIZG5YW5wFcnXbRtKad1NZ7xzLxZwERuM 3OmZHdBRS4shGvHsn4ZTtfhC500JWCovUH+e+RSRN0wJLpB+GWQGW7TDtcAoMk3+qAJP CaXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686658001; x=1689250001; 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=Cx7Otyq5+1ZFhhM5gJd8v7N5wlGF54/NzuozTjQVMIw=; b=IeIlxnIdJLC6uOm4Bv9jKCzQuD1+106kP3WJ9W9MSytwfqpiqw1ZXAxxMZ9FBTER3u xzx3/7LrvEPJoipWImcyE3cttec4evjMvygosbvH8t9m5BCH5PFpc0H4aNvZ6tqm9ge1 MAe9T68CNVSWBBfqTYcq3uyQdBZro43RMeNq1GG00bfY6WSJkWP3BI4W/lr/qIH0mS+7 RfjLDm6SAH0cgMeWZpiv2pIEZj5gNMg+BQGFzZTl/4tkaQUa4oRCrMWr+cr3Np/sU9qt jojMf9UHeCT+4yZ7TTiWA0JkSlZAePQaK8vcsKzsQA0BnRmSphUS69QlW4MSdNTueb9u 5/BQ== X-Gm-Message-State: AC+VfDw/N8CLewNMdQuMZfPIXEthplarvAWF8loPoenTkYy8LSLLxhrC BWN7hmpmdcPhV7QLg8cq+X2zSyOFqslAdA== X-Google-Smtp-Source: ACHHUZ7HpAppl/SPS8LsIzpEJrcNQs2oK8sxIvEHEqS0yazi4LkxDt6ZmKIqUMNA/tUvruPqQvs/qQ== X-Received: by 2002:a05:6512:220a:b0:4f6:4466:7ebb with SMTP id h10-20020a056512220a00b004f644667ebbmr4196254lfu.20.1686658000509; Tue, 13 Jun 2023 05:06:40 -0700 (PDT) Received: from fedora.. (78-73-77-63-no2450.tbcn.telia.com. [78.73.77.63]) by smtp.gmail.com with ESMTPSA id w28-20020ac2599c000000b004f61a57797fsm1758010lfn.60.2023.06.13.05.06.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 05:06:40 -0700 (PDT) From: Simon Farre To: gdb-patches@sourceware.org Cc: Simon Farre Subject: [PATCH v2] gdb/dap - Add support for additional target types Date: Tue, 13 Jun 2023 14:06:28 +0200 Message-Id: <20230613120628.49014-1-simon.farre.cx@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.7 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,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 List-Id: v2. Forgot to add new file to Makefile Adds support for extended-remote configuration. Initial work was really just adding 2-3 lines that checked for extended-remote but I figured this design makes it trivial to add the remaining target types and this design also is self-documenting. For remaining types, add the type to target requirements and the required field(s) for it and in parse_target add branch for what result it should be parsed into. --- gdb/data-directory/Makefile.in | 1 + gdb/python/lib/gdb/dap/__init__.py | 1 + gdb/python/lib/gdb/dap/attach.py | 72 ++++++++++++++++++++++++++++++ gdb/python/lib/gdb/dap/launch.py | 20 +-------- 4 files changed, 75 insertions(+), 19 deletions(-) create mode 100644 gdb/python/lib/gdb/dap/attach.py diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in index a3775a4a666..0b204a93ff7 100644 --- a/gdb/data-directory/Makefile.in +++ b/gdb/data-directory/Makefile.in @@ -95,6 +95,7 @@ PYTHON_FILE_LIST = \ gdb/dap/frames.py \ gdb/dap/__init__.py \ gdb/dap/io.py \ + gdb/dap/attach.py \ gdb/dap/launch.py \ gdb/dap/locations.py \ gdb/dap/memory.py \ diff --git a/gdb/python/lib/gdb/dap/__init__.py b/gdb/python/lib/gdb/dap/__init__.py index f3dd3ff7ea8..9e8a8566e56 100644 --- a/gdb/python/lib/gdb/dap/__init__.py +++ b/gdb/python/lib/gdb/dap/__init__.py @@ -25,6 +25,7 @@ from . import bt from . import disassemble from . import evaluate from . import launch +from . import attach from . import locations from . import memory from . import next diff --git a/gdb/python/lib/gdb/dap/attach.py b/gdb/python/lib/gdb/dap/attach.py new file mode 100644 index 00000000000..6f36b4fbe3f --- /dev/null +++ b/gdb/python/lib/gdb/dap/attach.py @@ -0,0 +1,72 @@ +# Copyright 2023 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 . + +import gdb + +# These are deprecated in 3.9, but required in older versions. +from typing import Optional + +from .server import request +from .startup import send_gdb_with_response + + +# To add targets in the future: add required parameters set to their type +target_type_requirements = {} +target_type_requirements["remote"] = {"address"} +target_type_requirements["extended-remote"] = {"address"} + +def check_target_requirements(target: dict[str]): + global target_type_requirements + type = target.get("type") + if type is None or target_type_requirements.get(type) is None: + supported = list(target_type_requirements.keys()) + raise Exception("'type' field incorrect or missing. Supported types {}" + .format(supported)) + + # If requirements is a subset of target; all requirements met + if not (target_type_requirements[type] <= target.keys()): + missing = target_type_requirements[type] - target.keys() + raise Exception("Required fields missing: {}".format(list(missing))) + +def parse_target(target: dict[str]) -> str: + check_target_requirements(target) + type = target["type"] + if type == "extended-remote" or type == "remote": + addr = target["address"] + return "target {} {}".format(type, addr) + + # We should never reach this; check_target_requirements make sure of that. + raise gdb.GdbError("Attach configuration parsing failed") + +@request("attach") +def attach( + *, + pid: Optional[int] = None, + target: Optional[dict] = None, + **args +): + # Ensure configurationDone does not try to run (in launch.py) + global _program + _program = None + if pid is not None: + cmd = "attach " + str(pid) + elif target is not None: + cmd = parse_target(target) + else: + raise Exception("attach requires either 'pid' or 'target' fields") + # Use send_gdb_with_response to ensure we get an error if the + # attach fails. + send_gdb_with_response(cmd) + return None diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index c3c09bc3dd0..031bd2dcde5 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -20,12 +20,11 @@ from typing import Mapping, Optional, Sequence from .events import ExecutionInvoker from .server import request, capability -from .startup import send_gdb, send_gdb_with_response, in_gdb_thread, exec_and_log +from .startup import send_gdb, in_gdb_thread, exec_and_log _program = None - @in_gdb_thread def _set_args_env(args, env): inf = gdb.selected_inferior() @@ -66,23 +65,6 @@ def launch( send_gdb(lambda: _set_args_env(args, env)) -@request("attach") -def attach(*, pid: Optional[int] = None, target: Optional[str] = None, **args): - # Ensure configurationDone does not try to run. - global _program - _program = None - if pid is not None: - cmd = "attach " + str(pid) - elif target is not None: - cmd = "target remote " + target - else: - raise Exception("attach requires either 'pid' or 'target'") - # Use send_gdb_with_response to ensure we get an error if the - # attach fails. - send_gdb_with_response(cmd) - return None - - @capability("supportsConfigurationDoneRequest") @request("configurationDone") def config_done(**args): -- 2.40.1