1 1.9 christos # Copyright (C) 2010-2024 Free Software Foundation, Inc. 2 1.1 christos # 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # This file is part of the GDB testsuite. 17 1.1 christos # It tests the mechanism exposing blocks to Guile. 18 1.1 christos 19 1.1 christos load_lib gdb-guile.exp 20 1.1 christos 21 1.9 christos require allow_guile_tests 22 1.9 christos 23 1.1 christos standard_testfile 24 1.1 christos 25 1.5 christos if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { 26 1.1 christos return -1 27 1.1 christos } 28 1.1 christos 29 1.1 christos if ![gdb_guile_runto_main] { 30 1.1 christos return 31 1.1 christos } 32 1.1 christos 33 1.1 christos gdb_breakpoint [gdb_get_line_number "Block break here."] 34 1.1 christos gdb_continue_to_breakpoint "Block break here." 35 1.1 christos 36 1.1 christos # Test initial innermost block. 37 1.1 christos gdb_scm_test_silent_cmd "guile (define frame (selected-frame))" \ 38 1.1 christos "Get frame inner" 39 1.1 christos gdb_scm_test_silent_cmd "guile (define block (frame-block frame))" \ 40 1.1 christos "Get block inner" 41 1.1 christos gdb_test "guile (print block)" "#<gdb:block $hex-$hex>" \ 42 1.1 christos "Check block not #f" 43 1.1 christos gdb_test "guile (print (block-function block))" \ 44 1.1 christos "#f" "First anonymous block" 45 1.1 christos gdb_test "guile (print (block-start block))" \ 46 1.1 christos "${decimal}" "Check start not #f" 47 1.1 christos gdb_test "guile (print (block-end block))" \ 48 1.1 christos "${decimal}" "Check end not #f" 49 1.1 christos 50 1.1 christos # Test eq?. 51 1.1 christos gdb_test "guile (print (eq? (frame-block frame) (frame-block frame)))" \ 52 1.1 christos "= #t" "Check eq? on same block" 53 1.1 christos gdb_test "guile (print (eq? block (block-global-block block)))" \ 54 1.1 christos "= #f" "Check eq? on different blocks" 55 1.1 christos 56 1.1 christos # Test global/static blocks. 57 1.1 christos gdb_scm_test_silent_cmd "guile (define frame (selected-frame))" \ 58 1.1 christos "Get frame for global/static" 59 1.1 christos gdb_scm_test_silent_cmd "guile (define block (frame-block frame))" \ 60 1.1 christos "Get block for global/static" 61 1.1 christos gdb_test "guile (print (block-global? block))" \ 62 1.1 christos "#f" "Not a global block" 63 1.1 christos gdb_test "guile (print (block-static? block))" \ 64 1.1 christos "#f" "Not a static block" 65 1.1 christos gdb_scm_test_silent_cmd "guile (define gblock (block-global-block block))" \ 66 1.1 christos "Get global block" 67 1.1 christos gdb_scm_test_silent_cmd "guile (define sblock (block-static-block block))" \ 68 1.1 christos "Get static block" 69 1.1 christos gdb_test "guile (print (block-global? gblock))" \ 70 1.1 christos "#t" "Is the global block" 71 1.1 christos gdb_test "guile (print (block-static? sblock))" \ 72 1.1 christos "#t" "Is the static block" 73 1.1 christos 74 1.1 christos # Move up superblock(s) until we reach function block_func. 75 1.1 christos gdb_test_no_output "guile (set! block (block-superblock block))" \ 76 1.1 christos "Get superblock" 77 1.1 christos gdb_test "guile (print (block-function block))" \ 78 1.1 christos "#f" "Second anonymous block" 79 1.1 christos gdb_test_no_output "guile (set! block (block-superblock block))" \ 80 1.1 christos "Get superblock 2" 81 1.1 christos gdb_test "guile (print (block-function block))" \ 82 1.1 christos "block_func" "Print superblock 2 function" 83 1.1 christos 84 1.1 christos # Switch frames, then test for main block. 85 1.1 christos gdb_test "up" ".*" 86 1.1 christos gdb_scm_test_silent_cmd "guile (define frame (selected-frame))" \ 87 1.1 christos "Get frame 2" 88 1.1 christos gdb_scm_test_silent_cmd "guile (define block (frame-block frame))" \ 89 1.1 christos "Get frame 2's block" 90 1.1 christos gdb_test "guile (print block)" "#<gdb:block main $hex-$hex>" \ 91 1.1 christos "Check Frame 2's block not #f" 92 1.1 christos gdb_test "guile (print (block-function block))" \ 93 1.1 christos "main" "main block" 94 1.1 christos 95 1.1 christos # Test block-valid?. This must always be the last test in this 96 1.1 christos # testcase as it unloads the object file. 97 1.1 christos delete_breakpoints 98 1.1 christos gdb_scm_test_silent_cmd "guile (define frame (selected-frame))" \ 99 1.1 christos "Get frame for valid?" 100 1.1 christos gdb_scm_test_silent_cmd "guile (define block (frame-block frame))" \ 101 1.1 christos "Get frame block for valid?" 102 1.1 christos gdb_test "guile (print (block-valid? block))" \ 103 1.1 christos "#t" "Check block validity" 104 1.1 christos gdb_unload 105 1.1 christos gdb_test "guile (print (block-valid? block))" \ 106 1.1 christos "#f" "Check block validity after unload" 107