From: Tom Tromey Date: Wed, 3 Dec 2025 14:07:20 +0000 (-0700) Subject: Allow DAP client to set Ada source charset at launch X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=793593eb34eaf5b26eb4d6d79b31d26c418f3d7c;p=thirdparty%2Fbinutils-gdb.git Allow DAP client to set Ada source charset at launch 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 --- diff --git a/gdb/NEWS b/gdb/NEWS index ded96539d72..9d3f2e97ed9 100644 --- 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 diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 164565c447a..7059f73935c 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -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}. diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index 6867258b486..6fde3396ee9 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -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 index 00000000000..31458863337 --- /dev/null +++ b/gdb/testsuite/gdb.dap/ada-non-ascii.exp @@ -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 . + +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 index 00000000000..060463689d4 --- /dev/null +++ b/gdb/testsuite/gdb.dap/ada-non-ascii/pack.adb @@ -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 . + +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 index 00000000000..170b6e563aa --- /dev/null +++ b/gdb/testsuite/gdb.dap/ada-non-ascii/pack.ads @@ -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 . + +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 index 00000000000..ec844539b1a --- /dev/null +++ b/gdb/testsuite/gdb.dap/ada-non-ascii/prog.adb @@ -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 . + +with Pack; use Pack; + +procedure Prog is + π : Integer := 3; -- The Indiana Approximation. +begin + Do_Nothing (π'Address); -- BREAK +end Prog; diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp index 6e351c0e958..58b9452908a 100644 --- a/gdb/testsuite/lib/dap-support.exp +++ b/gdb/testsuite/lib/dap-support.exp @@ -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" }