From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 7/7] Add Ada scope test for DAP
Date: Thu, 22 Jun 2023 10:19:33 -0600 [thread overview]
Message-ID: <20230614-dap-frame-decor-v2-7-10628dfa6b60@adacore.com> (raw)
In-Reply-To: <20230614-dap-frame-decor-v2-0-10628dfa6b60@adacore.com>
This adds a DAP test for fetching scopes and variables with an Ada
program. This test is the reason that the FrameVars code does not
check is_constant on the symbols it returns.
Note that this test also shows that string-printing is incorrect in
Ada. This is a known bug but I'm still considering how to fix it.
---
gdb/testsuite/gdb.dap/ada-scopes.exp | 84 +++++++++++++++++++++++++++++++
gdb/testsuite/gdb.dap/ada-scopes/pack.adb | 23 +++++++++
gdb/testsuite/gdb.dap/ada-scopes/pack.ads | 21 ++++++++
gdb/testsuite/gdb.dap/ada-scopes/prog.adb | 26 ++++++++++
4 files changed, 154 insertions(+)
diff --git a/gdb/testsuite/gdb.dap/ada-scopes.exp b/gdb/testsuite/gdb.dap/ada-scopes.exp
new file mode 100644
index 00000000000..75d51f96ab4
--- /dev/null
+++ b/gdb/testsuite/gdb.dap/ada-scopes.exp
@@ -0,0 +1,84 @@
+# 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 <http://www.gnu.org/licenses/>.
+
+load_lib ada.exp
+load_lib dap-support.exp
+
+require allow_ada_tests allow_dap_tests
+
+standard_ada_testfile prog
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable \
+ {debug additional_flags=-gnata}] != ""} {
+ return -1
+}
+
+if {[dap_launch $binfile] == ""} {
+ return
+}
+
+set line [gdb_get_line_number "STOP"]
+set obj [dap_check_request_and_response "set breakpoint" \
+ setBreakpoints \
+ [format {o source [o path [%s]] \
+ breakpoints [a [o line [i %d]]]} \
+ [list s $srcfile] $line]]
+set fn_bpno [dap_get_breakpoint_number $obj]
+
+dap_check_request_and_response "start inferior" configurationDone
+
+dap_wait_for_event_and_check "stopped at breakpoint" stopped \
+ "body reason" breakpoint \
+ "body hitBreakpointIds" $fn_bpno
+
+set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \
+ {o threadId [i 1]}] \
+ 0]
+set frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id]
+
+set scopes [dap_check_request_and_response "get scopes" scopes \
+ [format {o frameId [i %d]} $frame_id]]
+set scopes [dict get [lindex $scopes 0] body scopes]
+
+# This is what the implementation does, so we can assume it, but check
+# just in case something changes.
+lassign $scopes scope _ignore
+gdb_assert {[dict get $scope name] == "Locals"} "scope is locals"
+
+gdb_assert {[dict get $scope namedVariables] == 2} "two vars in scope"
+
+set num [dict get $scope variablesReference]
+set refs [lindex [dap_check_request_and_response "fetch variables" \
+ "variables" \
+ [format {o variablesReference [i %d] count [i 2]} \
+ $num]] \
+ 0]
+
+foreach var [dict get $refs body variables] {
+ set name [dict get $var name]
+
+ switch $name {
+ "value" {
+ gdb_assert {[dict get $var value] == "three"} "check value of value"
+ }
+ "my_string" {
+ }
+ default {
+ fail "unknown variable $name"
+ }
+ }
+}
+
+dap_shutdown
diff --git a/gdb/testsuite/gdb.dap/ada-scopes/pack.adb b/gdb/testsuite/gdb.dap/ada-scopes/pack.adb
new file mode 100644
index 00000000000..a97a8293b0e
--- /dev/null
+++ b/gdb/testsuite/gdb.dap/ada-scopes/pack.adb
@@ -0,0 +1,23 @@
+-- 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 <http://www.gnu.org/licenses/>.
+
+package body Pack is
+
+ procedure Do_Nothing (A : System.Address) is
+ begin
+ null;
+ end Do_Nothing;
+
+end Pack;
diff --git a/gdb/testsuite/gdb.dap/ada-scopes/pack.ads b/gdb/testsuite/gdb.dap/ada-scopes/pack.ads
new file mode 100644
index 00000000000..3a6721d62d2
--- /dev/null
+++ b/gdb/testsuite/gdb.dap/ada-scopes/pack.ads
@@ -0,0 +1,21 @@
+-- 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 <http://www.gnu.org/licenses/>.
+
+with System;
+package Pack is
+
+ procedure Do_Nothing (A : System.Address);
+
+end Pack;
diff --git a/gdb/testsuite/gdb.dap/ada-scopes/prog.adb b/gdb/testsuite/gdb.dap/ada-scopes/prog.adb
new file mode 100644
index 00000000000..5f6ccd5ee66
--- /dev/null
+++ b/gdb/testsuite/gdb.dap/ada-scopes/prog.adb
@@ -0,0 +1,26 @@
+-- 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 <http://www.gnu.org/licenses/>.
+
+with Pack; use Pack;
+
+procedure Foo is
+ type Enum_Type is (one, two, three);
+ Value : Enum_Type := three;
+
+ My_String : constant String := "Hello World";
+begin
+ Do_Nothing (Value'address);
+ Do_Nothing (My_String'address); -- STOP
+end Foo;
--
2.40.1
next prev parent reply other threads:[~2023-06-22 16:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-22 16:19 [PATCH v2 0/7] Reimplement DAP backtrace using frame filters Tom Tromey
2023-06-22 16:19 ` [PATCH v2 1/7] Fix execute_frame_filters doc string Tom Tromey
2023-06-22 16:19 ` [PATCH v2 2/7] Add new interface to frame filter iteration Tom Tromey
2023-06-22 16:19 ` [PATCH v2 3/7] Fix oversights in frame decorator code Tom Tromey
2023-06-22 16:19 ` [PATCH v2 4/7] Simplify FrameVars Tom Tromey
2023-06-26 15:02 ` Tom Tromey
2023-06-22 16:19 ` [PATCH v2 5/7] Reimplement DAP stack traces using frame filters Tom Tromey
2023-06-22 16:19 ` [PATCH v2 6/7] Handle typedefs in no-op pretty printers Tom Tromey
2023-06-22 16:19 ` Tom Tromey [this message]
2023-06-26 15:07 ` [PATCH v2 0/7] Reimplement DAP backtrace using frame filters Tom Tromey
2023-07-10 19:14 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230614-dap-frame-decor-v2-7-10628dfa6b60@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).