|
| 1 | +# Copyright 2023 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_launch $testfile] == ""} { |
| 35 | + return |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +set line [gdb_get_line_number "STOP"] |
| 40 | +set obj [dap_check_request_and_response "set breakpoint by line number" \ |
| 41 | + setBreakpoints \ |
| 42 | + [format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \ |
| 43 | + [list s $srcfile] $line]] |
| 44 | +set line_bpno [dap_get_breakpoint_number $obj] |
| 45 | + |
| 46 | +dap_check_request_and_response "start inferior" configurationDone |
| 47 | + |
| 48 | +dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ |
| 49 | + "body reason" breakpoint \ |
| 50 | + "body hitBreakpointIds" $line_bpno |
| 51 | + |
| 52 | +set bt [lindex [dap_check_request_and_response "backtrace" stackTrace \ |
| 53 | + {o threadId [i 1]}] \ |
| 54 | + 0] |
| 55 | +set frame_id [dict get [lindex [dict get $bt body stackFrames] 0] id] |
| 56 | + |
| 57 | +set scopes [dap_check_request_and_response "get scopes" scopes \ |
| 58 | + [format {o frameId [i %d]} $frame_id]] |
| 59 | +set scopes [dict get [lindex $scopes 0] body scopes] |
| 60 | + |
| 61 | +lassign $scopes scope reg_scope |
| 62 | +gdb_assert {[dict get $scope name] == "Locals"} "scope is locals" |
| 63 | +gdb_assert {[dict get $scope namedVariables] == 1} "one var in scope" |
| 64 | + |
| 65 | +set num [dict get $scope variablesReference] |
| 66 | +set refs [lindex [dap_check_request_and_response "fetch variable" \ |
| 67 | + "variables" \ |
| 68 | + [format {o variablesReference [i %d] count [i 1]} \ |
| 69 | + $num]] \ |
| 70 | + 0] |
| 71 | + |
| 72 | +set vars [dict get $refs body variables] |
| 73 | +gdb_assert {[llength $vars] == 1} "just one variable" |
| 74 | + |
| 75 | +set var [lindex $vars 0] |
| 76 | +gdb_assert {[dict get $var name] == "the_string"} "variable name" |
| 77 | +gdb_assert {[dict get $var value] == "contents"} "variable value" |
| 78 | +gdb_assert {[dict get $var namedVariables] == 2} "variable has two children" |
| 79 | + |
| 80 | +set num [dict get $var variablesReference] |
| 81 | +set refs [lindex [dap_check_request_and_response "fetch children of variable" \ |
| 82 | + "variables" \ |
| 83 | + [format {o variablesReference [i %d] count [i 2]} \ |
| 84 | + $num]] \ |
| 85 | + 0] |
| 86 | + |
| 87 | +set vars [dict get $refs body variables] |
| 88 | +gdb_assert {[llength $vars] == 2} "got two children of variable" |
| 89 | + |
| 90 | +set saw_first 0 |
| 91 | +set saw_second 0 |
| 92 | +foreach var [dict get $refs body variables] { |
| 93 | + set name [dict get $var name] |
| 94 | + switch $name { |
| 95 | + "first" { |
| 96 | + gdb_assert {[dict get $var value] == 23} "value of first" |
| 97 | + incr saw_first |
| 98 | + } |
| 99 | + |
| 100 | + "second" { |
| 101 | + # The result looks strange here, but only because TON does |
| 102 | + # not handle the backslash-quote sequence properly when |
| 103 | + # decoding the JSON. The actual JSON is: "value": |
| 104 | + # "\"DEI\"". |
| 105 | + gdb_assert {[dict get $var value] == "\\\"DEI\\\""} \ |
| 106 | + "value of second" |
| 107 | + incr saw_second |
| 108 | + } |
| 109 | + |
| 110 | + default { |
| 111 | + fail "unknown variable $name" |
| 112 | + } |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +gdb_assert {$saw_first == 1 && $saw_second == 1} "saw both children" |
| 117 | + |
| 118 | +dap_shutdown |
0 commit comments