old-cross-binutils/gdb/testsuite/gdb.python/py-breakpoint.exp

473 lines
17 KiB
Text
Raw Normal View History

# Copyright (C) 2010-2014 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 the mechanism
# exposing breakpoints to Python.
load_lib gdb-python.exp
* gdb.python/lib-types.exp: Use standard_testfile, prepare_for_testing. * gdb.python/py-block.exp: Use standard_testfile. * gdb.python/py-breakpoint.exp: Use standard_testfile. * gdb.python/py-events.exp: Use standard_testfile, standard_output_file. * gdb.python/py-evsignal.exp: Use standard_testfile. * gdb.python/py-evethreads.exp: Use standard_testfile. * gdb.python/py-explore-cc.exp: Use standard_testfile. * gdb.python/py-explore.exp: Use standard_testfile. * gdb.python/py-finish-breakpoint.exp: Use standard_testfile, standard_output_file. * gdb.python/py-finish-breakpoint2.exp: Use standard_testfile, prepare_for_testing. * gdb.python/py-frame-inline.exp: Use standard_testfile. * gdb.python/py-frame.exp: Use standard_testfile. * gdb.python/py-inferior.exp: Use standard_testfile. * gdb.python/py-infthread.exp: Use standard_testfile. * gdb.python/py-mi.exp: Use standard_testfile. * gdb.python/py-objfile-script.exp: Use standard_testfile, build_executable. * gdb.python/py-objfile.exp: Use standard_testfile. * gdb.python/py-pp-maint.exp: Use standard_testfile, prepare_for_testing. * gdb.python/py-prettyprint.exp: Use standard_testfile. * gdb.python/py-progspace.exp: Use standard_testfile, build_executable. * gdb.python/py-prompt.exp: Use standard_testfile, build_executable. * gdb.python/py-section-script.exp: Use standard_testfile, build_executable. * gdb.python/py-shared.exp: Use standard_testfile, standard_output_file, clean_restart. * gdb.python/py-symbol.exp: Use standard_output_file, prepare_for_testing. * gdb.python/py-symtab.exp: Use standard_output_file, prepare_for_testing * gdb.python/py-template.exp: Use standard_testfile. * gdb.python/py-type.exp: Use standard_testfile. * gdb.python/py-value-cc.exp: Use standard_testfile. * gdb.python/py-value.exp: Use standard_testfile. * gdb.python/python.exp: Use standard_testfile, build_executable.
2012-06-22 17:59:33 +00:00
standard_testfile
if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
return -1
}
# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }
proc test_bkpt_basic { } {
global srcfile testfile hex decimal
with_test_prefix "test_bkpt_basic" {
# Start with a fresh gdb.
clean_restart ${testfile}
if ![runto_main] then {
fail "Cannot run to main."
return 0
}
# Initially there should be one breakpoint: main.
gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \
"Get Breakpoint List" 0
gdb_test "python print (blist\[0\])" \
"<gdb.Breakpoint object at $hex>" "Check obj exists @main"
gdb_test "python print (blist\[0\].location)" \
"main." "Check breakpoint location @main"
set mult_line [gdb_get_line_number "Break at multiply."]
gdb_breakpoint ${mult_line}
gdb_continue_to_breakpoint "Break at multiply" \
".*Break at multiply.*"
# Check that the Python breakpoint code noted the addition of a
# breakpoint "behind the scenes".
gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \
"Get Breakpoint List" 0
gdb_test "python print (len(blist))" \
"2" "Check for two breakpoints"
gdb_test "python print (blist\[0\])" \
"<gdb.Breakpoint object at $hex>" "Check obj exists @main 2"
gdb_test "python print (blist\[0\].location)" \
"main." "Check breakpoint location @main 2"
gdb_test "python print (blist\[1\])" \
"<gdb.Breakpoint object at $hex>" "Check obj exists @mult_line"
gdb_test "python print (blist\[1\].location)" \
"py-breakpoint\.c:${mult_line}*" \
"Check breakpoint location @mult_line"
# Check hit and ignore counts.
gdb_test "python print (blist\[1\].hit_count)" \
"1" "Check breakpoint hit count @1"
gdb_py_test_silent_cmd "python blist\[1\].ignore_count = 4" \
"Set breakpoint hit count" 0
gdb_continue_to_breakpoint "Break at multiply @6" \
".*Break at multiply.*"
gdb_test "python print (blist\[1\].hit_count)" \
"6" "Check breakpoint hit count @6"
gdb_test "print result" \
" = 545" "Check expected variable result after 6 iterations"
# Test breakpoint is enabled and disabled correctly..
gdb_breakpoint [gdb_get_line_number "Break at add."]
gdb_continue_to_breakpoint "Break at add 1" ".*Break at add.*"
gdb_test "python print (blist\[1\].enabled)" \
"True" "Check breakpoint enabled."
gdb_py_test_silent_cmd "python blist\[1\].enabled = False" \
"Set breakpoint disabled." 0
gdb_continue_to_breakpoint "Break at add 2" ".*Break at add.*"
gdb_py_test_silent_cmd "python blist\[1\].enabled = True" \
"Set breakpoint enabled." 0
gdb_continue_to_breakpoint "Break at multiply after re-enable" \
".*Break at multiply.*"
# Test other getters and setters.
gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \
"Get Breakpoint List" 0
gdb_test "python print (blist\[1\].thread)" \
"None" "Check breakpoint thread"
gdb_test "python print (blist\[1\].type == gdb.BP_BREAKPOINT)" \
"True" "Check breakpoint type"
gdb_test "python print (blist\[0\].number)" \
"1" "Check breakpoint number 0"
gdb_test "python print (blist\[1\].number)" \
"2" "Check breakpoint number 1"
gdb_test "python print (blist\[2\].number)" \
"3" "Check breakpoint number 2"
}
}
proc test_bkpt_deletion { } {
global srcfile testfile hex decimal
with_test_prefix test_bkpt_deletion {
# Start with a fresh gdb.
clean_restart ${testfile}
if ![runto_main] then {
fail "Cannot run to main."
return 0
}
# Test breakpoints are deleted correctly.
set deltst_location [gdb_get_line_number "Break at multiply."]
set end_location [gdb_get_line_number "Break at end."]
gdb_py_test_silent_cmd "python dp1 = gdb.Breakpoint (\"$deltst_location\")" \
"Set breakpoint" 0
gdb_breakpoint [gdb_get_line_number "Break at end."]
gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" \
"Get Breakpoint List" 0
gdb_test "python print (len(del_list))" \
"3" "Number of breakpoints before delete"
gdb_continue_to_breakpoint "Break at multiply." \
".*/$srcfile:$deltst_location.*"
gdb_py_test_silent_cmd "python dp1.delete()" \
"Delete Breakpoint" 0
gdb_test "python print (dp1.number)" \
"RuntimeError: Breakpoint 2 is invalid.*" \
"Check breakpoint invalidated"
gdb_py_test_silent_cmd "python del_list = gdb.breakpoints()" \
"Get Breakpoint List" 0
gdb_test "python print (len(del_list))" \
"2" "Number of breakpoints after delete"
gdb_continue_to_breakpoint "Break at end." \
".*/$srcfile:$end_location.*"
}
}
proc test_bkpt_cond_and_cmds { } {
global srcfile testfile hex decimal
with_test_prefix test_bkpt_cond_and_cmds {
# Start with a fresh gdb.
clean_restart ${testfile}
if ![runto_main] then {
fail "Cannot run to main."
return 0
}
# Test conditional setting.
set bp_location1 [gdb_get_line_number "Break at multiply."]
gdb_py_test_silent_cmd "python bp1 = gdb.Breakpoint (\"$bp_location1\")" \
"Set breakpoint" 0
gdb_continue_to_breakpoint "Break at multiply" \
".*Break at multiply.*"
gdb_py_test_silent_cmd "python bp1.condition = \"i == 5\"" \
"Set breakpoint" 0
gdb_test "python print (bp1.condition)" "i == 5" \
"Test conditional has been set"
gdb_continue_to_breakpoint "Break at multiply @5" \
".*Break at multiply.*"
gdb_test "print i" \
"5" "Test conditional breakpoint stopped after five iterations"
gdb_py_test_silent_cmd "python bp1.condition = None" \
"Clear condition" 0
gdb_test "python print (bp1.condition)" \
"None" "Test conditional read"
gdb_continue_to_breakpoint "Break at multiply @6" \
".*Break at multiply.*"
gdb_test "print i" \
"6" "Test breakpoint stopped after six iterations"
# Test commands.
gdb_breakpoint [gdb_get_line_number "Break at add."]
set test {commands $bpnum}
gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
set test {print "Command for breakpoint has been executed."}
gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
set test {print result}
gdb_test_multiple $test $test { -re "\r\n>$" { pass $test } }
gdb_test "end"
gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \
"Get Breakpoint List" 0
gdb_test "python print (blist\[len(blist)-1\].commands)" \
"print \"Command for breakpoint has been executed.\".*print result"
}
}
proc test_bkpt_invisible { } {
global srcfile testfile hex decimal
with_test_prefix test_bkpt_invisible {
# Start with a fresh gdb.
clean_restart ${testfile}
if ![runto_main] then {
fail "Cannot run to main."
return 0
}
delete_breakpoints
set ibp_location [gdb_get_line_number "Break at multiply."]
gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=False)" \
"Set invisible breakpoint" 0
gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" \
"Get Breakpoint List" 0
gdb_test "python print (ilist\[0\])" \
"<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists 1"
gdb_test "python print (ilist\[0\].location)" \
"py-breakpoint\.c:$ibp_location*" "Check breakpoint location 1"
gdb_test "python print (ilist\[0\].visible)" \
"True" "Check breakpoint visibility 1"
gdb_test "info breakpoints" "py-breakpoint\.c:$ibp_location.*" \
"Check info breakpoints shows visible breakpoints"
delete_breakpoints
gdb_py_test_silent_cmd "python ibp = gdb.Breakpoint(\"$ibp_location\", internal=True)" \
"Set invisible breakpoint" 0
gdb_py_test_silent_cmd "python ilist = gdb.breakpoints()" \
"Get Breakpoint List" 0
gdb_test "python print (ilist\[0\])" \
"<gdb.Breakpoint object at $hex>" "Check invisible bp obj exists 2"
gdb_test "python print (ilist\[0\].location)" \
"py-breakpoint\.c:$ibp_location*" "Check breakpoint location 2"
gdb_test "python print (ilist\[0\].visible)" \
"False" "Check breakpoint visibility 2"
gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \
"Check info breakpoints does not show invisible breakpoints"
gdb_test "maint info breakpoints" \
"py-breakpoint\.c:$ibp_location.*" \
"Check maint info breakpoints shows invisible breakpoints"
}
2010-11-11 Phil Muldoon <pmuldoon@redhat.com> * python/py-breakpoint.c (BPPY_REQUIRE_VALID): Check if bp is NULL. (BPPY_SET_REQUIRE_VALID): Ditto. (bpnum_is_valid): Delete function. (bppy_get_visibility): New function. (bppy_new): Parse for, and validate internal keyword. Pass internal keyword to breakpoint or watchpoint functions. (build_bp_list): New function. (gdbpy_breakpoints): Rewrite. Use build_bp_list and iterate_over_breakpoints. (gdbpy_breakpoint_created): Rewrite. Do not store breakpoints in a look-aside vector. (gdbpy_breakpoint_deleted): Rewrite, defer breakpoint management to internal breakpoint chain. * breakpoint.c (set_breakpoint_number): New function. (breakpoint_1): Check if breakpoint number is more than zero. (set_raw_breakpoint_without_location): Set py_bp_object to NULL. (create_breakpoint_sal): Take a new parameter called internal. Call set_breakpoint_number with internal parameter. Do not mention internal breakpoints. All callers updated. (create_breakpoint): Ditto. (create_breakpoints_sal): Ditto. (watch_command_1): Ditto. (watch_command_wrapper): Take a new parameter called internal. All callers updated. (rwatch_command_wrapper): Ditto. (awatch_command_wrapper): Ditto. (save_breakpoints): Update breakpoint save condition check. (iterate_over_breakpoints): New function. * breakpoint.h: Add conditional python includes. Add py_bp_object and comment to struct breakpoint. Update all callers. * defs.h: Add PyObject definition for GDB builds without Python. 2010-11-11 Phil Muldoon <pmuldoon@redhat.com> * gdb.texinfo (Breakpoints In Python): Document "internal" parameter, and visible attribute. 2010-11-11 Phil Muldoon <pmuldoon@redhat.com> * gdb.python/py-breakpoint.exp: Add internal watchpoint and breakpoint tests.
2010-11-11 14:11:56 +00:00
}
proc test_watchpoints { } {
global srcfile testfile hex decimal
with_test_prefix test_watchpoints {
# Start with a fresh gdb.
clean_restart ${testfile}
# Disable hardware watchpoints if necessary.
if [target_info exists gdb,no_hardware_watchpoints] {
gdb_test_no_output "set can-use-hw-watchpoints 0" ""
}
if ![runto_main] then {
fail "Cannot run to main."
return 0
}
gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE )" \
"Set watchpoint" 0
gdb_test "continue" \
".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" \
"Test watchpoint write"
}
}
proc test_bkpt_internal { } {
global srcfile testfile hex decimal
with_test_prefix test_bkpt_internal {
# Start with a fresh gdb.
clean_restart ${testfile}
# Disable hardware watchpoints if necessary.
if [target_info exists gdb,no_hardware_watchpoints] {
gdb_test_no_output "set can-use-hw-watchpoints 0" ""
}
if ![runto_main] then {
fail "Cannot run to main."
return 0
}
delete_breakpoints
gdb_py_test_silent_cmd "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE, internal=True )" \
"Set watchpoint" 0
gdb_test "info breakpoints" \
"No breakpoints or watchpoints.*" \
"Check info breakpoints does not show invisible breakpoints"
gdb_test "maint info breakpoints" \
".*watchpoint.*result.*" \
"Check maint info breakpoints shows invisible breakpoints"
gdb_test "continue" \
".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*" \
"Test watchpoint write"
}
}
proc test_bkpt_eval_funcs { } {
global srcfile testfile hex decimal
with_test_prefix test_bkpt_eval_funcs {
# Start with a fresh gdb.
clean_restart ${testfile}
# Disable hardware watchpoints if necessary.
if [target_info exists gdb,no_hardware_watchpoints] {
gdb_test_no_output "set can-use-hw-watchpoints 0" ""
}
if ![runto_main] then {
fail "Cannot run to main."
return 0
}
delete_breakpoints
gdb_py_test_multiple "Sub-class a breakpoint" \
"python" "" \
"class bp_eval (gdb.Breakpoint):" "" \
" inf_i = 0" "" \
" count = 0" "" \
" def stop (self):" "" \
" self.count = self.count + 1" "" \
" self.inf_i = gdb.parse_and_eval(\"i\")" "" \
" if self.inf_i == 3:" "" \
" return True" "" \
" return False" "" \
"end" ""
gdb_py_test_multiple "Sub-class a second breakpoint" \
"python" "" \
"class bp_also_eval (gdb.Breakpoint):" "" \
" count = 0" "" \
" def stop (self):" "" \
" self.count = self.count + 1" "" \
" if self.count == 9:" "" \
" return True" "" \
" return False" "" \
"end" ""
gdb_py_test_multiple "Sub-class a third breakpoint" \
"python" "" \
"class basic (gdb.Breakpoint):" "" \
" count = 0" "" \
"end" ""
set bp_location2 [gdb_get_line_number "Break at multiply."]
set end_location [gdb_get_line_number "Break at end."]
gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$bp_location2\")" \
"Set breakpoint" 0
gdb_py_test_silent_cmd "python also_eval_bp1 = bp_also_eval(\"$bp_location2\")" \
"Set breakpoint" 0
gdb_py_test_silent_cmd "python never_eval_bp1 = bp_also_eval(\"$end_location\")" \
"Set breakpoint" 0
gdb_continue_to_breakpoint "Break at multiply, i==3" \
".*/$srcfile:$bp_location2.*"
gdb_test "print i" \
"3" "Check inferior value matches python accounting"
gdb_test "python print (eval_bp1.inf_i)" \
"3" "Check python accounting matches inferior"
gdb_test "python print (also_eval_bp1.count)" "4" \
"Check non firing same-location also_eval_bp1 function was also called at each stop."
gdb_test "python print (eval_bp1.count)" "4" \
"Check non firing same-location eval_bp1 function was also called at each stop."
delete_breakpoints
set cond_bp [gdb_get_line_number "Break at multiply."]
gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$cond_bp\")" \
"Set breakpoint" 0
set test_cond {cond $bpnum}
gdb_test "$test_cond \"foo==3\"" \
Extension Language API * configure.ac (libpython checking): Remove all but python.o from CONFIG_OBS. Remove all but python.c from CONFIG_SRCS. * configure: Regenerate. * Makefile.in (SFILES): Add extension.c. (HFILES_NO_SRCDIR): Add extension.h, extension-priv.h (COMMON_OBS): Add extension.o. * extension.h: New file. * extension-priv.h: New file. * extension.c: New file. * python/python-internal.h: #include "extension.h". (gdbpy_auto_load_enabled): Declare. (gdbpy_apply_val_pretty_printer): Declare. (gdbpy_apply_frame_filter): Declare. (gdbpy_preserve_values): Declare. (gdbpy_breakpoint_cond_says_stop): Declare. (gdbpy_breakpoint_has_cond): Declare. (void source_python_script_for_objfile): Delete. * python/python.c: #include "extension-priv.h". Delete inclusion of "observer.h". (extension_language_python): Moved here and renamed from script_language_python in py-auto-load.c. Redefined to be of type extension_language_defn. (python_extension_script_ops): New global. (python_extension_ops): New global. (struct python_env): New member previous_active. (restore_python_env): Call restore_active_ext_lang. (ensure_python_env): Call set_active_ext_lang. (gdbpy_clear_quit_flag): Renamed from clear_quit_flag, made static. New arg extlang. (gdbpy_set_quit_flag): Renamed from set_quit_flag, made static. New arg extlang. (gdbpy_check_quit_flag): Renamed from check_quit_flag, made static. New arg extlang. (gdbpy_eval_from_control_command): Renamed from eval_python_from_control_command, made static. New arg extlang. (gdbpy_source_script) Renamed from source_python_script, made static. New arg extlang. (gdbpy_before_prompt_hook): Renamed from before_prompt_hook. Change result to int. New arg extlang. (gdbpy_source_objfile_script): Renamed from source_python_script_for_objfile, made static. New arg extlang. (gdbpy_start_type_printers): Renamed from start_type_printers, made static. New args extlang, extlang_printers. Change result type to "void". (gdbpy_apply_type_printers): Renamed from apply_type_printers, made static. New arg extlang. Rename arg printers to extlang_printers and change type to ext_lang_type_printers *. (gdbpy_free_type_printers): Renamed from free_type_printers, made static. Replace argument arg with extlang, extlang_printers. (!HAVE_PYTHON, eval_python_from_control_command): Delete. (!HAVE_PYTHON, source_python_script): Delete. (!HAVE_PYTHON, gdbpy_should_stop): Delete. (!HAVE_PYTHON, gdbpy_breakpoint_has_py_cond): Delete. (!HAVE_PYTHON, start_type_printers): Delete. (!HAVE_PYTHON, apply_type_printers): Delete. (!HAVE_PYTHON, free_type_printers): Delete. (_initialize_python): Delete call to observer_attach_before_prompt. (finalize_python): Set/restore active extension language. (gdbpy_finish_initialization) Renamed from finish_python_initialization, made static. New arg extlang. (gdbpy_initialized): New function. * python/python.h: #include "extension.h". Delete #include "value.h", "mi/mi-cmds.h". (extension_language_python): Declare. (GDBPY_AUTO_FILE_NAME): Delete. (enum py_bt_status): Moved to extension.h and renamed to ext_lang_bt_status. (enum frame_filter_flags): Moved to extension.h. (enum py_frame_args): Moved to extension.h and renamed to ext_lang_frame_args. (finish_python_initialization): Delete. (eval_python_from_control_command): Delete. (source_python_script): Delete. (apply_val_pretty_printer): Delete. (apply_frame_filter): Delete. (preserve_python_values): Delete. (gdbpy_script_language_defn): Delete. (gdbpy_should_stop, gdbpy_breakpoint_has_py_cond): Delete. (start_type_printers, apply_type_printers, free_type_printers): Delete. * auto-load.c: #include "extension.h". (GDB_AUTO_FILE_NAME): Delete. (auto_load_gdb_scripts_enabled): Make public. New arg extlang. (script_language_gdb): Delete, moved to extension.c and renamed to extension_language_gdb. (source_gdb_script_for_objfile): Delete. (auto_load_pspace_info): New member unsupported_script_warning_printed. (loaded_script): Change type of language member to struct extension_language_defn *. (init_loaded_scripts_info): Initialize unsupported_script_warning_printed. (maybe_add_script): Make static. Change type of language arg to struct extension_language_defn *. (clear_section_scripts): Reset unsupported_script_warning_printed. (auto_load_objfile_script_1): Rewrite to use extension language API. (auto_load_objfile_script): Make public. Remove support-compiled-in and auto-load-enabled checks, moved to auto_load_scripts_for_objfile. (source_section_scripts): Rewrite to use extension language API. (load_auto_scripts_for_objfile): Rewrite to use auto_load_scripts_for_objfile. (collect_matching_scripts_data): Change type of language member to struct extension_language_defn *. (auto_load_info_scripts): Change type of language arg to struct extension_language_defn *. (unsupported_script_warning_print): New function. (script_not_found_warning_print): Make static. (_initialize_auto_load): Rewrite construction of scripts-directory help. * auto-load.h (struct objfile): Add forward decl. (struct script_language): Delete. (struct auto_load_pspace_info): Add forward decl. (struct extension_language_defn): Add forward decl. (maybe_add_script): Delete. (auto_load_objfile_script): Declare. (script_not_found_warning_print): Delete. (auto_load_info_scripts): Update prototype. (auto_load_gdb_scripts_enabled): Declare. * python/py-auto-load.c (gdbpy_auto_load_enabled): Renamed from auto_load_python_scripts_enabled and made public. (script_language_python): Delete, moved to python.c. (gdbpy_script_language_defn): Delete. (info_auto_load_python_scripts): Update to use extension_language_python. * breakpoint.c (condition_command): Replace call to gdbpy_breakpoint_has_py_cond with call to get_breakpoint_cond_ext_lang. (bpstat_check_breakpoint_conditions): Replace call to gdbpy_should_stop with call to breakpoint_ext_lang_cond_says_stop. * python/py-breakpoint.c (gdbpy_breakpoint_cond_says_stop): Renamed from gdbpy_should_stop. Change result type to enum scr_bp_stop. New arg slang. Return SCR_BP_STOP_UNSET if py_bp_object is NULL. (gdbpy_breakpoint_has_cond): Renamed from gdbpy_breakpoint_has_py_cond. New arg slang. (local_setattro): Print name of extension language with existing stop condition. * valprint.c (val_print, value_print): Update to call apply_ext_lang_val_pretty_printer. * cp-valprint.c (cp_print_value): Update call to apply_ext_lang_val_pretty_printer. * python/py-prettyprint.c: Remove #ifdef HAVE_PYTHON. (gdbpy_apply_val_pretty_printer): Renamed from apply_val_pretty_printer. New arg extlang. (!HAVE_PYTHON, apply_val_pretty_printer): Delete. * cli/cli-cmds.c (source_script_from_stream): Rewrite to use extension language API. * cli/cli-script.c (execute_control_command): Update to call eval_ext_lang_from_control_command. * mi/mi-cmd-stack.c (mi_cmd_stack_list_frames): Update to use enum ext_lang_bt_status values. Update call to apply_ext_lang_frame_filter. (mi_cmd_stack_list_locals): Ditto. (mi_cmd_stack_list_args): Ditto. (mi_cmd_stack_list_variables): Ditto. * mi/mi-main.c: Delete #include "python/python-internal.h". Add #include "extension.h". (mi_cmd_list_features): Replace reference to python internal variable gdb_python_initialized with call to ext_lang_initialized_p. * stack.c (backtrace_command_1): Update to use enum ext_lang_bt_status. Update to use enum ext_lang_frame_args. Update to call apply_ext_lang_frame_filter. * python/py-framefilter.c (extract_sym): Update to use enum ext_lang_bt_status. (extract_value, py_print_type, py_print_value): Ditto. (py_print_single_arg, enumerate_args, enumerate_locals): Ditto. (py_mi_print_variables, py_print_locals, py_print_args): Ditto. (py_print_frame): Ditto. (gdbpy_apply_frame_filter): Renamed from apply_frame_filter. New arg extlang. Update to use enum ext_lang_bt_status. * top.c (gdb_init): Delete #ifdef HAVE_PYTHON call to finish_python_initialization. Replace with call to finish_ext_lang_initialization. * typeprint.c (do_free_global_table): Update to call free_ext_lang_type_printers. (create_global_typedef_table): Update to call start_ext_lang_type_printers. (find_global_typedef): Update to call apply_ext_lang_type_printers. * typeprint.h (struct ext_lang_type_printers): Add forward decl. (type_print_options): Change type of global_printers from "void *" to "struct ext_lang_type_printers *". * value.c (preserve_values): Update to call preserve_ext_lang_values. * python/py-value.c: Remove #ifdef HAVE_PYTHON. (gdbpy_preserve_values): Renamed from preserve_python_values. New arg extlang. (!HAVE_PYTHON, preserve_python_values): Delete. * utils.c (quit_flag): Delete, moved to extension.c. (clear_quit_flag, set_quit_flag, check_quit_flag): Delete, moved to extension.c. * eval.c: Delete #include "python/python.h". * main.c: Delete #include "python/python.h". * defs.h: Update comment. testsuite/ * gdb.python/py-breakpoint.exp (test_bkpt_eval_funcs): Update expected output. * gdb.gdb/python-interrupts.exp: New file.
2014-02-06 03:27:58 +00:00
"Only one stop condition allowed. There is currently a Python.*" \
"Check you cannot add a CLI condition to a Python breakpoint that has defined stop"
gdb_py_test_silent_cmd "python eval_bp2 = basic(\"$cond_bp\")" \
"Set breakpoint" 0
gdb_py_test_silent_cmd "python eval_bp2.condition = \"1==1\"" \
"Set a condition" 0
gdb_py_test_multiple "Construct an eval function" \
"python" "" \
"def stop_func ():" "" \
" return True" "" \
"end" ""
gdb_test "python eval_bp2.stop = stop_func" \
Extension Language API * configure.ac (libpython checking): Remove all but python.o from CONFIG_OBS. Remove all but python.c from CONFIG_SRCS. * configure: Regenerate. * Makefile.in (SFILES): Add extension.c. (HFILES_NO_SRCDIR): Add extension.h, extension-priv.h (COMMON_OBS): Add extension.o. * extension.h: New file. * extension-priv.h: New file. * extension.c: New file. * python/python-internal.h: #include "extension.h". (gdbpy_auto_load_enabled): Declare. (gdbpy_apply_val_pretty_printer): Declare. (gdbpy_apply_frame_filter): Declare. (gdbpy_preserve_values): Declare. (gdbpy_breakpoint_cond_says_stop): Declare. (gdbpy_breakpoint_has_cond): Declare. (void source_python_script_for_objfile): Delete. * python/python.c: #include "extension-priv.h". Delete inclusion of "observer.h". (extension_language_python): Moved here and renamed from script_language_python in py-auto-load.c. Redefined to be of type extension_language_defn. (python_extension_script_ops): New global. (python_extension_ops): New global. (struct python_env): New member previous_active. (restore_python_env): Call restore_active_ext_lang. (ensure_python_env): Call set_active_ext_lang. (gdbpy_clear_quit_flag): Renamed from clear_quit_flag, made static. New arg extlang. (gdbpy_set_quit_flag): Renamed from set_quit_flag, made static. New arg extlang. (gdbpy_check_quit_flag): Renamed from check_quit_flag, made static. New arg extlang. (gdbpy_eval_from_control_command): Renamed from eval_python_from_control_command, made static. New arg extlang. (gdbpy_source_script) Renamed from source_python_script, made static. New arg extlang. (gdbpy_before_prompt_hook): Renamed from before_prompt_hook. Change result to int. New arg extlang. (gdbpy_source_objfile_script): Renamed from source_python_script_for_objfile, made static. New arg extlang. (gdbpy_start_type_printers): Renamed from start_type_printers, made static. New args extlang, extlang_printers. Change result type to "void". (gdbpy_apply_type_printers): Renamed from apply_type_printers, made static. New arg extlang. Rename arg printers to extlang_printers and change type to ext_lang_type_printers *. (gdbpy_free_type_printers): Renamed from free_type_printers, made static. Replace argument arg with extlang, extlang_printers. (!HAVE_PYTHON, eval_python_from_control_command): Delete. (!HAVE_PYTHON, source_python_script): Delete. (!HAVE_PYTHON, gdbpy_should_stop): Delete. (!HAVE_PYTHON, gdbpy_breakpoint_has_py_cond): Delete. (!HAVE_PYTHON, start_type_printers): Delete. (!HAVE_PYTHON, apply_type_printers): Delete. (!HAVE_PYTHON, free_type_printers): Delete. (_initialize_python): Delete call to observer_attach_before_prompt. (finalize_python): Set/restore active extension language. (gdbpy_finish_initialization) Renamed from finish_python_initialization, made static. New arg extlang. (gdbpy_initialized): New function. * python/python.h: #include "extension.h". Delete #include "value.h", "mi/mi-cmds.h". (extension_language_python): Declare. (GDBPY_AUTO_FILE_NAME): Delete. (enum py_bt_status): Moved to extension.h and renamed to ext_lang_bt_status. (enum frame_filter_flags): Moved to extension.h. (enum py_frame_args): Moved to extension.h and renamed to ext_lang_frame_args. (finish_python_initialization): Delete. (eval_python_from_control_command): Delete. (source_python_script): Delete. (apply_val_pretty_printer): Delete. (apply_frame_filter): Delete. (preserve_python_values): Delete. (gdbpy_script_language_defn): Delete. (gdbpy_should_stop, gdbpy_breakpoint_has_py_cond): Delete. (start_type_printers, apply_type_printers, free_type_printers): Delete. * auto-load.c: #include "extension.h". (GDB_AUTO_FILE_NAME): Delete. (auto_load_gdb_scripts_enabled): Make public. New arg extlang. (script_language_gdb): Delete, moved to extension.c and renamed to extension_language_gdb. (source_gdb_script_for_objfile): Delete. (auto_load_pspace_info): New member unsupported_script_warning_printed. (loaded_script): Change type of language member to struct extension_language_defn *. (init_loaded_scripts_info): Initialize unsupported_script_warning_printed. (maybe_add_script): Make static. Change type of language arg to struct extension_language_defn *. (clear_section_scripts): Reset unsupported_script_warning_printed. (auto_load_objfile_script_1): Rewrite to use extension language API. (auto_load_objfile_script): Make public. Remove support-compiled-in and auto-load-enabled checks, moved to auto_load_scripts_for_objfile. (source_section_scripts): Rewrite to use extension language API. (load_auto_scripts_for_objfile): Rewrite to use auto_load_scripts_for_objfile. (collect_matching_scripts_data): Change type of language member to struct extension_language_defn *. (auto_load_info_scripts): Change type of language arg to struct extension_language_defn *. (unsupported_script_warning_print): New function. (script_not_found_warning_print): Make static. (_initialize_auto_load): Rewrite construction of scripts-directory help. * auto-load.h (struct objfile): Add forward decl. (struct script_language): Delete. (struct auto_load_pspace_info): Add forward decl. (struct extension_language_defn): Add forward decl. (maybe_add_script): Delete. (auto_load_objfile_script): Declare. (script_not_found_warning_print): Delete. (auto_load_info_scripts): Update prototype. (auto_load_gdb_scripts_enabled): Declare. * python/py-auto-load.c (gdbpy_auto_load_enabled): Renamed from auto_load_python_scripts_enabled and made public. (script_language_python): Delete, moved to python.c. (gdbpy_script_language_defn): Delete. (info_auto_load_python_scripts): Update to use extension_language_python. * breakpoint.c (condition_command): Replace call to gdbpy_breakpoint_has_py_cond with call to get_breakpoint_cond_ext_lang. (bpstat_check_breakpoint_conditions): Replace call to gdbpy_should_stop with call to breakpoint_ext_lang_cond_says_stop. * python/py-breakpoint.c (gdbpy_breakpoint_cond_says_stop): Renamed from gdbpy_should_stop. Change result type to enum scr_bp_stop. New arg slang. Return SCR_BP_STOP_UNSET if py_bp_object is NULL. (gdbpy_breakpoint_has_cond): Renamed from gdbpy_breakpoint_has_py_cond. New arg slang. (local_setattro): Print name of extension language with existing stop condition. * valprint.c (val_print, value_print): Update to call apply_ext_lang_val_pretty_printer. * cp-valprint.c (cp_print_value): Update call to apply_ext_lang_val_pretty_printer. * python/py-prettyprint.c: Remove #ifdef HAVE_PYTHON. (gdbpy_apply_val_pretty_printer): Renamed from apply_val_pretty_printer. New arg extlang. (!HAVE_PYTHON, apply_val_pretty_printer): Delete. * cli/cli-cmds.c (source_script_from_stream): Rewrite to use extension language API. * cli/cli-script.c (execute_control_command): Update to call eval_ext_lang_from_control_command. * mi/mi-cmd-stack.c (mi_cmd_stack_list_frames): Update to use enum ext_lang_bt_status values. Update call to apply_ext_lang_frame_filter. (mi_cmd_stack_list_locals): Ditto. (mi_cmd_stack_list_args): Ditto. (mi_cmd_stack_list_variables): Ditto. * mi/mi-main.c: Delete #include "python/python-internal.h". Add #include "extension.h". (mi_cmd_list_features): Replace reference to python internal variable gdb_python_initialized with call to ext_lang_initialized_p. * stack.c (backtrace_command_1): Update to use enum ext_lang_bt_status. Update to use enum ext_lang_frame_args. Update to call apply_ext_lang_frame_filter. * python/py-framefilter.c (extract_sym): Update to use enum ext_lang_bt_status. (extract_value, py_print_type, py_print_value): Ditto. (py_print_single_arg, enumerate_args, enumerate_locals): Ditto. (py_mi_print_variables, py_print_locals, py_print_args): Ditto. (py_print_frame): Ditto. (gdbpy_apply_frame_filter): Renamed from apply_frame_filter. New arg extlang. Update to use enum ext_lang_bt_status. * top.c (gdb_init): Delete #ifdef HAVE_PYTHON call to finish_python_initialization. Replace with call to finish_ext_lang_initialization. * typeprint.c (do_free_global_table): Update to call free_ext_lang_type_printers. (create_global_typedef_table): Update to call start_ext_lang_type_printers. (find_global_typedef): Update to call apply_ext_lang_type_printers. * typeprint.h (struct ext_lang_type_printers): Add forward decl. (type_print_options): Change type of global_printers from "void *" to "struct ext_lang_type_printers *". * value.c (preserve_values): Update to call preserve_ext_lang_values. * python/py-value.c: Remove #ifdef HAVE_PYTHON. (gdbpy_preserve_values): Renamed from preserve_python_values. New arg extlang. (!HAVE_PYTHON, preserve_python_values): Delete. * utils.c (quit_flag): Delete, moved to extension.c. (clear_quit_flag, set_quit_flag, check_quit_flag): Delete, moved to extension.c. * eval.c: Delete #include "python/python.h". * main.c: Delete #include "python/python.h". * defs.h: Update comment. testsuite/ * gdb.python/py-breakpoint.exp (test_bkpt_eval_funcs): Update expected output. * gdb.gdb/python-interrupts.exp: New file.
2014-02-06 03:27:58 +00:00
"RuntimeError: Only one stop condition allowed. There is currently a GDB.*" \
"Assign stop function to a breakpoint that has a condition"
delete_breakpoints
gdb_breakpoint [gdb_get_line_number "Break at multiply."]
gdb_py_test_silent_cmd "python check_eval = bp_eval(\"$bp_location2\")" \
"Set breakpoint" 0
gdb_test "python print (check_eval.count)" "0" \
"Test that evaluate function has not been yet executed (ie count = 0)"
gdb_continue_to_breakpoint "Break at multiply, count==1" \
".*/$srcfile:$bp_location2.*"
gdb_test "python print (check_eval.count)" "1" \
"Test that evaluate function is run when location also has normal bp"
gdb_py_test_multiple "Sub-class a watchpoint" \
"python" "" \
"class wp_eval (gdb.Breakpoint):" "" \
" def stop (self):" "" \
" self.result = gdb.parse_and_eval(\"result\")" "" \
" if self.result == 788:" "" \
" return True" "" \
" return False" "" \
"end" ""
delete_breakpoints
gdb_py_test_silent_cmd "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE)" \
"Set watchpoint" 0
gdb_test "continue" \
".*\[Ww\]atchpoint.*result.*Old value =.*New value = 788.*" \
"Test watchpoint write"
gdb_test "python print (never_eval_bp1.count)" "0" \
"Check that this unrelated breakpoints eval function was never called."
}
}
proc test_bkpt_temporary { } {
global srcfile testfile hex decimal
with_test_prefix test_bkpt_temporary {
# Start with a fresh gdb.
clean_restart ${testfile}
if ![runto_main] then {
fail "Cannot run to main."
return 0
}
delete_breakpoints
gdb_py_test_multiple "Sub-class and check temporary breakpoint" \
"python" "" \
"class temp_bp (gdb.Breakpoint):" "" \
" count = 0" "" \
" def stop (self):" "" \
" self.count = self.count + 1" "" \
" return True" "" \
"end" ""
set ibp_location [gdb_get_line_number "Break at multiply."]
gdb_py_test_silent_cmd "python ibp = temp_bp(\"$ibp_location\", temporary=True)" \
"Set temporary breakpoint" 0
gdb_test "info breakpoints" \
"2.*breakpoint.*del.*py-breakpoint\.c:$ibp_location.*" \
"Check info breakpoints shows breakpoint with temporary status"
gdb_test "python print (ibp.location)" "py-breakpoint\.c:$ibp_location*" \
"Check temporary breakpoint location"
gdb_test "python print (ibp.temporary)" "True" \
"Check breakpoint temporary status"
gdb_continue_to_breakpoint "Break at multiply." \
".*/$srcfile:$ibp_location.*"
gdb_test "python print (ibp.count)" "1" \
"Check temporary stop callback executed before deletion."
gdb_test "python print (ibp.temporary)" "RuntimeError: Breakpoint 2 is invalid.*" \
"Check temporary breakpoint is deleted after being hit"
gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \
"Check info breakpoints shows temporary breakpoint is deleted"
}
}
test_bkpt_basic
test_bkpt_deletion
test_bkpt_cond_and_cmds
test_bkpt_invisible
test_watchpoints
test_bkpt_internal
test_bkpt_eval_funcs
test_bkpt_temporary