From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 1F0A6385609B for ; Tue, 22 Aug 2023 15:25:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F0A6385609B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-34ca1aadcccso10186625ab.3 for ; Tue, 22 Aug 2023 08:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1692717915; x=1693322715; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=sHMqeqP0+JJmT/uChfyzcsblAxMQZdLTmWi9g11ANtE=; b=LkBQ/DG78AcUxYZSgBRRKFWVjP3HCBrQWe+Bm/0ViPGlsRy9R+VcLj7jv70rFYOMOb oPQYW/FxRVFQ3zu0qc7LT71CIMeFuWS5r0zlaRmoSfjhLl3rRmk9LS4Rvk1BKmo+X9Fk vx0ood2BKCSRPGscVWh06pPvCmNWrTYga5kjzixydlAa3FMpC/C7S2GKbhdAxtstGhn4 RovVfMFjbpYRfoqREP8Rj2shnMC93wEa4hfo187gXuYxTPzb/9nNzymJUuIP7tRAWeTa ZEggfQHbMeHRXL9gbBUrRpY1PvW3jCwZBD+gdNpArToqdFiZktk93Q1vO5gvE0Hw0BXr 0jqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692717915; x=1693322715; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sHMqeqP0+JJmT/uChfyzcsblAxMQZdLTmWi9g11ANtE=; b=Xm6Ok7j3wurKUTlRlNMyFytuGABJJvUJbucKlHlyhXHO/2sJl+n54VPj+FJoB/cq/1 YIF0JcilfCTC+p7ziikoQEyhk434h4w8gzSa6dYRRFa6hNbBL6GfhRQHz2Ql98cH0jKc gWk01PumVfxUuLCJe9KUQfKveEaS4bS+Kz2JMrlwaz4ETXiiqpinZV4+56X1679dF3Gh Yz8oKx8iZgAVGM0DkG8DYx//7h3Vf+rR8Shzx7OwYq97gef2OzehR8ShbR0LWGaeKgAo DzPF5KmXuHIv5FDLFGTBUE43EAIA3WiOUIRg3M/tamtLsgYiBhr3wG26fFGAEKpbyIGJ MMbA== X-Gm-Message-State: AOJu0Yw0RAT4GbQE3TOx9aSrYU7j8RtSBxaXpdiRltRlaaDOHaGenl7f IHk7S//3JBKlDgTawQSilO7cIUveNbebZm23RcCLdQ== X-Google-Smtp-Source: AGHT+IEbyAvDPuMZ+iTjemcoUb58V72QLCn1F3tmQ/Q9hUYsbOuQda1AG6yLWgZquiQm2QHykQ1Yrw== X-Received: by 2002:a05:6e02:666:b0:349:3ca:bd1d with SMTP id l6-20020a056e02066600b0034903cabd1dmr12167766ilt.25.1692717915325; Tue, 22 Aug 2023 08:25:15 -0700 (PDT) Received: from localhost.localdomain (75-166-142-177.hlrn.qwest.net. [75.166.142.177]) by smtp.gmail.com with ESMTPSA id e8-20020a92de48000000b003460b8505easm1721608ilr.19.2023.08.22.08.25.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 08:25:14 -0700 (PDT) From: Tom Tromey Date: Tue, 22 Aug 2023 09:25:12 -0600 Subject: [PATCH 6/8] Select frame when fetching a frame variable in DAP MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230822-array-and-string-like-v1-6-2dcea29b0567@adacore.com> References: <20230822-array-and-string-like-v1-0-2dcea29b0567@adacore.com> In-Reply-To: <20230822-array-and-string-like-v1-0-2dcea29b0567@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 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 List-Id: Right now, if a program uses multiple languages, DAP value formatting will always use the language of the innermost frame. However, it is better to use the variable's defining frame instead. This patch does this by selecting the frame first. This also fixes a possibly latent bug in the "stepOut" command -- "finish" is sensitive to the selected frame, but the DAP code may already select other frames when convenient. The DAP stepOut request only works on the newest frame, so be sure to select it before invoking "finish". --- gdb/python/lib/gdb/dap/next.py | 11 ++++++++--- gdb/python/lib/gdb/dap/scopes.py | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py index 8b112770a0c..5046963cb81 100644 --- a/gdb/python/lib/gdb/dap/next.py +++ b/gdb/python/lib/gdb/dap/next.py @@ -23,9 +23,10 @@ from .state import set_thread # Helper function to set the current thread and the scheduler-locking # mode. Returns True if scheduler-locking was successfully set to -# 'on', False in all other cases, including error. +# 'on', False in all other cases, including error. When SELECT is +# True, also select that thread's newest frame. @in_gdb_thread -def _handle_thread_step(thread_id, single_thread): +def _handle_thread_step(thread_id, single_thread, select=False): # Ensure we're going to step the correct thread. set_thread(thread_id) if single_thread: @@ -41,6 +42,10 @@ def _handle_thread_step(thread_id, single_thread): gdb.execute("set scheduler-locking " + arg, from_tty=True, to_string=True) except gdb.error: result = False + # Other DAP code may select a frame, and the "finish" command uses + # the selected frame. + if select: + gdb.newest_frame().select() return result @@ -70,7 +75,7 @@ def step_in( @request("stepOut") def step_out(*, threadId: int, singleThread: bool = False): - send_gdb(lambda: _handle_thread_step(threadId, singleThread)) + send_gdb(lambda: _handle_thread_step(threadId, singleThread, True)) send_gdb(ExecutionInvoker("finish", StopKinds.STEP)) diff --git a/gdb/python/lib/gdb/dap/scopes.py b/gdb/python/lib/gdb/dap/scopes.py index 1687094c4ce..4874d001216 100644 --- a/gdb/python/lib/gdb/dap/scopes.py +++ b/gdb/python/lib/gdb/dap/scopes.py @@ -49,6 +49,10 @@ class _ScopeReference(BaseReference): @in_gdb_thread def fetch_one_child(self, idx): + # Make sure to select the frame first. Ideally this would not + # be needed, but this is a way to set the current language + # properly so that language-dependent APIs will work. + self.inf_frame.select() # Here SYM will conform to the SymValueWrapper interface. sym = self.var_list[idx] name = str(sym.symbol()) -- 2.40.1