mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-27 03:51:15 +08:00
c173cc8a66
Before Guile v2.1 [1], calls to `scm_make_smob_type' implicitly added the created class to the exports list of (oop goops); v2.1+ does not implicitly create bindings in any modules. This means that the GDB manual subsection documenting exported types is not quite right when GDB is linked against Guile <v2.1 (types are exported from (oop goops)) instead of (gdb)) and incorrect when linked against Guile v2.1+ (types are not bound to any variables at all!). There is a range of cases in which it's necessary or convenient to be able to refer to a GDB smob type, for instance: - Pattern matching based on the type of a value. - Defining GOOPS methods handling values from GDB (GOOPS methods typically use dynamic dispatch based on the types of the arguments). - Type-checking assertions when applying some defensive programming on an interface. - Generally any other situation one might encounter in a dynamically typed language that might need some introspection. If you're more familiar with Python, it would be quite similar to being unable to refer to the classes exported from the GDB module (which is to say: not crippling for the most part, but makes certain tasks more difficult than necessary). This commit makes a small change to GDB's smob registration machinery to make sure registered smobs get exported from the current module. This will likely cause warnings to the user about conflicting exports if they load both (gdb) and (oop goops) from a GDB linked against Guile v2.0, but it shouldn't impact functionality (and seemed preferable to trying to un-export bindings from (oop goops) if v2.0 was detected). [1]: This changed with Guile commit 28d0871b553a3959a6c59e2e4caec1c1509f8595 gdb/ChangeLog: 2021-06-07 George Barrett <bob@bob131.so> * guile/scm-gsmob.c (gdbscm_make_smob_type): Export registered smob type from the current module. gdb/testsuite/ChangeLog: 2021-06-07 George Barrett <bob@bob131.so> * gdb.guile/scm-gsmob.exp (test exports): Add tests to make sure the smob types currently listed in the GDB manual get exported from the (gdb) module. Change-Id: I7dcd791276b48dfc9edb64fc71170bbb42a6f6e7
97 lines
4.0 KiB
Plaintext
97 lines
4.0 KiB
Plaintext
# Copyright (C) 2014-2021 Free Software Foundation, Inc.
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# This file is part of the GDB testsuite.
|
|
# It tests basic gsmob features.
|
|
|
|
load_lib gdb-guile.exp
|
|
|
|
# Start with a fresh gdb.
|
|
gdb_exit
|
|
gdb_start
|
|
|
|
# Skip all tests if Guile scripting is not enabled.
|
|
if { [skip_guile_tests] } { continue }
|
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
gdb_install_guile_utils
|
|
gdb_install_guile_module
|
|
|
|
# Test the transition from alist to htab in the property list.
|
|
# N.B. This has the same value as gdb/guile/scm-gsmob.c.
|
|
set SMOB_PROP_HTAB_THRESHOLD 7
|
|
|
|
gdb_test_no_output "gu (define arch (current-arch))"
|
|
|
|
# Return a property name for integer I suitable for sorting.
|
|
|
|
proc prop_name { i } {
|
|
return [format "prop%02d" $i]
|
|
}
|
|
|
|
# Set and ref the properties in separate loops to verify previously set
|
|
# properties are not lost when we set a new property or switch to htabs.
|
|
for {set i 0} {$i <= $SMOB_PROP_HTAB_THRESHOLD} {incr i} {
|
|
gdb_test "gu (print (object-property arch '[prop_name $i]))" \
|
|
"= #f" "property prop$i not present before set"
|
|
gdb_test "gu (print (set-object-property! arch '[prop_name $i] $i))" \
|
|
"= $i" "set prop $i"
|
|
gdb_test "gu (print (object-property arch '[prop_name $i]))" \
|
|
"= $i" "property prop$i present after set"
|
|
}
|
|
for {set i 0} {$i <= $SMOB_PROP_HTAB_THRESHOLD} {incr i} {
|
|
gdb_test "gu (print (object-property arch '[prop_name $i]))" \
|
|
"= $i" "ref prop $i"
|
|
}
|
|
|
|
# Verify properties.
|
|
set prop_list ""
|
|
for {set i 0} {$i <= $SMOB_PROP_HTAB_THRESHOLD} {incr i} {
|
|
set prop_list "$prop_list [prop_name $i]"
|
|
}
|
|
set prop_list [lsort $prop_list]
|
|
verbose -log "prop_list: $prop_list"
|
|
gdb_test "gu (print (sort (map car (object-properties arch)) (lambda (a b) (string<? (symbol->string a) (symbol->string b)))))" \
|
|
"= \\($prop_list\\)" "object-properties"
|
|
|
|
# Check that smob classes are exported properly
|
|
with_test_prefix "test exports" {
|
|
# Import (oop goops) for is-a? and <class>
|
|
gdb_scm_test_silent_cmd "gu (use-modules (oop goops))" "import goops"
|
|
gdb_test_no_output "gu (define-syntax-rule (gdb-exports-class? x) (is-a? (@ (gdb) x) <class>))"
|
|
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:arch>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:block>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:block-symbols-iterator>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:breakpoint>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:command>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:exception>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:frame>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:iterator>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:lazy-string>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:objfile>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:parameter>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:pretty-printer>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:pretty-printer-worker>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:progspace>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:symbol>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:symtab>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:sal>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:type>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:field>))" "= #t"
|
|
gdb_test "gu (print (gdb-exports-class? <gdb:value>))" "= #t"
|
|
}
|