| 1 | # Copyright 2000, 2001, 2002, 2004, 2005, 2007, 2008, 2009 |
| 2 | # Free Software Foundation, Inc. |
| 3 | |
| 4 | # This program is free software; you can redistribute it and/or modify |
| 5 | # it under the terms of the GNU General Public License as published by |
| 6 | # the Free Software Foundation; either version 3 of the License, or |
| 7 | # (at your option) any later version. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | # GNU General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
| 17 | # |
| 18 | # Test essential Machine interface (MI) operations |
| 19 | # |
| 20 | # Verify that stack commands work. |
| 21 | |
| 22 | # The goal is not to test gdb functionality, which is done by other tests, |
| 23 | # but to verify the correct output response to MI operations. |
| 24 | # |
| 25 | |
| 26 | load_lib mi-support.exp |
| 27 | set MIFLAGS "-i=mi" |
| 28 | |
| 29 | gdb_exit |
| 30 | if [mi_gdb_start] { |
| 31 | continue |
| 32 | } |
| 33 | |
| 34 | set testfile "mi-stack" |
| 35 | set srcfile ${testfile}.c |
| 36 | set binfile ${objdir}/${subdir}/${testfile} |
| 37 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } { |
| 38 | untested mi-stack.exp |
| 39 | return -1 |
| 40 | } |
| 41 | |
| 42 | mi_delete_breakpoints |
| 43 | mi_gdb_reinitialize_dir $srcdir/$subdir |
| 44 | mi_gdb_reinitialize_dir $srcdir/$subdir |
| 45 | mi_gdb_load ${binfile} |
| 46 | |
| 47 | proc test_stack_frame_listing {} { |
| 48 | global mi_gdb_prompt |
| 49 | global hex fullname_syntax srcfile |
| 50 | |
| 51 | set line_callee4_head [gdb_get_line_number "callee4 ("] |
| 52 | set line_callee4_body [expr $line_callee4_head + 2] |
| 53 | |
| 54 | # Obtain a stack trace |
| 55 | # Tests: |
| 56 | # -stack-list-frames |
| 57 | # -stack-list-frames 1 1 |
| 58 | # -stack-list-frames 1 3 |
| 59 | # -stack-info-frame |
| 60 | |
| 61 | mi_gdb_test "231-stack-list-frames" \ |
| 62 | "231\\^done,stack=\\\[frame=\{level=\"0\",addr=\"$hex\",func=\"callee4\",file=\".*${srcfile}\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$line_callee4_body\"\},frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\},frame=\{level=\"2\",addr=\"$hex\",func=\"callee2\",.*\},frame=\{level=\"3\",addr=\"$hex\",func=\"callee1\",.*\},frame=\{level=\"4\",addr=\"$hex\",func=\"main\",.*\}\\\]" \ |
| 63 | "stack frame listing" |
| 64 | mi_gdb_test "232-stack-list-frames 1 1" \ |
| 65 | "232\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\}\\\]" \ |
| 66 | "stack frame listing 1 1" |
| 67 | mi_gdb_test "233-stack-list-frames 1 3" \ |
| 68 | "233\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\},frame=\{level=\"2\",addr=\"$hex\",func=\"callee2\",.*\},frame=\{level=\"3\",addr=\"$hex\",func=\"callee1\",.*\}\\\]" \ |
| 69 | "stack frame listing 1 3" |
| 70 | |
| 71 | mi_gdb_test "234-stack-list-frames 1" \ |
| 72 | "234\\^error,msg=\"mi_cmd_stack_list_frames: Usage.*FRAME_LOW FRAME_HIGH.*\"" \ |
| 73 | "stack frame listing wrong" |
| 74 | |
| 75 | mi_gdb_test "235-stack-info-frame" \ |
| 76 | "235\\^done,frame=\{level=\"0\",addr=\"$hex\",func=\"callee4\",file=\".*${srcfile}\",fullname=\"${fullname_syntax}${srcfile}\",line=\"$line_callee4_body\"\}" \ |
| 77 | "selected frame listing" |
| 78 | |
| 79 | mi_gdb_test "236-stack-list-frames 1 300" \ |
| 80 | "236\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"callee3\",.*\},frame=\{level=\"2\",addr=\"$hex\",func=\"callee2\",.*\},frame=\{level=\"3\",addr=\"$hex\",func=\"callee1\",.*\}\\\]" \ |
| 81 | "stack frame listing 1 300" |
| 82 | } |
| 83 | |
| 84 | proc test_stack_args_listing {} { |
| 85 | global mi_gdb_prompt |
| 86 | global hex |
| 87 | |
| 88 | # Obtain lists for args for the stack frames |
| 89 | # Tests: |
| 90 | # -stack-list-arguments 0 |
| 91 | # -stack-list-arguments 0 1 1 |
| 92 | # -stack-list-arguments 0 1 3 |
| 93 | # -stack-list-arguments 1 |
| 94 | # -stack-list-arguments 1 1 1 |
| 95 | # -stack-list-arguments 1 1 3 |
| 96 | # -stack-list-arguments |
| 97 | |
| 98 | mi_gdb_test "231-stack-list-arguments 0" \ |
| 99 | "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \ |
| 100 | "stack args listing 0" |
| 101 | |
| 102 | mi_gdb_test "232-stack-list-arguments 0 1 1" \ |
| 103 | "232\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\}\\\]" \ |
| 104 | "stack args listing 0 1 1" |
| 105 | |
| 106 | mi_gdb_test "233-stack-list-arguments 0 1 3" \ |
| 107 | "233\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\}\\\]" \ |
| 108 | "stack args listing 0 1 3" |
| 109 | |
| 110 | mi_gdb_test "231-stack-list-arguments 1" \ |
| 111 | "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \ |
| 112 | "stack args listing 1" |
| 113 | |
| 114 | mi_gdb_test "232-stack-list-arguments 1 1 1" \ |
| 115 | "232\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \ |
| 116 | "stack args listing 1 1 1" |
| 117 | |
| 118 | mi_gdb_test "233-stack-list-arguments 1 1 3" \ |
| 119 | "233\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\}\\\]" \ |
| 120 | "stack args listing 1 1 3" |
| 121 | |
| 122 | mi_gdb_test "234-stack-list-arguments" \ |
| 123 | "234\\^error,msg=\"mi_cmd_stack_list_args: Usage.*PRINT_VALUES.*FRAME_LOW FRAME_HIGH.*\"" \ |
| 124 | "stack args listing wrong" |
| 125 | |
| 126 | mi_gdb_test "235-stack-list-arguments 1 1 300" \ |
| 127 | "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \ |
| 128 | "stack args listing 1 1 300" |
| 129 | } |
| 130 | |
| 131 | proc test_stack_info_depth {} { |
| 132 | global mi_gdb_prompt |
| 133 | global hex |
| 134 | |
| 135 | # Obtain depth of stack |
| 136 | # Tests: |
| 137 | # -stack-info-depth |
| 138 | # -stack-info-depth 3 |
| 139 | # -stack-info-depth 99 |
| 140 | |
| 141 | mi_gdb_test "231-stack-info-depth" \ |
| 142 | "231\\^done,depth=\"5\"" \ |
| 143 | "stack info-depth" |
| 144 | |
| 145 | mi_gdb_test "231-stack-info-depth 3" \ |
| 146 | "231\\^done,depth=\"3\"" \ |
| 147 | "stack info-depth 3" |
| 148 | |
| 149 | mi_gdb_test "231-stack-info-depth 99" \ |
| 150 | "231\\^done,depth=\"5\"" \ |
| 151 | "stack info-depth 99" |
| 152 | |
| 153 | mi_gdb_test "231-stack-info-depth 99 99" \ |
| 154 | "231\\^error,msg=\"mi_cmd_stack_info_depth: Usage: .MAX_DEPTH.\"" \ |
| 155 | "stack info-depth wrong usage" |
| 156 | } |
| 157 | |
| 158 | proc test_stack_locals_listing {} { |
| 159 | global mi_gdb_prompt |
| 160 | global hex fullname_syntax srcfile |
| 161 | |
| 162 | # Obtain lists for locals for the stack frames |
| 163 | # Tests: |
| 164 | # -stack-list-locals 0 (--no-values) |
| 165 | # -stack-list-locals 1 (--all-values) |
| 166 | # -stack-list-locals 2 (--simple-values) |
| 167 | # -stack-list-arguments |
| 168 | |
| 169 | mi_gdb_test "232-stack-list-locals 0" \ |
| 170 | "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \ |
| 171 | "stack locals listing of names" |
| 172 | |
| 173 | set line_callee4_return_0 [gdb_get_line_number "return 0;"] |
| 174 | |
| 175 | # step until A, B, C, D have some reasonable values. |
| 176 | mi_execute_to "exec-next 4" "end-stepping-range" "callee4" "" ".*${srcfile}" $line_callee4_return_0 ""\ |
| 177 | "next's in callee4" |
| 178 | |
| 179 | mi_gdb_test "232-stack-list-locals 1" \ |
| 180 | "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \ |
| 181 | "stack locals listing of names and values" |
| 182 | |
| 183 | mi_gdb_test "232-stack-list-locals 2" \ |
| 184 | "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \ |
| 185 | "stack locals listing, simple types: names and values, complex type: names and types" |
| 186 | |
| 187 | mi_gdb_test "234-stack-list-locals" \ |
| 188 | "234\\^error,msg=\"mi_cmd_stack_list_locals: Usage.*PRINT_VALUES.*\"" \ |
| 189 | "stack locals listing wrong" |
| 190 | |
| 191 | mi_gdb_test "232-stack-select-frame 1" \ |
| 192 | "232\\^done" \ |
| 193 | "stack select frame 1" |
| 194 | |
| 195 | mi_gdb_test "232-stack-list-locals 1" \ |
| 196 | "232\\^done,locals=\\\[\\\]" \ |
| 197 | "stack locals listing for new frame" |
| 198 | |
| 199 | mi_gdb_test "232-stack-list-locals 1" \ |
| 200 | "232\\^done,locals=\\\[\\\]" \ |
| 201 | "stack locals for same frame (level 1)" |
| 202 | } |
| 203 | |
| 204 | mi_runto callee4 |
| 205 | test_stack_frame_listing |
| 206 | test_stack_args_listing |
| 207 | test_stack_locals_listing |
| 208 | test_stack_info_depth |
| 209 | |
| 210 | |
| 211 | mi_gdb_exit |
| 212 | return 0 |