]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Allow DAP client to set Ada source charset at launch
authorTom Tromey <tromey@adacore.com>
Wed, 3 Dec 2025 14:07:20 +0000 (07:07 -0700)
committerTom Tromey <tromey@adacore.com>
Fri, 9 Jan 2026 15:37:27 +0000 (08:37 -0700)
A co-worker reported that certain symbols weren't appearing in the DAP
'scopes' response.  In particular, symbols with non-ASCII names didn't
appear; though further research showed that this was in fact a result
of the variable in question actually being a constant.

Unfortunately Ada still requires the user to set the Ada source
character set in order to properly display symbol names.  For DAP, it
seemed to make sense to allow this as a launch parameter.  This patch
implements this.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
gdb/NEWS
gdb/doc/gdb.texinfo
gdb/python/lib/gdb/dap/launch.py
gdb/testsuite/gdb.dap/ada-non-ascii.exp [new file with mode: 0644]
gdb/testsuite/gdb.dap/ada-non-ascii/pack.adb [new file with mode: 0644]
gdb/testsuite/gdb.dap/ada-non-ascii/pack.ads [new file with mode: 0644]
gdb/testsuite/gdb.dap/ada-non-ascii/prog.adb [new file with mode: 0644]
gdb/testsuite/lib/dap-support.exp

index ded96539d72cb617a8ca9bc0326a596562f0c07b..9d3f2e97ed9f517f6fd5c53c1fd8fcc363868b96 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -97,6 +97,9 @@ New command class for help
   ** Unhandled Ada exceptions can now be caught using the "unhandled"
      exception filter.
 
+  ** The launch and attach requests now accept the adaSourceCharset
+     parameter.
+
 * Changed remote packets
 
 single-inf-arg in qSupported
index 164565c447a8fd862c8d70936756f4b5ddabd2d5..7059f73935cf6a97501ccae09bfa9883f0c82b30 100644 (file)
@@ -40205,6 +40205,10 @@ requests are defined by the adapter.  @value{GDBN} defines a couple
 parameters common to both:
 
 @table @code
+@item adaSourceCharset
+If provided, this is a string that is used to set the Ada source
+character set.  @xref{Ada Source Character Set}.
+
 @item program
 If provided, this is a string that specifies the program to use.  This
 corresponds to the @code{file} command.  @xref{Files}.
index 6867258b486a157f0680d3baa3a81e297446a92a..6fde3396ee994b28d09a61b2c59a6713022e2ac0 100644 (file)
@@ -80,12 +80,15 @@ def launch(
     env: Optional[Mapping[str, str]] = None,
     stopAtBeginningOfMainSubprogram: bool = False,
     stopOnEntry: bool = False,
+    adaSourceCharset: Optional[str] = None,
     **extra,
 ):
     # Launch setup is handled here.  This is done synchronously so
     # that errors can be reported in a natural way.
     @in_gdb_thread
     def _setup_launch():
+        if adaSourceCharset is not None:
+            exec_and_log("set ada source-charset " + adaSourceCharset)
         if cwd is not None:
             exec_and_log("cd " + cwd)
         if program is not None:
@@ -132,11 +135,14 @@ def attach(
     program: Optional[str] = None,
     pid: Optional[int] = None,
     target: Optional[str] = None,
+    adaSourceCharset: Optional[str] = None,
     **args,
 ):
     # The actual attach is handled by this function.
     @in_gdb_thread
     def _do_attach():
+        if adaSourceCharset is not None:
+            exec_and_log("set ada source-charset " + adaSourceCharset)
         if program is not None:
             file_command(program)
         if pid is not None:
diff --git a/gdb/testsuite/gdb.dap/ada-non-ascii.exp b/gdb/testsuite/gdb.dap/ada-non-ascii.exp
new file mode 100644 (file)
index 0000000..3145886
--- /dev/null
@@ -0,0 +1,100 @@
+# Copyright 2025 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_dap_tests
+require allow_ada_tests
+
+# Enable basic use of UTF-8.  LC_ALL gets reset for each testfile.
+setenv LC_ALL C.UTF-8
+
+standard_ada_testfile prog
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable \
+        {debug additional_flags=-gnatW8}] != ""} {
+    return
+}
+
+if {[dap_initialize] == ""} {
+    return
+}
+
+set launch_id [dap_launch $testfile ada_source_charset UTF-8]
+
+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 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 locals regs _ignore
+gdb_assert {[dict get $locals name] == "Locals"} "local scope"
+gdb_assert {[dict get $regs name] == "Registers"} "register scope"
+
+set num_vars [dict get $locals namedVariables]
+gdb_assert {$num_vars == 1} "correct number of locals"
+
+set num [dict get $locals variablesReference]
+set refs [lindex [dap_check_request_and_response "fetch variables" \
+                     "variables" \
+                     [format {o variablesReference [i %d] count [i %d]} \
+                          $num $num_vars]] \
+             0]
+
+foreach var [dict get $refs body variables] {
+    set name [dict get $var name]
+
+    # It doesn't matter what case is used for the variable name (GNAT
+    # upcases these Greek letters whereas it downcases Latin), and it
+    # doesn't matter if Python chooses to emit the character itself or
+    # a Unicode escape.  Therefore allow all of these.
+    switch -nocase -- $name {
+       "\\u03a0" -
+       "\\u03a6" -
+       "Π" -
+       "π" {
+           # Ok.
+       }
+       default {
+           fail "unknown variable $name"
+       }
+    }
+}
+
+dap_shutdown
diff --git a/gdb/testsuite/gdb.dap/ada-non-ascii/pack.adb b/gdb/testsuite/gdb.dap/ada-non-ascii/pack.adb
new file mode 100644 (file)
index 0000000..0604636
--- /dev/null
@@ -0,0 +1,23 @@
+--  Copyright 2025 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-non-ascii/pack.ads b/gdb/testsuite/gdb.dap/ada-non-ascii/pack.ads
new file mode 100644 (file)
index 0000000..170b6e5
--- /dev/null
@@ -0,0 +1,19 @@
+--  Copyright 2025 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-non-ascii/prog.adb b/gdb/testsuite/gdb.dap/ada-non-ascii/prog.adb
new file mode 100644 (file)
index 0000000..ec84453
--- /dev/null
@@ -0,0 +1,22 @@
+--  Copyright 2025 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 Prog is
+   π : Integer := 3;            --  The Indiana Approximation.
+begin
+   Do_Nothing (π'Address);      --  BREAK
+end Prog;
index 6e351c0e958a13026c0b208530c4b536eebd12f5..58b9452908a3b9c2756be1c13b5e944a1a4173c5 100644 (file)
@@ -302,6 +302,7 @@ proc dap_initialize {{name "initialize"} {extra ""}} {
 #   "stopAtBeginningOfMainSubprogram" will be passed to the launch
 #   request.
 # * cwd - value is the working directory to use.
+# * ada_source_charset - value is passed as adaSourceCharset
 #
 # After this proc is called, gdb will be ready to accept breakpoint
 # requests.
@@ -339,6 +340,10 @@ proc dap_launch {file {args {}}} {
                append envlist " cwd [format {[%s]} [list s $value]]"
            }
 
+           ada_source_charset {
+               append envlist " adaSourceCharset [format {[%s]} [list s $value]]"
+           }
+
            default {
                error "unrecognized parameter $key"
            }