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 253C03858D1E for ; Tue, 20 Jun 2023 08:16:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 253C03858D1E 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-4f8777caaa1so1352557e87.3 for ; Tue, 20 Jun 2023 01:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687248961; x=1689840961; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vtIOzBsZ7Ck1oQ9Z4x3061t7OaF9Bzc4qmrbxpwGtrI=; b=sMcflMfTyEfJJ1fNYnPTAdIt5ZGPHxlLw3qej4g4VRcXsGvDMvhnpZfzYHaXUjkzTr ZydQkAN8z9CPT2TXtjFBi+eTIQA8XvaUxXrMRXyjo7XxrfhokSNHO0Sbs20zqwrgKoBU /+xqrSx4VS1vTEPY0IBxX7tPy8mFjw18nLis4ulkYHVw29/9EBJnd4AiJhi6ZlLwabmy ZvEcm1bWu0fPsV1UjhnPu5R9EjYHRzL2RVkGzT3Gewx82a13zVYeZvrBaK2UqFEdznnq r1CzlwuwQD84Gc0ZOwoXbS/FHCr64lbB9/qP6P+fP9X1+poVNCvBnSpJovequ1R2PKEK nWeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687248961; x=1689840961; 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=vtIOzBsZ7Ck1oQ9Z4x3061t7OaF9Bzc4qmrbxpwGtrI=; b=h6blpbU60w81j7fADOHuia0D60FFSpZuBnFJFNMznkhglFnMU9jZg+X4fg4c4/60Bq KJFne/WKmC4MrUNv6awQZkswwJdMoo0RonCFrQW8M0DE4yZPGcLAxWiHyr9QQ4ovZmJX 2etlClOfR+ifvV2wvYHj3lmDF1gHAI1KlFHqkCmO3B4wgoHiXZN3q7k+UXCJLb9nd3Ut +CGvJcrClwXtCn9iQtRr5CPNFaDv6giizkQ09rv5XQ6DSxS3glbkqTuq4osVErZSoH9K M2hOpQ9+IMs2tjsluRtfSJT0Z3J59JC+Yq5qw/0BfnqyYmg0WomQ/HI9GMnPvWHXzpNl eh3Q== X-Gm-Message-State: AC+VfDzxfJJta420uDII6DDkC1fxaK29G3YLkP+lD0MjahbAb6swOhfl VHumqPQ9Oi45F/ULZS/kju6hxqF9ajmjrQ== X-Google-Smtp-Source: ACHHUZ6t6qsEFlX20+W7mHv3uHI5sJc8mcbB5mhYWUKV9492qXV+u6syib6pYfJqzJKZnylnei2hRg== X-Received: by 2002:a05:6512:340f:b0:4f5:1418:e230 with SMTP id i15-20020a056512340f00b004f51418e230mr7077578lfr.52.1687248960811; Tue, 20 Jun 2023 01:16:00 -0700 (PDT) Received: from fedora.. (78-73-77-63-no2450.tbcn.telia.com. [78.73.77.63]) by smtp.gmail.com with ESMTPSA id t27-20020ac2549b000000b004f60e0ecc78sm263569lfk.239.2023.06.20.01.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 01:16:00 -0700 (PDT) From: Simon Farre To: gdb-patches@sourceware.org Cc: tom@tromey.com, Simon Farre Subject: [PATCH] gdb/DAP Few bug fixes & Evaluate Array Watch vars Date: Tue, 20 Jun 2023 10:15:49 +0200 Message-Id: <20230620081549.202591-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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,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: This patch fixes a few bugs. First of all, name of VariableReferences must always be of string type. This patch makes sure that this is the case by formatting the name. If (when) the name is an integer, this will cause clients to fail or throw errors. Fixes a bug in NoOpArrayPrinter that calculated children to be N, but only ever retrieves N-1 children, which makes Python at some time later (during fetch_children -> fetch_one_child(N) ) raise an exception (out of list index) which makes the entire request go bad. The result[self.result_name] also f-strings the printer.to_string() value, because this can potentially be a LazyString (which is a Python object, not a string) and is not serializable by json.dumps. --- gdb/python/lib/gdb/dap/evaluate.py | 6 +++--- gdb/python/lib/gdb/dap/varref.py | 8 ++++++-- gdb/python/lib/gdb/printing.py | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gdb/python/lib/gdb/dap/evaluate.py b/gdb/python/lib/gdb/dap/evaluate.py index af7bf43afd0..382ba00877f 100644 --- a/gdb/python/lib/gdb/dap/evaluate.py +++ b/gdb/python/lib/gdb/dap/evaluate.py @@ -26,8 +26,8 @@ from .varref import find_variable, VariableReference class EvaluateResult(VariableReference): - def __init__(self, value): - super().__init__(None, value, "result") + def __init__(self, expr, value): + super().__init__(expr, value, "result") # Helper function to evaluate an expression in a certain frame. @@ -39,7 +39,7 @@ def _evaluate(expr, frame_id): frame.select() global_context = False val = gdb.parse_and_eval(expr, global_context=global_context) - ref = EvaluateResult(val) + ref = EvaluateResult(expr, val) return ref.to_object() diff --git a/gdb/python/lib/gdb/dap/varref.py b/gdb/python/lib/gdb/dap/varref.py index 23f18d647c3..9f6068b017e 100644 --- a/gdb/python/lib/gdb/dap/varref.py +++ b/gdb/python/lib/gdb/dap/varref.py @@ -66,7 +66,7 @@ class BaseReference: "variablesReference": self.ref, } if self.name is not None: - result["name"] = self.name + result["name"] = f"{self.name}" return result def no_children(self): @@ -152,7 +152,11 @@ class VariableReference(BaseReference): def to_object(self): result = super().to_object() - result[self.result_name] = self.printer.to_string() + # If we're a primitive, gdb.Value f-strings just fine + # We also must f-string printer.to_string() as it can be a LazyString + result[self.result_name] = ( + f"{self.value}" if self.ref == 0 else f"{self.printer.to_string()}" + ) num_children = self.child_count() if num_children is not None: if ( diff --git a/gdb/python/lib/gdb/printing.py b/gdb/python/lib/gdb/printing.py index ab62ef3e45c..353427d000a 100644 --- a/gdb/python/lib/gdb/printing.py +++ b/gdb/python/lib/gdb/printing.py @@ -298,7 +298,7 @@ class NoOpArrayPrinter: return "array" def children(self): - for i in range(self.low, self.high): + for i in range(self.low, self.high + 1): yield (i, self.value[i]) -- 2.40.1