binutils-gdb/gdb/testsuite/gdb.guile/scm-symbol.exp

197 lines
7.3 KiB
Plaintext
Raw Normal View History

# Copyright (C) 2010-2015 Free Software Foundation, Inc.
Add Guile as an extension language. * NEWS: Mention Guile scripting. * Makefile.in (SUBDIR_GUILE_OBS): New variable. (SUBDIR_GUILE_SRCS, SUBDIR_GUILE_DEPS): New variables (SUBDIR_GUILE_LDFLAGS, SUBDIR_GUILE_CFLAGS): New variables. (INTERNAL_CPPFLAGS): Add GUILE_CPPFLAGS. (CLIBS): Add GUILE_LIBS. (install-guile): New rule. (guile.o): New rule. (scm-arch.o, scm-auto-load.o, scm-block.o): New rules. (scm-breakpoint.o, scm-disasm.o, scm-exception.o): New rules. (scm-frame.o, scm-iterator.o, scm-lazy-string.o): New rules. (scm-math.o, scm-objfile.o, scm-ports.o): New rules. (scm-pretty-print.o, scm-safe-call.o, scm-gsmob.o): New rules. (scm-string.o, scm-symbol.o, scm-symtab.o): New rules. (scm-type.o, scm-utils.o, scm-value.o): New rules. * configure.ac: New option --with-guile. * configure: Regenerate. * config.in: Regenerate. * auto-load.c: Remove #include "python/python.h". Add #include "gdb/section-scripts.h". (source_section_scripts): Handle Guile scripts. (_initialize_auto_load): Add name of Guile objfile script to scripts-directory help text. * breakpoint.c (condition_command): Tweak comment to include Scheme. * breakpoint.h (gdbscm_breakpoint_object): Add forward decl. (struct breakpoint): New member scm_bp_object. * defs.h (enum command_control_type): New value guile_control. * cli/cli-cmds.c: Remove #include "python/python.h". Add #include "extension.h". (show_user): Update comment. (_initialize_cli_cmds): Update help text for "show user". Update help text for max-user-call-depth. * cli/cli-script.c: Remove #include "python/python.h". Add #include "extension.h". (multi_line_command_p): Add guile_control. (print_command_lines): Handle guile_control. (execute_control_command, recurse_read_control_structure): Ditto. (process_next_line): Recognize "guile" commands. * disasm.c (gdb_disassemble_info): Make non-static. * disasm.h: #include "dis-asm.h". (struct gdbarch): Add forward decl. (gdb_disassemble_info): Declare. * extension.c: #include "guile/guile.h". (extension_languages): Add guile. (get_ext_lang_defn): Handle EXT_LANG_GDB. * extension.h (enum extension_language): New value EXT_LANG_GUILE. * gdbtypes.c (get_unsigned_type_max): New function. (get_signed_type_minmax): New function. * gdbtypes.h (get_unsigned_type_max): Declare. (get_signed_type_minmax): Declare. * guile/README: New file. * guile/guile-internal.h: New file. * guile/guile.c: New file. * guile/guile.h: New file. * guile/scm-arch.c: New file. * guile/scm-auto-load.c: New file. * guile/scm-block.c: New file. * guile/scm-breakpoint.c: New file. * guile/scm-disasm.c: New file. * guile/scm-exception.c: New file. * guile/scm-frame.c: New file. * guile/scm-gsmob.c: New file. * guile/scm-iterator.c: New file. * guile/scm-lazy-string.c: New file. * guile/scm-math.c: New file. * guile/scm-objfile.c: New file. * guile/scm-ports.c: New file. * guile/scm-pretty-print.c: New file. * guile/scm-safe-call.c: New file. * guile/scm-string.c: New file. * guile/scm-symbol.c: New file. * guile/scm-symtab.c: New file. * guile/scm-type.c: New file. * guile/scm-utils.c: New file. * guile/scm-value.c: New file. * guile/lib/gdb.scm: New file. * guile/lib/gdb/boot.scm: New file. * guile/lib/gdb/experimental.scm: New file. * guile/lib/gdb/init.scm: New file. * guile/lib/gdb/iterator.scm: New file. * guile/lib/gdb/printing.scm: New file. * guile/lib/gdb/types.scm: New file. * data-directory/Makefile.in (GUILE_SRCDIR): New variable. (VPATH): Add $(GUILE_SRCDIR). (GUILE_DIR): New variable. (GUILE_INSTALL_DIR, GUILE_FILES): New variables. (all): Add stamp-guile dependency. (stamp-guile): New rule. (clean-guile, install-guile, uninstall-guile): New rules. (install-only): Add install-guile dependency. (uninstall): Add uninstall-guile dependency. (clean): Add clean-guile dependency. doc/ * Makefile.in (GDB_DOC_FILES): Add guile.texi. * gdb.texinfo (Auto-loading): Add set/show auto-load guile-scripts. (Extending GDB): New menu entries Guile, Multiple Extension Languages. (Guile docs): Include guile.texi. (objfile-gdbdotext file): Add objfile-gdb.scm. (dotdebug_gdb_scripts section): Mention Guile scripts. (Multiple Extension Languages): New node. * guile.texi: New file. testsuite/ * configure.ac (AC_OUTPUT): Add gdb.guile. * configure: Regenerate. * lib/gdb-guile.exp: New file. * lib/gdb.exp (get_target_charset): New function. * gdb.base/help.exp: Update expected output from "apropos apropos". * gdb.guile/Makefile.in: New file. * gdb.guile/guile.exp: New file. * gdb.guile/scm-arch.c: New file. * gdb.guile/scm-arch.exp: New file. * gdb.guile/scm-block.c: New file. * gdb.guile/scm-block.exp: New file. * gdb.guile/scm-breakpoint.c: New file. * gdb.guile/scm-breakpoint.exp: New file. * gdb.guile/scm-disasm.c: New file. * gdb.guile/scm-disasm.exp: New file. * gdb.guile/scm-equal.c: New file. * gdb.guile/scm-equal.exp: New file. * gdb.guile/scm-error.exp: New file. * gdb.guile/scm-error.scm: New file. * gdb.guile/scm-frame-args.c: New file. * gdb.guile/scm-frame-args.exp: New file. * gdb.guile/scm-frame-args.scm: New file. * gdb.guile/scm-frame-inline.c: New file. * gdb.guile/scm-frame-inline.exp: New file. * gdb.guile/scm-frame.c: New file. * gdb.guile/scm-frame.exp: New file. * gdb.guile/scm-generics.exp: New file. * gdb.guile/scm-gsmob.exp: New file. * gdb.guile/scm-iterator.c: New file. * gdb.guile/scm-iterator.exp: New file. * gdb.guile/scm-math.c: New file. * gdb.guile/scm-math.exp: New file. * gdb.guile/scm-objfile-script-gdb.in: New file. * gdb.guile/scm-objfile-script.c: New file. * gdb.guile/scm-objfile-script.exp: New file. * gdb.guile/scm-objfile.c: New file. * gdb.guile/scm-objfile.exp: New file. * gdb.guile/scm-ports.exp: New file. * gdb.guile/scm-pretty-print.c: New file. * gdb.guile/scm-pretty-print.exp: New file. * gdb.guile/scm-pretty-print.scm: New file. * gdb.guile/scm-section-script.c: New file. * gdb.guile/scm-section-script.exp: New file. * gdb.guile/scm-section-script.scm: New file. * gdb.guile/scm-symbol.c: New file. * gdb.guile/scm-symbol.exp: New file. * gdb.guile/scm-symtab-2.c: New file. * gdb.guile/scm-symtab.c: New file. * gdb.guile/scm-symtab.exp: New file. * gdb.guile/scm-type.c: New file. * gdb.guile/scm-type.exp: New file. * gdb.guile/scm-value-cc.cc: New file. * gdb.guile/scm-value-cc.exp: New file. * gdb.guile/scm-value.c: New file. * gdb.guile/scm-value.exp: New file. * gdb.guile/source2.scm: New file. * gdb.guile/types-module.cc: New file. * gdb.guile/types-module.exp: New file.
2014-02-10 11:40:01 +08:00
# 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 the mechanism exposing symbols to Guile.
load_lib gdb-guile.exp
standard_testfile
if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
return -1
}
# Skip all tests if Guile scripting is not enabled.
if { [skip_guile_tests] } { continue }
# These tests are done before we call gdb_guile_runto_main so we have to
# import the gdb module ourselves.
gdb_install_guile_utils
gdb_install_guile_module
# Test looking up a global symbol before we runto_main as this is the
# point where we don't have a current frame, and we don't want to
# require one.
gdb_scm_test_silent_cmd "guile (define main-func (lookup-global-symbol \"main\"))" \
"lookup main"
gdb_test "guile (print (symbol-function? main-func))" \
"= #t" "test (symbol-function? main)"
gdb_test "guile (print (lookup-global-symbol \"junk\"))" \
"= #f" "test (lookup-global-symbol junk)"
gdb_test "guile (print (symbol-value main-func))" \
"= {int \\(int, char \[*\]\[*\]\\)} $hex \\<main\\>" "print value of main"
set qq_line [gdb_get_line_number "line of qq"]
gdb_scm_test_silent_cmd "guile (define qq-var (lookup-global-symbol \"qq\"))" \
"lookup qq"
gdb_test "guile (print (symbol-line qq-var))" \
"= $qq_line" "print line number of qq"
gdb_test "guile (print (symbol-value qq-var))" \
"= 72" "print value of qq"
gdb_test "guile (print (symbol-needs-frame? qq-var))" \
"= #f" "print whether qq needs a frame"
if ![gdb_guile_runto_main] {
return
}
# Test symbol eq? and equal?.
gdb_test "guile (print (eq? (lookup-global-symbol \"main\") (lookup-global-symbol \"main\")))" \
"= #t"
gdb_test "guile (print (equal? (lookup-global-symbol \"main\") (lookup-global-symbol \"main\")))" \
"= #t"
gdb_breakpoint [gdb_get_line_number "Block break here."]
gdb_continue_to_breakpoint "Block break here."
gdb_scm_test_silent_cmd "guile (define frame (selected-frame))" \
"get frame at block break"
gdb_scm_test_silent_cmd "guile (define block (frame-block frame))" \
"get block at block break"
# Test symbol-argument?.
gdb_scm_test_silent_cmd "guile (define arg (car (lookup-symbol \"arg\")))" \
"get variable arg"
gdb_test "guile (print (symbol-variable? arg))" "= #f"
gdb_test "guile (print (symbol-constant? arg))" "= #f"
gdb_test "guile (print (symbol-argument? arg))" "= #t"
gdb_test "guile (print (symbol-function? arg))" "= #f"
# Test symbol-function?.
gdb_scm_test_silent_cmd "guile (define func (block-function block))" \
"get block function"
gdb_test "guile (print (symbol-variable? func))" "= #f"
gdb_test "guile (print (symbol-constant? func))" "= #f"
gdb_test "guile (print (symbol-argument? func))" "= #f"
gdb_test "guile (print (symbol-function? func))" "= #t"
# Test attributes of func.
gdb_test "guile (print (symbol-name func))" "func"
gdb_test "guile (print (symbol-print-name func))" "func"
gdb_test "guile (print (symbol-linkage-name func))" "func"
gdb_test "guile (print (= (symbol-addr-class func) SYMBOL_LOC_BLOCK))" "= #t"
gdb_breakpoint [gdb_get_line_number "Break at end."]
gdb_continue_to_breakpoint "Break at end."
gdb_scm_test_silent_cmd "guile (define frame (selected-frame))" \
"get frame at end"
# Test symbol-variable?.
gdb_scm_test_silent_cmd "guile (define a (car (lookup-symbol \"a\")))" \
"get variable a"
gdb_test "guile (print (symbol-variable? a))" "= #t"
gdb_test "guile (print (symbol-constant? a))" "= #f"
gdb_test "guile (print (symbol-argument? a))" "= #f"
gdb_test "guile (print (symbol-function? a))" "= #f"
# Test attributes of a.
gdb_test "guile (print (= (symbol-addr-class a) SYMBOL_LOC_COMPUTED))" "= #t"
gdb_test "guile (print (symbol-value a))" \
"ERROR: Symbol requires a frame to compute its value.*"\
"try to print value of a without a frame"
gdb_test "guile (print (symbol-value a #:frame frame))" \
"= 0" "print value of a"
gdb_test "guile (print (symbol-needs-frame? a))" \
"= #t" "print whether a needs a frame"
# Test symbol-constant?.
gdb_scm_test_silent_cmd "guile (define t (car (lookup-symbol \"one\")))" \
"get constant t"
gdb_test "guile (print (symbol-variable? t))" "= #f"
gdb_test "guile (print (symbol-constant? t))" "= #t"
gdb_test "guile (print (symbol-argument? t))" "= #f"
gdb_test "guile (print (symbol-function? t))" "= #f"
# Test attributes of t.
gdb_test "guile (print (= (symbol-addr-class t) SYMBOL_LOC_CONST))" "= #t"
# Test type attribute.
gdb_test "guile (print (symbol-type t))" "= enum tag"
# Test symtab attribute.
gdb_test "guile (print (symbol-symtab t))" "= #<gdb:symtab .*gdb.guile/scm-symbol.c>"
# C++ tests
# Recompile binary.
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}-cxx" executable "debug c++"] != "" } {
untested "Couldn't compile ${srcfile} in c++ mode"
return -1
}
# Start with a fresh gdb.
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}-cxx
if ![gdb_guile_runto_main] {
return
}
gdb_breakpoint [gdb_get_line_number "Break in class."]
gdb_continue_to_breakpoint "Break in class."
gdb_scm_test_silent_cmd "guile (define cplusframe (selected-frame))" \
"get frame at class"
gdb_scm_test_silent_cmd "guile (define cplusfunc (block-function (frame-block cplusframe)))" \
"get function at class"
gdb_test "guile (print (symbol-variable? cplusfunc))" "= #f"
gdb_test "guile (print (symbol-constant? cplusfunc))" "= #f"
gdb_test "guile (print (symbol-argument? cplusfunc))" "= #f"
gdb_test "guile (print (symbol-function? cplusfunc))" "= #t"
gdb_test "guile (print (symbol-name cplusfunc))" \
"= SimpleClass::valueofi().*" "test method.name"
gdb_test "guile (print (symbol-print-name cplusfunc))" \
"= SimpleClass::valueofi().*" "test method.print_name"
# FIXME: GDB is broken here and we're verifying broken behaviour.
# (linkage-name should be the mangled name)
gdb_test "guile (print (symbol-linkage-name cplusfunc))" \
"SimpleClass::valueofi().*" "test method.linkage_name"
gdb_test "guile (print (= (symbol-addr-class cplusfunc) SYMBOL_LOC_BLOCK))" "= #t"
# Test is_valid when the objfile is unloaded. This must be the last
# test as it unloads the object file in GDB.
# Start with a fresh gdb.
clean_restart ${testfile}
if ![gdb_guile_runto_main] {
return
}
gdb_breakpoint [gdb_get_line_number "Break at end."]
gdb_continue_to_breakpoint "Break at end."
gdb_scm_test_silent_cmd "guile (define a (car (lookup-symbol \"a\")))" \
"get variable a for unload"
gdb_test "guile (print (symbol-valid? a))" \
"= #t" "test symbol validity pre-unload"
delete_breakpoints
gdb_unload
gdb_test "guile (print (symbol-valid? a))" \
"= #f" "test symbol validity post-unload"
gdb_test_no_output "guile (set! a #f) (gc)" "test symbol destructor"