Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] Add DAP completion test
Date: Thu,  3 Sep 2026 13:51:08 -0600	[thread overview]
Message-ID: <20260903195108.3974413-1-tromey@adacore.com> (raw)

This adds a test for the DAP completions request.

While working on this I found a couple of buglets in the DAP
completions implementation.  I've filed these in bugzilla.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34592
---
 gdb/testsuite/gdb.dap/completions.c   |  32 ++++++++
 gdb/testsuite/gdb.dap/completions.exp | 107 ++++++++++++++++++++++++++
 2 files changed, 139 insertions(+)
 create mode 100644 gdb/testsuite/gdb.dap/completions.c
 create mode 100644 gdb/testsuite/gdb.dap/completions.exp

diff --git a/gdb/testsuite/gdb.dap/completions.c b/gdb/testsuite/gdb.dap/completions.c
new file mode 100644
index 00000000000..858f087074f
--- /dev/null
+++ b/gdb/testsuite/gdb.dap/completions.c
@@ -0,0 +1,32 @@
+/* Copyright 2026 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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/>.  */
+
+int unique_enough_prefix_1 = 23;
+
+int unique_enough_prefix_2 = 91;
+
+int inner_func ()
+{
+  int unique_enough_prefix_4 = 19;
+  return unique_enough_prefix_4 - 19; /* BREAK */
+}
+
+int main ()
+{
+  int unique_enough_prefix_3 = 17;
+  return inner_func () + unique_enough_prefix_3 - 17;
+}
diff --git a/gdb/testsuite/gdb.dap/completions.exp b/gdb/testsuite/gdb.dap/completions.exp
new file mode 100644
index 00000000000..f79f9ba07a1
--- /dev/null
+++ b/gdb/testsuite/gdb.dap/completions.exp
@@ -0,0 +1,107 @@
+# Copyright 2026 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/>.
+
+# Test "completions" request.
+
+require allow_dap_tests
+
+load_lib dap-support.exp
+
+standard_testfile
+
+if {[build_executable ${testfile}.exp $testfile] == -1} {
+    return
+}
+
+if {[dap_initialize] == ""} {
+    return
+}
+
+set launch_id [dap_launch $testfile]
+
+set line [gdb_get_line_number "BREAK"]
+set obj [dap_check_request_and_response "set breakpoint by line number" \
+	     setBreakpoints \
+	     [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \
+		  [list s $srcfile] $line]]
+set line_bpno [dap_get_breakpoint_number $obj]
+
+dap_check_request_and_response "configurationDone" configurationDone
+
+dap_check_response "launch response" launch $launch_id
+
+dap_wait_for_event_and_check "inferior started" thread "body reason" started
+
+dap_wait_for_event_and_check "stopped at line breakpoint" stopped \
+    "body reason" breakpoint \
+    "body hitBreakpointIds" $line_bpno
+
+set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \
+		    {o threadId [i 1]}] \
+	    0]
+set inner_frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id]
+set outer_frame_id [dict get [lindex [dict get $bt body stackFrames] 1] id]
+
+set pfx "print unique_enough_prefix_"
+set col [string length $pfx]
+
+proc check_results {actual args} {
+    foreach item $actual suffix $args {
+	set value [dict get $item label]
+	gdb_assert {$value == [string cat $::pfx $suffix]} \
+	    "checking suffix $suffix"
+    }
+}
+
+set result [lindex [dap_check_request_and_response \
+			"completions in inner frame" completions \
+			[format {o frameId [i %s] text [s {%s}] column [i %s]} \
+			     $inner_frame_id $pfx $col]] \
+		0]
+
+with_test_prefix inner_frame {
+    check_results [dict get $result body targets] "" 1 2 4
+}
+
+set result [lindex [dap_check_request_and_response \
+			"completions in outer frame" completions \
+			[format {o frameId [i %s] text [s {%s}] column [i %s]} \
+			     $outer_frame_id $pfx $col]] \
+		0]
+
+with_test_prefix outer_frame {
+    # The empty string here is wrong.  gdb should not return the
+    # argument text.  See PR dap/34592.
+    check_results [dict get $result body targets] "" 1 2 3
+}
+
+set result [lindex [dap_check_request_and_response \
+			"completions without frame" completions \
+			[format {o text [s {%s}] column [i %s]} \
+			     $pfx $col]] \
+		0]
+
+with_test_prefix "no frame" {
+    # Note that the result '3' here is actually wrong.  gdb should
+    # ignore the selected frame.  See PR dap/34591.
+    check_results [dict get $result body targets] "" 1 2 3
+}
+
+# The result here isn't important, this is just checking that the
+# request doesn't fail.
+dap_check_request_and_response "completion of empty string" completions \
+    {o text [s {}] column [i 0]}
+
+dap_shutdown

base-commit: f09597461f2a1a9d88e5986a044abe7171c922e4
-- 
2.55.0


                 reply	other threads:[~2026-09-03 19:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260903195108.3974413-1-tromey@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