1 1.1.1.9 christos # Copyright (C) 2010-2025 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 symbols to Guile. 18 1.1 christos 19 1.1 christos load_lib gdb-guile.exp 20 1.1 christos 21 1.1.1.7 christos require allow_guile_tests 22 1.1.1.7 christos 23 1.1 christos standard_testfile 24 1.1 christos 25 1.1.1.3 christos if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { 26 1.1 christos return -1 27 1.1 christos } 28 1.1 christos 29 1.1 christos # These tests are done before we call gdb_guile_runto_main so we have to 30 1.1 christos # import the gdb module ourselves. 31 1.1 christos gdb_install_guile_utils 32 1.1 christos gdb_install_guile_module 33 1.1 christos 34 1.1 christos # Test looking up a global symbol before we runto_main as this is the 35 1.1 christos # point where we don't have a current frame, and we don't want to 36 1.1 christos # require one. 37 1.1 christos gdb_scm_test_silent_cmd "guile (define main-func (lookup-global-symbol \"main\"))" \ 38 1.1 christos "lookup main" 39 1.1 christos gdb_test "guile (print (symbol-function? main-func))" \ 40 1.1.1.8 christos "= #t" "test, symbol-function? main" 41 1.1 christos gdb_test "guile (print (lookup-global-symbol \"junk\"))" \ 42 1.1.1.8 christos "= #f" "test, lookup-global-symbol junk" 43 1.1 christos 44 1.1 christos gdb_test "guile (print (symbol-value main-func))" \ 45 1.1 christos "= {int \\(int, char \[*\]\[*\]\\)} $hex \\<main\\>" "print value of main" 46 1.1 christos 47 1.1 christos set qq_line [gdb_get_line_number "line of qq"] 48 1.1 christos gdb_scm_test_silent_cmd "guile (define qq-var (lookup-global-symbol \"qq\"))" \ 49 1.1 christos "lookup qq" 50 1.1 christos gdb_test "guile (print (symbol-line qq-var))" \ 51 1.1 christos "= $qq_line" "print line number of qq" 52 1.1 christos gdb_test "guile (print (symbol-value qq-var))" \ 53 1.1 christos "= 72" "print value of qq" 54 1.1 christos gdb_test "guile (print (symbol-needs-frame? qq-var))" \ 55 1.1 christos "= #f" "print whether qq needs a frame" 56 1.1 christos 57 1.1 christos if ![gdb_guile_runto_main] { 58 1.1 christos return 59 1.1 christos } 60 1.1 christos 61 1.1 christos # Test symbol eq? and equal?. 62 1.1 christos gdb_test "guile (print (eq? (lookup-global-symbol \"main\") (lookup-global-symbol \"main\")))" \ 63 1.1 christos "= #t" 64 1.1 christos gdb_test "guile (print (equal? (lookup-global-symbol \"main\") (lookup-global-symbol \"main\")))" \ 65 1.1 christos "= #t" 66 1.1 christos 67 1.1 christos gdb_breakpoint [gdb_get_line_number "Block break here."] 68 1.1 christos gdb_continue_to_breakpoint "Block break here." 69 1.1 christos gdb_scm_test_silent_cmd "guile (define frame (selected-frame))" \ 70 1.1 christos "get frame at block break" 71 1.1 christos gdb_scm_test_silent_cmd "guile (define block (frame-block frame))" \ 72 1.1 christos "get block at block break" 73 1.1 christos 74 1.1 christos # Test symbol-argument?. 75 1.1 christos gdb_scm_test_silent_cmd "guile (define arg (car (lookup-symbol \"arg\")))" \ 76 1.1 christos "get variable arg" 77 1.1 christos gdb_test "guile (print (symbol-variable? arg))" "= #f" 78 1.1 christos gdb_test "guile (print (symbol-constant? arg))" "= #f" 79 1.1 christos gdb_test "guile (print (symbol-argument? arg))" "= #t" 80 1.1 christos gdb_test "guile (print (symbol-function? arg))" "= #f" 81 1.1 christos 82 1.1 christos # Test symbol-function?. 83 1.1 christos gdb_scm_test_silent_cmd "guile (define func (block-function block))" \ 84 1.1 christos "get block function" 85 1.1 christos gdb_test "guile (print (symbol-variable? func))" "= #f" 86 1.1 christos gdb_test "guile (print (symbol-constant? func))" "= #f" 87 1.1 christos gdb_test "guile (print (symbol-argument? func))" "= #f" 88 1.1 christos gdb_test "guile (print (symbol-function? func))" "= #t" 89 1.1 christos 90 1.1 christos # Test attributes of func. 91 1.1 christos gdb_test "guile (print (symbol-name func))" "func" 92 1.1 christos gdb_test "guile (print (symbol-print-name func))" "func" 93 1.1 christos gdb_test "guile (print (symbol-linkage-name func))" "func" 94 1.1 christos gdb_test "guile (print (= (symbol-addr-class func) SYMBOL_LOC_BLOCK))" "= #t" 95 1.1 christos 96 1.1 christos gdb_breakpoint [gdb_get_line_number "Break at end."] 97 1.1 christos gdb_continue_to_breakpoint "Break at end." 98 1.1 christos gdb_scm_test_silent_cmd "guile (define frame (selected-frame))" \ 99 1.1 christos "get frame at end" 100 1.1 christos 101 1.1 christos # Test symbol-variable?. 102 1.1 christos gdb_scm_test_silent_cmd "guile (define a (car (lookup-symbol \"a\")))" \ 103 1.1 christos "get variable a" 104 1.1 christos gdb_test "guile (print (symbol-variable? a))" "= #t" 105 1.1 christos gdb_test "guile (print (symbol-constant? a))" "= #f" 106 1.1 christos gdb_test "guile (print (symbol-argument? a))" "= #f" 107 1.1 christos gdb_test "guile (print (symbol-function? a))" "= #f" 108 1.1 christos 109 1.1 christos # Test attributes of a. 110 1.1 christos gdb_test "guile (print (= (symbol-addr-class a) SYMBOL_LOC_COMPUTED))" "= #t" 111 1.1 christos 112 1.1 christos gdb_test "guile (print (symbol-value a))" \ 113 1.1 christos "ERROR: Symbol requires a frame to compute its value.*"\ 114 1.1 christos "try to print value of a without a frame" 115 1.1 christos gdb_test "guile (print (symbol-value a #:frame frame))" \ 116 1.1 christos "= 0" "print value of a" 117 1.1 christos gdb_test "guile (print (symbol-needs-frame? a))" \ 118 1.1 christos "= #t" "print whether a needs a frame" 119 1.1 christos 120 1.1 christos # Test symbol-constant?. 121 1.1 christos gdb_scm_test_silent_cmd "guile (define t (car (lookup-symbol \"one\")))" \ 122 1.1 christos "get constant t" 123 1.1 christos gdb_test "guile (print (symbol-variable? t))" "= #f" 124 1.1 christos gdb_test "guile (print (symbol-constant? t))" "= #t" 125 1.1 christos gdb_test "guile (print (symbol-argument? t))" "= #f" 126 1.1 christos gdb_test "guile (print (symbol-function? t))" "= #f" 127 1.1 christos 128 1.1 christos # Test attributes of t. 129 1.1 christos gdb_test "guile (print (= (symbol-addr-class t) SYMBOL_LOC_CONST))" "= #t" 130 1.1 christos 131 1.1 christos # Test type attribute. 132 1.1 christos gdb_test "guile (print (symbol-type t))" "= enum tag" 133 1.1 christos 134 1.1 christos # Test symtab attribute. 135 1.1.1.7 christos gdb_test "guile (print (symbol-symtab t))" "= #<gdb:symtab (.*/)?scm-symbol.c>" 136 1.1 christos 137 1.1 christos # C++ tests 138 1.1 christos # Recompile binary. 139 1.1 christos if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}-cxx" executable "debug c++"] != "" } { 140 1.1.1.3 christos untested "failed to compile in C++ mode" 141 1.1 christos return -1 142 1.1 christos } 143 1.1 christos 144 1.1.1.9 christos clean_restart ${::testfile}-cxx 145 1.1 christos 146 1.1 christos if ![gdb_guile_runto_main] { 147 1.1 christos return 148 1.1 christos } 149 1.1 christos 150 1.1 christos gdb_breakpoint [gdb_get_line_number "Break in class."] 151 1.1 christos gdb_continue_to_breakpoint "Break in class." 152 1.1 christos 153 1.1 christos gdb_scm_test_silent_cmd "guile (define cplusframe (selected-frame))" \ 154 1.1 christos "get frame at class" 155 1.1 christos gdb_scm_test_silent_cmd "guile (define cplusfunc (block-function (frame-block cplusframe)))" \ 156 1.1 christos "get function at class" 157 1.1 christos 158 1.1 christos gdb_test "guile (print (symbol-variable? cplusfunc))" "= #f" 159 1.1 christos gdb_test "guile (print (symbol-constant? cplusfunc))" "= #f" 160 1.1 christos gdb_test "guile (print (symbol-argument? cplusfunc))" "= #f" 161 1.1 christos gdb_test "guile (print (symbol-function? cplusfunc))" "= #t" 162 1.1 christos 163 1.1 christos gdb_test "guile (print (symbol-name cplusfunc))" \ 164 1.1 christos "= SimpleClass::valueofi().*" "test method.name" 165 1.1 christos gdb_test "guile (print (symbol-print-name cplusfunc))" \ 166 1.1 christos "= SimpleClass::valueofi().*" "test method.print_name" 167 1.1 christos gdb_test "guile (print (symbol-linkage-name cplusfunc))" \ 168 1.1.1.5 christos "_ZN11SimpleClass8valueofiEv.*" "test method.linkage_name" 169 1.1 christos gdb_test "guile (print (= (symbol-addr-class cplusfunc) SYMBOL_LOC_BLOCK))" "= #t" 170 1.1 christos 171 1.1 christos # Test is_valid when the objfile is unloaded. This must be the last 172 1.1 christos # test as it unloads the object file in GDB. 173 1.1 christos # Start with a fresh gdb. 174 1.1 christos clean_restart ${testfile} 175 1.1 christos if ![gdb_guile_runto_main] { 176 1.1 christos return 177 1.1 christos } 178 1.1 christos 179 1.1 christos gdb_breakpoint [gdb_get_line_number "Break at end."] 180 1.1.1.6 christos gdb_continue_to_breakpoint "Break at end again" 181 1.1 christos gdb_scm_test_silent_cmd "guile (define a (car (lookup-symbol \"a\")))" \ 182 1.1 christos "get variable a for unload" 183 1.1 christos gdb_test "guile (print (symbol-valid? a))" \ 184 1.1 christos "= #t" "test symbol validity pre-unload" 185 1.1 christos delete_breakpoints 186 1.1 christos gdb_unload 187 1.1 christos gdb_test "guile (print (symbol-valid? a))" \ 188 1.1 christos "= #f" "test symbol validity post-unload" 189 1.1 christos gdb_test_no_output "guile (set! a #f) (gc)" "test symbol destructor" 190