]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2023-2024 Free Software Foundation, Inc. |
19201489 TT |
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 DAP stack format options. | |
17 | ||
18 | require allow_dap_tests | |
19 | ||
20 | load_lib dap-support.exp | |
21 | ||
22 | standard_testfile | |
23 | ||
24 | if {[build_executable ${testfile}.exp $testfile] == -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 "BREAK"] | |
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 | ||
53 | # Each request should return the same frame ID. Store it here, | |
54 | # indexed by requested frame. | |
55 | array set frame_id {} | |
56 | ||
57 | # Request a single frame of the stack trace and check it. NAME is the | |
58 | # name of the test. FRAME is the number of the frame to request. | |
59 | # FORMAT is contents of the StackFrameFormat object to use. It is in | |
60 | # TON form. EXPECTED is the expected 'name' value of the resulting | |
61 | # frame. If REGEXP is set, then EXPECTED is a regular expression; | |
62 | # otherwise it is treated as the exact string result. | |
63 | proc check_stack_frame {name frame format expected {regexp 0}} { | |
64 | with_test_prefix $name { | |
65 | set args [format {o startFrame [i %d] levels [i 1] threadId [i 1]} \ | |
66 | $frame] | |
67 | if {$format != ""} { | |
68 | append args " format \[o $format\]" | |
69 | } | |
70 | ||
71 | set bt [lindex [dap_check_request_and_response "backtrace" \ | |
72 | stackTrace $args] \ | |
73 | 0] | |
74 | set frame_info [lindex [dict get $bt body stackFrames] 0] | |
75 | ||
76 | # Each request at this level should return the same frame ID. | |
77 | set this_id [dict get $frame_info id] | |
78 | global frame_id | |
79 | if {[info exists frame_id($frame)]} { | |
80 | gdb_assert {$frame_id($frame) == $this_id} "unchanging frame id" | |
81 | } else { | |
82 | set frame_id($frame) $this_id | |
83 | } | |
84 | ||
85 | if {$regexp} { | |
86 | gdb_assert {[regexp $expected [dict get $frame_info name]]} \ | |
87 | "got expected name" | |
88 | } else { | |
89 | gdb_assert {[dict get $frame_info name] == $expected} \ | |
90 | "got expected name" | |
91 | } | |
92 | } | |
93 | } | |
94 | ||
95 | check_stack_frame empty 0 {} "function" | |
96 | ||
97 | check_stack_frame parameters 0 {parameters [l true] \ | |
98 | parameterTypes [l true] \ | |
99 | parameterNames [l true] \ | |
100 | parameterValues [l true]} \ | |
101 | {function([int] x = 64, [char] y = 65 'A')} | |
102 | ||
103 | # When 'parameters' is false, it disables the other parameter* | |
104 | # options. This was clarified in | |
105 | # https://github.com/microsoft/debug-adapter-protocol/issues/411 | |
106 | check_stack_frame noparams 0 {parameters [l false] \ | |
107 | parameterTypes [l true] \ | |
108 | parameterNames [l true] \ | |
109 | parameterValues [l true]} \ | |
110 | "function" | |
111 | ||
112 | check_stack_frame line 0 {line [l true] module [l true]} \ | |
113 | "function, line $line, module .*stack-format" \ | |
114 | 1 | |
115 | ||
116 | check_stack_frame hex 0 \ | |
117 | {parameters [l true] parameterValues [l true] hex [l true]} \ | |
118 | "function(0x40, 0x41)" | |
119 | ||
120 | check_stack_frame elided-main 1 {} "main" | |
121 | ||
122 | # The next requests will ask for all frames, so the old frame 1 will | |
123 | # be the new frame 4. Update the map to check this. | |
124 | set frame_id(4) $frame_id(1) | |
125 | unset frame_id(1) | |
126 | ||
127 | check_stack_frame no-elide 0 {includeAll [l true]} "function" | |
128 | check_stack_frame z-frame-1 1 {includeAll [l true]} "z_1" | |
129 | check_stack_frame z-frame-2 2 {includeAll [l true]} "z_2" | |
130 | check_stack_frame z-frame-3 3 {includeAll [l true]} "z_3" | |
131 | check_stack_frame main-include-all 4 {includeAll [l true]} "main" | |
132 | ||
133 | dap_shutdown |