From patchwork Mon Mar 6 16:00:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66038 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 2FACF385B526 for ; Mon, 6 Mar 2023 16:00:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2FACF385B526 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678118440; bh=TCXEDRKmo/LAjEropBvl2PofAc6YTl6g/5zijcm+Z2g=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=x8O+HQvJx+bwRTZL47r5gN9Ay4mu1uVEBZ+WELIeirP4pmR5WBnwwd994PiV1Pog4 scP7IiTH8i6mjsepuzGS2QRfY0PE/qzeYJltxsngsoAzeAjG9HkrSd2LSJ9kqSfx+Y bn0zCSa00quuYoo28HZWo0Q4sxNEeZjX+tmUVoGQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id BFC52385703F for ; Mon, 6 Mar 2023 16:00:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BFC52385703F Received: by mail-il1-x131.google.com with SMTP id i4so6600017ils.1 for ; Mon, 06 Mar 2023 08:00:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678118414; 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=TCXEDRKmo/LAjEropBvl2PofAc6YTl6g/5zijcm+Z2g=; b=TjiOHp4xLYEviynk1gqw6uvJLxsCax6Pszz0ib3Lueufd9Bmo3G1rIFA37AM5w8/0i 9FOvpApYajxZ7+8QkCnceL4jWtYwizixOeF/YgTrgMfCbJblo2PsGkM+CYU3OKaO+JpY bwwtozGIRIMxSmlcq0FG7WjSbmOErhEEjbp6xPF3t7q+Qg/U3c0y5PXFmU3M4E5EBCbg TpbnFjigqgXW/iZO8jbw5ttgL8Ihb6rxmVZgdyMs96GLByzK/SBn1NiML50QUckDZUCr xN+u7ROxdNi7xI9mfAwEIaM2/NDrOLT/XLhMYM/lv8CowjK04+/NViXvTzkr7m2NAiTn Qjag== X-Gm-Message-State: AO0yUKUVRXvsuA1IpAO/FkEml1tCjCFJILAXLAJoStwlD2Sa5d4dIZf6 lYtFrfWDgIj5EeUt+FwnTw0Z7TpM3aW1Y6gboX4= X-Google-Smtp-Source: AK7set9DaPwKPC/w25h/sD9q0UCr3Rls9nQv1Dsbp+Gbz3uKwTN/pjFprsfJJrh5wPqJDKXco/eXSg== X-Received: by 2002:a05:6e02:156d:b0:316:f99d:927c with SMTP id k13-20020a056e02156d00b00316f99d927cmr9563181ilu.10.1678118413986; Mon, 06 Mar 2023 08:00:13 -0800 (PST) Received: from localhost.localdomain (75-166-130-93.hlrn.qwest.net. [75.166.130.93]) by smtp.gmail.com with ESMTPSA id t8-20020a92dc08000000b00313b08feec7sm2909375iln.42.2023.03.06.08.00.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Mar 2023 08:00:13 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Implement repl evaluation for DAP Date: Mon, 6 Mar 2023 09:00:05 -0700 Message-Id: <20230306160005.1301114-1-tromey@adacore.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The evaluate command supports a "context" parameter which tells the adapter the context in which an evaluation occurs. One of the supported values is "repl", which we took to mean evaluation of a gdb command. That is what this patch implements. Note that some gdb commands probably will not work correctly with the rest of the protocol. For example if the user types "continue", confusion may result. This patch requires the earlier patch to fix up scopes in DAP. --- gdb/python/lib/gdb/dap/evaluate.py | 24 +++++++++++++++++++++--- gdb/testsuite/gdb.dap/basic-dap.exp | 5 +++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index d04ac169a8e..55d41b0806d 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -38,12 +38,30 @@ def _evaluate(expr, frame_id): return ref.to_object() +# Helper function to evaluate a gdb command in a certain frame. +@in_gdb_thread +def _repl(command, frame_id): + if frame_id is not None: + frame = frame_for_id(frame_id) + frame.select() + val = gdb.execute(command, from_tty=True, to_string=True) + return { + "result": val, + "variablesReference": 0, + } + + # FIXME 'format' & hex # FIXME supportsVariableType handling -# FIXME "repl" @request("evaluate") -def eval_request(*, expression, frameId=None, **args): - return send_gdb_with_response(lambda: _evaluate(expression, frameId)) +def eval_request(*, expression, frameId=None, context="variables", **args): + if context in ("watch", "variables"): + # These seem to be expression-like. + return send_gdb_with_response(lambda: _evaluate(expression, frameId)) + elif context == "repl": + return send_gdb_with_response(lambda: _repl(expression, frameId)) + else: + raise Exception(f'unknown evaluate context "{context}"') @in_gdb_thread diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp index 6f14df5df01..5e6e1b5d6d4 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -163,4 +163,9 @@ set obj [dap_check_request_and_response "disassemble one instruction" \ set response [lindex $obj 0] gdb_assert { [dict exists $response body instructions] } "instructions in disassemble output" +set obj [dap_check_request_and_response "command repl" \ + evaluate {o expression [s {output 23}] context [s repl]}] +set response [lindex $obj 0] +gdb_assert {[dict get $response body result] == 23} + dap_shutdown