1 # Copyright 2023-2024 Free Software Foundation, Inc. 2 3 # This program is free software; you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation; either version 3 of the License, or 6 # (at your option) any later version. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the GNU General Public License 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 # Test the handling of non-Value responses from 'children' method. 17 18 require allow_dap_tests 19 20 load_lib dap-support.exp 21 22 standard_testfile lazy-string.c 23 24 if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} { 25 return 26 } 27 28 set remote_python_file [gdb_remote_download host \ 29 ${srcdir}/${subdir}/${testfile}.py] 30 31 save_vars GDBFLAGS { 32 append GDBFLAGS " -iex \"source $remote_python_file\"" 33 34 if {[dap_initialize] == ""} { 35 return 36 } 37 } 38 39 set launch_id [dap_launch $testfile] 40 41 set line [gdb_get_line_number "STOP"] 42 set obj [dap_check_request_and_response "set breakpoint by line number" \ 43 setBreakpoints \ 44 [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \ 45 [list s $srcfile] $line]] 46 set line_bpno [dap_get_breakpoint_number $obj] 47 48 dap_check_request_and_response "configurationDone" configurationDone 49 50 dap_check_response "launch response" launch $launch_id 51 52 dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ 53 "body reason" breakpoint \ 54 "body hitBreakpointIds" $line_bpno 55 56 set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \ 57 {o threadId [i 1]}] \ 58 0] 59 set frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id] 60 61 set scopes [dap_check_request_and_response "get scopes" scopes \ 62 [format {o frameId [i %d]} $frame_id]] 63 set scopes [dict get [lindex $scopes 0] body scopes] 64 65 lassign $scopes scope reg_scope 66 gdb_assert {[dict get $scope name] == "Locals"} "scope is locals" 67 gdb_assert {[dict get $scope namedVariables] == 1} "one var in scope" 68 69 set num [dict get $scope variablesReference] 70 set refs [lindex [dap_check_request_and_response "fetch variable" \ 71 "variables" \ 72 [format {o variablesReference [i %d] count [i 1]} \ 73 $num]] \ 74 0] 75 76 set vars [dict get $refs body variables] 77 gdb_assert {[llength $vars] == 1} "just one variable" 78 79 set var [lindex $vars 0] 80 gdb_assert {[dict get $var name] == "the_string"} "variable name" 81 gdb_assert {[dict get $var value] == "contents"} "variable value" 82 gdb_assert {[dict get $var namedVariables] == 2} "variable has two children" 83 84 set num [dict get $var variablesReference] 85 set refs [lindex [dap_check_request_and_response "fetch children of variable" \ 86 "variables" \ 87 [format {o variablesReference [i %d] count [i 2]} \ 88 $num]] \ 89 0] 90 91 set vars [dict get $refs body variables] 92 gdb_assert {[llength $vars] == 2} "got two children of variable" 93 94 set saw_first 0 95 set saw_second 0 96 foreach var [dict get $refs body variables] { 97 set name [dict get $var name] 98 switch $name { 99 "first" { 100 gdb_assert {[dict get $var value] == 23} "value of first" 101 incr saw_first 102 } 103 104 "second" { 105 # The result looks strange here, but only because TON does 106 # not handle the backslash-quote sequence properly when 107 # decoding the JSON. The actual JSON is: "value": 108 # "\"DEI\"". 109 gdb_assert {[dict get $var value] == "\\\"DEI\\\""} \ 110 "value of second" 111 incr saw_second 112 } 113 114 default { 115 fail "unknown variable $name" 116 } 117 } 118 } 119 120 gdb_assert {$saw_first == 1 && $saw_second == 1} "saw both children" 121 122 dap_shutdown 123